Ticket #5625: 5625.r8539.diff
File 5625.r8539.diff, 15.9 KB (added by , 16 years ago) |
---|
-
wp-admin/includes/plugin.php
157 157 return $wp_plugins; 158 158 } 159 159 160 function is_plugin_active($plugin){ 160 /** 161 * Check whether the plugin is active by checking the active_plugins list. 162 * 163 * @since 2.5.0 164 * 165 * @param string $plugin Base plugin path from plugins directory. 166 * @return bool True, if in the active plugins list. False, not in the list. 167 */ 168 function is_plugin_active($plugin) { 161 169 return in_array($plugin, get_option('active_plugins')); 162 170 } 163 171 … … 328 336 return 0; 329 337 } 330 338 339 /** 340 * Whether the plugin can be uninstalled. 341 * 342 * @since {@internal Version Unknown}} 343 * 344 * @param string $plugin Plugin path to check. 345 * @return bool Whether plugin can be uninstalled. 346 */ 347 function is_uninstallable_plugin($plugin) { 348 $file = plugin_basename($plugin); 349 350 $uninstallable_plugins = (array) get_option('uninstall_plugins'); 351 if ( isset( $uninstallable_plugins[$file] ) || file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) ) 352 return true; 353 354 return false; 355 } 356 357 /** 358 * Uninstall a single plugin. 359 * 360 * Calls the uninstall hook, if it is available. 361 * 362 * @param string $plugin Relative plugin path from Plugin Directory. 363 */ 364 function uninstall_plugin($plugin) { 365 $file = plugin_basename($plugin); 366 367 if ( is_plugin_active($file) ) 368 return false; 369 370 $uninstallable_plugins = (array) get_option('uninstall_plugins'); 371 if ( file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) ) { 372 if ( isset( $uninstallable_plugins[$file] ) ) { 373 unset($uninstallable_plugins[$file]); 374 set_option('uninstall_plugins', $uninstallable_plugins); 375 } 376 unset($uninstallable_plugins); 377 378 define('WP_UNINSTALL_PLUGIN', $file); 379 include WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php'; 380 381 return true; 382 } 383 384 if ( isset( $uninstallable_plugins[$file] ) ) { 385 $callable = $uninstallable_plugins[$file]; 386 unset($uninstallable_plugins[$file]); 387 set_option('uninstall_plugins', $uninstallable_plugins); 388 unset($uninstallable_plugins); 389 390 include WP_PLUGIN_DIR . '/' . $file; 391 392 add_action( 'uninstall_' . $file, $callable ); 393 do_action( 'uninstall_' . $file ); 394 395 deactivate_plugins($file, true); 396 } 397 } 398 399 /** 400 * Uninstall multiple plugins. 401 * 402 * @since {@internal Version Unknown}} 403 * 404 * @param array $plugins 405 * @return bool Whether uninstall process is completed. 406 */ 407 function uninstall_plugins($plugins) { 408 if ( !is_array($plugins) ) 409 $plugins = array($plugins); 410 411 foreach ( (array) $plugins as $plugin ) 412 uninstall_plugin($plugin); 413 414 return true; 415 } 416 331 417 // 332 418 // Menu 333 419 // … … 616 702 return true; 617 703 } 618 704 619 ?> 705 ?> 706 No newline at end of file -
wp-admin/plugins.php
2 2 require_once('admin.php'); 3 3 4 4 $action = ''; 5 foreach( array(' activate-selected', 'deactivate-selected', 'delete-selected', 'clear-recent-list') as $action_key ) {5 foreach( array('uninstall-selected', 'activate-selected', 'deactivate-selected', 'delete-selected', 'clear-recent-list') as $action_key ) { 6 6 if( isset($_POST[$action_key]) ) { 7 7 $action = $action_key; 8 8 break; … … 44 44 wp_redirect('plugins.php?activate-multi=true'); 45 45 exit; 46 46 break; 47 case 'uninstall': 48 check_admin_referer('uninstall-plugin_' . $plugin); 49 uninstall_plugin($plugin); 50 wp_redirect('plugins.php?uninstall=true'); 51 exit; 52 break; 53 case 'uninstall-selected': 54 check_admin_referer('bulk-manage-plugins'); 55 uninstall_plugins($_POST['checked']); 56 wp_redirect('plugins.php?uninstall-multi=true'); 57 exit; 58 break; 47 59 case 'error_scrape': 48 60 check_admin_referer('plugin-activation-error_' . $plugin); 49 61 $valid = validate_plugin($plugin); … … 194 206 <div id="message" class="updated fade"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div> 195 207 <?php elseif (isset($_GET['deactivate-multi'])) : ?> 196 208 <div id="message" class="updated fade"><p><?php _e('Selected plugins <strong>deactivated</strong>.'); ?></p></div> 209 <?php elseif ( isset($_GET['uninstall']) ) : ?> 210 <div id="message" class="updated fade"><p><?php _e('Plugin <strong>uninstalled</strong>.') ?></p></div> 211 <?php elseif ( isset($_GET['uninstall-multi']) ) : ?> 212 <div id="message" class="updated fade"><p><?php _e('Selected plugins <strong>uninstalled</strong>.') ?></p></div> 197 213 <?php endif; ?> 198 214 199 215 <div class="wrap"> … … 292 308 if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) ) 293 309 $action_links[] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>'; 294 310 311 if( 'active' != $context && is_uninstallable_plugin($plugin_file) ) 312 $action_links[] = '<a href="' . wp_nonce_url('plugins.php?action=uninstall&plugin=' . $plugin_file, 'uninstall-plugin_' . $plugin_file) . '" title="' . __('Uninstall this plugin') . '" class="uninstall">' . __('Uninstall') . '</a>'; 313 295 314 $action_links = apply_filters('plugin_action_links', $action_links, $plugin_file, $plugin_data, $context); 296 315 297 316 echo " … … 340 359 <div class="tablenav"> 341 360 <div class="alignleft"> 342 361 <input type="submit" name="activate-selected" value="<?php _e('Activate') ?>" class="button-secondary" /> 362 <input type="submit" name="uninstall-selected" value="<?php _e('Uninstall') ?>" class="button-secondary" /> 343 363 <?php if( current_user_can('delete_plugins') ) : ?> 344 364 <input type="submit" name="delete-selected" value="<?php _e('Delete') ?>" class="button-secondary" /> 345 365 <?php endif; ?> … … 359 379 <div class="tablenav"> 360 380 <div class="alignleft"> 361 381 <input type="submit" name="activate-selected" value="<?php _e('Activate') ?>" class="button-secondary" /> 382 <input type="submit" name="uninstall-selected" value="<?php _e('Uninstall') ?>" class="button-secondary" /> 362 383 <?php if( current_user_can('delete_plugins') ) : ?> 363 384 <input type="submit" name="delete-selected" value="<?php _e('Delete') ?>" class="button-secondary" /> 364 385 <?php endif; ?> -
wp-includes/plugin.php
20 20 */ 21 21 22 22 /** 23 * add_filter() -Hooks a function or method to a specific filter action.23 * Hooks a function or method to a specific filter action. 24 24 * 25 25 * Filters are the hooks that WordPress launches to modify text of various types 26 26 * before adding it to the database or sending it to the browser screen. Plugins … … 69 69 } 70 70 71 71 /** 72 * has_filter() -Check if any filter has been registered for a hook.72 * Check if any filter has been registered for a hook. 73 73 * 74 74 * @package WordPress 75 75 * @subpackage Plugin … … 99 99 } 100 100 101 101 /** 102 * apply_filters() -Call the functions added to a filter hook.102 * Call the functions added to a filter hook. 103 103 * 104 104 * The callback functions attached to filter hook <tt>$tag</tt> are invoked by 105 105 * calling this function. This function can be used to create a new filter hook … … 171 171 } 172 172 173 173 /** 174 * remove_filter() -Removes a function from a specified filter hook.174 * Removes a function from a specified filter hook. 175 175 * 176 176 * This function removes a function attached to a specified filter hook. This 177 177 * method can be used to remove default functions attached to a specific filter 178 178 * hook and possibly replace them with a substitute. 179 179 * 180 * To remove a hook, the <tt>$function_to_remove</tt> and <tt>$priority</tt> arguments181 * must matchwhen the hook was added. This goes for both filters and actions. No warning180 * To remove a hook, the $function_to_remove and $priority arguments must match 181 * when the hook was added. This goes for both filters and actions. No warning 182 182 * will be given on removal failure. 183 183 * 184 184 * @package WordPress … … 208 208 209 209 210 210 /** 211 * current_filter() -Return the name of the current filter or action.211 * Return the name of the current filter or action. 212 212 * 213 213 * @package WordPress 214 214 * @subpackage Plugin … … 223 223 224 224 225 225 /** 226 * add_action() -Hooks a function on to a specific action.226 * Hooks a function on to a specific action. 227 227 * 228 228 * Actions are the hooks that the WordPress core launches at specific points 229 229 * during execution, or when specific events occur. Plugins can specify that … … 247 247 248 248 249 249 /** 250 * do_action() -Execute functions hooked on a specific action hook.250 * Execute functions hooked on a specific action hook. 251 251 * 252 252 * This function invokes all functions attached to action hook <tt>$tag</tt>. 253 253 * It is possible to create new action hooks by simply calling this function, … … 316 316 } 317 317 318 318 /** 319 * did_action() -Return the number times an action is fired.319 * Return the number times an action is fired. 320 320 * 321 321 * @package WordPress 322 322 * @subpackage Plugin … … 336 336 } 337 337 338 338 /** 339 * do_action_ref_array() -Execute functions hooked on a specific action hook, specifying arguments in an array.339 * Execute functions hooked on a specific action hook, specifying arguments in an array. 340 340 * 341 341 * @see do_action() This function is identical, but the arguments passed to 342 342 * the functions hooked to <tt>$tag</tt> are supplied using an array. … … 391 391 } 392 392 393 393 /** 394 * has_action() -Check if any action has been registered for a hook.394 * Check if any action has been registered for a hook. 395 395 * 396 396 * @package WordPress 397 397 * @subpackage Plugin … … 407 407 } 408 408 409 409 /** 410 * remove_action() -Removes a function from a specified action hook.410 * Removes a function from a specified action hook. 411 411 * 412 412 * This function removes a function attached to a specified action hook. This 413 413 * method can be used to remove default functions attached to a specific filter … … 432 432 // 433 433 434 434 /** 435 * plugin_basename() -Gets the basename of a plugin.435 * Gets the basename of a plugin. 436 436 * 437 437 * This method extracts the name of a plugin from its filename. 438 438 * … … 456 456 } 457 457 458 458 /** 459 * register_activation_hook() - Hook a function on a plugin activation action hook.459 * Set the activation hook for a plugin. 460 460 * 461 461 * When a plugin is activated, the action 'activate_PLUGINNAME' hook is 462 462 * activated. In the name of this hook, PLUGINNAME is replaced with the name of … … 474 474 * @access private 475 475 * 476 476 * @param string $file The filename of the plugin including the path. 477 * @param string$function the function hooked to the 'activate_PLUGIN' action.477 * @param callback $function the function hooked to the 'activate_PLUGIN' action. 478 478 */ 479 479 function register_activation_hook($file, $function) { 480 480 $file = plugin_basename($file); … … 482 482 } 483 483 484 484 /** 485 * register_deactivation_hook() - Hook a function on a plugin deactivation action hook.485 * Set the deactivation hook for a plugin. 486 486 * 487 487 * When a plugin is deactivated, the action 'deactivate_PLUGINNAME' hook is 488 * deactivated. In the name of this hook, PLUGINNAME is replaced with the name of 489 * the plugin, including the optional subdirectory. For example, when the plugin 490 * is located in <tt>wp-content/plugin/sampleplugin/sample.php</tt>, then the 491 * name of this hook will become 'activate_sampleplugin/sample.php'. 488 * deactivated. In the name of this hook, PLUGINNAME is replaced with the name 489 * of the plugin, including the optional subdirectory. For example, when the 490 * plugin is located in <tt>wp-content/plugin/sampleplugin/sample.php</tt>, then 491 * the name of this hook will become 'activate_sampleplugin/sample.php'. 492 * 492 493 * When the plugin consists of only one file and is (as by default) located at 493 494 * <tt>wp-content/plugin/sample.php</tt> the name of this hook will be 494 495 * 'activate_sample.php'. … … 500 501 * @access private 501 502 * 502 503 * @param string $file The filename of the plugin including the path. 503 * @param string$function the function hooked to the 'activate_PLUGIN' action.504 * @param callback $function the function hooked to the 'activate_PLUGIN' action. 504 505 */ 505 506 function register_deactivation_hook($file, $function) { 506 507 $file = plugin_basename($file); … … 508 509 } 509 510 510 511 /** 511 * _wp_call_all_hook() - Calls the 'all' hook, which will process the functions hooked into it.512 * Set the uninstallation hook for a plugin. 512 513 * 513 * The 'all' hook passes all of the arguments or parameters that were used for the 514 * hook, which this function was called for. 514 * Registers the uninstall hook that will be called when the user clicks on the 515 * uninstall link that calls for the plugin to uninstall itself. The link won't 516 * be active unless the plugin hooks into the action. 515 517 * 516 * This function is used internally for apply_filters(), do_action(), and do_action_ref_array() 517 * and is not meant to be used from outside those functions. This function does not check for the 518 * existence of the all hook, so it will fail unless the all hook exists prior to this function call. 518 * The plugin should not run arbitrary code outside of functions, when 519 * registering the uninstall hook. In order to run using the hook, the plugin 520 * will have to be included, which means that any code laying outside of a 521 * function will be run during the uninstall process. The plugin should not 522 * hinder the uninstall process. 519 523 * 524 * If the plugin can not be written without running code within the plugin, then 525 * the plugin should create a file named 'uninstall.php' in the base plugin 526 * folder. This file will be called, if it exists, during the uninstall process 527 * bypassing the uninstall hook. The plugin, when using the 'uninstall.php' 528 * should always check for the 'WP_UNINSTALLING_PLUGIN' constant, before 529 * executing. 530 * 531 * @param string $file 532 * @param callback $callback The callback to run when the hook is called. 533 */ 534 function register_uninstall_hook($file, $callback) { 535 // The option should not be autoloaded, because it is not needed in most 536 // cases. Emphasis should be put on using the 'uninstall.php' way of 537 // uninstalling the plugin. 538 $uninstallable_plugins = (array) get_option('uninstall_plugins'); 539 $uninstallable_plugins[$file] = $callback; 540 set_option('uninstall_plugins', $uninstallable_plugins); 541 } 542 543 /** 544 * Calls the 'all' hook, which will process the functions hooked into it. 545 * 546 * The 'all' hook passes all of the arguments or parameters that were used for 547 * the hook, which this function was called for. 548 * 549 * This function is used internally for apply_filters(), do_action(), and 550 * do_action_ref_array() and is not meant to be used from outside those 551 * functions. This function does not check for the existence of the all hook, so 552 * it will fail unless the all hook exists prior to this function call. 553 * 520 554 * @package WordPress 521 555 * @subpackage Plugin 522 556 * @since 2.5 … … 540 574 } 541 575 542 576 /** 543 * _wp_filter_build_unique_id() - Build Unique ID for storage and retrieval577 * Build Unique ID for storage and retrieval. 544 578 * 545 579 * The old way to serialize the callback caused issues and this function is the 546 580 * solution. It works by checking for objects and creating an a new property in … … 549 583 * 550 584 * It also allows for the removal of actions and filters for objects after they 551 585 * change class properties. It is possible to include the property $wp_filter_id 552 * in your class and set it to "null" or a number to bypass the workaround. However553 * this will prevent you from adding new classes and any new classes will overwrite554 * the previous hook by the same class.586 * in your class and set it to "null" or a number to bypass the workaround. 587 * However this will prevent you from adding new classes and any new classes 588 * will overwrite the previous hook by the same class. 555 589 * 556 * Functions and static method callbacks are just returned as strings and shouldn't557 * have any speed penalty.590 * Functions and static method callbacks are just returned as strings and 591 * shouldn't have any speed penalty. 558 592 * 559 593 * @package WordPress 560 594 * @subpackage Plugin