summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/class.jetpack-modules-list-table.php')
-rw-r--r--plugins/jetpack/class.jetpack-modules-list-table.php112
1 files changed, 64 insertions, 48 deletions
diff --git a/plugins/jetpack/class.jetpack-modules-list-table.php b/plugins/jetpack/class.jetpack-modules-list-table.php
index 4fa6fe1f..e8cabb93 100644
--- a/plugins/jetpack/class.jetpack-modules-list-table.php
+++ b/plugins/jetpack/class.jetpack-modules-list-table.php
@@ -1,7 +1,10 @@
<?php
-if ( ! class_exists( 'WP_List_Table' ) )
+use Automattic\Jetpack\Assets;
+
+if ( ! class_exists( 'WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
+}
class Jetpack_Modules_List_Table extends WP_List_Table {
@@ -23,13 +26,13 @@ class Jetpack_Modules_List_Table extends WP_List_Table {
*
* @param array $this->items Array of Jetpack modules.
*/
- $this->items = apply_filters( 'jetpack_modules_list_table_items', $this->items );
+ $this->items = apply_filters( 'jetpack_modules_list_table_items', $this->items );
$this->_column_headers = array( $this->get_columns(), array(), array(), 'name' );
- $modal_info = isset( $_GET['info'] ) ? $_GET['info'] : false;
+ $modal_info = isset( $_GET['info'] ) ? $_GET['info'] : false;
wp_register_script(
'models.jetpack-modules',
- Jetpack::get_file_url_for_environment(
+ Assets::get_file_url_for_environment(
'_inc/build/jetpack-modules.models.min.js',
'_inc/jetpack-modules.models.js'
),
@@ -38,7 +41,7 @@ class Jetpack_Modules_List_Table extends WP_List_Table {
);
wp_register_script(
'views.jetpack-modules',
- Jetpack::get_file_url_for_environment(
+ Assets::get_file_url_for_environment(
'_inc/build/jetpack-modules.views.min.js',
'_inc/jetpack-modules.views.js'
),
@@ -47,7 +50,7 @@ class Jetpack_Modules_List_Table extends WP_List_Table {
);
wp_register_script(
'jetpack-modules-list-table',
- Jetpack::get_file_url_for_environment(
+ Assets::get_file_url_for_environment(
'_inc/build/jetpack-modules.min.js',
'_inc/jetpack-modules.js'
),
@@ -60,16 +63,20 @@ class Jetpack_Modules_List_Table extends WP_List_Table {
true
);
- wp_localize_script( 'jetpack-modules-list-table', 'jetpackModulesData', array(
- 'modules' => Jetpack::get_translated_modules( $this->all_items ),
- '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_localize_script(
+ 'jetpack-modules-list-table',
+ 'jetpackModulesData',
+ array(
+ 'modules' => Jetpack::get_translated_modules( $this->all_items ),
+ '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' );
@@ -90,6 +97,7 @@ class Jetpack_Modules_List_Table extends WP_List_Table {
if ( data.items.length ) {
_.each( data.items, function( item, key, list ) {
if ( item === undefined ) return;
+ if ( 'pwa' == item.module && ! item.activated ) return;
if ( 'manage' == item.module && item.activated ) return; #>
<tr class="jetpack-module <# if ( ++i % 2 ) { #> alternate<# } #><# if ( item.activated ) { #> active<# } #><# if ( ! item.available ) { #> unavailable<# } #>" id="{{{ item.module }}}">
<th scope="row" class="check-column">
@@ -116,7 +124,7 @@ class Jetpack_Modules_List_Table extends WP_List_Table {
} else {
#>
<tr class="no-modules-found">
- <td colspan="2"><?php esc_html_e( 'No Modules Found' , 'jetpack' ); ?></td>
+ <td colspan="2"><?php esc_html_e( 'No Modules Found', 'jetpack' ); ?></td>
</tr>
<#
}
@@ -141,15 +149,13 @@ class Jetpack_Modules_List_Table extends WP_List_Table {
'all' => sprintf( $format, $title, $count, $url, $current ),
);
foreach ( $module_tags_unique as $title => $count ) {
- if ( 'Jumpstart' == $title ) {
- continue;
- }
$key = sanitize_title( $title );
$display_title = esc_html( wptexturize( $title ) );
$url = esc_url( add_query_arg( 'module_tag', urlencode( $title ) ) );
$current = '';
- if ( ! empty( $_GET['module_tag'] ) && $title == $_GET['module_tag'] )
- $current = ' class="current"';
+ if ( ! empty( $_GET['module_tag'] ) && $title == $_GET['module_tag'] ) {
+ $current = ' class="current"';
+ }
$views[ $key ] = sprintf( $format, $display_title, $count, $url, $current );
}
return $views;
@@ -163,7 +169,7 @@ class Jetpack_Modules_List_Table extends WP_List_Table {
$views[ $class ] = "\t<li class='$class'>$view</li>";
}
echo implode( "\n", $views ) . "\n";
- echo "</ul>";
+ echo '</ul>';
}
function filter_displayed_table_items( $modules ) {
@@ -174,8 +180,9 @@ class Jetpack_Modules_List_Table extends WP_List_Table {
// Handle module tag based filtering.
if ( ! empty( $_REQUEST['module_tag'] ) ) {
$module_tag = sanitize_text_field( $_REQUEST['module_tag'] );
- if ( ! in_array( $module_tag, $module['module_tags'] ) )
+ if ( ! in_array( $module_tag, $module['module_tags'] ) ) {
return false;
+ }
}
// If nothing rejected it, include it!
@@ -183,38 +190,42 @@ class Jetpack_Modules_List_Table extends WP_List_Table {
}
static function sort_requires_connection_last( $module1, $module2 ) {
- if ( $module1['requires_connection'] == $module2['requires_connection'] )
+ if ( $module1['requires_connection'] == $module2['requires_connection'] ) {
return 0;
- if ( $module1['requires_connection'] )
+ }
+ if ( $module1['requires_connection'] ) {
return 1;
- if ( $module2['requires_connection'] )
+ }
+ if ( $module2['requires_connection'] ) {
return -1;
+ }
return 0;
}
function get_columns() {
$columns = array(
- 'cb' => '<input type="checkbox" />',
- 'name' => __( 'Name', 'jetpack' ),
+ 'cb' => '<input type="checkbox" />',
+ 'name' => __( 'Name', 'jetpack' ),
);
return $columns;
}
function get_bulk_actions() {
$actions = array(
- 'bulk-activate' => __( 'Activate', 'jetpack' ),
+ 'bulk-activate' => __( 'Activate', 'jetpack' ),
'bulk-deactivate' => __( 'Deactivate', 'jetpack' ),
);
return $actions;
}
function single_row( $item ) {
- static $i = 0;
+ static $i = 0;
$row_class = ( ++$i % 2 ) ? ' alternate' : '';
- if ( ! empty( $item['activated'] ) )
+ if ( ! empty( $item['activated'] ) ) {
$row_class .= ' active';
+ }
if ( ! Jetpack_Admin::is_module_available( $item ) ) {
$row_class .= ' unavailable';
@@ -230,8 +241,9 @@ class Jetpack_Modules_List_Table extends WP_List_Table {
}
function column_cb( $item ) {
- if ( ! Jetpack_Admin::is_module_available( $item ) )
+ if ( ! Jetpack_Admin::is_module_available( $item ) ) {
return '';
+ }
return sprintf( '<input type="checkbox" name="modules[]" value="%s" />', $item['module'] );
}
@@ -260,22 +272,26 @@ class Jetpack_Modules_List_Table extends WP_List_Table {
}
if ( empty( $item['activated'] ) && Jetpack_Admin::is_module_available( $item ) ) {
- $url = wp_nonce_url(
- Jetpack::admin_url( array(
- 'page' => 'jetpack',
- 'action' => 'activate',
- 'module' => $item['module'],
- ) ),
+ $url = wp_nonce_url(
+ Jetpack::admin_url(
+ array(
+ 'page' => 'jetpack',
+ 'action' => 'activate',
+ 'module' => $item['module'],
+ )
+ ),
'jetpack_activate-' . $item['module']
);
$actions['activate'] = sprintf( '<a href="%s">%s</a>', esc_url( $url ), esc_html__( 'Activate', 'jetpack' ) );
} elseif ( ! empty( $item['activated'] ) ) {
- $url = wp_nonce_url(
- Jetpack::admin_url( array(
- 'page' => 'jetpack',
- 'action' => 'deactivate',
- 'module' => $item['module'],
- ) ),
+ $url = wp_nonce_url(
+ Jetpack::admin_url(
+ array(
+ 'page' => 'jetpack',
+ 'action' => 'deactivate',
+ 'module' => $item['module'],
+ )
+ ),
'jetpack_deactivate-' . $item['module']
);
$actions['delete'] = sprintf( '<a href="%s">%s</a>', esc_url( $url ), esc_html__( 'Deactivate', 'jetpack' ) );
@@ -299,7 +315,7 @@ class Jetpack_Modules_List_Table extends WP_List_Table {
function column_module_tags( $item ) {
$module_tags = array();
- foreach( $item['module_tags'] as $module_tag ) {
+ foreach ( $item['module_tags'] as $module_tag ) {
$module_tags[] = sprintf( '<a href="%3$s" data-title="%2$s">%1$s</a>', esc_html( $module_tag ), esc_attr( $module_tag ), esc_url( add_query_arg( 'module_tag', urlencode( $module_tag ) ) ) );
}
return implode( ', ', $module_tags );
@@ -316,11 +332,11 @@ class Jetpack_Modules_List_Table extends WP_List_Table {
}
}
- //Check if the info parameter provided in the URL corresponds to an actual module
+ // Check if the info parameter provided in the URL corresponds to an actual module
function module_info_check( $info = false, $modules ) {
if ( false == $info ) {
return false;
- } else if ( array_key_exists( $info, $modules ) ) {
+ } elseif ( array_key_exists( $info, $modules ) ) {
return $info;
}
}