X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/03f2fa83c13c1b532284205fa7efcab9b8b2c41f..febc815b2c9d85be5717da9e8d164bd2daa97e31:/wp-admin/includes/plugin.php diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index 1dfc977e..cf6b4bab 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -86,12 +86,20 @@ function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { // Site Wide Only is the old header for Network if ( ! $plugin_data['Network'] && $plugin_data['_sitewide'] ) { /* translators: 1: Site Wide Only: true, 2: Network: true */ - _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The %1$s plugin header is deprecated. Use %2$s instead.' ), 'Site Wide Only: true', 'Network: true' ) ); + _deprecated_argument( __FUNCTION__, '3.0.0', sprintf( __( 'The %1$s plugin header is deprecated. Use %2$s instead.' ), 'Site Wide Only: true', 'Network: true' ) ); $plugin_data['Network'] = $plugin_data['_sitewide']; } $plugin_data['Network'] = ( 'true' == strtolower( $plugin_data['Network'] ) ); unset( $plugin_data['_sitewide'] ); + // If no text domain is defined fall back to the plugin slug. + if ( ! $plugin_data['TextDomain'] ) { + $plugin_slug = dirname( plugin_basename( $plugin_file ) ); + if ( '.' !== $plugin_slug && false === strpos( $plugin_slug, '/' ) ) { + $plugin_data['TextDomain'] = $plugin_slug; + } + } + if ( $markup || $translate ) { $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate ); } else { @@ -117,11 +125,14 @@ function _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup // Translate fields if ( $translate ) { if ( $textdomain = $plugin_data['TextDomain'] ) { - if ( $plugin_data['DomainPath'] ) - load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) . $plugin_data['DomainPath'] ); - else - load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) ); - } elseif ( in_array( basename( $plugin_file ), array( 'hello.php', 'akismet.php' ) ) ) { + if ( ! is_textdomain_loaded( $textdomain ) ) { + if ( $plugin_data['DomainPath'] ) { + load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) . $plugin_data['DomainPath'] ); + } else { + load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) ); + } + } + } elseif ( 'hello.php' == basename( $plugin_file ) ) { $textdomain = 'default'; } if ( $textdomain ) { @@ -424,7 +435,12 @@ function _get_dropins() { } /** - * Check whether the plugin is active by checking the active_plugins list. + * Check whether a plugin is active. + * + * Only plugins installed in the plugins/ folder can be active. + * + * Plugins in the mu-plugins/ folder can't be "activated," so this function will + * return false for those plugins. * * @since 2.5.0 * @@ -453,6 +469,11 @@ function is_plugin_inactive( $plugin ) { /** * Check whether the plugin is active for the entire network. * + * Only plugins installed in the plugins/ folder can be active. + * + * Plugins in the mu-plugins/ folder can't be "activated," so this function will + * return false for those plugins. + * * @since 3.0.0 * * @param string $plugin Base plugin path from plugins directory. @@ -474,7 +495,7 @@ function is_plugin_active_for_network( $plugin ) { * be activated only as a network wide plugin. The plugin would also work * when Multisite is not enabled. * - * Checks for "Site Wide Only: true" for backwards compatibility. + * Checks for "Site Wide Only: true" for backward compatibility. * * @since 3.0.0 * @@ -508,11 +529,11 @@ function is_network_only_plugin( $plugin ) { * * @since 2.5.0 * - * @param string $plugin Plugin path to main plugin file with plugin data. - * @param string $redirect Optional. URL to redirect to. - * @param bool $network_wide Whether to enable the plugin for all sites in the - * network or just the current site. Multisite only. Default is false. - * @param bool $silent Prevent calling activation hooks. Optional, default is false. + * @param string $plugin Plugin path to main plugin file with plugin data. + * @param string $redirect Optional. URL to redirect to. + * @param bool $network_wide Optional. Whether to enable the plugin for all sites in the network + * or just the current site. Multisite only. Default false. + * @param bool $silent Optional. Whether to prevent calling activation hooks. Default false. * @return WP_Error|null WP_Error on invalid file or null on success. */ function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) { @@ -557,12 +578,10 @@ function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silen /** * Fires as a specific plugin is being activated. * - * This hook is the "activation" hook used internally by - * {@see register_activation_hook()}. The dynamic portion of the - * hook name, `$plugin`, refers to the plugin basename. + * This hook is the "activation" hook used internally by register_activation_hook(). + * The dynamic portion of the hook name, `$plugin`, refers to the plugin basename. * - * If a plugin is silently activated (such as during an update), - * this hook does not fire. + * If a plugin is silently activated (such as during an update), this hook does not fire. * * @since 2.0.0 * @@ -672,12 +691,10 @@ function deactivate_plugins( $plugins, $silent = false, $network_wide = null ) { /** * Fires as a specific plugin is being deactivated. * - * This hook is the "deactivation" hook used internally by - * {@see register_deactivation_hook()}. The dynamic portion of the - * hook name, `$plugin`, refers to the plugin basename. + * This hook is the "deactivation" hook used internally by register_deactivation_hook(). + * The dynamic portion of the hook name, `$plugin`, refers to the plugin basename. * - * If a plugin is silently deactivated (such as during an update), - * this hook does not fire. + * If a plugin is silently deactivated (such as during an update), this hook does not fire. * * @since 2.0.0 * @@ -765,11 +782,13 @@ function delete_plugins( $plugins, $deprecated = '' ) { foreach ( $plugins as $plugin ) $checked[] = 'checked[]=' . $plugin; - ob_start(); $url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-plugins'); - if ( false === ($credentials = request_filesystem_credentials($url)) ) { - $data = ob_get_clean(); + ob_start(); + $credentials = request_filesystem_credentials( $url ); + $data = ob_get_clean(); + + if ( false === $credentials ) { if ( ! empty($data) ){ include_once( ABSPATH . 'wp-admin/admin-header.php'); echo $data; @@ -779,8 +798,9 @@ function delete_plugins( $plugins, $deprecated = '' ) { return; } - if ( ! WP_Filesystem($credentials) ) { - request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again + if ( ! WP_Filesystem( $credentials ) ) { + ob_start(); + request_filesystem_credentials( $url, '', true ); // Failed to connect, Error and request again. $data = ob_get_clean(); if ( ! empty($data) ){ @@ -801,7 +821,7 @@ function delete_plugins( $plugins, $deprecated = '' ) { // Get the base plugin folder. $plugins_dir = $wp_filesystem->wp_plugins_dir(); if ( empty( $plugins_dir ) ) { - return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress Plugin directory.' ) ); + return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress plugin directory.' ) ); } $plugins_dir = trailingslashit( $plugins_dir ); @@ -920,11 +940,11 @@ function validate_active_plugins() { /** * Validate the plugin path. * - * Checks that the file exists and {@link validate_file() is valid file}. + * Checks that the file exists and is a valid file. See validate_file(). * * @since 2.5.0 * - * @param string $plugin Plugin Path + * @param string $plugin Plugin Path. * @return WP_Error|int 0 on success, WP_Error on failure. */ function validate_plugin($plugin) { @@ -971,6 +991,17 @@ function uninstall_plugin($plugin) { $file = plugin_basename($plugin); $uninstallable_plugins = (array) get_option('uninstall_plugins'); + + /** + * Fires in uninstall_plugin() immediately before the plugin is uninstalled. + * + * @since 4.5.0 + * + * @param string $plugin Relative plugin path from plugin directory. + * @param array $uninstallable_plugins Uninstallable plugins. + */ + do_action( 'pre_uninstall_plugin', $plugin, $uninstallable_plugins ); + if ( file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) ) { if ( isset( $uninstallable_plugins[$file] ) ) { unset($uninstallable_plugins[$file]); @@ -979,7 +1010,7 @@ function uninstall_plugin($plugin) { unset($uninstallable_plugins); define('WP_UNINSTALL_PLUGIN', $file); - wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . dirname( $file ) ); + wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file ); include( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ); return true; @@ -1000,7 +1031,7 @@ function uninstall_plugin($plugin) { * Fires in uninstall_plugin() once the plugin has been uninstalled. * * The action concatenates the 'uninstall_' prefix with the basename of the - * plugin passed to {@see uninstall_plugin()} to create a dynamically-named action. + * plugin passed to uninstall_plugin() to create a dynamically-named action. * * @since 2.7.0 */ @@ -1079,60 +1110,6 @@ function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $func return $hookname; } -/** - * Add a top-level menu page in the 'objects' section. - * - * This function takes a capability which will be used to determine whether - * or not a page is included in the menu. - * - * The function which is hooked in to handle the output of the page must check - * that the user has the required capability as well. - * - * @global int $_wp_last_object_menu - * - * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected. - * @param string $menu_title The text to be used for the menu. - * @param string $capability The capability required for this menu to be displayed to the user. - * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). - * @param callable $function The function to be called to output the content for this page. - * @param string $icon_url The url to the icon to be used for this menu. - * @return string The resulting page's hook_suffix. - */ -function add_object_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') { - global $_wp_last_object_menu; - - $_wp_last_object_menu++; - - return add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $_wp_last_object_menu); -} - -/** - * Add a top-level menu page in the 'utility' section. - * - * This function takes a capability which will be used to determine whether - * or not a page is included in the menu. - * - * The function which is hooked in to handle the output of the page must check - * that the user has the required capability as well. - * - * @global int $_wp_last_utility_menu - * - * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected. - * @param string $menu_title The text to be used for the menu. - * @param string $capability The capability required for this menu to be displayed to the user. - * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). - * @param callable $function The function to be called to output the content for this page. - * @param string $icon_url The url to the icon to be used for this menu. - * @return string The resulting page's hook_suffix. - */ -function add_utility_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') { - global $_wp_last_utility_menu; - - $_wp_last_utility_menu++; - - return add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $_wp_last_utility_menu); -} - /** * Add a submenu page. * @@ -1404,7 +1381,7 @@ function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $fun * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). * @param callable $function The function to be called to output the content for this page. * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. -*/ + */ function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function ); } @@ -1424,7 +1401,7 @@ function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $fun * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). * @param callable $function The function to be called to output the content for this page. * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. -*/ + */ function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } @@ -1803,12 +1780,12 @@ function register_setting( $option_group, $option_name, $sanitize_callback = '' global $new_whitelist_options; if ( 'misc' == $option_group ) { - _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); + _deprecated_argument( __FUNCTION__, '3.0.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); $option_group = 'general'; } if ( 'privacy' == $option_group ) { - _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) ); + _deprecated_argument( __FUNCTION__, '3.5.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) ); $option_group = 'reading'; } @@ -1832,12 +1809,12 @@ function unregister_setting( $option_group, $option_name, $sanitize_callback = ' global $new_whitelist_options; if ( 'misc' == $option_group ) { - _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); + _deprecated_argument( __FUNCTION__, '3.0.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); $option_group = 'general'; } if ( 'privacy' == $option_group ) { - _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) ); + _deprecated_argument( __FUNCTION__, '3.5.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) ); $option_group = 'reading'; } @@ -1849,7 +1826,9 @@ function unregister_setting( $option_group, $option_name, $sanitize_callback = ' } /** - * Refreshes the value of the options whitelist available via the 'whitelist_options' filter. + * Refreshes the value of the options whitelist available via the 'whitelist_options' hook. + * + * See the {@see 'whitelist_options'} filter. * * @since 2.7.0 *