Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r15745 r17310  
    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'];
    103105
    104106    return $plugin_data;
     
    107109function _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup = true, $translate = true) {
    108110
    109     //Translate fields30
     111    //Translate fields
    110112    if ( $translate && ! empty($plugin_data['TextDomain']) ) {
    111113        if ( ! empty( $plugin_data['DomainPath'] ) )
     
    118120    }
    119121
     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
    120133    //Apply Markup
    121134    if ( $markup ) {
    122135        if ( ! empty($plugin_data['PluginURI']) && ! empty($plugin_data['Name']) )
    123             $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . __( 'Visit plugin homepage' ) . '">' . $plugin_data['Name'] . '</a>';
     136            $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . esc_attr__( 'Visit plugin homepage' ) . '">' . $plugin_data['Name'] . '</a>';
    124137        else
    125138            $plugin_data['Title'] = $plugin_data['Name'];
    126139
    127140        if ( ! empty($plugin_data['AuthorURI']) && ! empty($plugin_data['Author']) )
    128             $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . __( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
     141            $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . esc_attr__( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
    129142
    130143        $plugin_data['Description'] = wptexturize( $plugin_data['Description'] );
     
    133146    }
    134147
    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);
     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 );
    142153
    143154    return $plugin_data;
     
    199210 * optimization purposes.
    200211 *
    201  * @since unknown
     212 * @since 1.5.0
    202213 *
    203214 * @param string $plugin_folder Optional. Relative path to single plugin folder.
     
    261272    }
    262273
    263     uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' ));
     274    uasort( $wp_plugins, '_sort_uname_callback' );
    264275
    265276    $cache_plugins[ $plugin_folder ] = $wp_plugins;
     
    313324        unset( $wp_plugins['index.php'] );
    314325
    315     uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' ));
     326    uasort( $wp_plugins, '_sort_uname_callback' );
    316327
    317328    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 */
     337function _sort_uname_callback( $a, $b ) {
     338    return strnatcasecmp( $a['Name'], $b['Name'] );
    318339}
    319340
     
    354375    }
    355376
    356     uksort( $dropins, create_function( '$a, $b', 'return strnatcasecmp( $a, $b );' ));
     377    uksort( $dropins, 'strnatcasecmp' );
    357378
    358379    return $dropins;
     
    402423
    403424/**
     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 */
     435function is_plugin_inactive( $plugin ) {
     436    return ! is_plugin_active( $plugin );
     437}
     438
     439/**
    404440 * Check whether the plugin is active for the entire network.
    405441 *
     
    429465 * @since 3.0.0
    430466 *
    431  * @param $file Plugin to check
    432  * $return bool True if plugin is network only, false otherwise.
     467 * @param string $plugin Plugin to check
     468 * @return bool True if plugin is network only, false otherwise.
    433469 */
    434470function is_network_only_plugin( $plugin ) {
     
    457493 * ensure that the success redirection will update the error redirection.
    458494 *
    459  * @since unknown
     495 * @since 2.5.0
    460496 *
    461497 * @param string $plugin Plugin path to main plugin file with plugin data.
    462498 * @param string $redirect Optional. URL to redirect to.
    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.
     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.
    464502 * @return WP_Error|null WP_Error on invalid file or null on success.
    465503 */
    466 function activate_plugin( $plugin, $redirect = '', $network_wide = false) {
    467     $plugin  = plugin_basename( trim( $plugin ) );
     504function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) {
     505    $plugin = plugin_basename( trim( $plugin ) );
    468506
    469507    if ( is_multisite() && ( $network_wide || is_network_only_plugin($plugin) ) ) {
     
    482520            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
    483521        ob_start();
    484         include(WP_PLUGIN_DIR . '/' . $plugin);
    485         do_action( 'activate_plugin', trim( $plugin) );
    486         do_action( 'activate_' . trim( $plugin ) );
     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
    487529        if ( $network_wide ) {
    488530            $current[$plugin] = time();
     
    493535            update_option('active_plugins', $current);
    494536        }
    495         do_action( 'activated_plugin', trim( $plugin) );
     537
     538        if ( ! $silent ) {
     539            do_action( 'activated_plugin', $plugin, $network_wide );
     540        }
     541
    496542        if ( ob_get_length() > 0 ) {
    497543            $output = ob_get_clean();
     
    510556 * parameter.
    511557 *
    512  * @since unknown
     558 * @since 2.5.0
    513559 *
    514560 * @param string|array $plugins Single plugin or list of plugins to deactivate.
    515  * @param bool $silent Optional, default is false. Prevent calling deactivate hook.
     561 * @param bool $silent Prevent calling deactivation hooks. Default is false.
    516562 */
    517563function deactivate_plugins( $plugins, $silent = false ) {
    518     $network_current = get_site_option( 'active_sitewide_plugins', array() );
     564    if ( is_multisite() )
     565        $network_current = get_site_option( 'active_sitewide_plugins', array() );
    519566    $current = get_option( 'active_plugins', array() );
    520567    $do_blog = $do_network = false;
    521568
    522569    foreach ( (array) $plugins as $plugin ) {
    523         $plugin = plugin_basename($plugin);
     570        $plugin = plugin_basename( trim( $plugin ) );
    524571        if ( ! is_plugin_active($plugin) )
    525572            continue;
     573
     574        $network_wide = is_plugin_active_for_network( $plugin );
     575
    526576        if ( ! $silent )
    527             do_action( 'deactivate_plugin', trim( $plugin ) );
    528 
    529         if ( is_plugin_active_for_network($plugin) ) {
    530             // Deactivate network wide
     577            do_action( 'deactivate_plugin', $plugin, $network_wide );
     578
     579        if ( $network_wide ) {
    531580            $do_network = true;
    532581            unset( $network_current[ $plugin ] );
    533582        } else {
    534             // Deactivate for this blog only
    535             $key = array_search( $plugin, (array) $current );
     583            $key = array_search( $plugin, $current );
    536584            if ( false !== $key ) {
    537585                $do_blog = true;
     
    540588        }
    541589
    542         //Used by Plugin updater to internally deactivate plugin, however, not to notify plugins of the fact to prevent plugin output.
    543590        if ( ! $silent ) {
    544             do_action( 'deactivate_' . trim( $plugin ) );
    545             do_action( 'deactivated_plugin', trim( $plugin ) );
     591            do_action( 'deactivate_' . $plugin, $network_wide );
     592            do_action( 'deactivated_plugin', $plugin, $network_wide );
    546593        }
    547594    }
     
    561608 * The execution will be halted as soon as one of the plugins has an error.
    562609 *
    563  * @since unknown
     610 * @since 2.6.0
    564611 *
    565612 * @param string|array $plugins
    566613 * @param string $redirect Redirect to page after successful activation.
    567614 * @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.
    568616 * @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation.
    569617 */
    570 function activate_plugins($plugins, $redirect = '', $network_wide) {
     618function activate_plugins( $plugins, $redirect = '', $network_wide = false, $silent = false ) {
    571619    if ( !is_array($plugins) )
    572620        $plugins = array($plugins);
    573621
    574622    $errors = array();
    575     foreach ( (array) $plugins as $plugin ) {
     623    foreach ( $plugins as $plugin ) {
    576624        if ( !empty($redirect) )
    577625            $redirect = add_query_arg('plugin', $plugin, $redirect);
    578         $result = activate_plugin($plugin, $redirect, $network_wide);
     626        $result = activate_plugin($plugin, $redirect, $network_wide, $silent);
    579627        if ( is_wp_error($result) )
    580628            $errors[$plugin] = $result;
     
    593641 * completed.
    594642 *
    595  * @since unknown
     643 * @since 2.6.0
    596644 *
    597645 * @param array $plugins List of plugin
     
    610658
    611659    ob_start();
    612     $url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-manage-plugins');
     660    $url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-plugins');
    613661    if ( false === ($credentials = request_filesystem_credentials($url)) ) {
    614662        $data = ob_get_contents();
     
    685733 * returns an array of deactivated ones.
    686734 *
    687  * @since unknown
     735 * @since 2.5.0
    688736 * @return array invalid plugins, plugin as key, error as value
    689737 */
     
    722770 * Checks that the file exists and {@link validate_file() is valid file}.
    723771 *
    724  * @since unknown
     772 * @since 2.5.0
    725773 *
    726774 * @param string $plugin Plugin Path
     
    816864 * @param string $icon_url The url to the icon to be used for this menu
    817865 * @param int $position The position in the menu order this one should appear
     866 *
     867 * @return string The resulting page's hook_suffix
    818868 */
    819869function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = NULL ) {
     
    864914 * @param callback $function The function to be called to output the content for this page.
    865915 * @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
    866918 */
    867919function add_object_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') {
     
    888940 * @param callback $function The function to be called to output the content for this page.
    889941 * @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
    890944 */
    891945function add_utility_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') {
     
    912966 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    913967 * @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
    914970 */
    915971function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    9621018/**
    9631019 * Add sub menu page to the tools main menu.
    964 *
     1020 *
    9651021 * This function takes a capability which will be used to determine whether
    9661022 * or not a page is included in the menu.
     
    9741030 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    9751031 * @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
    9761034 */
    9771035function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    9811039/**
    9821040 * Add sub menu page to the options main menu.
    983 *
     1041 *
    9841042 * This function takes a capability which will be used to determine whether
    9851043 * or not a page is included in the menu.
     
    9931051 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    9941052 * @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
    9951055 */
    9961056function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    10001060/**
    10011061 * Add sub menu page to the themes main menu.
    1002 *
     1062 *
    10031063 * This function takes a capability which will be used to determine whether
    10041064 * or not a page is included in the menu.
     
    10121072 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    10131073 * @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
    10141076 */
    10151077function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    10191081/**
    10201082 * Add sub menu page to the plugins main menu.
    1021 *
     1083 *
    10221084 * This function takes a capability which will be used to determine whether
    10231085 * or not a page is included in the menu.
     
    10311093 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    10321094 * @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
    10331097 */
    10341098function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    10381102/**
    10391103 * Add sub menu page to the Users/Profile main menu.
    1040 *
     1104 *
    10411105 * This function takes a capability which will be used to determine whether
    10421106 * or not a page is included in the menu.
     
    10501114 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    10511115 * @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
    10521118 */
    10531119function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    10601126/**
    10611127 * Add sub menu page to the Dashboard main menu.
    1062 *
     1128 *
    10631129 * This function takes a capability which will be used to determine whether
    10641130 * or not a page is included in the menu.
     
    10721138 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    10731139 * @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
    10741142 */
    10751143function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    10791147/**
    10801148 * Add sub menu page to the posts main menu.
    1081 *
     1149 *
    10821150 * This function takes a capability which will be used to determine whether
    10831151 * or not a page is included in the menu.
     
    10911159 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    10921160 * @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
    10931163 */
    10941164function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    10981168/**
    10991169 * Add sub menu page to the media main menu.
    1100 *
     1170 *
    11011171 * This function takes a capability which will be used to determine whether
    11021172 * or not a page is included in the menu.
     
    11101180 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    11111181 * @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
    11121184 */
    11131185function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    11171189/**
    11181190 * Add sub menu page to the links main menu.
    1119 *
     1191 *
    11201192 * This function takes a capability which will be used to determine whether
    11211193 * or not a page is included in the menu.
     
    11291201 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    11301202 * @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
    11311205 */
    11321206function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     
    11361210/**
    11371211 * Add sub menu page to the pages main menu.
    1138 *
     1212 *
    11391213 * This function takes a capability which will be used to determine whether
    11401214 * or not a page is included in the menu.
     
    11481222 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    11491223 * @param callback $function The function to be called to output the content for this page.
    1150  */
     1224 *
     1225 * @return string The resulting page's hook_suffix
     1226*/
    11511227function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    11521228    return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function );
     
    11551231/**
    11561232 * Add sub menu page to the comments main menu.
    1157 *
     1233 *
    11581234 * This function takes a capability which will be used to determine whether
    11591235 * or not a page is included in the menu.
     
    11671243 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
    11681244 * @param callback $function The function to be called to output the content for this page.
    1169  */
     1245 *
     1246 * @return string The resulting page's hook_suffix
     1247*/
    11701248function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    11711249    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 */
     1261function 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 */
     1283function 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;
    11721297}
    11731298
     
    11871312
    11881313    if ( isset( $_parent_pages[$menu_slug] ) ) {
    1189         if ( $_parent_pages[$menu_slug] ) {
    1190             $url = admin_url( add_query_arg( 'page', $menu_slug, $_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 ) );
    11911317        } else {
    1192             $url = admin_url('admin.php?page=' . $menu_slug);
     1318            $url = admin_url( 'admin.php?page=' . $menu_slug );
    11931319        }
    11941320    } else {
     
    15141640 * {@internal Missing Short Description}}
    15151641 *
    1516  * @since unknown
     1642 * @since 2.7.0
    15171643 *
    15181644 * @param unknown_type $options
     
    15321658 * {@internal Missing Short Description}}
    15331659 *
    1534  * @since unknown
     1660 * @since 2.7.0
    15351661 *
    15361662 * @param unknown_type $new_options
     
    15631689 * {@internal Missing Short Description}}
    15641690 *
    1565  * @since unknown
     1691 * @since 2.7.0
    15661692 *
    15671693 * @param unknown_type $del_options
Note: See TracChangeset for help on using the changeset viewer.