ray( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_presets' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); register_rest_route( $this->namespace, '/' . $this->rest_base . '/configs', array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_configs' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); } /** * Get a collection of items. * * @param WP_REST_Request $request Full details about the request. * @return WP_Error|WP_REST_Response */ public function get_items( $request ) { $objects = array(); $items = $this->controller->get_items(); foreach ( $items as $data ) { $object = new Banner( (int) $data->banner_id ); $data = $this->prepare_item_for_response( $object, $request ); $objects[] = $this->prepare_response_for_collection( $data ); } // Wrap the data in a response object. return rest_ensure_response( $objects ); } /** * Get a collection of items. * * @param WP_REST_Request $request Full details about the request. * @return WP_Error|WP_REST_Response */ public function get_item( $request ) { $object = new Banner( (int) $request['id'] ); if ( ! $object || 0 === $object->get_id() ) { return new WP_Error( 'cookieyes_rest_invalid_id', __( 'Invalid ID.', 'cookie-law-info' ), array( 'status' => 404 ) ); } $data = $this->prepare_item_for_response( $object, $request ); return rest_ensure_response( $data ); } /** * Create a new banner. * * @param WP_REST_Request $request Full details about the request. * @return WP_Error|WP_REST_Response */ public function create_item( $request ) { if ( ! empty( $request['id'] ) ) { return new WP_Error( 'cookieyes_rest_item_exists', __( 'Cannot create existing banner.', 'cookie-law-info' ), array( 'status' => 400 ) ); } $object = $this->prepare_item_for_database( $request ); $object->save(); $data = $this->prepare_item_for_response( $object, $request ); return rest_ensure_response( $data ); } /** * Update an existing banner. * * @param WP_REST_Request $request Full details about the request. * @return WP_Error|WP_REST_Response */ public function update_item( $request ) { if ( empty( $request['id'] ) ) { return new WP_Error( 'cookieyes_rest_item_exists', __( 'Invalid banner id', 'cookie-law-info' ), array( 'status' => 400 ) ); } $registered = $this->get_collection_params(); $object = $this->prepare_item_for_database( $request ); if ( isset( $registered['language'], $request['language'] ) ) { $object->set_language( sanitize_text_field( $request['language'] ) ); } $object->save(); $data = $this->prepare_item_for_response( $object, $request ); return rest_ensure_response( $data ); } /** * Delete an existing banner. * * @param WP_REST_Request $request Full details about the request. * @return WP_Error|WP_REST_Response */ public function delete_item( $request ) { if ( empty( $request['id'] ) ) { return new WP_Error( 'cookieyes_rest_item_exists', __( 'Invalid banner id', 'cookie-law-info' ), array( 'status' => 400 ) ); } $banner_id = $request['id']; $data = $this->controller->remove( $banner_id ); return rest_ensure_response( $data ); } /** * Performs bulk update request. * * @param object $request WP request object. * @return array */ public function bulk( $request ) { try { if ( ! isset( $request['banners'] ) ) { return new WP_Error( 'cookieyes_rest_invalid_data', __( 'No data specified to create/edit banners', 'cookie-law-info' ), array( 'status' => 404 ) ); } if ( ! defined( 'CKY_BULK_REQUEST' ) ) { define( 'CKY_BULK_REQUEST', true ); } $item_objects = array(); $objects = array(); $data = $request['banners']; foreach ( $data as $_banner ) { $object = $this->prepare_item_for_database( $_banner ); $object->save(); $item_objects[] = $object; } foreach ( $item_objects as $data ) { $data = $this->prepare_item_for_response( $data, $request ); $objects[] = $this->prepare_response_for_collection( $data ); } do_action( 'cky_after_update_banner' ); return rest_ensure_response( $objects ); } catch ( Exception $e ) { return new WP_Error( $e->getCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } } /** * Load banner preview. * * @param WP_REST_Request $request WP_REST_Request object. * @return WP_Error|WP_REST_Response */ public function get_preview( $request ) { $data = array(); if ( ! defined( 'CKY_PREVIEW_REQUEST' ) ) { define( 'CKY_PREVIEW_REQUEST', true ); } $object = $this->prepare_item_for_database( $request ); $language = isset( $request['language'] ) ? $request['language'] : cky_default_language(); $object->set_language( $language ); $template = $object->get_template(); $data['html'] = $template['html']; $data['styles'] = $template['styles']; return rest_ensure_response( $data ); } /** * Load presets * * @param WP_REST_Request $request WP_REST_Request object. * @return WP_Error|WP_REST_Response */ public function get_presets( $request ) { $registered = $this->get_collection_params(); $presets = array(); if ( isset( $registered['ver'], $request['ver'] ) ) { $template = new \CookieYes\Lite\Admin\Modules\Banners\Includes\Template( false ); $presets = $template->get_presets( $request['ver'] ); } return rest_ensure_response( $presets ); } /** * Load default banner configs * * @return WP_Error|WP_REST_Response */ public function get_configs() { $configs = array( 'gdpr' => $this->controller->get_default_configs(), 'ccpa' => $this->controller->get_default_configs( 'ccpa' ), ); return rest_ensure_response( $configs ); } /** * Format data to provide output to API * * @param object $object Object of the corresponding item. * @param array $request Request params. * @return array */ public function prepare_item_for_response( $object, $request ) { $data = $this->get_formatted_item_data( $object ); $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data = $this->filter_response_by_context( $data, $context ); return rest_ensure_response( $data ); } /** * Format the support before sending. * * @param Banner $object Banner object. * @return object */ public function get_formatted_item_data( $object ) { return array( 'id' => $object->get_id(), 'slug' => $object->get_slug(), 'name' => $object->get_name(), 'status' => $object->get_status(), 'default' => $object->get_default(), 'properties' => $object->get_settings(), 'contents' => $object->get_contents(), ); } /** * Prepare a single item for create or update. * * @param WP_REST_Request $request Request object. * @return object */ public function prepare_item_for_database( $request ) { $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; $object = new Banner( $id ); $object->set_name( $request['name'] ); $object->set_default( $request['default'] ); $object->set_status( $request['status'] ); $object->set_settings( $request['properties'] ); $object->set_contents( $request['contents'] ); return $object; } /** * Get the query params for collections. * * @return array */ public function get_collection_params() { return array( 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 'search' => array( 'description' => __( 'Limit results to those matching a string.', 'cookie-law-info' ), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg', ), 'ver' => array( 'description' => __( 'Version', 'cookie-law-info' ), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg', ), 'language' => array( 'description' => __( 'Language of the banner', 'cookie-law-info' ), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg', ), ); } /** * Get the Consent logs's schema, conforming to JSON Schema. * * @return array */ public function get_item_schema() { $schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'Banners', 'type' => 'object', 'properties' => array( 'id' => array( 'description' => __( 'Unique identifier for the resource.', 'cookie-law-info' ), 'type' => 'integer', 'context' => array( 'view' ), 'readonly' => true, ), 'name' => array( 'description' => __( 'Banner name for reference', 'cookie-law-info' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), 'slug' => array( 'description' => __( 'Banner unique name', 'cookie-law-info' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), 'settings' => array( 'description' => __( 'Banner settings.', 'cookie-law-info' ), 'type' => 'array', 'context' => array( 'view', 'edit' ), ), 'contents' => array( 'description' => __( 'Banner contents.', 'cookie-law-info' ), 'type' => 'object', 'context' => array( 'view', 'edit' ), ), 'default' => array( 'description' => __( 'Indicates whether the banner is default or not', 'cookie-law-info' ), 'type' => 'boolean', 'context' => array( 'view', 'edit' ), ), 'date_created' => array( 'description' => __( 'The date the banner was created, as GMT.', 'cookie-law-info' ), 'type' => 'date-time', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'date_modified' => array( 'description' => __( 'The date the banner was last modified, as GMT.', 'cookie-law-info' ), 'type' => 'date-time', 'context' => array( 'view', 'edit' ), ), ), ); return $this->add_additional_fields_schema( $schema ); } } // End the class.
Fatal error: Uncaught Error: Class "CookieYes\Lite\Admin\Modules\Banners\Api\Api" not found in /htdocs/wp-content/plugins/cookie-law-info/lite/admin/modules/banners/class-banners.php:55 Stack trace: #0 /htdocs/wp-content/plugins/cookie-law-info/lite/admin/modules/banners/class-banners.php(39): CookieYes\Lite\Admin\Modules\Banners\Banners->load_apis() #1 /htdocs/wp-content/plugins/cookie-law-info/lite/includes/class-modules.php(54): CookieYes\Lite\Admin\Modules\Banners\Banners->init() #2 /htdocs/wp-content/plugins/cookie-law-info/lite/admin/class-admin.php(180): CookieYes\Lite\Includes\Modules->__construct('banners') #3 /htdocs/wp-content/plugins/cookie-law-info/lite/admin/class-admin.php(81): CookieYes\Lite\Admin\Admin->load_modules() #4 /htdocs/wp-content/plugins/cookie-law-info/lite/includes/class-cli.php(153): CookieYes\Lite\Admin\Admin->__construct('cookie-law-info', '3.2.7') #5 /htdocs/wp-content/plugins/cookie-law-info/lite/includes/class-cli.php(95): CookieYes\Lite\Includes\CLI->define_admin_hooks() #6 /htdocs/wp-content/plugins/cookie-law-info/lite/loader.php(31): CookieYes\Lite\Includes\CLI->__construct() #7 /htdocs/wp-content/plugins/cookie-law-info/cookie-law-info.php(151): require_once('/htdocs/wp-cont...') #8 /htdocs/wp-settings.php(526): include_once('/htdocs/wp-cont...') #9 /htdocs/wp-config.php(92): require_once('/htdocs/wp-sett...') #10 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #11 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #12 /htdocs/index.php(17): require('/htdocs/wp-blog...') #13 {main} thrown in /htdocs/wp-content/plugins/cookie-law-info/lite/admin/modules/banners/class-banners.php on line 55