Ticket #11750: 11750-full-incl-valid-plugins-function.patch
File 11750-full-incl-valid-plugins-function.patch, 8.6 KB (added by , 15 years ago) |
---|
-
wp-admin/includes/plugin.php
258 258 * @param string $plugin Base plugin path from plugins directory. 259 259 * @return bool True, if in the active plugins list. False, not in the list. 260 260 */ 261 function is_plugin_active( $plugin) {262 return in_array( $plugin, apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );261 function is_plugin_active( $plugin ) { 262 return in_array( $plugin, apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) ) ); 263 263 } 264 264 265 265 /** … … 286 286 * @param string $redirect Optional. URL to redirect to. 287 287 * @return WP_Error|null WP_Error on invalid file or null on success. 288 288 */ 289 function activate_plugin( $plugin, $redirect = '') {290 $current = get_option( 'active_plugins');291 $plugin = plugin_basename(trim($plugin));289 function activate_plugin( $plugin, $redirect = '' ) { 290 $current = get_option( 'active_plugins', array() ); 291 $plugin = plugin_basename( trim( $plugin ) ); 292 292 293 293 $valid = validate_plugin($plugin); 294 294 if ( is_wp_error($valid) ) … … 322 322 * @param string|array $plugins Single plugin or list of plugins to deactivate. 323 323 * @param bool $silent Optional, default is false. Prevent calling deactivate hook. 324 324 */ 325 function deactivate_plugins( $plugins, $silent= false) {326 $current = get_option( 'active_plugins');325 function deactivate_plugins( $plugins, $silent = false ) { 326 $current = get_option( 'active_plugins', array() ); 327 327 328 if ( !is_array($plugins) ) 329 $plugins = array($plugins); 330 331 foreach ( $plugins as $plugin ) { 328 foreach ( (array) $plugins as $plugin ) { 332 329 $plugin = plugin_basename($plugin); 333 330 if( ! is_plugin_active($plugin) ) 334 331 continue; … … 475 472 return true; 476 473 } 477 474 475 /** 476 * validate active plugins 477 * 478 * validate all active plugins, deactivates invalid and 479 * returns an array of deactived ones. 480 * 481 * @since unknown 482 * @return array invalid plugins, plugin as key, error as value 483 */ 478 484 function validate_active_plugins() { 479 $ check_plugins = apply_filters( 'active_plugins', get_option('active_plugins') );485 $plugins = apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) ); 480 486 481 // Sanity check. If the active plugin list is not an array, make it an 482 // empty array. 483 if ( !is_array($check_plugins) ) { 487 // validate vartype: array 488 if ( !is_array( $plugins ) ) { 484 489 update_option('active_plugins', array()); 485 490 return; 486 491 } 487 492 488 //Invalid is any plugin that is deactivated due to error.489 493 $invalid = array(); 490 494 491 // If a plugin file does not exist, remove it from the list of active 492 // plugins. 493 foreach ( $check_plugins as $check_plugin ) { 494 $result = validate_plugin($check_plugin); 495 // invalid plugins get deactivated 496 foreach ( $plugins as $plugin ) { 497 $result = validate_plugin( $plugin ); 495 498 if ( is_wp_error( $result ) ) { 496 $invalid[$ check_plugin] = $result;497 deactivate_plugins( $ check_plugin, true);499 $invalid[$plugin] = $result; 500 deactivate_plugins( $plugin, true ); 498 501 } 499 502 } 500 503 return $invalid; -
wp-admin/plugin-editor.php
208 208 <div id="documentation"><label for="docs-list"><?php _e('Documentation:') ?></label> <?php echo $docs_select ?> <input type="button" class="button" value="<?php esc_attr_e( 'Lookup' ) ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'http://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_locale() ) ?>&version=<?php echo urlencode( $wp_version ) ?>&redirect=true'); }" /></div> 209 209 <?php endif; ?> 210 210 <?php if ( is_writeable($real_file) ) : ?> 211 <?php if ( in_array( $file, (array) get_option('active_plugins')) ) { ?>211 <?php if ( in_array( $file, (array) get_option( 'active_plugins', array() ) ) ) { ?> 212 212 <p><?php _e('<strong>Warning:</strong> Making changes to active plugins is not recommended. If your changes cause a fatal error, the plugin will be automatically deactivated.'); ?></p> 213 213 <?php } ?> 214 214 <p class="submit"> -
wp-includes/plugin.php
707 707 } 708 708 } 709 709 710 ?> 710 711 /** 712 * valid plugins 713 * 714 * filter a/the active list of plugins to filenames that are valid to 715 * include. 716 * 717 * Examples: 718 * 719 * valid_plugins(); 720 * return array of standard plugin files to include 721 * 722 * valid_plugins( WPMU_PLUGIN_DIR ) 723 * return array of WPMU plugin files to include 724 * 725 * @param array|string $plugins (optional) list of plugins, will take 726 * active_plugins option as default. 727 * additionally the path of a directory can 728 * be passed as string which will be iterated 729 * for valid plugin files then (WPMU Plugins 730 * flat style). 731 * @param string $dir (optional) plugin directory, defaults to WP_PLUGIN_DIR or 732 * to $plugins if used as string. 733 * @return array list of plugin files (full, absolute path) ripe to be included 734 * @since 3.0 735 */ 736 function valid_plugins( $plugins = null, $dir = null ) { 737 738 if ( is_null( $plugins ) ) 739 $plugins = apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) ); 740 741 if ( is_string( $plugins ) && is_dir( $plugins ) && $dh = opendir( $plugins ) ) { 742 $dir = is_null( $dir ) ? $plugins : $dir; 743 $plugins = array(); 744 while ( ( $plugins[] = readdir( $dh ) ) !== false ); 745 } 746 747 if ( !is_array( $plugins ) ) 748 return array(); 749 750 if ( is_null( $dir ) ) 751 $dir = WP_PLUGIN_DIR; 752 753 // check the $plugin name/filename 754 $valid = array(); 755 foreach( $plugins as $plugin ) { 756 if ( validate_file( $plugin ) // $plugin must validate as file 757 || '.php' != substr( $plugin, -4 ) // $plugin must end with '.php' 758 || !file_exists( $path = $dir . '/' . $plugin ) // $plugin must exist 759 ) continue; 760 $valid[] = $path; 761 } 762 return $valid; 763 } 764 765 ?> 766 No newline at end of file -
wp-includes/update.php
112 112 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 113 113 114 114 $plugins = get_plugins(); 115 $active = get_option( 'active_plugins' );115 $active = get_option( 'active_plugins', array() ); 116 116 $current = get_transient( 'update_plugins' ); 117 117 if ( ! is_object($current) ) 118 118 $current = new stdClass; … … 147 147 $current->last_checked = time(); 148 148 set_transient( 'update_plugins', $current ); 149 149 150 $to_send = (object) compact('plugins', 'active');150 $to_send = (object) compact('plugins', 'active'); 151 151 152 152 $options = array( 153 153 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3), -
wp-settings.php
439 439 if ( !defined( 'MUPLUGINDIR' ) ) 440 440 define( 'MUPLUGINDIR', 'wp-content/mu-plugins' ); // Relative to ABSPATH. For back compat. 441 441 442 if ( is_dir( WPMU_PLUGIN_DIR ) ) { 443 if ( $dh = opendir( WPMU_PLUGIN_DIR ) ) { 444 while ( ( $plugin = readdir( $dh ) ) !== false ) { 445 if ( substr( $plugin, -4 ) == '.php' ) { 446 include_once( WPMU_PLUGIN_DIR . '/' . $plugin ); 447 } 448 } 449 } 450 } 442 foreach ( valid_plugins( WPMU_PLUGIN_DIR ) as $plugin ) 443 include_once( $plugin ); 451 444 do_action('muplugins_loaded'); 452 445 453 446 /** … … 581 574 require(ABSPATH . 'my-hacks.php'); 582 575 } 583 576 584 $current_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) ); 585 if ( is_array($current_plugins) && !defined('WP_INSTALLING') ) { 586 foreach ( $current_plugins as $plugin ) { 587 // check the $plugin filename 588 // Validate plugin filename 589 if ( validate_file($plugin) // $plugin must validate as file 590 || '.php' != substr($plugin, -4) // $plugin must end with '.php' 591 || !file_exists(WP_PLUGIN_DIR . '/' . $plugin) // $plugin must exist 592 ) 593 continue; 594 595 include_once(WP_PLUGIN_DIR . '/' . $plugin); 596 } 577 // include valid plugin files / load plugins into global namespace 578 if ( !defined('WP_INSTALLING') ) { 579 foreach ( valid_plugins() as $plugin ) 580 include_once($plugin); 597 581 unset($plugin); 598 582 } 599 unset($current_plugins);600 583 601 584 require (ABSPATH . WPINC . '/pluggable.php'); 602 585