@@ -10,161 +10,161 @@ |
||
10 | 10 | */ |
11 | 11 | class Filler_Posts_Util { |
12 | 12 | |
13 | - /** |
|
14 | - * @var array<Filler_Posts> |
|
15 | - */ |
|
16 | - private $sources = array(); |
|
17 | - |
|
18 | - public function __construct( $post_id, $alternate_post_type = null ) { |
|
19 | - |
|
20 | - $post_type = $alternate_post_type ? $alternate_post_type : get_post_type( $post_id ); |
|
21 | - |
|
22 | - if ( 'post' === $post_type || ( is_array( $post_type ) && in_array( 'post', $post_type, true ) ) ) { |
|
23 | - $this->sources = array( |
|
24 | - new Same_Category_Filler_Posts( $post_id ), |
|
25 | - new Same_Post_Type_Filler_Posts( $post_id ), |
|
26 | - ); |
|
27 | - } elseif ( 'product' === $post_type || ( is_array( $post_type ) && in_array( 'product', $post_type, true ) ) ) { |
|
28 | - $this->sources = array( |
|
29 | - new Same_Post_Type_Same_Category_Posts( $post_id, 'product' ), |
|
30 | - new Same_Post_Type_Filler_Posts( $post_id, 'product' ), |
|
31 | - ); |
|
32 | - } else { |
|
33 | - $this->sources = array( |
|
34 | - new Same_Post_Type_Filler_Posts( $post_id ), |
|
35 | - ); |
|
36 | - } |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * @param $posts array<\WP_Post> |
|
41 | - * |
|
42 | - * @return array<int> |
|
43 | - */ |
|
44 | - private function extract_post_ids( $posts ) { |
|
45 | - return array_map( |
|
46 | - function ( $post ) { |
|
47 | - /** |
|
48 | - * @var $post \WP_Post |
|
49 | - */ |
|
50 | - return $post->ID; |
|
51 | - }, |
|
52 | - $posts |
|
53 | - ); |
|
54 | - } |
|
55 | - |
|
56 | - public function get_filler_posts( $filler_count, $post_ids_to_be_excluded ) { |
|
57 | - |
|
58 | - $filler_posts = array(); |
|
59 | - |
|
60 | - foreach ( $this->sources as $source ) { |
|
61 | - |
|
62 | - if ( $filler_count <= 0 ) { |
|
63 | - break; |
|
64 | - } |
|
65 | - /** |
|
66 | - * @var Filler_Posts $source |
|
67 | - */ |
|
68 | - $source->post_ids_to_be_excluded = $post_ids_to_be_excluded; |
|
69 | - $source->filler_count = $filler_count; |
|
70 | - |
|
71 | - $posts = $source->get_posts( $filler_count, $post_ids_to_be_excluded ); |
|
72 | - $post_ids = $this->extract_post_ids( $posts ); |
|
73 | - |
|
74 | - // Update the post ids, filler posts and filler count |
|
75 | - $post_ids_to_be_excluded = array_merge( $post_ids_to_be_excluded, $post_ids ); |
|
76 | - $filler_count = $filler_count - count( $posts ); |
|
77 | - $filler_posts = array_merge( $filler_posts, $posts ); |
|
78 | - } |
|
79 | - $filler_posts = $this->add_additional_properties_to_filler_posts( $filler_posts ); |
|
80 | - |
|
81 | - return $filler_posts; |
|
82 | - |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @param $posts array<\WP_Post> |
|
87 | - * |
|
88 | - * @return array $posts array<\WP_Post> |
|
89 | - */ |
|
90 | - private function add_additional_properties_to_filler_posts( $posts ) { |
|
91 | - return array_map( |
|
92 | - function ( $post ) { |
|
93 | - $post->thumbnail = get_the_post_thumbnail_url( $post->ID, 'medium' ); |
|
94 | - $post->permalink = get_permalink( $post->ID ); |
|
95 | - $post->post_title = html_entity_decode( $post->post_title, ENT_QUOTES, 'UTF-8' ); |
|
96 | - |
|
97 | - return $post; |
|
98 | - }, |
|
99 | - $posts |
|
100 | - ); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Called by wordlift navigator, converts all the posts to response format. |
|
105 | - * |
|
106 | - * @param $filler_count |
|
107 | - * @param $post_ids_to_be_excluded |
|
108 | - * |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - public function get_filler_response( $filler_count, $post_ids_to_be_excluded ) { |
|
112 | - $filler_posts = $this->get_filler_posts( $filler_count, $post_ids_to_be_excluded ); |
|
113 | - // Add thumbnail and permalink to filler posts |
|
114 | - $filler_response = array(); |
|
115 | - foreach ( $filler_posts as $post_obj ) { |
|
116 | - $thumbnail = get_the_post_thumbnail_url( $post_obj, 'medium' ); |
|
117 | - $filler_response[] = array( |
|
118 | - 'post' => array( |
|
119 | - 'id' => $post_obj->ID, |
|
120 | - 'permalink' => get_permalink( $post_obj->ID ), |
|
121 | - 'thumbnail' => ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH, |
|
122 | - 'title' => $post_obj->post_title, |
|
123 | - 'srcset' => Srcset_Util::get_srcset( $post_obj->ID, Srcset_Util::NAVIGATOR_WIDGET ), |
|
124 | - ), |
|
125 | - 'entity' => array( |
|
126 | - 'id' => 0, |
|
127 | - ), |
|
128 | - ); |
|
129 | - } |
|
130 | - |
|
131 | - return $filler_response; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Called by wordlift navigator, converts all the posts to response format. |
|
136 | - * |
|
137 | - * @param $filler_count |
|
138 | - * @param $post_ids_to_be_excluded |
|
139 | - * |
|
140 | - * @return array |
|
141 | - */ |
|
142 | - public function get_product_navigator_response( $filler_count, $post_ids_to_be_excluded ) { |
|
143 | - $filler_posts = $this->get_filler_posts( $filler_count, $post_ids_to_be_excluded ); |
|
144 | - // Add thumbnail and permalink to filler posts |
|
145 | - $filler_response = array(); |
|
146 | - foreach ( $filler_posts as $post_obj ) { |
|
147 | - $product = wc_get_product( $post_obj->ID ); |
|
148 | - $filler_response[] = array( |
|
149 | - 'product' => array( |
|
150 | - 'id' => $post_obj->ID, |
|
151 | - 'permalink' => get_permalink( $post_obj->ID ), |
|
152 | - 'title' => $post_obj->post_title, |
|
153 | - 'thumbnail' => get_the_post_thumbnail_url( $post_obj->ID, 'medium' ), |
|
154 | - 'regular_price' => $product->get_regular_price(), |
|
155 | - 'sale_price' => $product->get_sale_price(), |
|
156 | - 'price' => $product->get_price(), |
|
157 | - 'currency_symbol' => get_woocommerce_currency_symbol(), |
|
158 | - 'discount_pc' => ( $product->get_sale_price() && ( $product->get_regular_price() > 0 ) ) ? round( 1 - ( $product->get_sale_price() / $product->get_regular_price() ), 2 ) * 100 : 0, |
|
159 | - 'average_rating' => $product->get_average_rating(), |
|
160 | - 'rating_count' => $product->get_rating_count(), |
|
161 | - 'rating_html' => wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ), |
|
162 | - ), |
|
163 | - 'entity' => array(), |
|
164 | - ); |
|
165 | - } |
|
166 | - |
|
167 | - return $filler_response; |
|
168 | - } |
|
13 | + /** |
|
14 | + * @var array<Filler_Posts> |
|
15 | + */ |
|
16 | + private $sources = array(); |
|
17 | + |
|
18 | + public function __construct( $post_id, $alternate_post_type = null ) { |
|
19 | + |
|
20 | + $post_type = $alternate_post_type ? $alternate_post_type : get_post_type( $post_id ); |
|
21 | + |
|
22 | + if ( 'post' === $post_type || ( is_array( $post_type ) && in_array( 'post', $post_type, true ) ) ) { |
|
23 | + $this->sources = array( |
|
24 | + new Same_Category_Filler_Posts( $post_id ), |
|
25 | + new Same_Post_Type_Filler_Posts( $post_id ), |
|
26 | + ); |
|
27 | + } elseif ( 'product' === $post_type || ( is_array( $post_type ) && in_array( 'product', $post_type, true ) ) ) { |
|
28 | + $this->sources = array( |
|
29 | + new Same_Post_Type_Same_Category_Posts( $post_id, 'product' ), |
|
30 | + new Same_Post_Type_Filler_Posts( $post_id, 'product' ), |
|
31 | + ); |
|
32 | + } else { |
|
33 | + $this->sources = array( |
|
34 | + new Same_Post_Type_Filler_Posts( $post_id ), |
|
35 | + ); |
|
36 | + } |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * @param $posts array<\WP_Post> |
|
41 | + * |
|
42 | + * @return array<int> |
|
43 | + */ |
|
44 | + private function extract_post_ids( $posts ) { |
|
45 | + return array_map( |
|
46 | + function ( $post ) { |
|
47 | + /** |
|
48 | + * @var $post \WP_Post |
|
49 | + */ |
|
50 | + return $post->ID; |
|
51 | + }, |
|
52 | + $posts |
|
53 | + ); |
|
54 | + } |
|
55 | + |
|
56 | + public function get_filler_posts( $filler_count, $post_ids_to_be_excluded ) { |
|
57 | + |
|
58 | + $filler_posts = array(); |
|
59 | + |
|
60 | + foreach ( $this->sources as $source ) { |
|
61 | + |
|
62 | + if ( $filler_count <= 0 ) { |
|
63 | + break; |
|
64 | + } |
|
65 | + /** |
|
66 | + * @var Filler_Posts $source |
|
67 | + */ |
|
68 | + $source->post_ids_to_be_excluded = $post_ids_to_be_excluded; |
|
69 | + $source->filler_count = $filler_count; |
|
70 | + |
|
71 | + $posts = $source->get_posts( $filler_count, $post_ids_to_be_excluded ); |
|
72 | + $post_ids = $this->extract_post_ids( $posts ); |
|
73 | + |
|
74 | + // Update the post ids, filler posts and filler count |
|
75 | + $post_ids_to_be_excluded = array_merge( $post_ids_to_be_excluded, $post_ids ); |
|
76 | + $filler_count = $filler_count - count( $posts ); |
|
77 | + $filler_posts = array_merge( $filler_posts, $posts ); |
|
78 | + } |
|
79 | + $filler_posts = $this->add_additional_properties_to_filler_posts( $filler_posts ); |
|
80 | + |
|
81 | + return $filler_posts; |
|
82 | + |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @param $posts array<\WP_Post> |
|
87 | + * |
|
88 | + * @return array $posts array<\WP_Post> |
|
89 | + */ |
|
90 | + private function add_additional_properties_to_filler_posts( $posts ) { |
|
91 | + return array_map( |
|
92 | + function ( $post ) { |
|
93 | + $post->thumbnail = get_the_post_thumbnail_url( $post->ID, 'medium' ); |
|
94 | + $post->permalink = get_permalink( $post->ID ); |
|
95 | + $post->post_title = html_entity_decode( $post->post_title, ENT_QUOTES, 'UTF-8' ); |
|
96 | + |
|
97 | + return $post; |
|
98 | + }, |
|
99 | + $posts |
|
100 | + ); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Called by wordlift navigator, converts all the posts to response format. |
|
105 | + * |
|
106 | + * @param $filler_count |
|
107 | + * @param $post_ids_to_be_excluded |
|
108 | + * |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + public function get_filler_response( $filler_count, $post_ids_to_be_excluded ) { |
|
112 | + $filler_posts = $this->get_filler_posts( $filler_count, $post_ids_to_be_excluded ); |
|
113 | + // Add thumbnail and permalink to filler posts |
|
114 | + $filler_response = array(); |
|
115 | + foreach ( $filler_posts as $post_obj ) { |
|
116 | + $thumbnail = get_the_post_thumbnail_url( $post_obj, 'medium' ); |
|
117 | + $filler_response[] = array( |
|
118 | + 'post' => array( |
|
119 | + 'id' => $post_obj->ID, |
|
120 | + 'permalink' => get_permalink( $post_obj->ID ), |
|
121 | + 'thumbnail' => ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH, |
|
122 | + 'title' => $post_obj->post_title, |
|
123 | + 'srcset' => Srcset_Util::get_srcset( $post_obj->ID, Srcset_Util::NAVIGATOR_WIDGET ), |
|
124 | + ), |
|
125 | + 'entity' => array( |
|
126 | + 'id' => 0, |
|
127 | + ), |
|
128 | + ); |
|
129 | + } |
|
130 | + |
|
131 | + return $filler_response; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Called by wordlift navigator, converts all the posts to response format. |
|
136 | + * |
|
137 | + * @param $filler_count |
|
138 | + * @param $post_ids_to_be_excluded |
|
139 | + * |
|
140 | + * @return array |
|
141 | + */ |
|
142 | + public function get_product_navigator_response( $filler_count, $post_ids_to_be_excluded ) { |
|
143 | + $filler_posts = $this->get_filler_posts( $filler_count, $post_ids_to_be_excluded ); |
|
144 | + // Add thumbnail and permalink to filler posts |
|
145 | + $filler_response = array(); |
|
146 | + foreach ( $filler_posts as $post_obj ) { |
|
147 | + $product = wc_get_product( $post_obj->ID ); |
|
148 | + $filler_response[] = array( |
|
149 | + 'product' => array( |
|
150 | + 'id' => $post_obj->ID, |
|
151 | + 'permalink' => get_permalink( $post_obj->ID ), |
|
152 | + 'title' => $post_obj->post_title, |
|
153 | + 'thumbnail' => get_the_post_thumbnail_url( $post_obj->ID, 'medium' ), |
|
154 | + 'regular_price' => $product->get_regular_price(), |
|
155 | + 'sale_price' => $product->get_sale_price(), |
|
156 | + 'price' => $product->get_price(), |
|
157 | + 'currency_symbol' => get_woocommerce_currency_symbol(), |
|
158 | + 'discount_pc' => ( $product->get_sale_price() && ( $product->get_regular_price() > 0 ) ) ? round( 1 - ( $product->get_sale_price() / $product->get_regular_price() ), 2 ) * 100 : 0, |
|
159 | + 'average_rating' => $product->get_average_rating(), |
|
160 | + 'rating_count' => $product->get_rating_count(), |
|
161 | + 'rating_html' => wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ), |
|
162 | + ), |
|
163 | + 'entity' => array(), |
|
164 | + ); |
|
165 | + } |
|
166 | + |
|
167 | + return $filler_response; |
|
168 | + } |
|
169 | 169 | |
170 | 170 | } |
@@ -15,23 +15,23 @@ discard block |
||
15 | 15 | */ |
16 | 16 | private $sources = array(); |
17 | 17 | |
18 | - public function __construct( $post_id, $alternate_post_type = null ) { |
|
18 | + public function __construct($post_id, $alternate_post_type = null) { |
|
19 | 19 | |
20 | - $post_type = $alternate_post_type ? $alternate_post_type : get_post_type( $post_id ); |
|
20 | + $post_type = $alternate_post_type ? $alternate_post_type : get_post_type($post_id); |
|
21 | 21 | |
22 | - if ( 'post' === $post_type || ( is_array( $post_type ) && in_array( 'post', $post_type, true ) ) ) { |
|
22 | + if ('post' === $post_type || (is_array($post_type) && in_array('post', $post_type, true))) { |
|
23 | 23 | $this->sources = array( |
24 | - new Same_Category_Filler_Posts( $post_id ), |
|
25 | - new Same_Post_Type_Filler_Posts( $post_id ), |
|
24 | + new Same_Category_Filler_Posts($post_id), |
|
25 | + new Same_Post_Type_Filler_Posts($post_id), |
|
26 | 26 | ); |
27 | - } elseif ( 'product' === $post_type || ( is_array( $post_type ) && in_array( 'product', $post_type, true ) ) ) { |
|
27 | + } elseif ('product' === $post_type || (is_array($post_type) && in_array('product', $post_type, true))) { |
|
28 | 28 | $this->sources = array( |
29 | - new Same_Post_Type_Same_Category_Posts( $post_id, 'product' ), |
|
30 | - new Same_Post_Type_Filler_Posts( $post_id, 'product' ), |
|
29 | + new Same_Post_Type_Same_Category_Posts($post_id, 'product'), |
|
30 | + new Same_Post_Type_Filler_Posts($post_id, 'product'), |
|
31 | 31 | ); |
32 | 32 | } else { |
33 | 33 | $this->sources = array( |
34 | - new Same_Post_Type_Filler_Posts( $post_id ), |
|
34 | + new Same_Post_Type_Filler_Posts($post_id), |
|
35 | 35 | ); |
36 | 36 | } |
37 | 37 | } |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @return array<int> |
43 | 43 | */ |
44 | - private function extract_post_ids( $posts ) { |
|
44 | + private function extract_post_ids($posts) { |
|
45 | 45 | return array_map( |
46 | - function ( $post ) { |
|
46 | + function($post) { |
|
47 | 47 | /** |
48 | 48 | * @var $post \WP_Post |
49 | 49 | */ |
@@ -53,13 +53,13 @@ discard block |
||
53 | 53 | ); |
54 | 54 | } |
55 | 55 | |
56 | - public function get_filler_posts( $filler_count, $post_ids_to_be_excluded ) { |
|
56 | + public function get_filler_posts($filler_count, $post_ids_to_be_excluded) { |
|
57 | 57 | |
58 | 58 | $filler_posts = array(); |
59 | 59 | |
60 | - foreach ( $this->sources as $source ) { |
|
60 | + foreach ($this->sources as $source) { |
|
61 | 61 | |
62 | - if ( $filler_count <= 0 ) { |
|
62 | + if ($filler_count <= 0) { |
|
63 | 63 | break; |
64 | 64 | } |
65 | 65 | /** |
@@ -68,15 +68,15 @@ discard block |
||
68 | 68 | $source->post_ids_to_be_excluded = $post_ids_to_be_excluded; |
69 | 69 | $source->filler_count = $filler_count; |
70 | 70 | |
71 | - $posts = $source->get_posts( $filler_count, $post_ids_to_be_excluded ); |
|
72 | - $post_ids = $this->extract_post_ids( $posts ); |
|
71 | + $posts = $source->get_posts($filler_count, $post_ids_to_be_excluded); |
|
72 | + $post_ids = $this->extract_post_ids($posts); |
|
73 | 73 | |
74 | 74 | // Update the post ids, filler posts and filler count |
75 | - $post_ids_to_be_excluded = array_merge( $post_ids_to_be_excluded, $post_ids ); |
|
76 | - $filler_count = $filler_count - count( $posts ); |
|
77 | - $filler_posts = array_merge( $filler_posts, $posts ); |
|
75 | + $post_ids_to_be_excluded = array_merge($post_ids_to_be_excluded, $post_ids); |
|
76 | + $filler_count = $filler_count - count($posts); |
|
77 | + $filler_posts = array_merge($filler_posts, $posts); |
|
78 | 78 | } |
79 | - $filler_posts = $this->add_additional_properties_to_filler_posts( $filler_posts ); |
|
79 | + $filler_posts = $this->add_additional_properties_to_filler_posts($filler_posts); |
|
80 | 80 | |
81 | 81 | return $filler_posts; |
82 | 82 | |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | * |
88 | 88 | * @return array $posts array<\WP_Post> |
89 | 89 | */ |
90 | - private function add_additional_properties_to_filler_posts( $posts ) { |
|
90 | + private function add_additional_properties_to_filler_posts($posts) { |
|
91 | 91 | return array_map( |
92 | - function ( $post ) { |
|
93 | - $post->thumbnail = get_the_post_thumbnail_url( $post->ID, 'medium' ); |
|
94 | - $post->permalink = get_permalink( $post->ID ); |
|
95 | - $post->post_title = html_entity_decode( $post->post_title, ENT_QUOTES, 'UTF-8' ); |
|
92 | + function($post) { |
|
93 | + $post->thumbnail = get_the_post_thumbnail_url($post->ID, 'medium'); |
|
94 | + $post->permalink = get_permalink($post->ID); |
|
95 | + $post->post_title = html_entity_decode($post->post_title, ENT_QUOTES, 'UTF-8'); |
|
96 | 96 | |
97 | 97 | return $post; |
98 | 98 | }, |
@@ -108,19 +108,19 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return array |
110 | 110 | */ |
111 | - public function get_filler_response( $filler_count, $post_ids_to_be_excluded ) { |
|
112 | - $filler_posts = $this->get_filler_posts( $filler_count, $post_ids_to_be_excluded ); |
|
111 | + public function get_filler_response($filler_count, $post_ids_to_be_excluded) { |
|
112 | + $filler_posts = $this->get_filler_posts($filler_count, $post_ids_to_be_excluded); |
|
113 | 113 | // Add thumbnail and permalink to filler posts |
114 | 114 | $filler_response = array(); |
115 | - foreach ( $filler_posts as $post_obj ) { |
|
116 | - $thumbnail = get_the_post_thumbnail_url( $post_obj, 'medium' ); |
|
115 | + foreach ($filler_posts as $post_obj) { |
|
116 | + $thumbnail = get_the_post_thumbnail_url($post_obj, 'medium'); |
|
117 | 117 | $filler_response[] = array( |
118 | 118 | 'post' => array( |
119 | 119 | 'id' => $post_obj->ID, |
120 | - 'permalink' => get_permalink( $post_obj->ID ), |
|
121 | - 'thumbnail' => ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH, |
|
120 | + 'permalink' => get_permalink($post_obj->ID), |
|
121 | + 'thumbnail' => ($thumbnail) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH, |
|
122 | 122 | 'title' => $post_obj->post_title, |
123 | - 'srcset' => Srcset_Util::get_srcset( $post_obj->ID, Srcset_Util::NAVIGATOR_WIDGET ), |
|
123 | + 'srcset' => Srcset_Util::get_srcset($post_obj->ID, Srcset_Util::NAVIGATOR_WIDGET), |
|
124 | 124 | ), |
125 | 125 | 'entity' => array( |
126 | 126 | 'id' => 0, |
@@ -139,26 +139,26 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @return array |
141 | 141 | */ |
142 | - public function get_product_navigator_response( $filler_count, $post_ids_to_be_excluded ) { |
|
143 | - $filler_posts = $this->get_filler_posts( $filler_count, $post_ids_to_be_excluded ); |
|
142 | + public function get_product_navigator_response($filler_count, $post_ids_to_be_excluded) { |
|
143 | + $filler_posts = $this->get_filler_posts($filler_count, $post_ids_to_be_excluded); |
|
144 | 144 | // Add thumbnail and permalink to filler posts |
145 | 145 | $filler_response = array(); |
146 | - foreach ( $filler_posts as $post_obj ) { |
|
147 | - $product = wc_get_product( $post_obj->ID ); |
|
146 | + foreach ($filler_posts as $post_obj) { |
|
147 | + $product = wc_get_product($post_obj->ID); |
|
148 | 148 | $filler_response[] = array( |
149 | 149 | 'product' => array( |
150 | 150 | 'id' => $post_obj->ID, |
151 | - 'permalink' => get_permalink( $post_obj->ID ), |
|
151 | + 'permalink' => get_permalink($post_obj->ID), |
|
152 | 152 | 'title' => $post_obj->post_title, |
153 | - 'thumbnail' => get_the_post_thumbnail_url( $post_obj->ID, 'medium' ), |
|
153 | + 'thumbnail' => get_the_post_thumbnail_url($post_obj->ID, 'medium'), |
|
154 | 154 | 'regular_price' => $product->get_regular_price(), |
155 | 155 | 'sale_price' => $product->get_sale_price(), |
156 | 156 | 'price' => $product->get_price(), |
157 | 157 | 'currency_symbol' => get_woocommerce_currency_symbol(), |
158 | - 'discount_pc' => ( $product->get_sale_price() && ( $product->get_regular_price() > 0 ) ) ? round( 1 - ( $product->get_sale_price() / $product->get_regular_price() ), 2 ) * 100 : 0, |
|
158 | + 'discount_pc' => ($product->get_sale_price() && ($product->get_regular_price() > 0)) ? round(1 - ($product->get_sale_price() / $product->get_regular_price()), 2) * 100 : 0, |
|
159 | 159 | 'average_rating' => $product->get_average_rating(), |
160 | 160 | 'rating_count' => $product->get_rating_count(), |
161 | - 'rating_html' => wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ), |
|
161 | + 'rating_html' => wc_get_rating_html($product->get_average_rating(), $product->get_rating_count()), |
|
162 | 162 | ), |
163 | 163 | 'entity' => array(), |
164 | 164 | ); |
@@ -8,17 +8,17 @@ |
||
8 | 8 | */ |
9 | 9 | class Same_Post_Type_Filler_Posts extends Filler_Posts { |
10 | 10 | |
11 | - public function get_posts( $filler_count, $post_ids_to_be_excluded ) { |
|
11 | + public function get_posts( $filler_count, $post_ids_to_be_excluded ) { |
|
12 | 12 | |
13 | - $post_type = $this->alternate_post_type ? $this->alternate_post_type : get_post_type( $this->post_id ); |
|
13 | + $post_type = $this->alternate_post_type ? $this->alternate_post_type : get_post_type( $this->post_id ); |
|
14 | 14 | |
15 | - if ( 'entity' === $post_type ) { |
|
16 | - $post_type = 'post'; |
|
17 | - } |
|
15 | + if ( 'entity' === $post_type ) { |
|
16 | + $post_type = 'post'; |
|
17 | + } |
|
18 | 18 | |
19 | - return get_posts( |
|
20 | - array( 'post_type' => $post_type ) |
|
21 | - + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded ) |
|
22 | - ); |
|
23 | - } |
|
19 | + return get_posts( |
|
20 | + array( 'post_type' => $post_type ) |
|
21 | + + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded ) |
|
22 | + ); |
|
23 | + } |
|
24 | 24 | } |
@@ -8,17 +8,17 @@ |
||
8 | 8 | */ |
9 | 9 | class Same_Post_Type_Filler_Posts extends Filler_Posts { |
10 | 10 | |
11 | - public function get_posts( $filler_count, $post_ids_to_be_excluded ) { |
|
11 | + public function get_posts($filler_count, $post_ids_to_be_excluded) { |
|
12 | 12 | |
13 | - $post_type = $this->alternate_post_type ? $this->alternate_post_type : get_post_type( $this->post_id ); |
|
13 | + $post_type = $this->alternate_post_type ? $this->alternate_post_type : get_post_type($this->post_id); |
|
14 | 14 | |
15 | - if ( 'entity' === $post_type ) { |
|
15 | + if ('entity' === $post_type) { |
|
16 | 16 | $post_type = 'post'; |
17 | 17 | } |
18 | 18 | |
19 | 19 | return get_posts( |
20 | - array( 'post_type' => $post_type ) |
|
21 | - + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded ) |
|
20 | + array('post_type' => $post_type) |
|
21 | + + $this->get_posts_config($filler_count, $post_ids_to_be_excluded) |
|
22 | 22 | ); |
23 | 23 | } |
24 | 24 | } |
@@ -15,92 +15,92 @@ |
||
15 | 15 | */ |
16 | 16 | class Recipe_Maker_Jsonld_Hook { |
17 | 17 | |
18 | - /** |
|
19 | - * @var \Wordlift_Attachment_Service |
|
20 | - */ |
|
21 | - private $attachment_service; |
|
22 | - /** |
|
23 | - * @var Recipe_Maker_Validation_Service |
|
24 | - */ |
|
25 | - private $recipe_maker_validation_service; |
|
26 | - |
|
27 | - /** |
|
28 | - * Recipe_Maker_Jsonld_Hook constructor. |
|
29 | - * |
|
30 | - * @param $attachment_service \Wordlift_Attachment_Service |
|
31 | - * @param $recipe_maker_validation_service Recipe_Maker_Validation_Service |
|
32 | - */ |
|
33 | - public function __construct( $attachment_service, $recipe_maker_validation_service ) { |
|
34 | - |
|
35 | - $this->attachment_service = $attachment_service; |
|
36 | - $this->recipe_maker_validation_service = $recipe_maker_validation_service; |
|
37 | - $this->merge_recipe_jsonld(); |
|
38 | - } |
|
39 | - |
|
40 | - private function merge_recipe_jsonld() { |
|
41 | - // First we push all the linked recipes to references. |
|
42 | - add_filter( 'wl_entity_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 ); |
|
43 | - add_filter( 'wl_post_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 ); |
|
44 | - |
|
45 | - // Then we merge the jsonld for every recipe. |
|
46 | - add_filter( 'wl_entity_jsonld', array( $this, 'wl_entity_jsonld' ), 10, 2 ); |
|
47 | - } |
|
48 | - |
|
49 | - public function wl_entity_jsonld_array( $arr, $post_id ) { |
|
50 | - |
|
51 | - $jsonld = $arr['jsonld']; |
|
52 | - $references = $arr['references']; |
|
53 | - |
|
54 | - // check if wp recipe maker installed, if not return early. |
|
55 | - if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) { |
|
56 | - return $arr; |
|
57 | - } |
|
58 | - |
|
59 | - // 1. Get the jsonld from recipe maker for the post id. |
|
60 | - $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id ); |
|
61 | - |
|
62 | - // If there are no associated recipes for a post id then return early |
|
63 | - if ( ! $recipe_ids ) { |
|
64 | - return $arr; |
|
65 | - } |
|
66 | - |
|
67 | - return array( |
|
68 | - 'jsonld' => $jsonld, |
|
69 | - 'references' => array_merge( $recipe_ids, $references ), |
|
70 | - ); |
|
71 | - |
|
72 | - } |
|
73 | - |
|
74 | - public function wl_entity_jsonld( $jsonld, $post_id ) { |
|
75 | - $recipe_data = $this->process_single_recipe_item( $post_id ); |
|
76 | - if ( ! $recipe_data ) { |
|
77 | - return $jsonld; |
|
78 | - } |
|
79 | - |
|
80 | - if ( ! $jsonld ) { |
|
81 | - return $recipe_data; |
|
82 | - } |
|
83 | - |
|
84 | - return $recipe_data + $jsonld; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @param $linked_recipe_id int post id of that recipe. |
|
89 | - * |
|
90 | - * @return array Recipe valid jsonld data. |
|
91 | - */ |
|
92 | - private function process_single_recipe_item( $linked_recipe_id ) { |
|
93 | - // check if recipe maker present. |
|
94 | - if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) { |
|
95 | - return array(); |
|
96 | - } |
|
97 | - $linked_recipe = \WPRM_Recipe_Manager::get_recipe( $linked_recipe_id ); |
|
98 | - if ( $linked_recipe ) { |
|
99 | - $metadata = \WPRM_Metadata::get_metadata_details( $linked_recipe ); |
|
100 | - return $metadata ? $metadata : array(); |
|
101 | - } |
|
102 | - |
|
103 | - return array(); |
|
104 | - } |
|
18 | + /** |
|
19 | + * @var \Wordlift_Attachment_Service |
|
20 | + */ |
|
21 | + private $attachment_service; |
|
22 | + /** |
|
23 | + * @var Recipe_Maker_Validation_Service |
|
24 | + */ |
|
25 | + private $recipe_maker_validation_service; |
|
26 | + |
|
27 | + /** |
|
28 | + * Recipe_Maker_Jsonld_Hook constructor. |
|
29 | + * |
|
30 | + * @param $attachment_service \Wordlift_Attachment_Service |
|
31 | + * @param $recipe_maker_validation_service Recipe_Maker_Validation_Service |
|
32 | + */ |
|
33 | + public function __construct( $attachment_service, $recipe_maker_validation_service ) { |
|
34 | + |
|
35 | + $this->attachment_service = $attachment_service; |
|
36 | + $this->recipe_maker_validation_service = $recipe_maker_validation_service; |
|
37 | + $this->merge_recipe_jsonld(); |
|
38 | + } |
|
39 | + |
|
40 | + private function merge_recipe_jsonld() { |
|
41 | + // First we push all the linked recipes to references. |
|
42 | + add_filter( 'wl_entity_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 ); |
|
43 | + add_filter( 'wl_post_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 ); |
|
44 | + |
|
45 | + // Then we merge the jsonld for every recipe. |
|
46 | + add_filter( 'wl_entity_jsonld', array( $this, 'wl_entity_jsonld' ), 10, 2 ); |
|
47 | + } |
|
48 | + |
|
49 | + public function wl_entity_jsonld_array( $arr, $post_id ) { |
|
50 | + |
|
51 | + $jsonld = $arr['jsonld']; |
|
52 | + $references = $arr['references']; |
|
53 | + |
|
54 | + // check if wp recipe maker installed, if not return early. |
|
55 | + if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) { |
|
56 | + return $arr; |
|
57 | + } |
|
58 | + |
|
59 | + // 1. Get the jsonld from recipe maker for the post id. |
|
60 | + $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id ); |
|
61 | + |
|
62 | + // If there are no associated recipes for a post id then return early |
|
63 | + if ( ! $recipe_ids ) { |
|
64 | + return $arr; |
|
65 | + } |
|
66 | + |
|
67 | + return array( |
|
68 | + 'jsonld' => $jsonld, |
|
69 | + 'references' => array_merge( $recipe_ids, $references ), |
|
70 | + ); |
|
71 | + |
|
72 | + } |
|
73 | + |
|
74 | + public function wl_entity_jsonld( $jsonld, $post_id ) { |
|
75 | + $recipe_data = $this->process_single_recipe_item( $post_id ); |
|
76 | + if ( ! $recipe_data ) { |
|
77 | + return $jsonld; |
|
78 | + } |
|
79 | + |
|
80 | + if ( ! $jsonld ) { |
|
81 | + return $recipe_data; |
|
82 | + } |
|
83 | + |
|
84 | + return $recipe_data + $jsonld; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @param $linked_recipe_id int post id of that recipe. |
|
89 | + * |
|
90 | + * @return array Recipe valid jsonld data. |
|
91 | + */ |
|
92 | + private function process_single_recipe_item( $linked_recipe_id ) { |
|
93 | + // check if recipe maker present. |
|
94 | + if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) { |
|
95 | + return array(); |
|
96 | + } |
|
97 | + $linked_recipe = \WPRM_Recipe_Manager::get_recipe( $linked_recipe_id ); |
|
98 | + if ( $linked_recipe ) { |
|
99 | + $metadata = \WPRM_Metadata::get_metadata_details( $linked_recipe ); |
|
100 | + return $metadata ? $metadata : array(); |
|
101 | + } |
|
102 | + |
|
103 | + return array(); |
|
104 | + } |
|
105 | 105 | |
106 | 106 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param $attachment_service \Wordlift_Attachment_Service |
31 | 31 | * @param $recipe_maker_validation_service Recipe_Maker_Validation_Service |
32 | 32 | */ |
33 | - public function __construct( $attachment_service, $recipe_maker_validation_service ) { |
|
33 | + public function __construct($attachment_service, $recipe_maker_validation_service) { |
|
34 | 34 | |
35 | 35 | $this->attachment_service = $attachment_service; |
36 | 36 | $this->recipe_maker_validation_service = $recipe_maker_validation_service; |
@@ -39,45 +39,45 @@ discard block |
||
39 | 39 | |
40 | 40 | private function merge_recipe_jsonld() { |
41 | 41 | // First we push all the linked recipes to references. |
42 | - add_filter( 'wl_entity_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 ); |
|
43 | - add_filter( 'wl_post_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 ); |
|
42 | + add_filter('wl_entity_jsonld_array', array($this, 'wl_entity_jsonld_array'), 10, 2); |
|
43 | + add_filter('wl_post_jsonld_array', array($this, 'wl_entity_jsonld_array'), 10, 2); |
|
44 | 44 | |
45 | 45 | // Then we merge the jsonld for every recipe. |
46 | - add_filter( 'wl_entity_jsonld', array( $this, 'wl_entity_jsonld' ), 10, 2 ); |
|
46 | + add_filter('wl_entity_jsonld', array($this, 'wl_entity_jsonld'), 10, 2); |
|
47 | 47 | } |
48 | 48 | |
49 | - public function wl_entity_jsonld_array( $arr, $post_id ) { |
|
49 | + public function wl_entity_jsonld_array($arr, $post_id) { |
|
50 | 50 | |
51 | 51 | $jsonld = $arr['jsonld']; |
52 | 52 | $references = $arr['references']; |
53 | 53 | |
54 | 54 | // check if wp recipe maker installed, if not return early. |
55 | - if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) { |
|
55 | + if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available()) { |
|
56 | 56 | return $arr; |
57 | 57 | } |
58 | 58 | |
59 | 59 | // 1. Get the jsonld from recipe maker for the post id. |
60 | - $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id ); |
|
60 | + $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post($post_id); |
|
61 | 61 | |
62 | 62 | // If there are no associated recipes for a post id then return early |
63 | - if ( ! $recipe_ids ) { |
|
63 | + if ( ! $recipe_ids) { |
|
64 | 64 | return $arr; |
65 | 65 | } |
66 | 66 | |
67 | 67 | return array( |
68 | 68 | 'jsonld' => $jsonld, |
69 | - 'references' => array_merge( $recipe_ids, $references ), |
|
69 | + 'references' => array_merge($recipe_ids, $references), |
|
70 | 70 | ); |
71 | 71 | |
72 | 72 | } |
73 | 73 | |
74 | - public function wl_entity_jsonld( $jsonld, $post_id ) { |
|
75 | - $recipe_data = $this->process_single_recipe_item( $post_id ); |
|
76 | - if ( ! $recipe_data ) { |
|
74 | + public function wl_entity_jsonld($jsonld, $post_id) { |
|
75 | + $recipe_data = $this->process_single_recipe_item($post_id); |
|
76 | + if ( ! $recipe_data) { |
|
77 | 77 | return $jsonld; |
78 | 78 | } |
79 | 79 | |
80 | - if ( ! $jsonld ) { |
|
80 | + if ( ! $jsonld) { |
|
81 | 81 | return $recipe_data; |
82 | 82 | } |
83 | 83 | |
@@ -89,14 +89,14 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return array Recipe valid jsonld data. |
91 | 91 | */ |
92 | - private function process_single_recipe_item( $linked_recipe_id ) { |
|
92 | + private function process_single_recipe_item($linked_recipe_id) { |
|
93 | 93 | // check if recipe maker present. |
94 | - if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) { |
|
94 | + if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available()) { |
|
95 | 95 | return array(); |
96 | 96 | } |
97 | - $linked_recipe = \WPRM_Recipe_Manager::get_recipe( $linked_recipe_id ); |
|
98 | - if ( $linked_recipe ) { |
|
99 | - $metadata = \WPRM_Metadata::get_metadata_details( $linked_recipe ); |
|
97 | + $linked_recipe = \WPRM_Recipe_Manager::get_recipe($linked_recipe_id); |
|
98 | + if ($linked_recipe) { |
|
99 | + $metadata = \WPRM_Metadata::get_metadata_details($linked_recipe); |
|
100 | 100 | return $metadata ? $metadata : array(); |
101 | 101 | } |
102 | 102 |
@@ -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 | } |