[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/rest-api/search/ -> class-wp-rest-search-handler.php (source)

   1  <?php
   2  /**
   3   * REST API: WP_REST_Search_Handler class
   4   *
   5   * @package WordPress
   6   * @subpackage REST_API
   7   * @since 5.0.0
   8   */
   9  
  10  /**
  11   * Core base class representing a search handler for an object type in the REST API.
  12   *
  13   * @since 5.0.0
  14   */
  15  abstract class WP_REST_Search_Handler {
  16  
  17      /**
  18       * Field containing the IDs in the search result.
  19       */
  20      const RESULT_IDS = 'ids';
  21  
  22      /**
  23       * Field containing the total count in the search result.
  24       */
  25      const RESULT_TOTAL = 'total';
  26  
  27      /**
  28       * Object type managed by this search handler.
  29       *
  30       * @since 5.0.0
  31       * @var string
  32       */
  33      protected $type = '';
  34  
  35      /**
  36       * Object subtypes managed by this search handler.
  37       *
  38       * @since 5.0.0
  39       * @var array
  40       */
  41      protected $subtypes = array();
  42  
  43      /**
  44       * Gets the object type managed by this search handler.
  45       *
  46       * @since 5.0.0
  47       *
  48       * @return string Object type identifier.
  49       */
  50  	public function get_type() {
  51          return $this->type;
  52      }
  53  
  54      /**
  55       * Gets the object subtypes managed by this search handler.
  56       *
  57       * @since 5.0.0
  58       *
  59       * @return array Array of object subtype identifiers.
  60       */
  61  	public function get_subtypes() {
  62          return $this->subtypes;
  63      }
  64  
  65      /**
  66       * Searches the object type content for a given search request.
  67       *
  68       * @since 5.0.0
  69       *
  70       * @param WP_REST_Request $request Full REST request.
  71       * @return array Associative array containing an `WP_REST_Search_Handler::RESULT_IDS` containing
  72       *               an array of found IDs and `WP_REST_Search_Handler::RESULT_TOTAL` containing the
  73       *               total count for the matching search results.
  74       */
  75      abstract public function search_items( WP_REST_Request $request );
  76  
  77      /**
  78       * Prepares the search result for a given ID.
  79       *
  80       * @since 5.0.0
  81       * @since 5.6.0 The `$id` parameter can accept a string.
  82       *
  83       * @param int|string $id     Item ID.
  84       * @param array      $fields Fields to include for the item.
  85       * @return array Associative array containing all fields for the item.
  86       */
  87      abstract public function prepare_item( $id, array $fields );
  88  
  89      /**
  90       * Prepares links for the search result of a given ID.
  91       *
  92       * @since 5.0.0
  93       * @since 5.6.0 The `$id` parameter can accept a string.
  94       *
  95       * @param int|string $id Item ID.
  96       * @return array Links for the given item.
  97       */
  98      abstract public function prepare_item_links( $id );
  99  }


Generated: Thu Nov 21 01:00:03 2024 Cross-referenced by PHPXref 0.7.1