WC_Admin_Status::status_tools() – Handles output of tools.

You appear to be a bot. Output may be restricted

Description

Handles output of tools.

Usage

WC_Admin_Status::status_tools();

Parameters

Returns

void

Source

File name: woocommerce/includes/admin/class-wc-admin-status.php


Lines:

1 to 59 of 59
  public static function status_tools() {
    if ( ! class_exists( 'WC_REST_System_Status_Tools_Controller' ) ) {
      wp_die( 'Cannot load the REST API to access WC_REST_System_Status_Tools_Controller.' );
    }

    $tools                 = self::get_tools();
    $tool_requires_refresh = false;

    if ( ! empty( $_GET['action'] ) && ! empty( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ), 'debug_action' ) ) { // WPCS: input var ok, sanitization ok.
      $tools_controller = new WC_REST_System_Status_Tools_Controller();
      $action           = wc_clean( wp_unslash( $_GET['action'] ) ); // WPCS: input var ok.

      if ( array_key_exists( $action, $tools ) ) {
        $response = $tools_controller->execute_tool( $action );

        $tool                  = $tools[ $action ];
        $tool_requires_refresh = ArrayUtil::get_value_or_default( $tool, 'requires_refresh', false );
        $tool                  = array(
          'id'          => $action,
          'name'        => $tool['name'],
          'action'      => $tool['button'],
          'description' => $tool['desc'],
          'disabled'    => ArrayUtil::get_value_or_default( $tool, 'disabled', false ),
        );
        $tool                  = array_merge( $tool, $response );

        
/**
 * Fires after a WooCommerce system status tool has been executed.
 *
 * @param array  $tool  Details about the tool that has been executed.
 */
        do_action( 'woocommerce_system_status_tool_executed', $tool );
      } else {
        $response = array(
          'success' => false,
          'message' => __( 'Tool does not exist.', 'woocommerce' ),
        );
      }

      if ( $response['success'] ) {
        echo '<div class="updated inline"><p>' . esc_html( $response['message'] ) . '</p></div>';
      } else {
        echo '<div class="error inline"><p>' . esc_html( $response['message'] ) . '</p></div>';
      }
    }

    // Display message if settings settings have been saved.
    if ( isset( $_REQUEST['settings-updated'] ) ) { // WPCS: input var ok.
      echo '<div class="updated inline"><p>' . esc_html__( 'Your changes have been saved.', 'woocommerce' ) . '</p></div>';
    }

    if ( $tool_requires_refresh ) {
      $tools = self::get_tools();
    }

    include_once __DIR__ . '/views/html-admin-page-status-tools.php';
  }
 

 View on GitHub View on Trac