Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/plugin.php

    r18951 r20555  
    6666 *
    6767 * @param string $plugin_file Path to the plugin file
    68  * @param bool $markup If the returned data should have HTML markup applied
    69  * @param bool $translate If the returned data should be translated
     68 * @param bool $markup Optional. If the returned data should have HTML markup applied. Defaults to true.
     69 * @param bool $translate Optional. If the returned data should be translated. Defaults to true.
    7070 * @return array See above for description.
    7171 */
    … …  
    8989
    9090        // Site Wide Only is the old header for Network
    91         if ( empty( $plugin_data['Network'] ) && ! empty( $plugin_data['_sitewide'] ) ) {
     91        if ( ! $plugin_data['Network'] && $plugin_data['_sitewide'] ) {
    9292                _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The <code>%1$s</code> plugin header is deprecated. Use <code>%2$s</code> instead.' ), 'Site Wide Only: true', 'Network: true' ) );
    9393                $plugin_data['Network'] = $plugin_data['_sitewide'];
    … …  
    9696        unset( $plugin_data['_sitewide'] );
    9797
    98         //For backward compatibility by default Title is the same as Name.
    99         $plugin_data['Title'] = $plugin_data['Name'];
    100 
    101         if ( $markup || $translate )
     98        if ( $markup || $translate ) {
    10299                $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate );
    103         else
     100        } else {
     101                $plugin_data['Title']      = $plugin_data['Name'];
    104102                $plugin_data['AuthorName'] = $plugin_data['Author'];
     103        }
    105104
    106105        return $plugin_data;
    107106}
    108107
    109 function _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup = true, $translate = true) {
    110 
    111         //Translate fields
    112         if ( $translate && ! empty($plugin_data['TextDomain']) ) {
    113                 if ( ! empty( $plugin_data['DomainPath'] ) )
    114                         load_plugin_textdomain($plugin_data['TextDomain'], false, dirname($plugin_file). $plugin_data['DomainPath']);
    115                 else
    116                         load_plugin_textdomain($plugin_data['TextDomain'], false, dirname($plugin_file));
    117 
    118                 foreach ( array('Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version') as $field )
    119                         $plugin_data[ $field ] = translate($plugin_data[ $field ], $plugin_data['TextDomain']);
    120         }
    121 
    122         $plugins_allowedtags = array(
    123                 'a'       => array( 'href' => array(), 'title' => array() ),
    124                 'abbr'    => array( 'title' => array() ),
    125                 'acronym' => array( 'title' => array() ),
    126                 'code'    => array(),
    127                 'em'      => array(),
    128                 'strong'  => array(),
     108/**
     109 * Sanitizes plugin data, optionally adds markup, optionally translates.
     110 *
     111 * @since 2.7.0
     112 * @access private
     113 * @see get_plugin_data()
     114 */
     115function _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup = true, $translate = true ) {
     116
     117        // Translate fields
     118        if ( $translate ) {
     119                if ( $textdomain = $plugin_data['TextDomain'] ) {
     120                        if ( $plugin_data['DomainPath'] )
     121                                load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) . $plugin_data['DomainPath'] );
     122                        else
     123                                load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) );
     124                } elseif ( in_array( basename( $plugin_file ), array( 'hello.php', 'akismet.php' ) ) ) {
     125                        $textdomain = 'default';
     126                }
     127                if ( $textdomain ) {
     128                        foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field )
     129                                $plugin_data[ $field ] = translate( $plugin_data[ $field ], $textdomain );
     130                }
     131        }
     132
     133        // Sanitize fields
     134        $allowed_tags = $allowed_tags_in_links = array(
     135                'abbr'    => array( 'title' => true ),
     136                'acronym' => array( 'title' => true ),
     137                'code'    => true,
     138                'em'      => true,
     139                'strong'  => true,
    129140        );
    130 
    131         $plugin_data['AuthorName'] = $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $plugins_allowedtags );
    132 
    133         //Apply Markup
     141        $allowed_tags['a'] = array( 'href' => true, 'title' => true );
     142
     143        // Name is marked up inside <a> tags. Don't allow these.
     144        // Author is too, but some plugins have used <a> here (omitting Author URI).
     145        $plugin_data['Name']        = wp_kses( $plugin_data['Name'],        $allowed_tags_in_links );
     146        $plugin_data['Author']      = wp_kses( $plugin_data['Author'],      $allowed_tags );
     147
     148        $plugin_data['Description'] = wp_kses( $plugin_data['Description'], $allowed_tags );
     149        $plugin_data['Version']     = wp_kses( $plugin_data['Version'],     $allowed_tags );
     150
     151        $plugin_data['PluginURI']   = esc_url( $plugin_data['PluginURI'] );
     152        $plugin_data['AuthorURI']   = esc_url( $plugin_data['AuthorURI'] );
     153
     154        $plugin_data['Title']      = $plugin_data['Name'];
     155        $plugin_data['AuthorName'] = $plugin_data['Author'];
     156
     157        // Apply markup
    134158        if ( $markup ) {
    135                 if ( ! empty($plugin_data['PluginURI']) && ! empty($plugin_data['Name']) )
     159                if ( $plugin_data['PluginURI'] && $plugin_data['Name'] )
    136160                        $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . esc_attr__( 'Visit plugin homepage' ) . '">' . $plugin_data['Name'] . '</a>';
    137                 else
    138                         $plugin_data['Title'] = $plugin_data['Name'];
    139 
    140                 if ( ! empty($plugin_data['AuthorURI']) && ! empty($plugin_data['Author']) )
     161
     162                if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] )
    141163                        $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . esc_attr__( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
    142164
    143165                $plugin_data['Description'] = wptexturize( $plugin_data['Description'] );
    144                 if ( ! empty($plugin_data['Author']) )
    145                         $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s'), $plugin_data['Author'] ) . '.</cite>';
    146         }
    147 
    148         // Sanitize all displayed data. Author and AuthorName sanitized above.
    149         $plugin_data['Title']       = wp_kses( $plugin_data['Title'],       $plugins_allowedtags );
    150         $plugin_data['Version']     = wp_kses( $plugin_data['Version'],     $plugins_allowedtags );
    151         $plugin_data['Description'] = wp_kses( $plugin_data['Description'], $plugins_allowedtags );
    152         $plugin_data['Name']        = wp_kses( $plugin_data['Name'],        $plugins_allowedtags );
     166
     167                if ( $plugin_data['Author'] )
     168                        $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s.'), $plugin_data['Author'] ) . '</cite>';
     169        }
    153170
    154171        return $plugin_data;
    … …  
    556573 *
    557574 * @param string|array $plugins Single plugin or list of plugins to deactivate.
     575 * @param mixed $network_wide Whether to deactivate the plugin for all sites in the network.
     576 *      A value of null (the default) will deactivate plugins for both the site and the network.
    558577 * @param bool $silent Prevent calling deactivation hooks. Default is false.
    559578 */
    560 function deactivate_plugins( $plugins, $silent = false ) {
     579function deactivate_plugins( $plugins, $silent = false, $network_wide = null ) {
    561580        if ( is_multisite() )
    562581                $network_current = get_site_option( 'active_sitewide_plugins', array() );
    … …  
    569588                        continue;
    570589
    571                 $network_wide = is_plugin_active_for_network( $plugin );
     590                $network_deactivating = false !== $network_wide && is_plugin_active_for_network( $plugin );
    572591
    573592                if ( ! $silent )
    574                         do_action( 'deactivate_plugin', $plugin, $network_wide );
    575 
    576                 if ( $network_wide ) {
    577                         $do_network = true;
    578                         unset( $network_current[ $plugin ] );
    579                 } else {
     593                        do_action( 'deactivate_plugin', $plugin, $network_deactivating );
     594
     595                if ( false !== $network_wide ) {
     596                        if ( is_plugin_active_for_network( $plugin ) ) {
     597                                $do_network = true;
     598                                unset( $network_current[ $plugin ] );
     599                        } elseif ( $network_wide ) {
     600                                continue;
     601                        }
     602                }
     603
     604                if ( true !== $network_wide ) {
    580605                        $key = array_search( $plugin, $current );
    581606                        if ( false !== $key ) {
    … …  
    586611
    587612                if ( ! $silent ) {
    588                         do_action( 'deactivate_' . $plugin, $network_wide );
    589                         do_action( 'deactivated_plugin', $plugin, $network_wide );
     613                        do_action( 'deactivate_' . $plugin, $network_deactivating );
     614                        do_action( 'deactivated_plugin', $plugin, $network_deactivating );
    590615                }
    591616        }
    … …  
    864889 * @return string The resulting page's hook_suffix
    865890 */
    866 function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = NULL ) {
     891function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = null ) {
    867892        global $menu, $admin_page_hooks, $_registered_pages, $_parent_pages;
    868893
    … …  
    883908        $new_menu = array( $menu_title, $capability, $menu_slug, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
    884909
    885         if ( null === $position  )
     910        if ( null === $position )
    886911                $menu[] = $new_menu;
    887912        else
    … …  
    9861011
    9871012        // If the parent doesn't already have a submenu, add a link to the parent
    988         // as the first item in the submenu.  If the submenu file is the same as the
    989         // parent file someone is trying to link back to the parent manually.  In
     1013        // as the first item in the submenu. If the submenu file is the same as the
     1014        // parent file someone is trying to link back to the parent manually. In
    9901015        // this case, don't automatically add a link back to avoid duplication.
    991         if (!isset( $submenu[$parent_slug] ) && $menu_slug != $parent_slug  ) {
     1016        if (!isset( $submenu[$parent_slug] ) && $menu_slug != $parent_slug ) {
    9921017                foreach ( (array)$menu as $parent_menu ) {
    9931018                        if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) )
    … …  
    10031028
    10041029        $_registered_pages[$hookname] = true;
    1005         // backwards-compatibility for plugins using add_management page.  See wp-admin/admin.php for redirect from edit.php to tools.php
     1030        // backwards-compatibility for plugins using add_management page. See wp-admin/admin.php for redirect from edit.php to tools.php
    10061031        if ( 'tools.php' == $parent_slug )
    10071032                $_registered_pages[get_plugin_page_hookname( $menu_slug, 'edit.php')] = true;
    … …  
    12461271        return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function );
    12471272}
    1248 
    12491273
    12501274/**
    … …  
    15901614 * @since 2.7.0
    15911615 *
    1592  * @param string $option_group A settings group name.  Should correspond to a whitelisted option key name.
     1616 * @param string $option_group A settings group name. Should correspond to a whitelisted option key name.
    15931617 *      Default whitelisted option key names include "general," "discussion," and "reading," among others.
    15941618 * @param string $option_name The name of an option to sanitize and save.
    … …  
    17161740 * @since 2.7.0
    17171741 *
    1718  * @param string $option_group A settings group name.  This should match the group name used in register_setting().
     1742 * @param string $option_group A settings group name. This should match the group name used in register_setting().
    17191743 */
    17201744function settings_fields($option_group) {
    … …  
    17231747        wp_nonce_field("$option_group-options");
    17241748}
    1725 
    1726 ?>
Note: See TracChangeset for help on using the changeset viewer.