wordpress-fontawesome icon indicating copy to clipboard operation
wordpress-fontawesome copied to clipboard

documentation missing - FontAwesome::query()

Open zagarskas opened this issue 11 months ago • 0 comments

This link on this page is 404 image

https://fortawesome.github.io/wordpress-fontawesome/classes/FortAwesome.FontAwesome.html#method_query

Searching google for FontAwesome::query() brings no love.

Also note, the documentation on the following pages may not be accurate (or PHP8.2 and WPengine may be at fault here)

  • https://docs.fontawesome.com/apis/graphql/get-started
  • Content-Type: application/json does not work

The following would have been super helpful to know.

$api_get = '/font-awesome/v1/api';
		$request = new WP_REST_Request( 'POST', $api_get );

		$request->set_header( 'content-type', 'application/graphql' ); // works
               // FAILS: $request->set_header( 'content-type', 'application/json' );
		
	        /// all of these will fail with 'application/json' but work with application/graphql
		//$request->set_body( 'query { me { kits { token name } } }' );
		//$request->set_body( 'query { search (version: "6.0.0", query: "lightsaber", first: 5) { id } }' );
		$request->set_body( 'query { search (version: "6.0.0", query: "lightsaber", first: 15) { id unicode membership {free pro}	} }' );
				
		$response = rest_do_request( $request );

		if ( $response->is_error() ) { echo " failed"; print_r( $response );}
				
		if ( !$response->is_error() ) {
			echo "===worked=== ";
			$select2_json_data = $response->get_data();
			print_r( $select2_json_data );
			$headers = $response->get_headers();
			print_r( $headers );
		}
		exit();

I was able to find public function query( $request ) within class-fontawesome-api-controller.php which is what lead me to believe I should be using WP_REST_Request because class FontAwesome_API_Controller extends WP_REST_Controller

In closing:

  1. FontAwesome::query() documentation would be good
  2. showing working examples for WP_REST_Request on docs.fontawesome.com would be nice
  3. Lost lots of life on this... time I will want back on my deathbed. (maybe blame php 8.2? anyway, "documentation missing => life missing") image

PS: the WP plugin is super cool in all other regards. I have now read through most of the code, its nicely done.

zagarskas avatar Mar 08 '24 03:03 zagarskas