; $total = $wpdb->get_var( "SELECT FOUND_ROWS()" ); $max_pages = ceil( $total / $per_page ); if ( $page > $max_pages && $total > 0 ) { return new WP_Error( 'rest_post_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) ); } $response = rest_ensure_response( $featured_image_ids ); $response->header( 'X-WP-Total', (int) $total ); $response->header( 'X-WP-TotalPages', (int) $max_pages ); $request_params = $request->get_query_params(); $base = add_query_arg( $request_params, rest_url( $this->namespace . '/featuredimages' ) ); if ( $page > 1 ) { $prev_page = $page - 1; if ( $prev_page > $max_pages ) { $prev_page = $max_pages; } $prev_link = add_query_arg( 'page', $prev_page, $base ); $response->link_header( 'prev', $prev_link ); } if ( $max_pages > $page ) { $next_page = $page + 1; $next_link = add_query_arg( 'page', $next_page, $base ); $response->link_header( 'next', $next_link ); } return $response; } /** * Check to see if the current user is allowed to use this endpoint. * * @since 3.0.0 * * @param WP_REST_Request $request Full data about the request. * * @return bool Whether the current user has permission to regenerate thumbnails. */ public function permissions_check( $request ) { return current_user_can( RegenerateThumbnails()->capability ); } /** * Returns whether a variable is an array or not. This is needed because 3 arguments are * passed to validation callbacks but is_array() only accepts one argument. * * @since 3.0.0 * * @see https://core.trac.wordpress.org/ticket/34659 * * @param mixed $param The parameter value to validate. * @param WP_REST_Request $request The REST request. * @param string $key The parameter name. * * @return bool Whether the parameter is an array or not. */ public function is_array( $param, $request, $key ) { return is_array( $param ); } } opengraph-title' => 'open_graph_title', 'wpseo_opengraph-description' => 'open_graph_description', 'wpseo_opengraph-image' => 'open_graph_image', 'wpseo_opengraph-image-id' => 'open_graph_image_id', 'wpseo_twitter-title' => 'twitter_title', 'wpseo_twitter-description' => 'twitter_description', 'wpseo_twitter-image' => 'twitter_image', 'wpseo_twitter-image-id' => 'twitter_image_id', ]; } /** * Retrieves a meta value from the given meta data. * * @param string $meta_key The key to extract. * @param array $term_meta The meta data. * * @return null|string The meta value. */ protected function get_meta_value( $meta_key, $term_meta ) { if ( ! $term_meta || ! \array_key_exists( $meta_key, $term_meta ) ) { return null; } $value = $term_meta[ $meta_key ]; if ( \is_string( $value ) && $value === '' ) { return null; } return $value; } /** * Finds an alternative image for the social image. * * @param Indexable $indexable The indexable. * * @return array|bool False when not found, array with data when found. */ protected function find_alternative_image( Indexable $indexable ) { $content_image = $this->image->get_term_content_image( $indexable->object_id ); if ( $content_image ) { return [ 'image' => $content_image, 'source' => 'first-content-image', ]; } return false; } }