Changeset 42343 for trunk/src/wp-admin/includes/plugin.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-admin/includes/plugin.php (modified) (65 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/plugin.php
r42242 r42343 23 23 * Version: Must be set in the plugin for WordPress 2.3+ 24 24 * Text Domain: Optional. Unique identifier, should be same as the one used in 25 * load_plugin_textdomain()25 * load_plugin_textdomain() 26 26 * Domain Path: Optional. Only useful if the translations are located in a 27 * folder above the plugin's base path. For example, if .mo files are28 * located in the locale folder then Domain Path will be "/locale/" and29 * must have the first slash. Defaults to the base folder the plugin is30 * located in.27 * folder above the plugin's base path. For example, if .mo files are 28 * located in the locale folder then Domain Path will be "/locale/" and 29 * must have the first slash. Defaults to the base folder the plugin is 30 * located in. 31 31 * Network: Optional. Specify "Network: true" to require that a plugin is activated 32 * across all sites in an installation. This will prevent a plugin from being33 * activated on a single site when Multisite is enabled.32 * across all sites in an installation. This will prevent a plugin from being 33 * activated on a single site when Multisite is enabled. 34 34 * * / # Remove the space to close comment 35 35 * … … 69 69 70 70 $default_headers = array( 71 'Name' => 'Plugin Name',72 'PluginURI' => 'Plugin URI',73 'Version' => 'Version',71 'Name' => 'Plugin Name', 72 'PluginURI' => 'Plugin URI', 73 'Version' => 'Version', 74 74 'Description' => 'Description', 75 'Author' => 'Author',76 'AuthorURI' => 'Author URI',77 'TextDomain' => 'Text Domain',78 'DomainPath' => 'Domain Path',79 'Network' => 'Network',75 'Author' => 'Author', 76 'AuthorURI' => 'Author URI', 77 'TextDomain' => 'Text Domain', 78 'DomainPath' => 'Domain Path', 79 'Network' => 'Network', 80 80 // Site Wide Only is deprecated in favor of Network. 81 '_sitewide' => 'Site Wide Only',81 '_sitewide' => 'Site Wide Only', 82 82 ); 83 83 … … 137 137 } 138 138 if ( $textdomain ) { 139 foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field ) 139 foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field ) { 140 140 $plugin_data[ $field ] = translate( $plugin_data[ $field ], $textdomain ); 141 } 141 142 } 142 143 } 143 144 144 145 // Sanitize fields 145 $allowed_tags = $allowed_tags_in_links = array(146 $allowed_tags = $allowed_tags_in_links = array( 146 147 'abbr' => array( 'title' => true ), 147 148 'acronym' => array( 'title' => true ), … … 150 151 'strong' => true, 151 152 ); 152 $allowed_tags['a'] = array( 'href' => true, 'title' => true ); 153 $allowed_tags['a'] = array( 154 'href' => true, 155 'title' => true, 156 ); 153 157 154 158 // Name is marked up inside <a> tags. Don't allow these. 155 159 // Author is too, but some plugins have used <a> here (omitting Author URI). 156 $plugin_data['Name'] = wp_kses( $plugin_data['Name'],$allowed_tags_in_links );157 $plugin_data['Author'] = wp_kses( $plugin_data['Author'],$allowed_tags );160 $plugin_data['Name'] = wp_kses( $plugin_data['Name'], $allowed_tags_in_links ); 161 $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $allowed_tags ); 158 162 159 163 $plugin_data['Description'] = wp_kses( $plugin_data['Description'], $allowed_tags ); 160 $plugin_data['Version'] = wp_kses( $plugin_data['Version'], $allowed_tags );161 162 $plugin_data['PluginURI'] = esc_url( $plugin_data['PluginURI'] );163 $plugin_data['AuthorURI'] = esc_url( $plugin_data['AuthorURI'] );164 $plugin_data['Version'] = wp_kses( $plugin_data['Version'], $allowed_tags ); 165 166 $plugin_data['PluginURI'] = esc_url( $plugin_data['PluginURI'] ); 167 $plugin_data['AuthorURI'] = esc_url( $plugin_data['AuthorURI'] ); 164 168 165 169 $plugin_data['Title'] = $plugin_data['Name']; … … 168 172 // Apply markup 169 173 if ( $markup ) { 170 if ( $plugin_data['PluginURI'] && $plugin_data['Name'] ) 174 if ( $plugin_data['PluginURI'] && $plugin_data['Name'] ) { 171 175 $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '">' . $plugin_data['Name'] . '</a>'; 172 173 if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] ) 176 } 177 178 if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] ) { 174 179 $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>'; 180 } 175 181 176 182 $plugin_data['Description'] = wptexturize( $plugin_data['Description'] ); 177 183 178 if ( $plugin_data['Author'] ) 179 $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s.'), $plugin_data['Author'] ) . '</cite>'; 184 if ( $plugin_data['Author'] ) { 185 $plugin_data['Description'] .= ' <cite>' . sprintf( __( 'By %s.' ), $plugin_data['Author'] ) . '</cite>'; 186 } 180 187 } 181 188 … … 193 200 function get_plugin_files( $plugin ) { 194 201 $plugin_file = WP_PLUGIN_DIR . '/' . $plugin; 195 $dir = dirname( $plugin_file );202 $dir = dirname( $plugin_file ); 196 203 197 204 $plugin_files = array( plugin_basename( $plugin_file ) ); … … 238 245 * @return array Key is the plugin file path and the value is an array of the plugin data. 239 246 */ 240 function get_plugins( $plugin_folder = '') {241 242 if ( ! $cache_plugins = wp_cache_get( 'plugins', 'plugins') )247 function get_plugins( $plugin_folder = '' ) { 248 249 if ( ! $cache_plugins = wp_cache_get( 'plugins', 'plugins' ) ) { 243 250 $cache_plugins = array(); 244 245 if ( isset($cache_plugins[ $plugin_folder ]) ) 251 } 252 253 if ( isset( $cache_plugins[ $plugin_folder ] ) ) { 246 254 return $cache_plugins[ $plugin_folder ]; 247 248 $wp_plugins = array (); 255 } 256 257 $wp_plugins = array(); 249 258 $plugin_root = WP_PLUGIN_DIR; 250 if ( ! empty($plugin_folder) )259 if ( ! empty( $plugin_folder ) ) { 251 260 $plugin_root .= $plugin_folder; 261 } 252 262 253 263 // Files in wp-content/plugins directory 254 $plugins_dir = @ opendir( $plugin_root);264 $plugins_dir = @ opendir( $plugin_root ); 255 265 $plugin_files = array(); 256 266 if ( $plugins_dir ) { 257 while ( ($file = readdir( $plugins_dir ) ) !== false ) {258 if ( substr( $file, 0, 1) == '.' )267 while ( ( $file = readdir( $plugins_dir ) ) !== false ) { 268 if ( substr( $file, 0, 1 ) == '.' ) { 259 269 continue; 260 if ( is_dir( $plugin_root.'/'.$file ) ) { 261 $plugins_subdir = @ opendir( $plugin_root.'/'.$file ); 270 } 271 if ( is_dir( $plugin_root . '/' . $file ) ) { 272 $plugins_subdir = @ opendir( $plugin_root . '/' . $file ); 262 273 if ( $plugins_subdir ) { 263 while ( ($subfile = readdir( $plugins_subdir ) ) !== false ) {264 if ( substr( $subfile, 0, 1) == '.' )274 while ( ( $subfile = readdir( $plugins_subdir ) ) !== false ) { 275 if ( substr( $subfile, 0, 1 ) == '.' ) { 265 276 continue; 266 if ( substr($subfile, -4) == '.php' ) 277 } 278 if ( substr( $subfile, -4 ) == '.php' ) { 267 279 $plugin_files[] = "$file/$subfile"; 280 } 268 281 } 269 282 closedir( $plugins_subdir ); 270 283 } 271 284 } else { 272 if ( substr( $file, -4) == '.php' )285 if ( substr( $file, -4 ) == '.php' ) { 273 286 $plugin_files[] = $file; 287 } 274 288 } 275 289 } … … 277 291 } 278 292 279 if ( empty( $plugin_files) )293 if ( empty( $plugin_files ) ) { 280 294 return $wp_plugins; 295 } 281 296 282 297 foreach ( $plugin_files as $plugin_file ) { 283 if ( ! is_readable( "$plugin_root/$plugin_file" ) )298 if ( ! is_readable( "$plugin_root/$plugin_file" ) ) { 284 299 continue; 300 } 285 301 286 302 $plugin_data = get_plugin_data( "$plugin_root/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. 287 303 288 if ( empty ( $plugin_data['Name'] ) )304 if ( empty( $plugin_data['Name'] ) ) { 289 305 continue; 290 291 $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data; 306 } 307 308 $wp_plugins[ plugin_basename( $plugin_file ) ] = $plugin_data; 292 309 } 293 310 … … 295 312 296 313 $cache_plugins[ $plugin_folder ] = $wp_plugins; 297 wp_cache_set( 'plugins', $cache_plugins, 'plugins');314 wp_cache_set( 'plugins', $cache_plugins, 'plugins' ); 298 315 299 316 return $wp_plugins; … … 313 330 $plugin_files = array(); 314 331 315 if ( ! is_dir( WPMU_PLUGIN_DIR ) ) 332 if ( ! is_dir( WPMU_PLUGIN_DIR ) ) { 316 333 return $wp_plugins; 334 } 317 335 if ( $plugins_dir = @ opendir( WPMU_PLUGIN_DIR ) ) { 318 336 while ( ( $file = readdir( $plugins_dir ) ) !== false ) { 319 if ( substr( $file, -4 ) == '.php' ) 337 if ( substr( $file, -4 ) == '.php' ) { 320 338 $plugin_files[] = $file; 339 } 321 340 } 322 341 } else { … … 326 345 @closedir( $plugins_dir ); 327 346 328 if ( empty( $plugin_files) )347 if ( empty( $plugin_files ) ) { 329 348 return $wp_plugins; 349 } 330 350 331 351 foreach ( $plugin_files as $plugin_file ) { 332 if ( ! is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) )352 if ( ! is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) ) { 333 353 continue; 354 } 334 355 335 356 $plugin_data = get_plugin_data( WPMU_PLUGIN_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. 336 357 337 if ( empty ( $plugin_data['Name'] ) )358 if ( empty( $plugin_data['Name'] ) ) { 338 359 $plugin_data['Name'] = $plugin_file; 360 } 339 361 340 362 $wp_plugins[ $plugin_file ] = $plugin_data; 341 363 } 342 364 343 if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php' ) <= 30 )// silence is golden365 if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php' ) <= 30 ) { // silence is golden 344 366 unset( $wp_plugins['index.php'] ); 367 } 345 368 346 369 uasort( $wp_plugins, '_sort_uname_callback' ); … … 366 389 */ 367 390 function get_dropins() { 368 $dropins = array();391 $dropins = array(); 369 392 $plugin_files = array(); 370 393 … … 374 397 if ( $plugins_dir = @ opendir( WP_CONTENT_DIR ) ) { 375 398 while ( ( $file = readdir( $plugins_dir ) ) !== false ) { 376 if ( isset( $_dropins[ $file ] ) ) 399 if ( isset( $_dropins[ $file ] ) ) { 377 400 $plugin_files[] = $file; 401 } 378 402 } 379 403 } else { … … 383 407 @closedir( $plugins_dir ); 384 408 385 if ( empty( $plugin_files) )409 if ( empty( $plugin_files ) ) { 386 410 return $dropins; 411 } 387 412 388 413 foreach ( $plugin_files as $plugin_file ) { 389 if ( ! is_readable( WP_CONTENT_DIR . "/$plugin_file" ) )414 if ( ! is_readable( WP_CONTENT_DIR . "/$plugin_file" ) ) { 390 415 continue; 416 } 391 417 $plugin_data = get_plugin_data( WP_CONTENT_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. 392 if ( empty( $plugin_data['Name'] ) ) 418 if ( empty( $plugin_data['Name'] ) ) { 393 419 $plugin_data['Name'] = $plugin_file; 420 } 394 421 $dropins[ $plugin_file ] = $plugin_data; 395 422 } … … 407 434 * @since 3.0.0 408 435 * @return array Key is file name. The value is an array, with the first value the 409 * purpose of the drop-in and the second value the name of the constant that must be410 * true for the drop-in to be used, or true if no constant is required.436 * purpose of the drop-in and the second value the name of the constant that must be 437 * true for the drop-in to be used, or true if no constant is required. 411 438 */ 412 439 function _get_dropins() { 413 440 $dropins = array( 414 'advanced-cache.php' => array( __( 'Advanced caching plugin.' ), 'WP_CACHE' ), // WP_CACHE415 'db.php' => array( __( 'Custom database class.' ), true ), // auto on load441 'advanced-cache.php' => array( __( 'Advanced caching plugin.' ), 'WP_CACHE' ), // WP_CACHE 442 'db.php' => array( __( 'Custom database class.' ), true ), // auto on load 416 443 'db-error.php' => array( __( 'Custom database error message.' ), true ), // auto on error 417 'install.php' => array( __( 'Custom installation script.' ), true ), // auto on installation418 'maintenance.php' => array( __( 'Custom maintenance message.' ), true ), // auto on maintenance419 'object-cache.php' => array( __( 'External object cache.' ), true ), // auto on load444 'install.php' => array( __( 'Custom installation script.' ), true ), // auto on installation 445 'maintenance.php' => array( __( 'Custom maintenance message.' ), true ), // auto on maintenance 446 'object-cache.php' => array( __( 'External object cache.' ), true ), // auto on load 420 447 ); 421 448 422 449 if ( is_multisite() ) { 423 $dropins['sunrise.php' ]= array( __( 'Executed before Multisite is loaded.' ), 'SUNRISE' ); // SUNRISE424 $dropins['blog-deleted.php' ] = array( __( 'Custom site deleted message.'), true ); // auto on deleted blog425 $dropins['blog-inactive.php' ] = array( __( 'Custom site inactive message.'), true ); // auto on inactive blog450 $dropins['sunrise.php'] = array( __( 'Executed before Multisite is loaded.' ), 'SUNRISE' ); // SUNRISE 451 $dropins['blog-deleted.php'] = array( __( 'Custom site deleted message.' ), true ); // auto on deleted blog 452 $dropins['blog-inactive.php'] = array( __( 'Custom site inactive message.' ), true ); // auto on inactive blog 426 453 $dropins['blog-suspended.php'] = array( __( 'Custom site suspended message.' ), true ); // auto on archived or spammed blog 427 454 } … … 476 503 */ 477 504 function is_plugin_active_for_network( $plugin ) { 478 if ( ! is_multisite() )505 if ( ! is_multisite() ) { 479 506 return false; 480 481 $plugins = get_site_option( 'active_sitewide_plugins'); 482 if ( isset($plugins[$plugin]) ) 507 } 508 509 $plugins = get_site_option( 'active_sitewide_plugins' ); 510 if ( isset( $plugins[ $plugin ] ) ) { 483 511 return true; 512 } 484 513 485 514 return false; … … 500 529 function is_network_only_plugin( $plugin ) { 501 530 $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); 502 if ( $plugin_data ) 531 if ( $plugin_data ) { 503 532 return $plugin_data['Network']; 533 } 504 534 return false; 505 535 } … … 535 565 $plugin = plugin_basename( trim( $plugin ) ); 536 566 537 if ( is_multisite() && ( $network_wide || is_network_only_plugin( $plugin) ) ) {538 $network_wide = true;539 $current = get_site_option( 'active_sitewide_plugins', array() );567 if ( is_multisite() && ( $network_wide || is_network_only_plugin( $plugin ) ) ) { 568 $network_wide = true; 569 $current = get_site_option( 'active_sitewide_plugins', array() ); 540 570 $_GET['networkwide'] = 1; // Back compat for plugins looking for this value. 541 571 } else { … … 543 573 } 544 574 545 $valid = validate_plugin( $plugin);546 if ( is_wp_error( $valid) )575 $valid = validate_plugin( $plugin ); 576 if ( is_wp_error( $valid ) ) { 547 577 return $valid; 578 } 548 579 549 580 if ( ( $network_wide && ! isset( $current[ $plugin ] ) ) || ( ! $network_wide && ! in_array( $plugin, $current ) ) ) { 550 if ( !empty($redirect) ) 551 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 581 if ( ! empty( $redirect ) ) { 582 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 583 } 552 584 ob_start(); 553 585 wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin ); … … 588 620 589 621 if ( $network_wide ) { 590 $current = get_site_option( 'active_sitewide_plugins', array() );591 $current[ $plugin] = time();622 $current = get_site_option( 'active_sitewide_plugins', array() ); 623 $current[ $plugin ] = time(); 592 624 update_site_option( 'active_sitewide_plugins', $current ); 593 625 } else { 594 $current = get_option( 'active_plugins', array() );626 $current = get_option( 'active_plugins', array() ); 595 627 $current[] = $plugin; 596 sort( $current);597 update_option( 'active_plugins', $current);628 sort( $current ); 629 update_option( 'active_plugins', $current ); 598 630 } 599 631 … … 616 648 if ( ob_get_length() > 0 ) { 617 649 $output = ob_get_clean(); 618 return new WP_Error( 'unexpected_output', __('The plugin generated unexpected output.'), $output);650 return new WP_Error( 'unexpected_output', __( 'The plugin generated unexpected output.' ), $output ); 619 651 } 620 652 ob_end_clean(); … … 635 667 * @param bool $silent Prevent calling deactivation hooks. Default is false. 636 668 * @param mixed $network_wide Whether to deactivate the plugin for all sites in the network. 637 * A value of null (the default) will deactivate plugins for both the site and the network.669 * A value of null (the default) will deactivate plugins for both the site and the network. 638 670 */ 639 671 function deactivate_plugins( $plugins, $silent = false, $network_wide = null ) { 640 if ( is_multisite() ) 672 if ( is_multisite() ) { 641 673 $network_current = get_site_option( 'active_sitewide_plugins', array() ); 674 } 642 675 $current = get_option( 'active_plugins', array() ); 643 676 $do_blog = $do_network = false; … … 645 678 foreach ( (array) $plugins as $plugin ) { 646 679 $plugin = plugin_basename( trim( $plugin ) ); 647 if ( ! is_plugin_active( $plugin) )680 if ( ! is_plugin_active( $plugin ) ) { 648 681 continue; 682 } 649 683 650 684 $network_deactivating = false !== $network_wide && is_plugin_active_for_network( $plugin ); … … 715 749 } 716 750 717 if ( $do_blog ) 718 update_option('active_plugins', $current); 719 if ( $do_network ) 751 if ( $do_blog ) { 752 update_option( 'active_plugins', $current ); 753 } 754 if ( $do_network ) { 720 755 update_site_option( 'active_sitewide_plugins', $network_current ); 756 } 721 757 } 722 758 … … 738 774 */ 739 775 function activate_plugins( $plugins, $redirect = '', $network_wide = false, $silent = false ) { 740 if ( !is_array($plugins) ) 741 $plugins = array($plugins); 776 if ( ! is_array( $plugins ) ) { 777 $plugins = array( $plugins ); 778 } 742 779 743 780 $errors = array(); 744 781 foreach ( $plugins as $plugin ) { 745 if ( !empty($redirect) ) 746 $redirect = add_query_arg('plugin', $plugin, $redirect); 747 $result = activate_plugin($plugin, $redirect, $network_wide, $silent); 748 if ( is_wp_error($result) ) 749 $errors[$plugin] = $result; 750 } 751 752 if ( !empty($errors) ) 753 return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors); 782 if ( ! empty( $redirect ) ) { 783 $redirect = add_query_arg( 'plugin', $plugin, $redirect ); 784 } 785 $result = activate_plugin( $plugin, $redirect, $network_wide, $silent ); 786 if ( is_wp_error( $result ) ) { 787 $errors[ $plugin ] = $result; 788 } 789 } 790 791 if ( ! empty( $errors ) ) { 792 return new WP_Error( 'plugins_invalid', __( 'One of the plugins is invalid.' ), $errors ); 793 } 754 794 755 795 return true; … … 771 811 global $wp_filesystem; 772 812 773 if ( empty( $plugins) )813 if ( empty( $plugins ) ) { 774 814 return false; 815 } 775 816 776 817 $checked = array(); 777 foreach ( $plugins as $plugin ) 818 foreach ( $plugins as $plugin ) { 778 819 $checked[] = 'checked[]=' . $plugin; 779 780 $url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-plugins'); 820 } 821 822 $url = wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&' . implode( '&', $checked ), 'bulk-plugins' ); 781 823 782 824 ob_start(); 783 825 $credentials = request_filesystem_credentials( $url ); 784 $data = ob_get_clean();826 $data = ob_get_clean(); 785 827 786 828 if ( false === $credentials ) { 787 if ( ! empty( $data) ){788 include_once( ABSPATH . 'wp-admin/admin-header.php' );829 if ( ! empty( $data ) ) { 830 include_once( ABSPATH . 'wp-admin/admin-header.php' ); 789 831 echo $data; 790 include( ABSPATH . 'wp-admin/admin-footer.php' );832 include( ABSPATH . 'wp-admin/admin-footer.php' ); 791 833 exit; 792 834 } … … 799 841 $data = ob_get_clean(); 800 842 801 if ( ! empty( $data) ){802 include_once( ABSPATH . 'wp-admin/admin-header.php' );843 if ( ! empty( $data ) ) { 844 include_once( ABSPATH . 'wp-admin/admin-header.php' ); 803 845 echo $data; 804 include( ABSPATH . 'wp-admin/admin-footer.php' );846 include( ABSPATH . 'wp-admin/admin-footer.php' ); 805 847 exit; 806 848 } … … 808 850 } 809 851 810 if ( ! is_object($wp_filesystem) ) 811 return new WP_Error('fs_unavailable', __('Could not access filesystem.')); 812 813 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) 814 return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors); 852 if ( ! is_object( $wp_filesystem ) ) { 853 return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) ); 854 } 855 856 if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { 857 return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors ); 858 } 815 859 816 860 // Get the base plugin folder. … … 829 873 // Run Uninstall hook. 830 874 if ( is_uninstallable_plugin( $plugin_file ) ) { 831 uninstall_plugin( $plugin_file);875 uninstall_plugin( $plugin_file ); 832 876 } 833 877 … … 878 922 879 923 // Remove deleted plugins from the plugin updates list. 880 if ( $current = get_site_transient( 'update_plugins') ) {924 if ( $current = get_site_transient( 'update_plugins' ) ) { 881 925 // Don't remove the plugins that weren't deleted. 882 926 $deleted = array_diff( $plugins, $errors ); … … 923 967 if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) { 924 968 $network_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); 925 $plugins = array_merge( $plugins, array_keys( $network_plugins ) );926 } 927 928 if ( empty( $plugins ) ) 969 $plugins = array_merge( $plugins, array_keys( $network_plugins ) ); 970 } 971 972 if ( empty( $plugins ) ) { 929 973 return array(); 974 } 930 975 931 976 $invalid = array(); … … 935 980 $result = validate_plugin( $plugin ); 936 981 if ( is_wp_error( $result ) ) { 937 $invalid[ $plugin] = $result;982 $invalid[ $plugin ] = $result; 938 983 deactivate_plugins( $plugin, true ); 939 984 } … … 952 997 * @return WP_Error|int 0 on success, WP_Error on failure. 953 998 */ 954 function validate_plugin($plugin) { 955 if ( validate_file($plugin) ) 956 return new WP_Error('plugin_invalid', __('Invalid plugin path.')); 957 if ( ! file_exists(WP_PLUGIN_DIR . '/' . $plugin) ) 958 return new WP_Error('plugin_not_found', __('Plugin file does not exist.')); 999 function validate_plugin( $plugin ) { 1000 if ( validate_file( $plugin ) ) { 1001 return new WP_Error( 'plugin_invalid', __( 'Invalid plugin path.' ) ); 1002 } 1003 if ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin ) ) { 1004 return new WP_Error( 'plugin_not_found', __( 'Plugin file does not exist.' ) ); 1005 } 959 1006 960 1007 $installed_plugins = get_plugins(); 961 if ( ! isset($installed_plugins[$plugin]) ) 962 return new WP_Error('no_plugin_header', __('The plugin does not have a valid header.')); 1008 if ( ! isset( $installed_plugins[ $plugin ] ) ) { 1009 return new WP_Error( 'no_plugin_header', __( 'The plugin does not have a valid header.' ) ); 1010 } 963 1011 return 0; 964 1012 } … … 972 1020 * @return bool Whether plugin can be uninstalled. 973 1021 */ 974 function is_uninstallable_plugin( $plugin) {975 $file = plugin_basename( $plugin);976 977 $uninstallable_plugins = (array) get_option( 'uninstall_plugins');978 if ( isset( $uninstallable_plugins[ $file] ) || file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) )1022 function is_uninstallable_plugin( $plugin ) { 1023 $file = plugin_basename( $plugin ); 1024 1025 $uninstallable_plugins = (array) get_option( 'uninstall_plugins' ); 1026 if ( isset( $uninstallable_plugins[ $file ] ) || file_exists( WP_PLUGIN_DIR . '/' . dirname( $file ) . '/uninstall.php' ) ) { 979 1027 return true; 1028 } 980 1029 981 1030 return false; … … 992 1041 * @return true True if a plugin's uninstall.php file has been found and included. 993 1042 */ 994 function uninstall_plugin( $plugin) {995 $file = plugin_basename( $plugin);996 997 $uninstallable_plugins = (array) get_option( 'uninstall_plugins');1043 function uninstall_plugin( $plugin ) { 1044 $file = plugin_basename( $plugin ); 1045 1046 $uninstallable_plugins = (array) get_option( 'uninstall_plugins' ); 998 1047 999 1048 /** … … 1007 1056 do_action( 'pre_uninstall_plugin', $plugin, $uninstallable_plugins ); 1008 1057 1009 if ( file_exists( WP_PLUGIN_DIR . '/' . dirname( $file) . '/uninstall.php' ) ) {1010 if ( isset( $uninstallable_plugins[ $file] ) ) {1011 unset( $uninstallable_plugins[$file]);1012 update_option( 'uninstall_plugins', $uninstallable_plugins);1013 } 1014 unset( $uninstallable_plugins);1015 1016 define( 'WP_UNINSTALL_PLUGIN', $file);1058 if ( file_exists( WP_PLUGIN_DIR . '/' . dirname( $file ) . '/uninstall.php' ) ) { 1059 if ( isset( $uninstallable_plugins[ $file ] ) ) { 1060 unset( $uninstallable_plugins[ $file ] ); 1061 update_option( 'uninstall_plugins', $uninstallable_plugins ); 1062 } 1063 unset( $uninstallable_plugins ); 1064 1065 define( 'WP_UNINSTALL_PLUGIN', $file ); 1017 1066 wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file ); 1018 include( WP_PLUGIN_DIR . '/' . dirname( $file) . '/uninstall.php' );1067 include( WP_PLUGIN_DIR . '/' . dirname( $file ) . '/uninstall.php' ); 1019 1068 1020 1069 return true; 1021 1070 } 1022 1071 1023 if ( isset( $uninstallable_plugins[ $file] ) ) {1024 $callable = $uninstallable_plugins[ $file];1025 unset( $uninstallable_plugins[$file]);1026 update_option( 'uninstall_plugins', $uninstallable_plugins);1027 unset( $uninstallable_plugins);1072 if ( isset( $uninstallable_plugins[ $file ] ) ) { 1073 $callable = $uninstallable_plugins[ $file ]; 1074 unset( $uninstallable_plugins[ $file ] ); 1075 update_option( 'uninstall_plugins', $uninstallable_plugins ); 1076 unset( $uninstallable_plugins ); 1028 1077 1029 1078 wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file ); … … 1083 1132 $menu_slug = plugin_basename( $menu_slug ); 1084 1133 1085 $admin_page_hooks[ $menu_slug] = sanitize_title( $menu_title );1134 $admin_page_hooks[ $menu_slug ] = sanitize_title( $menu_title ); 1086 1135 1087 1136 $hookname = get_plugin_page_hookname( $menu_slug, '' ); 1088 1137 1089 if ( ! empty( $function ) && !empty( $hookname ) && current_user_can( $capability ) )1138 if ( ! empty( $function ) && ! empty( $hookname ) && current_user_can( $capability ) ) { 1090 1139 add_action( $hookname, $function ); 1091 1092 if ( empty($icon_url) ) { 1093 $icon_url = 'dashicons-admin-generic'; 1140 } 1141 1142 if ( empty( $icon_url ) ) { 1143 $icon_url = 'dashicons-admin-generic'; 1094 1144 $icon_class = 'menu-icon-generic '; 1095 1145 } else { 1096 $icon_url = set_url_scheme( $icon_url );1146 $icon_url = set_url_scheme( $icon_url ); 1097 1147 $icon_class = ''; 1098 1148 } … … 1103 1153 $menu[] = $new_menu; 1104 1154 } elseif ( isset( $menu[ "$position" ] ) ) { 1105 $position = $position + substr( base_convert( md5( $menu_slug . $menu_title ), 16, 10 ), -5 ) * 0.00001;1155 $position = $position + substr( base_convert( md5( $menu_slug . $menu_title ), 16, 10 ), -5 ) * 0.00001; 1106 1156 $menu[ "$position" ] = $new_menu; 1107 1157 } else { … … 1109 1159 } 1110 1160 1111 $_registered_pages[ $hookname] = true;1161 $_registered_pages[ $hookname ] = true; 1112 1162 1113 1163 // No parent as top level 1114 $_parent_pages[ $menu_slug] = false;1164 $_parent_pages[ $menu_slug ] = false; 1115 1165 1116 1166 return $hookname; … … 1149 1199 $_registered_pages, $_parent_pages; 1150 1200 1151 $menu_slug = plugin_basename( $menu_slug ); 1152 $parent_slug = plugin_basename( $parent_slug); 1153 1154 if ( isset( $_wp_real_parent_file[$parent_slug] ) ) 1155 $parent_slug = $_wp_real_parent_file[$parent_slug]; 1156 1157 if ( !current_user_can( $capability ) ) { 1158 $_wp_submenu_nopriv[$parent_slug][$menu_slug] = true; 1201 $menu_slug = plugin_basename( $menu_slug ); 1202 $parent_slug = plugin_basename( $parent_slug ); 1203 1204 if ( isset( $_wp_real_parent_file[ $parent_slug ] ) ) { 1205 $parent_slug = $_wp_real_parent_file[ $parent_slug ]; 1206 } 1207 1208 if ( ! current_user_can( $capability ) ) { 1209 $_wp_submenu_nopriv[ $parent_slug ][ $menu_slug ] = true; 1159 1210 return false; 1160 1211 } … … 1166 1217 * this case, don't automatically add a link back to avoid duplication. 1167 1218 */ 1168 if (!isset( $submenu[$parent_slug] ) && $menu_slug != $parent_slug ) { 1169 foreach ( (array)$menu as $parent_menu ) { 1170 if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) ) 1171 $submenu[$parent_slug][] = array_slice( $parent_menu, 0, 4 ); 1172 } 1173 } 1174 1175 $submenu[$parent_slug][] = array ( $menu_title, $capability, $menu_slug, $page_title ); 1176 1177 $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug); 1178 if (!empty ( $function ) && !empty ( $hookname )) 1219 if ( ! isset( $submenu[ $parent_slug ] ) && $menu_slug != $parent_slug ) { 1220 foreach ( (array) $menu as $parent_menu ) { 1221 if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) ) { 1222 $submenu[ $parent_slug ][] = array_slice( $parent_menu, 0, 4 ); 1223 } 1224 } 1225 } 1226 1227 $submenu[ $parent_slug ][] = array( $menu_title, $capability, $menu_slug, $page_title ); 1228 1229 $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug ); 1230 if ( ! empty( $function ) && ! empty( $hookname ) ) { 1179 1231 add_action( $hookname, $function ); 1180 1181 $_registered_pages[$hookname] = true; 1232 } 1233 1234 $_registered_pages[ $hookname ] = true; 1182 1235 1183 1236 /* … … 1185 1238 * See wp-admin/admin.php for redirect from edit.php to tools.php 1186 1239 */ 1187 if ( 'tools.php' == $parent_slug ) 1188 $_registered_pages[get_plugin_page_hookname( $menu_slug, 'edit.php')] = true; 1240 if ( 'tools.php' == $parent_slug ) { 1241 $_registered_pages[ get_plugin_page_hookname( $menu_slug, 'edit.php' ) ] = true; 1242 } 1189 1243 1190 1244 // No parent as top level. 1191 $_parent_pages[ $menu_slug] = $parent_slug;1245 $_parent_pages[ $menu_slug ] = $parent_slug; 1192 1246 1193 1247 return $hookname; … … 1291 1345 */ 1292 1346 function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { 1293 if ( current_user_can( 'edit_users') )1347 if ( current_user_can( 'edit_users' ) ) { 1294 1348 $parent = 'users.php'; 1295 else1349 } else { 1296 1350 $parent = 'profile.php'; 1351 } 1297 1352 return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function ); 1298 1353 } … … 1432 1487 foreach ( $menu as $i => $item ) { 1433 1488 if ( $menu_slug == $item[2] ) { 1434 unset( $menu[ $i] );1489 unset( $menu[ $i ] ); 1435 1490 return $item; 1436 1491 } … … 1454 1509 global $submenu; 1455 1510 1456 if ( ! isset( $submenu[$menu_slug] ) )1511 if ( ! isset( $submenu[ $menu_slug ] ) ) { 1457 1512 return false; 1458 1459 foreach ( $submenu[$menu_slug] as $i => $item ) { 1513 } 1514 1515 foreach ( $submenu[ $menu_slug ] as $i => $item ) { 1460 1516 if ( $submenu_slug == $item[2] ) { 1461 unset( $submenu[ $menu_slug][$i] );1517 unset( $submenu[ $menu_slug ][ $i ] ); 1462 1518 return $item; 1463 1519 } … … 1480 1536 * @return string the url 1481 1537 */ 1482 function menu_page_url( $menu_slug, $echo = true) {1538 function menu_page_url( $menu_slug, $echo = true ) { 1483 1539 global $_parent_pages; 1484 1540 1485 if ( isset( $_parent_pages[ $menu_slug] ) ) {1486 $parent_slug = $_parent_pages[ $menu_slug];1487 if ( $parent_slug && ! isset( $_parent_pages[ $parent_slug] ) ) {1541 if ( isset( $_parent_pages[ $menu_slug ] ) ) { 1542 $parent_slug = $_parent_pages[ $menu_slug ]; 1543 if ( $parent_slug && ! isset( $_parent_pages[ $parent_slug ] ) ) { 1488 1544 $url = admin_url( add_query_arg( 'page', $menu_slug, $parent_slug ) ); 1489 1545 } else { … … 1494 1550 } 1495 1551 1496 $url = esc_url( $url);1497 1498 if ( $echo ) 1552 $url = esc_url( $url ); 1553 1554 if ( $echo ) { 1499 1555 echo $url; 1556 } 1500 1557 1501 1558 return $url; … … 1506 1563 // 1507 1564 /** 1508 *1509 1565 * @global string $parent_file 1510 1566 * @global array $menu … … 1521 1577 $plugin_page, $_wp_real_parent_file, $_wp_menu_nopriv, $_wp_submenu_nopriv; 1522 1578 1523 if ( !empty ( $parent ) && 'admin.php' != $parent ) { 1524 if ( isset( $_wp_real_parent_file[$parent] ) ) 1525 $parent = $_wp_real_parent_file[$parent]; 1579 if ( ! empty( $parent ) && 'admin.php' != $parent ) { 1580 if ( isset( $_wp_real_parent_file[ $parent ] ) ) { 1581 $parent = $_wp_real_parent_file[ $parent ]; 1582 } 1526 1583 return $parent; 1527 1584 } 1528 1585 1529 1586 if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) { 1530 foreach ( (array) $menu as $parent_menu ) {1587 foreach ( (array) $menu as $parent_menu ) { 1531 1588 if ( $parent_menu[2] == $plugin_page ) { 1532 1589 $parent_file = $plugin_page; 1533 if ( isset( $_wp_real_parent_file[$parent_file] ) ) 1534 $parent_file = $_wp_real_parent_file[$parent_file]; 1590 if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) { 1591 $parent_file = $_wp_real_parent_file[ $parent_file ]; 1592 } 1535 1593 return $parent_file; 1536 1594 } 1537 1595 } 1538 if ( isset( $_wp_menu_nopriv[ $plugin_page] ) ) {1596 if ( isset( $_wp_menu_nopriv[ $plugin_page ] ) ) { 1539 1597 $parent_file = $plugin_page; 1540 if ( isset( $_wp_real_parent_file[$parent_file] ) ) 1541 $parent_file = $_wp_real_parent_file[$parent_file]; 1598 if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) { 1599 $parent_file = $_wp_real_parent_file[ $parent_file ]; 1600 } 1542 1601 return $parent_file; 1543 1602 } 1544 1603 } 1545 1604 1546 if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow][$plugin_page] ) ) {1605 if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow ][ $plugin_page ] ) ) { 1547 1606 $parent_file = $pagenow; 1548 if ( isset( $_wp_real_parent_file[$parent_file] ) ) 1549 $parent_file = $_wp_real_parent_file[$parent_file]; 1607 if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) { 1608 $parent_file = $_wp_real_parent_file[ $parent_file ]; 1609 } 1550 1610 return $parent_file; 1551 1611 } 1552 1612 1553 foreach (array_keys( (array)$submenu ) as $parent) { 1554 foreach ( $submenu[$parent] as $submenu_array ) { 1555 if ( isset( $_wp_real_parent_file[$parent] ) ) 1556 $parent = $_wp_real_parent_file[$parent]; 1557 if ( !empty($typenow) && ($submenu_array[2] == "$pagenow?post_type=$typenow") ) { 1613 foreach ( array_keys( (array) $submenu ) as $parent ) { 1614 foreach ( $submenu[ $parent ] as $submenu_array ) { 1615 if ( isset( $_wp_real_parent_file[ $parent ] ) ) { 1616 $parent = $_wp_real_parent_file[ $parent ]; 1617 } 1618 if ( ! empty( $typenow ) && ( $submenu_array[2] == "$pagenow?post_type=$typenow" ) ) { 1558 1619 $parent_file = $parent; 1559 1620 return $parent; 1560 } elseif ( $submenu_array[2] == $pagenow && empty( $typenow) && ( empty($parent_file) || false === strpos($parent_file, '?') ) ) {1621 } elseif ( $submenu_array[2] == $pagenow && empty( $typenow ) && ( empty( $parent_file ) || false === strpos( $parent_file, '?' ) ) ) { 1561 1622 $parent_file = $parent; 1562 1623 return $parent; 1563 } elseif ( isset( $plugin_page ) && ( $plugin_page == $submenu_array[2] ) ) {1624 } elseif ( isset( $plugin_page ) && ( $plugin_page == $submenu_array[2] ) ) { 1564 1625 $parent_file = $parent; 1565 1626 return $parent; … … 1568 1629 } 1569 1630 1570 if ( empty( $parent_file) )1631 if ( empty( $parent_file ) ) { 1571 1632 $parent_file = ''; 1633 } 1572 1634 return ''; 1573 1635 } 1574 1636 1575 1637 /** 1576 *1577 1638 * @global string $title 1578 1639 * @global array $menu … … 1585 1646 global $title, $menu, $submenu, $pagenow, $plugin_page, $typenow; 1586 1647 1587 if ( ! empty ( $title ) )1648 if ( ! empty( $title ) ) { 1588 1649 return $title; 1650 } 1589 1651 1590 1652 $hook = get_plugin_page_hook( $plugin_page, $pagenow ); … … 1592 1654 $parent = $parent1 = get_admin_page_parent(); 1593 1655 1594 if ( empty ( $parent) ) {1595 foreach ( (array) $menu as $menu_array ) {1656 if ( empty( $parent ) ) { 1657 foreach ( (array) $menu as $menu_array ) { 1596 1658 if ( isset( $menu_array[3] ) ) { 1597 1659 if ( $menu_array[2] == $pagenow ) { 1598 1660 $title = $menu_array[3]; 1599 1661 return $menu_array[3]; 1600 } elseif ( isset( $plugin_page ) && ( $plugin_page == $menu_array[2] ) && ($hook == $menu_array[3] ) ) {1662 } elseif ( isset( $plugin_page ) && ( $plugin_page == $menu_array[2] ) && ( $hook == $menu_array[3] ) ) { 1601 1663 $title = $menu_array[3]; 1602 1664 return $menu_array[3]; … … 1609 1671 } else { 1610 1672 foreach ( array_keys( $submenu ) as $parent ) { 1611 foreach ( $submenu[ $parent] as $submenu_array ) {1673 foreach ( $submenu[ $parent ] as $submenu_array ) { 1612 1674 if ( isset( $plugin_page ) && 1613 1675 ( $plugin_page == $submenu_array[2] ) && … … 1617 1679 ( $plugin_page == $hook ) || 1618 1680 ( $pagenow == 'admin.php' && $parent1 != $submenu_array[2] ) || 1619 ( ! empty($typenow) && $parent == $pagenow . '?post_type=' . $typenow)1681 ( ! empty( $typenow ) && $parent == $pagenow . '?post_type=' . $typenow ) 1620 1682 ) 1621 1683 ) { 1622 1684 $title = $submenu_array[3]; 1623 1685 return $submenu_array[3]; 1624 }1625 1626 if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) // not the current page1686 } 1687 1688 if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) { // not the current page 1627 1689 continue; 1690 } 1628 1691 1629 1692 if ( isset( $submenu_array[3] ) ) { … … 1636 1699 } 1637 1700 } 1638 if ( empty ( $title ) ) {1701 if ( empty( $title ) ) { 1639 1702 foreach ( $menu as $menu_array ) { 1640 1703 if ( isset( $plugin_page ) && 1641 1704 ( $plugin_page == $menu_array[2] ) && 1642 1705 ( $pagenow == 'admin.php' ) && 1643 ( $parent1 == $menu_array[2] ) ) 1644 { 1706 ( $parent1 == $menu_array[2] ) ) { 1645 1707 $title = $menu_array[3]; 1646 1708 return $menu_array[3]; 1647 }1709 } 1648 1710 } 1649 1711 } … … 1662 1724 function get_plugin_page_hook( $plugin_page, $parent_page ) { 1663 1725 $hook = get_plugin_page_hookname( $plugin_page, $parent_page ); 1664 if ( has_action( $hook) )1726 if ( has_action( $hook ) ) { 1665 1727 return $hook; 1666 else1728 } else { 1667 1729 return null; 1668 }1669 1670 /** 1671 *1730 } 1731 } 1732 1733 /** 1672 1734 * @global array $admin_page_hooks 1673 1735 * @param string $plugin_page … … 1680 1742 1681 1743 $page_type = 'admin'; 1682 if ( empty ( $parent_page ) || 'admin.php' == $parent_page || isset( $admin_page_hooks[$plugin_page] ) ) {1683 if ( isset( $admin_page_hooks[ $plugin_page] ) ) {1744 if ( empty( $parent_page ) || 'admin.php' == $parent_page || isset( $admin_page_hooks[ $plugin_page ] ) ) { 1745 if ( isset( $admin_page_hooks[ $plugin_page ] ) ) { 1684 1746 $page_type = 'toplevel'; 1685 } elseif ( isset( $admin_page_hooks[ $parent] )) {1686 $page_type = $admin_page_hooks[ $parent];1687 } 1688 } elseif ( isset( $admin_page_hooks[ $parent] ) ) {1689 $page_type = $admin_page_hooks[ $parent];1747 } elseif ( isset( $admin_page_hooks[ $parent ] ) ) { 1748 $page_type = $admin_page_hooks[ $parent ]; 1749 } 1750 } elseif ( isset( $admin_page_hooks[ $parent ] ) ) { 1751 $page_type = $admin_page_hooks[ $parent ]; 1690 1752 } 1691 1753 … … 1696 1758 1697 1759 /** 1698 *1699 1760 * @global string $pagenow 1700 1761 * @global array $menu … … 1711 1772 $parent = get_admin_page_parent(); 1712 1773 1713 if ( ! isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$pagenow] ) )1774 if ( ! isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $parent ][ $pagenow ] ) ) { 1714 1775 return false; 1776 } 1715 1777 1716 1778 if ( isset( $plugin_page ) ) { 1717 if ( isset( $_wp_submenu_nopriv[ $parent][$plugin_page] ) )1779 if ( isset( $_wp_submenu_nopriv[ $parent ][ $plugin_page ] ) ) { 1718 1780 return false; 1719 1720 $hookname = get_plugin_page_hookname($plugin_page, $parent); 1721 1722 if ( !isset($_registered_pages[$hookname]) ) 1781 } 1782 1783 $hookname = get_plugin_page_hookname( $plugin_page, $parent ); 1784 1785 if ( ! isset( $_registered_pages[ $hookname ] ) ) { 1723 1786 return false; 1724 } 1725 1726 if ( empty( $parent) ) { 1727 if ( isset( $_wp_menu_nopriv[$pagenow] ) ) 1787 } 1788 } 1789 1790 if ( empty( $parent ) ) { 1791 if ( isset( $_wp_menu_nopriv[ $pagenow ] ) ) { 1728 1792 return false; 1729 if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) ) 1793 } 1794 if ( isset( $_wp_submenu_nopriv[ $pagenow ][ $pagenow ] ) ) { 1730 1795 return false; 1731 if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) 1796 } 1797 if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow ][ $plugin_page ] ) ) { 1732 1798 return false; 1733 if ( isset( $plugin_page ) && isset( $_wp_menu_nopriv[$plugin_page] ) ) 1799 } 1800 if ( isset( $plugin_page ) && isset( $_wp_menu_nopriv[ $plugin_page ] ) ) { 1734 1801 return false; 1735 foreach (array_keys( $_wp_submenu_nopriv ) as $key ) { 1736 if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) ) 1802 } 1803 foreach ( array_keys( $_wp_submenu_nopriv ) as $key ) { 1804 if ( isset( $_wp_submenu_nopriv[ $key ][ $pagenow ] ) ) { 1737 1805 return false; 1738 if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) ) 1739 return false; 1806 } 1807 if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $key ][ $plugin_page ] ) ) { 1808 return false; 1809 } 1740 1810 } 1741 1811 return true; 1742 1812 } 1743 1813 1744 if ( isset( $plugin_page ) && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[ $plugin_page] ) )1814 if ( isset( $plugin_page ) && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[ $plugin_page ] ) ) { 1745 1815 return false; 1746 1747 if ( isset( $submenu[$parent] ) ) { 1748 foreach ( $submenu[$parent] as $submenu_array ) { 1816 } 1817 1818 if ( isset( $submenu[ $parent ] ) ) { 1819 foreach ( $submenu[ $parent ] as $submenu_array ) { 1749 1820 if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) { 1750 if ( current_user_can( $submenu_array[1] ) )1821 if ( current_user_can( $submenu_array[1] ) ) { 1751 1822 return true; 1752 else1823 } else { 1753 1824 return false; 1825 } 1754 1826 } elseif ( $submenu_array[2] == $pagenow ) { 1755 if ( current_user_can( $submenu_array[1] ) )1827 if ( current_user_can( $submenu_array[1] ) ) { 1756 1828 return true; 1757 else1829 } else { 1758 1830 return false; 1831 } 1759 1832 } 1760 1833 } … … 1762 1835 1763 1836 foreach ( $menu as $menu_array ) { 1764 if ( $menu_array[2] == $parent ) {1765 if ( current_user_can( $menu_array[1] ) )1837 if ( $menu_array[2] == $parent ) { 1838 if ( current_user_can( $menu_array[1] ) ) { 1766 1839 return true; 1767 else1840 } else { 1768 1841 return false; 1842 } 1769 1843 } 1770 1844 } … … 1790 1864 global $new_whitelist_options; 1791 1865 1792 if ( is_array( $new_whitelist_options ) ) 1866 if ( is_array( $new_whitelist_options ) ) { 1793 1867 $options = add_option_whitelist( $new_whitelist_options, $options ); 1868 } 1794 1869 1795 1870 return $options; … … 1808 1883 */ 1809 1884 function add_option_whitelist( $new_options, $options = '' ) { 1810 if ( $options == '' ) 1885 if ( $options == '' ) { 1811 1886 global $whitelist_options; 1812 else1887 } else { 1813 1888 $whitelist_options = $options; 1889 } 1814 1890 1815 1891 foreach ( $new_options as $page => $keys ) { 1816 1892 foreach ( $keys as $key ) { 1817 if ( ! isset($whitelist_options[ $page ]) || !is_array($whitelist_options[ $page ]) ) {1818 $whitelist_options[ $page ] = array();1893 if ( ! isset( $whitelist_options[ $page ] ) || ! is_array( $whitelist_options[ $page ] ) ) { 1894 $whitelist_options[ $page ] = array(); 1819 1895 $whitelist_options[ $page ][] = $key; 1820 1896 } else { 1821 1897 $pos = array_search( $key, $whitelist_options[ $page ] ); 1822 if ( $pos === false ) 1898 if ( $pos === false ) { 1823 1899 $whitelist_options[ $page ][] = $key; 1900 } 1824 1901 } 1825 1902 } … … 1841 1918 */ 1842 1919 function remove_option_whitelist( $del_options, $options = '' ) { 1843 if ( $options == '' ) 1920 if ( $options == '' ) { 1844 1921 global $whitelist_options; 1845 else1922 } else { 1846 1923 $whitelist_options = $options; 1924 } 1847 1925 1848 1926 foreach ( $del_options as $page => $keys ) { 1849 1927 foreach ( $keys as $key ) { 1850 if ( isset( $whitelist_options[ $page ]) && is_array($whitelist_options[ $page ]) ) {1928 if ( isset( $whitelist_options[ $page ] ) && is_array( $whitelist_options[ $page ] ) ) { 1851 1929 $pos = array_search( $key, $whitelist_options[ $page ] ); 1852 if ( $pos !== false ) 1930 if ( $pos !== false ) { 1853 1931 unset( $whitelist_options[ $page ][ $pos ] ); 1932 } 1854 1933 } 1855 1934 } … … 1866 1945 * @param string $option_group A settings group name. This should match the group name used in register_setting(). 1867 1946 */ 1868 function settings_fields( $option_group) {1869 echo "<input type='hidden' name='option_page' value='" . esc_attr( $option_group) . "' />";1947 function settings_fields( $option_group ) { 1948 echo "<input type='hidden' name='option_page' value='" . esc_attr( $option_group ) . "' />"; 1870 1949 echo '<input type="hidden" name="action" value="update" />'; 1871 wp_nonce_field( "$option_group-options");1950 wp_nonce_field( "$option_group-options" ); 1872 1951 } 1873 1952 … … 1880 1959 */ 1881 1960 function wp_clean_plugins_cache( $clear_update_cache = true ) { 1882 if ( $clear_update_cache ) 1961 if ( $clear_update_cache ) { 1883 1962 delete_site_transient( 'update_plugins' ); 1963 } 1884 1964 wp_cache_delete( 'plugins', 'plugins' ); 1885 1965 }
Note: See TracChangeset
for help on using the changeset viewer.