PageRenderTime 45ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/includes/class-wp-plugins-list-table.php

https://github.com/sharpmachine/wakeupmedia.com
PHP | 445 lines | 345 code | 89 blank | 11 comment | 105 complexity | 6881bd24a31029742591160f150a70e8 MD5 | raw file
  1. <?php
  2. /**
  3. * Plugins List Table class.
  4. *
  5. * @package WordPress
  6. * @subpackage List_Table
  7. * @since 3.1.0
  8. * @access private
  9. */
  10. class WP_Plugins_List_Table extends WP_List_Table {
  11. function __construct() {
  12. global $status, $page;
  13. $status = 'all';
  14. if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) )
  15. $status = $_REQUEST['plugin_status'];
  16. if ( isset($_REQUEST['s']) )
  17. $_SERVER['REQUEST_URI'] = add_query_arg('s', stripslashes($_REQUEST['s']) );
  18. $page = $this->get_pagenum();
  19. parent::__construct( array(
  20. 'plural' => 'plugins',
  21. ) );
  22. }
  23. function get_table_classes() {
  24. return array( 'widefat', $this->_args['plural'] );
  25. }
  26. function ajax_user_can() {
  27. if ( is_multisite() ) {
  28. $menu_perms = get_site_option( 'menu_items', array() );
  29. if ( empty( $menu_perms['plugins'] ) && ! is_super_admin() )
  30. return false;
  31. }
  32. return current_user_can('activate_plugins');
  33. }
  34. function prepare_items() {
  35. global $status, $plugins, $totals, $page, $orderby, $order, $s;
  36. wp_reset_vars( array( 'orderby', 'order', 's' ) );
  37. $plugins = array(
  38. 'all' => apply_filters( 'all_plugins', get_plugins() ),
  39. 'search' => array(),
  40. 'active' => array(),
  41. 'inactive' => array(),
  42. 'recently_activated' => array(),
  43. 'upgrade' => array(),
  44. 'mustuse' => array(),
  45. 'dropins' => array()
  46. );
  47. $screen = get_current_screen();
  48. if ( ! is_multisite() || ( $screen->is_network && current_user_can('manage_network_plugins') ) ) {
  49. if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) )
  50. $plugins['mustuse'] = get_mu_plugins();
  51. if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) )
  52. $plugins['dropins'] = get_dropins();
  53. if ( current_user_can( 'update_plugins' ) ) {
  54. $current = get_site_transient( 'update_plugins' );
  55. foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
  56. if ( isset( $current->response[ $plugin_file ] ) ) {
  57. $plugins['all'][ $plugin_file ]['update'] = true;
  58. $plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ];
  59. }
  60. }
  61. }
  62. }
  63. set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), 86400 );
  64. if ( ! $screen->is_network ) {
  65. $recently_activated = get_option( 'recently_activated', array() );
  66. $one_week = 7*24*60*60;
  67. foreach ( $recently_activated as $key => $time )
  68. if ( $time + $one_week < time() )
  69. unset( $recently_activated[$key] );
  70. update_option( 'recently_activated', $recently_activated );
  71. }
  72. foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
  73. // Filter into individual sections
  74. if ( is_multisite() && ! $screen->is_network && is_network_only_plugin( $plugin_file ) ) {
  75. unset( $plugins['all'][ $plugin_file ] );
  76. } elseif ( ! $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) {
  77. unset( $plugins['all'][ $plugin_file ] );
  78. } elseif ( ( ! $screen->is_network && is_plugin_active( $plugin_file ) )
  79. || ( $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) ) {
  80. $plugins['active'][ $plugin_file ] = $plugin_data;
  81. } else {
  82. if ( !$screen->is_network && isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated?
  83. $plugins['recently_activated'][ $plugin_file ] = $plugin_data;
  84. $plugins['inactive'][ $plugin_file ] = $plugin_data;
  85. }
  86. }
  87. if ( $s ) {
  88. $status = 'search';
  89. $plugins['search'] = array_filter( $plugins['all'], array( &$this, '_search_callback' ) );
  90. }
  91. $totals = array();
  92. foreach ( $plugins as $type => $list )
  93. $totals[ $type ] = count( $list );
  94. if ( empty( $plugins[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
  95. $status = 'all';
  96. $this->items = array();
  97. foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) {
  98. // Translate, Don't Apply Markup, Sanitize HTML
  99. $this->items[$plugin_file] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );
  100. }
  101. $total_this_page = $totals[ $status ];
  102. if ( $orderby ) {
  103. $orderby = ucfirst( $orderby );
  104. $order = strtoupper( $order );
  105. uasort( $this->items, array( &$this, '_order_callback' ) );
  106. }
  107. $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 );
  108. $start = ( $page - 1 ) * $plugins_per_page;
  109. if ( $total_this_page > $plugins_per_page )
  110. $this->items = array_slice( $this->items, $start, $plugins_per_page );
  111. $this->set_pagination_args( array(
  112. 'total_items' => $total_this_page,
  113. 'per_page' => $plugins_per_page,
  114. ) );
  115. }
  116. function _search_callback( $plugin ) {
  117. static $term;
  118. if ( is_null( $term ) )
  119. $term = stripslashes( $_REQUEST['s'] );
  120. foreach ( $plugin as $value )
  121. if ( stripos( $value, $term ) !== false )
  122. return true;
  123. return false;
  124. }
  125. function _order_callback( $plugin_a, $plugin_b ) {
  126. global $orderby, $order;
  127. $a = $plugin_a[$orderby];
  128. $b = $plugin_b[$orderby];
  129. if ( $a == $b )
  130. return 0;
  131. if ( 'DESC' == $order )
  132. return ( $a < $b ) ? 1 : -1;
  133. else
  134. return ( $a < $b ) ? -1 : 1;
  135. }
  136. function no_items() {
  137. global $plugins;
  138. if ( !empty( $plugins['all'] ) )
  139. _e( 'No plugins found.' );
  140. else
  141. _e( 'You do not appear to have any plugins available at this time.' );
  142. }
  143. function get_columns() {
  144. global $status;
  145. return array(
  146. 'cb' => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',
  147. 'name' => __( 'Plugin' ),
  148. 'description' => __( 'Description' ),
  149. );
  150. }
  151. function get_sortable_columns() {
  152. return array();
  153. }
  154. function get_views() {
  155. global $totals, $status;
  156. $status_links = array();
  157. foreach ( $totals as $type => $count ) {
  158. if ( !$count )
  159. continue;
  160. switch ( $type ) {
  161. case 'all':
  162. $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' );
  163. break;
  164. case 'active':
  165. $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count );
  166. break;
  167. case 'recently_activated':
  168. $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count );
  169. break;
  170. case 'inactive':
  171. $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count );
  172. break;
  173. case 'mustuse':
  174. $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count );
  175. break;
  176. case 'dropins':
  177. $text = _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count );
  178. break;
  179. case 'upgrade':
  180. $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
  181. break;
  182. }
  183. if ( 'search' != $type ) {
  184. $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
  185. add_query_arg('plugin_status', $type, 'plugins.php'),
  186. ( $type == $status ) ? ' class="current"' : '',
  187. sprintf( $text, number_format_i18n( $count ) )
  188. );
  189. }
  190. }
  191. return $status_links;
  192. }
  193. function get_bulk_actions() {
  194. global $status;
  195. $actions = array();
  196. $screen = get_current_screen();
  197. if ( 'active' != $status )
  198. $actions['activate-selected'] = $screen->is_network ? __( 'Network Activate' ) : __( 'Activate' );
  199. if ( 'inactive' != $status && 'recent' != $status )
  200. $actions['deactivate-selected'] = $screen->is_network ? __( 'Network Deactivate' ) : __( 'Deactivate' );
  201. if ( !is_multisite() || $screen->is_network ) {
  202. if ( current_user_can( 'update_plugins' ) )
  203. $actions['update-selected'] = __( 'Update' );
  204. if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) )
  205. $actions['delete-selected'] = __( 'Delete' );
  206. }
  207. return $actions;
  208. }
  209. function bulk_actions( $which ) {
  210. global $status;
  211. if ( in_array( $status, array( 'mustuse', 'dropins' ) ) )
  212. return;
  213. parent::bulk_actions( $which );
  214. }
  215. function extra_tablenav( $which ) {
  216. global $status;
  217. if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) )
  218. return;
  219. echo '<div class="alignleft actions">';
  220. $screen = get_current_screen();
  221. if ( ! $screen->is_network && 'recently_activated' == $status )
  222. submit_button( __( 'Clear List' ), 'secondary', 'clear-recent-list', false );
  223. elseif ( 'top' == $which && 'mustuse' == $status )
  224. echo '<p>' . sprintf( __( 'Files in the <code>%s</code> directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '</p>';
  225. elseif ( 'top' == $which && 'dropins' == $status )
  226. 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>';
  227. echo '</div>';
  228. }
  229. function current_action() {
  230. if ( isset($_POST['clear-recent-list']) )
  231. return 'clear-recent-list';
  232. return parent::current_action();
  233. }
  234. function display_rows() {
  235. global $status;
  236. $screen = get_current_screen();
  237. if ( is_multisite() && !$screen->is_network && in_array( $status, array( 'mustuse', 'dropins' ) ) )
  238. return;
  239. foreach ( $this->items as $plugin_file => $plugin_data )
  240. $this->single_row( $plugin_file, $plugin_data );
  241. }
  242. function single_row( $plugin_file, $plugin_data ) {
  243. global $status, $page, $s, $totals;
  244. $context = $status;
  245. $screen = get_current_screen();
  246. // preorder
  247. $actions = array(
  248. 'deactivate' => '',
  249. 'activate' => '',
  250. 'edit' => '',
  251. 'delete' => '',
  252. );
  253. if ( 'mustuse' == $context ) {
  254. $is_active = true;
  255. } elseif ( 'dropins' == $context ) {
  256. $dropins = _get_dropins();
  257. $plugin_name = $plugin_file;
  258. if ( $plugin_file != $plugin_data['Name'] )
  259. $plugin_name .= '<br/>' . $plugin_data['Name'];
  260. if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant
  261. $is_active = true;
  262. $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
  263. } elseif ( constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true
  264. $is_active = true;
  265. $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
  266. } else {
  267. $is_active = false;
  268. $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="attention">' . __('Inactive:') . '</span></strong> ' . sprintf( __( 'Requires <code>%s</code> in <code>wp-config.php</code>.' ), "define('" . $dropins[ $plugin_file ][1] . "', true);" ) . '</p>';
  269. }
  270. if ( $plugin_data['Description'] )
  271. $description .= '<p>' . $plugin_data['Description'] . '</p>';
  272. } else {
  273. if ( $screen->is_network )
  274. $is_active = is_plugin_active_for_network( $plugin_file );
  275. else
  276. $is_active = is_plugin_active( $plugin_file );
  277. if ( $screen->is_network ) {
  278. if ( $is_active ) {
  279. if ( current_user_can( 'manage_network_plugins' ) )
  280. $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
  281. } else {
  282. if ( current_user_can( 'manage_network_plugins' ) )
  283. $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
  284. if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) )
  285. $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
  286. }
  287. } else {
  288. if ( $is_active ) {
  289. $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Deactivate') . '</a>';
  290. } else {
  291. $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>';
  292. if ( ! is_multisite() && current_user_can('delete_plugins') )
  293. $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
  294. } // end if $is_active
  295. } // end if $screen->is_network
  296. if ( ( ! is_multisite() || $screen->is_network ) && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
  297. $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . esc_attr__('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
  298. } // end if $context
  299. $prefix = $screen->is_network ? 'network_admin_' : '';
  300. $actions = apply_filters( $prefix . 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context );
  301. $actions = apply_filters( $prefix . "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
  302. $class = $is_active ? 'active' : 'inactive';
  303. $checkbox_id = "checkbox_" . md5($plugin_data['Name']);
  304. $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>";
  305. if ( 'dropins' != $context ) {
  306. $description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : '&nbsp;' ) . '</p>';
  307. $plugin_name = $plugin_data['Name'];
  308. }
  309. $id = sanitize_title( $plugin_name );
  310. if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) )
  311. $class .= ' update';
  312. echo "<tr id='$id' class='$class'>";
  313. list( $columns, $hidden ) = $this->get_column_info();
  314. foreach ( $columns as $column_name => $column_display_name ) {
  315. $style = '';
  316. if ( in_array( $column_name, $hidden ) )
  317. $style = ' style="display:none;"';
  318. switch ( $column_name ) {
  319. case 'cb':
  320. echo "<th scope='row' class='check-column'>$checkbox</th>";
  321. break;
  322. case 'name':
  323. echo "<td class='plugin-title'$style><strong>$plugin_name</strong>";
  324. echo $this->row_actions( $actions, true );
  325. echo "</td>";
  326. break;
  327. case 'description':
  328. echo "<td class='column-description desc'$style>
  329. <div class='plugin-description'>$description</div>
  330. <div class='$class second plugin-version-author-uri'>";
  331. $plugin_meta = array();
  332. if ( !empty( $plugin_data['Version'] ) )
  333. $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
  334. if ( !empty( $plugin_data['Author'] ) ) {
  335. $author = $plugin_data['Author'];
  336. if ( !empty( $plugin_data['AuthorURI'] ) )
  337. $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . esc_attr__( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
  338. $plugin_meta[] = sprintf( __( 'By %s' ), $author );
  339. }
  340. if ( ! empty( $plugin_data['PluginURI'] ) )
  341. $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . esc_attr__( 'Visit plugin site' ) . '">' . __( 'Visit plugin site' ) . '</a>';
  342. $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status );
  343. echo implode( ' | ', $plugin_meta );
  344. echo "</div></td>";
  345. break;
  346. default:
  347. echo "<td class='$column_name column-$column_name'$style>";
  348. do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data );
  349. echo "</td>";
  350. }
  351. }
  352. echo "</tr>";
  353. do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status );
  354. do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status );
  355. }
  356. }