WordPress.org

Forums

WP REST API (WP API)
[resolved] Extending WP_JSON_CustomPostType gives (2 posts)

  1. Patrick Hesselberg
    Member
    Posted 1 year ago #

    Error message:
    Catchable fatal error: Argument 1 passed to WP_JSON_CustomPostType::__construct() must implement interface WP_JSON_ResponseHandler, none given, called in /var/www/wp-content/plugins/... on line 12 and defined in /var/www/wp-content/plugins/json-rest-api/lib/class-wp-json-customposttype.php on line 31

    Code:

    function osd_api() {
    	global $osd_api;
    
    	$osd_api = new OSD_API();
    	add_filter( 'json_endpoints', array( $osd_api, 'register_routes' ) );
    }
    add_action( 'plugins_loaded', 'osd_api' );
    
    class OSD_API extends WP_JSON_CustomPostType {
    	protected $base = '/swimmers';
    	protected $type = 'swimmer';
    
    	function register_routes( $routes ) {
    		$routes = parent::registerRoutes( $routes );
    
    		return $routes;
    	}
    }

    I've tryed to follow your guide here but it also gives me the error message even if I change my code to the example code (the second one).

    http://wordpress.org/plugins/json-rest-api/

  2. Patrick Hesselberg
    Member
    Posted 1 year ago #

    After having a deep look into the code I realized that I should change the hook:
    add_action( 'wp_json_server_before_serve', 'osd_api' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.