web/wp-admin/includes/class-wp-plugins-list-table.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
     7  * @since 3.1.0
     7  * @since 3.1.0
     8  * @access private
     8  * @access private
     9  */
     9  */
    10 class WP_Plugins_List_Table extends WP_List_Table {
    10 class WP_Plugins_List_Table extends WP_List_Table {
    11 
    11 
    12 	function __construct() {
    12 	function __construct( $args = array() ) {
    13 		global $status, $page;
    13 		global $status, $page;
       
    14 
       
    15 		parent::__construct( array(
       
    16 			'plural' => 'plugins',
       
    17 			'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
       
    18 		) );
    14 
    19 
    15 		$status = 'all';
    20 		$status = 'all';
    16 		if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) )
    21 		if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) )
    17 			$status = $_REQUEST['plugin_status'];
    22 			$status = $_REQUEST['plugin_status'];
    18 
    23 
    19 		if ( isset($_REQUEST['s']) )
    24 		if ( isset($_REQUEST['s']) )
    20 			$_SERVER['REQUEST_URI'] = add_query_arg('s', stripslashes($_REQUEST['s']) );
    25 			$_SERVER['REQUEST_URI'] = add_query_arg('s', stripslashes($_REQUEST['s']) );
    21 
    26 
    22 		$page = $this->get_pagenum();
    27 		$page = $this->get_pagenum();
    23 
       
    24 		parent::__construct( array(
       
    25 			'plural' => 'plugins',
       
    26 		) );
       
    27 	}
    28 	}
    28 
    29 
    29 	function get_table_classes() {
    30 	function get_table_classes() {
    30 		return array( 'widefat', $this->_args['plural'] );
    31 		return array( 'widefat', $this->_args['plural'] );
    31 	}
    32 	}
    32 
    33 
    33 	function ajax_user_can() {
    34 	function ajax_user_can() {
    34 		if ( is_multisite() ) {
       
    35 			$menu_perms = get_site_option( 'menu_items', array() );
       
    36 
       
    37 			if ( empty( $menu_perms['plugins'] ) && ! is_super_admin() )
       
    38 				return false;
       
    39 		}
       
    40 
       
    41 		return current_user_can('activate_plugins');
    35 		return current_user_can('activate_plugins');
    42 	}
    36 	}
    43 
    37 
    44 	function prepare_items() {
    38 	function prepare_items() {
    45 		global $status, $plugins, $totals, $page, $orderby, $order, $s;
    39 		global $status, $plugins, $totals, $page, $orderby, $order, $s;
    55 			'upgrade' => array(),
    49 			'upgrade' => array(),
    56 			'mustuse' => array(),
    50 			'mustuse' => array(),
    57 			'dropins' => array()
    51 			'dropins' => array()
    58 		);
    52 		);
    59 
    53 
    60 		$screen = get_current_screen();
    54 		$screen = $this->screen;
    61 
    55 
    62 		if ( ! is_multisite() || ( $screen->is_network && current_user_can('manage_network_plugins') ) ) {
    56 		if ( ! is_multisite() || ( $screen->is_network && current_user_can('manage_network_plugins') ) ) {
    63 			if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) )
    57 			if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) )
    64 				$plugins['mustuse'] = get_mu_plugins();
    58 				$plugins['mustuse'] = get_mu_plugins();
    65 			if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) )
    59 			if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) )
    74 					}
    68 					}
    75 				}
    69 				}
    76 			}
    70 			}
    77 		}
    71 		}
    78 
    72 
    79 		set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), 86400 );
    73 		set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), DAY_IN_SECONDS );
    80 
    74 
    81 		if ( ! $screen->is_network ) {
    75 		if ( ! $screen->is_network ) {
    82 			$recently_activated = get_option( 'recently_activated', array() );
    76 			$recently_activated = get_option( 'recently_activated', array() );
    83 
    77 
    84 			$one_week = 7*24*60*60;
       
    85 			foreach ( $recently_activated as $key => $time )
    78 			foreach ( $recently_activated as $key => $time )
    86 				if ( $time + $one_week < time() )
    79 				if ( $time + WEEK_IN_SECONDS < time() )
    87 					unset( $recently_activated[$key] );
    80 					unset( $recently_activated[$key] );
    88 			update_option( 'recently_activated', $recently_activated );
    81 			update_option( 'recently_activated', $recently_activated );
    89 		}
    82 		}
    90 
    83 
    91 		foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
    84 		foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
    96 				unset( $plugins['all'][ $plugin_file ] );
    89 				unset( $plugins['all'][ $plugin_file ] );
    97 			} elseif ( ( ! $screen->is_network && is_plugin_active( $plugin_file ) )
    90 			} elseif ( ( ! $screen->is_network && is_plugin_active( $plugin_file ) )
    98 				|| ( $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) ) {
    91 				|| ( $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) ) {
    99 				$plugins['active'][ $plugin_file ] = $plugin_data;
    92 				$plugins['active'][ $plugin_file ] = $plugin_data;
   100 			} else {
    93 			} else {
   101 				if ( !$screen->is_network && isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated?
    94 				if ( ! $screen->is_network && isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated?
   102 					$plugins['recently_activated'][ $plugin_file ] = $plugin_data;
    95 					$plugins['recently_activated'][ $plugin_file ] = $plugin_data;
   103 				$plugins['inactive'][ $plugin_file ] = $plugin_data;
    96 				$plugins['inactive'][ $plugin_file ] = $plugin_data;
   104 			}
    97 			}
   105 		}
    98 		}
   106 
    99 
   241 	function get_bulk_actions() {
   234 	function get_bulk_actions() {
   242 		global $status;
   235 		global $status;
   243 
   236 
   244 		$actions = array();
   237 		$actions = array();
   245 
   238 
   246 		$screen = get_current_screen();
       
   247 
       
   248 		if ( 'active' != $status )
   239 		if ( 'active' != $status )
   249 			$actions['activate-selected'] = $screen->is_network ? __( 'Network Activate' ) : __( 'Activate' );
   240 			$actions['activate-selected'] = $this->screen->is_network ? __( 'Network Activate' ) : __( 'Activate' );
   250 
   241 
   251 		if ( 'inactive' != $status && 'recent' != $status )
   242 		if ( 'inactive' != $status && 'recent' != $status )
   252 			$actions['deactivate-selected'] = $screen->is_network ? __( 'Network Deactivate' ) : __( 'Deactivate' );
   243 			$actions['deactivate-selected'] = $this->screen->is_network ? __( 'Network Deactivate' ) : __( 'Deactivate' );
   253 
   244 
   254 		if ( !is_multisite() || $screen->is_network ) {
   245 		if ( !is_multisite() || $this->screen->is_network ) {
   255 			if ( current_user_can( 'update_plugins' ) )
   246 			if ( current_user_can( 'update_plugins' ) )
   256 				$actions['update-selected'] = __( 'Update' );
   247 				$actions['update-selected'] = __( 'Update' );
   257 			if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) )
   248 			if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) )
   258 				$actions['delete-selected'] = __( 'Delete' );
   249 				$actions['delete-selected'] = __( 'Delete' );
   259 		}
   250 		}
   260 
   251 
   261 		return $actions;
   252 		return $actions;
   262 	}
   253 	}
   263 
   254 
   264 	function bulk_actions( $which ) {
   255 	function bulk_actions() {
   265 		global $status;
   256 		global $status;
   266 
   257 
   267 		if ( in_array( $status, array( 'mustuse', 'dropins' ) ) )
   258 		if ( in_array( $status, array( 'mustuse', 'dropins' ) ) )
   268 			return;
   259 			return;
   269 
   260 
   270 		parent::bulk_actions( $which );
   261 		parent::bulk_actions();
   271 	}
   262 	}
   272 
   263 
   273 	function extra_tablenav( $which ) {
   264 	function extra_tablenav( $which ) {
   274 		global $status;
   265 		global $status;
   275 
   266 
   276 		if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) )
   267 		if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) )
   277 			return;
   268 			return;
   278 
   269 
   279 		echo '<div class="alignleft actions">';
   270 		echo '<div class="alignleft actions">';
   280 
   271 
   281 		$screen = get_current_screen();
   272 		if ( ! $this->screen->is_network && 'recently_activated' == $status )
   282 
   273 			submit_button( __( 'Clear List' ), 'button', 'clear-recent-list', false );
   283 		if ( ! $screen->is_network && 'recently_activated' == $status )
       
   284 			submit_button( __( 'Clear List' ), 'secondary', 'clear-recent-list', false );
       
   285 		elseif ( 'top' == $which && 'mustuse' == $status )
   274 		elseif ( 'top' == $which && 'mustuse' == $status )
   286 			echo '<p>' . sprintf( __( 'Files in the <code>%s</code> directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '</p>';
   275 			echo '<p>' . sprintf( __( 'Files in the <code>%s</code> directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '</p>';
   287 		elseif ( 'top' == $which && 'dropins' == $status )
   276 		elseif ( 'top' == $which && 'dropins' == $status )
   288 			echo '<p>' . sprintf( __( 'Drop-ins are advanced plugins in the <code>%s</code> directory that replace WordPress functionality when present.' ), str_replace( ABSPATH, '', WP_CONTENT_DIR ) ) . '</p>';
   277 			echo '<p>' . sprintf( __( 'Drop-ins are advanced plugins in the <code>%s</code> directory that replace WordPress functionality when present.' ), str_replace( ABSPATH, '', WP_CONTENT_DIR ) ) . '</p>';
   289 
   278 
   298 	}
   287 	}
   299 
   288 
   300 	function display_rows() {
   289 	function display_rows() {
   301 		global $status;
   290 		global $status;
   302 
   291 
   303 		$screen = get_current_screen();
   292 		if ( is_multisite() && ! $this->screen->is_network && in_array( $status, array( 'mustuse', 'dropins' ) ) )
   304 
       
   305 		if ( is_multisite() && !$screen->is_network && in_array( $status, array( 'mustuse', 'dropins' ) ) )
       
   306 			return;
   293 			return;
   307 
   294 
   308 		foreach ( $this->items as $plugin_file => $plugin_data )
   295 		foreach ( $this->items as $plugin_file => $plugin_data )
   309 			$this->single_row( $plugin_file, $plugin_data );
   296 			$this->single_row( array( $plugin_file, $plugin_data ) );
   310 	}
   297 	}
   311 
   298 
   312 	function single_row( $plugin_file, $plugin_data ) {
   299 	function single_row( $item ) {
   313 		global $status, $page, $s, $totals;
   300 		global $status, $page, $s, $totals;
   314 
   301 
       
   302 		list( $plugin_file, $plugin_data ) = $item;
   315 		$context = $status;
   303 		$context = $status;
   316 
   304 		$screen = $this->screen;
   317 		$screen = get_current_screen();
       
   318 
   305 
   319 		// preorder
   306 		// preorder
   320 		$actions = array(
   307 		$actions = array(
   321 			'deactivate' => '',
   308 			'deactivate' => '',
   322 			'activate' => '',
   309 			'activate' => '',
   378 		$actions = apply_filters( $prefix . 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context );
   365 		$actions = apply_filters( $prefix . 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context );
   379 		$actions = apply_filters( $prefix . "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
   366 		$actions = apply_filters( $prefix . "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
   380 
   367 
   381 		$class = $is_active ? 'active' : 'inactive';
   368 		$class = $is_active ? 'active' : 'inactive';
   382 		$checkbox_id =  "checkbox_" . md5($plugin_data['Name']);
   369 		$checkbox_id =  "checkbox_" . md5($plugin_data['Name']);
   383 		$checkbox = in_array( $status, array( 'mustuse', 'dropins' ) ) ? '' : "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $plugin_data['Name'] . "</label>";
   370 		if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
       
   371 			$checkbox = '';
       
   372 		} else {
       
   373 			$checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf( __( 'Select %s' ), $plugin_data['Name'] ) . "</label>"
       
   374 				. "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' id='" . $checkbox_id . "' />";
       
   375 		}
   384 		if ( 'dropins' != $context ) {
   376 		if ( 'dropins' != $context ) {
   385 			$description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : '&nbsp;' ) . '</p>';
   377 			$description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : '&nbsp;' ) . '</p>';
   386 			$plugin_name = $plugin_data['Name'];
   378 			$plugin_name = $plugin_data['Name'];
   387 		}
   379 		}
   388 
   380