PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/plugins.php

https://gitlab.com/endomorphosis/reservationtelco
PHP | 785 lines | 658 code | 96 blank | 31 comment | 159 complexity | 9037f8efe40a95265eee26164fe5fc60 MD5 | raw file
  1. <?php
  2. /**
  3. * Plugins administration panel.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** WordPress Administration Bootstrap */
  9. require_once('./admin.php');
  10. if ( ! current_user_can( 'activate_plugins' ) )
  11. wp_die( __( 'You do not have sufficient permissions to manage plugins for this site.' ) );
  12. if ( isset($_POST['clear-recent-list']) )
  13. $action = 'clear-recent-list';
  14. elseif ( !empty($_REQUEST['action']) )
  15. $action = $_REQUEST['action'];
  16. elseif ( !empty($_REQUEST['action2']) )
  17. $action = $_REQUEST['action2'];
  18. else
  19. $action = false;
  20. $plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '';
  21. $default_status = get_user_option('plugins_last_view');
  22. if ( empty($default_status) )
  23. $default_status = 'all';
  24. $status = isset($_REQUEST['plugin_status']) ? $_REQUEST['plugin_status'] : $default_status;
  25. if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade', 'network', 'mustuse', 'dropins', 'search')) )
  26. $status = 'all';
  27. if ( $status != $default_status && 'search' != $status )
  28. update_user_meta($current_user->ID, 'plugins_last_view', $status);
  29. $page = isset($_REQUEST['paged']) ? $_REQUEST['paged'] : 1;
  30. //Clean up request URI from temporary args for screen options/paging uri's to work as expected.
  31. $_SERVER['REQUEST_URI'] = remove_query_arg(array('error', 'deleted', 'activate', 'activate-multi', 'deactivate', 'deactivate-multi', '_error_nonce'), $_SERVER['REQUEST_URI']);
  32. if ( !empty($action) ) {
  33. $network_wide = false;
  34. if ( ( isset( $_GET['networkwide'] ) || 'network-activate-selected' == $action ) && is_multisite() && current_user_can( 'manage_network_plugins' ) )
  35. $network_wide = true;
  36. switch ( $action ) {
  37. case 'activate':
  38. if ( ! current_user_can('activate_plugins') )
  39. wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
  40. check_admin_referer('activate-plugin_' . $plugin);
  41. $result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin, $network_wide);
  42. if ( is_wp_error( $result ) ) {
  43. if ( 'unexpected_output' == $result->get_error_code() ) {
  44. $redirect = 'plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin;
  45. wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect));
  46. exit;
  47. } else {
  48. wp_die($result);
  49. }
  50. }
  51. $recent = (array)get_option('recently_activated');
  52. if ( isset($recent[ $plugin ]) ) {
  53. unset($recent[ $plugin ]);
  54. update_option('recently_activated', $recent);
  55. }
  56. if ( isset($_GET['from']) && 'import' == $_GET['from'] ) {
  57. wp_redirect("import.php?import=" . str_replace('-importer', '', dirname($plugin)) ); // overrides the ?error=true one above and redirects to the Imports page, striping the -importer suffix
  58. } else {
  59. wp_redirect("plugins.php?activate=true&plugin_status=$status&paged=$page"); // overrides the ?error=true one above
  60. }
  61. exit;
  62. break;
  63. case 'activate-selected':
  64. case 'network-activate-selected':
  65. if ( ! current_user_can('activate_plugins') )
  66. wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
  67. check_admin_referer('bulk-manage-plugins');
  68. $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  69. $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); // Only activate plugins which are not already active.
  70. if ( empty($plugins) ) {
  71. wp_redirect("plugins.php?plugin_status=$status&paged=$page");
  72. exit;
  73. }
  74. activate_plugins($plugins, 'plugins.php?error=true', $network_wide);
  75. $recent = (array)get_option('recently_activated');
  76. foreach ( $plugins as $plugin => $time)
  77. if ( isset($recent[ $plugin ]) )
  78. unset($recent[ $plugin ]);
  79. update_option('recently_activated', $recent);
  80. wp_redirect("plugins.php?activate-multi=true&plugin_status=$status&paged=$page");
  81. exit;
  82. break;
  83. case 'update-selected' :
  84. check_admin_referer( 'bulk-manage-plugins' );
  85. if ( isset( $_GET['plugins'] ) )
  86. $plugins = explode( ',', $_GET['plugins'] );
  87. elseif ( isset( $_POST['checked'] ) )
  88. $plugins = (array) $_POST['checked'];
  89. else
  90. $plugins = array();
  91. $title = __( 'Upgrade Plugins' );
  92. $parent_file = 'plugins.php';
  93. require_once( './admin-header.php' );
  94. echo '<div class="wrap">';
  95. screen_icon();
  96. echo '<h2>' . esc_html( $title ) . '</h2>';
  97. $url = 'update.php?action=update-selected&amp;plugins=' . urlencode( join(',', $plugins) );
  98. $url = wp_nonce_url($url, 'bulk-update-plugins');
  99. echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
  100. echo '</div>';
  101. require_once( './admin-footer.php' );
  102. exit;
  103. break;
  104. case 'error_scrape':
  105. if ( ! current_user_can('activate_plugins') )
  106. wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
  107. check_admin_referer('plugin-activation-error_' . $plugin);
  108. $valid = validate_plugin($plugin);
  109. if ( is_wp_error($valid) )
  110. wp_die($valid);
  111. if ( ! WP_DEBUG ) {
  112. if ( defined('E_RECOVERABLE_ERROR') )
  113. error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR);
  114. else
  115. error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
  116. }
  117. @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
  118. // Go back to "sandbox" scope so we get the same errors as before
  119. function plugin_sandbox_scrape( $plugin ) {
  120. include( WP_PLUGIN_DIR . '/' . $plugin );
  121. }
  122. plugin_sandbox_scrape( $plugin );
  123. do_action('activate_' . $plugin);
  124. exit;
  125. break;
  126. case 'deactivate':
  127. if ( ! current_user_can('activate_plugins') )
  128. wp_die(__('You do not have sufficient permissions to deactivate plugins for this site.'));
  129. check_admin_referer('deactivate-plugin_' . $plugin);
  130. deactivate_plugins($plugin);
  131. update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated'));
  132. if (headers_sent())
  133. echo "<meta http-equiv='refresh' content='" . esc_attr( "0;url=plugins.php?deactivate=true&plugin_status=$status&paged=$page" ) . "' />";
  134. else
  135. wp_redirect("plugins.php?deactivate=true&plugin_status=$status&paged=$page");
  136. exit;
  137. break;
  138. case 'deactivate-selected':
  139. if ( ! current_user_can('activate_plugins') )
  140. wp_die(__('You do not have sufficient permissions to deactivate plugins for this site.'));
  141. check_admin_referer('bulk-manage-plugins');
  142. $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  143. $plugins = array_filter($plugins, 'is_plugin_active'); //Do not deactivate plugins which are already deactivated.
  144. if ( empty($plugins) ) {
  145. wp_redirect("plugins.php?plugin_status=$status&paged=$page");
  146. exit;
  147. }
  148. deactivate_plugins($plugins);
  149. $deactivated = array();
  150. foreach ( $plugins as $plugin )
  151. $deactivated[ $plugin ] = time();
  152. update_option('recently_activated', $deactivated + (array)get_option('recently_activated'));
  153. wp_redirect("plugins.php?deactivate-multi=true&plugin_status=$status&paged=$page");
  154. exit;
  155. break;
  156. case 'delete-selected':
  157. if ( ! current_user_can('delete_plugins') )
  158. wp_die(__('You do not have sufficient permissions to delete plugins for this site.'));
  159. check_admin_referer('bulk-manage-plugins');
  160. //$_POST = from the plugin form; $_GET = from the FTP details screen.
  161. $plugins = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
  162. $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); //Do not allow to delete Activated plugins.
  163. if ( empty($plugins) ) {
  164. wp_redirect("plugins.php?plugin_status=$status&paged=$page");
  165. exit;
  166. }
  167. include(ABSPATH . 'wp-admin/update.php');
  168. $parent_file = 'plugins.php';
  169. if ( ! isset($_REQUEST['verify-delete']) ) {
  170. wp_enqueue_script('jquery');
  171. require_once('./admin-header.php');
  172. ?>
  173. <div class="wrap">
  174. <?php
  175. $files_to_delete = $plugin_info = array();
  176. foreach ( (array) $plugins as $plugin ) {
  177. if ( '.' == dirname($plugin) ) {
  178. $files_to_delete[] = WP_PLUGIN_DIR . '/' . $plugin;
  179. if( $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin) ) {
  180. $plugin_info[ $plugin ] = $data;
  181. $plugin_info[ $plugin ]['is_uninstallable'] = is_uninstallable_plugin( $plugin );
  182. }
  183. } else {
  184. // Locate all the files in that folder
  185. $files = list_files( WP_PLUGIN_DIR . '/' . dirname($plugin) );
  186. if ( $files ) {
  187. $files_to_delete = array_merge($files_to_delete, $files);
  188. }
  189. // Get plugins list from that folder
  190. if ( $folder_plugins = get_plugins( '/' . dirname($plugin)) ) {
  191. foreach( $folder_plugins as $plugin_file => $data ) {
  192. $plugin_info[ $plugin_file ] = $data;
  193. $plugin_info[ $plugin_file ]['is_uninstallable'] = is_uninstallable_plugin( $plugin );
  194. }
  195. }
  196. }
  197. }
  198. screen_icon();
  199. $plugins_to_delete = count( $plugin_info );
  200. echo '<h2>' . _n( 'Delete Plugin', 'Delete Plugins', $plugins_to_delete ) . '</h2>';
  201. ?>
  202. <p><?php echo _n( 'You are about to remove the following plugin:', 'You are about to remove the following plugins:', $plugins_to_delete ); ?></p>
  203. <ul class="ul-disc">
  204. <?php
  205. $data_to_delete = false;
  206. foreach ( $plugin_info as $plugin ) {
  207. if ( $plugin['is_uninstallable'] ) {
  208. /* translators: 1: plugin name, 2: plugin author */
  209. echo '<li>', sprintf( __( '<strong>%1$s</strong> by <em>%2$s</em> (will also <strong>delete its data</strong>)' ), $plugin['Name'], $plugin['Author'] ), '</li>';
  210. $data_to_delete = true;
  211. } else {
  212. /* translators: 1: plugin name, 2: plugin author */
  213. echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), $plugin['Name'], $plugin['Author'] ), '</li>';
  214. }
  215. }
  216. ?>
  217. </ul>
  218. <p><?php
  219. if ( $data_to_delete )
  220. _e('Are you sure you wish to delete these files and data?');
  221. else
  222. _e('Are you sure you wish to delete these files?');
  223. ?></p>
  224. <form method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;">
  225. <input type="hidden" name="verify-delete" value="1" />
  226. <input type="hidden" name="action" value="delete-selected" />
  227. <?php
  228. foreach ( (array)$plugins as $plugin )
  229. echo '<input type="hidden" name="checked[]" value="' . esc_attr($plugin) . '" />';
  230. ?>
  231. <?php wp_nonce_field('bulk-manage-plugins') ?>
  232. <input type="submit" name="submit" value="<?php $data_to_delete ? esc_attr_e('Yes, Delete these files and data') : esc_attr_e('Yes, Delete these files') ?>" class="button" />
  233. </form>
  234. <form method="post" action="<?php echo esc_url(wp_get_referer()); ?>" style="display:inline;">
  235. <input type="submit" name="submit" value="<?php esc_attr_e('No, Return me to the plugin list') ?>" class="button" />
  236. </form>
  237. <p><a href="#" onclick="jQuery('#files-list').toggle(); return false;"><?php _e('Click to view entire list of files which will be deleted'); ?></a></p>
  238. <div id="files-list" style="display:none;">
  239. <ul class="code">
  240. <?php
  241. foreach ( (array)$files_to_delete as $file )
  242. echo '<li>' . str_replace(WP_PLUGIN_DIR, '', $file) . '</li>';
  243. ?>
  244. </ul>
  245. </div>
  246. </div>
  247. <?php
  248. require_once('./admin-footer.php');
  249. exit;
  250. } //Endif verify-delete
  251. $delete_result = delete_plugins($plugins);
  252. set_transient('plugins_delete_result_'.$user_ID, $delete_result); //Store the result in a cache rather than a URL param due to object type & length
  253. wp_redirect("plugins.php?deleted=true&plugin_status=$status&paged=$page");
  254. exit;
  255. break;
  256. case 'clear-recent-list':
  257. update_option('recently_activated', array());
  258. break;
  259. }
  260. }
  261. wp_enqueue_script('plugin-install');
  262. add_thickbox();
  263. add_contextual_help($current_screen,
  264. '<p>' . __('Plugins extend and expand the functionality of WordPress. Once a plugin is installed, you may activate it or deactivate it here.') . '</p>' .
  265. '<p>' . sprintf(__('You can find additional plugins for your site by using the <a href="%1$s">Plugin Browser/Installer</a> functionality or by browsing the <a href="%2$s">WordPress Plugin Directory</a> directly and installing new plugins manually. To manually install a plugin you generally just need to upload the plugin file into your <code>/wp-content/plugins</code> directory. Once a plugin has been installed, you can activate it here.'), 'plugin-install.php', 'http://wordpress.org/extend/plugins/') . '</p>' .
  266. '<p>' . __('Most of the time, plugins play nicely with the core of WordPress and with other plugins. Sometimes, though, a plugin&#8217;s code will get in the way of another plugin, causing compatibility issues. If your site starts doing strange things, this may be the problem. Try deactivating all your plugins and re-activating them in various combinations until you isolate which one(s) caused the issue.') . '</p>' .
  267. '<p>' . sprintf( __('If something goes wrong with a plugin and you can&#8217;t use WordPress, delete or rename that file in the <code>%s</code> directory and it will be automatically deactivated.'), WP_PLUGIN_DIR) . '</p>' .
  268. '<p><strong>' . __('For more information:') . '</strong></p>' .
  269. '<p>' . __('<a href="http://codex.wordpress.org/Managing_Plugins#Plugin_Management">Documentation on Managing Plugins</a>') . '</p>' .
  270. '<p>' . __('<a href="http://wordpress.org/support/">Support Forums</a>') . '</p>'
  271. );
  272. if ( is_multisite() && is_super_admin() ) {
  273. $menu_perms = get_site_option('menu_items', array());
  274. if ( empty($menu_perms['plugins']) )
  275. add_action( 'admin_notices', '_admin_notice_multisite_activate_plugins_page' );
  276. unset($menu_perms);
  277. }
  278. $title = __('Plugins');
  279. require_once('./admin-header.php');
  280. $invalid = validate_active_plugins();
  281. if ( !empty($invalid) )
  282. foreach ( $invalid as $plugin_file => $error )
  283. echo '<div id="message" class="error"><p>' . sprintf(__('The plugin <code>%s</code> has been <strong>deactivated</strong> due to an error: %s'), esc_html($plugin_file), $error->get_error_message()) . '</p></div>';
  284. ?>
  285. <?php if ( isset($_GET['error']) ) :
  286. if ( isset($_GET['charsout']) )
  287. $errmsg = sprintf(__('The plugin generated %d characters of <strong>unexpected output</strong> during activation. If you notice &#8220;headers already sent&#8221; messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.'), $_GET['charsout']);
  288. else
  289. $errmsg = __('Plugin could not be activated because it triggered a <strong>fatal error</strong>.');
  290. ?>
  291. <div id="message" class="updated"><p><?php echo $errmsg; ?></p>
  292. <?php
  293. if ( !isset($_GET['charsout']) && wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) ) { ?>
  294. <iframe style="border:0" width="100%" height="70px" src="<?php echo admin_url('plugins.php?action=error_scrape&amp;plugin=' . esc_attr($plugin) . '&amp;_wpnonce=' . esc_attr($_GET['_error_nonce'])); ?>"></iframe>
  295. <?php
  296. }
  297. ?>
  298. </div>
  299. <?php elseif ( isset($_GET['deleted']) ) :
  300. $delete_result = get_transient('plugins_delete_result_'.$user_ID);
  301. delete_transient('plugins_delete_result'); //Delete it once we're done.
  302. if ( is_wp_error($delete_result) ) : ?>
  303. <div id="message" class="updated"><p><?php printf( __('Plugin could not be deleted due to an error: %s'), $delete_result->get_error_message() ); ?></p></div>
  304. <?php else : ?>
  305. <div id="message" class="updated"><p><?php _e('The selected plugins have been <strong>deleted</strong>.'); ?></p></div>
  306. <?php endif; ?>
  307. <?php elseif ( isset($_GET['activate']) ) : ?>
  308. <div id="message" class="updated"><p><?php _e('Plugin <strong>activated</strong>.') ?></p></div>
  309. <?php elseif (isset($_GET['activate-multi'])) : ?>
  310. <div id="message" class="updated"><p><?php _e('Selected plugins <strong>activated</strong>.'); ?></p></div>
  311. <?php elseif ( isset($_GET['deactivate']) ) : ?>
  312. <div id="message" class="updated"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div>
  313. <?php elseif (isset($_GET['deactivate-multi'])) : ?>
  314. <div id="message" class="updated"><p><?php _e('Selected plugins <strong>deactivated</strong>.'); ?></p></div>
  315. <?php elseif ( 'update-selected' == $action ) : ?>
  316. <div id="message" class="updated"><p><?php _e('No out of date plugins were selected.'); ?></p></div>
  317. <?php endif; ?>
  318. <div class="wrap">
  319. <?php screen_icon(); ?>
  320. <h2><?php echo esc_html( $title ); if ( current_user_can('install_plugins') ) { ?> <a href="plugin-install.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'plugin'); ?></a><?php } ?></h2>
  321. <?php
  322. $all_plugins = apply_filters( 'all_plugins', get_plugins() );
  323. $search_plugins = array();
  324. $active_plugins = array();
  325. $inactive_plugins = array();
  326. $recent_plugins = array();
  327. $recently_activated = get_option('recently_activated', array());
  328. $upgrade_plugins = array();
  329. $network_plugins = array();
  330. $mustuse_plugins = $dropins_plugins = array();
  331. if ( ! is_multisite() || current_user_can('manage_network_plugins') ) {
  332. if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) )
  333. $mustuse_plugins = get_mu_plugins();
  334. if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) )
  335. $dropins_plugins = get_dropins();
  336. }
  337. set_transient( 'plugin_slugs', array_keys($all_plugins), 86400 );
  338. // Clean out any plugins which were deactivated over a week ago.
  339. foreach ( $recently_activated as $key => $time )
  340. if ( $time + (7*24*60*60) < time() ) //1 week
  341. unset($recently_activated[ $key ]);
  342. if ( $recently_activated != get_option('recently_activated') ) //If array changed, update it.
  343. update_option('recently_activated', $recently_activated);
  344. $current = get_site_transient( 'update_plugins' );
  345. foreach ( array( 'all_plugins', 'mustuse_plugins', 'dropins_plugins' ) as $plugin_array_name) {
  346. foreach ( (array) $$plugin_array_name as $plugin_file => $plugin_data ) {
  347. // Translate, Apply Markup, Sanitize HTML
  348. $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, false, true);
  349. ${$plugin_array_name}[ $plugin_file ] = $plugin_data;
  350. }
  351. }
  352. unset( $plugin_array_name );
  353. foreach ( (array) $all_plugins as $plugin_file => $plugin_data) {
  354. // Filter into individual sections
  355. if ( is_multisite() && is_network_only_plugin( $plugin_file ) && !current_user_can( 'manage_network_plugins' ) ) {
  356. unset( $all_plugins[ $plugin_file ] );
  357. continue;
  358. } elseif ( is_plugin_active_for_network($plugin_file) ) {
  359. $network_plugins[ $plugin_file ] = $plugin_data;
  360. } elseif ( is_plugin_active($plugin_file) ) {
  361. $active_plugins[ $plugin_file ] = $plugin_data;
  362. } else {
  363. if ( isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated?
  364. $recent_plugins[ $plugin_file ] = $plugin_data;
  365. $inactive_plugins[ $plugin_file ] = $plugin_data;
  366. }
  367. if ( isset( $current->response[ $plugin_file ] ) )
  368. $upgrade_plugins[ $plugin_file ] = $plugin_data;
  369. }
  370. if ( !current_user_can('update_plugins') )
  371. $upgrade_plugins = array();
  372. $total_all_plugins = count($all_plugins);
  373. $total_inactive_plugins = count($inactive_plugins);
  374. $total_active_plugins = count($active_plugins);
  375. $total_recent_plugins = count($recent_plugins);
  376. $total_upgrade_plugins = count($upgrade_plugins);
  377. $total_network_plugins = count($network_plugins);
  378. $total_mustuse_plugins = count($mustuse_plugins);
  379. $total_dropins_plugins = count($dropins_plugins);
  380. // Searching.
  381. if ( !empty($_GET['s']) ) {
  382. function _search_plugins_filter_callback($plugin) {
  383. static $term;
  384. if ( is_null($term) )
  385. $term = stripslashes($_GET['s']);
  386. if ( stripos($plugin['Name'], $term) !== false ||
  387. stripos($plugin['Description'], $term) !== false ||
  388. stripos($plugin['Author'], $term) !== false ||
  389. stripos($plugin['PluginURI'], $term) !== false ||
  390. stripos($plugin['AuthorURI'], $term) !== false ||
  391. stripos($plugin['Version'], $term) !== false )
  392. return true;
  393. else
  394. return false;
  395. }
  396. $status = 'search';
  397. $search_plugins = array_filter($all_plugins, '_search_plugins_filter_callback');
  398. $total_search_plugins = count($search_plugins);
  399. }
  400. $plugin_array_name = "${status}_plugins";
  401. if ( empty($$plugin_array_name) && !in_array($status, array('all', 'search')) ) {
  402. $status = 'all';
  403. $plugin_array_name = "${status}_plugins";
  404. }
  405. $plugins = &$$plugin_array_name;
  406. // Paging.
  407. $total_this_page = "total_{$status}_plugins";
  408. $total_this_page = $$total_this_page;
  409. $plugins_per_page = (int) get_user_option( 'plugins_per_page' );
  410. if ( empty( $plugins_per_page ) || $plugins_per_page < 1 )
  411. $plugins_per_page = 999;
  412. $plugins_per_page = apply_filters( 'plugins_per_page', $plugins_per_page );
  413. $start = ($page - 1) * $plugins_per_page;
  414. $page_links = paginate_links( array(
  415. 'base' => add_query_arg( 'paged', '%#%' ),
  416. 'format' => '',
  417. 'prev_text' => __('&laquo;'),
  418. 'next_text' => __('&raquo;'),
  419. 'total' => ceil($total_this_page / $plugins_per_page),
  420. 'current' => $page
  421. ));
  422. $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
  423. number_format_i18n( $start + 1 ),
  424. number_format_i18n( min( $page * $plugins_per_page, $total_this_page ) ),
  425. '<span class="total-type-count">' . number_format_i18n( $total_this_page ) . '</span>',
  426. $page_links
  427. );
  428. /**
  429. * @ignore
  430. *
  431. * @param array $plugins
  432. * @param string $context
  433. */
  434. function print_plugins_table($plugins, $context = '') {
  435. global $page;
  436. $checkbox = ! in_array( $context, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '';
  437. ?>
  438. <table class="widefat" cellspacing="0" id="<?php echo $context ?>-plugins-table">
  439. <thead>
  440. <tr>
  441. <th scope="col" class="manage-column check-column"><?php echo $checkbox; ?></th>
  442. <th scope="col" class="manage-column"><?php _e('Plugin'); ?></th>
  443. <th scope="col" class="manage-column"><?php _e('Description'); ?></th>
  444. </tr>
  445. </thead>
  446. <tfoot>
  447. <tr>
  448. <th scope="col" class="manage-column check-column"><?php echo $checkbox; ?></th>
  449. <th scope="col" class="manage-column"><?php _e('Plugin'); ?></th>
  450. <th scope="col" class="manage-column"><?php _e('Description'); ?></th>
  451. </tr>
  452. </tfoot>
  453. <tbody class="plugins">
  454. <?php
  455. if ( empty($plugins) ) {
  456. echo '<tr>
  457. <td colspan="3">' . __('No plugins to show') . '</td>
  458. </tr>';
  459. }
  460. foreach ( (array)$plugins as $plugin_file => $plugin_data) {
  461. // preorder
  462. $actions = array(
  463. 'network_deactivate' => '', 'deactivate' => '',
  464. 'network_only' => '', 'activate' => '',
  465. 'network_activate' => '',
  466. 'edit' => '',
  467. 'delete' => '',
  468. );
  469. if ( 'mustuse' == $context ) {
  470. $is_active = true;
  471. } elseif ( 'dropins' == $context ) {
  472. $dropins = _get_dropins();
  473. $plugin_name = $plugin_file;
  474. if ( $plugin_file != $plugin_data['Name'] )
  475. $plugin_name .= '<br/>' . $plugin_data['Name'];
  476. if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant
  477. $is_active = true;
  478. $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
  479. } elseif ( constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true
  480. $is_active = true;
  481. $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
  482. } else {
  483. $is_active = false;
  484. $description = '<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>';
  485. }
  486. $description .= '<p>' . $plugin_data['Description'] . '</p>';
  487. } else {
  488. $is_active_for_network = is_plugin_active_for_network($plugin_file);
  489. $is_active = $is_active_for_network || is_plugin_active( $plugin_file );
  490. if ( $is_active_for_network && !is_super_admin() )
  491. continue;
  492. if ( $is_active ) {
  493. if ( $is_active_for_network ) {
  494. if ( is_super_admin() )
  495. $actions['network_deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
  496. } else {
  497. $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>';
  498. }
  499. } else {
  500. if ( is_multisite() && is_network_only_plugin( $plugin_file ) )
  501. $actions['network_only'] = '<span title="' . __('This plugin can only be activated for all sites in a network') . '">' . __('Network Only') . '</span>';
  502. else
  503. $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>';
  504. if ( is_multisite() && current_user_can( 'manage_network_plugins' ) )
  505. $actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
  506. if ( current_user_can('delete_plugins') )
  507. $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'bulk-manage-plugins') . '" title="' . __('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
  508. } // end if $is_active
  509. if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
  510. $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
  511. } // end if $context
  512. $actions = apply_filters( 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context );
  513. $actions = apply_filters( "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
  514. $class = $is_active ? 'active' : 'inactive';
  515. $checkbox = in_array( $context, array( 'mustuse', 'dropins' ) ) ? '' : "<input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' />";
  516. if ( 'dropins' != $context ) {
  517. $description = '<p>' . $plugin_data['Description'] . '</p>';
  518. $plugin_name = $plugin_data['Name'];
  519. }
  520. echo "
  521. <tr class='$class'>
  522. <th scope='row' class='check-column'>$checkbox</th>
  523. <td class='plugin-title'><strong>$plugin_name</strong></td>
  524. <td class='desc'>$description</td>
  525. </tr>
  526. <tr class='$class second'>
  527. <td></td>
  528. <td class='plugin-title'>";
  529. echo '<div class="row-actions-visible">';
  530. foreach ( $actions as $action => $link ) {
  531. $sep = end($actions) == $link ? '' : ' | ';
  532. echo "<span class='$action'>$link$sep</span>";
  533. }
  534. echo "</div></td>
  535. <td class='desc'>";
  536. $plugin_meta = array();
  537. if ( !empty($plugin_data['Version']) )
  538. $plugin_meta[] = sprintf(__('Version %s'), $plugin_data['Version']);
  539. if ( !empty($plugin_data['Author']) ) {
  540. $author = $plugin_data['Author'];
  541. if ( !empty($plugin_data['AuthorURI']) )
  542. $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . __( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
  543. $plugin_meta[] = sprintf( __('By %s'), $author );
  544. }
  545. if ( ! empty($plugin_data['PluginURI']) )
  546. $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . __( 'Visit plugin site' ) . '">' . __('Visit plugin site') . '</a>';
  547. $plugin_meta = apply_filters('plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $context);
  548. echo implode(' | ', $plugin_meta);
  549. echo "</td>
  550. </tr>\n";
  551. do_action( 'after_plugin_row', $plugin_file, $plugin_data, $context );
  552. do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $context );
  553. }
  554. ?>
  555. </tbody>
  556. </table>
  557. <?php
  558. } //End print_plugins_table()
  559. /**
  560. * @ignore
  561. *
  562. * @param string $context
  563. */
  564. function print_plugin_actions($context, $field_name = 'action' ) {
  565. if ( in_array( $context, array( 'mustuse', 'dropins' ) ) )
  566. return;
  567. ?>
  568. <div class="alignleft actions">
  569. <select name="<?php echo $field_name; ?>">
  570. <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
  571. <?php if ( 'active' != $context ) : ?>
  572. <option value="activate-selected"><?php _e('Activate'); ?></option>
  573. <?php endif; ?>
  574. <?php if ( is_multisite() && 'network' != $context ) : ?>
  575. <option value="network-activate-selected"><?php _e('Network Activate'); ?></option>
  576. <?php endif; ?>
  577. <?php if ( 'inactive' != $context && 'recent' != $context ) : ?>
  578. <option value="deactivate-selected"><?php _e('Deactivate'); ?></option>
  579. <?php endif; ?>
  580. <?php if ( current_user_can( 'update_plugins' ) ) : ?>
  581. <option value="update-selected"><?php _e( 'Upgrade' ); ?></option>
  582. <?php endif; ?>
  583. <?php if ( current_user_can('delete_plugins') && ( 'active' != $context ) ) : ?>
  584. <option value="delete-selected"><?php _e('Delete'); ?></option>
  585. <?php endif; ?>
  586. </select>
  587. <input type="submit" name="doaction_active" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary action" />
  588. <?php if ( 'recent' == $context ) : ?>
  589. <input type="submit" name="clear-recent-list" value="<?php esc_attr_e('Clear List') ?>" class="button-secondary" />
  590. <?php endif; ?>
  591. </div>
  592. <?php
  593. }
  594. ?>
  595. <form method="get" action="">
  596. <p class="search-box">
  597. <label class="screen-reader-text" for="plugin-search-input"><?php _e( 'Search Plugins' ); ?>:</label>
  598. <input type="text" id="plugin-search-input" name="s" value="<?php _admin_search_query(); ?>" />
  599. <input type="submit" value="<?php esc_attr_e( 'Search Installed Plugins' ); ?>" class="button" />
  600. </p>
  601. </form>
  602. <?php do_action( 'pre_current_active_plugins', $all_plugins ) ?>
  603. <form method="post" action="<?php echo admin_url('plugins.php') ?>">
  604. <?php wp_nonce_field('bulk-manage-plugins') ?>
  605. <input type="hidden" name="plugin_status" value="<?php echo esc_attr($status) ?>" />
  606. <input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" />
  607. <ul class="subsubsub">
  608. <?php
  609. $status_links = array();
  610. $class = ( 'all' == $status ) ? ' class="current"' : '';
  611. $status_links[] = "<li><a href='plugins.php?plugin_status=all' $class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_all_plugins, 'plugins' ), number_format_i18n( $total_all_plugins ) ) . '</a>';
  612. if ( ! empty($active_plugins) ) {
  613. $class = ( 'active' == $status ) ? ' class="current"' : '';
  614. $status_links[] = "<li><a href='plugins.php?plugin_status=active' $class>" . sprintf( _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $total_active_plugins ), number_format_i18n( $total_active_plugins ) ) . '</a>';
  615. }
  616. if ( ! empty($recent_plugins) ) {
  617. $class = ( 'recent' == $status ) ? ' class="current"' : '';
  618. $status_links[] = "<li><a href='plugins.php?plugin_status=recent' $class>" . sprintf( _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $total_recent_plugins ), number_format_i18n( $total_recent_plugins ) ) . '</a>';
  619. }
  620. if ( ! empty($inactive_plugins) ) {
  621. $class = ( 'inactive' == $status ) ? ' class="current"' : '';
  622. $status_links[] = "<li><a href='plugins.php?plugin_status=inactive' $class>" . sprintf( _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $total_inactive_plugins ), number_format_i18n( $total_inactive_plugins ) ) . '</a>';
  623. }
  624. if ( ! empty($network_plugins) ) {
  625. $class = ( 'network' == $status ) ? ' class="current"' : '';
  626. $status_links[] = "<li><a href='plugins.php?plugin_status=network' $class>" . sprintf( _n( 'Network <span class="count">(%s)</span>', 'Network <span class="count">(%s)</span>', $total_network_plugins ), number_format_i18n( $total_network_plugins ) ) . '</a>';
  627. }
  628. if ( ! empty($mustuse_plugins) ) {
  629. $class = ( 'mustuse' == $status ) ? ' class="current"' : '';
  630. $status_links[] = "<li><a href='plugins.php?plugin_status=mustuse' $class>" . sprintf( _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $total_mustuse_plugins ), number_format_i18n( $total_mustuse_plugins ) ) . '</a>';
  631. }
  632. if ( ! empty($dropins_plugins) ) {
  633. $class = ( 'dropins' == $status ) ? ' class="current"' : '';
  634. $status_links[] = "<li><a href='plugins.php?plugin_status=dropins' $class>" . sprintf( _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $total_dropins_plugins ), number_format_i18n( $total_dropins_plugins ) ) . '</a>';
  635. }
  636. if ( ! empty($upgrade_plugins) ) {
  637. $class = ( 'upgrade' == $status ) ? ' class="current"' : '';
  638. $status_links[] = "<li><a href='plugins.php?plugin_status=upgrade' $class>" . sprintf( _n( 'Upgrade Available <span class="count">(%s)</span>', 'Upgrade Available <span class="count">(%s)</span>', $total_upgrade_plugins ), number_format_i18n( $total_upgrade_plugins ) ) . '</a>';
  639. }
  640. if ( ! empty($search_plugins) ) {
  641. $class = ( 'search' == $status ) ? ' class="current"' : '';
  642. $term = isset($_REQUEST['s']) ? urlencode(stripslashes($_REQUEST['s'])) : '';
  643. $status_links[] = "<li><a href='plugins.php?s=$term' $class>" . sprintf( _n( 'Search Results <span class="count">(%s)</span>', 'Search Results <span class="count">(%s)</span>', $total_search_plugins ), number_format_i18n( $total_search_plugins ) ) . '</a>';
  644. }
  645. echo implode( " |</li>\n", $status_links ) . '</li>';
  646. unset( $status_links );
  647. ?>
  648. </ul>
  649. <?php
  650. if ( 'mustuse' == $status )
  651. echo '<div class="clear"><p>' . __( 'Files in the <code>wp-content/mu-plugins</code> directory are executed automatically.' ) . '</p>';
  652. elseif ( 'dropins' == $status )
  653. echo '<div class="clear"><p>' . __( 'Drop-ins are advanced plugins in the <code>wp-content</code> directory that replace WordPress functionality when present.' ) . '</p>';
  654. if ( !empty( $plugins ) && ( ! in_array( $status, array( 'mustuse', 'dropins' ) ) || $page_links ) ) :
  655. ?>
  656. <div class="tablenav">
  657. <?php
  658. if ( $page_links )
  659. echo '<div class="tablenav-pages">', $page_links_text, '</div>';
  660. print_plugin_actions($status);
  661. ?>
  662. </div>
  663. <div class="clear"></div>
  664. <?php
  665. endif;
  666. if ( $total_this_page > $plugins_per_page )
  667. $plugins = array_slice($plugins, $start, $plugins_per_page);
  668. print_plugins_table($plugins, $status);
  669. if ( !empty( $plugins ) && ! in_array( $status, array( 'mustuse', 'dropins' ) ) || $page_links ) {
  670. ?>
  671. <div class="tablenav">
  672. <?php
  673. if ( $page_links )
  674. echo "<div class='tablenav-pages'>$page_links_text</div>";
  675. print_plugin_actions($status, "action2");
  676. ?>
  677. </div>
  678. <?php } elseif ( ! empty( $all_plugins ) ) { ?>
  679. <p><?php __( 'No plugins found.' ); ?></p>
  680. <?php } ?>
  681. </form>
  682. <?php if ( empty($all_plugins) ) : ?>
  683. <br class="clear" />
  684. <p><?php _e('You do not appear to have any plugins available at this time.') ?></p>
  685. <?php endif; ?>
  686. </div>
  687. <?php
  688. include('./admin-footer.php');
  689. ?>