version(), [ 'strategy' => 'defer', ] ); wp_add_inline_script( 'surecart-affiliate-tracking', 'window.SureCartAffiliatesConfig = ' . wp_json_encode( [ 'endpoint' => esc_url_raw( rest_url( "$this->name/v$this->version/$this->endpoint" ) ), ] ) . ';', 'before' ); } /** * Register REST Routes * * @return void */ public function registerRoutes() { register_rest_route( "$this->name/v$this->version", "$this->endpoint", [ [ 'methods' => \WP_REST_Server::CREATABLE, 'callback' => $this->callback( VisitsController::class, 'create' ), 'permission_callback' => '__return_true', 'args' => [ 'affiliation_code' => [ 'description' => esc_html__( 'The affiliation code.', 'surecart' ), 'type' => 'string', 'required' => true, ], 'url' => [ 'description' => esc_html__( 'The URL the visit happened on.', 'surecart' ), 'type' => 'string', 'format' => 'uri', 'required' => true, ], 'referrer' => [ 'description' => esc_html__( 'The page referrer.', 'surecart' ), 'type' => 'string', ], ], ], 'schema' => [ $this, 'get_item_schema' ], ] ); } /** * Get our schema for a visit. * * @return array The schema for a visit. */ public function get_item_schema() { if ( $this->schema ) { // Since WordPress 5.3, the schema can be cached in the $schema property. return $this->schema; } $this->schema = [ '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => $this->endpoint, 'type' => 'object', 'properties' => [ 'id' => [ 'description' => esc_html__( 'Unique identifier for the object.', 'surecart' ), 'type' => 'string', 'readonly' => true, ], ], ]; return $this->schema; } }