Runner::after_wp_load()


Source Source

File: libraries/lifterlms-cli/src/Commands/Restful/Runner.php

	public static function after_wp_load() {

		if ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) {
			return;
		}

		if ( ! class_exists( 'WP_REST_Server' ) ) {
			return;
		}

		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;
		}

		foreach ( $response_data['routes'] as $route => $route_data ) {

			// Skip non LifterLMS routes.
			if ( 0 !== strpos( $route, '/llms/' ) ) {
				continue;
			}

			if ( empty( $route_data['schema']['title'] ) ) {
				\WP_CLI::debug( "No schema title found for {$route}, skipping LifterLMS CLI REST command registration.", 'lifterlms' );
				continue;
			}

			$name         = $route_data['schema']['title'];
			$rest_command = new Command( $name, $route, $route_data['schema'] );
			self::register_route_commands( $rest_command, $route, $route_data );

		}

	}

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.