~canonical-sysadmins/wordpress/4.2.4

« back to all changes in this revision

Viewing changes to wp-admin/includes/plugin.php

  • Committer: Nick Moffitt
  • Date: 2015-01-15 11:05:37 UTC
  • mfrom: (1.1.1 wp4-upstream)
  • Revision ID: nick.moffitt@canonical.com-20150115110537-8bp1y42eyg0jsa7c
Tags: 4.1
MergeĀ upstreamĀ versionĀ 4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 * must not have any newlines or only parts of the description will be displayed
15
15
 * and the same goes for the plugin data. The below is formatted for printing.
16
16
 *
17
 
 * <code>
18
 
 * /*
19
 
 * Plugin Name: Name of Plugin
20
 
 * Plugin URI: Link to plugin information
21
 
 * Description: Plugin Description
22
 
 * Author: Plugin author's name
23
 
 * Author URI: Link to the author's web site
24
 
 * Version: Must be set in the plugin for WordPress 2.3+
25
 
 * Text Domain: Optional. Unique identifier, should be same as the one used in
26
 
 *              plugin_text_domain()
27
 
 * Domain Path: Optional. Only useful if the translations are located in a
28
 
 *              folder above the plugin's base path. For example, if .mo files are
29
 
 *              located in the locale folder then Domain Path will be "/locale/" and
30
 
 *              must have the first slash. Defaults to the base folder the plugin is
31
 
 *              located in.
32
 
 * Network: Optional. Specify "Network: true" to require that a plugin is activated
33
 
 *              across all sites in an installation. This will prevent a plugin from being
34
 
 *              activated on a single site when Multisite is enabled.
35
 
 *  * / # Remove the space to close comment
36
 
 * </code>
 
17
 *     /*
 
18
 *     Plugin Name: Name of Plugin
 
19
 *     Plugin URI: Link to plugin information
 
20
 *     Description: Plugin Description
 
21
 *     Author: Plugin author's name
 
22
 *     Author URI: Link to the author's web site
 
23
 *     Version: Must be set in the plugin for WordPress 2.3+
 
24
 *     Text Domain: Optional. Unique identifier, should be same as the one used in
 
25
 *              plugin_text_domain()
 
26
 *     Domain Path: Optional. Only useful if the translations are located in a
 
27
 *              folder above the plugin's base path. For example, if .mo files are
 
28
 *              located in the locale folder then Domain Path will be "/locale/" and
 
29
 *              must have the first slash. Defaults to the base folder the plugin is
 
30
 *              located in.
 
31
 *     Network: Optional. Specify "Network: true" to require that a plugin is activated
 
32
 *              across all sites in an installation. This will prevent a plugin from being
 
33
 *              activated on a single site when Multisite is enabled.
 
34
 *      * / # Remove the space to close comment
37
35
 *
38
36
 * Plugin data returned array contains the following:
39
 
 *              'Name' - Name of the plugin, must be unique.
40
 
 *              'Title' - Title of the plugin and the link to the plugin's web site.
41
 
 *              'Description' - Description of what the plugin does and/or notes
42
 
 *              from the author.
43
 
 *              'Author' - The author's name
44
 
 *              'AuthorURI' - The authors web site address.
45
 
 *              'Version' - The plugin version number.
46
 
 *              'PluginURI' - Plugin web site address.
47
 
 *              'TextDomain' - Plugin's text domain for localization.
48
 
 *              'DomainPath' - Plugin's relative directory path to .mo files.
49
 
 *              'Network' - Boolean. Whether the plugin can only be activated network wide.
 
37
 *
 
38
 * - 'Name' - Name of the plugin, must be unique.
 
39
 * - 'Title' - Title of the plugin and the link to the plugin's web site.
 
40
 * - 'Description' - Description of what the plugin does and/or notes
 
41
 * - from the author.
 
42
 * - 'Author' - The author's name
 
43
 * - 'AuthorURI' - The authors web site address.
 
44
 * - 'Version' - The plugin version number.
 
45
 * - 'PluginURI' - Plugin web site address.
 
46
 * - 'TextDomain' - Plugin's text domain for localization.
 
47
 * - 'DomainPath' - Plugin's relative directory path to .mo files.
 
48
 * - 'Network' - Boolean. Whether the plugin can only be activated network wide.
50
49
 *
51
50
 * Some users have issues with opening large files and manipulating the contents
52
51
 * for want is usually the first 1kiB or 2kiB. This function stops pulling in
60
59
 * the file. This is not checked however and the file is only opened for
61
60
 * reading.
62
61
 *
63
 
 * @link http://trac.wordpress.org/ticket/5651 Previous Optimizations.
64
 
 * @link http://trac.wordpress.org/ticket/7372 Further and better Optimizations.
 
62
 * @link https://core.trac.wordpress.org/ticket/5651 Previous Optimizations.
 
63
 * @link https://core.trac.wordpress.org/ticket/7372 Further and better Optimizations.
 
64
 *
65
65
 * @since 1.5.0
66
66
 *
67
67
 * @param string $plugin_file Path to the plugin file
533
533
        if ( is_wp_error($valid) )
534
534
                return $valid;
535
535
 
536
 
        if ( !in_array($plugin, $current) ) {
 
536
        if ( ( $network_wide && ! isset( $current[ $plugin ] ) ) || ( ! $network_wide && ! in_array( $plugin, $current ) ) ) {
537
537
                if ( !empty($redirect) )
538
538
                        wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error
539
539
                ob_start();
558
558
                        do_action( 'activate_plugin', $plugin, $network_wide );
559
559
 
560
560
                        /**
561
 
                         * Fires as a specific plugin is being deactivated.
 
561
                         * Fires as a specific plugin is being activated.
562
562
                         *
563
 
                         * This hook is the "deactivation" hook used internally by
564
 
                         * register_deactivation_hook(). The dynamic portion of the
565
 
                         * hook name, $plugin. refers to the plugin basename.
 
563
                         * This hook is the "activation" hook used internally by
 
564
                         * {@see register_activation_hook()}. The dynamic portion of the
 
565
                         * hook name, `$plugin`, refers to the plugin basename.
566
566
                         *
567
567
                         * If a plugin is silently activated (such as during an update),
568
568
                         * this hook does not fire.
674
674
                         * Fires as a specific plugin is being deactivated.
675
675
                         *
676
676
                         * This hook is the "deactivation" hook used internally by
677
 
                         * register_deactivation_hook(). The dynamic portion of the
678
 
                         * hook name, $plugin. refers to the plugin basename.
 
677
                         * {@see register_deactivation_hook()}. The dynamic portion of the
 
678
                         * hook name, `$plugin`, refers to the plugin basename.
679
679
                         *
680
680
                         * If a plugin is silently deactivated (such as during an update),
681
681
                         * this hook does not fire.
797
797
        if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
798
798
                return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
799
799
 
800
 
        //Get the base plugin folder
 
800
        // Get the base plugin folder.
801
801
        $plugins_dir = $wp_filesystem->wp_plugins_dir();
802
 
        if ( empty($plugins_dir) )
803
 
                return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.'));
 
802
        if ( empty( $plugins_dir ) ) {
 
803
                return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress Plugin directory.' ) );
 
804
        }
804
805
 
805
806
        $plugins_dir = trailingslashit( $plugins_dir );
806
807
 
 
808
        $translations_dir = $wp_filesystem->wp_lang_dir();
 
809
        $translations_dir = trailingslashit( $translations_dir );
 
810
 
 
811
        $plugin_translations = wp_get_installed_translations( 'plugins' );
 
812
 
807
813
        $errors = array();
808
814
 
809
815
        foreach( $plugins as $plugin_file ) {
810
 
                // Run Uninstall hook
811
 
                if ( is_uninstallable_plugin( $plugin_file ) )
 
816
                // Run Uninstall hook.
 
817
                if ( is_uninstallable_plugin( $plugin_file ) ) {
812
818
                        uninstall_plugin($plugin_file);
 
819
                }
813
820
 
814
 
                $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin_file) );
 
821
                $this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin_file ) );
815
822
                // If plugin is in its own directory, recursively delete the directory.
816
 
                if ( strpos($plugin_file, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory separator AND that it's not the root plugin folder
817
 
                        $deleted = $wp_filesystem->delete($this_plugin_dir, true);
818
 
                else
819
 
                        $deleted = $wp_filesystem->delete($plugins_dir . $plugin_file);
 
823
                if ( strpos( $plugin_file, '/' ) && $this_plugin_dir != $plugins_dir ) { //base check on if plugin includes directory separator AND that it's not the root plugin folder
 
824
                        $deleted = $wp_filesystem->delete( $this_plugin_dir, true );
 
825
                } else {
 
826
                        $deleted = $wp_filesystem->delete( $plugins_dir . $plugin_file );
 
827
                }
820
828
 
821
 
                if ( ! $deleted )
 
829
                if ( ! $deleted ) {
822
830
                        $errors[] = $plugin_file;
 
831
                        continue;
 
832
                }
 
833
 
 
834
                // Remove language files, silently.
 
835
                $plugin_slug = dirname( $plugin_file );
 
836
                if ( '.' !== $plugin_slug && ! empty( $plugin_translations[ $plugin_slug ] ) ) {
 
837
                        $translations = $plugin_translations[ $plugin_slug ];
 
838
 
 
839
                        foreach ( $translations as $translation => $data ) {
 
840
                                $wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.po' );
 
841
                                $wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.mo' );
 
842
                        }
 
843
                }
823
844
        }
824
845
 
825
846
        // Remove deleted plugins from the plugin updates list.
1098
1119
 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
1099
1120
 * @param callback $function The function to be called to output the content for this page.
1100
1121
 *
1101
 
 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required.
 
1122
 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
1102
1123
 */
1103
1124
function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
1104
1125
        global $submenu;
1168
1189
 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
1169
1190
 * @param callback $function The function to be called to output the content for this page.
1170
1191
 *
1171
 
 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required.
 
1192
 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
1172
1193
 */
1173
1194
function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
1174
1195
        return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function );
1189
1210
 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
1190
1211
 * @param callback $function The function to be called to output the content for this page.
1191
1212
 *
1192
 
 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required.
 
1213
 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
1193
1214
 */
1194
1215
function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
1195
1216
        return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $function );
1210
1231
 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
1211
1232
 * @param callback $function The function to be called to output the content for this page.
1212
1233
 *
1213
 
 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required.
 
1234
 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
1214
1235
 */
1215
1236
function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
1216
1237
        return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $function );
1231
1252
 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
1232
1253
 * @param callback $function The function to be called to output the content for this page.
1233
1254
 *
1234
 
 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required.
 
1255
 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
1235
1256
 */
1236
1257
function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
1237
1258
        return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $function );
1252
1273
 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
1253
1274
 * @param callback $function The function to be called to output the content for this page.
1254
1275
 *
1255
 
 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required.
 
1276
 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
1256
1277
 */
1257
1278
function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
1258
1279
        if ( current_user_can('edit_users') )
1276
1297
 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
1277
1298
 * @param callback $function The function to be called to output the content for this page.
1278
1299
 *
1279
 
 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required.
 
1300
 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
1280
1301
 */
1281
1302
function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
1282
1303
        return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $function );
1297
1318
 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
1298
1319
 * @param callback $function The function to be called to output the content for this page.
1299
1320
 *
1300
 
 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required.
 
1321
 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
1301
1322
 */
1302
1323
function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
1303
1324
        return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $function );
1318
1339
 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
1319
1340
 * @param callback $function The function to be called to output the content for this page.
1320
1341
 *
1321
 
 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required.
 
1342
 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
1322
1343
 */
1323
1344
function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
1324
1345
        return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $function );
1339
1360
 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
1340
1361
 * @param callback $function The function to be called to output the content for this page.
1341
1362
 *
1342
 
 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required.
 
1363
 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
1343
1364
 */
1344
1365
function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
1345
1366
        return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $function );
1360
1381
 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
1361
1382
 * @param callback $function The function to be called to output the content for this page.
1362
1383
 *
1363
 
 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required.
 
1384
 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
1364
1385
*/
1365
1386
function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
1366
1387
        return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function );
1381
1402
 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
1382
1403
 * @param callback $function The function to be called to output the content for this page.
1383
1404
 *
1384
 
 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required.
 
1405
 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
1385
1406
*/
1386
1407
function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
1387
1408
        return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function );
1723
1744
 * @param string $option_group A settings group name. Should correspond to a whitelisted option key name.
1724
1745
 *      Default whitelisted option key names include "general," "discussion," and "reading," among others.
1725
1746
 * @param string $option_name The name of an option to sanitize and save.
1726
 
 * @param unknown_type $sanitize_callback A callback function that sanitizes the option's value.
1727
 
 * @return unknown
 
1747
 * @param callable $sanitize_callback A callback function that sanitizes the option's value.
1728
1748
 */
1729
1749
function register_setting( $option_group, $option_name, $sanitize_callback = '' ) {
1730
1750
        global $new_whitelist_options;
1749
1769
 *
1750
1770
 * @since 2.7.0
1751
1771
 *
1752
 
 * @param unknown_type $option_group
1753
 
 * @param unknown_type $option_name
1754
 
 * @param unknown_type $sanitize_callback
1755
 
 * @return unknown
 
1772
 * @param string   $option_group
 
1773
 * @param string   $option_name
 
1774
 * @param callable $sanitize_callback
1756
1775
 */
1757
1776
function unregister_setting( $option_group, $option_name, $sanitize_callback = '' ) {
1758
1777
        global $new_whitelist_options;
1779
1798
 *
1780
1799
 * @since 2.7.0
1781
1800
 *
1782
 
 * @param unknown_type $options
1783
 
 * @return unknown
 
1801
 * @param array $options
 
1802
 * @return array
1784
1803
 */
1785
1804
function option_update_filter( $options ) {
1786
1805
        global $new_whitelist_options;
1797
1816
 *
1798
1817
 * @since 2.7.0
1799
1818
 *
1800
 
 * @param unknown_type $new_options
1801
 
 * @param unknown_type $options
1802
 
 * @return unknown
 
1819
 * @param array        $new_options
 
1820
 * @param string|array $options
 
1821
 * @return array
1803
1822
 */
1804
1823
function add_option_whitelist( $new_options, $options = '' ) {
1805
1824
        if ( $options == '' )
1828
1847
 *
1829
1848
 * @since 2.7.0
1830
1849
 *
1831
 
 * @param unknown_type $del_options
1832
 
 * @param unknown_type $options
1833
 
 * @return unknown
 
1850
 * @param array        $del_options
 
1851
 * @param string|array $options
 
1852
 * @return array
1834
1853
 */
1835
1854
function remove_option_whitelist( $del_options, $options = '' ) {
1836
1855
        if ( $options == '' )