WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WC_REST_System_Status_Tools_V2_Controller::execute_tool() public WC 1.0

Actually executes a tool.

{} Это метод класса: WC_REST_System_Status_Tools_V2_Controller{}

Хуки из метода
Возвращает

Массив.

Использование

$WC_REST_System_Status_Tools_V2_Controller = new WC_REST_System_Status_Tools_V2_Controller();
$WC_REST_System_Status_Tools_V2_Controller->execute_tool( $tool );
$tool(строка) (обязательный)
Tool.

Код WC_REST_System_Status_Tools_V2_Controller::execute_tool() WC 4.7.0

<?php
public function execute_tool( $tool ) {
	global $wpdb;
	$ran = true;
	switch ( $tool ) {
		case 'clear_transients':
			wc_delete_product_transients();
			wc_delete_shop_order_transients();
			delete_transient( 'wc_count_comments' );
			delete_transient( 'as_comment_count' );

			$attribute_taxonomies = wc_get_attribute_taxonomies();

			if ( $attribute_taxonomies ) {
				foreach ( $attribute_taxonomies as $attribute ) {
					delete_transient( 'wc_layered_nav_counts_pa_' . $attribute->attribute_name );
				}
			}

			WC_Cache_Helper::get_transient_version( 'shipping', true );
			$message = __( 'Product transients cleared', 'woocommerce' );
			break;

		case 'clear_expired_transients':
			/* translators: %d: amount of expired transients */
			$message = sprintf( __( '%d transients rows cleared', 'woocommerce' ), wc_delete_expired_transients() );
			break;

		case 'delete_orphaned_variations':
			// Delete orphans.
			$result = absint(
				$wpdb->query(
					"DELETE products
				FROM {$wpdb->posts} products
				LEFT JOIN {$wpdb->posts} wp ON wp.ID = products.post_parent
				WHERE wp.ID IS NULL AND products.post_type = 'product_variation';"
				)
			);
			/* translators: %d: amount of orphaned variations */
			$message = sprintf( __( '%d orphaned variations deleted', 'woocommerce' ), $result );
			break;

		case 'clear_expired_download_permissions':
			// Delete expired download permissions and ones with 0 downloads remaining.
			$result = absint(
				$wpdb->query(
					$wpdb->prepare(
						"DELETE FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions
						WHERE ( downloads_remaining != '' AND downloads_remaining = 0 ) OR ( access_expires IS NOT NULL AND access_expires < %s )",
						gmdate( 'Y-m-d', current_time( 'timestamp' ) )
					)
				)
			);
			/* translators: %d: amount of permissions */
			$message = sprintf( __( '%d permissions deleted', 'woocommerce' ), $result );
			break;

		case 'regenerate_product_lookup_tables':
			if ( ! wc_update_product_lookup_tables_is_running() ) {
				wc_update_product_lookup_tables();
			}
			$message = __( 'Lookup tables are regenerating', 'woocommerce' );
			break;
		case 'reset_roles':
			// Remove then re-add caps and roles.
			WC_Install::remove_roles();
			WC_Install::create_roles();
			$message = __( 'Roles successfully reset', 'woocommerce' );
			break;

		case 'recount_terms':
			$product_cats = get_terms(
				'product_cat',
				array(
					'hide_empty' => false,
					'fields'     => 'id=>parent',
				)
			);
			_wc_term_recount( $product_cats, get_taxonomy( 'product_cat' ), true, false );
			$product_tags = get_terms(
				'product_tag',
				array(
					'hide_empty' => false,
					'fields'     => 'id=>parent',
				)
			);
			_wc_term_recount( $product_tags, get_taxonomy( 'product_tag' ), true, false );
			$message = __( 'Terms successfully recounted', 'woocommerce' );
			break;

		case 'clear_sessions':
			$wpdb->query( "TRUNCATE {$wpdb->prefix}woocommerce_sessions" );
			$result = absint( $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key='_woocommerce_persistent_cart_" . get_current_blog_id() . "';" ) ); // WPCS: unprepared SQL ok.
			wp_cache_flush();
			/* translators: %d: amount of sessions */
			$message = sprintf( __( 'Deleted all active sessions, and %d saved carts.', 'woocommerce' ), absint( $result ) );
			break;

		case 'install_pages':
			WC_Install::create_pages();
			$message = __( 'All missing WooCommerce pages successfully installed', 'woocommerce' );
			break;

		case 'delete_taxes':
			$wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rates;" );
			$wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rate_locations;" );

			if ( method_exists( 'WC_Cache_Helper', 'invalidate_cache_group' ) ) {
				WC_Cache_Helper::invalidate_cache_group( 'taxes' );
			} else {
				WC_Cache_Helper::incr_cache_prefix( 'taxes' );
			}
			$message = __( 'Tax rates successfully deleted', 'woocommerce' );
			break;

		case 'regenerate_thumbnails':
			WC_Regenerate_Images::queue_image_regeneration();
			$message = __( 'Thumbnail regeneration has been scheduled to run in the background.', 'woocommerce' );
			break;

		case 'db_update_routine':
			$blog_id = get_current_blog_id();
			// Used to fire an action added in WP_Background_Process::_construct() that calls WP_Background_Process::handle_cron_healthcheck().
			// This method will make sure the database updates are executed even if cron is disabled. Nothing will happen if the updates are already running.
			do_action( 'wp_' . $blog_id . '_wc_updater_cron' );
			$message = __( 'Database upgrade routine has been scheduled to run in the background.', 'woocommerce' );
			break;

		case 'clear_template_cache':
			if ( function_exists( 'wc_clear_template_cache' ) ) {
				wc_clear_template_cache();
				$message = __( 'Template cache cleared.', 'woocommerce' );
			} else {
				$message = __( 'The active version of WooCommerce does not support template cache clearing.', 'woocommerce' );
				$ran = false;
			}
			break;

		case 'verify_db_tables':
			if ( ! method_exists( 'WC_Install', 'verify_base_tables' ) ) {
				$message = __( 'You need WooCommerce 4.2 or newer to run this tool.', 'woocommerce' );
				$ran = false;
				break;
			}
			// Try to manually create table again.
			$missing_tables = WC_Install::verify_base_tables( true, true );
			if ( 0 === count( $missing_tables ) ) {
				$message = __( 'Database verified successfully.', 'woocommerce' );
			} else {
				$message = __( 'Verifying database... One or more tables are still missing: ', 'woocommerce' );
				$message .= implode( ', ', $missing_tables );
				$ran = false;
			}
			break;

		default:
			$tools = $this->get_tools();
			if ( isset( $tools[ $tool ]['callback'] ) ) {
				$callback = $tools[ $tool ]['callback'];
				$return   = call_user_func( $callback );
				if ( is_string( $return ) ) {
					$message = $return;
				} elseif ( false === $return ) {
					$callback_string = is_array( $callback ) ? get_class( $callback[0] ) . '::' . $callback[1] : $callback;
					$ran             = false;
					/* translators: %s: callback string */
					$message = sprintf( __( 'There was an error calling %s', 'woocommerce' ), $callback_string );
				} else {
					$message = __( 'Tool ran.', 'woocommerce' );
				}
			} else {
				$ran     = false;
				$message = __( 'There was an error calling this tool. There is no callback present.', 'woocommerce' );
			}
			break;
	}

	return array(
		'success' => $ran,
		'message' => $message,
	);
}