"code", "redirect_uri" => $redirect_uri, "scope" => "event:write", "client_id" => $client_id ), "{$instance_url}/oauth/authorize")); // return $instance_url; exit; } add_action( 'network_admin_edit_wpgancio_instance_url', 'wpgancio_instance_url_save_settings' ); function wpgancio_instance_url_save_settings(){ // check_admin_referer( 'misha-validate' ); // Nonce security check if (isset($_POST['wpgancio_instance_url'])) { update_site_option( 'wpgancio_instance_url', $_POST['wpgancio_instance_url'] ); } else { delete_site_option( 'wpgancio_instance_url'); } wp_redirect( add_query_arg( array( 'page' => 'wpgancio', 'updated' => true ), network_admin_url('settings.php?page=wpgancio') )); exit; } // Fires before the administration menu loads in the admin, add our options page function wpgancio_instance_url_validate ($instance_url) { if (!is_network_admin()) { $old_instance_url = get_option('wpgancio_instance_url'); if ($instance_url === $old_instance_url) { return $instance_url; } } else { $old_instance_url = get_site_option('wpgancio_instance_url'); if ($instance_url === $old_instance_url) { return $instance_url; } } if (!is_network_admin()) { $redirect_uri = get_site_url(null, '/wp-admin/options-general.php?page=wpgancio'); } else { $redirect_uri = get_site_url(null, '/wp-admin/network/settings.php?page=wpgancio'); } // create this WP instance as a new client in selected gancio instance $response = wp_remote_post("$instance_url/api/client", array( 'method' => 'POST', 'body' => array( 'client_name' => 'WPGancio', 'redirect_uris' => esc_html($redirect_uri), 'scopes' => 'event:write', 'website' => 'https://gancio.org' ) )); if (is_wp_error($response)) { add_settings_error('wpgancio_messages', 'wpgancio_messages', $response->get_error_message()); } else { $data = json_decode( wp_remote_retrieve_body($response), true); if (!is_network_admin()) { update_option('wpgancio_client_secret', sanitize_key($data['client_secret'])); update_option('wpgancio_client_id', sanitize_key($data['client_id'])); } else { update_site_option('wpgancio_client_secret', sanitize_key($data['client_secret'])); update_site_option('wpgancio_client_id', sanitize_key($data['client_id'])); } return $instance_url; } } // instance url field cb // field callbacks can accept an $args parameter, which is an array. // $args is defined at the add_settings_field() function. // wordpress has magic interaction with the following keys: label_for, class. // the "label_for" key value is used for the "for" attribute of the