This commit is contained in:
emmymayo
2025-02-05 23:15:46 +01:00
commit 7269c99357
16995 changed files with 3389680 additions and 0 deletions
@@ -0,0 +1,611 @@
<?php
/**
* Class for the Jetpack About Page within the wp-admin.
*
* @package automattic/jetpack
*/
/**
* Disable direct access and execution.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
require_once __DIR__ . '/class.jetpack-admin-page.php';
/**
* Builds the landing page and its menu.
*/
class Jetpack_About_Page extends Jetpack_Admin_Page {
/**
* Show the settings page only when Jetpack is connected or in dev mode.
*
* @var bool If the page should be shown.
*/
protected $dont_show_if_not_active = true;
/**
* Anonymous info about a12s. The method fetch_a8c_data() stores the response from wpcom here.
*
* @var array
*/
private $a8c_data = null;
/**
* Add a submenu item to the Jetpack admin menu.
*
* @return string
*/
public function get_page_hook() {
// Add the main admin Jetpack menu.
return add_submenu_page(
'',
esc_html__( 'About Jetpack', 'jetpack' ),
'',
'jetpack_admin_page',
'jetpack_about',
array( $this, 'render' )
);
}
/**
* Add page action
*
* @param string $hook Hook of current page.
*/
public function add_page_actions( $hook ) {
if ( 'admin_page_jetpack_about' === $hook ) {
$this->a8c_data = $this->fetch_a8c_data();
}
}
/**
* Enqueues scripts and styles for the admin page.
*/
public function page_admin_scripts() {
wp_enqueue_style( 'plugin-install' );
wp_enqueue_script( 'plugin-install' );
// required for plugin modal action button functionality.
wp_enqueue_script( 'updates' );
// required for modal popup JS and styling.
wp_enqueue_style( 'thickbox' );
wp_enqueue_script( 'thickbox' );
}
/**
* Load styles for static page.
*/
public function additional_styles() {
Jetpack_Admin_Page::load_wrapper_styles();
}
/**
* Render the page with a common top and bottom part, and page specific content
*/
public function render() {
Jetpack_Admin_Page::wrap_ui( array( $this, 'page_render' ), array( 'show-nav' => false ) );
}
/**
* Render the page content
*/
public function page_render() {
?>
<div class="jp-lower">
<h1 class="screen-reader-text"><?php esc_html_e( 'About Jetpack', 'jetpack' ); ?></h1>
<div class="jetpack-about__link-back">
<a href="<?php echo esc_url( admin_url( 'admin.php?page=jetpack' ) ); ?>">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="0" fill="none" width="24" height="24"/><g><path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"/></g></svg>
<?php esc_html_e( 'Back to Jetpack Dashboard', 'jetpack' ); ?>
</a>
</div>
<div class="jetpack-about__main">
<div class="jetpack-about__logo">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 800 96" style="enable-background:new 0 0 800 96;" xml:space="preserve">
<g>
<path style="fill: #39c;" d="M292.922,78c-19.777,0-32.598-14.245-32.598-29.078V47.08c0-15.086,12.821-29.08,32.598-29.08
c19.861,0,32.682,13.994,32.682,29.08v1.843C325.604,63.755,312.783,78,292.922,78z M315.044,47.245
c0-10.808-7.877-20.447-22.122-20.447s-22.04,9.639-22.04,20.447v1.341c0,10.811,7.795,20.614,22.04,20.614
s22.122-9.803,22.122-20.614V47.245z"/>
<path d="M69.602,75.821l-7.374-13.826H29.463l-7.124,13.826H11.277l30.167-55.81h8.715l30.671,55.81H69.602z M45.552,30.906
L33.401,54.369h24.72L45.552,30.906z"/>
<path d="M128.427,78c-20.028,0-29.329-10.894-29.329-25.391V20.012h10.391v32.765c0,10.308,6.788,16.424,19.692,16.424
c13.242,0,18.687-6.116,18.687-16.424V20.012h10.475v32.598C158.342,66.436,149.46,78,128.427,78z"/>
<path d="M216.667,28.727v47.094h-10.475V28.727h-24.386v-8.715h59.245v8.715H216.667z"/>
<path d="M418.955,75.821V31.659l-2.766,4.861l-23.379,39.301h-5.112L364.569,36.52l-2.765-4.861v44.162h-10.224v-55.81h14.497
l22.038,38.296L390.713,63l2.599-4.692l21.786-38.296h14.331v55.81H418.955z"/>
<path d="M508.619,75.821l-7.374-13.826H468.48l-7.123,13.826h-11.061l30.167-55.81h8.715l30.669,55.81H508.619z M484.569,30.906
l-12.151,23.464h24.72L484.569,30.906z"/>
<path d="M562.081,28.727v47.094h-10.474V28.727h-24.386v-8.715h59.245v8.715H562.081z"/>
<path d="M638.924,28.727v47.094H628.45V28.727h-24.386v-8.715h59.245v8.715H638.924z"/>
<path d="M689.118,75.821v-50.53c4.19,0,5.866-2.263,5.866-5.28h4.442v55.81H689.118z"/>
<path d="M781.464,35.765c-5.028-4.609-12.402-8.967-22.374-8.967c-14.916,0-23.296,10.225-23.296,20.867v1.089
c0,10.558,8.464,20.445,24.05,20.445c9.303,0,17.012-4.441,21.872-8.965L788,66.854C781.883,72.887,771.492,78,759.174,78
c-21.118,0-33.939-13.743-33.939-28.828v-1.843c0-15.084,13.993-29.329,34.44-29.329c11.816,0,22.541,4.944,28.324,11.146
L781.464,35.765z"/>
<path d="M299.82,37.417c1.889,1.218,2.418,3.749,1.192,5.648l-9.553,14.797c-1.226,1.901-3.752,2.452-5.637,1.234l0,0
c-1.886-1.22-2.421-3.745-1.192-5.647l9.553-14.797C295.41,36.753,297.935,36.201,299.82,37.417L299.82,37.417z"/>
</g>
</svg>
</div>
<div class="jetpack-about__content">
<div class="jetpack-about__images">
<ul class="jetpack-about__gravatars">
<?php $this->display_gravatars(); ?>
</ul>
<p class="meet-the-team">
<a href="https://automattic.com/about/" target="_blank" rel="noopener noreferrer" class="jptracks" data-jptracks-name="jetpack_about_meet_the_team"><?php esc_html_e( 'Meet the Automattic team', 'jetpack' ); ?></a>
<svg class="gridicons-external" height="24" width="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g><path d="M19 13v6c0 1.105-.895 2-2 2H5c-1.105 0-2-.895-2-2V7c0-1.105.895-2 2-2h6v2H5v12h12v-6h2zM13 3v2h4.586l-7.793 7.793 1.414 1.414L19 6.414V11h2V3h-8z"></path></g></svg>
</p>
</div>
<div class="jetpack-about__text">
<p>
<?php esc_html_e( 'We are the people behind WordPress.com, WooCommerce, Jetpack, Simplenote, Longreads, VaultPress, Akismet, Gravatar, Crowdsignal, Cloudup, and more. We believe in making the web a better place.', 'jetpack' ); ?>
<a href="https://automattic.com/" target="_blank" rel="noopener noreferrer" class="jptracks" data-jptracks-name="jetpack_about_learn_more">
<?php esc_html_e( 'Learn more about us', 'jetpack' ); ?>
</a>
<svg class="gridicons-external" height="24" width="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g><path d="M19 13v6c0 1.105-.895 2-2 2H5c-1.105 0-2-.895-2-2V7c0-1.105.895-2 2-2h6v2H5v12h12v-6h2zM13 3v2h4.586l-7.793 7.793 1.414 1.414L19 6.414V11h2V3h-8z"></path></g></svg>
</p>
<p>
<?php
echo esc_html(
sprintf(
/* translators: first placeholder is the number of Automattic employees. The second is the number of countries of origin*/
__( 'Were a distributed company with over %1$s Automatticians in more than %2$s countries speaking at least %3$s different languages. Our common goal is to democratize publishing so that anyone with a story can tell it, regardless of income, gender, politics, language, or where they live in the world.', 'jetpack' ),
$this->a8c_data['a12s'],
$this->a8c_data['countries'],
$this->a8c_data['languages']
)
);
?>
</p>
<p>
<?php esc_html_e( 'We believe in Open Source and the vast majority of our work is available under the GPL.', 'jetpack' ); ?>
</p>
<p>
<?php
// Maybe use printf() because we'll want to escape the string but still allow for the link, so we can't use esc_html_e().
echo wp_kses(
__( 'We strive to live by the <a href="https://automattic.com/creed/" target="_blank" class="jptracks" data-jptracks-name="jetpack_about_creed" rel="noopener noreferrer">Automattic Creed</a><svg class="gridicons-external" height="24" width="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g><path d="M19 13v6c0 1.105-.895 2-2 2H5c-1.105 0-2-.895-2-2V7c0-1.105.895-2 2-2h6v2H5v12h12v-6h2zM13 3v2h4.586l-7.793 7.793 1.414 1.414L19 6.414V11h2V3h-8z"></path></g></svg>', 'jetpack' ),
array(
'a' => array(
'href' => array(),
'class' => array(),
'target' => array(),
'rel' => array(),
'data-jptracks-name' => array(),
),
'svg' => array(
'class' => array(),
'height' => array(),
'width' => array(),
'xmlns' => array(),
'viewbox' => array(),
),
'g' => array(),
'path' => array(
'd' => array(),
),
)
);
?>
</p>
<p>
<a href="https://automattic.com/work-with-us" target="_blank" rel="noopener noreferrer" class="jptracks" data-jptracks-name="jetpack_about_work_with_us"><?php esc_html_e( 'Come work with us', 'jetpack' ); ?>
</a><svg class="gridicons-external" height="24" width="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g><path d="M19 13v6c0 1.105-.895 2-2 2H5c-1.105 0-2-.895-2-2V7c0-1.105.895-2 2-2h6v2H5v12h12v-6h2zM13 3v2h4.586l-7.793 7.793 1.414 1.414L19 6.414V11h2V3h-8z"></path></g></svg>
</p>
</div>
</div>
</div>
<div class="jetpack-about__colophon">
<h3><?php esc_html_e( 'Popular WordPress services by Automattic', 'jetpack' ); ?></h3>
<ul class="jetpack-about__services">
<?php $this->display_plugins(); ?>
</ul>
<p class="jetpack-about__services-more">
<?php
echo wp_kses(
__( 'For even more of our WordPress plugins, please take a look at <a href="https://profiles.wordpress.org/automattic/#content-plugins" target="_blank" rel="noopener noreferrer" class="jptracks" data-jptracks-name="jetpack_about_wporg_profile">our WordPress.org profile</a>.', 'jetpack' ),
array(
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
'class' => array(),
'data-jptracks-name' => array(),
),
)
);
?>
</p>
</div>
</div>
<?php
}
/**
* Add information cards for a8c plugins.
*/
public function display_plugins() {
$plugins_allowedtags = array(
'a' => array(
'href' => array(),
'title' => array(),
'target' => array(),
),
'abbr' => array( 'title' => array() ),
'acronym' => array( 'title' => array() ),
'code' => array(),
'pre' => array(),
'em' => array(),
'strong' => array(),
'ul' => array(),
'ol' => array(),
'li' => array(),
'p' => array(),
'br' => array(),
);
// slugs for plugins we want to display.
$a8c_plugins = $this->a8c_data['featured_plugins'];
// need this to access the plugins_api() function.
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$plugins = array();
foreach ( $a8c_plugins as $slug ) {
$args = array(
'slug' => $slug,
'fields' => array(
'added' => false,
'author' => false,
'author_profile' => false,
'banners' => false,
'contributors' => false,
'donate_link' => false,
'homepage' => false,
'reviews' => false,
'screenshots' => false,
'support_threads' => false,
'support_threads_resolved' => false,
'sections' => false,
'tags' => false,
'versions' => false,
'compatibility' => true,
'downloaded' => true,
'downloadlink' => true,
'icons' => true,
'last_updated' => true,
'num_ratings' => true,
'rating' => true,
'requires' => true,
'requires_php' => true,
'short_description' => true,
'tested' => true,
),
);
// should probably add some error checking here too.
$api = plugins_api( 'plugin_information', $args );
$plugins[] = $api;
}
foreach ( $plugins as $plugin ) {
if ( is_object( $plugin ) ) {
$plugin = (array) $plugin;
}
$title = wp_kses( $plugin['name'], $plugins_allowedtags );
$version = wp_kses( $plugin['version'], $plugins_allowedtags );
$name = wp_strip_all_tags( $title . ' ' . $version );
// Remove any HTML from the description.
$description = wp_strip_all_tags( $plugin['short_description'] );
$wp_version = get_bloginfo( 'version' );
$compatible_php = ( empty( $plugin['requires_php'] ) || version_compare( phpversion(), $plugin['requires_php'], '>=' ) );
$compatible_wp = ( empty( $plugin['requires'] ) || version_compare( $wp_version, $plugin['requires'], '>=' ) );
$action_links = array();
// install button.
if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
$status = install_plugin_install_status( $plugin );
switch ( $status['status'] ) {
case 'install':
if ( $status['url'] ) {
if ( $compatible_php && $compatible_wp ) {
$action_links[] = sprintf(
'<a class="install-now button jptracks is-rna" data-slug="%1$s" href="%2$s" aria-label="%3$s" data-name="%4$s" data-jptracks-name="jetpack_about_install_button" data-jptracks-prop="%4$s">%5$s</a>',
esc_attr( $plugin['slug'] ),
esc_url( $status['url'] ),
/* translators: %s: plugin name and version */
esc_attr( sprintf( __( 'Install %s now', 'jetpack' ), $name ) ),
esc_attr( $name ),
esc_html__( 'Install Now', 'jetpack' )
);
} else {
$action_links[] = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
_x( 'Cannot Install', 'plugin', 'jetpack' )
);
}
}
break;
case 'update_available':
if ( $status['url'] ) {
$action_links[] = sprintf(
'<a class="update-now button aria-button-if-js jptracks" data-plugin="%1$s" data-slug="%2$s" href="%3$s" aria-label="%4$s" data-name="%5$s" data-jptracks-name="jetpack_about_update_button" data-jptracks-prop="%5$s">%6$s</a>',
esc_attr( $status['file'] ),
esc_attr( $plugin['slug'] ),
esc_url( $status['url'] ),
/* translators: %s: plugin name and version */
esc_attr( sprintf( __( 'Update %s now', 'jetpack' ), $name ) ),
esc_attr( $name ),
__( 'Update Now', 'jetpack' )
);
}
break;
case 'latest_installed':
case 'newer_installed':
if ( is_plugin_active( $status['file'] ) ) {
$action_links[] = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
_x( 'Active', 'plugin', 'jetpack' )
);
} elseif ( current_user_can( 'activate_plugin', $status['file'] ) ) {
$button_text = __( 'Activate', 'jetpack' );
/* translators: %s: plugin name */
$button_label = _x( 'Activate %s', 'plugin', 'jetpack' );
$activate_url = add_query_arg(
array(
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
'action' => 'activate',
'plugin' => $status['file'],
),
network_admin_url( 'plugins.php' )
);
if ( is_network_admin() ) {
$button_text = __( 'Network Activate', 'jetpack' );
/* translators: %s: plugin name */
$button_label = _x( 'Network Activate %s', 'plugin', 'jetpack' );
$activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url );
}
$action_links[] = sprintf(
'<a href="%1$s" class="button activate-now" aria-label="%2$s" data-jptracks-name="jetpack_about_activate_button" data-jptracks-prop="%3$s">%4$s</a>',
esc_url( $activate_url ),
esc_attr( sprintf( $button_label, $plugin['name'] ) ),
esc_attr( $plugin['name'] ),
$button_text
);
} else {
$action_links[] = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
_x( 'Installed', 'plugin', 'jetpack' )
);
}
break;
}
}
$plugin_install = "plugin-install.php?tab=plugin-information&amp;plugin={$plugin['slug']}&amp;TB_iframe=true&amp;width=600&amp;height=550";
$details_link = is_multisite()
? network_admin_url( $plugin_install )
: admin_url( $plugin_install );
if ( ! empty( $plugin['icons']['svg'] ) ) {
$plugin_icon_url = $plugin['icons']['svg'];
} elseif ( ! empty( $plugin['icons']['2x'] ) ) {
$plugin_icon_url = $plugin['icons']['2x'];
} elseif ( ! empty( $plugin['icons']['1x'] ) ) {
$plugin_icon_url = $plugin['icons']['1x'];
} else {
$plugin_icon_url = $plugin['icons']['default'];
}
?>
<li class="jetpack-about__plugin plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
<?php
if ( ! $compatible_php || ! $compatible_wp ) {
echo '<div class="notice inline notice-error notice-alt"><p>';
if ( ! $compatible_php && ! $compatible_wp ) {
esc_html_e( 'This plugin doesn&#8217;t work with your versions of WordPress and PHP.', 'jetpack' );
if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
printf(
/* translators: 1: "Update WordPress" screen URL, 2: "Update PHP" page URL */
' ' . wp_kses( __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.', 'jetpack' ), array( 'a' => array( 'href' => true ) ) ),
esc_url( self_admin_url( 'update-core.php' ) ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation();
} elseif ( current_user_can( 'update_core' ) ) {
printf(
/* translators: %s: "Update WordPress" screen URL */
' ' . wp_kses( __( '<a href="%s">Please update WordPress</a>.', 'jetpack' ), array( 'a' => array( 'href' => true ) ) ),
esc_url( self_admin_url( 'update-core.php' ) )
);
} elseif ( current_user_can( 'update_php' ) ) {
printf(
/* translators: %s: "Update PHP" page URL */
' ' . wp_kses( __( '<a href="%s">Learn more about updating PHP</a>.', 'jetpack' ), array( 'a' => array( 'href' => true ) ) ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation();
}
} elseif ( ! $compatible_wp ) {
esc_html_e( 'This plugin doesn&#8217;t work with your version of WordPress.', 'jetpack' );
if ( current_user_can( 'update_core' ) ) {
printf(
/* translators: %s: "Update WordPress" screen URL */
' ' . wp_kses( __( '<a href="%s">Please update WordPress</a>.', 'jetpack' ), array( 'a' => array( 'href' => true ) ) ),
esc_url( self_admin_url( 'update-core.php' ) )
);
}
} elseif ( ! $compatible_php ) {
esc_html_e( 'This plugin doesn&#8217;t work with your version of PHP.', 'jetpack' );
if ( current_user_can( 'update_php' ) ) {
printf(
/* translators: %s: "Update PHP" page URL */
' ' . wp_kses( __( '<a href="%s">Learn more about updating PHP</a>.', 'jetpack' ), array( 'a' => array( 'href' => true ) ) ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation();
}
}
echo '</p></div>';
}
?>
<div class="plugin-card-top">
<div class="name column-name">
<h3>
<a href="<?php echo esc_url( $details_link ); ?>" class="jptracks thickbox open-plugin-details-modal" data-jptracks-name="jetpack_about_plugin_modal" data-jptracks-prop="<?php echo esc_attr( $plugin['slug'] ); ?>">
<?php echo esc_html( $title ); ?>
<img src="<?php echo esc_url( $plugin_icon_url ); ?>" class="plugin-icon" alt="<?php esc_attr_e( 'Plugin icon', 'jetpack' ); ?>" aria-hidden="true">
</a>
</h3>
</div>
<div class="desc column-description">
<p><?php echo esc_html( $description ); ?></p>
</div>
<div class="details-link">
<a class="jptracks thickbox open-plugin-details-modal" href="<?php echo esc_url( $details_link ); ?>" data-jptracks-name="jetpack_about_plugin_details_modal" data-jptracks-prop="<?php echo esc_attr( $plugin['slug'] ); ?>"><?php esc_html_e( 'More Details', 'jetpack' ); ?></a>
</div>
</div>
<div class="plugin-card-bottom">
<div class="meta">
<?php
wp_star_rating(
array(
'rating' => $plugin['rating'],
'type' => 'percent',
'number' => $plugin['num_ratings'],
)
);
?>
<span class="num-ratings" aria-hidden="true">(<?php echo esc_html( number_format_i18n( $plugin['num_ratings'] ) ); ?> <?php esc_html_e( 'ratings', 'jetpack' ); ?>)</span>
<div class="downloaded">
<?php
if ( $plugin['active_installs'] >= 1000000 ) {
$active_installs_millions = floor( $plugin['active_installs'] / 1000000 );
$active_installs_text = sprintf(
/* translators: number of millions of installs. */
_nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations', 'jetpack' ),
number_format_i18n( $active_installs_millions )
);
} elseif ( 0 === $plugin['active_installs'] ) {
$active_installs_text = _x( 'Less Than 10', 'Active plugin installations', 'jetpack' );
} else {
$active_installs_text = number_format_i18n( $plugin['active_installs'] ) . '+';
}
/* translators: number of active installs */
printf( esc_html__( '%s Active Installations', 'jetpack' ), esc_html( $active_installs_text ) );
?>
</div>
</div>
<div class="action-links">
<?php
if ( $action_links ) {
// The var simply collects strings that have already been sanitized.
// phpcs:ignore WordPress.Security.EscapeOutput
echo '<ul class="action-buttons"><li>' . implode( '</li><li>', $action_links ) . '</li></ul>';
}
?>
</div>
</div>
</li>
<?php
}
}
/**
* Fetch anonymous data about A12s from wpcom: total count, number of countries, languages spoken.
*
* @since 7.4
*
* @return array $data
*/
private function fetch_a8c_data() {
$data = get_transient( 'jetpack_a8c_data' );
if ( false === $data ) {
$data = json_decode(
wp_remote_retrieve_body(
wp_remote_get( 'https://public-api.wordpress.com/wpcom/v2/jetpack-about' )
),
true
);
if ( ! empty( $data ) && is_array( $data ) ) {
set_transient( 'jetpack_a8c_data', $data, WEEK_IN_SECONDS );
} else {
// Fallback if everything fails.
$data = array(
'a12s' => 888,
'countries' => 69,
'languages' => 83,
'featured_plugins' => array(
'woocommerce',
'wp-super-cache',
'wp-job-manager',
'co-authors-plus',
),
);
}
}
return $data;
}
/**
* Compile and display a list of avatars for A12s that gave their permission.
*
* @since 7.3
*/
public function display_gravatars() {
$hashes = array(
'https://1.gravatar.com/avatar/d2ab03dbab0c97740be75f290a2e3190',
'https://2.gravatar.com/avatar/b0b357b291ac72bc7da81b4d74430fe6',
'https://2.gravatar.com/avatar/9e149207a0e0818abed0edbb1fb2d0bf',
'https://2.gravatar.com/avatar/9f376366854d750124dffe057dda99c9',
'https://1.gravatar.com/avatar/1c75d26ad0d38624f02b15accc1f20cd',
'https://1.gravatar.com/avatar/c510e69d83c7d10be4df64feeff4e46a',
'https://0.gravatar.com/avatar/88ec0dcadea38adf5f30a17e54e9b248',
'https://1.gravatar.com/avatar/1ec3571e0201a990ceca5e365e780efa',
'https://0.gravatar.com/avatar/0619d4de8aef78c81b2194ff1d164d85',
'https://0.gravatar.com/avatar/7fdcad31a04def0ab9583af475c9036c',
'https://0.gravatar.com/avatar/b3618d70c63bbc5cc7caee0beded5ff0',
'https://1.gravatar.com/avatar/4d346581a3340e32cf93703c9ce46bd4',
'https://2.gravatar.com/avatar/9c2f6b95a00dfccfadc6a912a2b859ba',
'https://1.gravatar.com/avatar/1a33e7a69df4f675fcd799edca088ac2',
'https://2.gravatar.com/avatar/d5dc443845c134f365519568d5d80e62',
'https://0.gravatar.com/avatar/c0ccdd53794779bcc07fcae7b79c4d80',
);
$output = '';
foreach ( $hashes as $hash ) {
$output .= '<li><img src="' . esc_url( $hash ) . '?s=150"></li>' . "\n";
}
echo wp_kses(
$output,
array(
'li' => true,
'img' => array(
'src' => true,
),
)
);
}
}
@@ -0,0 +1,515 @@
<?php
/**
* A utility class that generates the initial state for Redux in wp-admin.
* Modularized from `class.jetpack-react-page.php`.
*
* @package automattic/jetpack
*/
use Automattic\Jetpack\Blaze;
use Automattic\Jetpack\Boost_Speed_Score\Speed_Score_History;
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Connection\Plugin_Storage as Connection_Plugin_Storage;
use Automattic\Jetpack\Connection\REST_Connector;
use Automattic\Jetpack\Constants;
use Automattic\Jetpack\Current_Plan as Jetpack_Plan;
use Automattic\Jetpack\Device_Detection\User_Agent_Info;
use Automattic\Jetpack\Identity_Crisis;
use Automattic\Jetpack\Image_CDN\Image_CDN_Core;
use Automattic\Jetpack\Image_CDN\Image_CDN_Image;
use Automattic\Jetpack\IP\Utils as IP_Utils;
use Automattic\Jetpack\Licensing;
use Automattic\Jetpack\Licensing\Endpoints as Licensing_Endpoints;
use Automattic\Jetpack\My_Jetpack\Initializer as My_Jetpack_Initializer;
use Automattic\Jetpack\My_Jetpack\Jetpack_Manage;
use Automattic\Jetpack\Partner;
use Automattic\Jetpack\Partner_Coupon as Jetpack_Partner_Coupon;
use Automattic\Jetpack\Stats\Options as Stats_Options;
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Status\Host;
/**
* Responsible for populating the initial Redux state.
*/
class Jetpack_Redux_State_Helper {
/**
* Generate minimal state for React to fetch its own data asynchronously after load
* This can improve user experience, reducing time spent on server requests before serving the page
* e.g. used by React Disconnect Dialog on plugins page where the full initial state is not needed
*/
public static function get_minimal_state() {
return array(
'WP_API_root' => esc_url_raw( rest_url() ),
'WP_API_nonce' => wp_create_nonce( 'wp_rest' ),
);
}
/**
* Generate the initial state array to be used by the Redux store.
*/
public static function get_initial_state() {
global $is_safari;
// Load API endpoint base classes and endpoints for getting the module list fed into the JS Admin Page.
require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/class.jetpack-core-api-xmlrpc-consumer-endpoint.php';
require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php';
require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/class.jetpack-core-api-site-endpoints.php';
$module_list_endpoint = new Jetpack_Core_API_Module_List_Endpoint();
$modules = $module_list_endpoint->get_modules();
// Preparing translated fields for JSON encoding by transforming all HTML entities to
// respective characters.
foreach ( $modules as $slug => $data ) {
$modules[ $slug ]['name'] = html_entity_decode( $data['name'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );
$modules[ $slug ]['description'] = html_entity_decode( $data['description'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );
$modules[ $slug ]['short_description'] = html_entity_decode( $data['short_description'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );
$modules[ $slug ]['long_description'] = html_entity_decode( $data['long_description'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );
}
// "mock" a block module in order to get it searchable in the settings.
$modules['blocks']['module'] = 'blocks';
$modules['blocks']['additional_search_queries'] = esc_html_x( 'blocks, block, gutenberg', 'Search terms', 'jetpack' );
// "mock" an Earn module in order to get it searchable in the settings.
$modules['earn']['module'] = 'earn';
$modules['earn']['additional_search_queries'] = esc_html_x( 'earn, paypal, stripe, payments, pay', 'Search terms', 'jetpack' );
// Collecting roles that can view site stats.
$stats_roles = array();
$enabled_roles = Stats_Options::get_option( 'roles' );
if ( ! function_exists( 'get_editable_roles' ) ) {
require_once ABSPATH . 'wp-admin/includes/user.php';
}
foreach ( get_editable_roles() as $slug => $role ) {
$stats_roles[ $slug ] = array(
'name' => translate_user_role( $role['name'] ),
'canView' => is_array( $enabled_roles ) ? in_array( $slug, $enabled_roles, true ) : false,
);
}
// Get information about current theme.
$current_theme = wp_get_theme();
// Get all themes that Infinite Scroll provides support for natively.
$inf_scr_support_themes = array();
foreach ( Jetpack::glob_php( JETPACK__PLUGIN_DIR . 'modules/infinite-scroll/themes' ) as $path ) {
if ( is_readable( $path ) ) {
$inf_scr_support_themes[] = basename( $path, '.php' );
}
}
// Get last post, to build the link to Customizer in the Related Posts module.
$last_post = get_posts( array( 'posts_per_page' => 1 ) );
$last_post = isset( $last_post[0] ) && $last_post[0] instanceof WP_Post
? get_permalink( $last_post[0]->ID )
: get_home_url();
$current_user_data = jetpack_current_user_data();
/**
* Adds information to the `connectionStatus` API field that is unique to the Jetpack React dashboard.
*/
$connection_status = array(
'isInIdentityCrisis' => Identity_Crisis::validate_sync_error_idc_option(),
'sandboxDomain' => JETPACK__SANDBOX_DOMAIN,
/**
* Filter to add connection errors
* Format: array( array( 'code' => '...', 'message' => '...', 'action' => '...' ), ... )
*
* @since 8.7.0
*
* @param array $errors Connection errors.
*/
'errors' => apply_filters( 'react_connection_errors_initial_state', array() ),
);
$connection_status = array_merge( REST_Connector::connection_status( false ), $connection_status );
$host = new Host();
$speed_score_history = new Speed_Score_History( wp_parse_url( get_site_url(), PHP_URL_HOST ) );
$block_availability = Jetpack_Gutenberg::get_cached_availability();
return array(
'WP_API_root' => esc_url_raw( rest_url() ),
'WP_API_nonce' => wp_create_nonce( 'wp_rest' ),
'registrationNonce' => wp_create_nonce( 'jetpack-registration-nonce' ),
'purchaseToken' => self::get_purchase_token(),
'partnerCoupon' => Jetpack_Partner_Coupon::get_coupon(),
'pluginBaseUrl' => plugins_url( '', JETPACK__PLUGIN_FILE ),
'connectionStatus' => $connection_status,
'connectedPlugins' => Connection_Plugin_Storage::get_all(),
'connectUrl' => false == $current_user_data['isConnected'] // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
? Jetpack::init()->build_connect_url( true, false, false )
: '',
'dismissedNotices' => self::get_dismissed_jetpack_notices(),
'isDevVersion' => Jetpack::is_development_version(),
'currentVersion' => JETPACK__VERSION,
'is_gutenberg_available' => true,
'getModules' => $modules,
'rawUrl' => ( new Status() )->get_site_suffix(),
'adminUrl' => esc_url( admin_url() ),
'siteTitle' => (string) htmlspecialchars_decode( get_option( 'blogname' ), ENT_QUOTES ),
'stats' => array(
// data is populated asynchronously on page load.
'data' => array(
'general' => false,
'day' => false,
'week' => false,
'month' => false,
),
'roles' => $stats_roles,
),
'aff' => Partner::init()->get_partner_code( Partner::AFFILIATE_CODE ),
'partnerSubsidiaryId' => Partner::init()->get_partner_code( Partner::SUBSIDIARY_CODE ),
'settings' => self::get_flattened_settings(),
'userData' => array(
'currentUser' => $current_user_data,
),
'siteData' => array(
'blog_id' => Jetpack_Options::get_option( 'id', 0 ),
'icon' => has_site_icon()
? apply_filters( 'jetpack_photon_url', get_site_icon_url(), array( 'w' => 64 ) )
: '',
'siteVisibleToSearchEngines' => '1' == get_option( 'blog_public' ), // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
/**
* Whether promotions are visible or not.
*
* @since 4.8.0
*
* @param bool $are_promotions_active Status of promotions visibility. True by default.
*/
'showPromotions' => apply_filters( 'jetpack_show_promotions', true ),
'isAtomicSite' => $host->is_woa_site(),
'isWoASite' => $host->is_woa_site(),
'isAtomicPlatform' => $host->is_atomic_platform(),
'plan' => Jetpack_Plan::get(),
'showBackups' => Jetpack::show_backups_ui(),
'showRecommendations' => Jetpack_Recommendations::is_enabled(),
/** This filter is documented in my-jetpack/src/class-initializer.php */
'showMyJetpack' => My_Jetpack_Initializer::should_initialize(),
'isMultisite' => is_multisite(),
'dateFormat' => get_option( 'date_format' ),
'latestBoostSpeedScores' => $speed_score_history->latest(),
'isSharingBlockAvailable' => (bool) isset( $block_availability['sharing-buttons'] )
&& $block_availability['sharing-buttons']['available'],
),
'themeData' => array(
'name' => $current_theme->get( 'Name' ),
'stylesheet' => $current_theme->get_stylesheet(),
'hasUpdate' => (bool) get_theme_update_available( $current_theme ),
'isBlockTheme' => (bool) $current_theme->is_block_theme(),
'support' => array(
'infinite-scroll' => current_theme_supports( 'infinite-scroll' ) || in_array( $current_theme->get_stylesheet(), $inf_scr_support_themes, true ),
'widgets' => current_theme_supports( 'widgets' ),
'webfonts' => wp_theme_has_theme_json()
&& ( function_exists( 'wp_register_webfont_provider' ) || function_exists( 'wp_register_webfonts' ) ),
),
),
'jetpackStateNotices' => array(
'messageCode' => Jetpack::state( 'message' ),
'errorCode' => Jetpack::state( 'error' ),
'errorDescription' => Jetpack::state( 'error_description' ),
'messageContent' => Jetpack::state( 'display_update_modal' ) ? self::get_update_modal_data() : null,
),
'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(),
'currentIp' => IP_Utils::get_ip(),
'lastPostUrl' => esc_url( $last_post ),
'externalServicesConnectUrls' => self::get_external_services_connect_urls(),
'calypsoEnv' => ( new Host() )->get_calypso_env(),
'products' => Jetpack::get_products_for_purchase(),
'recommendationsStep' => Jetpack_Core_Json_Api_Endpoints::get_recommendations_step()['step'],
'isSafari' => $is_safari || User_Agent_Info::is_opera_desktop(), // @todo Rename isSafari everywhere.
'doNotUseConnectionIframe' => Constants::is_true( 'JETPACK_SHOULD_NOT_USE_CONNECTION_IFRAME' ),
'licensing' => array(
'error' => Licensing::instance()->last_error(),
'showLicensingUi' => Licensing::instance()->is_licensing_input_enabled(),
'userCounts' => Licensing_Endpoints::get_user_license_counts(),
'activationNoticeDismiss' => Licensing::instance()->get_license_activation_notice_dismiss(),
),
'jetpackManage' => array(
'isEnabled' => Jetpack_Manage::could_use_jp_manage(),
'isAgencyAccount' => Jetpack_Manage::is_agency_account(),
),
'hasSeenWCConnectionModal' => Jetpack_Options::get_option( 'has_seen_wc_connection_modal', false ),
'newRecommendations' => Jetpack_Recommendations::get_new_conditional_recommendations(),
// Check if WooCommerce plugin is active (based on https://docs.woocommerce.com/document/create-a-plugin/).
'isWooCommerceActive' => in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', Jetpack::get_active_plugins() ), true ),
'useMyJetpackLicensingUI' => My_Jetpack_Initializer::is_licensing_ui_enabled(),
'isOdysseyStatsEnabled' => Stats_Options::get_option( 'enable_odyssey_stats' ),
'shouldInitializeBlaze' => Blaze::should_initialize(),
'isBlazeDashboardEnabled' => Blaze::is_dashboard_enabled(),
'socialInitialState' => self::get_publicize_initial_state(),
'isSubscriptionSiteEnabled' => apply_filters( 'jetpack_subscription_site_enabled', false ),
'newsletterDateExample' => gmdate( get_option( 'date_format' ), time() ),
'subscriptionSiteEditSupported' => $current_theme->is_block_theme(),
);
}
/**
* Gets the initial state for the Publicize module.
*
* @return array|null
*/
public static function get_publicize_initial_state() {
$jetpack_social_settings = new Automattic\Jetpack\Publicize\Jetpack_Social_Settings\Settings();
$initial_state = $jetpack_social_settings->get_initial_state();
if ( empty( $initial_state ) ) {
return null;
}
return $initial_state;
}
/**
* Gets array of any Jetpack notices that have been dismissed.
*
* @return mixed|void
*/
public static function get_dismissed_jetpack_notices() {
$jetpack_dismissed_notices = get_option( 'jetpack_dismissed_notices', array() );
/**
* Array of notices that have been dismissed.
*
* @param array $jetpack_dismissed_notices If empty, will not show any Jetpack notices.
*/
$dismissed_notices = apply_filters( 'jetpack_dismissed_notices', $jetpack_dismissed_notices );
return $dismissed_notices;
}
/**
* Returns an array of modules and settings both as first class members of the object.
*
* @return array flattened settings with modules.
*/
public static function get_flattened_settings() {
$core_api_endpoint = new Jetpack_Core_API_Data();
$settings = $core_api_endpoint->get_all_options();
return $settings->data;
}
/**
* Returns the release post content and image data as an associative array.
* This data is used to create the update modal.
*/
public static function get_update_modal_data() {
$post_data = self::get_release_post_data();
if ( ! isset( $post_data['posts'][0] ) ) {
return;
}
$post = $post_data['posts'][0];
if ( empty( $post['content'] ) ) {
return;
}
// This allows us to embed videopress videos into the release post.
add_filter( 'wp_kses_allowed_html', array( __CLASS__, 'allow_post_embed_iframe' ), 10, 2 );
$content = wp_kses_post( $post['content'] );
remove_filter( 'wp_kses_allowed_html', array( __CLASS__, 'allow_post_embed_iframe' ), 10 );
$post_title = isset( $post['title'] ) ? $post['title'] : null;
$title = wp_kses( $post_title, array() );
$post_thumbnail = isset( $post['post_thumbnail'] ) ? $post['post_thumbnail'] : null;
if ( ! empty( $post_thumbnail ) ) {
$photon_image = new Image_CDN_Image(
array(
'file' => Image_CDN_Core::cdn_url( $post_thumbnail['URL'] ),
'width' => $post_thumbnail['width'],
'height' => $post_thumbnail['height'],
),
$post_thumbnail['mime_type']
);
$photon_image->resize(
array(
'width' => 600,
'height' => null,
'crop' => false,
)
);
$post_thumbnail_url = $photon_image->get_raw_filename();
} else {
$post_thumbnail_url = null;
}
$post_array = array(
'release_post_content' => $content,
'release_post_featured_image' => $post_thumbnail_url,
'release_post_title' => $title,
);
return $post_array;
}
/**
* Temporarily allow post content to contain iframes, e.g. for videopress.
*
* @param string $tags The tags.
* @param string $context The context.
*/
public static function allow_post_embed_iframe( $tags, $context ) {
if ( 'post' === $context ) {
$tags['iframe'] = array(
'src' => true,
'height' => true,
'width' => true,
'frameborder' => true,
'allowfullscreen' => true,
);
}
return $tags;
}
/**
* Obtains the release post from the Jetpack release post blog. A release post will be displayed in the
* update modal when a post has a tag equal to the Jetpack version number.
*
* The response parameters for the post array can be found here:
* https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/posts/%24post_ID/#apidoc-response
*
* @return array|null Returns an associative array containing the release post data at index ['posts'][0].
* Returns null if the release post data is not available.
*/
public static function get_release_post_data() {
if ( Constants::is_defined( 'TESTING_IN_JETPACK' ) && Constants::get_constant( 'TESTING_IN_JETPACK' ) ) {
return null;
}
$release_post_src = add_query_arg(
array(
'order_by' => 'date',
'tag' => JETPACK__VERSION,
'number' => '1',
),
'https://public-api.wordpress.com/rest/v1/sites/' . JETPACK__RELEASE_POST_BLOG_SLUG . '/posts'
);
$response = wp_remote_get( $release_post_src );
if ( ! is_array( $response ) ) {
return null;
}
return json_decode( wp_remote_retrieve_body( $response ), true );
}
/**
* Get external services connect URLs.
*/
public static function get_external_services_connect_urls() {
$connect_urls = array();
require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-keyring-service-helper.php';
// phpcs:disable
foreach ( Jetpack_Keyring_Service_Helper::SERVICES as $service_name => $service_info ) {
// phpcs:enable
$connect_urls[ $service_name ] = Jetpack_Keyring_Service_Helper::connect_url( $service_name, $service_info['for'] );
}
return $connect_urls;
}
/**
* Gets a purchase token that is used for Jetpack logged out visitor checkout.
* The purchase token should be appended to all CTA url's that lead to checkout.
*
* @since 9.8.0
* @return string|boolean
*/
public static function get_purchase_token() {
if ( ! Jetpack::current_user_can_purchase() ) {
return false;
}
$purchase_token = Jetpack_Options::get_option( 'purchase_token', false );
if ( $purchase_token ) {
return $purchase_token;
}
// If the purchase token is not saved in the options table yet, then add it.
Jetpack_Options::update_option( 'purchase_token', self::generate_purchase_token(), true );
return Jetpack_Options::get_option( 'purchase_token', false );
}
/**
* Generates a purchase token that is used for Jetpack logged out visitor checkout.
*
* @since 9.8.0
* @return string
*/
public static function generate_purchase_token() {
return wp_generate_password( 12, false );
}
}
// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move these functions to some other file.
/**
* Gather data about the current user.
*
* @since 4.1.0
*
* @return array
*/
function jetpack_current_user_data() {
$jetpack_connection = new Connection_Manager( 'jetpack' );
$current_user = wp_get_current_user();
$is_user_connected = $jetpack_connection->is_user_connected( $current_user->ID );
$is_master_user = $is_user_connected && (int) $current_user->ID && (int) Jetpack_Options::get_option( 'master_user' ) === (int) $current_user->ID;
$dotcom_data = $jetpack_connection->get_connected_user_data();
// Add connected user gravatar to the returned dotcom_data.
// Probably we shouldn't do this when $dotcom_data is false, but we have been since 2016 so
// clients probably expect that by now.
if ( false === $dotcom_data ) {
$dotcom_data = array();
}
$dotcom_data['avatar'] = ( ! empty( $dotcom_data['email'] ) ?
get_avatar_url(
$dotcom_data['email'],
array(
'size' => 64,
'default' => 'mysteryman',
)
)
: false );
$current_user_data = array(
'isConnected' => $is_user_connected,
'isMaster' => $is_master_user,
'username' => $current_user->user_login,
'displayName' => $current_user->display_name,
'email' => $current_user->user_email,
'id' => $current_user->ID,
'wpcomUser' => $dotcom_data,
'gravatar' => get_avatar_url( $current_user->ID ),
'permissions' => array(
'admin_page' => current_user_can( 'jetpack_admin_page' ),
'connect' => current_user_can( 'jetpack_connect' ),
'connect_user' => current_user_can( 'jetpack_connect_user' ),
'disconnect' => current_user_can( 'jetpack_disconnect' ),
'manage_modules' => current_user_can( 'jetpack_manage_modules' ),
'network_admin' => current_user_can( 'jetpack_network_admin_page' ),
'network_sites_page' => current_user_can( 'jetpack_network_sites_page' ),
'edit_posts' => current_user_can( 'edit_posts' ),
'publish_posts' => current_user_can( 'publish_posts' ),
'manage_options' => current_user_can( 'manage_options' ),
'view_stats' => current_user_can( 'view_stats' ),
'manage_plugins' => current_user_can( 'install_plugins' )
&& current_user_can( 'activate_plugins' )
&& current_user_can( 'update_plugins' )
&& current_user_can( 'delete_plugins' ),
),
);
return $current_user_data;
}
@@ -0,0 +1,402 @@
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
* Main class file for Jetpack Admin pages.
*
* @package automattic/jetpack
*/
use Automattic\Jetpack\Current_Plan as Jetpack_Plan;
use Automattic\Jetpack\Identity_Crisis;
use Automattic\Jetpack\Redirect;
use Automattic\Jetpack\Status;
/**
* Shared logic between Jetpack admin pages.
*/
abstract class Jetpack_Admin_Page {
/**
* Add page specific actions given the page hook.
*
* @param string $hook Hook of current page.
*/
abstract public function add_page_actions( $hook );
/**
* Create a menu item for the page and returns the hook.
*
* @return string|false Return value from WordPress's `add_menu_page()` or `add_submenu_page()`.
*/
abstract public function get_page_hook();
/**
* Enqueue and localize page specific scripts.
*/
abstract public function page_admin_scripts();
/**
* Render page specific HTML
*/
abstract public function page_render();
/**
* Function called after admin_styles to load any additional needed styles.
*
* @since 4.3.0
*/
public function additional_styles() {}
/**
* Add common page actions and attach page-specific actions.
*/
public function add_actions() {
$is_offline_mode = ( new Status() )->is_offline_mode();
// If user is not an admin and site is in Offline Mode or not connected yet then don't do anything.
if ( ! current_user_can( 'manage_options' ) && ( $is_offline_mode || ! Jetpack::is_connection_ready() ) ) {
return;
}
// Is Jetpack not connected and not offline?
// True means that Jetpack is NOT connected and NOT in offline mode.
// If Jetpack is connected OR in offline mode, this will be false.
$connectable = ! Jetpack::is_connection_ready() && ! $is_offline_mode;
// Don't add in the modules page unless modules are available!
if ( $this->dont_show_if_not_active && $connectable ) {
return;
}
// Initialize menu item for the page in the admin.
$hook = $this->get_page_hook();
// Attach hooks common to all Jetpack admin pages based on the created hook.
add_action( "load-$hook", array( $this, 'admin_page_load' ) );
add_action( "admin_print_styles-$hook", array( $this, 'admin_styles' ) );
add_action( "admin_print_scripts-$hook", array( $this, 'admin_scripts' ) );
add_action( "admin_print_styles-$hook", array( $this, 'additional_styles' ) );
// Check if the site plan changed and deactivate modules accordingly.
add_action( 'current_screen', array( $this, 'check_plan_deactivate_modules' ) );
// Attach page specific actions in addition to the above.
$this->add_page_actions( $hook );
}
/**
* Render the page with a common top and bottom part, and page specific content.
*/
public function render() {
/** This action is documented in class.jetpack.php */
do_action( 'jetpack_initialize_tracking' );
// We're in an IDC: we need a decision made before we show the UI again.
if ( $this->block_page_rendering_for_idc() ) {
return;
}
// Check if we are looking at the main dashboard.
if ( isset( $_GET['page'] ) && 'jetpack' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- View logic.
$this->page_render();
return;
}
$args = array();
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['page'] ) && 'jetpack_modules' === $_GET['page'] ) {
$args['is-wide'] = true;
}
self::wrap_ui( array( $this, 'page_render' ), $args );
}
/**
* Call the existing admin page events.
*/
public function admin_page_load() {
Jetpack::init()->admin_page_load();
}
/**
* Add page specific scripts and jetpack stats for all menu pages.
*/
public function admin_scripts() {
$this->page_admin_scripts(); // Delegate to inheriting class.
add_action( 'admin_footer', array( Jetpack::init(), 'do_stats' ) );
}
/**
* Enqueue the Jetpack admin stylesheet.
*/
public function admin_styles() {
$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
wp_enqueue_style( 'jetpack-admin', plugins_url( "css/jetpack-admin{$min}.css", JETPACK__PLUGIN_FILE ), array( 'genericons', 'jetpack-connection' ), JETPACK__VERSION . '-20121016' );
wp_style_add_data( 'jetpack-admin', 'rtl', 'replace' );
wp_style_add_data( 'jetpack-admin', 'suffix', $min );
}
/**
* Checks if REST API is enabled.
*
* @since 4.4.2
*
* @return bool
*/
public function is_rest_api_enabled() {
return /** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */
apply_filters( 'rest_enabled', true ) &&
/** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */
apply_filters( 'rest_authentication_errors', true );
}
/**
* Checks the site plan and deactivates modules that were active but are no longer included in the plan.
*
* @since 4.4.0
*
* @param WP_Screen $page Current WP_Screen object.
*
* @return array
*/
public function check_plan_deactivate_modules( $page ) {
if (
( new Status() )->is_offline_mode()
|| ! in_array(
$page->base,
array(
'toplevel_page_jetpack',
'admin_page_jetpack_modules',
'jetpack_page_vaultpress',
'jetpack_page_stats',
'jetpack_page_akismet-key-config',
),
true
)
) {
return false;
}
$current = Jetpack_Plan::get();
$to_deactivate = array();
if ( isset( $current['product_slug'] ) ) {
$active = Jetpack::get_active_modules();
switch ( $current['product_slug'] ) {
case 'jetpack_free':
case 'jetpack_personal':
case 'jetpack_personal_monthly':
$to_deactivate = array( 'google-analytics', 'wordads', 'search' );
break;
case 'jetpack_premium':
case 'jetpack_premium_monthly':
$to_deactivate = array( 'google-analytics', 'search' );
break;
}
$to_deactivate = array_intersect( $active, $to_deactivate );
$to_leave_enabled = array();
foreach ( $to_deactivate as $feature ) {
if ( Jetpack_Plan::supports( $feature ) ) {
$to_leave_enabled [] = $feature;
}
}
$to_deactivate = array_diff( $to_deactivate, $to_leave_enabled );
if ( ! empty( $to_deactivate ) ) {
Jetpack::update_active_modules( array_filter( array_diff( $active, $to_deactivate ) ) );
}
}
return array(
'current' => $current,
'deactivate' => $to_deactivate,
);
}
/**
* Enqueue inline wrapper styles for the main container.
*/
public static function load_wrapper_styles() {
$rtl = is_rtl() ? '.rtl' : '';
wp_enqueue_style( 'dops-css', plugins_url( "_inc/build/admin{$rtl}.css", JETPACK__PLUGIN_FILE ), array(), JETPACK__VERSION );
wp_enqueue_style( 'components-css', plugins_url( "_inc/build/style.min{$rtl}.css", JETPACK__PLUGIN_FILE ), array( 'wp-components' ), JETPACK__VERSION );
}
/**
* Build header, content, and footer for admin page.
*
* @param callable $callback Callback to produce the content of the page. The callback is responsible for any needed escaping.
* @param array $args Options for the wrapping. Also passed to the `jetpack_admin_pages_wrap_ui_after_callback` action.
* - is-wide: (bool) Set the "is-wide" class on the wrapper div, which increases the max width. Default false.
* - show-nav: (bool) Whether to show the navigation bar at the top of the page. Default true.
*/
public static function wrap_ui( $callback, $args = array() ) {
$defaults = array(
'is-wide' => false,
'show-nav' => true,
);
$args = wp_parse_args( $args, $defaults );
// Is Jetpack not connected and not offline?
// True means that Jetpack is NOT connected and NOT in offline mode.
// If Jetpack is connected OR in offline mode, this will be false.
$connectable = ! Jetpack::is_connection_ready() && ! ( new Status() )->is_offline_mode();
$jetpack_admin_url = admin_url( 'admin.php?page=jetpack' );
$jetpack_about_url = ! $connectable
? admin_url( 'admin.php?page=jetpack_about' )
: Redirect::get_url( 'jetpack' );
$jetpack_privacy_url = ! $connectable
? $jetpack_admin_url . '#/privacy'
: Redirect::get_url( 'a8c-privacy' );
$external_link_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" class="jp-footer__menu-item__icon" aria-hidden="true" focusable="false"><path d="M18.2 17c0 .7-.6 1.2-1.2 1.2H7c-.7 0-1.2-.6-1.2-1.2V7c0-.7.6-1.2 1.2-1.2h3.2V4.2H7C5.5 4.2 4.2 5.5 4.2 7v10c0 1.5 1.2 2.8 2.8 2.8h10c1.5 0 2.8-1.2 2.8-2.8v-3.6h-1.5V17zM14.9 3v1.5h3.7l-6.4 6.4 1.1 1.1 6.4-6.4v3.7h1.5V3h-6.3z"></path></svg>';
?>
<div id="jp-plugin-container" class="
<?php
if ( $args['is-wide'] ) {
echo 'is-wide'; }
?>
">
<div class="jp-masthead jp-masthead-middle">
<div class="jp-masthead__inside-container">
<div class="jp-masthead__logo-container">
<a class="jp-masthead__logo-link" href="<?php echo esc_url( $jetpack_admin_url ); ?>">
<svg class="jetpack-logo__masthead" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" height="40" viewBox="0 0 118 32"><path fill="#069e08" d="M16,0C7.2,0,0,7.2,0,16s7.2,16,16,16s16-7.2,16-16S24.8,0,16,0z M15,19H7l8-16V19z M17,29V13h8L17,29z"></path><path d="M41.3,26.6c-0.5-0.7-0.9-1.4-1.3-2.1c2.3-1.4,3-2.5,3-4.6V8h-3V6h6v13.4C46,22.8,45,24.8,41.3,26.6z"></path><path d="M65,18.4c0,1.1,0.8,1.3,1.4,1.3c0.5,0,2-0.2,2.6-0.4v2.1c-0.9,0.3-2.5,0.5-3.7,0.5c-1.5,0-3.2-0.5-3.2-3.1V12H60v-2h2.1V7.1 H65V10h4v2h-4V18.4z"></path><path d="M71,10h3v1.3c1.1-0.8,1.9-1.3,3.3-1.3c2.5,0,4.5,1.8,4.5,5.6s-2.2,6.3-5.8,6.3c-0.9,0-1.3-0.1-2-0.3V28h-3V10z M76.5,12.3 c-0.8,0-1.6,0.4-2.5,1.2v5.9c0.6,0.1,0.9,0.2,1.8,0.2c2,0,3.2-1.3,3.2-3.9C79,13.4,78.1,12.3,76.5,12.3z"></path><path d="M93,22h-3v-1.5c-0.9,0.7-1.9,1.5-3.5,1.5c-1.5,0-3.1-1.1-3.1-3.2c0-2.9,2.5-3.4,4.2-3.7l2.4-0.3v-0.3c0-1.5-0.5-2.3-2-2.3 c-0.7,0-2.3,0.5-3.7,1.1L84,11c1.2-0.4,3-1,4.4-1c2.7,0,4.6,1.4,4.6,4.7L93,22z M90,16.4l-2.2,0.4c-0.7,0.1-1.4,0.5-1.4,1.6 c0,0.9,0.5,1.4,1.3,1.4s1.5-0.5,2.3-1V16.4z"></path><path d="M104.5,21.3c-1.1,0.4-2.2,0.6-3.5,0.6c-4.2,0-5.9-2.4-5.9-5.9c0-3.7,2.3-6,6.1-6c1.4,0,2.3,0.2,3.2,0.5V13 c-0.8-0.3-2-0.6-3.2-0.6c-1.7,0-3.2,0.9-3.2,3.6c0,2.9,1.5,3.8,3.3,3.8c0.9,0,1.9-0.2,3.2-0.7V21.3z"></path><path d="M110,15.2c0.2-0.3,0.2-0.8,3.8-5.2h3.7l-4.6,5.7l5,6.3h-3.7l-4.2-5.8V22h-3V6h3V15.2z"></path><path d="M58.5,21.3c-1.5,0.5-2.7,0.6-4.2,0.6c-3.6,0-5.8-1.8-5.8-6c0-3.1,1.9-5.9,5.5-5.9s4.9,2.5,4.9,4.9c0,0.8,0,1.5-0.1,2h-7.3 c0.1,2.5,1.5,2.8,3.6,2.8c1.1,0,2.2-0.3,3.4-0.7C58.5,19,58.5,21.3,58.5,21.3z M56,15c0-1.4-0.5-2.9-2-2.9c-1.4,0-2.3,1.3-2.4,2.9 C51.6,15,56,15,56,15z"></path></svg>
</a>
</div>
<?php
if ( $args['show-nav'] ) :
?>
<div class="jp-masthead__nav">
<?php
if ( is_network_admin() ) {
$current_screen = get_current_screen();
$highlight_current_sites = ( 'toplevel_page_jetpack-network' === $current_screen->id ? 'is-primary' : '' );
$highlight_current_settings = ( 'jetpack_page_jetpack-settings-network' === $current_screen->id ? 'is-primary' : '' );
?>
<span class="dops-button-group">
<?php
if ( current_user_can( 'jetpack_network_sites_page' ) ) {
?>
<a href="<?php echo esc_url( network_admin_url( 'admin.php?page=jetpack' ) ); ?>" type="button" class="<?php echo esc_attr( $highlight_current_sites ); ?> dops-button is-compact" title="<?php esc_html_e( "Manage your network's Jetpack Sites.", 'jetpack' ); ?>"><?php echo esc_html_x( 'Sites', 'Navigation item', 'jetpack' ); ?></a>
<?php
} if ( current_user_can( 'jetpack_network_settings_page' ) ) {
?>
<a href="<?php echo esc_url( network_admin_url( 'admin.php?page=jetpack-settings' ) ); ?>" type="button" class="<?php echo esc_attr( $highlight_current_settings ); ?> dops-button is-compact" title="<?php esc_html_e( "Manage your network's Jetpack Sites.", 'jetpack' ); ?>"><?php echo esc_html_x( 'Network Settings', 'Navigation item', 'jetpack' ); ?></a>
<?php
}
?>
</span>
<?php } else { ?>
<span class="dops-button-group">
<a href="<?php echo esc_url( $jetpack_admin_url ); ?>" type="button" class="dops-button is-compact"><?php esc_html_e( 'Dashboard', 'jetpack' ); ?></a>
<?php
if ( current_user_can( 'jetpack_manage_modules' ) ) {
?>
<a href="<?php echo esc_url( $jetpack_admin_url . '#/settings' ); ?>" type="button" class="dops-button is-compact"><?php esc_html_e( 'Settings', 'jetpack' ); ?></a>
<?php
}
?>
</span>
<?php } ?>
</div>
<?php endif; ?>
</div>
</div>
<div class="wrap"><div id="jp-admin-notices" aria-live="polite"></div></div>
<!-- START OF CALLBACK -->
<?php
ob_start();
call_user_func( $callback );
$callback_ui = ob_get_contents();
ob_end_clean();
echo $callback_ui;// phpcs:ignore WordPress.Security.EscapeOutput -- Callback is responsible for any needed escaping.
?>
<!-- END OF CALLBACK -->
<div id="jp-stats-report-bottom">
<div class="wrap">
<?php
/**
* Fires at the bottom of the Jetpack admin page template, after the dynamic content section.
*
* @since 10.0.0
*
* @param string $callback The callback sent to the Jetpack_Admin_Page::wrap_ui method.
* @param array $args The arguments sent to the Jetpack_Admin_Page::wrap_ui method.
*/
do_action( 'jetpack_admin_pages_wrap_ui_after_callback', $callback, $args );
?>
</div>
</div>
<div class="jp-footer jp-footer--static">
<div class="jp-footer__container">
<div class="jp-footer__logo">
<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 32 32" class="jetpack-logo jp-footer__jetpack-symbol" aria-labelledby="jetpack-logo-title" height="16" aria-label="<?php esc_html_e( 'Jetpack logo', 'jetpack' ); ?>">
<desc id="jetpack-logo-title">
<?php esc_html_e( 'Jetpack Logo', 'jetpack' ); ?>
</desc>
<path fill="#000" d="M16,0C7.2,0,0,7.2,0,16s7.2,16,16,16s16-7.2,16-16S24.8,0,16,0z M15,19H7l8-16V19z M17,29V13h8L17,29z"></path>
</svg>
<span class="jp-footer__module-name">
<a href="<?php echo esc_url( Redirect::get_url( 'jetpack' ) ); ?>" target="_blank" rel="noopener noreferrer" aria-label="Jetpack 12.2-a.0">
<?php esc_html_e( 'Jetpack', 'jetpack' ); ?>
</a>
</span>
</div>
<div class="jp-footer__menu">
<a href="<?php echo esc_url( $jetpack_about_url ); ?>" title="<?php esc_attr__( 'About Jetpack', 'jetpack' ); ?>" class="jp-footer__menu-item">
<?php echo esc_html__( 'About', 'jetpack' ); ?>
</a>
<a href="<?php echo esc_url( $jetpack_privacy_url ); ?>" rel="noopener noreferrer" title="<?php esc_html_e( "Automattic's Privacy Policy", 'jetpack' ); ?>" class="jp-footer__menu-item <?php echo ! $connectable ? 'is-external' : ''; ?> ?>" target="<?php echo ! $connectable ? '_blank' : '_self'; ?>">
<?php echo esc_html_x( 'Privacy', 'Navigation item', 'jetpack' ); ?>
<?php echo ! $connectable ? $external_link_icon : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</a>
<a href="<?php echo esc_url( Redirect::get_url( 'wpcom-tos' ) ); ?>" target="_blank" rel="noopener noreferrer" title="<?php esc_html__( 'WordPress.com Terms of Service', 'jetpack' ); ?>" class="jp-footer__menu-item is-external">
<?php echo esc_html_x( 'Terms', 'Navigation item', 'jetpack' ); ?>
<?php echo $external_link_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</a>
<a href="<?php echo esc_url( Redirect::get_url( 'jetpack' ) ); ?>" target="_blank" rel="noopener noreferrer" aria-label="Jetpack 12.2-a.0" class="jp-footer__menu-item is-external">
Version <?php echo esc_html( JETPACK__VERSION ); ?>
<?php echo $external_link_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</a>
<?php if ( is_multisite() && current_user_can( 'jetpack_network_sites_page' ) ) { ?>
<a href="<?php echo esc_url( network_admin_url( 'admin.php?page=jetpack' ) ); ?>" title="<?php esc_html_e( "Manage your network's Jetpack Sites.", 'jetpack' ); ?>" class="jp-footer__menu-item"><?php echo esc_html_x( 'Network Sites', 'Navigation item', 'jetpack' ); ?></a>
<?php } ?>
<?php if ( is_multisite() && current_user_can( 'jetpack_network_settings_page' ) ) { ?>
<a href="<?php echo esc_url( network_admin_url( 'admin.php?page=jetpack-settings' ) ); ?>" title="<?php esc_html_e( "Manage your network's Jetpack Sites.", 'jetpack' ); ?>" class="jp-footer__menu-item"><?php echo esc_html_x( 'Network Settings', 'Navigation item', 'jetpack' ); ?></a>
<?php } ?>
<?php if ( current_user_can( 'manage_options' ) ) { ?>
<a href="<?php echo esc_url( admin_url( 'admin.php?page=jetpack_modules' ) ); ?>" title="<?php esc_html_e( 'Access the full list of Jetpack modules available on your site.', 'jetpack' ); ?>" class="jp-footer__menu-item"><?php echo esc_html_x( 'Modules', 'Navigation item', 'jetpack' ); ?></a>
<a href="<?php echo esc_url( admin_url( 'admin.php?page=jetpack-debugger' ) ); ?>" title="<?php esc_html_e( "Test your site's compatibility with Jetpack.", 'jetpack' ); ?>" class="jp-footer__menu-item"><?php echo esc_html_x( 'Debug', 'Navigation item', 'jetpack' ); ?></a>
<?php } ?>
</div>
<a class="jp-footer__a8c-logo" href="<?php echo esc_url( $jetpack_about_url ); ?>" aria-label="<?php echo esc_attr__( 'An Automattic Airline', 'jetpack' ); ?>">
<svg role="img" x="0" y="0" viewBox="0 0 935 38.2" enable-background="new 0 0 935 38.2" aria-labelledby="jp-automattic-byline-logo-title" height="7" class="jp-automattic-byline-logo">
<desc id="jp-automattic-byline-logo-title">
<?php echo esc_attr__( 'An Automattic Airline', 'jetpack' ); ?>
</desc>
<path d="M317.1 38.2c-12.6 0-20.7-9.1-20.7-18.5v-1.2c0-9.6 8.2-18.5 20.7-18.5 12.6 0 20.8 8.9 20.8 18.5v1.2C337.9 29.1 329.7 38.2 317.1 38.2zM331.2 18.6c0-6.9-5-13-14.1-13s-14 6.1-14 13v0.9c0 6.9 5 13.1 14 13.1s14.1-6.2 14.1-13.1V18.6zM175 36.8l-4.7-8.8h-20.9l-4.5 8.8h-7L157 1.3h5.5L182 36.8H175zM159.7 8.2L152 23.1h15.7L159.7 8.2zM212.4 38.2c-12.7 0-18.7-6.9-18.7-16.2V1.3h6.6v20.9c0 6.6 4.3 10.5 12.5 10.5 8.4 0 11.9-3.9 11.9-10.5V1.3h6.7V22C231.4 30.8 225.8 38.2 212.4 38.2zM268.6 6.8v30h-6.7v-30h-15.5V1.3h37.7v5.5H268.6zM397.3 36.8V8.7l-1.8 3.1 -14.9 25h-3.3l-14.7-25 -1.8-3.1v28.1h-6.5V1.3h9.2l14 24.4 1.7 3 1.7-3 13.9-24.4h9.1v35.5H397.3zM454.4 36.8l-4.7-8.8h-20.9l-4.5 8.8h-7l19.2-35.5h5.5l19.5 35.5H454.4zM439.1 8.2l-7.7 14.9h15.7L439.1 8.2zM488.4 6.8v30h-6.7v-30h-15.5V1.3h37.7v5.5H488.4zM537.3 6.8v30h-6.7v-30h-15.5V1.3h37.7v5.5H537.3zM569.3 36.8V4.6c2.7 0 3.7-1.4 3.7-3.4h2.8v35.5L569.3 36.8 569.3 36.8zM628 11.3c-3.2-2.9-7.9-5.7-14.2-5.7 -9.5 0-14.8 6.5-14.8 13.3v0.7c0 6.7 5.4 13 15.3 13 5.9 0 10.8-2.8 13.9-5.7l4 4.2c-3.9 3.8-10.5 7.1-18.3 7.1 -13.4 0-21.6-8.7-21.6-18.3v-1.2c0-9.6 8.9-18.7 21.9-18.7 7.5 0 14.3 3.1 18 7.1L628 11.3zM321.5 12.4c1.2 0.8 1.5 2.4 0.8 3.6l-6.1 9.4c-0.8 1.2-2.4 1.6-3.6 0.8l0 0c-1.2-0.8-1.5-2.4-0.8-3.6l6.1-9.4C318.7 11.9 320.3 11.6 321.5 12.4L321.5 12.4z"></path><path d="M37.5 36.7l-4.7-8.9H11.7l-4.6 8.9H0L19.4 0.8H25l19.7 35.9H37.5zM22 7.8l-7.8 15.1h15.9L22 7.8zM82.8 36.7l-23.3-24 -2.3-2.5v26.6h-6.7v-36H57l22.6 24 2.3 2.6V0.8h6.7v35.9H82.8z"></path><path d="M719.9 37l-4.8-8.9H694l-4.6 8.9h-7.1l19.5-36h5.6l19.8 36H719.9zM704.4 8l-7.8 15.1h15.9L704.4 8zM733 37V1h6.8v36H733zM781 37c-1.8 0-2.6-2.5-2.9-5.8l-0.2-3.7c-0.2-3.6-1.7-5.1-8.4-5.1h-12.8V37H750V1h19.6c10.8 0 15.7 4.3 15.7 9.9 0 3.9-2 7.7-9 9 7 0.5 8.5 3.7 8.6 7.9l0.1 3c0.1 2.5 0.5 4.3 2.2 6.1V37H781zM778.5 11.8c0-2.6-2.1-5.1-7.9-5.1h-13.8v10.8h14.4c5 0 7.3-2.4 7.3-5.2V11.8zM794.8 37V1h6.8v30.4h28.2V37H794.8zM836.7 37V1h6.8v36H836.7zM886.2 37l-23.4-24.1 -2.3-2.5V37h-6.8V1h6.5l22.7 24.1 2.3 2.6V1h6.8v36H886.2zM902.3 37V1H935v5.6h-26v9.2h20v5.5h-20v10.1h26V37H902.3z"></path>
</svg>
</a>
</div>
</div>
</div>
<?php
}
/**
* Should we block the page rendering because the site is in IDC?
*
* @return bool
*/
protected function block_page_rendering_for_idc() {
return Jetpack::is_connection_ready() && Identity_Crisis::validate_sync_error_idc_option() && ! Jetpack_Options::get_option( 'safe_mode_confirmed' );
}
}
@@ -0,0 +1,6 @@
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
/** This is intentionally left empty as a stub because some sites were caching the require()
*
* @see https://github.com/Automattic/jetpack/issues/5091
* @package automattic/jetpack
*/
@@ -0,0 +1,334 @@
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
use Automattic\Jetpack\Admin_UI\Admin_Menu;
use Automattic\Jetpack\Assets\Logo;
use Automattic\Jetpack\Connection\Initial_State as Connection_Initial_State;
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Status;
require_once __DIR__ . '/class.jetpack-admin-page.php';
require_once __DIR__ . '/class-jetpack-redux-state-helper.php';
/**
* Builds the landing page and its menu.
*/
class Jetpack_React_Page extends Jetpack_Admin_Page {
/**
* Show the landing page only when Jetpack is connected.
*
* @var bool
*/
protected $dont_show_if_not_active = false;
/**
* Used for fallback when REST API is disabled.
*
* @var bool
*/
protected $is_redirecting = false;
/**
* Add the main admin Jetpack menu.
*
* @return string|false Return value from WordPress's `add_menu_page()`.
*/
public function get_page_hook() {
$icon = ( new Logo() )->get_base64_logo();
return add_menu_page( 'Jetpack', 'Jetpack', 'jetpack_admin_page', 'jetpack', array( $this, 'render' ), $icon, 3 );
}
/**
* Add page action.
*
* @param string $hook Hook of current page.
* @return void
*/
public function add_page_actions( $hook ) {
/** This action is documented in class.jetpack-admin.php */
do_action( 'jetpack_admin_menu', $hook );
if ( ! isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return;
}
$page = sanitize_text_field( wp_unslash( $_GET['page'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( 'jetpack' !== $page ) {
if ( strpos( $page, 'jetpack/' ) === 0 ) {
$section = substr( $page, 8 );
wp_safe_redirect( admin_url( 'admin.php?page=jetpack#/' . $section ) );
exit( 0 );
}
return; // No need to handle the fallback redirection if we are not on the Jetpack page.
}
// Adding a redirect meta tag if the REST API is disabled.
if ( ! $this->is_rest_api_enabled() ) {
$this->is_redirecting = true;
add_action( 'admin_head', array( $this, 'add_fallback_head_meta' ) );
}
// Adding a redirect meta tag wrapped in noscript tags for all browsers in case they have JavaScript disabled.
add_action( 'admin_head', array( $this, 'add_noscript_head_meta' ) );
// If this is the first time the user is viewing the admin, don't show JITMs.
// This filter is added just in time because this function is called on admin_menu
// and JITMs are initialized on admin_init.
if ( Jetpack::is_connection_ready() && ! Jetpack_Options::get_option( 'first_admin_view', false ) ) {
Jetpack_Options::update_option( 'first_admin_view', true );
add_filter( 'jetpack_just_in_time_msgs', '__return_false' );
}
}
/**
* Remove the main Jetpack submenu if a site is in offline mode or connected.
* At that point, admins can access the Jetpack Dashboard instead.
*
* @since 13.8
*/
public function remove_jetpack_menu() {
if (
( new Status() )->is_offline_mode()
|| Jetpack::is_connection_ready()
) {
remove_submenu_page( 'jetpack', 'jetpack' );
}
}
/**
* Add Jetpack Dashboard sub-link and point it to AAG if the user can view stats, manage modules or if Protect is active.
*
* Works in Dev Mode or when user is connected.
*
* @since 4.3.0
*/
public function jetpack_add_dashboard_sub_nav_item() {
if ( ( new Status() )->is_offline_mode() || Jetpack::is_connection_ready() ) {
Admin_Menu::add_menu(
__( 'Dashboard', 'jetpack' ),
__( 'Dashboard', 'jetpack' ),
'jetpack_admin_page',
Jetpack::admin_url( array( 'page' => 'jetpack#/dashboard' ) ),
null, // @phan-suppress-current-line PhanTypeMismatchArgumentProbablyReal -- See https://core.trac.wordpress.org/ticket/52539.
14
);
}
}
/**
* Determine whether a user can access the Jetpack Settings page.
*
* Rules are:
* - user is allowed to see the Jetpack Admin
* - site is connected or in offline mode
* - non-admins only need access to the settings when there are modules they can manage.
*
* @return bool $can_access_settings Can the user access settings.
*/
private function can_access_settings() {
$connection = new Connection_Manager( 'jetpack' );
$status = new Status();
// User must have the necessary permissions to see the Jetpack settings pages.
if ( ! current_user_can( 'edit_posts' ) ) {
return false;
}
// In offline mode, allow access to admins.
if ( $status->is_offline_mode() && current_user_can( 'manage_options' ) ) {
return true;
}
// If not in offline mode but site is not connected, bail.
if ( ! Jetpack::is_connection_ready() ) {
return false;
}
/*
* Additional checks for non-admins.
*/
if ( ! current_user_can( 'manage_options' ) ) {
// If the site isn't connected at all, bail.
if ( ! $connection->has_connected_owner() ) {
return false;
}
/*
* If they haven't connected their own account yet,
* they have no use for the settings page.
* They will not be able to manage any settings.
*/
if ( ! $connection->is_user_connected() ) {
return false;
}
/*
* Non-admins only have access to settings
* for the following modules:
* - Publicize
* - Post By Email
* If those modules are not available, bail.
*/
if (
! Jetpack::is_module_active( 'post-by-email' )
&& ! Jetpack::is_module_active( 'publicize' )
) {
return false;
}
}
// fallback.
return true;
}
/**
* Jetpack Settings sub-link.
*
* @since 4.3.0
* @since 9.7.0 If Connection does not have an owner, restrict it to admins
*/
public function jetpack_add_settings_sub_nav_item() {
if ( $this->can_access_settings() ) {
Admin_Menu::add_menu(
__( 'Settings', 'jetpack' ),
__( 'Settings', 'jetpack' ),
'jetpack_admin_page',
Jetpack::admin_url( array( 'page' => 'jetpack#/settings' ) ),
null, // @phan-suppress-current-line PhanTypeMismatchArgumentProbablyReal -- See https://core.trac.wordpress.org/ticket/52539.
13
);
}
}
/**
* Fallback redirect meta tag if the REST API is disabled.
*
* @return void
*/
public function add_fallback_head_meta() {
echo '<meta http-equiv="refresh" content="0; url=?page=jetpack_modules">';
}
/**
* Fallback meta tag wrapped in noscript tags for all browsers in case they have JavaScript disabled.
*
* @return void
*/
public function add_noscript_head_meta() {
echo '<noscript>';
$this->add_fallback_head_meta();
echo '</noscript>';
}
/**
* Add action to render page specific HTML.
*
* @return void
*/
public function page_render() {
/** This action is already documented in class.jetpack-admin-page.php */
do_action( 'jetpack_notices' );
// Fetch static.html.
$static_html = @file_get_contents( JETPACK__PLUGIN_DIR . '_inc/build/static.html' ); //phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents, Not fetching a remote file.
if ( false === $static_html ) {
// If we still have nothing, display an error.
echo '<p>';
esc_html_e( 'Error fetching static.html. Try running: ', 'jetpack' );
echo '<code>pnpm run distclean && pnpm jetpack build plugins/jetpack</code>';
echo '</p>';
} else {
// We got the static.html so let's display it.
echo $static_html; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
/**
* Allow robust deep links to React.
*
* The Jetpack dashboard requires fragments/hash values to make
* a deep link to it but passing fragments as part of a return URL
* will most often be discarded throughout the process.
* This logic aims to bridge this gap and reduce the chance of React
* specific links being broken while passing them along.
*/
public function react_redirects() {
global $pagenow;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( 'admin.php' !== $pagenow || ! isset( $_GET['jp-react-redirect'] ) ) {
return;
}
$allowed_paths = array(
'product-purchased' => admin_url( '/admin.php?page=jetpack#/recommendations/product-purchased' ),
);
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$target = sanitize_text_field( wp_unslash( $_GET['jp-react-redirect'] ) );
if ( isset( $allowed_paths[ $target ] ) ) {
wp_safe_redirect( $allowed_paths[ $target ] );
exit( 0 );
}
}
/**
* Load styles for static page.
*/
public function additional_styles() {
Jetpack_Admin_Page::load_wrapper_styles();
}
/**
* Load admin page scripts.
*/
public function page_admin_scripts() {
if ( $this->is_redirecting ) {
return; // No need for scripts on a fallback page.
}
$status = new Status();
$is_offline_mode = $status->is_offline_mode();
$site_suffix = $status->get_site_suffix();
$script_deps_path = JETPACK__PLUGIN_DIR . '_inc/build/admin.asset.php';
$script_dependencies = array( 'jquery', 'wp-polyfill' );
$version = JETPACK__VERSION;
if ( file_exists( $script_deps_path ) ) {
$asset_manifest = include $script_deps_path;
$script_dependencies = $asset_manifest['dependencies'];
$version = $asset_manifest['version'];
}
$blog_id_prop = '';
if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) {
$blog_id = Connection_Manager::get_site_id( true );
if ( $blog_id ) {
$blog_id_prop = ', currentBlogID: "' . (int) $blog_id . '"';
}
}
wp_enqueue_script(
'react-plugin',
plugins_url( '_inc/build/admin.js', JETPACK__PLUGIN_FILE ),
$script_dependencies,
$version,
true
);
if ( ! $is_offline_mode && Jetpack::is_connection_ready() ) {
// Required for Analytics.
wp_enqueue_script( 'jp-tracks', '//stats.wp.com/w.js', array(), gmdate( 'YW' ), true );
}
wp_set_script_translations( 'react-plugin', 'jetpack' );
// Add objects to be passed to the initial state of the app.
// Use wp_add_inline_script instead of wp_localize_script, see https://core.trac.wordpress.org/ticket/25280.
wp_add_inline_script( 'react-plugin', 'var Initial_State=JSON.parse(decodeURIComponent("' . rawurlencode( wp_json_encode( Jetpack_Redux_State_Helper::get_initial_state() ) ) . '"));', 'before' );
// This will set the default URL of the jp_redirects lib.
wp_add_inline_script( 'react-plugin', 'var jetpack_redirects = { currentSiteRawUrl: "' . $site_suffix . '"' . $blog_id_prop . ' };', 'before' );
// Adds Connection package initial state.
Connection_Initial_State::render_script( 'react-plugin' );
}
}
@@ -0,0 +1,194 @@
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
use Automattic\Jetpack\Assets;
use Automattic\Jetpack\Tracking;
require_once __DIR__ . '/class.jetpack-admin-page.php';
require_once JETPACK__PLUGIN_DIR . 'class.jetpack-modules-list-table.php';
/**
* Builds the settings page and its menu
*/
class Jetpack_Settings_Page extends Jetpack_Admin_Page {
/**
* Show the settings page only when Jetpack is connected or in dev mode.
*
* @var boolean
*/
protected $dont_show_if_not_active = true;
/**
* Add page action.
*
* @param string $hook Hook of current page.
* @return void
*/
public function add_page_actions( $hook ) {} //phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
/**
* Adds the Settings sub menu.
*/
public function get_page_hook() {
return add_submenu_page(
'',
__( 'Jetpack Settings', 'jetpack' ),
__( 'Settings', 'jetpack' ),
'jetpack_manage_modules',
'jetpack_modules',
array( $this, 'render' )
);
}
/**
* Renders the module list table where you can use bulk action or row
* actions to activate/deactivate and configure modules
*/
public function page_render() {
$list_table = new Jetpack_Modules_List_Table();
// We have static.html so let's continue trying to fetch the others.
$noscript_notice = @file_get_contents( JETPACK__PLUGIN_DIR . '_inc/build/static-noscript-notice.html' ); //phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents, Not fetching a remote file.
$rest_api_notice = @file_get_contents( JETPACK__PLUGIN_DIR . '_inc/build/static-version-notice.html' ); //phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents, Not fetching a remote file.
$noscript_notice = str_replace(
'#HEADER_TEXT#',
esc_html__( 'You have JavaScript disabled', 'jetpack' ),
$noscript_notice
);
$noscript_notice = str_replace(
'#TEXT#',
esc_html__( "Turn on JavaScript to unlock Jetpack's full potential!", 'jetpack' ),
$noscript_notice
);
$rest_api_notice = str_replace(
'#HEADER_TEXT#',
esc_html( __( 'WordPress REST API is disabled', 'jetpack' ) ),
$rest_api_notice
);
$rest_api_notice = str_replace(
'#TEXT#',
esc_html( __( "Enable WordPress REST API to unlock Jetpack's full potential!", 'jetpack' ) ),
$rest_api_notice
);
if ( ! $this->is_rest_api_enabled() ) {
echo $rest_api_notice; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
echo $noscript_notice; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
<div class="jetpack-module-list">
<div class="wrap">
<div class="manage-left jp-static-block">
<table class="table table-bordered fixed-top jetpack-modules">
<thead>
<tr>
<th class="check-column"><input type="checkbox" class="checkall"></th>
<th colspan="2">
<?php $list_table->unprotected_display_tablenav( 'top' ); ?>
<span class="filter-search">
<button type="button" class="button">Filter</button>
</span>
</th>
</tr>
</thead>
</table>
<form class="jetpack-modules-list-table-form" onsubmit="return false;">
<table class="<?php echo esc_attr( implode( ' ', $list_table->get_table_classes() ) ); ?>">
<tbody id="the-list">
<?php $list_table->display_rows_or_placeholder(); ?>
</tbody>
</table>
</form>
</div>
<div class="manage-right">
<div class="bumper">
<form class="navbar-form" role="search">
<input type="hidden" name="page" value="jetpack_modules" />
<?php $list_table->search_box( __( 'Search', 'jetpack' ), 'srch-term' ); ?>
<p><?php esc_html_e( 'View', 'jetpack' ); ?></p>
<span class="dops-button-group button-group filter-active">
<button type="button" class="dops-button is-compact button
<?php // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is view logic.
if ( empty( $_GET['activated'] ) ) {
echo 'active';
}
?>
">
<?php esc_html_e( 'All', 'jetpack' ); ?></button>
<button type="button" class="dops-button button
<?php // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is view logic.
if ( ! empty( $_GET['activated'] ) && 'true' === $_GET['activated'] ) {
echo 'active';
}
?>
" data-filter-by="activated" data-filter-value="true"><?php esc_html_e( 'Active', 'jetpack' ); ?></button>
<button type="button" class="dops-button button
<?php // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is view logic.
if ( ! empty( $_GET['activated'] ) && 'false' === $_GET['activated'] ) {
echo 'active';
}
?>
" data-filter-by="activated" data-filter-value="false"><?php esc_html_e( 'Inactive', 'jetpack' ); ?></button>
</span>
<p><?php esc_html_e( 'Sort by', 'jetpack' ); ?></p>
<span class="dops-button-group button-group sort">
<button type="button" class="dops-button button
<?php // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is view logic.
if ( empty( $_GET['sort_by'] ) ) {
echo 'active';
}
?>
" data-sort-by="name"><?php esc_html_e( 'Alphabetical', 'jetpack' ); ?></button>
<button type="button" class="dops-button button
<?php // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is view logic.
if ( ! empty( $_GET['sort_by'] ) && 'introduced' === $_GET['sort_by'] ) {
echo 'active';
}
?>
" data-sort-by="introduced" data-sort-order="reverse"><?php esc_html_e( 'Newest', 'jetpack' ); ?></button>
<button type="button" class="dops-button button
<?php // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is view logic.
if ( ! empty( $_GET['sort_by'] ) && 'sort' === $_GET['sort_by'] ) {
echo 'active';
}
?>
" data-sort-by="sort"><?php esc_html_e( 'Popular', 'jetpack' ); ?></button>
</span>
<p><?php esc_html_e( 'Show', 'jetpack' ); ?></p>
<?php $list_table->views(); ?>
</form>
</div>
</div>
</div>
</div><!-- /.content -->
<?php
$tracking = new Tracking();
$tracking->record_user_event( 'wpa_page_view', array( 'path' => 'old_settings' ) );
}
/**
* Load styles for static page.
*
* @since 4.3.0
*/
public function additional_styles() {
Jetpack_Admin_Page::load_wrapper_styles();
}
/**
* Javascript logic specific to the list table
*/
public function page_admin_scripts() {
wp_enqueue_script(
'jetpack-admin-js',
Assets::get_file_url_for_environment( '_inc/build/jetpack-admin.min.js', '_inc/jetpack-admin.js' ),
array( 'jquery' ),
JETPACK__VERSION,
true
);
}
}