@@ -9,44 +9,44 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Wordlift_Context_Cards_Service { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - private $endpoint; |
|
| 12 | + /** |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + private $endpoint; |
|
| 16 | 16 | |
| 17 | - function __construct() { |
|
| 17 | + function __construct() { |
|
| 18 | 18 | |
| 19 | - $this->endpoint = '/jsonld'; |
|
| 19 | + $this->endpoint = '/jsonld'; |
|
| 20 | 20 | |
| 21 | - // PHP 5.3 compatibility as `$this` cannot be used in closures. |
|
| 22 | - $that = $this; |
|
| 21 | + // PHP 5.3 compatibility as `$this` cannot be used in closures. |
|
| 22 | + $that = $this; |
|
| 23 | 23 | |
| 24 | - add_action( 'rest_api_init', function () use ( $that ) { |
|
| 25 | - register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, $that->endpoint, array( |
|
| 26 | - 'methods' => 'GET', |
|
| 27 | - 'callback' => array( $that, 'context_data' ), |
|
| 28 | - ) ); |
|
| 29 | - } ); |
|
| 24 | + add_action( 'rest_api_init', function () use ( $that ) { |
|
| 25 | + register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, $that->endpoint, array( |
|
| 26 | + 'methods' => 'GET', |
|
| 27 | + 'callback' => array( $that, 'context_data' ), |
|
| 28 | + ) ); |
|
| 29 | + } ); |
|
| 30 | 30 | |
| 31 | - } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - public function context_data( $request ) { |
|
| 33 | + public function context_data( $request ) { |
|
| 34 | 34 | |
| 35 | - $entity_uri = urldecode( $request->get_param( 'entity_url' ) ); |
|
| 36 | - $entity_id = url_to_postid( $entity_uri ); |
|
| 37 | - $jsonld = Wordlift_Jsonld_Service::get_instance()->get_jsonld( false, $entity_id ); |
|
| 35 | + $entity_uri = urldecode( $request->get_param( 'entity_url' ) ); |
|
| 36 | + $entity_id = url_to_postid( $entity_uri ); |
|
| 37 | + $jsonld = Wordlift_Jsonld_Service::get_instance()->get_jsonld( false, $entity_id ); |
|
| 38 | 38 | |
| 39 | - return $jsonld; |
|
| 39 | + return $jsonld; |
|
| 40 | 40 | |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function enqueue_scripts() { |
|
| 44 | - $show_context_cards = true; |
|
| 45 | - $show_context_cards = apply_filters( 'wl_show_context_cards', $show_context_cards ); |
|
| 46 | - if ( $show_context_cards ) { |
|
| 47 | - wp_enqueue_script( 'wordlift-cloud' ); |
|
| 48 | - wp_add_inline_script( 'wordlift-cloud', "wordliftCloud.contextCards('a.wl-entity-page-link', '" . get_rest_url() . WL_REST_ROUTE_DEFAULT_NAMESPACE . $this->endpoint . "')" ); |
|
| 49 | - } |
|
| 50 | - } |
|
| 43 | + public function enqueue_scripts() { |
|
| 44 | + $show_context_cards = true; |
|
| 45 | + $show_context_cards = apply_filters( 'wl_show_context_cards', $show_context_cards ); |
|
| 46 | + if ( $show_context_cards ) { |
|
| 47 | + wp_enqueue_script( 'wordlift-cloud' ); |
|
| 48 | + wp_add_inline_script( 'wordlift-cloud', "wordliftCloud.contextCards('a.wl-entity-page-link', '" . get_rest_url() . WL_REST_ROUTE_DEFAULT_NAMESPACE . $this->endpoint . "')" ); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | 52 | } |
@@ -21,20 +21,20 @@ discard block |
||
| 21 | 21 | // PHP 5.3 compatibility as `$this` cannot be used in closures. |
| 22 | 22 | $that = $this; |
| 23 | 23 | |
| 24 | - add_action( 'rest_api_init', function () use ( $that ) { |
|
| 25 | - register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, $that->endpoint, array( |
|
| 24 | + add_action('rest_api_init', function() use ($that) { |
|
| 25 | + register_rest_route(WL_REST_ROUTE_DEFAULT_NAMESPACE, $that->endpoint, array( |
|
| 26 | 26 | 'methods' => 'GET', |
| 27 | - 'callback' => array( $that, 'context_data' ), |
|
| 28 | - ) ); |
|
| 27 | + 'callback' => array($that, 'context_data'), |
|
| 28 | + )); |
|
| 29 | 29 | } ); |
| 30 | 30 | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function context_data( $request ) { |
|
| 33 | + public function context_data($request) { |
|
| 34 | 34 | |
| 35 | - $entity_uri = urldecode( $request->get_param( 'entity_url' ) ); |
|
| 36 | - $entity_id = url_to_postid( $entity_uri ); |
|
| 37 | - $jsonld = Wordlift_Jsonld_Service::get_instance()->get_jsonld( false, $entity_id ); |
|
| 35 | + $entity_uri = urldecode($request->get_param('entity_url')); |
|
| 36 | + $entity_id = url_to_postid($entity_uri); |
|
| 37 | + $jsonld = Wordlift_Jsonld_Service::get_instance()->get_jsonld(false, $entity_id); |
|
| 38 | 38 | |
| 39 | 39 | return $jsonld; |
| 40 | 40 | |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | public function enqueue_scripts() { |
| 44 | 44 | $show_context_cards = true; |
| 45 | - $show_context_cards = apply_filters( 'wl_show_context_cards', $show_context_cards ); |
|
| 46 | - if ( $show_context_cards ) { |
|
| 47 | - wp_enqueue_script( 'wordlift-cloud' ); |
|
| 48 | - wp_add_inline_script( 'wordlift-cloud', "wordliftCloud.contextCards('a.wl-entity-page-link', '" . get_rest_url() . WL_REST_ROUTE_DEFAULT_NAMESPACE . $this->endpoint . "')" ); |
|
| 45 | + $show_context_cards = apply_filters('wl_show_context_cards', $show_context_cards); |
|
| 46 | + if ($show_context_cards) { |
|
| 47 | + wp_enqueue_script('wordlift-cloud'); |
|
| 48 | + wp_add_inline_script('wordlift-cloud', "wordliftCloud.contextCards('a.wl-entity-page-link', '".get_rest_url().WL_REST_ROUTE_DEFAULT_NAMESPACE.$this->endpoint."')"); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |