@@ -13,34 +13,34 @@ |
||
13 | 13 | */ |
14 | 14 | class Recipe_Maker_Post_Type_Hook { |
15 | 15 | |
16 | - const RECIPE_MAKER_POST_TYPE = 'wprm_recipe'; |
|
16 | + const RECIPE_MAKER_POST_TYPE = 'wprm_recipe'; |
|
17 | 17 | |
18 | - public function __construct() { |
|
18 | + public function __construct() { |
|
19 | 19 | |
20 | - add_filter( |
|
21 | - 'wl_default_entity_type_for_post_type', |
|
22 | - array( $this, 'wl_default_entity_type_for_post_type' ), |
|
23 | - 10, |
|
24 | - 2 |
|
25 | - ); |
|
20 | + add_filter( |
|
21 | + 'wl_default_entity_type_for_post_type', |
|
22 | + array( $this, 'wl_default_entity_type_for_post_type' ), |
|
23 | + 10, |
|
24 | + 2 |
|
25 | + ); |
|
26 | 26 | |
27 | - add_filter( 'wl_valid_entity_post_types', array( $this, 'add_post_type' ) ); |
|
27 | + add_filter( 'wl_valid_entity_post_types', array( $this, 'add_post_type' ) ); |
|
28 | 28 | |
29 | - } |
|
29 | + } |
|
30 | 30 | |
31 | - public function add_post_type( $post_types ) { |
|
31 | + public function add_post_type( $post_types ) { |
|
32 | 32 | |
33 | - $post_types[] = self::RECIPE_MAKER_POST_TYPE; |
|
33 | + $post_types[] = self::RECIPE_MAKER_POST_TYPE; |
|
34 | 34 | |
35 | - return $post_types; |
|
36 | - } |
|
35 | + return $post_types; |
|
36 | + } |
|
37 | 37 | |
38 | - public function wl_default_entity_type_for_post_type( $entity_type, $post_type ) { |
|
38 | + public function wl_default_entity_type_for_post_type( $entity_type, $post_type ) { |
|
39 | 39 | |
40 | - if ( self::RECIPE_MAKER_POST_TYPE === $post_type ) { |
|
41 | - return 'http://schema.org/Recipe'; |
|
42 | - } |
|
40 | + if ( self::RECIPE_MAKER_POST_TYPE === $post_type ) { |
|
41 | + return 'http://schema.org/Recipe'; |
|
42 | + } |
|
43 | 43 | |
44 | - return $entity_type; |
|
45 | - } |
|
44 | + return $entity_type; |
|
45 | + } |
|
46 | 46 | } |
@@ -19,25 +19,25 @@ |
||
19 | 19 | |
20 | 20 | add_filter( |
21 | 21 | 'wl_default_entity_type_for_post_type', |
22 | - array( $this, 'wl_default_entity_type_for_post_type' ), |
|
22 | + array($this, 'wl_default_entity_type_for_post_type'), |
|
23 | 23 | 10, |
24 | 24 | 2 |
25 | 25 | ); |
26 | 26 | |
27 | - add_filter( 'wl_valid_entity_post_types', array( $this, 'add_post_type' ) ); |
|
27 | + add_filter('wl_valid_entity_post_types', array($this, 'add_post_type')); |
|
28 | 28 | |
29 | 29 | } |
30 | 30 | |
31 | - public function add_post_type( $post_types ) { |
|
31 | + public function add_post_type($post_types) { |
|
32 | 32 | |
33 | 33 | $post_types[] = self::RECIPE_MAKER_POST_TYPE; |
34 | 34 | |
35 | 35 | return $post_types; |
36 | 36 | } |
37 | 37 | |
38 | - public function wl_default_entity_type_for_post_type( $entity_type, $post_type ) { |
|
38 | + public function wl_default_entity_type_for_post_type($entity_type, $post_type) { |
|
39 | 39 | |
40 | - if ( self::RECIPE_MAKER_POST_TYPE === $post_type ) { |
|
40 | + if (self::RECIPE_MAKER_POST_TYPE === $post_type) { |
|
41 | 41 | return 'http://schema.org/Recipe'; |
42 | 42 | } |
43 | 43 |
@@ -10,60 +10,60 @@ |
||
10 | 10 | |
11 | 11 | class Recipe_Maker_Jsonld_Swap { |
12 | 12 | |
13 | - /** |
|
14 | - * @var Recipe_Maker_Validation_Service |
|
15 | - */ |
|
16 | - private $validation_service; |
|
17 | - /** |
|
18 | - * @var \Wordlift_Jsonld_Service |
|
19 | - */ |
|
20 | - private $jsonld_service; |
|
21 | - |
|
22 | - /** |
|
23 | - * @param $validation_service Recipe_Maker_Validation_Service |
|
24 | - */ |
|
25 | - public function __construct( $validation_service, $jsonld_service ) { |
|
26 | - |
|
27 | - $this->validation_service = $validation_service; |
|
28 | - $this->jsonld_service = $jsonld_service; |
|
29 | - |
|
30 | - add_filter( 'wprm_recipe_metadata', array( $this, 'alter_jsonld' ), 10 ); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Remove recipe maker jsonld or add mentions based on the integration. |
|
35 | - * |
|
36 | - * @param $metadata |
|
37 | - * @param $recipe |
|
38 | - * |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public function alter_jsonld( $metadata ) { |
|
42 | - |
|
43 | - // If this filter is invoked on any other page except post, then we should not modify the jsonld. |
|
44 | - if ( ! get_post() instanceof \WP_Post ) { |
|
45 | - return $metadata; |
|
46 | - } |
|
47 | - |
|
48 | - $post_id = get_the_ID(); |
|
49 | - |
|
50 | - /** |
|
51 | - * We dont print our jsonld when the page has recipe maker, we enhance the recipe maker jsonld |
|
52 | - * by adding only the `mentions` property. |
|
53 | - */ |
|
54 | - add_filter( 'wl_jsonld_enabled', '__return_false' ); |
|
55 | - |
|
56 | - $post_jsonld = $this->jsonld_service->get_jsonld( false, $post_id, Jsonld_Context_Enum::PAGE ); |
|
57 | - |
|
58 | - if ( 0 === count( $post_jsonld ) || ! array_key_exists( 'mentions', $post_jsonld[0] ) |
|
59 | - || 0 === count( $post_jsonld[0]['mentions'] ) ) { |
|
60 | - // Even if we don't have mentions return the metadata. |
|
61 | - return $metadata; |
|
62 | - } |
|
63 | - |
|
64 | - $metadata['mentions'] = $post_jsonld[0]['mentions']; |
|
65 | - |
|
66 | - return $metadata; |
|
67 | - } |
|
13 | + /** |
|
14 | + * @var Recipe_Maker_Validation_Service |
|
15 | + */ |
|
16 | + private $validation_service; |
|
17 | + /** |
|
18 | + * @var \Wordlift_Jsonld_Service |
|
19 | + */ |
|
20 | + private $jsonld_service; |
|
21 | + |
|
22 | + /** |
|
23 | + * @param $validation_service Recipe_Maker_Validation_Service |
|
24 | + */ |
|
25 | + public function __construct( $validation_service, $jsonld_service ) { |
|
26 | + |
|
27 | + $this->validation_service = $validation_service; |
|
28 | + $this->jsonld_service = $jsonld_service; |
|
29 | + |
|
30 | + add_filter( 'wprm_recipe_metadata', array( $this, 'alter_jsonld' ), 10 ); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Remove recipe maker jsonld or add mentions based on the integration. |
|
35 | + * |
|
36 | + * @param $metadata |
|
37 | + * @param $recipe |
|
38 | + * |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public function alter_jsonld( $metadata ) { |
|
42 | + |
|
43 | + // If this filter is invoked on any other page except post, then we should not modify the jsonld. |
|
44 | + if ( ! get_post() instanceof \WP_Post ) { |
|
45 | + return $metadata; |
|
46 | + } |
|
47 | + |
|
48 | + $post_id = get_the_ID(); |
|
49 | + |
|
50 | + /** |
|
51 | + * We dont print our jsonld when the page has recipe maker, we enhance the recipe maker jsonld |
|
52 | + * by adding only the `mentions` property. |
|
53 | + */ |
|
54 | + add_filter( 'wl_jsonld_enabled', '__return_false' ); |
|
55 | + |
|
56 | + $post_jsonld = $this->jsonld_service->get_jsonld( false, $post_id, Jsonld_Context_Enum::PAGE ); |
|
57 | + |
|
58 | + if ( 0 === count( $post_jsonld ) || ! array_key_exists( 'mentions', $post_jsonld[0] ) |
|
59 | + || 0 === count( $post_jsonld[0]['mentions'] ) ) { |
|
60 | + // Even if we don't have mentions return the metadata. |
|
61 | + return $metadata; |
|
62 | + } |
|
63 | + |
|
64 | + $metadata['mentions'] = $post_jsonld[0]['mentions']; |
|
65 | + |
|
66 | + return $metadata; |
|
67 | + } |
|
68 | 68 | |
69 | 69 | } |
@@ -22,12 +22,12 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @param $validation_service Recipe_Maker_Validation_Service |
24 | 24 | */ |
25 | - public function __construct( $validation_service, $jsonld_service ) { |
|
25 | + public function __construct($validation_service, $jsonld_service) { |
|
26 | 26 | |
27 | 27 | $this->validation_service = $validation_service; |
28 | 28 | $this->jsonld_service = $jsonld_service; |
29 | 29 | |
30 | - add_filter( 'wprm_recipe_metadata', array( $this, 'alter_jsonld' ), 10 ); |
|
30 | + add_filter('wprm_recipe_metadata', array($this, 'alter_jsonld'), 10); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -38,10 +38,10 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return array |
40 | 40 | */ |
41 | - public function alter_jsonld( $metadata ) { |
|
41 | + public function alter_jsonld($metadata) { |
|
42 | 42 | |
43 | 43 | // If this filter is invoked on any other page except post, then we should not modify the jsonld. |
44 | - if ( ! get_post() instanceof \WP_Post ) { |
|
44 | + if ( ! get_post() instanceof \WP_Post) { |
|
45 | 45 | return $metadata; |
46 | 46 | } |
47 | 47 | |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | * We dont print our jsonld when the page has recipe maker, we enhance the recipe maker jsonld |
52 | 52 | * by adding only the `mentions` property. |
53 | 53 | */ |
54 | - add_filter( 'wl_jsonld_enabled', '__return_false' ); |
|
54 | + add_filter('wl_jsonld_enabled', '__return_false'); |
|
55 | 55 | |
56 | - $post_jsonld = $this->jsonld_service->get_jsonld( false, $post_id, Jsonld_Context_Enum::PAGE ); |
|
56 | + $post_jsonld = $this->jsonld_service->get_jsonld(false, $post_id, Jsonld_Context_Enum::PAGE); |
|
57 | 57 | |
58 | - if ( 0 === count( $post_jsonld ) || ! array_key_exists( 'mentions', $post_jsonld[0] ) |
|
59 | - || 0 === count( $post_jsonld[0]['mentions'] ) ) { |
|
58 | + if (0 === count($post_jsonld) || ! array_key_exists('mentions', $post_jsonld[0]) |
|
59 | + || 0 === count($post_jsonld[0]['mentions'])) { |
|
60 | 60 | // Even if we don't have mentions return the metadata. |
61 | 61 | return $metadata; |
62 | 62 | } |
@@ -11,35 +11,35 @@ |
||
11 | 11 | */ |
12 | 12 | class Recipe_Maker_Entity_Type_Procedure { |
13 | 13 | |
14 | - /** |
|
15 | - * Run the procedure and set all wprecipe post type |
|
16 | - * to 'Recipe' in entity type. |
|
17 | - */ |
|
18 | - public function run_procedure() { |
|
19 | - $posts = $this->get_all_published_recipe_maker_posts(); |
|
20 | - foreach ( $posts as $post_id ) { |
|
21 | - // set entity type to Product. |
|
22 | - \Wordlift_Entity_Type_Service::get_instance() |
|
23 | - ->set( |
|
24 | - $post_id, |
|
25 | - 'http://schema.org/Recipe', |
|
26 | - true |
|
27 | - ); |
|
28 | - } |
|
29 | - } |
|
14 | + /** |
|
15 | + * Run the procedure and set all wprecipe post type |
|
16 | + * to 'Recipe' in entity type. |
|
17 | + */ |
|
18 | + public function run_procedure() { |
|
19 | + $posts = $this->get_all_published_recipe_maker_posts(); |
|
20 | + foreach ( $posts as $post_id ) { |
|
21 | + // set entity type to Product. |
|
22 | + \Wordlift_Entity_Type_Service::get_instance() |
|
23 | + ->set( |
|
24 | + $post_id, |
|
25 | + 'http://schema.org/Recipe', |
|
26 | + true |
|
27 | + ); |
|
28 | + } |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @return int[]|\WP_Post[] |
|
33 | - */ |
|
34 | - private function get_all_published_recipe_maker_posts() { |
|
35 | - return get_posts( |
|
36 | - array( |
|
37 | - 'post_type' => Recipe_Maker_Post_Type_Hook::RECIPE_MAKER_POST_TYPE, |
|
38 | - 'posts_per_page' => - 1, |
|
39 | - 'post_status' => 'publish', |
|
40 | - 'fields' => 'ids', |
|
41 | - ) |
|
42 | - ); |
|
43 | - } |
|
31 | + /** |
|
32 | + * @return int[]|\WP_Post[] |
|
33 | + */ |
|
34 | + private function get_all_published_recipe_maker_posts() { |
|
35 | + return get_posts( |
|
36 | + array( |
|
37 | + 'post_type' => Recipe_Maker_Post_Type_Hook::RECIPE_MAKER_POST_TYPE, |
|
38 | + 'posts_per_page' => - 1, |
|
39 | + 'post_status' => 'publish', |
|
40 | + 'fields' => 'ids', |
|
41 | + ) |
|
42 | + ); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | */ |
18 | 18 | public function run_procedure() { |
19 | 19 | $posts = $this->get_all_published_recipe_maker_posts(); |
20 | - foreach ( $posts as $post_id ) { |
|
20 | + foreach ($posts as $post_id) { |
|
21 | 21 | // set entity type to Product. |
22 | 22 | \Wordlift_Entity_Type_Service::get_instance() |
23 | 23 | ->set( |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | return get_posts( |
36 | 36 | array( |
37 | 37 | 'post_type' => Recipe_Maker_Post_Type_Hook::RECIPE_MAKER_POST_TYPE, |
38 | - 'posts_per_page' => - 1, |
|
38 | + 'posts_per_page' => -1, |
|
39 | 39 | 'post_status' => 'publish', |
40 | 40 | 'fields' => 'ids', |
41 | 41 | ) |
@@ -16,60 +16,60 @@ |
||
16 | 16 | */ |
17 | 17 | class Recipe_Maker_After_Get_Jsonld_Hook { |
18 | 18 | |
19 | - /** |
|
20 | - * @var Recipe_Maker_Validation_Service |
|
21 | - */ |
|
22 | - private $recipe_maker_validation_service; |
|
19 | + /** |
|
20 | + * @var Recipe_Maker_Validation_Service |
|
21 | + */ |
|
22 | + private $recipe_maker_validation_service; |
|
23 | 23 | |
24 | - public function __construct( $recipe_maker_validation_service ) { |
|
25 | - $this->recipe_maker_validation_service = $recipe_maker_validation_service; |
|
26 | - // Add the filter to alter final jsonld. |
|
27 | - add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 ); |
|
28 | - } |
|
24 | + public function __construct( $recipe_maker_validation_service ) { |
|
25 | + $this->recipe_maker_validation_service = $recipe_maker_validation_service; |
|
26 | + // Add the filter to alter final jsonld. |
|
27 | + add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 ); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Add isPartOf to all the recipes. |
|
32 | - * |
|
33 | - * @param $jsonld array |
|
34 | - * |
|
35 | - * @param $post_id int |
|
36 | - * |
|
37 | - * @return array The altered jsonld array. |
|
38 | - */ |
|
39 | - public function wl_after_get_jsonld( $jsonld, $post_id ) { |
|
40 | - if ( ! is_array( $jsonld ) || count( $jsonld ) === 0 ) { |
|
41 | - return $jsonld; |
|
42 | - } |
|
43 | - // If there are no recipes in the post then dont alter the jsonld. |
|
44 | - if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) { |
|
45 | - return $jsonld; |
|
46 | - } |
|
30 | + /** |
|
31 | + * Add isPartOf to all the recipes. |
|
32 | + * |
|
33 | + * @param $jsonld array |
|
34 | + * |
|
35 | + * @param $post_id int |
|
36 | + * |
|
37 | + * @return array The altered jsonld array. |
|
38 | + */ |
|
39 | + public function wl_after_get_jsonld( $jsonld, $post_id ) { |
|
40 | + if ( ! is_array( $jsonld ) || count( $jsonld ) === 0 ) { |
|
41 | + return $jsonld; |
|
42 | + } |
|
43 | + // If there are no recipes in the post then dont alter the jsonld. |
|
44 | + if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) { |
|
45 | + return $jsonld; |
|
46 | + } |
|
47 | 47 | |
48 | - // We remove the current post jsonld. |
|
49 | - $post_jsonld = array_shift( $jsonld ); |
|
50 | - $post_jsonld_id = array_key_exists( '@id', $post_jsonld ) ? $post_jsonld['@id'] : false; |
|
48 | + // We remove the current post jsonld. |
|
49 | + $post_jsonld = array_shift( $jsonld ); |
|
50 | + $post_jsonld_id = array_key_exists( '@id', $post_jsonld ) ? $post_jsonld['@id'] : false; |
|
51 | 51 | |
52 | - if ( ! $post_jsonld_id ) { |
|
53 | - return $jsonld; |
|
54 | - } |
|
52 | + if ( ! $post_jsonld_id ) { |
|
53 | + return $jsonld; |
|
54 | + } |
|
55 | 55 | |
56 | - foreach ( $jsonld as $key => $value ) { |
|
57 | - if ( ! array_key_exists( '@type', $value ) ) { |
|
58 | - continue; |
|
59 | - } |
|
60 | - $type = $value['@type']; |
|
61 | - if ( 'Recipe' === $type ) { |
|
62 | - $value['isPartOf'] = array( |
|
63 | - '@id' => $post_jsonld_id, |
|
64 | - ); |
|
65 | - $jsonld[ $key ] = $value; |
|
66 | - } |
|
67 | - } |
|
56 | + foreach ( $jsonld as $key => $value ) { |
|
57 | + if ( ! array_key_exists( '@type', $value ) ) { |
|
58 | + continue; |
|
59 | + } |
|
60 | + $type = $value['@type']; |
|
61 | + if ( 'Recipe' === $type ) { |
|
62 | + $value['isPartOf'] = array( |
|
63 | + '@id' => $post_jsonld_id, |
|
64 | + ); |
|
65 | + $jsonld[ $key ] = $value; |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | - // Add back the post jsonld to first of array. |
|
70 | - array_unshift( $jsonld, $post_jsonld ); |
|
69 | + // Add back the post jsonld to first of array. |
|
70 | + array_unshift( $jsonld, $post_jsonld ); |
|
71 | 71 | |
72 | - return $jsonld; |
|
73 | - } |
|
72 | + return $jsonld; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | } |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | */ |
22 | 22 | private $recipe_maker_validation_service; |
23 | 23 | |
24 | - public function __construct( $recipe_maker_validation_service ) { |
|
24 | + public function __construct($recipe_maker_validation_service) { |
|
25 | 25 | $this->recipe_maker_validation_service = $recipe_maker_validation_service; |
26 | 26 | // Add the filter to alter final jsonld. |
27 | - add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 ); |
|
27 | + add_filter('wl_after_get_jsonld', array($this, 'wl_after_get_jsonld'), 10, 2); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -36,38 +36,38 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @return array The altered jsonld array. |
38 | 38 | */ |
39 | - public function wl_after_get_jsonld( $jsonld, $post_id ) { |
|
40 | - if ( ! is_array( $jsonld ) || count( $jsonld ) === 0 ) { |
|
39 | + public function wl_after_get_jsonld($jsonld, $post_id) { |
|
40 | + if ( ! is_array($jsonld) || count($jsonld) === 0) { |
|
41 | 41 | return $jsonld; |
42 | 42 | } |
43 | 43 | // If there are no recipes in the post then dont alter the jsonld. |
44 | - if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) { |
|
44 | + if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post($post_id)) { |
|
45 | 45 | return $jsonld; |
46 | 46 | } |
47 | 47 | |
48 | 48 | // We remove the current post jsonld. |
49 | - $post_jsonld = array_shift( $jsonld ); |
|
50 | - $post_jsonld_id = array_key_exists( '@id', $post_jsonld ) ? $post_jsonld['@id'] : false; |
|
49 | + $post_jsonld = array_shift($jsonld); |
|
50 | + $post_jsonld_id = array_key_exists('@id', $post_jsonld) ? $post_jsonld['@id'] : false; |
|
51 | 51 | |
52 | - if ( ! $post_jsonld_id ) { |
|
52 | + if ( ! $post_jsonld_id) { |
|
53 | 53 | return $jsonld; |
54 | 54 | } |
55 | 55 | |
56 | - foreach ( $jsonld as $key => $value ) { |
|
57 | - if ( ! array_key_exists( '@type', $value ) ) { |
|
56 | + foreach ($jsonld as $key => $value) { |
|
57 | + if ( ! array_key_exists('@type', $value)) { |
|
58 | 58 | continue; |
59 | 59 | } |
60 | 60 | $type = $value['@type']; |
61 | - if ( 'Recipe' === $type ) { |
|
61 | + if ('Recipe' === $type) { |
|
62 | 62 | $value['isPartOf'] = array( |
63 | 63 | '@id' => $post_jsonld_id, |
64 | 64 | ); |
65 | - $jsonld[ $key ] = $value; |
|
65 | + $jsonld[$key] = $value; |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | |
69 | 69 | // Add back the post jsonld to first of array. |
70 | - array_unshift( $jsonld, $post_jsonld ); |
|
70 | + array_unshift($jsonld, $post_jsonld); |
|
71 | 71 | |
72 | 72 | return $jsonld; |
73 | 73 | } |
@@ -11,102 +11,102 @@ |
||
11 | 11 | */ |
12 | 12 | class Recipe_Maker_Warning { |
13 | 13 | |
14 | - /** |
|
15 | - * @var Recipe_Maker_Validation_Service |
|
16 | - */ |
|
17 | - private $recipe_maker_validation_service; |
|
18 | - |
|
19 | - public function __construct( $recipe_maker_validation_service ) { |
|
20 | - $this->recipe_maker_validation_service = $recipe_maker_validation_service; |
|
21 | - /** |
|
22 | - * Filter: wl_feature__enable__notices. |
|
23 | - * |
|
24 | - * @param bool whether the notices needs to be enabled or not. |
|
25 | - * |
|
26 | - * @return bool |
|
27 | - * @since 3.27.6 |
|
28 | - */ |
|
29 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
30 | - add_action( 'admin_notices', array( $this, 'display_image_size_warning' ) ); |
|
31 | - } |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * Show the warning after applying the conditions. |
|
36 | - */ |
|
37 | - public function display_image_size_warning() { |
|
38 | - |
|
39 | - // Check if we are on the post. |
|
40 | - if ( ! get_post() instanceof \WP_Post ) { |
|
41 | - return false; |
|
42 | - } |
|
43 | - if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) { |
|
44 | - return false; |
|
45 | - } |
|
46 | - $post_id = get_the_ID(); |
|
47 | - |
|
48 | - // Dont show notification if there is no recipes referred by the post. |
|
49 | - if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) { |
|
50 | - return false; |
|
51 | - } |
|
52 | - |
|
53 | - $recipe_with_image_warnings = $this->get_warnings( $post_id ); |
|
54 | - |
|
55 | - if ( count( $recipe_with_image_warnings ) > 0 ) { |
|
56 | - // Show notification. |
|
57 | - ?> |
|
14 | + /** |
|
15 | + * @var Recipe_Maker_Validation_Service |
|
16 | + */ |
|
17 | + private $recipe_maker_validation_service; |
|
18 | + |
|
19 | + public function __construct( $recipe_maker_validation_service ) { |
|
20 | + $this->recipe_maker_validation_service = $recipe_maker_validation_service; |
|
21 | + /** |
|
22 | + * Filter: wl_feature__enable__notices. |
|
23 | + * |
|
24 | + * @param bool whether the notices needs to be enabled or not. |
|
25 | + * |
|
26 | + * @return bool |
|
27 | + * @since 3.27.6 |
|
28 | + */ |
|
29 | + if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
30 | + add_action( 'admin_notices', array( $this, 'display_image_size_warning' ) ); |
|
31 | + } |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * Show the warning after applying the conditions. |
|
36 | + */ |
|
37 | + public function display_image_size_warning() { |
|
38 | + |
|
39 | + // Check if we are on the post. |
|
40 | + if ( ! get_post() instanceof \WP_Post ) { |
|
41 | + return false; |
|
42 | + } |
|
43 | + if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) { |
|
44 | + return false; |
|
45 | + } |
|
46 | + $post_id = get_the_ID(); |
|
47 | + |
|
48 | + // Dont show notification if there is no recipes referred by the post. |
|
49 | + if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) { |
|
50 | + return false; |
|
51 | + } |
|
52 | + |
|
53 | + $recipe_with_image_warnings = $this->get_warnings( $post_id ); |
|
54 | + |
|
55 | + if ( count( $recipe_with_image_warnings ) > 0 ) { |
|
56 | + // Show notification. |
|
57 | + ?> |
|
58 | 58 | <div class="notice notice-warning is-dismissible"> |
59 | 59 | <p><?php echo wp_kses( __( 'The following recipes didnt have minimum image size of 1200 x 1200 px', 'wordlift' ), array() ); ?></p> |
60 | 60 | <ol> |
61 | 61 | <?php |
62 | - foreach ( $recipe_with_image_warnings as $post_id ) { |
|
63 | - echo '<li>' . esc_html( get_the_title( $post_id ) ) . '</li>'; |
|
64 | - } |
|
65 | - ?> |
|
62 | + foreach ( $recipe_with_image_warnings as $post_id ) { |
|
63 | + echo '<li>' . esc_html( get_the_title( $post_id ) ) . '</li>'; |
|
64 | + } |
|
65 | + ?> |
|
66 | 66 | </ol> |
67 | 67 | </div> |
68 | 68 | <?php |
69 | - } |
|
70 | - |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @param $post_id |
|
75 | - * |
|
76 | - * @return array |
|
77 | - */ |
|
78 | - private function get_warnings( $post_id ) { |
|
79 | - |
|
80 | - $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id ); |
|
81 | - |
|
82 | - // Dont show duplicate warnings. |
|
83 | - $recipe_ids = array_unique( $recipe_ids ); |
|
84 | - |
|
85 | - $recipe_with_image_warnings = array(); |
|
86 | - |
|
87 | - foreach ( $recipe_ids as $recipe_id ) { |
|
88 | - $recipe = \WPRM_Recipe_Manager::get_recipe( $recipe_id ); |
|
89 | - if ( ! $recipe ) { |
|
90 | - continue; |
|
91 | - } |
|
92 | - $image_id = $recipe->image_id(); |
|
93 | - $image_data = wp_get_attachment_image_src( $image_id, array( 1200, 1200 ) ); |
|
94 | - if ( ! is_array( $image_data ) ) { |
|
95 | - continue; |
|
96 | - } |
|
97 | - $image_width = array_key_exists( 1, $image_data ) ? $image_data [1] : false; |
|
98 | - $image_height = array_key_exists( 2, $image_data ) ? $image_data [2] : false; |
|
99 | - if ( ! ( $image_height && $image_width ) ) { |
|
100 | - continue; |
|
101 | - } |
|
102 | - |
|
103 | - if ( $image_height < 1200 || $image_width < 1200 ) { |
|
104 | - // Image size not present in 1200 * 1200, show a warning. |
|
105 | - $recipe_with_image_warnings[] = $recipe_id; |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - return $recipe_with_image_warnings; |
|
110 | - } |
|
69 | + } |
|
70 | + |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @param $post_id |
|
75 | + * |
|
76 | + * @return array |
|
77 | + */ |
|
78 | + private function get_warnings( $post_id ) { |
|
79 | + |
|
80 | + $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id ); |
|
81 | + |
|
82 | + // Dont show duplicate warnings. |
|
83 | + $recipe_ids = array_unique( $recipe_ids ); |
|
84 | + |
|
85 | + $recipe_with_image_warnings = array(); |
|
86 | + |
|
87 | + foreach ( $recipe_ids as $recipe_id ) { |
|
88 | + $recipe = \WPRM_Recipe_Manager::get_recipe( $recipe_id ); |
|
89 | + if ( ! $recipe ) { |
|
90 | + continue; |
|
91 | + } |
|
92 | + $image_id = $recipe->image_id(); |
|
93 | + $image_data = wp_get_attachment_image_src( $image_id, array( 1200, 1200 ) ); |
|
94 | + if ( ! is_array( $image_data ) ) { |
|
95 | + continue; |
|
96 | + } |
|
97 | + $image_width = array_key_exists( 1, $image_data ) ? $image_data [1] : false; |
|
98 | + $image_height = array_key_exists( 2, $image_data ) ? $image_data [2] : false; |
|
99 | + if ( ! ( $image_height && $image_width ) ) { |
|
100 | + continue; |
|
101 | + } |
|
102 | + |
|
103 | + if ( $image_height < 1200 || $image_width < 1200 ) { |
|
104 | + // Image size not present in 1200 * 1200, show a warning. |
|
105 | + $recipe_with_image_warnings[] = $recipe_id; |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + return $recipe_with_image_warnings; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | */ |
17 | 17 | private $recipe_maker_validation_service; |
18 | 18 | |
19 | - public function __construct( $recipe_maker_validation_service ) { |
|
19 | + public function __construct($recipe_maker_validation_service) { |
|
20 | 20 | $this->recipe_maker_validation_service = $recipe_maker_validation_service; |
21 | 21 | /** |
22 | 22 | * Filter: wl_feature__enable__notices. |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | * @return bool |
27 | 27 | * @since 3.27.6 |
28 | 28 | */ |
29 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
30 | - add_action( 'admin_notices', array( $this, 'display_image_size_warning' ) ); |
|
29 | + if (apply_filters('wl_feature__enable__notices', true)) { |
|
30 | + add_action('admin_notices', array($this, 'display_image_size_warning')); |
|
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
@@ -37,30 +37,30 @@ discard block |
||
37 | 37 | public function display_image_size_warning() { |
38 | 38 | |
39 | 39 | // Check if we are on the post. |
40 | - if ( ! get_post() instanceof \WP_Post ) { |
|
40 | + if ( ! get_post() instanceof \WP_Post) { |
|
41 | 41 | return false; |
42 | 42 | } |
43 | - if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) { |
|
43 | + if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available()) { |
|
44 | 44 | return false; |
45 | 45 | } |
46 | 46 | $post_id = get_the_ID(); |
47 | 47 | |
48 | 48 | // Dont show notification if there is no recipes referred by the post. |
49 | - if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) { |
|
49 | + if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post($post_id)) { |
|
50 | 50 | return false; |
51 | 51 | } |
52 | 52 | |
53 | - $recipe_with_image_warnings = $this->get_warnings( $post_id ); |
|
53 | + $recipe_with_image_warnings = $this->get_warnings($post_id); |
|
54 | 54 | |
55 | - if ( count( $recipe_with_image_warnings ) > 0 ) { |
|
55 | + if (count($recipe_with_image_warnings) > 0) { |
|
56 | 56 | // Show notification. |
57 | 57 | ?> |
58 | 58 | <div class="notice notice-warning is-dismissible"> |
59 | - <p><?php echo wp_kses( __( 'The following recipes didnt have minimum image size of 1200 x 1200 px', 'wordlift' ), array() ); ?></p> |
|
59 | + <p><?php echo wp_kses(__('The following recipes didnt have minimum image size of 1200 x 1200 px', 'wordlift'), array()); ?></p> |
|
60 | 60 | <ol> |
61 | 61 | <?php |
62 | - foreach ( $recipe_with_image_warnings as $post_id ) { |
|
63 | - echo '<li>' . esc_html( get_the_title( $post_id ) ) . '</li>'; |
|
62 | + foreach ($recipe_with_image_warnings as $post_id) { |
|
63 | + echo '<li>'.esc_html(get_the_title($post_id)).'</li>'; |
|
64 | 64 | } |
65 | 65 | ?> |
66 | 66 | </ol> |
@@ -75,32 +75,32 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return array |
77 | 77 | */ |
78 | - private function get_warnings( $post_id ) { |
|
78 | + private function get_warnings($post_id) { |
|
79 | 79 | |
80 | - $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id ); |
|
80 | + $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post($post_id); |
|
81 | 81 | |
82 | 82 | // Dont show duplicate warnings. |
83 | - $recipe_ids = array_unique( $recipe_ids ); |
|
83 | + $recipe_ids = array_unique($recipe_ids); |
|
84 | 84 | |
85 | 85 | $recipe_with_image_warnings = array(); |
86 | 86 | |
87 | - foreach ( $recipe_ids as $recipe_id ) { |
|
88 | - $recipe = \WPRM_Recipe_Manager::get_recipe( $recipe_id ); |
|
89 | - if ( ! $recipe ) { |
|
87 | + foreach ($recipe_ids as $recipe_id) { |
|
88 | + $recipe = \WPRM_Recipe_Manager::get_recipe($recipe_id); |
|
89 | + if ( ! $recipe) { |
|
90 | 90 | continue; |
91 | 91 | } |
92 | 92 | $image_id = $recipe->image_id(); |
93 | - $image_data = wp_get_attachment_image_src( $image_id, array( 1200, 1200 ) ); |
|
94 | - if ( ! is_array( $image_data ) ) { |
|
93 | + $image_data = wp_get_attachment_image_src($image_id, array(1200, 1200)); |
|
94 | + if ( ! is_array($image_data)) { |
|
95 | 95 | continue; |
96 | 96 | } |
97 | - $image_width = array_key_exists( 1, $image_data ) ? $image_data [1] : false; |
|
98 | - $image_height = array_key_exists( 2, $image_data ) ? $image_data [2] : false; |
|
99 | - if ( ! ( $image_height && $image_width ) ) { |
|
97 | + $image_width = array_key_exists(1, $image_data) ? $image_data [1] : false; |
|
98 | + $image_height = array_key_exists(2, $image_data) ? $image_data [2] : false; |
|
99 | + if ( ! ($image_height && $image_width)) { |
|
100 | 100 | continue; |
101 | 101 | } |
102 | 102 | |
103 | - if ( $image_height < 1200 || $image_width < 1200 ) { |
|
103 | + if ($image_height < 1200 || $image_width < 1200) { |
|
104 | 104 | // Image size not present in 1200 * 1200, show a warning. |
105 | 105 | $recipe_with_image_warnings[] = $recipe_id; |
106 | 106 | } |
@@ -8,31 +8,31 @@ |
||
8 | 8 | */ |
9 | 9 | class Recipe_Maker_Validation_Service { |
10 | 10 | |
11 | - public function is_atleast_once_recipe_present_in_the_post( $post_id ) { |
|
12 | - |
|
13 | - if ( ! $this->is_wp_recipe_maker_available() ) { |
|
14 | - return false; |
|
15 | - } |
|
16 | - $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id ); |
|
17 | - |
|
18 | - return is_array( $recipe_ids ) ? count( $recipe_ids ) > 0 : false; |
|
19 | - } |
|
20 | - |
|
21 | - public function is_wp_recipe_maker_available() { |
|
22 | - /** |
|
23 | - * Dont alter the jsonld if the classes are not present. |
|
24 | - */ |
|
25 | - if ( ! class_exists( '\WPRM_Recipe_Manager' ) || ! class_exists( 'WPRM_Metadata' ) ) { |
|
26 | - return false; |
|
27 | - } |
|
28 | - if ( ! method_exists( '\WPRM_Recipe_Manager', 'get_recipe_ids_from_post' ) || |
|
29 | - ! method_exists( '\WPRM_Recipe_Manager', 'get_recipe' ) || |
|
30 | - ! method_exists( '\WPRM_Metadata', 'get_metadata_details' ) |
|
31 | - ) { |
|
32 | - return false; |
|
33 | - } |
|
34 | - |
|
35 | - return true; |
|
36 | - } |
|
11 | + public function is_atleast_once_recipe_present_in_the_post( $post_id ) { |
|
12 | + |
|
13 | + if ( ! $this->is_wp_recipe_maker_available() ) { |
|
14 | + return false; |
|
15 | + } |
|
16 | + $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id ); |
|
17 | + |
|
18 | + return is_array( $recipe_ids ) ? count( $recipe_ids ) > 0 : false; |
|
19 | + } |
|
20 | + |
|
21 | + public function is_wp_recipe_maker_available() { |
|
22 | + /** |
|
23 | + * Dont alter the jsonld if the classes are not present. |
|
24 | + */ |
|
25 | + if ( ! class_exists( '\WPRM_Recipe_Manager' ) || ! class_exists( 'WPRM_Metadata' ) ) { |
|
26 | + return false; |
|
27 | + } |
|
28 | + if ( ! method_exists( '\WPRM_Recipe_Manager', 'get_recipe_ids_from_post' ) || |
|
29 | + ! method_exists( '\WPRM_Recipe_Manager', 'get_recipe' ) || |
|
30 | + ! method_exists( '\WPRM_Metadata', 'get_metadata_details' ) |
|
31 | + ) { |
|
32 | + return false; |
|
33 | + } |
|
34 | + |
|
35 | + return true; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | } |
@@ -8,26 +8,26 @@ |
||
8 | 8 | */ |
9 | 9 | class Recipe_Maker_Validation_Service { |
10 | 10 | |
11 | - public function is_atleast_once_recipe_present_in_the_post( $post_id ) { |
|
11 | + public function is_atleast_once_recipe_present_in_the_post($post_id) { |
|
12 | 12 | |
13 | - if ( ! $this->is_wp_recipe_maker_available() ) { |
|
13 | + if ( ! $this->is_wp_recipe_maker_available()) { |
|
14 | 14 | return false; |
15 | 15 | } |
16 | - $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id ); |
|
16 | + $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post($post_id); |
|
17 | 17 | |
18 | - return is_array( $recipe_ids ) ? count( $recipe_ids ) > 0 : false; |
|
18 | + return is_array($recipe_ids) ? count($recipe_ids) > 0 : false; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | public function is_wp_recipe_maker_available() { |
22 | 22 | /** |
23 | 23 | * Dont alter the jsonld if the classes are not present. |
24 | 24 | */ |
25 | - if ( ! class_exists( '\WPRM_Recipe_Manager' ) || ! class_exists( 'WPRM_Metadata' ) ) { |
|
25 | + if ( ! class_exists('\WPRM_Recipe_Manager') || ! class_exists('WPRM_Metadata')) { |
|
26 | 26 | return false; |
27 | 27 | } |
28 | - if ( ! method_exists( '\WPRM_Recipe_Manager', 'get_recipe_ids_from_post' ) || |
|
29 | - ! method_exists( '\WPRM_Recipe_Manager', 'get_recipe' ) || |
|
30 | - ! method_exists( '\WPRM_Metadata', 'get_metadata_details' ) |
|
28 | + if ( ! method_exists('\WPRM_Recipe_Manager', 'get_recipe_ids_from_post') || |
|
29 | + ! method_exists('\WPRM_Recipe_Manager', 'get_recipe') || |
|
30 | + ! method_exists('\WPRM_Metadata', 'get_metadata_details') |
|
31 | 31 | ) { |
32 | 32 | return false; |
33 | 33 | } |
@@ -11,88 +11,88 @@ |
||
11 | 11 | |
12 | 12 | class Webhooks_Manager { |
13 | 13 | |
14 | - /** |
|
15 | - * Registering the actions to call up sync_many or sync_delete methods |
|
16 | - */ |
|
17 | - public function __construct() { |
|
18 | - add_action( 'wl_sync__sync_many', array( $this, 'sync_many' ), 10 ); |
|
19 | - add_action( 'wl_sync__delete_one', array( $this, 'sync_delete' ), 10, 3 ); |
|
20 | - } |
|
14 | + /** |
|
15 | + * Registering the actions to call up sync_many or sync_delete methods |
|
16 | + */ |
|
17 | + public function __construct() { |
|
18 | + add_action( 'wl_sync__sync_many', array( $this, 'sync_many' ), 10 ); |
|
19 | + add_action( 'wl_sync__delete_one', array( $this, 'sync_delete' ), 10, 3 ); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * Method to call up webhook with post requested |
|
24 | - * |
|
25 | - * @param array $hashes |
|
26 | - */ |
|
27 | - public function sync_many( $hashes ) { |
|
22 | + /** |
|
23 | + * Method to call up webhook with post requested |
|
24 | + * |
|
25 | + * @param array $hashes |
|
26 | + */ |
|
27 | + public function sync_many( $hashes ) { |
|
28 | 28 | |
29 | - $urls = explode( "\n", get_option( Webhooks_Loader::URLS_OPTION_NAME, '' ) ); |
|
30 | - if ( empty( $urls ) ) { |
|
31 | - return; |
|
32 | - } |
|
29 | + $urls = explode( "\n", get_option( Webhooks_Loader::URLS_OPTION_NAME, '' ) ); |
|
30 | + if ( empty( $urls ) ) { |
|
31 | + return; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Allow 3rd parties to filter out the objects that we want to send via webhooks. |
|
36 | - * |
|
37 | - * @since 3.34.0 |
|
38 | - * @var Sync_Object_Adapter[] $filtered_objects |
|
39 | - */ |
|
40 | - $filtered_hashes = apply_filters( 'wl_webhooks__sync_many__objects', $hashes ); |
|
34 | + /** |
|
35 | + * Allow 3rd parties to filter out the objects that we want to send via webhooks. |
|
36 | + * |
|
37 | + * @since 3.34.0 |
|
38 | + * @var Sync_Object_Adapter[] $filtered_objects |
|
39 | + */ |
|
40 | + $filtered_hashes = apply_filters( 'wl_webhooks__sync_many__objects', $hashes ); |
|
41 | 41 | |
42 | - foreach ( $urls as $url ) { |
|
43 | - foreach ( $filtered_hashes as $hash ) { |
|
44 | - $jsonld = $hash[2]; |
|
45 | - $filtered_url = apply_filters( 'wl_webhooks__sync_many__url', $url, $hash ); |
|
46 | - wp_remote_request( |
|
47 | - $filtered_url, |
|
48 | - apply_filters( |
|
49 | - 'wl_webhooks__sync_many__args', |
|
50 | - array( |
|
51 | - 'blocking' => false, |
|
52 | - 'method' => 'PUT', |
|
53 | - 'headers' => array( 'content-type' => 'application/json; ' . get_bloginfo( 'charset' ) ), |
|
54 | - 'body' => $jsonld, |
|
55 | - ), |
|
56 | - $hash |
|
57 | - ) |
|
58 | - ); |
|
59 | - } |
|
60 | - } |
|
61 | - } |
|
42 | + foreach ( $urls as $url ) { |
|
43 | + foreach ( $filtered_hashes as $hash ) { |
|
44 | + $jsonld = $hash[2]; |
|
45 | + $filtered_url = apply_filters( 'wl_webhooks__sync_many__url', $url, $hash ); |
|
46 | + wp_remote_request( |
|
47 | + $filtered_url, |
|
48 | + apply_filters( |
|
49 | + 'wl_webhooks__sync_many__args', |
|
50 | + array( |
|
51 | + 'blocking' => false, |
|
52 | + 'method' => 'PUT', |
|
53 | + 'headers' => array( 'content-type' => 'application/json; ' . get_bloginfo( 'charset' ) ), |
|
54 | + 'body' => $jsonld, |
|
55 | + ), |
|
56 | + $hash |
|
57 | + ) |
|
58 | + ); |
|
59 | + } |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Method to call up webhook with delete requested |
|
65 | - * |
|
66 | - * @param string $type |
|
67 | - * @param int $object_id |
|
68 | - * @param string $uri |
|
69 | - */ |
|
70 | - public function sync_delete( $type, $object_id, $uri ) { |
|
63 | + /** |
|
64 | + * Method to call up webhook with delete requested |
|
65 | + * |
|
66 | + * @param string $type |
|
67 | + * @param int $object_id |
|
68 | + * @param string $uri |
|
69 | + */ |
|
70 | + public function sync_delete( $type, $object_id, $uri ) { |
|
71 | 71 | |
72 | - $urls = explode( "\n", get_option( Webhooks_Loader::URLS_OPTION_NAME, '' ) ); |
|
73 | - if ( empty( $urls ) ) { |
|
74 | - return; |
|
75 | - } |
|
72 | + $urls = explode( "\n", get_option( Webhooks_Loader::URLS_OPTION_NAME, '' ) ); |
|
73 | + if ( empty( $urls ) ) { |
|
74 | + return; |
|
75 | + } |
|
76 | 76 | |
77 | - if ( ! apply_filters( 'wl_webhooks__sync_delete', true, $type, $object_id, $uri ) ) { |
|
78 | - return; |
|
79 | - } |
|
77 | + if ( ! apply_filters( 'wl_webhooks__sync_delete', true, $type, $object_id, $uri ) ) { |
|
78 | + return; |
|
79 | + } |
|
80 | 80 | |
81 | - foreach ( $urls as $template_url ) { |
|
82 | - $url = add_query_arg( array( 'uri' => $uri ), $template_url ); |
|
83 | - $filtered_url = apply_filters( 'wl_webhooks__sync_delete__url', $url, $type, $object_id, $uri ); |
|
84 | - wp_remote_request( |
|
85 | - $filtered_url, |
|
86 | - apply_filters( |
|
87 | - 'wl_webhooks__sync_delete__args', |
|
88 | - array( |
|
89 | - 'blocking' => false, |
|
90 | - 'method' => 'DELETE', |
|
91 | - ) |
|
92 | - ) |
|
93 | - ); |
|
94 | - } |
|
81 | + foreach ( $urls as $template_url ) { |
|
82 | + $url = add_query_arg( array( 'uri' => $uri ), $template_url ); |
|
83 | + $filtered_url = apply_filters( 'wl_webhooks__sync_delete__url', $url, $type, $object_id, $uri ); |
|
84 | + wp_remote_request( |
|
85 | + $filtered_url, |
|
86 | + apply_filters( |
|
87 | + 'wl_webhooks__sync_delete__args', |
|
88 | + array( |
|
89 | + 'blocking' => false, |
|
90 | + 'method' => 'DELETE', |
|
91 | + ) |
|
92 | + ) |
|
93 | + ); |
|
94 | + } |
|
95 | 95 | |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | 98 | } |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | * Registering the actions to call up sync_many or sync_delete methods |
16 | 16 | */ |
17 | 17 | public function __construct() { |
18 | - add_action( 'wl_sync__sync_many', array( $this, 'sync_many' ), 10 ); |
|
19 | - add_action( 'wl_sync__delete_one', array( $this, 'sync_delete' ), 10, 3 ); |
|
18 | + add_action('wl_sync__sync_many', array($this, 'sync_many'), 10); |
|
19 | + add_action('wl_sync__delete_one', array($this, 'sync_delete'), 10, 3); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @param array $hashes |
26 | 26 | */ |
27 | - public function sync_many( $hashes ) { |
|
27 | + public function sync_many($hashes) { |
|
28 | 28 | |
29 | - $urls = explode( "\n", get_option( Webhooks_Loader::URLS_OPTION_NAME, '' ) ); |
|
30 | - if ( empty( $urls ) ) { |
|
29 | + $urls = explode("\n", get_option(Webhooks_Loader::URLS_OPTION_NAME, '')); |
|
30 | + if (empty($urls)) { |
|
31 | 31 | return; |
32 | 32 | } |
33 | 33 | |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | * @since 3.34.0 |
38 | 38 | * @var Sync_Object_Adapter[] $filtered_objects |
39 | 39 | */ |
40 | - $filtered_hashes = apply_filters( 'wl_webhooks__sync_many__objects', $hashes ); |
|
40 | + $filtered_hashes = apply_filters('wl_webhooks__sync_many__objects', $hashes); |
|
41 | 41 | |
42 | - foreach ( $urls as $url ) { |
|
43 | - foreach ( $filtered_hashes as $hash ) { |
|
42 | + foreach ($urls as $url) { |
|
43 | + foreach ($filtered_hashes as $hash) { |
|
44 | 44 | $jsonld = $hash[2]; |
45 | - $filtered_url = apply_filters( 'wl_webhooks__sync_many__url', $url, $hash ); |
|
45 | + $filtered_url = apply_filters('wl_webhooks__sync_many__url', $url, $hash); |
|
46 | 46 | wp_remote_request( |
47 | 47 | $filtered_url, |
48 | 48 | apply_filters( |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | array( |
51 | 51 | 'blocking' => false, |
52 | 52 | 'method' => 'PUT', |
53 | - 'headers' => array( 'content-type' => 'application/json; ' . get_bloginfo( 'charset' ) ), |
|
53 | + 'headers' => array('content-type' => 'application/json; '.get_bloginfo('charset')), |
|
54 | 54 | 'body' => $jsonld, |
55 | 55 | ), |
56 | 56 | $hash |
@@ -67,20 +67,20 @@ discard block |
||
67 | 67 | * @param int $object_id |
68 | 68 | * @param string $uri |
69 | 69 | */ |
70 | - public function sync_delete( $type, $object_id, $uri ) { |
|
70 | + public function sync_delete($type, $object_id, $uri) { |
|
71 | 71 | |
72 | - $urls = explode( "\n", get_option( Webhooks_Loader::URLS_OPTION_NAME, '' ) ); |
|
73 | - if ( empty( $urls ) ) { |
|
72 | + $urls = explode("\n", get_option(Webhooks_Loader::URLS_OPTION_NAME, '')); |
|
73 | + if (empty($urls)) { |
|
74 | 74 | return; |
75 | 75 | } |
76 | 76 | |
77 | - if ( ! apply_filters( 'wl_webhooks__sync_delete', true, $type, $object_id, $uri ) ) { |
|
77 | + if ( ! apply_filters('wl_webhooks__sync_delete', true, $type, $object_id, $uri)) { |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | - foreach ( $urls as $template_url ) { |
|
82 | - $url = add_query_arg( array( 'uri' => $uri ), $template_url ); |
|
83 | - $filtered_url = apply_filters( 'wl_webhooks__sync_delete__url', $url, $type, $object_id, $uri ); |
|
81 | + foreach ($urls as $template_url) { |
|
82 | + $url = add_query_arg(array('uri' => $uri), $template_url); |
|
83 | + $filtered_url = apply_filters('wl_webhooks__sync_delete__url', $url, $type, $object_id, $uri); |
|
84 | 84 | wp_remote_request( |
85 | 85 | $filtered_url, |
86 | 86 | apply_filters( |
@@ -16,166 +16,166 @@ |
||
16 | 16 | |
17 | 17 | final class Post_Excerpt_Meta_Box_Adapter { |
18 | 18 | |
19 | - /** |
|
20 | - * Key used by WordPress to add the excerpt meta box in |
|
21 | - * the $wp_meta_boxes global variable. |
|
22 | - */ |
|
23 | - const POST_EXCERPT_META_BOX_KEY = 'postexcerpt'; |
|
24 | - |
|
25 | - /** |
|
26 | - * Div id used for adding the additional content |
|
27 | - * to the WordPress excerpt meta box. |
|
28 | - */ |
|
29 | - const WORDLIFT_EXCERPT_DIV_ID = 'wl-custom-excerpt-wrapper'; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var callable|null The default callback used by WordPress to |
|
33 | - * echo the post_excerpt contents, defaults to null. |
|
34 | - */ |
|
35 | - public $wordpress_excerpt_callback = null; |
|
36 | - |
|
37 | - /** |
|
38 | - * Invokes the default callback inside our custom template callback |
|
39 | - * |
|
40 | - * @param $post array The post array. |
|
41 | - */ |
|
42 | - public function print_wordlift_custom_post_excerpt_box( $post ) { |
|
43 | - call_user_func( $this->wordpress_excerpt_callback, $post ); |
|
44 | - // Invoke our call back to add additional html, the react script will find this id and render the component there. |
|
45 | - echo "<div id='" . esc_html( self::WORDLIFT_EXCERPT_DIV_ID ) . "'></div>"; |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Replaces the default post excerpt meta box with custom post excerpt meta box. |
|
50 | - */ |
|
51 | - public function replace_post_excerpt_meta_box() { |
|
52 | - global $wp_meta_boxes; |
|
53 | - $post_type = get_post_type(); |
|
54 | - |
|
55 | - // Bail out if feature is turned off |
|
56 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
57 | - if ( ! apply_filters( 'wl_feature__enable__post-excerpt', true ) ) { |
|
58 | - return; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @since 3.27.6 |
|
63 | - * |
|
64 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1188 |
|
65 | - */ |
|
66 | - if ( ! isset( $wp_meta_boxes[ $post_type ] ) ) { |
|
67 | - return; |
|
68 | - } |
|
69 | - |
|
70 | - $core_meta_boxes = $wp_meta_boxes[ $post_type ]['normal']['core']; |
|
71 | - |
|
72 | - if ( ! isset( $core_meta_boxes[ self::POST_EXCERPT_META_BOX_KEY ] ) ) { |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - $post_excerpt_meta_box = $core_meta_boxes[ self::POST_EXCERPT_META_BOX_KEY ]; |
|
77 | - $callback = $post_excerpt_meta_box['callback']; |
|
78 | - /** |
|
79 | - * do_meta_boxes action is called 3 times by WordPress for |
|
80 | - * different set of metaboxes, so to prevent overwriting our |
|
81 | - * callback with null, this check is necessary. |
|
82 | - */ |
|
83 | - if ( null !== $callback && array( $this, 'print_wordlift_custom_post_excerpt_box' ) !== $callback ) { |
|
84 | - $this->wordpress_excerpt_callback = $callback; |
|
85 | - $this->remove_default_post_excerpt_meta_box(); |
|
86 | - $this->add_custom_post_excerpt_meta_box(); |
|
87 | - $this->enqueue_post_excerpt_scripts(); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Removes the registered post excerpt metabox. |
|
93 | - */ |
|
94 | - private function remove_default_post_excerpt_meta_box() { |
|
95 | - |
|
96 | - remove_meta_box( self::POST_EXCERPT_META_BOX_KEY, get_current_screen(), 'normal' ); |
|
97 | - |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Deserializes the string, and rewrite the order for post excerpt. |
|
102 | - * |
|
103 | - * @param $order array |
|
104 | - * |
|
105 | - * @return array |
|
106 | - */ |
|
107 | - private function deserialize_and_rewrite_order( $order ) { |
|
108 | - $side = explode( ',', $order['side'] ); |
|
109 | - $normal = explode( ',', $order['normal'] ); |
|
110 | - $advanced = explode( ',', $order['advanced'] ); |
|
111 | - $remove_array = array( self::POST_EXCERPT_META_BOX_KEY ); |
|
112 | - |
|
113 | - // We first remove from the side category if it is previously present. |
|
114 | - $side = array_diff( $side, $remove_array ); |
|
115 | - if ( count( $side ) === 0 ) { |
|
116 | - // No boxes present, so add our excerpt box at o th position. |
|
117 | - array_push( $side, self::POST_EXCERPT_META_BOX_KEY ); |
|
118 | - } else { |
|
119 | - // Add custom excerpt metabox at second position |
|
120 | - array_splice( $side, 1, 0, $remove_array ); |
|
121 | - } |
|
122 | - |
|
123 | - // We remove postexcerpt from all other metaboxes category. |
|
124 | - $normal = array_diff( $normal, $remove_array ); |
|
125 | - $advanced = array_diff( $advanced, $remove_array ); |
|
126 | - |
|
127 | - return array( |
|
128 | - 'normal' => $normal, |
|
129 | - 'side' => $side, |
|
130 | - 'advanced' => $advanced, |
|
131 | - ); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Adds the custom post excerpt metabox. |
|
136 | - */ |
|
137 | - private function add_custom_post_excerpt_meta_box() { |
|
138 | - add_meta_box( |
|
139 | - self::POST_EXCERPT_META_BOX_KEY, |
|
140 | - // phpcs:ignore WordPress.WP.I18n.MissingArgDomainDefault |
|
141 | - __( 'Excerpt' ), |
|
142 | - array( $this, 'print_wordlift_custom_post_excerpt_box' ), |
|
143 | - // Mimic the settings of the default metabox. |
|
144 | - null, |
|
145 | - 'normal', |
|
146 | - 'high' |
|
147 | - ); |
|
148 | - } |
|
149 | - |
|
150 | - private function enqueue_post_excerpt_scripts() { |
|
151 | - Scripts_Helper::enqueue_based_on_wordpress_version( |
|
152 | - 'wl-post-excerpt', |
|
153 | - plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/post-excerpt', |
|
154 | - array( 'react', 'react-dom', 'wp-polyfill' ), |
|
155 | - true |
|
156 | - ); |
|
157 | - wp_enqueue_style( |
|
158 | - 'wl-post-excerpt', |
|
159 | - plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/post-excerpt.css', |
|
160 | - array(), |
|
161 | - WORDLIFT_VERSION |
|
162 | - ); |
|
163 | - wp_localize_script( |
|
164 | - 'wl-post-excerpt', |
|
165 | - '_wlExcerptSettings', |
|
166 | - $this->get_post_excerpt_translations() |
|
167 | - ); |
|
168 | - } |
|
169 | - |
|
170 | - public function get_post_excerpt_translations() { |
|
171 | - |
|
172 | - return array( |
|
173 | - 'orText' => __( 'Or use WordLift suggested post excerpt:', 'wordlift' ), |
|
174 | - 'generatingText' => __( 'Generating excerpt...', 'wordlift' ), |
|
175 | - 'restUrl' => get_rest_url( null, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/post-excerpt' ), |
|
176 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
177 | - 'postId' => get_the_ID(), |
|
178 | - ); |
|
179 | - } |
|
19 | + /** |
|
20 | + * Key used by WordPress to add the excerpt meta box in |
|
21 | + * the $wp_meta_boxes global variable. |
|
22 | + */ |
|
23 | + const POST_EXCERPT_META_BOX_KEY = 'postexcerpt'; |
|
24 | + |
|
25 | + /** |
|
26 | + * Div id used for adding the additional content |
|
27 | + * to the WordPress excerpt meta box. |
|
28 | + */ |
|
29 | + const WORDLIFT_EXCERPT_DIV_ID = 'wl-custom-excerpt-wrapper'; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var callable|null The default callback used by WordPress to |
|
33 | + * echo the post_excerpt contents, defaults to null. |
|
34 | + */ |
|
35 | + public $wordpress_excerpt_callback = null; |
|
36 | + |
|
37 | + /** |
|
38 | + * Invokes the default callback inside our custom template callback |
|
39 | + * |
|
40 | + * @param $post array The post array. |
|
41 | + */ |
|
42 | + public function print_wordlift_custom_post_excerpt_box( $post ) { |
|
43 | + call_user_func( $this->wordpress_excerpt_callback, $post ); |
|
44 | + // Invoke our call back to add additional html, the react script will find this id and render the component there. |
|
45 | + echo "<div id='" . esc_html( self::WORDLIFT_EXCERPT_DIV_ID ) . "'></div>"; |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Replaces the default post excerpt meta box with custom post excerpt meta box. |
|
50 | + */ |
|
51 | + public function replace_post_excerpt_meta_box() { |
|
52 | + global $wp_meta_boxes; |
|
53 | + $post_type = get_post_type(); |
|
54 | + |
|
55 | + // Bail out if feature is turned off |
|
56 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
57 | + if ( ! apply_filters( 'wl_feature__enable__post-excerpt', true ) ) { |
|
58 | + return; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @since 3.27.6 |
|
63 | + * |
|
64 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1188 |
|
65 | + */ |
|
66 | + if ( ! isset( $wp_meta_boxes[ $post_type ] ) ) { |
|
67 | + return; |
|
68 | + } |
|
69 | + |
|
70 | + $core_meta_boxes = $wp_meta_boxes[ $post_type ]['normal']['core']; |
|
71 | + |
|
72 | + if ( ! isset( $core_meta_boxes[ self::POST_EXCERPT_META_BOX_KEY ] ) ) { |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + $post_excerpt_meta_box = $core_meta_boxes[ self::POST_EXCERPT_META_BOX_KEY ]; |
|
77 | + $callback = $post_excerpt_meta_box['callback']; |
|
78 | + /** |
|
79 | + * do_meta_boxes action is called 3 times by WordPress for |
|
80 | + * different set of metaboxes, so to prevent overwriting our |
|
81 | + * callback with null, this check is necessary. |
|
82 | + */ |
|
83 | + if ( null !== $callback && array( $this, 'print_wordlift_custom_post_excerpt_box' ) !== $callback ) { |
|
84 | + $this->wordpress_excerpt_callback = $callback; |
|
85 | + $this->remove_default_post_excerpt_meta_box(); |
|
86 | + $this->add_custom_post_excerpt_meta_box(); |
|
87 | + $this->enqueue_post_excerpt_scripts(); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Removes the registered post excerpt metabox. |
|
93 | + */ |
|
94 | + private function remove_default_post_excerpt_meta_box() { |
|
95 | + |
|
96 | + remove_meta_box( self::POST_EXCERPT_META_BOX_KEY, get_current_screen(), 'normal' ); |
|
97 | + |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Deserializes the string, and rewrite the order for post excerpt. |
|
102 | + * |
|
103 | + * @param $order array |
|
104 | + * |
|
105 | + * @return array |
|
106 | + */ |
|
107 | + private function deserialize_and_rewrite_order( $order ) { |
|
108 | + $side = explode( ',', $order['side'] ); |
|
109 | + $normal = explode( ',', $order['normal'] ); |
|
110 | + $advanced = explode( ',', $order['advanced'] ); |
|
111 | + $remove_array = array( self::POST_EXCERPT_META_BOX_KEY ); |
|
112 | + |
|
113 | + // We first remove from the side category if it is previously present. |
|
114 | + $side = array_diff( $side, $remove_array ); |
|
115 | + if ( count( $side ) === 0 ) { |
|
116 | + // No boxes present, so add our excerpt box at o th position. |
|
117 | + array_push( $side, self::POST_EXCERPT_META_BOX_KEY ); |
|
118 | + } else { |
|
119 | + // Add custom excerpt metabox at second position |
|
120 | + array_splice( $side, 1, 0, $remove_array ); |
|
121 | + } |
|
122 | + |
|
123 | + // We remove postexcerpt from all other metaboxes category. |
|
124 | + $normal = array_diff( $normal, $remove_array ); |
|
125 | + $advanced = array_diff( $advanced, $remove_array ); |
|
126 | + |
|
127 | + return array( |
|
128 | + 'normal' => $normal, |
|
129 | + 'side' => $side, |
|
130 | + 'advanced' => $advanced, |
|
131 | + ); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Adds the custom post excerpt metabox. |
|
136 | + */ |
|
137 | + private function add_custom_post_excerpt_meta_box() { |
|
138 | + add_meta_box( |
|
139 | + self::POST_EXCERPT_META_BOX_KEY, |
|
140 | + // phpcs:ignore WordPress.WP.I18n.MissingArgDomainDefault |
|
141 | + __( 'Excerpt' ), |
|
142 | + array( $this, 'print_wordlift_custom_post_excerpt_box' ), |
|
143 | + // Mimic the settings of the default metabox. |
|
144 | + null, |
|
145 | + 'normal', |
|
146 | + 'high' |
|
147 | + ); |
|
148 | + } |
|
149 | + |
|
150 | + private function enqueue_post_excerpt_scripts() { |
|
151 | + Scripts_Helper::enqueue_based_on_wordpress_version( |
|
152 | + 'wl-post-excerpt', |
|
153 | + plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/post-excerpt', |
|
154 | + array( 'react', 'react-dom', 'wp-polyfill' ), |
|
155 | + true |
|
156 | + ); |
|
157 | + wp_enqueue_style( |
|
158 | + 'wl-post-excerpt', |
|
159 | + plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/post-excerpt.css', |
|
160 | + array(), |
|
161 | + WORDLIFT_VERSION |
|
162 | + ); |
|
163 | + wp_localize_script( |
|
164 | + 'wl-post-excerpt', |
|
165 | + '_wlExcerptSettings', |
|
166 | + $this->get_post_excerpt_translations() |
|
167 | + ); |
|
168 | + } |
|
169 | + |
|
170 | + public function get_post_excerpt_translations() { |
|
171 | + |
|
172 | + return array( |
|
173 | + 'orText' => __( 'Or use WordLift suggested post excerpt:', 'wordlift' ), |
|
174 | + 'generatingText' => __( 'Generating excerpt...', 'wordlift' ), |
|
175 | + 'restUrl' => get_rest_url( null, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/post-excerpt' ), |
|
176 | + 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
177 | + 'postId' => get_the_ID(), |
|
178 | + ); |
|
179 | + } |
|
180 | 180 | |
181 | 181 | } |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @param $post array The post array. |
41 | 41 | */ |
42 | - public function print_wordlift_custom_post_excerpt_box( $post ) { |
|
43 | - call_user_func( $this->wordpress_excerpt_callback, $post ); |
|
42 | + public function print_wordlift_custom_post_excerpt_box($post) { |
|
43 | + call_user_func($this->wordpress_excerpt_callback, $post); |
|
44 | 44 | // Invoke our call back to add additional html, the react script will find this id and render the component there. |
45 | - echo "<div id='" . esc_html( self::WORDLIFT_EXCERPT_DIV_ID ) . "'></div>"; |
|
45 | + echo "<div id='".esc_html(self::WORDLIFT_EXCERPT_DIV_ID)."'></div>"; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | // Bail out if feature is turned off |
56 | 56 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
57 | - if ( ! apply_filters( 'wl_feature__enable__post-excerpt', true ) ) { |
|
57 | + if ( ! apply_filters('wl_feature__enable__post-excerpt', true)) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | 60 | |
@@ -63,24 +63,24 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @see https://github.com/insideout10/wordlift-plugin/issues/1188 |
65 | 65 | */ |
66 | - if ( ! isset( $wp_meta_boxes[ $post_type ] ) ) { |
|
66 | + if ( ! isset($wp_meta_boxes[$post_type])) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
70 | - $core_meta_boxes = $wp_meta_boxes[ $post_type ]['normal']['core']; |
|
70 | + $core_meta_boxes = $wp_meta_boxes[$post_type]['normal']['core']; |
|
71 | 71 | |
72 | - if ( ! isset( $core_meta_boxes[ self::POST_EXCERPT_META_BOX_KEY ] ) ) { |
|
72 | + if ( ! isset($core_meta_boxes[self::POST_EXCERPT_META_BOX_KEY])) { |
|
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | - $post_excerpt_meta_box = $core_meta_boxes[ self::POST_EXCERPT_META_BOX_KEY ]; |
|
76 | + $post_excerpt_meta_box = $core_meta_boxes[self::POST_EXCERPT_META_BOX_KEY]; |
|
77 | 77 | $callback = $post_excerpt_meta_box['callback']; |
78 | 78 | /** |
79 | 79 | * do_meta_boxes action is called 3 times by WordPress for |
80 | 80 | * different set of metaboxes, so to prevent overwriting our |
81 | 81 | * callback with null, this check is necessary. |
82 | 82 | */ |
83 | - if ( null !== $callback && array( $this, 'print_wordlift_custom_post_excerpt_box' ) !== $callback ) { |
|
83 | + if (null !== $callback && array($this, 'print_wordlift_custom_post_excerpt_box') !== $callback) { |
|
84 | 84 | $this->wordpress_excerpt_callback = $callback; |
85 | 85 | $this->remove_default_post_excerpt_meta_box(); |
86 | 86 | $this->add_custom_post_excerpt_meta_box(); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | private function remove_default_post_excerpt_meta_box() { |
95 | 95 | |
96 | - remove_meta_box( self::POST_EXCERPT_META_BOX_KEY, get_current_screen(), 'normal' ); |
|
96 | + remove_meta_box(self::POST_EXCERPT_META_BOX_KEY, get_current_screen(), 'normal'); |
|
97 | 97 | |
98 | 98 | } |
99 | 99 | |
@@ -104,25 +104,25 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @return array |
106 | 106 | */ |
107 | - private function deserialize_and_rewrite_order( $order ) { |
|
108 | - $side = explode( ',', $order['side'] ); |
|
109 | - $normal = explode( ',', $order['normal'] ); |
|
110 | - $advanced = explode( ',', $order['advanced'] ); |
|
111 | - $remove_array = array( self::POST_EXCERPT_META_BOX_KEY ); |
|
107 | + private function deserialize_and_rewrite_order($order) { |
|
108 | + $side = explode(',', $order['side']); |
|
109 | + $normal = explode(',', $order['normal']); |
|
110 | + $advanced = explode(',', $order['advanced']); |
|
111 | + $remove_array = array(self::POST_EXCERPT_META_BOX_KEY); |
|
112 | 112 | |
113 | 113 | // We first remove from the side category if it is previously present. |
114 | - $side = array_diff( $side, $remove_array ); |
|
115 | - if ( count( $side ) === 0 ) { |
|
114 | + $side = array_diff($side, $remove_array); |
|
115 | + if (count($side) === 0) { |
|
116 | 116 | // No boxes present, so add our excerpt box at o th position. |
117 | - array_push( $side, self::POST_EXCERPT_META_BOX_KEY ); |
|
117 | + array_push($side, self::POST_EXCERPT_META_BOX_KEY); |
|
118 | 118 | } else { |
119 | 119 | // Add custom excerpt metabox at second position |
120 | - array_splice( $side, 1, 0, $remove_array ); |
|
120 | + array_splice($side, 1, 0, $remove_array); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | // We remove postexcerpt from all other metaboxes category. |
124 | - $normal = array_diff( $normal, $remove_array ); |
|
125 | - $advanced = array_diff( $advanced, $remove_array ); |
|
124 | + $normal = array_diff($normal, $remove_array); |
|
125 | + $advanced = array_diff($advanced, $remove_array); |
|
126 | 126 | |
127 | 127 | return array( |
128 | 128 | 'normal' => $normal, |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | add_meta_box( |
139 | 139 | self::POST_EXCERPT_META_BOX_KEY, |
140 | 140 | // phpcs:ignore WordPress.WP.I18n.MissingArgDomainDefault |
141 | - __( 'Excerpt' ), |
|
142 | - array( $this, 'print_wordlift_custom_post_excerpt_box' ), |
|
141 | + __('Excerpt'), |
|
142 | + array($this, 'print_wordlift_custom_post_excerpt_box'), |
|
143 | 143 | // Mimic the settings of the default metabox. |
144 | 144 | null, |
145 | 145 | 'normal', |
@@ -150,13 +150,13 @@ discard block |
||
150 | 150 | private function enqueue_post_excerpt_scripts() { |
151 | 151 | Scripts_Helper::enqueue_based_on_wordpress_version( |
152 | 152 | 'wl-post-excerpt', |
153 | - plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/post-excerpt', |
|
154 | - array( 'react', 'react-dom', 'wp-polyfill' ), |
|
153 | + plugin_dir_url(dirname(__DIR__)).'js/dist/post-excerpt', |
|
154 | + array('react', 'react-dom', 'wp-polyfill'), |
|
155 | 155 | true |
156 | 156 | ); |
157 | 157 | wp_enqueue_style( |
158 | 158 | 'wl-post-excerpt', |
159 | - plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/post-excerpt.css', |
|
159 | + plugin_dir_url(dirname(__DIR__)).'js/dist/post-excerpt.css', |
|
160 | 160 | array(), |
161 | 161 | WORDLIFT_VERSION |
162 | 162 | ); |
@@ -170,10 +170,10 @@ discard block |
||
170 | 170 | public function get_post_excerpt_translations() { |
171 | 171 | |
172 | 172 | return array( |
173 | - 'orText' => __( 'Or use WordLift suggested post excerpt:', 'wordlift' ), |
|
174 | - 'generatingText' => __( 'Generating excerpt...', 'wordlift' ), |
|
175 | - 'restUrl' => get_rest_url( null, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/post-excerpt' ), |
|
176 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
173 | + 'orText' => __('Or use WordLift suggested post excerpt:', 'wordlift'), |
|
174 | + 'generatingText' => __('Generating excerpt...', 'wordlift'), |
|
175 | + 'restUrl' => get_rest_url(null, WL_REST_ROUTE_DEFAULT_NAMESPACE.'/post-excerpt'), |
|
176 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
177 | 177 | 'postId' => get_the_ID(), |
178 | 178 | ); |
179 | 179 | } |
@@ -18,168 +18,168 @@ |
||
18 | 18 | |
19 | 19 | class Linked_Data_Autocomplete_Service implements Autocomplete_Service { |
20 | 20 | |
21 | - /** |
|
22 | - * A {@link Wordlift_Log_Service} instance. |
|
23 | - * |
|
24 | - * @since 3.15.0 |
|
25 | - * @access private |
|
26 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
27 | - */ |
|
28 | - private $log; |
|
29 | - private $entity_helper; |
|
30 | - private $entity_uri_service; |
|
31 | - /** |
|
32 | - * @var \Wordlift_Entity_Service |
|
33 | - */ |
|
34 | - private $entity_service; |
|
35 | - |
|
36 | - /** |
|
37 | - * The {@link Class_Wordlift_Autocomplete_Service} instance. |
|
38 | - * |
|
39 | - * @param Entity_Helper $entity_helper |
|
40 | - * @param \Wordlift_Entity_Uri_Service $entity_uri_service |
|
41 | - * @param \Wordlift_Entity_Service $entity_service |
|
42 | - * |
|
43 | - * @since 3.15.0 |
|
44 | - */ |
|
45 | - public function __construct( $entity_helper, $entity_uri_service, $entity_service ) { |
|
46 | - |
|
47 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Autocomplete_Service' ); |
|
48 | - |
|
49 | - $this->entity_helper = $entity_helper; |
|
50 | - $this->entity_uri_service = $entity_uri_service; |
|
51 | - $this->entity_service = $entity_service; |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Make request to external API and return the response. |
|
57 | - * |
|
58 | - * @param string $query The search string. |
|
59 | - * @param string $scope The search scope: "local" will search only in the local dataset; "cloud" will search also |
|
60 | - * in Wikipedia. By default is "cloud". |
|
61 | - * @param array|string $excludes The exclude parameter string. |
|
62 | - * |
|
63 | - * @return array $response The API response. |
|
64 | - * @since 3.15.0 |
|
65 | - */ |
|
66 | - public function query( $query, $scope = 'cloud', $excludes = array() ) { |
|
67 | - |
|
68 | - $results = $this->do_query( $query, $scope, $excludes ); |
|
69 | - |
|
70 | - $uris = array_reduce( |
|
71 | - $results, |
|
72 | - function ( $carry, $result ) { |
|
73 | - |
|
74 | - $carry[] = $result['id']; |
|
75 | - |
|
76 | - return array_merge( $carry, $result['sameAss'] ); |
|
77 | - }, |
|
78 | - array() |
|
79 | - ); |
|
80 | - |
|
81 | - $mappings = $this->entity_helper->map_many_to_local( $uris ); |
|
82 | - |
|
83 | - $that = $this; |
|
84 | - $mapped_results = array_map( |
|
85 | - function ( $result ) use ( $that, $mappings ) { |
|
86 | - |
|
87 | - if ( $that->entity_uri_service->is_internal( $result['id'] ) ) { |
|
88 | - return $result; |
|
89 | - } |
|
90 | - |
|
91 | - $uris = array_merge( (array) $result['id'], $result['sameAss'] ); |
|
92 | - |
|
93 | - foreach ( $uris as $uri ) { |
|
94 | - if ( isset( $mappings[ $uri ] ) ) { |
|
95 | - $local_entity = $that->entity_uri_service->get_entity( $mappings[ $uri ] ); |
|
96 | - |
|
97 | - return $that->post_to_autocomplete_result( $mappings[ $uri ], $local_entity ); |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - return $result; |
|
102 | - }, |
|
103 | - $results |
|
104 | - ); |
|
105 | - |
|
106 | - return $mapped_results; |
|
107 | - } |
|
108 | - |
|
109 | - private function do_query( $query, $scope = 'cloud', $exclude = '' ) { |
|
110 | - $url = $this->build_request_url( $query, $exclude, $scope ); |
|
111 | - |
|
112 | - // Return the response. |
|
113 | - $response = Default_Api_Service::get_instance()->get( $url )->get_response(); |
|
114 | - |
|
115 | - // If the response is valid, then send the suggestions. |
|
116 | - if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) { |
|
117 | - // Echo the response. |
|
118 | - return json_decode( wp_remote_retrieve_body( $response ), true ); |
|
119 | - } else { |
|
120 | - // Default error message. |
|
121 | - $error_message = 'Something went wrong.'; |
|
122 | - |
|
123 | - // Get the real error message if there is WP_Error. |
|
124 | - if ( is_wp_error( $response ) ) { |
|
125 | - $error_message = $response->get_error_message(); |
|
126 | - } |
|
127 | - |
|
128 | - $this->log->error( $error_message ); |
|
129 | - |
|
130 | - return array(); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Build the autocomplete url. |
|
136 | - * |
|
137 | - * @param string $query The search string. |
|
138 | - * @param array|string $exclude The exclude parameter. |
|
139 | - * @param string $scope The search scope: "local" will search only in the local dataset; "cloud" will search also |
|
140 | - * in Wikipedia. By default is "cloud". |
|
141 | - * |
|
142 | - * @return string Built url. |
|
143 | - * @since 3.15.0 |
|
144 | - */ |
|
145 | - private function build_request_url( $query, $exclude, $scope ) { |
|
146 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
147 | - |
|
148 | - $args = array( |
|
149 | - 'key' => $configuration_service->get_key(), |
|
150 | - 'language' => $configuration_service->get_language_code(), |
|
151 | - 'query' => $query, |
|
152 | - 'scope' => $scope, |
|
153 | - 'limit' => 10, |
|
154 | - ); |
|
155 | - |
|
156 | - // Add args to URL. |
|
157 | - $request_url = add_query_arg( urlencode_deep( $args ), '/autocomplete' ); |
|
158 | - |
|
159 | - // Add the exclude parameter. |
|
160 | - if ( ! empty( $exclude ) ) { |
|
161 | - $request_url .= '&exclude=' . implode( '&exclude=', array_map( 'urlencode', (array) $exclude ) ); |
|
162 | - } |
|
163 | - |
|
164 | - // return the built url. |
|
165 | - return $request_url; |
|
166 | - } |
|
167 | - |
|
168 | - private function post_to_autocomplete_result( $uri, $post ) { |
|
169 | - |
|
170 | - return array( |
|
171 | - 'id' => $uri, |
|
172 | - 'label' => array( $post->post_title ), |
|
173 | - 'labels' => $this->entity_service->get_alternative_labels( $post->ID ), |
|
174 | - 'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post ) ), |
|
175 | - 'scope' => 'local', |
|
176 | - 'sameAss' => get_post_meta( $post->ID, Wordlift_Schema_Service::FIELD_SAME_AS ), |
|
177 | - // The following properties are less relevant because we're linking entities that exist already in the |
|
178 | - // vocabulary. That's why we don't make an effort to load the real data. |
|
179 | - 'types' => array( 'http://schema.org/Thing' ), |
|
180 | - 'urls' => array(), |
|
181 | - 'images' => array(), |
|
182 | - ); |
|
183 | - } |
|
21 | + /** |
|
22 | + * A {@link Wordlift_Log_Service} instance. |
|
23 | + * |
|
24 | + * @since 3.15.0 |
|
25 | + * @access private |
|
26 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
27 | + */ |
|
28 | + private $log; |
|
29 | + private $entity_helper; |
|
30 | + private $entity_uri_service; |
|
31 | + /** |
|
32 | + * @var \Wordlift_Entity_Service |
|
33 | + */ |
|
34 | + private $entity_service; |
|
35 | + |
|
36 | + /** |
|
37 | + * The {@link Class_Wordlift_Autocomplete_Service} instance. |
|
38 | + * |
|
39 | + * @param Entity_Helper $entity_helper |
|
40 | + * @param \Wordlift_Entity_Uri_Service $entity_uri_service |
|
41 | + * @param \Wordlift_Entity_Service $entity_service |
|
42 | + * |
|
43 | + * @since 3.15.0 |
|
44 | + */ |
|
45 | + public function __construct( $entity_helper, $entity_uri_service, $entity_service ) { |
|
46 | + |
|
47 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Autocomplete_Service' ); |
|
48 | + |
|
49 | + $this->entity_helper = $entity_helper; |
|
50 | + $this->entity_uri_service = $entity_uri_service; |
|
51 | + $this->entity_service = $entity_service; |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Make request to external API and return the response. |
|
57 | + * |
|
58 | + * @param string $query The search string. |
|
59 | + * @param string $scope The search scope: "local" will search only in the local dataset; "cloud" will search also |
|
60 | + * in Wikipedia. By default is "cloud". |
|
61 | + * @param array|string $excludes The exclude parameter string. |
|
62 | + * |
|
63 | + * @return array $response The API response. |
|
64 | + * @since 3.15.0 |
|
65 | + */ |
|
66 | + public function query( $query, $scope = 'cloud', $excludes = array() ) { |
|
67 | + |
|
68 | + $results = $this->do_query( $query, $scope, $excludes ); |
|
69 | + |
|
70 | + $uris = array_reduce( |
|
71 | + $results, |
|
72 | + function ( $carry, $result ) { |
|
73 | + |
|
74 | + $carry[] = $result['id']; |
|
75 | + |
|
76 | + return array_merge( $carry, $result['sameAss'] ); |
|
77 | + }, |
|
78 | + array() |
|
79 | + ); |
|
80 | + |
|
81 | + $mappings = $this->entity_helper->map_many_to_local( $uris ); |
|
82 | + |
|
83 | + $that = $this; |
|
84 | + $mapped_results = array_map( |
|
85 | + function ( $result ) use ( $that, $mappings ) { |
|
86 | + |
|
87 | + if ( $that->entity_uri_service->is_internal( $result['id'] ) ) { |
|
88 | + return $result; |
|
89 | + } |
|
90 | + |
|
91 | + $uris = array_merge( (array) $result['id'], $result['sameAss'] ); |
|
92 | + |
|
93 | + foreach ( $uris as $uri ) { |
|
94 | + if ( isset( $mappings[ $uri ] ) ) { |
|
95 | + $local_entity = $that->entity_uri_service->get_entity( $mappings[ $uri ] ); |
|
96 | + |
|
97 | + return $that->post_to_autocomplete_result( $mappings[ $uri ], $local_entity ); |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + return $result; |
|
102 | + }, |
|
103 | + $results |
|
104 | + ); |
|
105 | + |
|
106 | + return $mapped_results; |
|
107 | + } |
|
108 | + |
|
109 | + private function do_query( $query, $scope = 'cloud', $exclude = '' ) { |
|
110 | + $url = $this->build_request_url( $query, $exclude, $scope ); |
|
111 | + |
|
112 | + // Return the response. |
|
113 | + $response = Default_Api_Service::get_instance()->get( $url )->get_response(); |
|
114 | + |
|
115 | + // If the response is valid, then send the suggestions. |
|
116 | + if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) { |
|
117 | + // Echo the response. |
|
118 | + return json_decode( wp_remote_retrieve_body( $response ), true ); |
|
119 | + } else { |
|
120 | + // Default error message. |
|
121 | + $error_message = 'Something went wrong.'; |
|
122 | + |
|
123 | + // Get the real error message if there is WP_Error. |
|
124 | + if ( is_wp_error( $response ) ) { |
|
125 | + $error_message = $response->get_error_message(); |
|
126 | + } |
|
127 | + |
|
128 | + $this->log->error( $error_message ); |
|
129 | + |
|
130 | + return array(); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Build the autocomplete url. |
|
136 | + * |
|
137 | + * @param string $query The search string. |
|
138 | + * @param array|string $exclude The exclude parameter. |
|
139 | + * @param string $scope The search scope: "local" will search only in the local dataset; "cloud" will search also |
|
140 | + * in Wikipedia. By default is "cloud". |
|
141 | + * |
|
142 | + * @return string Built url. |
|
143 | + * @since 3.15.0 |
|
144 | + */ |
|
145 | + private function build_request_url( $query, $exclude, $scope ) { |
|
146 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
147 | + |
|
148 | + $args = array( |
|
149 | + 'key' => $configuration_service->get_key(), |
|
150 | + 'language' => $configuration_service->get_language_code(), |
|
151 | + 'query' => $query, |
|
152 | + 'scope' => $scope, |
|
153 | + 'limit' => 10, |
|
154 | + ); |
|
155 | + |
|
156 | + // Add args to URL. |
|
157 | + $request_url = add_query_arg( urlencode_deep( $args ), '/autocomplete' ); |
|
158 | + |
|
159 | + // Add the exclude parameter. |
|
160 | + if ( ! empty( $exclude ) ) { |
|
161 | + $request_url .= '&exclude=' . implode( '&exclude=', array_map( 'urlencode', (array) $exclude ) ); |
|
162 | + } |
|
163 | + |
|
164 | + // return the built url. |
|
165 | + return $request_url; |
|
166 | + } |
|
167 | + |
|
168 | + private function post_to_autocomplete_result( $uri, $post ) { |
|
169 | + |
|
170 | + return array( |
|
171 | + 'id' => $uri, |
|
172 | + 'label' => array( $post->post_title ), |
|
173 | + 'labels' => $this->entity_service->get_alternative_labels( $post->ID ), |
|
174 | + 'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post ) ), |
|
175 | + 'scope' => 'local', |
|
176 | + 'sameAss' => get_post_meta( $post->ID, Wordlift_Schema_Service::FIELD_SAME_AS ), |
|
177 | + // The following properties are less relevant because we're linking entities that exist already in the |
|
178 | + // vocabulary. That's why we don't make an effort to load the real data. |
|
179 | + 'types' => array( 'http://schema.org/Thing' ), |
|
180 | + 'urls' => array(), |
|
181 | + 'images' => array(), |
|
182 | + ); |
|
183 | + } |
|
184 | 184 | |
185 | 185 | } |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @since 3.15.0 |
44 | 44 | */ |
45 | - public function __construct( $entity_helper, $entity_uri_service, $entity_service ) { |
|
45 | + public function __construct($entity_helper, $entity_uri_service, $entity_service) { |
|
46 | 46 | |
47 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Autocomplete_Service' ); |
|
47 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Autocomplete_Service'); |
|
48 | 48 | |
49 | 49 | $this->entity_helper = $entity_helper; |
50 | 50 | $this->entity_uri_service = $entity_uri_service; |
@@ -63,38 +63,38 @@ discard block |
||
63 | 63 | * @return array $response The API response. |
64 | 64 | * @since 3.15.0 |
65 | 65 | */ |
66 | - public function query( $query, $scope = 'cloud', $excludes = array() ) { |
|
66 | + public function query($query, $scope = 'cloud', $excludes = array()) { |
|
67 | 67 | |
68 | - $results = $this->do_query( $query, $scope, $excludes ); |
|
68 | + $results = $this->do_query($query, $scope, $excludes); |
|
69 | 69 | |
70 | 70 | $uris = array_reduce( |
71 | 71 | $results, |
72 | - function ( $carry, $result ) { |
|
72 | + function($carry, $result) { |
|
73 | 73 | |
74 | 74 | $carry[] = $result['id']; |
75 | 75 | |
76 | - return array_merge( $carry, $result['sameAss'] ); |
|
76 | + return array_merge($carry, $result['sameAss']); |
|
77 | 77 | }, |
78 | 78 | array() |
79 | 79 | ); |
80 | 80 | |
81 | - $mappings = $this->entity_helper->map_many_to_local( $uris ); |
|
81 | + $mappings = $this->entity_helper->map_many_to_local($uris); |
|
82 | 82 | |
83 | 83 | $that = $this; |
84 | 84 | $mapped_results = array_map( |
85 | - function ( $result ) use ( $that, $mappings ) { |
|
85 | + function($result) use ($that, $mappings) { |
|
86 | 86 | |
87 | - if ( $that->entity_uri_service->is_internal( $result['id'] ) ) { |
|
87 | + if ($that->entity_uri_service->is_internal($result['id'])) { |
|
88 | 88 | return $result; |
89 | 89 | } |
90 | 90 | |
91 | - $uris = array_merge( (array) $result['id'], $result['sameAss'] ); |
|
91 | + $uris = array_merge((array) $result['id'], $result['sameAss']); |
|
92 | 92 | |
93 | - foreach ( $uris as $uri ) { |
|
94 | - if ( isset( $mappings[ $uri ] ) ) { |
|
95 | - $local_entity = $that->entity_uri_service->get_entity( $mappings[ $uri ] ); |
|
93 | + foreach ($uris as $uri) { |
|
94 | + if (isset($mappings[$uri])) { |
|
95 | + $local_entity = $that->entity_uri_service->get_entity($mappings[$uri]); |
|
96 | 96 | |
97 | - return $that->post_to_autocomplete_result( $mappings[ $uri ], $local_entity ); |
|
97 | + return $that->post_to_autocomplete_result($mappings[$uri], $local_entity); |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
@@ -106,26 +106,26 @@ discard block |
||
106 | 106 | return $mapped_results; |
107 | 107 | } |
108 | 108 | |
109 | - private function do_query( $query, $scope = 'cloud', $exclude = '' ) { |
|
110 | - $url = $this->build_request_url( $query, $exclude, $scope ); |
|
109 | + private function do_query($query, $scope = 'cloud', $exclude = '') { |
|
110 | + $url = $this->build_request_url($query, $exclude, $scope); |
|
111 | 111 | |
112 | 112 | // Return the response. |
113 | - $response = Default_Api_Service::get_instance()->get( $url )->get_response(); |
|
113 | + $response = Default_Api_Service::get_instance()->get($url)->get_response(); |
|
114 | 114 | |
115 | 115 | // If the response is valid, then send the suggestions. |
116 | - if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) { |
|
116 | + if ( ! is_wp_error($response) && 200 === (int) $response['response']['code']) { |
|
117 | 117 | // Echo the response. |
118 | - return json_decode( wp_remote_retrieve_body( $response ), true ); |
|
118 | + return json_decode(wp_remote_retrieve_body($response), true); |
|
119 | 119 | } else { |
120 | 120 | // Default error message. |
121 | 121 | $error_message = 'Something went wrong.'; |
122 | 122 | |
123 | 123 | // Get the real error message if there is WP_Error. |
124 | - if ( is_wp_error( $response ) ) { |
|
124 | + if (is_wp_error($response)) { |
|
125 | 125 | $error_message = $response->get_error_message(); |
126 | 126 | } |
127 | 127 | |
128 | - $this->log->error( $error_message ); |
|
128 | + $this->log->error($error_message); |
|
129 | 129 | |
130 | 130 | return array(); |
131 | 131 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @return string Built url. |
143 | 143 | * @since 3.15.0 |
144 | 144 | */ |
145 | - private function build_request_url( $query, $exclude, $scope ) { |
|
145 | + private function build_request_url($query, $exclude, $scope) { |
|
146 | 146 | $configuration_service = Wordlift_Configuration_Service::get_instance(); |
147 | 147 | |
148 | 148 | $args = array( |
@@ -154,29 +154,29 @@ discard block |
||
154 | 154 | ); |
155 | 155 | |
156 | 156 | // Add args to URL. |
157 | - $request_url = add_query_arg( urlencode_deep( $args ), '/autocomplete' ); |
|
157 | + $request_url = add_query_arg(urlencode_deep($args), '/autocomplete'); |
|
158 | 158 | |
159 | 159 | // Add the exclude parameter. |
160 | - if ( ! empty( $exclude ) ) { |
|
161 | - $request_url .= '&exclude=' . implode( '&exclude=', array_map( 'urlencode', (array) $exclude ) ); |
|
160 | + if ( ! empty($exclude)) { |
|
161 | + $request_url .= '&exclude='.implode('&exclude=', array_map('urlencode', (array) $exclude)); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | // return the built url. |
165 | 165 | return $request_url; |
166 | 166 | } |
167 | 167 | |
168 | - private function post_to_autocomplete_result( $uri, $post ) { |
|
168 | + private function post_to_autocomplete_result($uri, $post) { |
|
169 | 169 | |
170 | 170 | return array( |
171 | 171 | 'id' => $uri, |
172 | - 'label' => array( $post->post_title ), |
|
173 | - 'labels' => $this->entity_service->get_alternative_labels( $post->ID ), |
|
174 | - 'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post ) ), |
|
172 | + 'label' => array($post->post_title), |
|
173 | + 'labels' => $this->entity_service->get_alternative_labels($post->ID), |
|
174 | + 'descriptions' => array(Wordlift_Post_Excerpt_Helper::get_text_excerpt($post)), |
|
175 | 175 | 'scope' => 'local', |
176 | - 'sameAss' => get_post_meta( $post->ID, Wordlift_Schema_Service::FIELD_SAME_AS ), |
|
176 | + 'sameAss' => get_post_meta($post->ID, Wordlift_Schema_Service::FIELD_SAME_AS), |
|
177 | 177 | // The following properties are less relevant because we're linking entities that exist already in the |
178 | 178 | // vocabulary. That's why we don't make an effort to load the real data. |
179 | - 'types' => array( 'http://schema.org/Thing' ), |
|
179 | + 'types' => array('http://schema.org/Thing'), |
|
180 | 180 | 'urls' => array(), |
181 | 181 | 'images' => array(), |
182 | 182 | ); |