WC_CLI_Runner::after_wp_load()
Register's all endpoints as commands once WP and WC have all loaded.
Method of the class: WC_CLI_Runner{}
Hooks from the method
Return
null
. Nothing (null).
Usage
$result = WC_CLI_Runner::after_wp_load();
WC_CLI_Runner::after_wp_load() WC CLI Runner::after wp load code WC 9.4.2
public static function after_wp_load() { global $wp_rest_server; $wp_rest_server = new WP_REST_Server(); do_action( 'rest_api_init', $wp_rest_server ); $request = new WP_REST_Request( 'GET', '/' ); $request->set_param( 'context', 'help' ); $response = $wp_rest_server->dispatch( $request ); $response_data = $response->get_data(); if ( empty( $response_data ) ) { return; } // Loop through all of our endpoints and register any valid WC endpoints. foreach ( $response_data['routes'] as $route => $route_data ) { // Only register endpoints for WC and our target version. if ( substr( $route, 0, 4 + strlen( self::$target_rest_version ) ) !== '/wc/' . self::$target_rest_version ) { continue; } // Only register endpoints with schemas. if ( empty( $route_data['schema']['title'] ) ) { /* translators: %s: Route to a given WC-API endpoint */ WP_CLI::debug( sprintf( __( 'No schema title found for %s, skipping REST command registration.', 'woocommerce' ), $route ), 'wc' ); continue; } // Ignore batch endpoints. if ( 'batch' === $route_data['schema']['title'] ) { continue; } // Disable specific endpoints. $route_pieces = explode( '/', $route ); $endpoint_piece = str_replace( '/wc/' . $route_pieces[2] . '/', '', $route ); if ( in_array( $endpoint_piece, self::$disabled_endpoints, true ) ) { continue; } self::register_route_commands( new WC_CLI_REST_Command( $route_data['schema']['title'], $route, $route_data['schema'] ), $route, $route_data ); } }