delete_plugins

Definition:
function delete_plugins($plugins, $redirect = '' ) {}

Remove directory and files of a plugin for a single or list of plugin(s).
If the plugins parameter list is empty, false will be returned. True when completed.

Parameters

  • array $plugins: List of plugin
  • string $redirect: Redirect to page when complete.

Source code

function delete_plugins($plugins, $redirect = '' ) {

	global $wp_filesystem;



	if ( empty($plugins) )

		return false;



	$checked = array();

	foreach( $plugins as $plugin )

		$checked[] = 'checked[]=' . $plugin;



	ob_start();

	$url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-plugins');

	if ( false === ($credentials = request_filesystem_credentials($url)) ) {

		$data = ob_get_contents();

		ob_end_clean();

		if ( ! empty($data) ){

			include_once( ABSPATH . 'wp-admin/admin-header.php');

			echo $data;

			include( ABSPATH . 'wp-admin/admin-footer.php');

			exit;

		}

		return;

	}



	if ( ! WP_Filesystem($credentials) ) {

		request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again

		$data = ob_get_contents();

		ob_end_clean();

		if ( ! empty($data) ){

			include_once( ABSPATH . 'wp-admin/admin-header.php');

			echo $data;

			include( ABSPATH . 'wp-admin/admin-footer.php');

			exit;

		}

		return;

	}



	if ( ! is_object($wp_filesystem) )

		return new WP_Error('fs_unavailable', __('Could not access filesystem.'));



	if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )

		return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);



	//Get the base plugin folder

	$plugins_dir = $wp_filesystem->wp_plugins_dir();

	if ( empty($plugins_dir) )

		return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.'));



	$plugins_dir = trailingslashit( $plugins_dir );



	$errors = array();



	foreach( $plugins as $plugin_file ) {

		// Run Uninstall hook

		if ( is_uninstallable_plugin( $plugin_file ) )

			uninstall_plugin($plugin_file);



		$this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin_file) );

		// If plugin is in its own directory, recursively delete the directory.

		if ( strpos($plugin_file, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory separator AND that its not the root plugin folder

			$deleted = $wp_filesystem->delete($this_plugin_dir, true);

		else

			$deleted = $wp_filesystem->delete($plugins_dir . $plugin_file);



		if ( ! $deleted )

			$errors[] = $plugin_file;

	}



	if ( ! empty($errors) )

		return new WP_Error('could_not_remove_plugin', sprintf(__('Could not fully remove the plugin(s) %s.'), implode(', ', $errors)) );



	// Force refresh of plugin update information

	if ( $current = get_site_transient('update_plugins') ) {

		unset( $current->response[ $plugin_file ] );

		set_site_transient('update_plugins', $current);

	}



	return true;

}

804

delete_option

Definition:
function delete_option( $option ) {}

Removes option by name. Prevents removal of protected WordPress options.

Parameters

  • string $option: Name of option to remove. Expected to not be SQL-escaped.

Return values

returns:True, if option is successfully deleted. False on failure.

Defined actions

  • delete_option
    do_action( 'delete_option', $option );
  • delete_option_$option
    do_action( "delete_option_$option", $option );
  • deleted_option
    do_action( 'deleted_option', $option );

Source code

function delete_option( $option ) {

	global $wpdb;



	wp_protect_special_option( $option );



	// Get the ID, if no ID then return

	$row = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) );

	if ( is_null( $row ) )

		return false;

	do_action( 'delete_option', $option );

	$result = $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name = %s", $option) );

	if ( ! defined( 'WP_INSTALLING' ) ) {

		if ( 'yes' == $row->autoload ) {

			$alloptions = wp_load_alloptions();

			if ( is_array( $alloptions ) && isset( $alloptions[$option] ) ) {

				unset( $alloptions[$option] );

				wp_cache_set( 'alloptions', $alloptions, 'options' );

			}

		} else {

			wp_cache_delete( $option, 'options' );

		}

	}

	if ( $result ) {

		do_action( "delete_option_$option", $option );

		do_action( 'deleted_option', $option );

		return true;

	}

	return false;

}

802

delete_get_calendar_cache

Definition:
function delete_get_calendar_cache() {}

Purge the cached results of get_calendar.

Source code

function delete_get_calendar_cache() {

	wp_cache_delete( 'get_calendar', 'calendar' );

}

796