Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r17310 r15745  
    101101    if ( $markup || $translate )
    102102        $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate );
    103     else
    104         $plugin_data['AuthorName'] = $plugin_data['Author'];
    105103
    106104    return $plugin_data;
     
    109107function _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup = true, $translate = true) {
    110108
    111     //Translate fields
     109    //Translate fields30
    112110    if ( $translate && ! empty($plugin_data['TextDomain']) ) {
    113111        if ( ! empty( $plugin_data['DomainPath'] ) )
     
    120118    }
    121119
    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(),
    129     );
    130 
    131     $plugin_data['AuthorName'] = $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $plugins_allowedtags );
    132 
    133120    //Apply Markup
    134121    if ( $markup ) {
    135122        if ( ! empty($plugin_data['PluginURI']) && ! empty($plugin_data['Name']) )
    136             $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . esc_attr__( 'Visit plugin homepage' ) . '">' . $plugin_data['Name'] . '</a>';
     123            $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . __( 'Visit plugin homepage' ) . '">' . $plugin_data['Name'] . '</a>';
    137124        else
    138125            $plugin_data['Title'] = $plugin_data['Name'];
    139126
    140127        if ( ! empty($plugin_data['AuthorURI']) && ! empty($plugin_data['Author']) )
    141             $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . esc_attr__( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
     128            $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . __( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
    142129
    143130        $plugin_data['Description'] = wptexturize( $plugin_data['Description'] );
     
    146133    }
    147134
    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 );
     135    $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array());
     136
     137    // Sanitize all displayed data
     138    $plugin_data['Title']       = wp_kses($plugin_data['Title'], $plugins_allowedtags);
     139    $plugin_data['Version']     = wp_kses($plugin_data['Version'], $plugins_allowedtags);
     140    $plugin_data['Description'] = wp_kses($plugin_data['Description'], $plugins_allowedtags);
     141    $plugin_data['Author']      = wp_kses($plugin_data['Author'], $plugins_allowedtags);
    153142
    154143    return $plugin_data;
     
    210199 * optimization purposes.
    211200 *
    212  * @since 1.5.0
     201 * @since unknown
    213202 *
    214203 * @param string $plugin_folder Optional. Relative path to single plugin folder.
     
    272261    }
    273262
    274     uasort( $wp_plugins, '_sort_uname_callback' );
     263    uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' ));
    275264
    276265    $cache_plugins[ $plugin_folder ] = $wp_plugins;
     
    324313        unset( $wp_plugins['index.php'] );
    325314
    326     uasort( $wp_plugins, '_sort_uname_callback' );
     315    uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' ));
    327316
    328317    return $wp_plugins;
    329 }
    330 
    331 /**
    332  * Callback to sort array by a 'Name' key.
    333  *
    334  * @since 3.1.0
    335  * @access private
    336  */
    337 function _sort_uname_callback( $a, $b ) {
    338     return strnatcasecmp( $a['Name'], $b['Name'] );
    339318}
    340319
     
    375354    }
    376355
    377     uksort( $dropins, 'strnatcasecmp' );
     356    uksort( $dropins, create_function( '$a, $b', 'return strnatcasecmp( $a, $b );' ));
    378357
    379358    return $dropins;
     
    423402
    424403/**
    425  * Check whether the plugin is inactive.
    426  *
    427  * Reverse of is_plugin_active(). Used as a callback.
    428  *
    429  * @since 3.1.0
    430  * @see is_plugin_active()
    431  *
    432  * @param string $plugin Base plugin path from plugins directory.
    433  * @return bool True if inactive. False if active.
    434  */
    435 function is_plugin_inactive( $plugin ) {
    436     return ! is_plugin_active( $plugin );
    437 }
    438 
    439 /**
    440404 * Check whether the plugin is active for the entire network.
    441405 *
     
    465429 * @since 3.0.0
    466430 *
    467  * @param string $plugin Plugin to check
    468  * @return bool True if plugin is network only, false otherwise.
     431 * @param $file Plugin to check
     432 * $return bool True if plugin is network only, false otherwise.
    469433 */
    470434function is_network_only_plugin( $plugin ) {
     
    493457 * ensure that the success redirection will update the error redirection.
    494458 *
    495  * @since 2.5.0
     459 * @since unknown
    496460 *
    497461 * @param string $plugin Plugin path to main plugin file with plugin data.
    498462 * @param string $redirect Optional. URL to redirect to.
    499  * @param bool $network_wide Whether to enable the plugin for all sites in the
    500  *   network or just the current site. Multisite only. Default is false.
    501  * @param bool $silent Prevent calling activation hooks. Optional, default is false.
     463 * @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.
    502464 * @return WP_Error|null WP_Error on invalid file or null on success.
    503465 */
    504 function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) {
    505     $plugin = plugin_basename( trim( $plugin ) );
     466function activate_plugin( $plugin, $redirect = '', $network_wide = false) {
     467    $plugin  = plugin_basename( trim( $plugin ) );
    506468
    507469    if ( is_multisite() && ( $network_wide || is_network_only_plugin($plugin) ) ) {
     
    520482            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
    521483        ob_start();
    522         include_once(WP_PLUGIN_DIR . '/' . $plugin);
    523 
    524         if ( ! $silent ) {
    525             do_action( 'activate_plugin', $plugin, $network_wide );
    526             do_action( 'activate_' . $plugin, $network_wide );
    527         }
    528 
     484        include(WP_PLUGIN_DIR . '/' . $plugin);
     485        do_action( 'activate_plugin', trim( $plugin) );
     486        do_action( 'activate_' . trim( $plugin ) );
    529487        if ( $network_wide ) {
    530488            $current[$plugin] = time();
     
    535493            update_option('active_plugins', $current);
    536494        }
    537 
    538         if ( ! $silent ) {
    539             do_action( 'activated_plugin', $plugin, $network_wide );
    540         }
    541 
     495        do_action( 'activated_plugin', trim( $plugin) );
    542496        if ( ob_get_length() > 0 ) {
    543497            $output = ob_get_clean();
     
    556510 * parameter.
    557511 *
    558  * @since 2.5.0
     512 * @since unknown
    559513 *
    560514 * @param string|array $plugins Single plugin or list of plugins to deactivate.
    561  * @param bool $silent Prevent calling deactivation hooks. Default is false.
     515 * @param bool $silent Optional, default is false. Prevent calling deactivate hook.
    562516 */
    563517function deactivate_plugins( $plugins, $silent = false ) {
    564     if ( is_multisite() )
    565         $network_current = get_site_option( 'active_sitewide_plugins', array() );
     518    $network_current = get_site_option( 'active_sitewide_plugins', array() );
    566519    $current = get_option( 'active_plugins', array() );
    567520    $do_blog = $do_network = false;
    568521
    569522    foreach ( (array) $plugins as $plugin ) {
    570         $plugin = plugin_basename( trim( $plugin ) );
     523        $plugin = plugin_basename($plugin);
    571524        if ( ! is_plugin_active($plugin) )
    572525            continue;
    573 
    574         $network_wide = is_plugin_active_for_network( $plugin );
    575 
    576526        if ( ! $silent )
    577             do_action( 'deactivate_plugin', $plugin, $network_wide );
    578 
    579         if ( $network_wide ) {
     527            do_action( 'deactivate_plugin', trim( $plugin ) );
     528
     529        if ( is_plugin_active_for_network($plugin) ) {
     530            // Deactivate network wide
    580531            $do_network = true;
    581532            unset( $network_current[ $plugin ] );
    582533        } else {
    583             $key = array_search( $plugin, $current );
     534            // Deactivate for this blog only
     535            $key = array_search( $plugin, (array) $current );
    584536            if ( false !== $key ) {
    585537                $do_blog = true;
     
    588540        }
    589541
     542        //Used by Plugin updater to internally deactivate plugin, however, not to notify plugins of the fact to prevent plugin output.
    590543        if ( ! $silent ) {
    591             do_action( 'deactivate_' . $plugin, $network_wide );
    592             do_action( 'deactivated_plugin', $plugin, $network_wide );
     544            do_action( 'deactivate_' . trim( $plugin ) );
     545            do_action( 'deactivated_plugin', trim( $plugin ) );
    593546        }
    594547    }
     
    608561 * The execution will be halted as soon as one of the plugins has an error.
    609562 *
    610  * @since 2.6.0
     563 * @since unknown
    611564 *
    612565 * @param string|array $plugins
    613566 * @param string $redirect Redirect to page after successful activation.
    614567 * @param bool $network_wide Whether to enable the plugin for all sites in the network.
    615  * @param bool $silent Prevent calling activation hooks. Default is false.
    616568 * @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation.
    617569 */
    618 function activate_plugins( $plugins, $redirect = '', $network_wide = false, $silent = false ) {
     570function activate_plugins($plugins, $redirect = '', $network_wide) {
    619571    if ( !is_array($plugins) )
    620572        $plugins = array($plugins);
    621573
    622574    $errors = array();
    623     foreach ( $plugins as $plugin ) {
     575    foreach ( (array) $plugins as $plugin ) {
    624576        if ( !empty($redirect) )
    625577            $redirect = add_query_arg('plugin', $plugin, $redirect);
    626         $result = activate_plugin($plugin, $redirect, $network_wide, $silent);
     578        $result = activate_plugin($plugin, $redirect, $network_wide);
    627579        if ( is_wp_error($result) )
    628580            $errors[$plugin] = $result;
     
    641593 * completed.
    642594 *
    643  * @since 2.6.0
     595 * @since unknown
    644596 *
    645597 * @param array $plugins List of plugin
     
    658610
    659611    ob_start();
    660     $url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-plugins');
     612    $url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-manage-plugins');
    661613    if ( false === ($credentials = request_filesystem_credentials($url)) ) {
    662614        $data = ob_get_contents();
     
    733685 * returns an array of deactivated ones.
    734686 *
    735  * @since 2.5.0
     687 * @since unknown
    736688 * @return array invalid plugins, plugin as key, error as value
    737689 */
     
    770722 * Checks that the file exists and {@link validate_file() is valid file}.
    771723 *
    772  * @since 2.5.0
     724 * @since unknown
    773725 *
    774726 * @param string $plugin Plugin Path
     
    864816 * @param string $icon_url The url to the icon to be used for this menu
    865817 * @param int $position The position in the menu order this one should appear
    866  *
    867  * @return string The resulting page's hook_suffix
    868818 */
    869819function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = NULL ) {
     
    914864 * @param callback $function The function to be called to output the content for this page.
    915865 * @param string $icon_url The url to the icon to be used for this menu
    916  *
    917  * @return string The resulting page's hook_suffix
    918866 */
    919867function add_object_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') {
     
    940888 * @param callback $function The function to be called to output the content for this page.
    941889 * @param string $icon_url The url to the icon to be used for this menu
    942  *
    943  * @return string The resulting page's hook_suffix
    944890 */
    945891function add_utility_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') {
     
    966912 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    967913 * @param callback $function The function to be called to output the content for this page.
    968  *
    969  * @return string The resulting page's hook_suffix
    970914 */
    971915function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    1018962/**
    1019963 * Add sub menu page to the tools main menu.
    1020  *
     964*
    1021965 * This function takes a capability which will be used to determine whether
    1022966 * or not a page is included in the menu.
     
    1030974 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    1031975 * @param callback $function The function to be called to output the content for this page.
    1032  *
    1033  * @return string The resulting page's hook_suffix
    1034976 */
    1035977function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    1039981/**
    1040982 * Add sub menu page to the options main menu.
    1041  *
     983*
    1042984 * This function takes a capability which will be used to determine whether
    1043985 * or not a page is included in the menu.
     
    1051993 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    1052994 * @param callback $function The function to be called to output the content for this page.
    1053  *
    1054  * @return string The resulting page's hook_suffix
    1055995 */
    1056996function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    10601000/**
    10611001 * Add sub menu page to the themes main menu.
    1062  *
     1002*
    10631003 * This function takes a capability which will be used to determine whether
    10641004 * or not a page is included in the menu.
     
    10721012 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    10731013 * @param callback $function The function to be called to output the content for this page.
    1074  *
    1075  * @return string The resulting page's hook_suffix
    10761014 */
    10771015function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    10811019/**
    10821020 * Add sub menu page to the plugins main menu.
    1083  *
     1021*
    10841022 * This function takes a capability which will be used to determine whether
    10851023 * or not a page is included in the menu.
     
    10931031 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    10941032 * @param callback $function The function to be called to output the content for this page.
    1095  *
    1096  * @return string The resulting page's hook_suffix
    10971033 */
    10981034function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    11021038/**
    11031039 * Add sub menu page to the Users/Profile main menu.
    1104  *
     1040*
    11051041 * This function takes a capability which will be used to determine whether
    11061042 * or not a page is included in the menu.
     
    11141050 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    11151051 * @param callback $function The function to be called to output the content for this page.
    1116  *
    1117  * @return string The resulting page's hook_suffix
    11181052 */
    11191053function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    11261060/**
    11271061 * Add sub menu page to the Dashboard main menu.
    1128  *
     1062*
    11291063 * This function takes a capability which will be used to determine whether
    11301064 * or not a page is included in the menu.
     
    11381072 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    11391073 * @param callback $function The function to be called to output the content for this page.
    1140  *
    1141  * @return string The resulting page's hook_suffix
    11421074 */
    11431075function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    11471079/**
    11481080 * Add sub menu page to the posts main menu.
    1149  *
     1081*
    11501082 * This function takes a capability which will be used to determine whether
    11511083 * or not a page is included in the menu.
     
    11591091 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    11601092 * @param callback $function The function to be called to output the content for this page.
    1161  *
    1162  * @return string The resulting page's hook_suffix
    11631093 */
    11641094function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    11681098/**
    11691099 * Add sub menu page to the media main menu.
    1170  *
     1100*
    11711101 * This function takes a capability which will be used to determine whether
    11721102 * or not a page is included in the menu.
     
    11801110 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    11811111 * @param callback $function The function to be called to output the content for this page.
    1182  *
    1183  * @return string The resulting page's hook_suffix
    11841112 */
    11851113function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    11891117/**
    11901118 * Add sub menu page to the links main menu.
    1191  *
     1119*
    11921120 * This function takes a capability which will be used to determine whether
    11931121 * or not a page is included in the menu.
     
    12011129 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    12021130 * @param callback $function The function to be called to output the content for this page.
    1203  *
    1204  * @return string The resulting page's hook_suffix
    12051131 */
    12061132function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    12101136/**
    12111137 * Add sub menu page to the pages main menu.
    1212  *
     1138*
    12131139 * This function takes a capability which will be used to determine whether
    12141140 * or not a page is included in the menu.
     
    12221148 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    12231149 * @param callback $function The function to be called to output the content for this page.
    1224  *
    1225  * @return string The resulting page's hook_suffix
    1226 */
     1150 */
    12271151function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    12281152    return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function );
     
    12311155/**
    12321156 * Add sub menu page to the comments main menu.
    1233  *
     1157*
    12341158 * This function takes a capability which will be used to determine whether
    12351159 * or not a page is included in the menu.
     
    12431167 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    12441168 * @param callback $function The function to be called to output the content for this page.
    1245  *
    1246  * @return string The resulting page's hook_suffix
    1247 */
     1169 */
    12481170function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    12491171    return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function );
    1250 }
    1251 
    1252 
    1253 /**
    1254  * Remove a top level admin menu
    1255  *
    1256  * @since 3.1.0
    1257  *
    1258  * @param string $menu_slug The slug of the menu
    1259  * @return array|bool The removed menu on success, False if not found
    1260  */
    1261 function remove_menu_page( $menu_slug ) {
    1262     global $menu;
    1263 
    1264     foreach ( $menu as $i => $item ) {
    1265         if ( $menu_slug == $item[2] ) {
    1266             unset( $menu[$i] );
    1267             return $item;
    1268         }
    1269     }
    1270 
    1271     return false;
    1272 }
    1273 
    1274 /**
    1275  * Remove an admin submenu
    1276  *
    1277  * @since 3.1.0
    1278  *
    1279  * @param string $menu_slug The slug for the parent menu
    1280  * @param string $submenu_slug The slug of the submenu
    1281  * @return array|bool The removed submenu on success, False if not found
    1282  */
    1283 function remove_submenu_page( $menu_slug, $submenu_slug ) {
    1284     global $submenu;
    1285 
    1286     if ( !isset( $submenu[$menu_slug] ) )
    1287         return false;
    1288 
    1289     foreach ( $submenu[$menu_slug] as $i => $item ) {
    1290         if ( $submenu_slug == $item[2] ) {
    1291             unset( $submenu[$menu_slug][$i] );
    1292             return $item;
    1293         }
    1294     }
    1295 
    1296     return false;
    12971172}
    12981173
     
    13121187
    13131188    if ( isset( $_parent_pages[$menu_slug] ) ) {
    1314         $parent_slug = $_parent_pages[$menu_slug];
    1315         if ( $parent_slug && ! isset( $_parent_pages[$parent_slug] ) ) {
    1316             $url = admin_url( add_query_arg( 'page', $menu_slug, $parent_slug ) );
     1189        if ( $_parent_pages[$menu_slug] ) {
     1190            $url = admin_url( add_query_arg( 'page', $menu_slug, $_parent_pages[$menu_slug] ) );
    13171191        } else {
    1318             $url = admin_url( 'admin.php?page=' . $menu_slug );
     1192            $url = admin_url('admin.php?page=' . $menu_slug);
    13191193        }
    13201194    } else {
     
    16401514 * {@internal Missing Short Description}}
    16411515 *
    1642  * @since 2.7.0
     1516 * @since unknown
    16431517 *
    16441518 * @param unknown_type $options
     
    16581532 * {@internal Missing Short Description}}
    16591533 *
    1660  * @since 2.7.0
     1534 * @since unknown
    16611535 *
    16621536 * @param unknown_type $new_options
     
    16891563 * {@internal Missing Short Description}}
    16901564 *
    1691  * @since 2.7.0
     1565 * @since unknown
    16921566 *
    16931567 * @param unknown_type $del_options
Note: See TracChangeset for help on using the changeset viewer.