Changes from branches/3.0/wp-admin/includes/plugin.php at r15745 to trunk/wp-admin/includes/plugin.php at r17310
- File:
-
- 1 edited
-
trunk/wp-admin/includes/plugin.php (modified) (50 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/plugin.php
r15745 r17310 101 101 if ( $markup || $translate ) 102 102 $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate ); 103 else 104 $plugin_data['AuthorName'] = $plugin_data['Author']; 103 105 104 106 return $plugin_data; … … 107 109 function _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup = true, $translate = true) { 108 110 109 //Translate fields 30111 //Translate fields 110 112 if ( $translate && ! empty($plugin_data['TextDomain']) ) { 111 113 if ( ! empty( $plugin_data['DomainPath'] ) ) … … 118 120 } 119 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(), 129 ); 130 131 $plugin_data['AuthorName'] = $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $plugins_allowedtags ); 132 120 133 //Apply Markup 121 134 if ( $markup ) { 122 135 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>'; 124 137 else 125 138 $plugin_data['Title'] = $plugin_data['Name']; 126 139 127 140 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>'; 129 142 130 143 $plugin_data['Description'] = wptexturize( $plugin_data['Description'] ); … … 133 146 } 134 147 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 ); 142 153 143 154 return $plugin_data; … … 199 210 * optimization purposes. 200 211 * 201 * @since unknown212 * @since 1.5.0 202 213 * 203 214 * @param string $plugin_folder Optional. Relative path to single plugin folder. … … 261 272 } 262 273 263 uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' ));274 uasort( $wp_plugins, '_sort_uname_callback' ); 264 275 265 276 $cache_plugins[ $plugin_folder ] = $wp_plugins; … … 313 324 unset( $wp_plugins['index.php'] ); 314 325 315 uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' ));326 uasort( $wp_plugins, '_sort_uname_callback' ); 316 327 317 328 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'] ); 318 339 } 319 340 … … 354 375 } 355 376 356 uksort( $dropins, create_function( '$a, $b', 'return strnatcasecmp( $a, $b );' ));377 uksort( $dropins, 'strnatcasecmp' ); 357 378 358 379 return $dropins; … … 402 423 403 424 /** 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 /** 404 440 * Check whether the plugin is active for the entire network. 405 441 * … … 429 465 * @since 3.0.0 430 466 * 431 * @param $filePlugin to check432 * $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. 433 469 */ 434 470 function is_network_only_plugin( $plugin ) { … … 457 493 * ensure that the success redirection will update the error redirection. 458 494 * 459 * @since unknown495 * @since 2.5.0 460 496 * 461 497 * @param string $plugin Plugin path to main plugin file with plugin data. 462 498 * @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. 464 502 * @return WP_Error|null WP_Error on invalid file or null on success. 465 503 */ 466 function activate_plugin( $plugin, $redirect = '', $network_wide = false ) {467 $plugin = plugin_basename( trim( $plugin ) );504 function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) { 505 $plugin = plugin_basename( trim( $plugin ) ); 468 506 469 507 if ( is_multisite() && ( $network_wide || is_network_only_plugin($plugin) ) ) { … … 482 520 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 483 521 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 487 529 if ( $network_wide ) { 488 530 $current[$plugin] = time(); … … 493 535 update_option('active_plugins', $current); 494 536 } 495 do_action( 'activated_plugin', trim( $plugin) ); 537 538 if ( ! $silent ) { 539 do_action( 'activated_plugin', $plugin, $network_wide ); 540 } 541 496 542 if ( ob_get_length() > 0 ) { 497 543 $output = ob_get_clean(); … … 510 556 * parameter. 511 557 * 512 * @since unknown558 * @since 2.5.0 513 559 * 514 560 * @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. 516 562 */ 517 563 function 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() ); 519 566 $current = get_option( 'active_plugins', array() ); 520 567 $do_blog = $do_network = false; 521 568 522 569 foreach ( (array) $plugins as $plugin ) { 523 $plugin = plugin_basename( $plugin);570 $plugin = plugin_basename( trim( $plugin ) ); 524 571 if ( ! is_plugin_active($plugin) ) 525 572 continue; 573 574 $network_wide = is_plugin_active_for_network( $plugin ); 575 526 576 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 ) { 531 580 $do_network = true; 532 581 unset( $network_current[ $plugin ] ); 533 582 } else { 534 // Deactivate for this blog only 535 $key = array_search( $plugin, (array) $current ); 583 $key = array_search( $plugin, $current ); 536 584 if ( false !== $key ) { 537 585 $do_blog = true; … … 540 588 } 541 589 542 //Used by Plugin updater to internally deactivate plugin, however, not to notify plugins of the fact to prevent plugin output.543 590 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 ); 546 593 } 547 594 } … … 561 608 * The execution will be halted as soon as one of the plugins has an error. 562 609 * 563 * @since unknown610 * @since 2.6.0 564 611 * 565 612 * @param string|array $plugins 566 613 * @param string $redirect Redirect to page after successful activation. 567 614 * @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. 568 616 * @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation. 569 617 */ 570 function activate_plugins( $plugins, $redirect = '', $network_wide) {618 function activate_plugins( $plugins, $redirect = '', $network_wide = false, $silent = false ) { 571 619 if ( !is_array($plugins) ) 572 620 $plugins = array($plugins); 573 621 574 622 $errors = array(); 575 foreach ( (array)$plugins as $plugin ) {623 foreach ( $plugins as $plugin ) { 576 624 if ( !empty($redirect) ) 577 625 $redirect = add_query_arg('plugin', $plugin, $redirect); 578 $result = activate_plugin($plugin, $redirect, $network_wide );626 $result = activate_plugin($plugin, $redirect, $network_wide, $silent); 579 627 if ( is_wp_error($result) ) 580 628 $errors[$plugin] = $result; … … 593 641 * completed. 594 642 * 595 * @since unknown643 * @since 2.6.0 596 644 * 597 645 * @param array $plugins List of plugin … … 610 658 611 659 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'); 613 661 if ( false === ($credentials = request_filesystem_credentials($url)) ) { 614 662 $data = ob_get_contents(); … … 685 733 * returns an array of deactivated ones. 686 734 * 687 * @since unknown735 * @since 2.5.0 688 736 * @return array invalid plugins, plugin as key, error as value 689 737 */ … … 722 770 * Checks that the file exists and {@link validate_file() is valid file}. 723 771 * 724 * @since unknown772 * @since 2.5.0 725 773 * 726 774 * @param string $plugin Plugin Path … … 816 864 * @param string $icon_url The url to the icon to be used for this menu 817 865 * @param int $position The position in the menu order this one should appear 866 * 867 * @return string The resulting page's hook_suffix 818 868 */ 819 869 function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = NULL ) { … … 864 914 * @param callback $function The function to be called to output the content for this page. 865 915 * @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 866 918 */ 867 919 function add_object_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') { … … 888 940 * @param callback $function The function to be called to output the content for this page. 889 941 * @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 890 944 */ 891 945 function add_utility_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') { … … 912 966 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) 913 967 * @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 914 970 */ 915 971 function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { … … 962 1018 /** 963 1019 * Add sub menu page to the tools main menu. 964 *1020 * 965 1021 * This function takes a capability which will be used to determine whether 966 1022 * or not a page is included in the menu. … … 974 1030 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) 975 1031 * @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 976 1034 */ 977 1035 function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { … … 981 1039 /** 982 1040 * Add sub menu page to the options main menu. 983 *1041 * 984 1042 * This function takes a capability which will be used to determine whether 985 1043 * or not a page is included in the menu. … … 993 1051 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) 994 1052 * @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 995 1055 */ 996 1056 function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { … … 1000 1060 /** 1001 1061 * Add sub menu page to the themes main menu. 1002 *1062 * 1003 1063 * This function takes a capability which will be used to determine whether 1004 1064 * or not a page is included in the menu. … … 1012 1072 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) 1013 1073 * @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 1014 1076 */ 1015 1077 function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { … … 1019 1081 /** 1020 1082 * Add sub menu page to the plugins main menu. 1021 *1083 * 1022 1084 * This function takes a capability which will be used to determine whether 1023 1085 * or not a page is included in the menu. … … 1031 1093 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) 1032 1094 * @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 1033 1097 */ 1034 1098 function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { … … 1038 1102 /** 1039 1103 * Add sub menu page to the Users/Profile main menu. 1040 *1104 * 1041 1105 * This function takes a capability which will be used to determine whether 1042 1106 * or not a page is included in the menu. … … 1050 1114 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) 1051 1115 * @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 1052 1118 */ 1053 1119 function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { … … 1060 1126 /** 1061 1127 * Add sub menu page to the Dashboard main menu. 1062 *1128 * 1063 1129 * This function takes a capability which will be used to determine whether 1064 1130 * or not a page is included in the menu. … … 1072 1138 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) 1073 1139 * @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 1074 1142 */ 1075 1143 function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { … … 1079 1147 /** 1080 1148 * Add sub menu page to the posts main menu. 1081 *1149 * 1082 1150 * This function takes a capability which will be used to determine whether 1083 1151 * or not a page is included in the menu. … … 1091 1159 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) 1092 1160 * @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 1093 1163 */ 1094 1164 function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { … … 1098 1168 /** 1099 1169 * Add sub menu page to the media main menu. 1100 *1170 * 1101 1171 * This function takes a capability which will be used to determine whether 1102 1172 * or not a page is included in the menu. … … 1110 1180 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) 1111 1181 * @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 1112 1184 */ 1113 1185 function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { … … 1117 1189 /** 1118 1190 * Add sub menu page to the links main menu. 1119 *1191 * 1120 1192 * This function takes a capability which will be used to determine whether 1121 1193 * or not a page is included in the menu. … … 1129 1201 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) 1130 1202 * @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 1131 1205 */ 1132 1206 function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { … … 1136 1210 /** 1137 1211 * Add sub menu page to the pages main menu. 1138 *1212 * 1139 1213 * This function takes a capability which will be used to determine whether 1140 1214 * or not a page is included in the menu. … … 1148 1222 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) 1149 1223 * @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 */ 1151 1227 function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { 1152 1228 return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function ); … … 1155 1231 /** 1156 1232 * Add sub menu page to the comments main menu. 1157 *1233 * 1158 1234 * This function takes a capability which will be used to determine whether 1159 1235 * or not a page is included in the menu. … … 1167 1243 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) 1168 1244 * @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 */ 1170 1248 function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { 1171 1249 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; 1172 1297 } 1173 1298 … … 1187 1312 1188 1313 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 ) ); 1191 1317 } else { 1192 $url = admin_url( 'admin.php?page=' . $menu_slug);1318 $url = admin_url( 'admin.php?page=' . $menu_slug ); 1193 1319 } 1194 1320 } else { … … 1514 1640 * {@internal Missing Short Description}} 1515 1641 * 1516 * @since unknown1642 * @since 2.7.0 1517 1643 * 1518 1644 * @param unknown_type $options … … 1532 1658 * {@internal Missing Short Description}} 1533 1659 * 1534 * @since unknown1660 * @since 2.7.0 1535 1661 * 1536 1662 * @param unknown_type $new_options … … 1563 1689 * {@internal Missing Short Description}} 1564 1690 * 1565 * @since unknown1691 * @since 2.7.0 1566 1692 * 1567 1693 * @param unknown_type $del_options
Note: See TracChangeset
for help on using the changeset viewer.