namespace = 'kb-image-picker/v1'; } /** * Registers the routes for the objects of the controller. * * @see register_rest_route() */ public function register_routes() { register_rest_route( $this->namespace, '/process_images', array( array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => array( $this, 'process_images' ), 'permission_callback' => array( $this, 'get_items_permission_check' ), 'args' => $this->get_collection_params(), ), ) ); } /** * Checks if a given request has access to search content. * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has search access, WP_Error object otherwise. */ public function get_items_permission_check( $request ) { return current_user_can( 'edit_posts' ); } /** * Imports a collection of images. * * @param WP_REST_Request $request Full details about the request. * * @return array A list of local or pexels images, where the ID is an attachment_id or pexels_id. * @throws InvalidArgumentException * @throws Throwable * @throws ImageDownloadException */ public function process_images( $request ) { $parameters = (array) $request->get_json_params(); return kadence_blocks()->get( Image_Downloader::class )->download( $parameters ); } /** * Retrieves the query params for the search results collection. * * @return array Collection parameters. */ public function get_collection_params(): array { $query_params = parent::get_collection_params(); $query_params[ self::PROP_IMAGE_TYPE ] = array( 'description' => __( 'The Image type to return', 'kadence-blocks' ), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', ); $query_params[ self::PROP_IMAGE_SIZES ] = array( 'description' => __( 'The Image type to return', 'kadence-blocks' ), 'type' => 'array', 'sanitize_callback' => array( $this, 'sanitize_image_sizes_array' ), ); return $query_params; } }