from_request() public static method

Returns a new context object, instantiated according to the data in the current request.
Since: 3.0.0
public static from_request ( ) : static
return static Context object.
コード例 #1
0
 /**
  * Initializes the AJAX-based live search.
  *
  * @since 3.0.0
  *
  * @return void
  */
 public function initialize()
 {
     add_action('wp_ajax_' . self::ACTION, function () {
         $context = RelationshipContext::from_request();
         ob_start();
         $this->search_results->render($context);
         wp_send_json_success(['html' => ob_get_clean(), 'remoteSiteId' => $context->remote_site_id()]);
     });
 }
コード例 #2
0
 /**
  * Constructor. Sets up the properties.
  *
  * @since 3.0.0
  *
  * @param ContentRelations $content_relations Content relations API object.
  */
 public function __construct(ContentRelations $content_relations)
 {
     $this->content_relations = $content_relations;
     $this->context = RelationshipContext::from_request();
 }