Module slug => product group slug. */ public static function get_module_product_groups_map() { return array( // Grow your audience. 'blaze' => 'growth', 'comment-likes' => 'growth', 'comments' => 'growth', 'contact-form' => 'growth', 'gravatar-hovercards' => 'growth', 'likes' => 'growth', 'publicize' => 'growth', 'related-posts' => 'growth', 'sharedaddy' => 'growth', 'simple-payments' => 'growth', 'stats' => 'growth', 'subscriptions' => 'growth', 'woocommerce-analytics' => 'growth', 'wordads' => 'growth', 'wpcom-reader' => 'growth', // Speed up your site. 'carousel' => 'performance', 'google-fonts' => 'performance', 'infinite-scroll' => 'performance', 'photon' => 'performance', 'photon-cdn' => 'performance', 'search' => 'performance', 'tiled-gallery' => 'performance', 'videopress' => 'performance', // Protect your site. 'account-protection' => 'security', 'monitor' => 'security', 'notes' => 'security', 'protect' => 'security', 'sso' => 'security', 'vaultpress' => 'security', 'waf' => 'security', ); } /** * Get the product group slug for a given module. * * @param string $slug Module slug. * @return string Product group slug. */ public static function get_module_product_group( $slug ) { $map = self::get_module_product_groups_map(); return $map[ $slug ] ?? 'other'; } /** * Get the translated display name for a product group. * * @param string $group Product group slug. * @return string Translated group name. */ public static function get_product_group_name( $group ) { switch ( $group ) { case 'growth': return __( 'Grow your audience', 'jetpack' ); case 'performance': return __( 'Speed up your site', 'jetpack' ); case 'security': return __( 'Protect your site', 'jetpack' ); default: return __( 'Other features', 'jetpack' ); } } /** * Whether a module is flagged as recommended. * * @param array $module Module data (with raw, untranslated module tags). * @return bool */ public static function is_module_recommended( $module ) { return ! empty( $module['module_tags'] ) && in_array( 'Recommended', (array) $module['module_tags'], true ); } /** * Remove the legacy `vaultpress` module from the modules screen. * * The `vaultpress` module is a leftover stub for the original standalone * VaultPress plugin. It is hard-coded as never activatable (see * Jetpack_Admin::is_module_available()) and is unrelated to the modern * VaultPress Backup product, which is delivered through My Jetpack and the * standalone Jetpack VaultPress Backup plugin rather than a Jetpack module. * Showing a permanently-unavailable row that merely reuses the modern * product's name is misleading, so we drop it from this screen only. Other * surfaces (REST, the React dashboard, standalone plugins) are unaffected. * * @param array $modules Array of Jetpack modules keyed by slug. * @return array Modules without the legacy `vaultpress` entry. */ public static function hide_legacy_vaultpress_module( $modules ) { unset( $modules['vaultpress'] ); return $modules; } /** Constructor. */ public function __construct() { parent::__construct(); Jetpack::init(); // Scope this to the modules screen so REST/React/standalone surfaces keep the legacy slug. add_filter( 'jetpack_modules_list_table_items', array( __CLASS__, 'hide_legacy_vaultpress_module' ) ); if ( $this->compat_fields && is_array( $this->compat_fields ) ) { array_push( $this->compat_fields, 'all_items' ); } /** * Filters the list of modules available to be displayed in the Jetpack Settings screen. * * @since 3.0.0 * * @param array $modules Array of Jetpack modules. */ $this->all_items = apply_filters( 'jetpack_modules_list_table_items', Jetpack_Admin::init()->get_modules() ); $this->items = $this->all_items; $this->items = $this->filter_displayed_table_items( $this->items ); $this->_column_headers = array( $this->get_columns(), array(), array(), 'name' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce: This is a view, not a model or controller. InputNotSanitized: Sanitized below via `$this->module_info_check()`. $modal_info = isset( $_GET['info'] ) ? wp_unslash( $_GET['info'] ) : false; // Adding in a hidden h1 heading for screen-readers. ?>
all_items ); foreach ( array_keys( $modules_for_js ) as $slug ) { $group = self::get_module_product_group( $slug ); $modules_for_js[ $slug ]['product_group'] = $group; $modules_for_js[ $slug ]['product_group_name'] = self::get_product_group_name( $group ); // Detect recommendation from the raw (untranslated) module tags. $modules_for_js[ $slug ]['recommended'] = isset( $this->all_items[ $slug ] ) && self::is_module_recommended( $this->all_items[ $slug ] ); } wp_localize_script( 'jetpack-modules-list-table', 'jetpackModulesData', array( 'modules' => $modules_for_js, 'i18n' => array( 'search_placeholder' => __( 'Search modules…', 'jetpack' ), ), 'modalinfo' => $this->module_info_check( $modal_info, $this->all_items ), 'nonces' => array( 'bulk' => wp_create_nonce( 'bulk-jetpack_page_jetpack_modules' ), ), ) ); wp_enqueue_script( 'jetpack-modules-list-table' ); /** * Filters the js_templates callback value. * * @since 3.6.0 * * @param array array( $this, 'js_templates' ) js_templates callback. */ add_action( 'admin_footer', apply_filters( 'jetpack_modules_list_table_js_template_callback', array( $this, 'js_templates' ) ), 9 ); } /** * Output row template. */ public function js_templates() { ?> get_modules() ); $array_of_module_tags = wp_list_pluck( $modules, 'module_tags' ); $module_tags = array_merge( ...array_values( $array_of_module_tags ) ); $module_tags = array_map( 'jetpack_get_module_i18n_tag', $module_tags ); $module_tags_unique = array_count_values( $module_tags ); ksort( $module_tags_unique ); $format = '%1$s (%2$s)'; $title = __( 'All', 'jetpack' ); $count = is_countable( $modules ) ? count( $modules ) : 0; $url = esc_url( remove_query_arg( 'module_tag' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is a view, not a model or controller. $views = array( 'all' => sprintf( $format, $title, $count, $url, 'class="all"' ), ); foreach ( $module_tags_unique as $title => $count ) { $key = sanitize_title( $title ); $display_title = esc_html( wptexturize( $title ) ); $url = esc_url( add_query_arg( 'module_tag', rawurlencode( $title ) ) ); $views[ $key ] = sprintf( $format, $display_title, $count, $url, '' ); } return $views; } /** * Output views HTML. */ public function views() { $views = $this->get_views(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is a view, not a model or controller. $module_tag = empty( $_GET['module_tag'] ) ? 'all' : sanitize_title( wp_unslash( $_GET['module_tag'] ) ); echo "