/** * @todo Ensure sites are not in/active before performing action */ public function process_bulk_action() { if (!isset($_POST['bulk']) || empty($_POST['bulk'])) { return; } // Thou shall not pass! There is nothing to do $jpms = Jetpack_Network::init(); $action = $this->current_action(); switch ($action) { case 'connect': foreach ($_POST['bulk'] as $k => $site) { $jpms->do_subsiteregister($site); } break; case 'disconnect': foreach ($_POST['bulk'] as $k => $site) { $jpms->do_subsitedisconnect($site); } break; } }
/** * This is the old pre-3.0 admin page. It is replaced by the Jetpack_Admin class. * Tentatively left here for comparison purposes. */ function admin_page() { global $current_user; $is_connected = Jetpack::is_active(); $user_token = Jetpack_Data::get_access_token($current_user->ID); $is_user_connected = $user_token && !is_wp_error($user_token); $is_master_user = $current_user->ID == Jetpack_Options::get_option('master_user'); $can_reconnect_jpms = true; if (is_plugin_active_for_network('jetpack/jetpack.php')) { $jpms = Jetpack_Network::init(); $can_reconnect_jpms = $jpms->get_option('sub-site-connection-override') ? 1 : 0; } ?> <div class="wrap" id="jetpack-settings"> <div id="jp-header"<?php if ($is_connected) { ?> class="small"<?php } ?> > <div id="jp-clouds"> <?php if ($is_connected && $can_reconnect_jpms) { ?> <div id="jp-disconnectors"> <?php if (current_user_can('jetpack_disconnect')) { ?> <div id="jp-disconnect" class="jp-disconnect"> <a href="<?php echo wp_nonce_url(Jetpack::admin_url('action=disconnect'), 'jetpack-disconnect'); ?> "><div class="deftext"><?php _e('Connected to WordPress.com', 'jetpack'); ?> </div><div class="hovertext"><?php _e('Disconnect from WordPress.com', 'jetpack'); ?> </div></a> </div> <?php } ?> <?php if ($is_user_connected && !$is_master_user) { ?> <div id="jp-unlink" class="jp-disconnect"> <a href="<?php echo wp_nonce_url(Jetpack::admin_url('action=unlink'), 'jetpack-unlink'); ?> "><div class="deftext"><?php _e('User linked to WordPress.com', 'jetpack'); ?> </div><div class="hovertext"><?php _e('Unlink user from WordPress.com', 'jetpack'); ?> </div></a> </div> <?php } ?> </div> <?php } ?> <h3><?php _e('Jetpack by WordPress.com', 'jetpack'); ?> </h3> <?php if (!$is_connected) { ?> <div id="jp-notice"> <p><?php _e('Jetpack supercharges your self-hosted WordPress site with the awesome cloud power of WordPress.com.', 'jetpack'); ?> </p> </div> <?php } ?> </div> </div> <h2 style="display: none"></h2> <!-- For WP JS message relocation --> <?php Jetpack::init()->load_view('admin/network-activated-notice.php'); ?> <?php do_action('jetpack_notices'); ?> <?php // If the connection has not been made then show the marketing text. if (!$can_reconnect_jpms && !$is_connected) { ?> <div id="message" class="updated jetpack-message jp-connect jp-multisite" style="display:block !important"> <div class="jetpack-wrap-container"> <div class="jetpack-text-container"> <h4> <p><?php _e('To use Jetpack please contact your WordPress administrator to connect it for you.', 'jetpack'); ?> </p> </h4> </div> </div> </div> <?php } if (!Jetpack::is_development_mode() && $can_reconnect_jpms) { ?> <?php if (!$is_connected) { $dismiss_and_deactivate_url = wp_nonce_url(Jetpack::admin_url('?page=jetpack&jetpack-notice=dismiss'), 'jetpack-deactivate'); ?> <div id="message" class="updated jetpack-message jp-connect" style="display:block !important;"> <div id="jp-dismiss" class="jetpack-close-button-container"> <a class="jetpack-close-button" href="<?php echo esc_url($dismiss_and_deactivate_url); ?> "><?php _e('Dismiss this notice.', 'jetpack'); ?> </a> </div> <div class="jetpack-wrap-container"> <div class="jetpack-text-container"> <h4> <p><?php _e('To enable all of the Jetpack features you’ll need to connect your website to WordPress.com using the button to the right. Once you’ve made the connection you’ll activate all the delightful features below.', 'jetpack'); ?> </p> </h4> </div> <div class="jetpack-install-container"> <p class="submit"><a href="<?php echo $this->build_connect_url(); ?> " class="button-connector" id="wpcom-connect"><?php _e('Connect to WordPress.com', 'jetpack'); ?> </a></p> </div> </div> </div> <?php } else { ?> <?php /* TODO: if not master user, show user disconnect button? */ ?> <?php } ?> <?php } // ! Jetpack::is_development_mode() ?> <?php if (Jetpack::is_active() && !Jetpack::is_development_mode() && !$is_user_connected) { ?> <div id="message" class="updated jetpack-message jp-connect" style="display:block !important;"> <div class="jetpack-wrap-container"> <div class="jetpack-text-container"> <h4> <p><?php _e('To enable all of the Jetpack features you’ll need to link your account here to your WordPress.com account using the button to the right.', 'jetpack'); ?> </p> </h4> </div> <div class="jetpack-install-container"> <p class="submit"><a href="<?php echo $this->build_connect_url(); ?> " class="button-connector" id="wpcom-connect"><?php _e('Link account with WordPress.com', 'jetpack'); ?> </a></p> </div> </div> </div> <?php } ?> <?php if (isset($_GET['configure']) && Jetpack::is_module($_GET['configure']) && current_user_can('manage_options')) { $this->admin_screen_configure_module($_GET['configure']); } else { $this->admin_screen_list_modules(); } ?> <div id="survey" class="jp-survey"> <div class="jp-survey-container"> <div class="jp-survey-text"> <h4><?php _e('Have feedback on Jetpack?', 'jetpack'); ?> </h4> <br /> <?php _e('Answer a short survey to let us know how we’re doing and what to add in the future.', 'jetpack'); ?> </div> <div class="jp-survey-button-container"> <p class="submit"><?php printf('<a id="jp-survey-button" class="button-primary" target="_blank" href="%1$s">%2$s</a>', 'http://jetpack.me/survey/?rel=' . JETPACK__VERSION, __('Take Survey', 'jetpack')); ?> </p> </div> </div> </div> <?php if ($is_connected && $this->current_user_is_connection_owner()) { ?> <p id="news-sub"><?php _e('Checking email updates status…', 'jetpack'); ?> </p> <script type="text/javascript"> jQuery(document).ready(function($){ $.get( ajaxurl, { action: 'jetpack-check-news-subscription', rand: jQuery.now().toString() + Math.random().toString() }, function( data ) { if ( 'subscribed' == data ) { $( '#news-sub' ).html( '<?php printf(esc_js(_x('You are currently subscribed to email updates. %s', '%s = Unsubscribe link', 'jetpack')), '<a href="#" class="jp-news-link button">' . esc_js(__('Unsubscribe', 'jetpack')) . '</a>'); ?> ' ); } else { $( '#news-sub' ).html( '<?php printf(esc_js(_x('Want to receive updates about Jetpack by email? %s', '%s = Subscribe link', 'jetpack')), '<a href="#" class="jp-news-link button-primary">' . esc_js(__('Subscribe', 'jetpack')) . '</a>'); ?> ' ); } $( '.jp-news-link' ).click( function() { $( '#news-sub' ).append( ' <img src="<?php echo esc_js(esc_url(admin_url('images/loading.gif'))); ?> " align="absmiddle" id="jp-news-loading" />' ); $.get( ajaxurl, { action: 'jetpack-subscribe-to-news', rand: jQuery.now().toString() + Math.random().toString() }, function( data ) { if ( 'subscribed' == data ) { $( '#news-sub' ).text( '<?php echo esc_js(__('You have been subscribed to receive email updates.', 'jetpack')); ?> ' ); } else { $( '#news-sub' ).text( '<?php echo esc_js(__('You will no longer receive email updates about Jetpack.', 'jetpack')); ?> ' ); } $( '#jp-news-loading' ).remove(); } ); return false; } ); } ); } ); </script> <?php } ?> <div id="jp-footer"> <p class="automattic"><?php _e('An <span>Automattic</span> Airline', 'jetpack'); ?> </p> <p class="small"> <a href="http://jetpack.me/" target="_blank">Jetpack <?php echo esc_html(JETPACK__VERSION); ?> </a> | <a href="http://automattic.com/privacy/" target="_blank"><?php _e('Privacy Policy', 'jetpack'); ?> </a> | <a href="http://wordpress.com/tos/" target="_blank"><?php _e('Terms of Service', 'jetpack'); ?> </a> | <?php if (current_user_can('manage_options')) { ?> <a href="<?php echo Jetpack::admin_url(array('page' => 'jetpack-debugger')); ?> "><?php _e('Debug', 'jetpack'); ?> </a> | <?php } ?> <a href="http://jetpack.me/support/" target="_blank"><?php _e('Support', 'jetpack'); ?> </a> </p> </div> <div id="jetpack-configuration" style="display:none;"> <p><img width="16" src="<?php echo esc_url(plugins_url('_inc/images/wpspin_light-2x.gif', __FILE__)); ?> " alt="Loading ..." /></p> </div> </div> <?php }
/** * Builds a URL to the Jetpack connection auth page * * @since 3.9.5 * * @param bool $raw If true, URL will not be escaped. * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. * If string, will be a custom redirect. * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. * * @return string Connect URL */ function build_connect_url($raw = false, $redirect = false, $from = false) { if (!Jetpack_Options::get_option('blog_token') || !Jetpack_Options::get_option('id')) { $url = Jetpack::nonce_url_no_esc(Jetpack::admin_url('action=register'), 'jetpack-register'); if (is_network_admin()) { $url = add_query_arg('is_multisite', network_admin_url('admin.php?page=jetpack-settings'), $url); } } else { require_once JETPACK__GLOTPRESS_LOCALES_PATH; $role = $this->translate_current_user_to_role(); $signed_role = $this->sign_role($role); $user = wp_get_current_user(); $redirect = $redirect ? esc_url_raw($redirect) : esc_url_raw(menu_page_url('jetpack', false)); $gp_locale = GP_Locales::by_field('wp_locale', get_locale()); if (isset($_REQUEST['is_multisite'])) { $redirect = Jetpack_Network::init()->get_url('network_admin_page'); } $secrets = Jetpack::init()->generate_secrets('authorize'); @(list($secret) = explode(':', $secrets)); $site_icon = function_exists('has_site_icon') && has_site_icon() ? get_site_icon_url() : false; $args = urlencode_deep(array('response_type' => 'code', 'client_id' => Jetpack_Options::get_option('id'), 'redirect_uri' => add_query_arg(array('action' => 'authorize', '_wpnonce' => wp_create_nonce("jetpack-authorize_{$role}_{$redirect}"), 'redirect' => urlencode($redirect)), menu_page_url('jetpack', false)), 'state' => $user->ID, 'scope' => $signed_role, 'user_email' => $user->user_email, 'user_login' => $user->user_login, 'is_active' => Jetpack::is_active(), 'jp_version' => JETPACK__VERSION, 'auth_type' => 'calypso', 'secret' => $secret, 'locale' => isset($gp_locale->slug) ? $gp_locale->slug : '', 'blogname' => get_option('blogname'), 'site_url' => site_url(), 'home_url' => home_url(), 'site_icon' => $site_icon)); $url = add_query_arg($args, Jetpack::api_url('authorize')); } if ($from) { $url = add_query_arg('from', $from, $url); } if (isset($_GET['calypso_env'])) { $url = add_query_arg('calypso_env', $_GET['calypso_env'], $url); } return $raw ? $url : esc_url($url); }
/** * Builds a URL to the Jetpack connection auth page * * @since 3.9.5 * * @param bool $raw If true, URL will not be escaped. * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. * If string, will be a custom redirect. * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. * * @return string Connect URL */ function build_connect_url($raw = false, $redirect = false, $from = false) { if (!Jetpack_Options::get_option('blog_token') || !Jetpack_Options::get_option('id')) { $url = Jetpack::nonce_url_no_esc(Jetpack::admin_url('action=register'), 'jetpack-register'); if (is_network_admin()) { $url = add_query_arg('is_multisite', network_admin_url('admin.php?page=jetpack-settings'), $url); } } else { if (defined('JETPACK__GLOTPRESS_LOCALES_PATH') && (include_once JETPACK__GLOTPRESS_LOCALES_PATH)) { $gp_locale = GP_Locales::by_field('wp_locale', get_locale()); } $role = self::translate_current_user_to_role(); $signed_role = self::sign_role($role); $user = wp_get_current_user(); $jetpack_admin_page = esc_url_raw(admin_url('admin.php?page=jetpack')); $redirect = $redirect ? wp_validate_redirect(esc_url_raw($redirect), $jetpack_admin_page) : $jetpack_admin_page; if (isset($_REQUEST['is_multisite'])) { $redirect = Jetpack_Network::init()->get_url('network_admin_page'); } $secrets = Jetpack::init()->generate_secrets('authorize'); @(list($secret) = explode(':', $secrets)); $site_icon = function_exists('has_site_icon') && has_site_icon() ? get_site_icon_url() : false; /** * Filter the type of authorization. * 'calypso' completes authorization on wordpress.com/jetpack/connect * while 'jetpack' ( or any other value ) completes the authorization at jetpack.wordpress.com. * * @since 4.3.3 * * @param string $auth_type Defaults to 'calypso', can also be 'jetpack'. */ $auth_type = apply_filters('jetpack_auth_type', 'calypso'); $args = urlencode_deep(array('response_type' => 'code', 'client_id' => Jetpack_Options::get_option('id'), 'redirect_uri' => add_query_arg(array('action' => 'authorize', '_wpnonce' => wp_create_nonce("jetpack-authorize_{$role}_{$redirect}"), 'redirect' => urlencode($redirect)), esc_url(admin_url('admin.php?page=jetpack'))), 'state' => $user->ID, 'scope' => $signed_role, 'user_email' => $user->user_email, 'user_login' => $user->user_login, 'is_active' => Jetpack::is_active(), 'jp_version' => JETPACK__VERSION, 'auth_type' => $auth_type, 'secret' => $secret, 'locale' => isset($gp_locale) && isset($gp_locale->slug) ? $gp_locale->slug : '', 'blogname' => get_option('blogname'), 'site_url' => site_url(), 'home_url' => home_url(), 'site_icon' => $site_icon)); $url = add_query_arg($args, Jetpack::api_url('authorize')); } if ($from) { $url = add_query_arg('from', $from, $url); } if (isset($_GET['calypso_env'])) { $url = add_query_arg('calypso_env', sanitize_key($_GET['calypso_env']), $url); } return $raw ? $url : esc_url($url); }
function build_connect_url($raw = false, $redirect = false) { if (!Jetpack_Options::get_option('blog_token') || !Jetpack_Options::get_option('id')) { $url = Jetpack::nonce_url_no_esc(Jetpack::admin_url('action=register'), 'jetpack-register'); if (is_network_admin()) { $url = add_query_arg('is_multisite', network_admin_url('admin.php?page=jetpack-settings'), $url); } } else { $role = $this->translate_current_user_to_role(); $signed_role = $this->sign_role($role); $user = wp_get_current_user(); $redirect = $redirect ? esc_url_raw($redirect) : ''; if (isset($_REQUEST['is_multisite'])) { $redirect = Jetpack_Network::init()->get_url('network_admin_page'); } $args = urlencode_deep(array('response_type' => 'code', 'client_id' => Jetpack_Options::get_option('id'), 'redirect_uri' => add_query_arg(array('action' => 'authorize', '_wpnonce' => wp_create_nonce("jetpack-authorize_{$role}_{$redirect}"), 'redirect' => $redirect ? urlencode($redirect) : false), menu_page_url('jetpack', false)), 'state' => $user->ID, 'scope' => $signed_role, 'user_email' => $user->user_email, 'user_login' => $user->user_login, 'is_active' => Jetpack::is_active(), 'jp_version' => JETPACK__VERSION)); $url = add_query_arg($args, Jetpack::api_url('authorize')); } return $raw ? $url : esc_url($url); }
/** * @since 2.8 **/ public function test_body_class_contains_network_admin() { $jpms = Jetpack_Network::init(); $classes = $jpms->body_class(''); $this->assertInternalType('string', $classes); $this->assertContains('network-admin', $classes); }
function admin_page() { global $current_user; $is_connected = Jetpack::is_active(); $user_token = Jetpack_Data::get_access_token($current_user->ID); $is_user_connected = $user_token && !is_wp_error($user_token); $is_master_user = $current_user->ID == Jetpack_Options::get_option('master_user'); $can_reconnect_jpms = true; if (is_plugin_active_for_network('jetpack/jetpack.php')) { $jpms = Jetpack_Network::init(); $can_reconnect_jpms = $jpms->get_option('sub-site-connection-override') ? 1 : 0; } //slim// Clear annoying banners and foot prints: ?> <div class="wrap" id="jetpack-settings"> <?php if (isset($_GET['configure']) && Jetpack::is_module($_GET['configure']) && current_user_can('manage_options')) { $this->admin_screen_configure_module($_GET['configure']); } else { $this->admin_screen_list_modules(); } ?> <div id="jetpack-configuration" style="display:none;"> <p><img width="16" src="<?php echo esc_url(plugins_url('_inc/images/wpspin_light-2x.gif', __FILE__)); ?> " alt="Loading ..." /></p> </div> </div> <?php }