settings = $settings; $this->generator = $generator; $this->abilities = $abilities; } /** * Hooks. Kept out of the constructor like Audio::register_hooks(). */ public function register_hooks() { add_action( 'rest_api_init', array($this, 'register_routes') ); } /** * REST routes for the tab. */ public function register_routes() { // posts (all enabled post types), type:, or library. $scope = array( 'required' => false, 'type' => 'string', 'default' => 'posts', 'sanitize_callback' => array($this, 'normalize_scope'), ); $id = array( 'required' => true, 'type' => 'integer', 'sanitize_callback' => 'absint', ); register_rest_route( 'aifi/v1', '/audit', array( 'methods' => 'GET', 'callback' => array($this, 'rest_audit'), 'permission_callback' => array($this, 'check_permission'), 'args' => array( 'scope' => $scope, 'problem' => array( 'required' => false, 'type' => 'string', 'default' => 'all', 'enum' => self::PROBLEMS, ), 'page' => array( 'required' => false, 'type' => 'integer', 'default' => 1, 'minimum' => 1, 'sanitize_callback' => 'absint', ), 'refresh' => array( 'required' => false, 'type' => 'boolean', 'default' => false, ), ), ) ); register_rest_route( 'aifi/v1', '/audit/fill-alt', array( 'methods' => 'POST', 'callback' => array($this, 'rest_fill_alt'), 'permission_callback' => array($this, 'check_permission'), 'args' => array( 'scope' => $scope, 'offset' => array( 'required' => false, 'type' => 'integer', 'default' => 0, 'minimum' => 0, 'sanitize_callback' => 'absint', ), ), ) ); register_rest_route( 'aifi/v1', '/audit/measure', array( 'methods' => 'POST', 'callback' => array($this, 'rest_measure'), 'permission_callback' => array($this, 'check_permission'), 'args' => array( 'scope' => $scope, ), ) ); register_rest_route( 'aifi/v1', '/audit/update', array( 'methods' => 'POST', 'callback' => array($this, 'rest_update'), 'permission_callback' => array($this, 'check_permission'), 'args' => array( 'attachment_id' => $id, 'title' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', ), 'alt' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', ), 'caption' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_textarea_field', ), 'post_id' => array( 'type' => 'integer', 'sanitize_callback' => 'absint', 'default' => 0, ), ), ) ); register_rest_route( 'aifi/v1', '/audit/convert', array( 'methods' => 'POST', 'callback' => array($this, 'rest_convert'), 'permission_callback' => array($this, 'check_permission'), 'args' => array( 'attachment_id' => $id, ), ) ); } /** * Only the plugin's own settings screen may call these routes. * * @param \WP_REST_Request $request Request. * @return true|\WP_Error */ public function check_permission( $request ) { if ( !wp_verify_nonce( $request->get_header( 'X-WP-Nonce' ), 'wp_rest' ) ) { return new \WP_Error('rest_forbidden', __( 'Invalid nonce.', 'ai-featured-image-generator' ), array( 'status' => rest_authorization_required_code(), )); } if ( !current_user_can( Settings::capability() ) ) { return new \WP_Error('rest_forbidden', __( 'Sorry, you are not allowed to audit images.', 'ai-featured-image-generator' ), array( 'status' => rest_authorization_required_code(), )); } return true; } // ------------------------------------------------------------------ // Scan (Free and Pro) // ------------------------------------------------------------------ /** * GET /audit: the counts and one page of the chosen list. * * @param \WP_REST_Request $request Request. * @return \WP_REST_Response|\WP_Error */ public function rest_audit( $request ) { $scope = $this->normalize_scope( $request['scope'] ); $problem = ( in_array( $request['problem'], self::PROBLEMS, true ) ? $request['problem'] : 'all' ); $page = max( 1, (int) $request['page'] ); // Check images (and opening the tab) asks for a fresh scan. Cards and pages // reuse it, so they only filter what was already found. $scan = $this->scan( $scope, (bool) $request['refresh'] ); if ( is_wp_error( $scan ) ) { return $scan; } // A Media Library list says where each image is used, from the posts check. if ( $request['refresh'] && 'library' === $scope ) { delete_transient( self::scan_key( 'posts' ) ); } return rest_ensure_response( array( 'summary' => $this->summary( $scan ), 'list' => $this->page( $scan, $problem, $page ), ) ); } /** * The last check for a scope, or a new one when there is none or $fresh is set. * * @param string $scope From normalize_scope(). * @param bool $fresh Scan again. * @return array|\WP_Error */ private function scan( $scope, $fresh = false ) { $key = self::scan_key( $scope ); $scan = ( $fresh ? false : get_transient( $key ) ); if ( is_array( $scan ) && isset( $scan['found'] ) ) { return $scan; } $scan = $this->abilities->audit_scan( $this->scan_input( $scope ) ); if ( !is_wp_error( $scan ) ) { set_transient( $key, $scan, self::SCAN_TTL ); } return $scan; } /** * Post types the tab can check one at a time: those with AI images turned on. * * @return string[] Plural label, keyed by post type. */ public function post_types() { return self::post_types_for( $this->settings ); } /** * Same as post_types(), for the settings screen that draws the choice. * * @param Settings $settings Settings. * @return string[] */ public static function post_types_for( $settings ) { $types = array(); foreach ( $settings->get_content_post_types() as $type ) { $object = get_post_type_object( $type ); if ( $object && $object->show_ui && 'attachment' !== $type ) { $types[$type] = (string) $object->labels->name; } } return $types; } /** * What to check: posts (every enabled post type), type:, or library. * Anything else falls back to posts. * * @param mixed $scope Raw value. * @return string */ public function normalize_scope( $scope ) { $scope = ( is_string( $scope ) ? $scope : '' ); if ( 'library' === $scope ) { return 'library'; } if ( 0 === strpos( $scope, 'type:' ) && isset( $this->post_types()[substr( $scope, 5 )] ) ) { return $scope; } return 'posts'; } /** * The scan input for a scope. Posts checks include WooCommerce product galleries. * * @param string $scope From normalize_scope(). * @return array */ private function scan_input( $scope ) { if ( 'library' === $scope ) { return array( 'scope' => 'library', ); } $input = array( 'scope' => 'posts', 'gallery' => true, ); if ( 0 === strpos( $scope, 'type:' ) ) { $input['post_type'] = substr( $scope, 5 ); } return $input; } /** * Images of a check that can be measured for blur and cut-off edges, once each. * * @param array $scan Result of Abilities::audit_scan(). * @return int[] */ private function measurable_ids( $scan ) { $ids = array(); foreach ( $scan['found'] as $img ) { if ( !empty( $img['attachment_id'] ) && empty( $img['external'] ) && 'svg' !== $img['format'] ) { $ids[(int) $img['attachment_id']] = true; } } $ids = array_keys( $ids ); if ( $ids ) { update_meta_cache( 'post', $ids ); } return $ids; } /** * POST /audit/measure: measures the next images of the last check for blur and * cut-off edges. Each image is measured once and kept until it changes, so the * page calls this until `remaining` is 0 and every later check is quick. * * @param \WP_REST_Request $request Request. * @return \WP_REST_Response|\WP_Error */ public function rest_measure( $request ) { $scope = $this->normalize_scope( $request['scope'] ); $scan = $this->scan( $scope ); if ( is_wp_error( $scan ) ) { return $scan; } $start = microtime( true ); $done = 0; foreach ( $this->measurable_ids( $scan ) as $id ) { if ( null !== $this->abilities->measure_attachment( $id, false ) ) { continue; } $this->abilities->measure_attachment( $id ); $done++; if ( $done >= self::MEASURE_BATCH || microtime( true ) - $start >= self::MEASURE_SECONDS ) { break; } } return rest_ensure_response( array( 'measured_now' => $done, 'summary' => $this->summary( $scan ), ) ); } /** * Counts for the cards. Each image counts once, however many posts use it. * * @param array $scan Result of Abilities::audit_scan(). * @return array */ public function summary( $scan ) { $seen = array(); $seen_alt = array(); $counts = array( 'images' => 0, 'missing_alt' => 0, 'large' => 0, 'not_webp' => 0, ); foreach ( $scan['found'] as $img ) { $key = $this->image_key( $img ); if ( $this->is_missing_alt( $img ) && !isset( $seen_alt[$this->alt_key( $img )] ) ) { $seen_alt[$this->alt_key( $img )] = true; $counts['missing_alt']++; } if ( isset( $seen[$key] ) ) { continue; } $seen[$key] = true; $counts['images']++; if ( $this->is_large( $img ) ) { $counts['large']++; } if ( $this->is_not_webp( $img ) ) { $counts['not_webp']++; } } // Blur and cut-off edges, from the measurements kept on each image. $counts['blurry'] = 0; $counts['cut_off'] = 0; $counts['measurable'] = 0; $counts['remaining'] = 0; foreach ( $this->measurable_ids( $scan ) as $id ) { $m = $this->abilities->measure_attachment( $id, false ); $counts['measurable']++; if ( null === $m ) { $counts['remaining']++; } elseif ( $m ) { $counts['blurry'] += ( 'blurry' === $m['sharpness_label'] ? 1 : 0 ); $counts['cut_off'] += ( empty( $m['busy_edges'] ) ? 0 : 1 ); } } return array_merge( $counts, array( 'scope' => $scan['scope'], 'scanned' => (int) $scan['scanned'], 'note' => (string) $scan['note'], ) ); } /** * One page of a list. Blur and cut-off edges come from the measurements kept on * each image, so an image shows up there once /audit/measure has seen it. * * @param array $scan Result of Abilities::audit_scan(). * @param string $problem One of self::PROBLEMS. * @param int $page Page, from 1. * @return array */ public function page( $scan, $problem, $page ) { $note = (string) $scan['note']; $all = array(); foreach ( $scan['found'] as $img ) { switch ( $problem ) { case 'missing_alt': $hit = $this->is_missing_alt( $img ); break; case 'large': $hit = $this->is_large( $img ); break; case 'not_webp': $hit = $this->is_not_webp( $img ); break; case 'blurry': case 'cut_off': $m = ( empty( $img['attachment_id'] ) || !empty( $img['external'] ) ? null : $this->abilities->measure_attachment( (int) $img['attachment_id'], false ) ); if ( !$m ) { $hit = false; break; } $img['sharpness_label'] = $m['sharpness_label']; $img['busy_edges'] = $m['busy_edges']; $hit = ( 'blurry' === $problem ? 'blurry' === $m['sharpness_label'] : !empty( $m['busy_edges'] ) ); break; default: $hit = true; } if ( !$hit ) { continue; } // One row per image, however many posts use it. The posts check finds an // image once per post, so those posts are gathered on its row. $key = $this->image_key( $img ); if ( !isset( $all[$key] ) ) { $all[$key] = array( 'img' => $img, 'posts' => array(), ); } $post_id = ( isset( $img['location'] ) && 'library' !== $img['location'] && !empty( $img['post_id'] ) ? (int) $img['post_id'] : 0 ); if ( $post_id && !isset( $all[$key]['posts'][$post_id] ) ) { $all[$key]['posts'][$post_id] = (string) $img['location']; } } $all = array_values( $all ); $matched = count( $all ); $pages = (int) ceil( $matched / self::PER_PAGE ); $locked = !Providers::can_use_premium(); if ( $locked ) { // Free sees the top of each list only, whatever page is asked for. $page = 1; } $images = array_slice( $all, ($page - 1) * self::PER_PAGE, self::PER_PAGE ); if ( $locked ) { $images = array_slice( $images, 0, self::FREE_ROWS ); $pages = min( $pages, 1 ); } return array( 'problem' => $problem, 'page' => $page, 'total_pages' => $pages, 'matched' => $matched, 'locked' => $locked, 'note' => $note, 'rows' => $this->rows( $images ), ); } /** * Transient that keeps the last check, per scope and per user. * * @param string $scope From normalize_scope(). * @return string */ private static function scan_key( $scope ) { return 'aifi_audit_' . str_replace( ':', '_', $scope ) . '_' . get_current_user_id(); } /** * Drops the kept checks after a fix, so the next list shows the change. */ private function forget_scan() { delete_transient( self::scan_key( 'posts' ) ); delete_transient( self::scan_key( 'library' ) ); foreach ( array_keys( $this->post_types() ) as $type ) { delete_transient( self::scan_key( 'type:' . $type ) ); } } /** * Rows for one page. A Media Library image only says which post it was uploaded * to, which is not where it is shown, so the page looks up where each one is * really used: as a featured image or inside a post's content. * * @param array[] $groups Each: img (from the scan) and posts (post id => featured or content). * @return array[] */ private function rows( $groups ) { // The posts and images of this page, with their meta, in one query each. $prime = array(); foreach ( $groups as $group ) { $img = $group['img']; $prime[] = ( isset( $img['attachment_id'] ) ? (int) $img['attachment_id'] : 0 ); $prime[] = ( isset( $img['post_id'] ) ? (int) $img['post_id'] : 0 ); $prime[] = ( isset( $img['uploaded_to'] ) ? (int) $img['uploaded_to'] : 0 ); foreach ( array_keys( $group['posts'] ) as $pid ) { $prime[] = (int) $pid; } } self::prime_posts( $prime ); $ids = array(); foreach ( $groups as $group ) { $img = $group['img']; if ( !$group['posts'] && !empty( $img['attachment_id'] ) && empty( $img['external'] ) ) { $ids[] = (int) $img['attachment_id']; } } $usage = $this->usage( array_unique( $ids ) ); $rows = array(); foreach ( $groups as $group ) { $img = $group['img']; $id = ( isset( $img['attachment_id'] ) ? (int) $img['attachment_id'] : 0 ); $posts = $group['posts']; if ( !$posts && isset( $usage[$id] ) ) { $posts = $usage[$id]; } $rows[] = $this->row( $img, $posts ); } return $rows; } /** * Where images are shown, taken from the check of the site's posts (the same one * "All my content" runs): as a featured image, in a product gallery or inside the content. * * @param int[] $ids Attachments. * @return array[] Post id => featured or content, keyed by attachment id. */ private function usage( $ids ) { $usage = array(); if ( !$ids ) { return $usage; } $posts = $this->scan( 'posts' ); if ( is_wp_error( $posts ) ) { return $usage; } $want = array_flip( $ids ); foreach ( $posts['found'] as $img ) { $id = ( isset( $img['attachment_id'] ) ? (int) $img['attachment_id'] : 0 ); $post_id = ( isset( $img['post_id'] ) ? (int) $img['post_id'] : 0 ); if ( isset( $want[$id] ) && $post_id && !isset( $usage[$id][$post_id] ) ) { $usage[$id][$post_id] = ( isset( $img['location'] ) ? (string) $img['location'] : '' ); } } return $usage; } /** * A post as the table shows it: its title, where to edit it, and where to see it. * A post that is not published yet opens as a preview. * * @param int $post_id Post. * @param string $where featured, content, or '' when unknown. * @return array|null */ private function post_link( $post_id, $where ) { $post = get_post( $post_id ); if ( !$post ) { return null; } $live = in_array( $post->post_status, array('publish', 'private'), true ); $view = ( $live ? get_permalink( $post ) : get_preview_post_link( $post ) ); $title = html_entity_decode( (string) get_the_title( $post ), ENT_QUOTES, 'UTF-8' ); return array( 'id' => (int) $post->ID, 'title' => ( '' !== trim( $title ) ? $title : __( '(no title)', 'ai-featured-image-generator' ) ), 'edit_url' => (string) get_edit_post_link( $post->ID, 'raw' ), 'view_url' => ( $view ? (string) $view : '' ), 'published' => $live, 'where' => $where, ); } /** * Fields the table needs for one image. * * @param array $img Image from the scan. * @return array */ private function row( $img, $posts = array() ) { $id = ( isset( $img['attachment_id'] ) ? (int) $img['attachment_id'] : 0 ); $post_id = ( isset( $img['post_id'] ) ? (int) $img['post_id'] : (( isset( $img['uploaded_to'] ) ? (int) $img['uploaded_to'] : 0 )) ); $thumb = ( $id ? wp_get_attachment_image_url( $id, 'thumbnail' ) : '' ); $library = !isset( $img['location'] ) || 'library' === $img['location']; // The first three posts are named, the rest are counted. $used = array(); foreach ( array_slice( $posts, 0, 3, true ) as $pid => $where ) { $link = $this->post_link( (int) $pid, (string) $where ); if ( $link ) { $used[] = $link; } } $uploaded_to = ( $library && !$used && !empty( $img['uploaded_to'] ) ? $this->post_link( (int) $img['uploaded_to'], '' ) : null ); return array( 'media_url' => ( $id && !empty( $img['attachment_id'] ) && empty( $img['external'] ) ? (string) get_edit_post_link( $id, 'raw' ) : '' ), 'used' => $used, 'used_more' => max( 0, count( $posts ) - 3 ), 'uploaded_to' => $uploaded_to, 'attachment_id' => $id, 'external' => !empty( $img['external'] ), 'thumb' => ( $thumb ? $thumb : (string) $img['url'] ), 'url' => (string) $img['url'], 'title' => ( isset( $img['title'] ) ? html_entity_decode( (string) $img['title'], ENT_QUOTES, 'UTF-8' ) : '' ), 'alt' => (string) $img['alt'], 'caption' => ( $id ? (string) wp_get_attachment_caption( $id ) : '' ), 'format' => (string) $img['format'], 'kb' => (int) $img['kb'], 'width' => (int) $img['width'], 'height' => (int) $img['height'], 'location' => ( isset( $img['location'] ) ? (string) $img['location'] : 'library' ), 'post_id' => $post_id, 'post_title' => ( $post_id ? html_entity_decode( (string) get_the_title( $post_id ), ENT_QUOTES, 'UTF-8' ) : '' ), 'edit_url' => ( $post_id ? (string) get_edit_post_link( $post_id, 'raw' ) : '' ), 'missing_alt' => $this->is_missing_alt( $img ), 'large' => $this->is_large( $img ), 'can_convert' => $id && in_array( $img['format'], array('jpg', 'png'), true ), 'sharpness_label' => ( isset( $img['sharpness_label'] ) ? (string) $img['sharpness_label'] : '' ), 'busy_edges' => ( isset( $img['busy_edges'] ) ? array_values( (array) $img['busy_edges'] ) : array() ), ); } /** * Loads posts and their meta into the cache in one query each, so the loops after * an id list never ask for them one at a time. * * @param int[] $ids Post or attachment ids (zeros and repeats are fine). */ private static function prime_posts( $ids ) { $ids = array_values( array_filter( array_unique( array_map( 'intval', $ids ) ) ) ); if ( !$ids ) { return; } _prime_post_caches( $ids, false, true ); update_meta_cache( 'post', $ids ); } /** * @param array $img Image from the scan. * @return string Same key for every use of one image. */ private function image_key( $img ) { return ( !empty( $img['attachment_id'] ) ? 'a' . (int) $img['attachment_id'] : 'u' . (string) $img['url'] ); } /** * Where an image's alt text lives: on the image itself, or in one post's image tag. * * @param array $img Image from the scan. * @return string */ private function alt_key( $img ) { $in_post = isset( $img['location'] ) && 'content' === $img['location'] && !empty( $img['post_id'] ); return (( $in_post ? 'p' . (int) $img['post_id'] . '-' : '' )) . $this->image_key( $img ); } /** * Missing alt text the plugin can fill: images in the Media Library only. * * @param array $img Image from the scan. * @return bool */ private function is_missing_alt( $img ) { return '' === trim( (string) $img['alt'] ) && empty( $img['external'] ); } /** * @param array $img Image from the scan. * @return bool */ private function is_large( $img ) { return (int) $img['kb'] > self::LARGE_KB; } /** * JPG and PNG files, which WebP makes smaller. * * @param array $img Image from the scan. * @return bool */ private function is_not_webp( $img ) { return empty( $img['external'] ) && in_array( $img['format'], array('jpg', 'png'), true ); } // ------------------------------------------------------------------ // Fixes (Pro) // ------------------------------------------------------------------ /** * The upgrade error for every fix. * * @return \WP_Error */ private function premium_error() { return new \WP_Error('premium_required', __( 'Fixing images from the Image Audit is a Pro feature. Please upgrade to fix them in one click.', 'ai-featured-image-generator' ), array( 'status' => 403, )); } /** * POST /audit/fill-alt: fills the next batch of images with no alt text. * * The run works through the kept check (the list on screen) in order: `offset` is * where the next batch starts in it. The site is checked again only once the run is * over. An entry counts as skipped only when it still has no alt text afterwards, so * an image that an earlier entry already filled (the same image in a post's content * and as a featured image) is not reported as skipped. * * @param \WP_REST_Request $request Request. * @return \WP_REST_Response|\WP_Error */ public function rest_fill_alt( $request ) { if ( !Providers::can_use_premium() ) { return $this->premium_error(); } return $this->premium_error(); } /** * Whether one place still has no alt text, read fresh after a fill. * * @param array $img Image from the scan. * @return bool */ private function still_missing( $img ) { $id = ( isset( $img['attachment_id'] ) ? (int) $img['attachment_id'] : 0 ); if ( isset( $img['location'] ) && 'content' === $img['location'] && !empty( $img['post_id'] ) ) { return 'filled' !== $this->content_alt_state( (int) $img['post_id'], $id ); } return '' === trim( (string) get_post_meta( $id, '_wp_attachment_image_alt', true ) ); } /** * The alt text of an image's tags in one post. * * @param int $post_id Post. * @param int $attachment_id Image. * @return string filled (every tag has alt text), missing (one has none) or none (no tag). */ private function content_alt_state( $post_id, $attachment_id ) { if ( !$attachment_id || !preg_match_all( '/]*>/i', (string) get_post_field( 'post_content', $post_id ), $tags ) ) { return 'none'; } $state = 'none'; foreach ( $tags[0] as $tag ) { if ( !preg_match( '/\\bwp-image-' . (int) $attachment_id . '\\b/', $tag ) ) { continue; } if ( !preg_match( '/(?generator->build_alt_text( array( 'title' => wp_strip_all_tags( (string) $title ), ) ); if ( '' === $alt ) { return ''; } $own = (string) get_post_meta( $id, '_wp_attachment_image_alt', true ); if ( 'content' === $location ) { if ( !$post_id || !current_user_can( 'edit_post', $post_id ) || !$this->fill_content_alt( $post_id, $id, $alt ) ) { return ''; } if ( '' === trim( $own ) ) { update_post_meta( $id, '_wp_attachment_image_alt', $alt ); } return $alt; } if ( '' !== trim( $own ) ) { return ''; } update_post_meta( $id, '_wp_attachment_image_alt', $alt ); return $alt; } /** * Sets the alt text of an image's tags in a post where it is empty or missing. * Only tags marked with the image's wp-image-ID class are touched, which is how * the block and classic editors mark Media Library images. * * @param int $post_id Post. * @param int $attachment_id Image. * @param string $alt Alt text. * @param bool $overwrite Also replace an alt text that is already there (an edit by hand). * @return bool True when the post changed. */ private function fill_content_alt( $post_id, $attachment_id, $alt, $overwrite = false ) { $content = (string) get_post_field( 'post_content', $post_id ); $changed = false; $updated = preg_replace_callback( '/]*>/i', function ( $m ) use( $attachment_id, $alt, $overwrite, &$changed ) { $tag = $m[0]; if ( !preg_match( '/\\bwp-image-' . (int) $attachment_id . '\\b/', $tag ) ) { return $tag; } $value = 'alt="' . esc_attr( $alt ) . '"'; if ( preg_match( '/(?/s', function ( $m ) use($attachment_id, $alt) { $attrs = json_decode( $m[1], true ); if ( !is_array( $attrs ) || (int) ($attrs['attachmentId'] ?? 0) !== (int) $attachment_id ) { return $m[0]; } $attrs['alt'] = $alt; return ''; }, $updated ); if ( is_string( $with_block ) ) { $updated = $with_block; } // The post is saved as the current user. Without unfiltered_html (any site admin on // multisite) WordPress would run the whole content through kses and strip embeds // and scripts that were allowed when they were added. Only alt attributes change // here, so the filters are off for this one save. $kses = false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' ); if ( $kses ) { kses_remove_filters(); } // An automatic alt text fix is not a version anyone needs to restore. $revision = has_action( 'post_updated', 'wp_save_post_revision' ); if ( false !== $revision ) { remove_action( 'post_updated', 'wp_save_post_revision', $revision ); } try { $result = wp_update_post( array( 'ID' => $post_id, 'post_content' => wp_slash( $updated ), ), true ); } finally { if ( false !== $revision ) { add_action( 'post_updated', 'wp_save_post_revision', $revision, 1 ); } if ( $kses ) { kses_init_filters(); } } return !is_wp_error( $result ); } /** * POST /audit/update: changes an image's title, alt text or caption. * * @param \WP_REST_Request $request Request. * @return \WP_REST_Response|\WP_Error */ public function rest_update( $request ) { if ( !Providers::can_use_premium() ) { return $this->premium_error(); } return $this->premium_error(); } /** * POST /audit/convert: saves a JPG or PNG as WebP and points every post at it. * * @param \WP_REST_Request $request Request. * @return \WP_REST_Response|\WP_Error */ public function rest_convert( $request ) { if ( !Providers::can_use_premium() ) { return $this->premium_error(); } return $this->premium_error(); } }