@@ -12,177 +12,177 @@ |
||
12 | 12 | */ |
13 | 13 | class Analysis_Service { |
14 | 14 | |
15 | - /** |
|
16 | - * @var Default_Api_Service |
|
17 | - */ |
|
18 | - private $api_service; |
|
19 | - /** |
|
20 | - * @var Cache |
|
21 | - */ |
|
22 | - private $cache_service; |
|
23 | - /** |
|
24 | - * @var \Wordlift_Log_Service |
|
25 | - */ |
|
26 | - private $log; |
|
27 | - |
|
28 | - /** |
|
29 | - * Tag_Rest_Endpoint constructor. |
|
30 | - * |
|
31 | - * @param Default_Api_Service $api_service |
|
32 | - * @param Cache $cache_service |
|
33 | - */ |
|
34 | - public function __construct( $api_service, $cache_service ) { |
|
35 | - |
|
36 | - $this->api_service = $api_service; |
|
37 | - |
|
38 | - $this->cache_service = $cache_service; |
|
39 | - |
|
40 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
41 | - |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Check if entities are in cache, if not return the results from |
|
46 | - * cache service. |
|
47 | - * |
|
48 | - * @param $tag \WP_Term |
|
49 | - */ |
|
50 | - public function get_entities( $tag ) { |
|
51 | - |
|
52 | - $cache_key = $tag->term_id; |
|
53 | - $cache_result = $this->cache_service->get( $cache_key ); |
|
54 | - if ( false !== $cache_result ) { |
|
55 | - return $cache_result; |
|
56 | - } |
|
57 | - |
|
58 | - // send the request. |
|
59 | - $tag_name = $tag->name; |
|
60 | - |
|
61 | - $entities = $this->get_entities_by_search_query( $tag_name ); |
|
62 | - |
|
63 | - if ( ! $entities ) { |
|
64 | - return false; |
|
65 | - } |
|
66 | - |
|
67 | - $this->cache_service->put( $cache_key, $entities ); |
|
68 | - |
|
69 | - return $entities; |
|
70 | - |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @param $entity_url string |
|
75 | - * Formats the entity url from https://foo.com/some/path to |
|
76 | - * https/foo.com/some/path |
|
77 | - * |
|
78 | - * @return bool|string |
|
79 | - */ |
|
80 | - public static function format_entity_url( $entity_url ) { |
|
81 | - $result = wp_parse_url( $entity_url ); |
|
82 | - if ( ! $result ) { |
|
83 | - return false; |
|
84 | - } |
|
85 | - if ( ! array_key_exists( 'scheme', $result ) |
|
86 | - || ! array_key_exists( 'host', $result ) |
|
87 | - || ! array_key_exists( 'path', $result ) ) { |
|
88 | - return false; |
|
89 | - } |
|
90 | - |
|
91 | - return $result['scheme'] . '/' . $result['host'] . $result['path']; |
|
92 | - } |
|
93 | - |
|
94 | - private function get_meta( $entity_url ) { |
|
95 | - |
|
96 | - $cache_results = $this->cache_service->get( $entity_url ); |
|
97 | - |
|
98 | - if ( false !== $cache_results ) { |
|
99 | - return $cache_results; |
|
100 | - } |
|
101 | - |
|
102 | - $formatted_url = self::format_entity_url( $entity_url ); |
|
103 | - |
|
104 | - if ( ! $formatted_url ) { |
|
105 | - return array(); |
|
106 | - } |
|
107 | - |
|
108 | - $meta_url = 'https://api.wordlift.io/id/' . $formatted_url; |
|
109 | - |
|
110 | - $response = wp_remote_get( $meta_url ); |
|
111 | - |
|
112 | - if ( is_wp_error( $response ) |
|
113 | - || ! isset( $response['response']['code'] ) |
|
114 | - || 2 !== (int) $response['response']['code'] / 100 ) { |
|
115 | - return false; |
|
116 | - } |
|
117 | - |
|
118 | - if ( ! is_wp_error( $response ) ) { |
|
119 | - $meta = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
120 | - $this->cache_service->put( $entity_url, $meta ); |
|
121 | - |
|
122 | - return $meta; |
|
123 | - } |
|
124 | - |
|
125 | - return array(); |
|
126 | - |
|
127 | - } |
|
128 | - |
|
129 | - private function get_meta_for_entities( $entities ) { |
|
130 | - |
|
131 | - $filtered_entities = array(); |
|
132 | - foreach ( $entities as $entity ) { |
|
133 | - $entity['meta'] = array(); |
|
134 | - $meta = $this->get_meta( $entity['entityId'] ); |
|
135 | - if ( $meta ) { |
|
136 | - $meta = Default_Entity_List::compact_jsonld( $meta ); |
|
137 | - $entity['meta'] = $meta; |
|
138 | - $filtered_entities[] = $entity; |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - return $filtered_entities; |
|
143 | - |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @param $tag_name |
|
148 | - * |
|
149 | - * @return array |
|
150 | - */ |
|
151 | - public function get_entities_by_search_query( $tag_name ) { |
|
152 | - $response = $this->api_service->request( |
|
153 | - 'POST', |
|
154 | - '/analysis/single', |
|
155 | - array( 'Content-Type' => 'application/json' ), |
|
156 | - wp_json_encode( |
|
157 | - array( |
|
158 | - 'content' => $tag_name, |
|
159 | - 'contentType' => 'text/plain', |
|
160 | - 'version' => '1.0.0', |
|
161 | - 'contentLanguage' => 'en', |
|
162 | - 'scope' => $this->get_scope(), |
|
163 | - ) |
|
164 | - ) |
|
165 | - ); |
|
166 | - |
|
167 | - if ( ! $response->is_success() ) { |
|
168 | - return false; |
|
169 | - } |
|
170 | - |
|
171 | - $response = json_decode( $response->get_body(), true ); |
|
172 | - |
|
173 | - if ( ! array_key_exists( 'entities', $response ) ) { |
|
174 | - return false; |
|
175 | - } |
|
176 | - |
|
177 | - $entities = $this->get_meta_for_entities( $response['entities'] ); |
|
178 | - |
|
179 | - return $entities; |
|
180 | - } |
|
181 | - |
|
182 | - public function get_scope() { |
|
183 | - $service = \Wordlift_Configuration_Service::get_instance(); |
|
15 | + /** |
|
16 | + * @var Default_Api_Service |
|
17 | + */ |
|
18 | + private $api_service; |
|
19 | + /** |
|
20 | + * @var Cache |
|
21 | + */ |
|
22 | + private $cache_service; |
|
23 | + /** |
|
24 | + * @var \Wordlift_Log_Service |
|
25 | + */ |
|
26 | + private $log; |
|
27 | + |
|
28 | + /** |
|
29 | + * Tag_Rest_Endpoint constructor. |
|
30 | + * |
|
31 | + * @param Default_Api_Service $api_service |
|
32 | + * @param Cache $cache_service |
|
33 | + */ |
|
34 | + public function __construct( $api_service, $cache_service ) { |
|
35 | + |
|
36 | + $this->api_service = $api_service; |
|
37 | + |
|
38 | + $this->cache_service = $cache_service; |
|
39 | + |
|
40 | + $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
41 | + |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Check if entities are in cache, if not return the results from |
|
46 | + * cache service. |
|
47 | + * |
|
48 | + * @param $tag \WP_Term |
|
49 | + */ |
|
50 | + public function get_entities( $tag ) { |
|
51 | + |
|
52 | + $cache_key = $tag->term_id; |
|
53 | + $cache_result = $this->cache_service->get( $cache_key ); |
|
54 | + if ( false !== $cache_result ) { |
|
55 | + return $cache_result; |
|
56 | + } |
|
57 | + |
|
58 | + // send the request. |
|
59 | + $tag_name = $tag->name; |
|
60 | + |
|
61 | + $entities = $this->get_entities_by_search_query( $tag_name ); |
|
62 | + |
|
63 | + if ( ! $entities ) { |
|
64 | + return false; |
|
65 | + } |
|
66 | + |
|
67 | + $this->cache_service->put( $cache_key, $entities ); |
|
68 | + |
|
69 | + return $entities; |
|
70 | + |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @param $entity_url string |
|
75 | + * Formats the entity url from https://foo.com/some/path to |
|
76 | + * https/foo.com/some/path |
|
77 | + * |
|
78 | + * @return bool|string |
|
79 | + */ |
|
80 | + public static function format_entity_url( $entity_url ) { |
|
81 | + $result = wp_parse_url( $entity_url ); |
|
82 | + if ( ! $result ) { |
|
83 | + return false; |
|
84 | + } |
|
85 | + if ( ! array_key_exists( 'scheme', $result ) |
|
86 | + || ! array_key_exists( 'host', $result ) |
|
87 | + || ! array_key_exists( 'path', $result ) ) { |
|
88 | + return false; |
|
89 | + } |
|
90 | + |
|
91 | + return $result['scheme'] . '/' . $result['host'] . $result['path']; |
|
92 | + } |
|
93 | + |
|
94 | + private function get_meta( $entity_url ) { |
|
95 | + |
|
96 | + $cache_results = $this->cache_service->get( $entity_url ); |
|
97 | + |
|
98 | + if ( false !== $cache_results ) { |
|
99 | + return $cache_results; |
|
100 | + } |
|
101 | + |
|
102 | + $formatted_url = self::format_entity_url( $entity_url ); |
|
103 | + |
|
104 | + if ( ! $formatted_url ) { |
|
105 | + return array(); |
|
106 | + } |
|
107 | + |
|
108 | + $meta_url = 'https://api.wordlift.io/id/' . $formatted_url; |
|
109 | + |
|
110 | + $response = wp_remote_get( $meta_url ); |
|
111 | + |
|
112 | + if ( is_wp_error( $response ) |
|
113 | + || ! isset( $response['response']['code'] ) |
|
114 | + || 2 !== (int) $response['response']['code'] / 100 ) { |
|
115 | + return false; |
|
116 | + } |
|
117 | + |
|
118 | + if ( ! is_wp_error( $response ) ) { |
|
119 | + $meta = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
120 | + $this->cache_service->put( $entity_url, $meta ); |
|
121 | + |
|
122 | + return $meta; |
|
123 | + } |
|
124 | + |
|
125 | + return array(); |
|
126 | + |
|
127 | + } |
|
128 | + |
|
129 | + private function get_meta_for_entities( $entities ) { |
|
130 | + |
|
131 | + $filtered_entities = array(); |
|
132 | + foreach ( $entities as $entity ) { |
|
133 | + $entity['meta'] = array(); |
|
134 | + $meta = $this->get_meta( $entity['entityId'] ); |
|
135 | + if ( $meta ) { |
|
136 | + $meta = Default_Entity_List::compact_jsonld( $meta ); |
|
137 | + $entity['meta'] = $meta; |
|
138 | + $filtered_entities[] = $entity; |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + return $filtered_entities; |
|
143 | + |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @param $tag_name |
|
148 | + * |
|
149 | + * @return array |
|
150 | + */ |
|
151 | + public function get_entities_by_search_query( $tag_name ) { |
|
152 | + $response = $this->api_service->request( |
|
153 | + 'POST', |
|
154 | + '/analysis/single', |
|
155 | + array( 'Content-Type' => 'application/json' ), |
|
156 | + wp_json_encode( |
|
157 | + array( |
|
158 | + 'content' => $tag_name, |
|
159 | + 'contentType' => 'text/plain', |
|
160 | + 'version' => '1.0.0', |
|
161 | + 'contentLanguage' => 'en', |
|
162 | + 'scope' => $this->get_scope(), |
|
163 | + ) |
|
164 | + ) |
|
165 | + ); |
|
166 | + |
|
167 | + if ( ! $response->is_success() ) { |
|
168 | + return false; |
|
169 | + } |
|
170 | + |
|
171 | + $response = json_decode( $response->get_body(), true ); |
|
172 | + |
|
173 | + if ( ! array_key_exists( 'entities', $response ) ) { |
|
174 | + return false; |
|
175 | + } |
|
176 | + |
|
177 | + $entities = $this->get_meta_for_entities( $response['entities'] ); |
|
178 | + |
|
179 | + return $entities; |
|
180 | + } |
|
181 | + |
|
182 | + public function get_scope() { |
|
183 | + $service = \Wordlift_Configuration_Service::get_instance(); |
|
184 | 184 | |
185 | - return count( $service->get_network_dataset_ids() ) > 0 ? 'network-only' : 'cloud-only'; |
|
186 | - } |
|
185 | + return count( $service->get_network_dataset_ids() ) > 0 ? 'network-only' : 'cloud-only'; |
|
186 | + } |
|
187 | 187 | |
188 | 188 | } |
@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | * @param Default_Api_Service $api_service |
32 | 32 | * @param Cache $cache_service |
33 | 33 | */ |
34 | - public function __construct( $api_service, $cache_service ) { |
|
34 | + public function __construct($api_service, $cache_service) { |
|
35 | 35 | |
36 | 36 | $this->api_service = $api_service; |
37 | 37 | |
38 | 38 | $this->cache_service = $cache_service; |
39 | 39 | |
40 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
40 | + $this->log = \Wordlift_Log_Service::get_logger(get_class()); |
|
41 | 41 | |
42 | 42 | } |
43 | 43 | |
@@ -47,24 +47,24 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @param $tag \WP_Term |
49 | 49 | */ |
50 | - public function get_entities( $tag ) { |
|
50 | + public function get_entities($tag) { |
|
51 | 51 | |
52 | 52 | $cache_key = $tag->term_id; |
53 | - $cache_result = $this->cache_service->get( $cache_key ); |
|
54 | - if ( false !== $cache_result ) { |
|
53 | + $cache_result = $this->cache_service->get($cache_key); |
|
54 | + if (false !== $cache_result) { |
|
55 | 55 | return $cache_result; |
56 | 56 | } |
57 | 57 | |
58 | 58 | // send the request. |
59 | 59 | $tag_name = $tag->name; |
60 | 60 | |
61 | - $entities = $this->get_entities_by_search_query( $tag_name ); |
|
61 | + $entities = $this->get_entities_by_search_query($tag_name); |
|
62 | 62 | |
63 | - if ( ! $entities ) { |
|
63 | + if ( ! $entities) { |
|
64 | 64 | return false; |
65 | 65 | } |
66 | 66 | |
67 | - $this->cache_service->put( $cache_key, $entities ); |
|
67 | + $this->cache_service->put($cache_key, $entities); |
|
68 | 68 | |
69 | 69 | return $entities; |
70 | 70 | |
@@ -77,47 +77,47 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return bool|string |
79 | 79 | */ |
80 | - public static function format_entity_url( $entity_url ) { |
|
81 | - $result = wp_parse_url( $entity_url ); |
|
82 | - if ( ! $result ) { |
|
80 | + public static function format_entity_url($entity_url) { |
|
81 | + $result = wp_parse_url($entity_url); |
|
82 | + if ( ! $result) { |
|
83 | 83 | return false; |
84 | 84 | } |
85 | - if ( ! array_key_exists( 'scheme', $result ) |
|
86 | - || ! array_key_exists( 'host', $result ) |
|
87 | - || ! array_key_exists( 'path', $result ) ) { |
|
85 | + if ( ! array_key_exists('scheme', $result) |
|
86 | + || ! array_key_exists('host', $result) |
|
87 | + || ! array_key_exists('path', $result)) { |
|
88 | 88 | return false; |
89 | 89 | } |
90 | 90 | |
91 | - return $result['scheme'] . '/' . $result['host'] . $result['path']; |
|
91 | + return $result['scheme'].'/'.$result['host'].$result['path']; |
|
92 | 92 | } |
93 | 93 | |
94 | - private function get_meta( $entity_url ) { |
|
94 | + private function get_meta($entity_url) { |
|
95 | 95 | |
96 | - $cache_results = $this->cache_service->get( $entity_url ); |
|
96 | + $cache_results = $this->cache_service->get($entity_url); |
|
97 | 97 | |
98 | - if ( false !== $cache_results ) { |
|
98 | + if (false !== $cache_results) { |
|
99 | 99 | return $cache_results; |
100 | 100 | } |
101 | 101 | |
102 | - $formatted_url = self::format_entity_url( $entity_url ); |
|
102 | + $formatted_url = self::format_entity_url($entity_url); |
|
103 | 103 | |
104 | - if ( ! $formatted_url ) { |
|
104 | + if ( ! $formatted_url) { |
|
105 | 105 | return array(); |
106 | 106 | } |
107 | 107 | |
108 | - $meta_url = 'https://api.wordlift.io/id/' . $formatted_url; |
|
108 | + $meta_url = 'https://api.wordlift.io/id/'.$formatted_url; |
|
109 | 109 | |
110 | - $response = wp_remote_get( $meta_url ); |
|
110 | + $response = wp_remote_get($meta_url); |
|
111 | 111 | |
112 | - if ( is_wp_error( $response ) |
|
113 | - || ! isset( $response['response']['code'] ) |
|
114 | - || 2 !== (int) $response['response']['code'] / 100 ) { |
|
112 | + if (is_wp_error($response) |
|
113 | + || ! isset($response['response']['code']) |
|
114 | + || 2 !== (int) $response['response']['code'] / 100) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
118 | - if ( ! is_wp_error( $response ) ) { |
|
119 | - $meta = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
120 | - $this->cache_service->put( $entity_url, $meta ); |
|
118 | + if ( ! is_wp_error($response)) { |
|
119 | + $meta = json_decode(wp_remote_retrieve_body($response), true); |
|
120 | + $this->cache_service->put($entity_url, $meta); |
|
121 | 121 | |
122 | 122 | return $meta; |
123 | 123 | } |
@@ -126,14 +126,14 @@ discard block |
||
126 | 126 | |
127 | 127 | } |
128 | 128 | |
129 | - private function get_meta_for_entities( $entities ) { |
|
129 | + private function get_meta_for_entities($entities) { |
|
130 | 130 | |
131 | 131 | $filtered_entities = array(); |
132 | - foreach ( $entities as $entity ) { |
|
132 | + foreach ($entities as $entity) { |
|
133 | 133 | $entity['meta'] = array(); |
134 | - $meta = $this->get_meta( $entity['entityId'] ); |
|
135 | - if ( $meta ) { |
|
136 | - $meta = Default_Entity_List::compact_jsonld( $meta ); |
|
134 | + $meta = $this->get_meta($entity['entityId']); |
|
135 | + if ($meta) { |
|
136 | + $meta = Default_Entity_List::compact_jsonld($meta); |
|
137 | 137 | $entity['meta'] = $meta; |
138 | 138 | $filtered_entities[] = $entity; |
139 | 139 | } |
@@ -148,11 +148,11 @@ discard block |
||
148 | 148 | * |
149 | 149 | * @return array |
150 | 150 | */ |
151 | - public function get_entities_by_search_query( $tag_name ) { |
|
151 | + public function get_entities_by_search_query($tag_name) { |
|
152 | 152 | $response = $this->api_service->request( |
153 | 153 | 'POST', |
154 | 154 | '/analysis/single', |
155 | - array( 'Content-Type' => 'application/json' ), |
|
155 | + array('Content-Type' => 'application/json'), |
|
156 | 156 | wp_json_encode( |
157 | 157 | array( |
158 | 158 | 'content' => $tag_name, |
@@ -164,17 +164,17 @@ discard block |
||
164 | 164 | ) |
165 | 165 | ); |
166 | 166 | |
167 | - if ( ! $response->is_success() ) { |
|
167 | + if ( ! $response->is_success()) { |
|
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | |
171 | - $response = json_decode( $response->get_body(), true ); |
|
171 | + $response = json_decode($response->get_body(), true); |
|
172 | 172 | |
173 | - if ( ! array_key_exists( 'entities', $response ) ) { |
|
173 | + if ( ! array_key_exists('entities', $response)) { |
|
174 | 174 | return false; |
175 | 175 | } |
176 | 176 | |
177 | - $entities = $this->get_meta_for_entities( $response['entities'] ); |
|
177 | + $entities = $this->get_meta_for_entities($response['entities']); |
|
178 | 178 | |
179 | 179 | return $entities; |
180 | 180 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | public function get_scope() { |
183 | 183 | $service = \Wordlift_Configuration_Service::get_instance(); |
184 | 184 | |
185 | - return count( $service->get_network_dataset_ids() ) > 0 ? 'network-only' : 'cloud-only'; |
|
185 | + return count($service->get_network_dataset_ids()) > 0 ? 'network-only' : 'cloud-only'; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | use Wordlift\Task\Single_Call_Task; |
20 | 20 | |
21 | 21 | if ( ! defined( 'ABSPATH' ) ) { |
22 | - exit; |
|
22 | + exit; |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | define( 'WL_FOOD_KG_FILE', __FILE__ ); |
@@ -27,86 +27,86 @@ discard block |
||
27 | 27 | |
28 | 28 | function __wl_foodkg__load() { |
29 | 29 | |
30 | - // Autoloader for plugin itself. |
|
31 | - if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
|
32 | - require __DIR__ . '/vendor/autoload.php'; |
|
33 | - } |
|
34 | - |
|
35 | - $container_builder = new ContainerBuilder(); |
|
36 | - $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
37 | - $loader->load( 'services.yml' ); |
|
38 | - $container_builder->compile(); |
|
39 | - |
|
40 | - $notices = $container_builder->get( 'Wordlift\Modules\Food_Kg\Notices' ); |
|
41 | - $notices->register_hooks(); |
|
42 | - |
|
43 | - /** |
|
44 | - * @var Preconditions $preconditions |
|
45 | - */ |
|
46 | - $preconditions = $container_builder->get( 'Wordlift\Modules\Food_Kg\Preconditions' ); |
|
47 | - if ( ! $preconditions->pass() ) { |
|
48 | - return; |
|
49 | - } |
|
50 | - |
|
51 | - // Meta Box. |
|
52 | - $meta_box = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Meta_Box' ); |
|
53 | - $meta_box->register_hooks(); |
|
54 | - |
|
55 | - $module = $container_builder->get( 'Wordlift\Modules\Food_Kg\Module' ); |
|
56 | - $module->register_hooks(); |
|
57 | - |
|
58 | - /** @var Jsonld $jsonld */ |
|
59 | - $jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Jsonld' ); |
|
60 | - $jsonld->register_hooks(); |
|
61 | - |
|
62 | - /** |
|
63 | - * Ingredients API. |
|
64 | - */ |
|
65 | - $ingredients_api = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_API' ); |
|
66 | - $ingredients_api->register_hooks(); |
|
67 | - |
|
68 | - /** @var Main_Ingredient_Jsonld $jsonld */ |
|
69 | - $main_ingredient_jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld' ); |
|
70 | - $main_ingredient_jsonld->register_hooks(); |
|
71 | - |
|
72 | - // Main Ingredient Background Task. |
|
73 | - $main_ingredient_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy' ); |
|
74 | - Background_Task_Factory::create_action_scheduler_task( |
|
75 | - 'wl_main_ingredient_sync', |
|
76 | - 'wordlift', |
|
77 | - new All_Posts_Task( |
|
78 | - array( $main_ingredient_recipe_lift, 'process' ), |
|
79 | - 'wprm_recipe', |
|
80 | - 'sync-main-ingredient' |
|
81 | - ), |
|
82 | - '/main-ingredient', |
|
83 | - 'sync-main-ingredient', |
|
84 | - __( 'Synchronize Main Ingredient', 'wordlift' ) |
|
85 | - ); |
|
86 | - |
|
87 | - // Ingredients Taxonomy Background Task. |
|
88 | - $ingredients_taxonomy_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_Taxonomy_Recipe_Lift_Strategy' ); |
|
89 | - Background_Task_Factory::create( |
|
90 | - new Single_Call_Task( |
|
91 | - array( $ingredients_taxonomy_recipe_lift, 'run' ), |
|
92 | - 'sync-ingredients-taxonomy' |
|
93 | - ), |
|
94 | - '/sync-ingredients-taxonomy', |
|
95 | - 'sync-ingredients-taxonomy', |
|
96 | - __( 'Synchronize Ingredients Taxonomy', 'wordlift' ) |
|
97 | - ); |
|
98 | - |
|
99 | - if ( is_admin() ) { |
|
100 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Page' ); |
|
101 | - $page->register_hooks(); |
|
102 | - |
|
103 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Ingredients_Taxonomy_Page' ); |
|
104 | - $page->register_hooks(); |
|
105 | - |
|
106 | - // Download Ingredients Data. |
|
107 | - $download_ingredients_data = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data' ); |
|
108 | - $download_ingredients_data->register_hooks(); |
|
109 | - } |
|
30 | + // Autoloader for plugin itself. |
|
31 | + if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
|
32 | + require __DIR__ . '/vendor/autoload.php'; |
|
33 | + } |
|
34 | + |
|
35 | + $container_builder = new ContainerBuilder(); |
|
36 | + $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
37 | + $loader->load( 'services.yml' ); |
|
38 | + $container_builder->compile(); |
|
39 | + |
|
40 | + $notices = $container_builder->get( 'Wordlift\Modules\Food_Kg\Notices' ); |
|
41 | + $notices->register_hooks(); |
|
42 | + |
|
43 | + /** |
|
44 | + * @var Preconditions $preconditions |
|
45 | + */ |
|
46 | + $preconditions = $container_builder->get( 'Wordlift\Modules\Food_Kg\Preconditions' ); |
|
47 | + if ( ! $preconditions->pass() ) { |
|
48 | + return; |
|
49 | + } |
|
50 | + |
|
51 | + // Meta Box. |
|
52 | + $meta_box = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Meta_Box' ); |
|
53 | + $meta_box->register_hooks(); |
|
54 | + |
|
55 | + $module = $container_builder->get( 'Wordlift\Modules\Food_Kg\Module' ); |
|
56 | + $module->register_hooks(); |
|
57 | + |
|
58 | + /** @var Jsonld $jsonld */ |
|
59 | + $jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Jsonld' ); |
|
60 | + $jsonld->register_hooks(); |
|
61 | + |
|
62 | + /** |
|
63 | + * Ingredients API. |
|
64 | + */ |
|
65 | + $ingredients_api = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_API' ); |
|
66 | + $ingredients_api->register_hooks(); |
|
67 | + |
|
68 | + /** @var Main_Ingredient_Jsonld $jsonld */ |
|
69 | + $main_ingredient_jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld' ); |
|
70 | + $main_ingredient_jsonld->register_hooks(); |
|
71 | + |
|
72 | + // Main Ingredient Background Task. |
|
73 | + $main_ingredient_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy' ); |
|
74 | + Background_Task_Factory::create_action_scheduler_task( |
|
75 | + 'wl_main_ingredient_sync', |
|
76 | + 'wordlift', |
|
77 | + new All_Posts_Task( |
|
78 | + array( $main_ingredient_recipe_lift, 'process' ), |
|
79 | + 'wprm_recipe', |
|
80 | + 'sync-main-ingredient' |
|
81 | + ), |
|
82 | + '/main-ingredient', |
|
83 | + 'sync-main-ingredient', |
|
84 | + __( 'Synchronize Main Ingredient', 'wordlift' ) |
|
85 | + ); |
|
86 | + |
|
87 | + // Ingredients Taxonomy Background Task. |
|
88 | + $ingredients_taxonomy_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_Taxonomy_Recipe_Lift_Strategy' ); |
|
89 | + Background_Task_Factory::create( |
|
90 | + new Single_Call_Task( |
|
91 | + array( $ingredients_taxonomy_recipe_lift, 'run' ), |
|
92 | + 'sync-ingredients-taxonomy' |
|
93 | + ), |
|
94 | + '/sync-ingredients-taxonomy', |
|
95 | + 'sync-ingredients-taxonomy', |
|
96 | + __( 'Synchronize Ingredients Taxonomy', 'wordlift' ) |
|
97 | + ); |
|
98 | + |
|
99 | + if ( is_admin() ) { |
|
100 | + $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Page' ); |
|
101 | + $page->register_hooks(); |
|
102 | + |
|
103 | + $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Ingredients_Taxonomy_Page' ); |
|
104 | + $page->register_hooks(); |
|
105 | + |
|
106 | + // Download Ingredients Data. |
|
107 | + $download_ingredients_data = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data' ); |
|
108 | + $download_ingredients_data->register_hooks(); |
|
109 | + } |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | add_action( 'plugins_loaded', '__wl_foodkg__load' ); |
@@ -18,96 +18,96 @@ |
||
18 | 18 | use Wordlift\Task\Background\Background_Task_Factory; |
19 | 19 | use Wordlift\Task\Single_Call_Task; |
20 | 20 | |
21 | -if ( ! defined( 'ABSPATH' ) ) { |
|
21 | +if ( ! defined('ABSPATH')) { |
|
22 | 22 | exit; |
23 | 23 | } |
24 | 24 | |
25 | -define( 'WL_FOOD_KG_FILE', __FILE__ ); |
|
26 | -define( 'WL_FOOD_KG_DIR_PATH', dirname( WL_FOOD_KG_FILE ) ); |
|
25 | +define('WL_FOOD_KG_FILE', __FILE__); |
|
26 | +define('WL_FOOD_KG_DIR_PATH', dirname(WL_FOOD_KG_FILE)); |
|
27 | 27 | |
28 | 28 | function __wl_foodkg__load() { |
29 | 29 | |
30 | 30 | // Autoloader for plugin itself. |
31 | - if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
|
32 | - require __DIR__ . '/vendor/autoload.php'; |
|
31 | + if (file_exists(__DIR__.'/vendor/autoload.php')) { |
|
32 | + require __DIR__.'/vendor/autoload.php'; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | $container_builder = new ContainerBuilder(); |
36 | - $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
37 | - $loader->load( 'services.yml' ); |
|
36 | + $loader = new YamlFileLoader($container_builder, new FileLocator(__DIR__)); |
|
37 | + $loader->load('services.yml'); |
|
38 | 38 | $container_builder->compile(); |
39 | 39 | |
40 | - $notices = $container_builder->get( 'Wordlift\Modules\Food_Kg\Notices' ); |
|
40 | + $notices = $container_builder->get('Wordlift\Modules\Food_Kg\Notices'); |
|
41 | 41 | $notices->register_hooks(); |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @var Preconditions $preconditions |
45 | 45 | */ |
46 | - $preconditions = $container_builder->get( 'Wordlift\Modules\Food_Kg\Preconditions' ); |
|
47 | - if ( ! $preconditions->pass() ) { |
|
46 | + $preconditions = $container_builder->get('Wordlift\Modules\Food_Kg\Preconditions'); |
|
47 | + if ( ! $preconditions->pass()) { |
|
48 | 48 | return; |
49 | 49 | } |
50 | 50 | |
51 | 51 | // Meta Box. |
52 | - $meta_box = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Meta_Box' ); |
|
52 | + $meta_box = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Meta_Box'); |
|
53 | 53 | $meta_box->register_hooks(); |
54 | 54 | |
55 | - $module = $container_builder->get( 'Wordlift\Modules\Food_Kg\Module' ); |
|
55 | + $module = $container_builder->get('Wordlift\Modules\Food_Kg\Module'); |
|
56 | 56 | $module->register_hooks(); |
57 | 57 | |
58 | 58 | /** @var Jsonld $jsonld */ |
59 | - $jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Jsonld' ); |
|
59 | + $jsonld = $container_builder->get('Wordlift\Modules\Food_Kg\Jsonld'); |
|
60 | 60 | $jsonld->register_hooks(); |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * Ingredients API. |
64 | 64 | */ |
65 | - $ingredients_api = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_API' ); |
|
65 | + $ingredients_api = $container_builder->get('Wordlift\Modules\Food_Kg\Ingredients_API'); |
|
66 | 66 | $ingredients_api->register_hooks(); |
67 | 67 | |
68 | 68 | /** @var Main_Ingredient_Jsonld $jsonld */ |
69 | - $main_ingredient_jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld' ); |
|
69 | + $main_ingredient_jsonld = $container_builder->get('Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld'); |
|
70 | 70 | $main_ingredient_jsonld->register_hooks(); |
71 | 71 | |
72 | 72 | // Main Ingredient Background Task. |
73 | - $main_ingredient_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy' ); |
|
73 | + $main_ingredient_recipe_lift = $container_builder->get('Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy'); |
|
74 | 74 | Background_Task_Factory::create_action_scheduler_task( |
75 | 75 | 'wl_main_ingredient_sync', |
76 | 76 | 'wordlift', |
77 | 77 | new All_Posts_Task( |
78 | - array( $main_ingredient_recipe_lift, 'process' ), |
|
78 | + array($main_ingredient_recipe_lift, 'process'), |
|
79 | 79 | 'wprm_recipe', |
80 | 80 | 'sync-main-ingredient' |
81 | 81 | ), |
82 | 82 | '/main-ingredient', |
83 | 83 | 'sync-main-ingredient', |
84 | - __( 'Synchronize Main Ingredient', 'wordlift' ) |
|
84 | + __('Synchronize Main Ingredient', 'wordlift') |
|
85 | 85 | ); |
86 | 86 | |
87 | 87 | // Ingredients Taxonomy Background Task. |
88 | - $ingredients_taxonomy_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_Taxonomy_Recipe_Lift_Strategy' ); |
|
88 | + $ingredients_taxonomy_recipe_lift = $container_builder->get('Wordlift\Modules\Food_Kg\Ingredients_Taxonomy_Recipe_Lift_Strategy'); |
|
89 | 89 | Background_Task_Factory::create( |
90 | 90 | new Single_Call_Task( |
91 | - array( $ingredients_taxonomy_recipe_lift, 'run' ), |
|
91 | + array($ingredients_taxonomy_recipe_lift, 'run'), |
|
92 | 92 | 'sync-ingredients-taxonomy' |
93 | 93 | ), |
94 | 94 | '/sync-ingredients-taxonomy', |
95 | 95 | 'sync-ingredients-taxonomy', |
96 | - __( 'Synchronize Ingredients Taxonomy', 'wordlift' ) |
|
96 | + __('Synchronize Ingredients Taxonomy', 'wordlift') |
|
97 | 97 | ); |
98 | 98 | |
99 | - if ( is_admin() ) { |
|
100 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Page' ); |
|
99 | + if (is_admin()) { |
|
100 | + $page = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Page'); |
|
101 | 101 | $page->register_hooks(); |
102 | 102 | |
103 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Ingredients_Taxonomy_Page' ); |
|
103 | + $page = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Ingredients_Taxonomy_Page'); |
|
104 | 104 | $page->register_hooks(); |
105 | 105 | |
106 | 106 | // Download Ingredients Data. |
107 | - $download_ingredients_data = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data' ); |
|
107 | + $download_ingredients_data = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data'); |
|
108 | 108 | $download_ingredients_data->register_hooks(); |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | -add_action( 'plugins_loaded', '__wl_foodkg__load' ); |
|
112 | +add_action('plugins_loaded', '__wl_foodkg__load'); |
|
113 | 113 |
@@ -4,122 +4,122 @@ |
||
4 | 4 | |
5 | 5 | class Context { |
6 | 6 | |
7 | - private $count; |
|
8 | - private $offset; |
|
9 | - private $started; |
|
10 | - private $updated; |
|
11 | - |
|
12 | - /** |
|
13 | - * @param $count |
|
14 | - * @param $offset |
|
15 | - * @param $started |
|
16 | - * @param $updated |
|
17 | - */ |
|
18 | - public function __construct( $count, $offset, $started, $updated ) { |
|
19 | - $this->count = $count; |
|
20 | - $this->offset = $offset; |
|
21 | - $this->started = $started; |
|
22 | - $this->updated = $updated; |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @return int |
|
27 | - */ |
|
28 | - public function get_count() { |
|
29 | - return $this->count; |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * @param int $count |
|
34 | - * |
|
35 | - * @return Context |
|
36 | - */ |
|
37 | - public function set_count( $count ) { |
|
38 | - $this->count = $count; |
|
39 | - |
|
40 | - return $this; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @return int |
|
45 | - */ |
|
46 | - public function get_offset() { |
|
47 | - return $this->offset; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * @param int $offset |
|
52 | - * |
|
53 | - * @return Context |
|
54 | - */ |
|
55 | - public function set_offset( $offset ) { |
|
56 | - $this->offset = $offset; |
|
57 | - |
|
58 | - return $this; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @return int |
|
63 | - */ |
|
64 | - public function get_started() { |
|
65 | - return $this->started; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @param int $started |
|
70 | - * |
|
71 | - * @return Context |
|
72 | - */ |
|
73 | - public function set_started( $started ) { |
|
74 | - $this->started = $started; |
|
75 | - |
|
76 | - return $this; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @return int |
|
81 | - */ |
|
82 | - public function get_updated() { |
|
83 | - return $this->updated; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param int $updated |
|
88 | - * |
|
89 | - * @return Context |
|
90 | - */ |
|
91 | - public function set_updated( $updated ) { |
|
92 | - $this->updated = $updated; |
|
93 | - |
|
94 | - return $this; |
|
95 | - } |
|
96 | - |
|
97 | - public function get_data() { |
|
98 | - return array( |
|
99 | - 'count' => $this->count, |
|
100 | - 'updated' => $this->updated, |
|
101 | - 'started' => $this->started, |
|
102 | - 'offset' => $this->offset, |
|
103 | - 'index' => $this->offset, |
|
104 | - ); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param $count int |
|
109 | - * |
|
110 | - * @return Context |
|
111 | - */ |
|
112 | - public static function from( $count ) { |
|
113 | - return new self( $count, 0, time(), time() ); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * @param $data array |
|
118 | - * |
|
119 | - * @return Context |
|
120 | - */ |
|
121 | - public static function from_data( $data ) { |
|
122 | - return new self( $data['count'], $data['offset'], $data['started'], $data['updated'] ); |
|
123 | - } |
|
7 | + private $count; |
|
8 | + private $offset; |
|
9 | + private $started; |
|
10 | + private $updated; |
|
11 | + |
|
12 | + /** |
|
13 | + * @param $count |
|
14 | + * @param $offset |
|
15 | + * @param $started |
|
16 | + * @param $updated |
|
17 | + */ |
|
18 | + public function __construct( $count, $offset, $started, $updated ) { |
|
19 | + $this->count = $count; |
|
20 | + $this->offset = $offset; |
|
21 | + $this->started = $started; |
|
22 | + $this->updated = $updated; |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @return int |
|
27 | + */ |
|
28 | + public function get_count() { |
|
29 | + return $this->count; |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * @param int $count |
|
34 | + * |
|
35 | + * @return Context |
|
36 | + */ |
|
37 | + public function set_count( $count ) { |
|
38 | + $this->count = $count; |
|
39 | + |
|
40 | + return $this; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @return int |
|
45 | + */ |
|
46 | + public function get_offset() { |
|
47 | + return $this->offset; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * @param int $offset |
|
52 | + * |
|
53 | + * @return Context |
|
54 | + */ |
|
55 | + public function set_offset( $offset ) { |
|
56 | + $this->offset = $offset; |
|
57 | + |
|
58 | + return $this; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @return int |
|
63 | + */ |
|
64 | + public function get_started() { |
|
65 | + return $this->started; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @param int $started |
|
70 | + * |
|
71 | + * @return Context |
|
72 | + */ |
|
73 | + public function set_started( $started ) { |
|
74 | + $this->started = $started; |
|
75 | + |
|
76 | + return $this; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @return int |
|
81 | + */ |
|
82 | + public function get_updated() { |
|
83 | + return $this->updated; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param int $updated |
|
88 | + * |
|
89 | + * @return Context |
|
90 | + */ |
|
91 | + public function set_updated( $updated ) { |
|
92 | + $this->updated = $updated; |
|
93 | + |
|
94 | + return $this; |
|
95 | + } |
|
96 | + |
|
97 | + public function get_data() { |
|
98 | + return array( |
|
99 | + 'count' => $this->count, |
|
100 | + 'updated' => $this->updated, |
|
101 | + 'started' => $this->started, |
|
102 | + 'offset' => $this->offset, |
|
103 | + 'index' => $this->offset, |
|
104 | + ); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param $count int |
|
109 | + * |
|
110 | + * @return Context |
|
111 | + */ |
|
112 | + public static function from( $count ) { |
|
113 | + return new self( $count, 0, time(), time() ); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * @param $data array |
|
118 | + * |
|
119 | + * @return Context |
|
120 | + */ |
|
121 | + public static function from_data( $data ) { |
|
122 | + return new self( $data['count'], $data['offset'], $data['started'], $data['updated'] ); |
|
123 | + } |
|
124 | 124 | |
125 | 125 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * @param $started |
16 | 16 | * @param $updated |
17 | 17 | */ |
18 | - public function __construct( $count, $offset, $started, $updated ) { |
|
18 | + public function __construct($count, $offset, $started, $updated) { |
|
19 | 19 | $this->count = $count; |
20 | 20 | $this->offset = $offset; |
21 | 21 | $this->started = $started; |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @return Context |
36 | 36 | */ |
37 | - public function set_count( $count ) { |
|
37 | + public function set_count($count) { |
|
38 | 38 | $this->count = $count; |
39 | 39 | |
40 | 40 | return $this; |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return Context |
54 | 54 | */ |
55 | - public function set_offset( $offset ) { |
|
55 | + public function set_offset($offset) { |
|
56 | 56 | $this->offset = $offset; |
57 | 57 | |
58 | 58 | return $this; |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return Context |
72 | 72 | */ |
73 | - public function set_started( $started ) { |
|
73 | + public function set_started($started) { |
|
74 | 74 | $this->started = $started; |
75 | 75 | |
76 | 76 | return $this; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return Context |
90 | 90 | */ |
91 | - public function set_updated( $updated ) { |
|
91 | + public function set_updated($updated) { |
|
92 | 92 | $this->updated = $updated; |
93 | 93 | |
94 | 94 | return $this; |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @return Context |
111 | 111 | */ |
112 | - public static function from( $count ) { |
|
113 | - return new self( $count, 0, time(), time() ); |
|
112 | + public static function from($count) { |
|
113 | + return new self($count, 0, time(), time()); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @return Context |
120 | 120 | */ |
121 | - public static function from_data( $data ) { |
|
122 | - return new self( $data['count'], $data['offset'], $data['started'], $data['updated'] ); |
|
121 | + public static function from_data($data) { |
|
122 | + return new self($data['count'], $data['offset'], $data['started'], $data['updated']); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | } |
@@ -8,95 +8,95 @@ |
||
8 | 8 | |
9 | 9 | class Background_Task_Route { |
10 | 10 | |
11 | - const VERSION_STRING = 'wordlift/v1'; |
|
12 | - |
|
13 | - /** |
|
14 | - * @var Background_Route_Task |
|
15 | - */ |
|
16 | - private $background_task; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - private $route_name; |
|
22 | - |
|
23 | - public function __construct( $background_task, $route_name ) { |
|
24 | - $this->background_task = $background_task; |
|
25 | - $this->route_name = $route_name; |
|
26 | - } |
|
27 | - |
|
28 | - public static function create( $task, $route_name ) { |
|
29 | - $route = new self( $task, $route_name ); |
|
30 | - |
|
31 | - add_action( 'rest_api_init', array( $route, 'register' ) ); |
|
32 | - |
|
33 | - return $route; |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * @throws Exception if the input value is invalid. |
|
38 | - */ |
|
39 | - public function register() { |
|
40 | - Assertions::starts_with( $this->route_name, '/', 'The route name must start with a slash.' ); |
|
41 | - |
|
42 | - register_rest_route( |
|
43 | - self::VERSION_STRING, |
|
44 | - $this->route_name, |
|
45 | - array( |
|
46 | - 'methods' => WP_REST_Server::CREATABLE, |
|
47 | - 'callback' => function () { |
|
48 | - return $this->background_task->start(); |
|
49 | - }, |
|
50 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
51 | - ) |
|
52 | - ); |
|
53 | - |
|
54 | - register_rest_route( |
|
55 | - self::VERSION_STRING, |
|
56 | - $this->route_name, |
|
57 | - array( |
|
58 | - 'methods' => WP_REST_Server::READABLE, |
|
59 | - 'callback' => function () { |
|
60 | - return $this->background_task->get_info(); |
|
61 | - }, |
|
62 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
63 | - ) |
|
64 | - ); |
|
65 | - |
|
66 | - register_rest_route( |
|
67 | - self::VERSION_STRING, |
|
68 | - $this->route_name, |
|
69 | - array( |
|
70 | - 'methods' => WP_REST_Server::DELETABLE, |
|
71 | - 'callback' => function () { |
|
72 | - return $this->background_task->stop(); |
|
73 | - }, |
|
74 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
75 | - ) |
|
76 | - ); |
|
77 | - |
|
78 | - register_rest_route( |
|
79 | - self::VERSION_STRING, |
|
80 | - $this->route_name, |
|
81 | - array( |
|
82 | - 'methods' => 'PUT', |
|
83 | - 'callback' => function () { |
|
84 | - return $this->background_task->resume(); |
|
85 | - }, |
|
86 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
87 | - ) |
|
88 | - ); |
|
89 | - |
|
90 | - } |
|
91 | - |
|
92 | - public function permission_callback() { |
|
93 | - $user = wp_get_current_user(); |
|
94 | - |
|
95 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
96 | - } |
|
97 | - |
|
98 | - public function get_rest_path() { |
|
99 | - return self::VERSION_STRING . $this->route_name; |
|
100 | - } |
|
11 | + const VERSION_STRING = 'wordlift/v1'; |
|
12 | + |
|
13 | + /** |
|
14 | + * @var Background_Route_Task |
|
15 | + */ |
|
16 | + private $background_task; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + private $route_name; |
|
22 | + |
|
23 | + public function __construct( $background_task, $route_name ) { |
|
24 | + $this->background_task = $background_task; |
|
25 | + $this->route_name = $route_name; |
|
26 | + } |
|
27 | + |
|
28 | + public static function create( $task, $route_name ) { |
|
29 | + $route = new self( $task, $route_name ); |
|
30 | + |
|
31 | + add_action( 'rest_api_init', array( $route, 'register' ) ); |
|
32 | + |
|
33 | + return $route; |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * @throws Exception if the input value is invalid. |
|
38 | + */ |
|
39 | + public function register() { |
|
40 | + Assertions::starts_with( $this->route_name, '/', 'The route name must start with a slash.' ); |
|
41 | + |
|
42 | + register_rest_route( |
|
43 | + self::VERSION_STRING, |
|
44 | + $this->route_name, |
|
45 | + array( |
|
46 | + 'methods' => WP_REST_Server::CREATABLE, |
|
47 | + 'callback' => function () { |
|
48 | + return $this->background_task->start(); |
|
49 | + }, |
|
50 | + 'permission_callback' => array( $this, 'permission_callback' ), |
|
51 | + ) |
|
52 | + ); |
|
53 | + |
|
54 | + register_rest_route( |
|
55 | + self::VERSION_STRING, |
|
56 | + $this->route_name, |
|
57 | + array( |
|
58 | + 'methods' => WP_REST_Server::READABLE, |
|
59 | + 'callback' => function () { |
|
60 | + return $this->background_task->get_info(); |
|
61 | + }, |
|
62 | + 'permission_callback' => array( $this, 'permission_callback' ), |
|
63 | + ) |
|
64 | + ); |
|
65 | + |
|
66 | + register_rest_route( |
|
67 | + self::VERSION_STRING, |
|
68 | + $this->route_name, |
|
69 | + array( |
|
70 | + 'methods' => WP_REST_Server::DELETABLE, |
|
71 | + 'callback' => function () { |
|
72 | + return $this->background_task->stop(); |
|
73 | + }, |
|
74 | + 'permission_callback' => array( $this, 'permission_callback' ), |
|
75 | + ) |
|
76 | + ); |
|
77 | + |
|
78 | + register_rest_route( |
|
79 | + self::VERSION_STRING, |
|
80 | + $this->route_name, |
|
81 | + array( |
|
82 | + 'methods' => 'PUT', |
|
83 | + 'callback' => function () { |
|
84 | + return $this->background_task->resume(); |
|
85 | + }, |
|
86 | + 'permission_callback' => array( $this, 'permission_callback' ), |
|
87 | + ) |
|
88 | + ); |
|
89 | + |
|
90 | + } |
|
91 | + |
|
92 | + public function permission_callback() { |
|
93 | + $user = wp_get_current_user(); |
|
94 | + |
|
95 | + return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
96 | + } |
|
97 | + |
|
98 | + public function get_rest_path() { |
|
99 | + return self::VERSION_STRING . $this->route_name; |
|
100 | + } |
|
101 | 101 | |
102 | 102 | } |
@@ -20,15 +20,15 @@ discard block |
||
20 | 20 | */ |
21 | 21 | private $route_name; |
22 | 22 | |
23 | - public function __construct( $background_task, $route_name ) { |
|
23 | + public function __construct($background_task, $route_name) { |
|
24 | 24 | $this->background_task = $background_task; |
25 | 25 | $this->route_name = $route_name; |
26 | 26 | } |
27 | 27 | |
28 | - public static function create( $task, $route_name ) { |
|
29 | - $route = new self( $task, $route_name ); |
|
28 | + public static function create($task, $route_name) { |
|
29 | + $route = new self($task, $route_name); |
|
30 | 30 | |
31 | - add_action( 'rest_api_init', array( $route, 'register' ) ); |
|
31 | + add_action('rest_api_init', array($route, 'register')); |
|
32 | 32 | |
33 | 33 | return $route; |
34 | 34 | } |
@@ -37,17 +37,17 @@ discard block |
||
37 | 37 | * @throws Exception if the input value is invalid. |
38 | 38 | */ |
39 | 39 | public function register() { |
40 | - Assertions::starts_with( $this->route_name, '/', 'The route name must start with a slash.' ); |
|
40 | + Assertions::starts_with($this->route_name, '/', 'The route name must start with a slash.'); |
|
41 | 41 | |
42 | 42 | register_rest_route( |
43 | 43 | self::VERSION_STRING, |
44 | 44 | $this->route_name, |
45 | 45 | array( |
46 | 46 | 'methods' => WP_REST_Server::CREATABLE, |
47 | - 'callback' => function () { |
|
47 | + 'callback' => function() { |
|
48 | 48 | return $this->background_task->start(); |
49 | 49 | }, |
50 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
50 | + 'permission_callback' => array($this, 'permission_callback'), |
|
51 | 51 | ) |
52 | 52 | ); |
53 | 53 | |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | $this->route_name, |
57 | 57 | array( |
58 | 58 | 'methods' => WP_REST_Server::READABLE, |
59 | - 'callback' => function () { |
|
59 | + 'callback' => function() { |
|
60 | 60 | return $this->background_task->get_info(); |
61 | 61 | }, |
62 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
62 | + 'permission_callback' => array($this, 'permission_callback'), |
|
63 | 63 | ) |
64 | 64 | ); |
65 | 65 | |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | $this->route_name, |
69 | 69 | array( |
70 | 70 | 'methods' => WP_REST_Server::DELETABLE, |
71 | - 'callback' => function () { |
|
71 | + 'callback' => function() { |
|
72 | 72 | return $this->background_task->stop(); |
73 | 73 | }, |
74 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
74 | + 'permission_callback' => array($this, 'permission_callback'), |
|
75 | 75 | ) |
76 | 76 | ); |
77 | 77 | |
@@ -80,10 +80,10 @@ discard block |
||
80 | 80 | $this->route_name, |
81 | 81 | array( |
82 | 82 | 'methods' => 'PUT', |
83 | - 'callback' => function () { |
|
83 | + 'callback' => function() { |
|
84 | 84 | return $this->background_task->resume(); |
85 | 85 | }, |
86 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
86 | + 'permission_callback' => array($this, 'permission_callback'), |
|
87 | 87 | ) |
88 | 88 | ); |
89 | 89 | |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | public function permission_callback() { |
93 | 93 | $user = wp_get_current_user(); |
94 | 94 | |
95 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
95 | + return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | public function get_rest_path() { |
99 | - return self::VERSION_STRING . $this->route_name; |
|
99 | + return self::VERSION_STRING.$this->route_name; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | } |
@@ -7,119 +7,119 @@ |
||
7 | 7 | |
8 | 8 | class Background_Task extends Wordlift_Plugin_WP_Background_Process implements Background_Route_Task { |
9 | 9 | |
10 | - const STATE_STARTED = 'started'; |
|
11 | - const STATE_STOPPED = 'stopped'; |
|
12 | - |
|
13 | - /** |
|
14 | - * The current state of the task, started or stopped. |
|
15 | - * |
|
16 | - * @var Background_Task_State $state |
|
17 | - */ |
|
18 | - private $state; |
|
19 | - |
|
20 | - /** |
|
21 | - * The actual task. |
|
22 | - * |
|
23 | - * @var Task $task |
|
24 | - */ |
|
25 | - private $task; |
|
26 | - |
|
27 | - /** |
|
28 | - * The prefix to store the state and other information in WP's options table, determined at instantiation. |
|
29 | - * |
|
30 | - * @var string $option_prefix |
|
31 | - */ |
|
32 | - private $option_prefix; |
|
33 | - |
|
34 | - /** |
|
35 | - * @param Task $task |
|
36 | - */ |
|
37 | - public function __construct( $task ) { |
|
38 | - $this->action = $task->get_id(); |
|
39 | - $this->option_prefix = "_{$this->action}_"; |
|
40 | - |
|
41 | - parent::__construct(); |
|
42 | - |
|
43 | - // Set the current state. |
|
44 | - if ( self::STATE_STARTED === $this->get_state() ) { |
|
45 | - $this->state = new Background_Task_Started_State( $this, $task ); |
|
46 | - } else { |
|
47 | - $this->state = new Background_Task_Stopped_State( $this ); |
|
48 | - } |
|
49 | - |
|
50 | - $this->task = $task; |
|
51 | - } |
|
52 | - |
|
53 | - public static function create( $task ) { |
|
54 | - return new self( $task ); |
|
55 | - } |
|
56 | - |
|
57 | - public function get_option_prefix() { |
|
58 | - return $this->option_prefix; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * This function is called: |
|
63 | - * - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance. |
|
64 | - * - To synchronize a post, by passing a numeric ID. |
|
65 | - * |
|
66 | - * This function returns the parameter for the next call or NULL if there are no more posts to process. |
|
67 | - * |
|
68 | - * @param mixed $item Queue item to iterate over. |
|
69 | - * |
|
70 | - * @return int[]|false The next post IDs or false if there are no more. |
|
71 | - */ |
|
72 | - protected function task( $item ) { |
|
73 | - |
|
74 | - return $this->state->task( $item ); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Transition to the started state. |
|
79 | - */ |
|
80 | - public function start() { |
|
81 | - $this->state->leave(); |
|
82 | - $this->state = new Background_Task_Started_State( $this, $this->task ); |
|
83 | - $this->state->enter(); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Transition to the stopped state. |
|
88 | - */ |
|
89 | - public function stop() { |
|
90 | - $this->state->leave(); |
|
91 | - $this->state = new Background_Task_Stopped_State( $this ); |
|
92 | - $this->state->enter(); |
|
93 | - } |
|
94 | - |
|
95 | - public function resume() { |
|
96 | - $this->state->resume(); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Get the current state. |
|
101 | - * |
|
102 | - * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
|
103 | - */ |
|
104 | - public function get_state() { |
|
105 | - return get_option( $this->option_prefix . 'state', self::STATE_STOPPED ); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Persist the current state. |
|
110 | - * |
|
111 | - * @param string $value |
|
112 | - * |
|
113 | - * @return bool |
|
114 | - */ |
|
115 | - public function set_state( $value ) { |
|
116 | - return null === $value |
|
117 | - ? delete_option( $this->option_prefix . 'state' ) |
|
118 | - : update_option( $this->option_prefix . 'state', $value, true ); |
|
119 | - } |
|
120 | - |
|
121 | - public function get_info() { |
|
122 | - return $this->state->get_info(); |
|
123 | - } |
|
10 | + const STATE_STARTED = 'started'; |
|
11 | + const STATE_STOPPED = 'stopped'; |
|
12 | + |
|
13 | + /** |
|
14 | + * The current state of the task, started or stopped. |
|
15 | + * |
|
16 | + * @var Background_Task_State $state |
|
17 | + */ |
|
18 | + private $state; |
|
19 | + |
|
20 | + /** |
|
21 | + * The actual task. |
|
22 | + * |
|
23 | + * @var Task $task |
|
24 | + */ |
|
25 | + private $task; |
|
26 | + |
|
27 | + /** |
|
28 | + * The prefix to store the state and other information in WP's options table, determined at instantiation. |
|
29 | + * |
|
30 | + * @var string $option_prefix |
|
31 | + */ |
|
32 | + private $option_prefix; |
|
33 | + |
|
34 | + /** |
|
35 | + * @param Task $task |
|
36 | + */ |
|
37 | + public function __construct( $task ) { |
|
38 | + $this->action = $task->get_id(); |
|
39 | + $this->option_prefix = "_{$this->action}_"; |
|
40 | + |
|
41 | + parent::__construct(); |
|
42 | + |
|
43 | + // Set the current state. |
|
44 | + if ( self::STATE_STARTED === $this->get_state() ) { |
|
45 | + $this->state = new Background_Task_Started_State( $this, $task ); |
|
46 | + } else { |
|
47 | + $this->state = new Background_Task_Stopped_State( $this ); |
|
48 | + } |
|
49 | + |
|
50 | + $this->task = $task; |
|
51 | + } |
|
52 | + |
|
53 | + public static function create( $task ) { |
|
54 | + return new self( $task ); |
|
55 | + } |
|
56 | + |
|
57 | + public function get_option_prefix() { |
|
58 | + return $this->option_prefix; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * This function is called: |
|
63 | + * - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance. |
|
64 | + * - To synchronize a post, by passing a numeric ID. |
|
65 | + * |
|
66 | + * This function returns the parameter for the next call or NULL if there are no more posts to process. |
|
67 | + * |
|
68 | + * @param mixed $item Queue item to iterate over. |
|
69 | + * |
|
70 | + * @return int[]|false The next post IDs or false if there are no more. |
|
71 | + */ |
|
72 | + protected function task( $item ) { |
|
73 | + |
|
74 | + return $this->state->task( $item ); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Transition to the started state. |
|
79 | + */ |
|
80 | + public function start() { |
|
81 | + $this->state->leave(); |
|
82 | + $this->state = new Background_Task_Started_State( $this, $this->task ); |
|
83 | + $this->state->enter(); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Transition to the stopped state. |
|
88 | + */ |
|
89 | + public function stop() { |
|
90 | + $this->state->leave(); |
|
91 | + $this->state = new Background_Task_Stopped_State( $this ); |
|
92 | + $this->state->enter(); |
|
93 | + } |
|
94 | + |
|
95 | + public function resume() { |
|
96 | + $this->state->resume(); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Get the current state. |
|
101 | + * |
|
102 | + * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
|
103 | + */ |
|
104 | + public function get_state() { |
|
105 | + return get_option( $this->option_prefix . 'state', self::STATE_STOPPED ); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Persist the current state. |
|
110 | + * |
|
111 | + * @param string $value |
|
112 | + * |
|
113 | + * @return bool |
|
114 | + */ |
|
115 | + public function set_state( $value ) { |
|
116 | + return null === $value |
|
117 | + ? delete_option( $this->option_prefix . 'state' ) |
|
118 | + : update_option( $this->option_prefix . 'state', $value, true ); |
|
119 | + } |
|
120 | + |
|
121 | + public function get_info() { |
|
122 | + return $this->state->get_info(); |
|
123 | + } |
|
124 | 124 | |
125 | 125 | } |
@@ -3,18 +3,18 @@ |
||
3 | 3 | namespace Wordlift\Task\Background; |
4 | 4 | |
5 | 5 | interface Background_Route_Task { |
6 | - /** |
|
7 | - * Transition to the started state. |
|
8 | - */ |
|
9 | - public function start(); |
|
6 | + /** |
|
7 | + * Transition to the started state. |
|
8 | + */ |
|
9 | + public function start(); |
|
10 | 10 | |
11 | - /** |
|
12 | - * Transition to the stopped state. |
|
13 | - */ |
|
14 | - public function stop(); |
|
11 | + /** |
|
12 | + * Transition to the stopped state. |
|
13 | + */ |
|
14 | + public function stop(); |
|
15 | 15 | |
16 | - public function resume(); |
|
16 | + public function resume(); |
|
17 | 17 | |
18 | - public function get_info(); |
|
18 | + public function get_info(); |
|
19 | 19 | |
20 | 20 | } |
@@ -14,58 +14,58 @@ |
||
14 | 14 | */ |
15 | 15 | class Background_Task_Factory { |
16 | 16 | |
17 | - /** |
|
18 | - * Create a {@link Background_Task} given the provided task and route. |
|
19 | - * |
|
20 | - * @param Task $task The target task. |
|
21 | - * @param string $route The route name. |
|
22 | - * @param string $page_id The page id. |
|
23 | - * @param string $page_title The page title. |
|
24 | - * |
|
25 | - * @return void |
|
26 | - * @throws Exception in case of invalid arguments. |
|
27 | - */ |
|
28 | - public static function create( $task, $route, $page_id, $page_title ) { |
|
29 | - self::assertions( $task, $route ); |
|
30 | - $background_task = Background_Task::create( $task ); |
|
31 | - $background_task_route = Background_Task_Route::create( $background_task, $route ); |
|
32 | - Background_Task_Page::create( $page_title, $page_id, $background_task_route ); |
|
33 | - } |
|
17 | + /** |
|
18 | + * Create a {@link Background_Task} given the provided task and route. |
|
19 | + * |
|
20 | + * @param Task $task The target task. |
|
21 | + * @param string $route The route name. |
|
22 | + * @param string $page_id The page id. |
|
23 | + * @param string $page_title The page title. |
|
24 | + * |
|
25 | + * @return void |
|
26 | + * @throws Exception in case of invalid arguments. |
|
27 | + */ |
|
28 | + public static function create( $task, $route, $page_id, $page_title ) { |
|
29 | + self::assertions( $task, $route ); |
|
30 | + $background_task = Background_Task::create( $task ); |
|
31 | + $background_task_route = Background_Task_Route::create( $background_task, $route ); |
|
32 | + Background_Task_Page::create( $page_title, $page_id, $background_task_route ); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Create a {@link Background_Task} given the provided task and route. |
|
37 | - * |
|
38 | - * @param Task $task The target task. |
|
39 | - * @param string $route The route name. |
|
40 | - * @param string $page_id The page id. |
|
41 | - * @param string $page_title The page title. |
|
42 | - * |
|
43 | - * @return void |
|
44 | - * @throws Exception in case of invalid arguments. |
|
45 | - */ |
|
46 | - public static function create_action_scheduler_task( $hook, $group, $task, $route, $page_id, $page_title, $batch_size = 5 ) { |
|
47 | - self::assertions( $task, $route ); |
|
48 | - $background_task = new \Wordlift\Task\Action_Scheduler\Background_Task( |
|
49 | - $hook, |
|
50 | - $group, |
|
51 | - $task, |
|
52 | - "_{$hook}_", |
|
53 | - $batch_size |
|
54 | - ); |
|
55 | - $background_task_route = Background_Task_Route::create( $background_task, $route ); |
|
56 | - Background_Task_Page::create( $page_title, $page_id, $background_task_route ); |
|
57 | - } |
|
35 | + /** |
|
36 | + * Create a {@link Background_Task} given the provided task and route. |
|
37 | + * |
|
38 | + * @param Task $task The target task. |
|
39 | + * @param string $route The route name. |
|
40 | + * @param string $page_id The page id. |
|
41 | + * @param string $page_title The page title. |
|
42 | + * |
|
43 | + * @return void |
|
44 | + * @throws Exception in case of invalid arguments. |
|
45 | + */ |
|
46 | + public static function create_action_scheduler_task( $hook, $group, $task, $route, $page_id, $page_title, $batch_size = 5 ) { |
|
47 | + self::assertions( $task, $route ); |
|
48 | + $background_task = new \Wordlift\Task\Action_Scheduler\Background_Task( |
|
49 | + $hook, |
|
50 | + $group, |
|
51 | + $task, |
|
52 | + "_{$hook}_", |
|
53 | + $batch_size |
|
54 | + ); |
|
55 | + $background_task_route = Background_Task_Route::create( $background_task, $route ); |
|
56 | + Background_Task_Page::create( $page_title, $page_id, $background_task_route ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @param Task $task |
|
61 | - * @param $route |
|
62 | - * |
|
63 | - * @return void |
|
64 | - * @throws Exception in case of invalid arguments. |
|
65 | - */ |
|
66 | - private static function assertions( Task $task, $route ) { |
|
67 | - Assertions::is_a( $task, 'Wordlift\Task\Task' ); |
|
68 | - Assertions::starts_with( $route, '/', __( 'The route must start with a slash.', 'wordlift' ) ); |
|
69 | - } |
|
59 | + /** |
|
60 | + * @param Task $task |
|
61 | + * @param $route |
|
62 | + * |
|
63 | + * @return void |
|
64 | + * @throws Exception in case of invalid arguments. |
|
65 | + */ |
|
66 | + private static function assertions( Task $task, $route ) { |
|
67 | + Assertions::is_a( $task, 'Wordlift\Task\Task' ); |
|
68 | + Assertions::starts_with( $route, '/', __( 'The route must start with a slash.', 'wordlift' ) ); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | } |
@@ -25,11 +25,11 @@ discard block |
||
25 | 25 | * @return void |
26 | 26 | * @throws Exception in case of invalid arguments. |
27 | 27 | */ |
28 | - public static function create( $task, $route, $page_id, $page_title ) { |
|
29 | - self::assertions( $task, $route ); |
|
30 | - $background_task = Background_Task::create( $task ); |
|
31 | - $background_task_route = Background_Task_Route::create( $background_task, $route ); |
|
32 | - Background_Task_Page::create( $page_title, $page_id, $background_task_route ); |
|
28 | + public static function create($task, $route, $page_id, $page_title) { |
|
29 | + self::assertions($task, $route); |
|
30 | + $background_task = Background_Task::create($task); |
|
31 | + $background_task_route = Background_Task_Route::create($background_task, $route); |
|
32 | + Background_Task_Page::create($page_title, $page_id, $background_task_route); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -43,17 +43,17 @@ discard block |
||
43 | 43 | * @return void |
44 | 44 | * @throws Exception in case of invalid arguments. |
45 | 45 | */ |
46 | - public static function create_action_scheduler_task( $hook, $group, $task, $route, $page_id, $page_title, $batch_size = 5 ) { |
|
47 | - self::assertions( $task, $route ); |
|
48 | - $background_task = new \Wordlift\Task\Action_Scheduler\Background_Task( |
|
46 | + public static function create_action_scheduler_task($hook, $group, $task, $route, $page_id, $page_title, $batch_size = 5) { |
|
47 | + self::assertions($task, $route); |
|
48 | + $background_task = new \Wordlift\Task\Action_Scheduler\Background_Task( |
|
49 | 49 | $hook, |
50 | 50 | $group, |
51 | 51 | $task, |
52 | 52 | "_{$hook}_", |
53 | 53 | $batch_size |
54 | 54 | ); |
55 | - $background_task_route = Background_Task_Route::create( $background_task, $route ); |
|
56 | - Background_Task_Page::create( $page_title, $page_id, $background_task_route ); |
|
55 | + $background_task_route = Background_Task_Route::create($background_task, $route); |
|
56 | + Background_Task_Page::create($page_title, $page_id, $background_task_route); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | * @return void |
64 | 64 | * @throws Exception in case of invalid arguments. |
65 | 65 | */ |
66 | - private static function assertions( Task $task, $route ) { |
|
67 | - Assertions::is_a( $task, 'Wordlift\Task\Task' ); |
|
68 | - Assertions::starts_with( $route, '/', __( 'The route must start with a slash.', 'wordlift' ) ); |
|
66 | + private static function assertions(Task $task, $route) { |
|
67 | + Assertions::is_a($task, 'Wordlift\Task\Task'); |
|
68 | + Assertions::starts_with($route, '/', __('The route must start with a slash.', 'wordlift')); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | } |
@@ -8,101 +8,101 @@ |
||
8 | 8 | use Wordlift\Task\Task; |
9 | 9 | |
10 | 10 | class Background_Task extends Action_Scheduler_Background_Process implements Background_Route_Task { |
11 | - /** |
|
12 | - * The option prefix to store state. |
|
13 | - * |
|
14 | - * @var string $option_prefix |
|
15 | - */ |
|
16 | - private $option_prefix; |
|
17 | - /** |
|
18 | - * @var Task |
|
19 | - */ |
|
20 | - private $task; |
|
21 | - |
|
22 | - const STATE_STARTED = 'started'; |
|
23 | - const STATE_STOPPED = 'stopped'; |
|
24 | - /** |
|
25 | - * @var int |
|
26 | - */ |
|
27 | - private $batch_size; |
|
28 | - |
|
29 | - public function __construct( $hook, $group, $task, $option_prefix, $batch_size = 5 ) { |
|
30 | - parent::__construct( $hook, $group ); |
|
31 | - $this->task = $task; |
|
32 | - $this->option_prefix = $option_prefix; |
|
33 | - $this->batch_size = $batch_size; |
|
34 | - } |
|
35 | - |
|
36 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
37 | - public function do_task( $args ) { |
|
38 | - if ( self::STATE_STOPPED === $this->get_process_state() ) { |
|
39 | - return State::complete(); |
|
40 | - } |
|
41 | - $context = $this->get_context(); |
|
42 | - $this->task->tick( null, $context->get_data() + array( 'batch_size' => $this->batch_size ) ); |
|
43 | - |
|
44 | - if ( ( $context->get_count() - $context->get_offset() ) >= 0 ) { |
|
45 | - $context->set_offset( $context->get_offset() + $this->batch_size )->set_updated( time() ); |
|
46 | - $this->set_info( $context ); |
|
47 | - return State::items_in_queue(); |
|
48 | - } else { |
|
49 | - $this->set_process_state( self::STATE_STOPPED ); |
|
50 | - return State::complete(); |
|
51 | - } |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - public function start() { |
|
56 | - $this->delete_info(); |
|
57 | - $this->set_process_state( self::STATE_STARTED ); |
|
58 | - $this->schedule(); |
|
59 | - } |
|
60 | - |
|
61 | - public function stop() { |
|
62 | - $this->set_process_state( self::STATE_STOPPED ); |
|
63 | - $this->unschedule(); |
|
64 | - } |
|
65 | - |
|
66 | - public function resume() { |
|
67 | - $this->set_process_state( self::STATE_STARTED ); |
|
68 | - $this->schedule(); |
|
69 | - } |
|
70 | - |
|
71 | - public function get_info() { |
|
72 | - return $this->get_context()->get_data() + array( 'state' => $this->get_process_state() ); |
|
73 | - } |
|
74 | - |
|
75 | - public function get_context() { |
|
76 | - $data = get_option( |
|
77 | - "{$this->option_prefix}_state", |
|
78 | - null |
|
79 | - ); |
|
80 | - |
|
81 | - if ( null === $data ) { |
|
82 | - return Context::from( (int) $this->task->starting() ); |
|
83 | - } |
|
84 | - |
|
85 | - return Context::from_data( $data ); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @param $context Context |
|
90 | - * |
|
91 | - * @return void |
|
92 | - */ |
|
93 | - public function set_info( $context ) { |
|
94 | - update_option( "{$this->option_prefix}_state", $context->get_data() ); |
|
95 | - } |
|
96 | - |
|
97 | - private function delete_info() { |
|
98 | - delete_option( "{$this->option_prefix}_state" ); |
|
99 | - } |
|
100 | - |
|
101 | - private function get_process_state() { |
|
102 | - return get_option( "{$this->option_prefix}_action_scheduler_state", self::STATE_STOPPED ); |
|
103 | - } |
|
104 | - |
|
105 | - private function set_process_state( $state ) { |
|
106 | - update_option( "{$this->option_prefix}_action_scheduler_state", $state ); |
|
107 | - } |
|
11 | + /** |
|
12 | + * The option prefix to store state. |
|
13 | + * |
|
14 | + * @var string $option_prefix |
|
15 | + */ |
|
16 | + private $option_prefix; |
|
17 | + /** |
|
18 | + * @var Task |
|
19 | + */ |
|
20 | + private $task; |
|
21 | + |
|
22 | + const STATE_STARTED = 'started'; |
|
23 | + const STATE_STOPPED = 'stopped'; |
|
24 | + /** |
|
25 | + * @var int |
|
26 | + */ |
|
27 | + private $batch_size; |
|
28 | + |
|
29 | + public function __construct( $hook, $group, $task, $option_prefix, $batch_size = 5 ) { |
|
30 | + parent::__construct( $hook, $group ); |
|
31 | + $this->task = $task; |
|
32 | + $this->option_prefix = $option_prefix; |
|
33 | + $this->batch_size = $batch_size; |
|
34 | + } |
|
35 | + |
|
36 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
37 | + public function do_task( $args ) { |
|
38 | + if ( self::STATE_STOPPED === $this->get_process_state() ) { |
|
39 | + return State::complete(); |
|
40 | + } |
|
41 | + $context = $this->get_context(); |
|
42 | + $this->task->tick( null, $context->get_data() + array( 'batch_size' => $this->batch_size ) ); |
|
43 | + |
|
44 | + if ( ( $context->get_count() - $context->get_offset() ) >= 0 ) { |
|
45 | + $context->set_offset( $context->get_offset() + $this->batch_size )->set_updated( time() ); |
|
46 | + $this->set_info( $context ); |
|
47 | + return State::items_in_queue(); |
|
48 | + } else { |
|
49 | + $this->set_process_state( self::STATE_STOPPED ); |
|
50 | + return State::complete(); |
|
51 | + } |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + public function start() { |
|
56 | + $this->delete_info(); |
|
57 | + $this->set_process_state( self::STATE_STARTED ); |
|
58 | + $this->schedule(); |
|
59 | + } |
|
60 | + |
|
61 | + public function stop() { |
|
62 | + $this->set_process_state( self::STATE_STOPPED ); |
|
63 | + $this->unschedule(); |
|
64 | + } |
|
65 | + |
|
66 | + public function resume() { |
|
67 | + $this->set_process_state( self::STATE_STARTED ); |
|
68 | + $this->schedule(); |
|
69 | + } |
|
70 | + |
|
71 | + public function get_info() { |
|
72 | + return $this->get_context()->get_data() + array( 'state' => $this->get_process_state() ); |
|
73 | + } |
|
74 | + |
|
75 | + public function get_context() { |
|
76 | + $data = get_option( |
|
77 | + "{$this->option_prefix}_state", |
|
78 | + null |
|
79 | + ); |
|
80 | + |
|
81 | + if ( null === $data ) { |
|
82 | + return Context::from( (int) $this->task->starting() ); |
|
83 | + } |
|
84 | + |
|
85 | + return Context::from_data( $data ); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @param $context Context |
|
90 | + * |
|
91 | + * @return void |
|
92 | + */ |
|
93 | + public function set_info( $context ) { |
|
94 | + update_option( "{$this->option_prefix}_state", $context->get_data() ); |
|
95 | + } |
|
96 | + |
|
97 | + private function delete_info() { |
|
98 | + delete_option( "{$this->option_prefix}_state" ); |
|
99 | + } |
|
100 | + |
|
101 | + private function get_process_state() { |
|
102 | + return get_option( "{$this->option_prefix}_action_scheduler_state", self::STATE_STOPPED ); |
|
103 | + } |
|
104 | + |
|
105 | + private function set_process_state( $state ) { |
|
106 | + update_option( "{$this->option_prefix}_action_scheduler_state", $state ); |
|
107 | + } |
|
108 | 108 | } |
@@ -26,27 +26,27 @@ discard block |
||
26 | 26 | */ |
27 | 27 | private $batch_size; |
28 | 28 | |
29 | - public function __construct( $hook, $group, $task, $option_prefix, $batch_size = 5 ) { |
|
30 | - parent::__construct( $hook, $group ); |
|
29 | + public function __construct($hook, $group, $task, $option_prefix, $batch_size = 5) { |
|
30 | + parent::__construct($hook, $group); |
|
31 | 31 | $this->task = $task; |
32 | 32 | $this->option_prefix = $option_prefix; |
33 | 33 | $this->batch_size = $batch_size; |
34 | 34 | } |
35 | 35 | |
36 | 36 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
37 | - public function do_task( $args ) { |
|
38 | - if ( self::STATE_STOPPED === $this->get_process_state() ) { |
|
37 | + public function do_task($args) { |
|
38 | + if (self::STATE_STOPPED === $this->get_process_state()) { |
|
39 | 39 | return State::complete(); |
40 | 40 | } |
41 | 41 | $context = $this->get_context(); |
42 | - $this->task->tick( null, $context->get_data() + array( 'batch_size' => $this->batch_size ) ); |
|
42 | + $this->task->tick(null, $context->get_data() + array('batch_size' => $this->batch_size)); |
|
43 | 43 | |
44 | - if ( ( $context->get_count() - $context->get_offset() ) >= 0 ) { |
|
45 | - $context->set_offset( $context->get_offset() + $this->batch_size )->set_updated( time() ); |
|
46 | - $this->set_info( $context ); |
|
44 | + if (($context->get_count() - $context->get_offset()) >= 0) { |
|
45 | + $context->set_offset($context->get_offset() + $this->batch_size)->set_updated(time()); |
|
46 | + $this->set_info($context); |
|
47 | 47 | return State::items_in_queue(); |
48 | 48 | } else { |
49 | - $this->set_process_state( self::STATE_STOPPED ); |
|
49 | + $this->set_process_state(self::STATE_STOPPED); |
|
50 | 50 | return State::complete(); |
51 | 51 | } |
52 | 52 | |
@@ -54,22 +54,22 @@ discard block |
||
54 | 54 | |
55 | 55 | public function start() { |
56 | 56 | $this->delete_info(); |
57 | - $this->set_process_state( self::STATE_STARTED ); |
|
57 | + $this->set_process_state(self::STATE_STARTED); |
|
58 | 58 | $this->schedule(); |
59 | 59 | } |
60 | 60 | |
61 | 61 | public function stop() { |
62 | - $this->set_process_state( self::STATE_STOPPED ); |
|
62 | + $this->set_process_state(self::STATE_STOPPED); |
|
63 | 63 | $this->unschedule(); |
64 | 64 | } |
65 | 65 | |
66 | 66 | public function resume() { |
67 | - $this->set_process_state( self::STATE_STARTED ); |
|
67 | + $this->set_process_state(self::STATE_STARTED); |
|
68 | 68 | $this->schedule(); |
69 | 69 | } |
70 | 70 | |
71 | 71 | public function get_info() { |
72 | - return $this->get_context()->get_data() + array( 'state' => $this->get_process_state() ); |
|
72 | + return $this->get_context()->get_data() + array('state' => $this->get_process_state()); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | public function get_context() { |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | null |
79 | 79 | ); |
80 | 80 | |
81 | - if ( null === $data ) { |
|
82 | - return Context::from( (int) $this->task->starting() ); |
|
81 | + if (null === $data) { |
|
82 | + return Context::from((int) $this->task->starting()); |
|
83 | 83 | } |
84 | 84 | |
85 | - return Context::from_data( $data ); |
|
85 | + return Context::from_data($data); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -90,19 +90,19 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @return void |
92 | 92 | */ |
93 | - public function set_info( $context ) { |
|
94 | - update_option( "{$this->option_prefix}_state", $context->get_data() ); |
|
93 | + public function set_info($context) { |
|
94 | + update_option("{$this->option_prefix}_state", $context->get_data()); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | private function delete_info() { |
98 | - delete_option( "{$this->option_prefix}_state" ); |
|
98 | + delete_option("{$this->option_prefix}_state"); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | private function get_process_state() { |
102 | - return get_option( "{$this->option_prefix}_action_scheduler_state", self::STATE_STOPPED ); |
|
102 | + return get_option("{$this->option_prefix}_action_scheduler_state", self::STATE_STOPPED); |
|
103 | 103 | } |
104 | 104 | |
105 | - private function set_process_state( $state ) { |
|
106 | - update_option( "{$this->option_prefix}_action_scheduler_state", $state ); |
|
105 | + private function set_process_state($state) { |
|
106 | + update_option("{$this->option_prefix}_action_scheduler_state", $state); |
|
107 | 107 | } |
108 | 108 | } |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | use Wordlift\Post\Post_Adapter; |
33 | 33 | // If this file is called directly, abort. |
34 | 34 | if ( ! defined( 'WPINC' ) ) { |
35 | - die; |
|
35 | + die; |
|
36 | 36 | } |
37 | 37 | define( |
38 | - 'WORDLIFT_PLUGIN_FILE', |
|
39 | - __FILE__ |
|
38 | + 'WORDLIFT_PLUGIN_FILE', |
|
39 | + __FILE__ |
|
40 | 40 | ); |
41 | 41 | define( 'WORDLIFT_VERSION', '3.40.5' ); |
42 | 42 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @since 3.33.6 |
51 | 51 | */ |
52 | 52 | if ( ! apply_filters( 'wl_is_enabled', true ) ) { |
53 | - return; |
|
53 | + return; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
@@ -79,33 +79,33 @@ discard block |
||
79 | 79 | */ |
80 | 80 | function activate_wordlift() { |
81 | 81 | |
82 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
82 | + $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
83 | 83 | |
84 | - $log->info( 'Activating WordLift...' ); |
|
84 | + $log->info( 'Activating WordLift...' ); |
|
85 | 85 | |
86 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
87 | - Wordlift_Activator::activate(); |
|
86 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
87 | + Wordlift_Activator::activate(); |
|
88 | 88 | |
89 | - /** |
|
90 | - * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
91 | - * |
|
92 | - * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
93 | - * @since 3.19.2 |
|
94 | - */ |
|
95 | - Wordlift_Http_Api::activate(); |
|
96 | - |
|
97 | - // Ensure the post type is registered before flushing the rewrite rules. |
|
98 | - Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
99 | - flush_rewrite_rules(); |
|
100 | - /** |
|
101 | - * @since 3.27.7 |
|
102 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
103 | - */ |
|
104 | - Top_Entities::activate(); |
|
89 | + /** |
|
90 | + * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
91 | + * |
|
92 | + * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
93 | + * @since 3.19.2 |
|
94 | + */ |
|
95 | + Wordlift_Http_Api::activate(); |
|
96 | + |
|
97 | + // Ensure the post type is registered before flushing the rewrite rules. |
|
98 | + Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
99 | + flush_rewrite_rules(); |
|
100 | + /** |
|
101 | + * @since 3.27.7 |
|
102 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
103 | + */ |
|
104 | + Top_Entities::activate(); |
|
105 | 105 | |
106 | - if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) { |
|
107 | - wp_schedule_event( time(), 'daily', 'wl_daily_cron' ); |
|
108 | - } |
|
106 | + if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) { |
|
107 | + wp_schedule_event( time(), 'daily', 'wl_daily_cron' ); |
|
108 | + } |
|
109 | 109 | |
110 | 110 | } |
111 | 111 | |
@@ -115,23 +115,23 @@ discard block |
||
115 | 115 | */ |
116 | 116 | function deactivate_wordlift() { |
117 | 117 | |
118 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
119 | - Wordlift_Deactivator::deactivate(); |
|
120 | - Wordlift_Http_Api::deactivate(); |
|
121 | - Ttl_Cache_Cleaner::deactivate(); |
|
122 | - /** |
|
123 | - * @since 3.27.7 |
|
124 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
125 | - */ |
|
126 | - Top_Entities::deactivate(); |
|
127 | - /** |
|
128 | - * @since 3.27.8 |
|
129 | - * Remove notification flag on deactivation. |
|
130 | - */ |
|
131 | - Key_Validation_Notice::remove_notification_flag(); |
|
132 | - flush_rewrite_rules(); |
|
133 | - |
|
134 | - wp_clear_scheduled_hook( 'wl_daily_cron' ); |
|
118 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
119 | + Wordlift_Deactivator::deactivate(); |
|
120 | + Wordlift_Http_Api::deactivate(); |
|
121 | + Ttl_Cache_Cleaner::deactivate(); |
|
122 | + /** |
|
123 | + * @since 3.27.7 |
|
124 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
125 | + */ |
|
126 | + Top_Entities::deactivate(); |
|
127 | + /** |
|
128 | + * @since 3.27.8 |
|
129 | + * Remove notification flag on deactivation. |
|
130 | + */ |
|
131 | + Key_Validation_Notice::remove_notification_flag(); |
|
132 | + flush_rewrite_rules(); |
|
133 | + |
|
134 | + wp_clear_scheduled_hook( 'wl_daily_cron' ); |
|
135 | 135 | |
136 | 136 | } |
137 | 137 | |
@@ -154,84 +154,84 @@ discard block |
||
154 | 154 | * @since 1.0.0 |
155 | 155 | */ |
156 | 156 | function run_wordlift() { |
157 | - /** |
|
158 | - * Filter: wl_feature__enable__widgets. |
|
159 | - * |
|
160 | - * @param bool whether the widgets needed to be registered, defaults to true. |
|
161 | - * |
|
162 | - * @return bool |
|
163 | - * @since 3.27.6 |
|
164 | - */ |
|
165 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
166 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
167 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
168 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
169 | - } |
|
170 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
171 | - |
|
172 | - /** |
|
173 | - * Filter: wl_feature__enable__analysis |
|
174 | - * |
|
175 | - * @param bool Whether to send api request to analysis or not |
|
176 | - * |
|
177 | - * @return bool |
|
178 | - * @since 3.27.6 |
|
179 | - */ |
|
180 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
181 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
182 | - } else { |
|
183 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
184 | - } |
|
185 | - |
|
186 | - $plugin = new Wordlift(); |
|
187 | - $plugin->run(); |
|
188 | - |
|
189 | - // Initialize the TTL Cache Cleaner. |
|
190 | - new Ttl_Cache_Cleaner(); |
|
191 | - |
|
192 | - // Load the new Post Adapter. |
|
193 | - new Post_Adapter(); |
|
194 | - |
|
195 | - // Load the API Data Hooks. |
|
196 | - new Api_Data_Hooks(); |
|
197 | - |
|
198 | - add_action( |
|
199 | - 'plugins_loaded', |
|
200 | - function () { |
|
201 | - // All features from registry should be initialized here. |
|
202 | - $features_registry = Features_Registry::get_instance(); |
|
203 | - $features_registry->initialize_all_features(); |
|
204 | - }, |
|
205 | - 5 |
|
206 | - ); |
|
207 | - |
|
208 | - add_action( |
|
209 | - 'plugins_loaded', |
|
210 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
211 | - function () use ( $plugin ) { |
|
212 | - |
|
213 | - new Wordlift_Products_Navigator_Shortcode_REST(); |
|
214 | - |
|
215 | - // Register the Dataset module, requires `$api_service`. |
|
216 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
217 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
218 | - |
|
219 | - /* |
|
157 | + /** |
|
158 | + * Filter: wl_feature__enable__widgets. |
|
159 | + * |
|
160 | + * @param bool whether the widgets needed to be registered, defaults to true. |
|
161 | + * |
|
162 | + * @return bool |
|
163 | + * @since 3.27.6 |
|
164 | + */ |
|
165 | + if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
166 | + add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
167 | + add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
168 | + add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
169 | + } |
|
170 | + add_filter( 'widget_text', 'do_shortcode' ); |
|
171 | + |
|
172 | + /** |
|
173 | + * Filter: wl_feature__enable__analysis |
|
174 | + * |
|
175 | + * @param bool Whether to send api request to analysis or not |
|
176 | + * |
|
177 | + * @return bool |
|
178 | + * @since 3.27.6 |
|
179 | + */ |
|
180 | + if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
181 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
182 | + } else { |
|
183 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
184 | + } |
|
185 | + |
|
186 | + $plugin = new Wordlift(); |
|
187 | + $plugin->run(); |
|
188 | + |
|
189 | + // Initialize the TTL Cache Cleaner. |
|
190 | + new Ttl_Cache_Cleaner(); |
|
191 | + |
|
192 | + // Load the new Post Adapter. |
|
193 | + new Post_Adapter(); |
|
194 | + |
|
195 | + // Load the API Data Hooks. |
|
196 | + new Api_Data_Hooks(); |
|
197 | + |
|
198 | + add_action( |
|
199 | + 'plugins_loaded', |
|
200 | + function () { |
|
201 | + // All features from registry should be initialized here. |
|
202 | + $features_registry = Features_Registry::get_instance(); |
|
203 | + $features_registry->initialize_all_features(); |
|
204 | + }, |
|
205 | + 5 |
|
206 | + ); |
|
207 | + |
|
208 | + add_action( |
|
209 | + 'plugins_loaded', |
|
210 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
211 | + function () use ( $plugin ) { |
|
212 | + |
|
213 | + new Wordlift_Products_Navigator_Shortcode_REST(); |
|
214 | + |
|
215 | + // Register the Dataset module, requires `$api_service`. |
|
216 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
217 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
218 | + |
|
219 | + /* |
|
220 | 220 | * Require the Entity annotation cleanup module. |
221 | 221 | * |
222 | 222 | * @since 3.34.6 |
223 | 223 | */ |
224 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php'; |
|
224 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php'; |
|
225 | 225 | |
226 | - /* |
|
226 | + /* |
|
227 | 227 | * Import LOD entities. |
228 | 228 | * |
229 | 229 | * @since 3.35.0 |
230 | 230 | */ |
231 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php'; |
|
231 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php'; |
|
232 | 232 | |
233 | - } |
|
234 | - ); |
|
233 | + } |
|
234 | + ); |
|
235 | 235 | |
236 | 236 | } |
237 | 237 | |
@@ -245,45 +245,45 @@ discard block |
||
245 | 245 | */ |
246 | 246 | function wordlift_plugin_autoload_register() { |
247 | 247 | |
248 | - spl_autoload_register( |
|
249 | - function ( $class_name ) { |
|
248 | + spl_autoload_register( |
|
249 | + function ( $class_name ) { |
|
250 | 250 | |
251 | - // Bail out if these are not our classes. |
|
252 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
253 | - return false; |
|
254 | - } |
|
251 | + // Bail out if these are not our classes. |
|
252 | + if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
253 | + return false; |
|
254 | + } |
|
255 | 255 | |
256 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
256 | + $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
257 | 257 | |
258 | - preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
258 | + preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
259 | 259 | |
260 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
261 | - $file = 'class-' . $matches[2] . '.php'; |
|
260 | + $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
261 | + $file = 'class-' . $matches[2] . '.php'; |
|
262 | 262 | |
263 | - $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
263 | + $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
264 | 264 | |
265 | - if ( ! file_exists( $full_path ) ) { |
|
266 | - return false; |
|
267 | - } |
|
265 | + if ( ! file_exists( $full_path ) ) { |
|
266 | + return false; |
|
267 | + } |
|
268 | 268 | |
269 | - require_once $full_path; |
|
269 | + require_once $full_path; |
|
270 | 270 | |
271 | - return true; |
|
272 | - } |
|
273 | - ); |
|
271 | + return true; |
|
272 | + } |
|
273 | + ); |
|
274 | 274 | |
275 | 275 | } |
276 | 276 | |
277 | 277 | function wl_block_categories( $categories ) { |
278 | - return array_merge( |
|
279 | - $categories, |
|
280 | - array( |
|
281 | - array( |
|
282 | - 'slug' => 'wordlift', |
|
283 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
284 | - ), |
|
285 | - ) |
|
286 | - ); |
|
278 | + return array_merge( |
|
279 | + $categories, |
|
280 | + array( |
|
281 | + array( |
|
282 | + 'slug' => 'wordlift', |
|
283 | + 'title' => __( 'WordLift', 'wordlift' ), |
|
284 | + ), |
|
285 | + ) |
|
286 | + ); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -291,19 +291,19 @@ discard block |
||
291 | 291 | * this has to be removed when removing the legacy fields from the ui. |
292 | 292 | */ |
293 | 293 | function wl_enqueue_leaflet( $in_footer = false ) { |
294 | - // Leaflet. |
|
295 | - wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
296 | - wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
294 | + // Leaflet. |
|
295 | + wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
296 | + wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | add_filter( 'block_categories', 'wl_block_categories', 10 ); |
300 | 300 | |
301 | 301 | // Temporary fix for a typo in WooCommerce Extension. |
302 | 302 | add_filter( |
303 | - 'wl_feature__enable__dataset', |
|
304 | - function ( $value ) { |
|
305 | - return apply_filters( 'wl_features__enable__dataset', $value ); |
|
306 | - } |
|
303 | + 'wl_feature__enable__dataset', |
|
304 | + function ( $value ) { |
|
305 | + return apply_filters( 'wl_features__enable__dataset', $value ); |
|
306 | + } |
|
307 | 307 | ); |
308 | 308 | |
309 | 309 | require_once __DIR__ . '/modules/food-kg/load.php'; |
@@ -312,26 +312,26 @@ discard block |
||
312 | 312 | require_once __DIR__ . '/modules/include-exclude-push-config/load.php'; |
313 | 313 | |
314 | 314 | add_action( |
315 | - 'update_plugins_adthrive.wordlift.io', |
|
316 | - function ( $update, $plugin_data, $plugin_file ) { |
|
317 | - // Bail out if it's not our plugin. |
|
318 | - $update_uri = $plugin_data['UpdateURI']; |
|
319 | - if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) { |
|
320 | - return $update; |
|
321 | - } |
|
322 | - |
|
323 | - $response = wp_remote_get( "$update_uri?nocache=" . time() ); |
|
324 | - |
|
325 | - if ( is_wp_error( $response ) ) { |
|
326 | - return $update; |
|
327 | - } |
|
328 | - |
|
329 | - try { |
|
330 | - return json_decode( wp_remote_retrieve_body( $response ) ); |
|
331 | - } catch ( Exception $e ) { |
|
332 | - return $update; |
|
333 | - } |
|
334 | - }, |
|
335 | - 10, |
|
336 | - 3 |
|
315 | + 'update_plugins_adthrive.wordlift.io', |
|
316 | + function ( $update, $plugin_data, $plugin_file ) { |
|
317 | + // Bail out if it's not our plugin. |
|
318 | + $update_uri = $plugin_data['UpdateURI']; |
|
319 | + if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) { |
|
320 | + return $update; |
|
321 | + } |
|
322 | + |
|
323 | + $response = wp_remote_get( "$update_uri?nocache=" . time() ); |
|
324 | + |
|
325 | + if ( is_wp_error( $response ) ) { |
|
326 | + return $update; |
|
327 | + } |
|
328 | + |
|
329 | + try { |
|
330 | + return json_decode( wp_remote_retrieve_body( $response ) ); |
|
331 | + } catch ( Exception $e ) { |
|
332 | + return $update; |
|
333 | + } |
|
334 | + }, |
|
335 | + 10, |
|
336 | + 3 |
|
337 | 337 | ); |
@@ -31,29 +31,29 @@ discard block |
||
31 | 31 | use Wordlift\Features\Features_Registry; |
32 | 32 | use Wordlift\Post\Post_Adapter; |
33 | 33 | // If this file is called directly, abort. |
34 | -if ( ! defined( 'WPINC' ) ) { |
|
34 | +if ( ! defined('WPINC')) { |
|
35 | 35 | die; |
36 | 36 | } |
37 | 37 | define( |
38 | 38 | 'WORDLIFT_PLUGIN_FILE', |
39 | 39 | __FILE__ |
40 | 40 | ); |
41 | -define( 'WORDLIFT_VERSION', '3.40.5' ); |
|
41 | +define('WORDLIFT_VERSION', '3.40.5'); |
|
42 | 42 | |
43 | -require_once plugin_dir_path( __FILE__ ) . '/libraries/action-scheduler/action-scheduler.php'; |
|
44 | -require_once __DIR__ . '/modules/common/load.php'; |
|
45 | -require_once __DIR__ . '/modules/include-exclude/load.php'; |
|
43 | +require_once plugin_dir_path(__FILE__).'/libraries/action-scheduler/action-scheduler.php'; |
|
44 | +require_once __DIR__.'/modules/common/load.php'; |
|
45 | +require_once __DIR__.'/modules/include-exclude/load.php'; |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Filter to disable WLP on any request, defaults to true. |
49 | 49 | * |
50 | 50 | * @since 3.33.6 |
51 | 51 | */ |
52 | -if ( ! apply_filters( 'wl_is_enabled', true ) ) { |
|
52 | +if ( ! apply_filters('wl_is_enabled', true)) { |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
56 | -require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
|
56 | +require_once plugin_dir_path(__FILE__).'vendor/autoload.php'; |
|
57 | 57 | |
58 | 58 | /* |
59 | 59 | * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http. |
@@ -63,15 +63,15 @@ discard block |
||
63 | 63 | wordlift_plugin_autoload_register(); |
64 | 64 | |
65 | 65 | // Include WordLift constants. |
66 | -require_once plugin_dir_path( __FILE__ ) . 'wordlift-constants.php'; |
|
66 | +require_once plugin_dir_path(__FILE__).'wordlift-constants.php'; |
|
67 | 67 | |
68 | 68 | // Load modules. |
69 | -require_once plugin_dir_path( __FILE__ ) . 'modules/core/wordlift-core.php'; |
|
69 | +require_once plugin_dir_path(__FILE__).'modules/core/wordlift-core.php'; |
|
70 | 70 | |
71 | -require_once plugin_dir_path( __FILE__ ) . 'deprecations.php'; |
|
71 | +require_once plugin_dir_path(__FILE__).'deprecations.php'; |
|
72 | 72 | |
73 | 73 | // Load early to enable/disable features. |
74 | -require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php'; |
|
74 | +require_once plugin_dir_path(__FILE__).'wordlift/features/index.php'; |
|
75 | 75 | |
76 | 76 | /** |
77 | 77 | * The code that runs during plugin activation. |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | */ |
80 | 80 | function activate_wordlift() { |
81 | 81 | |
82 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
82 | + $log = Wordlift_Log_Service::get_logger('activate_wordlift'); |
|
83 | 83 | |
84 | - $log->info( 'Activating WordLift...' ); |
|
84 | + $log->info('Activating WordLift...'); |
|
85 | 85 | |
86 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
86 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php'; |
|
87 | 87 | Wordlift_Activator::activate(); |
88 | 88 | |
89 | 89 | /** |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | */ |
104 | 104 | Top_Entities::activate(); |
105 | 105 | |
106 | - if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) { |
|
107 | - wp_schedule_event( time(), 'daily', 'wl_daily_cron' ); |
|
106 | + if ( ! wp_next_scheduled('wl_daily_cron')) { |
|
107 | + wp_schedule_event(time(), 'daily', 'wl_daily_cron'); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | function deactivate_wordlift() { |
117 | 117 | |
118 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
118 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php'; |
|
119 | 119 | Wordlift_Deactivator::deactivate(); |
120 | 120 | Wordlift_Http_Api::deactivate(); |
121 | 121 | Ttl_Cache_Cleaner::deactivate(); |
@@ -131,18 +131,18 @@ discard block |
||
131 | 131 | Key_Validation_Notice::remove_notification_flag(); |
132 | 132 | flush_rewrite_rules(); |
133 | 133 | |
134 | - wp_clear_scheduled_hook( 'wl_daily_cron' ); |
|
134 | + wp_clear_scheduled_hook('wl_daily_cron'); |
|
135 | 135 | |
136 | 136 | } |
137 | 137 | |
138 | -register_activation_hook( __FILE__, 'activate_wordlift' ); |
|
139 | -register_deactivation_hook( __FILE__, 'deactivate_wordlift' ); |
|
138 | +register_activation_hook(__FILE__, 'activate_wordlift'); |
|
139 | +register_deactivation_hook(__FILE__, 'deactivate_wordlift'); |
|
140 | 140 | |
141 | 141 | /** |
142 | 142 | * The core plugin class that is used to define internationalization, |
143 | 143 | * admin-specific hooks, and public-facing site hooks. |
144 | 144 | */ |
145 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php'; |
|
145 | +require plugin_dir_path(__FILE__).'includes/class-wordlift.php'; |
|
146 | 146 | |
147 | 147 | /** |
148 | 148 | * Begins execution of the plugin. |
@@ -162,12 +162,12 @@ discard block |
||
162 | 162 | * @return bool |
163 | 163 | * @since 3.27.6 |
164 | 164 | */ |
165 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
166 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
167 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
168 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
165 | + if (apply_filters('wl_feature__enable__widgets', true)) { |
|
166 | + add_action('widgets_init', 'wl_register_chord_widget'); |
|
167 | + add_action('widgets_init', 'wl_register_geo_widget'); |
|
168 | + add_action('widgets_init', 'wl_register_timeline_widget'); |
|
169 | 169 | } |
170 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
170 | + add_filter('widget_text', 'do_shortcode'); |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Filter: wl_feature__enable__analysis |
@@ -177,10 +177,10 @@ discard block |
||
177 | 177 | * @return bool |
178 | 178 | * @since 3.27.6 |
179 | 179 | */ |
180 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
181 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
180 | + if (apply_filters('wl_feature__enable__analysis', true)) { |
|
181 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action'); |
|
182 | 182 | } else { |
183 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
183 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action'); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | $plugin = new Wordlift(); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | |
198 | 198 | add_action( |
199 | 199 | 'plugins_loaded', |
200 | - function () { |
|
200 | + function() { |
|
201 | 201 | // All features from registry should be initialized here. |
202 | 202 | $features_registry = Features_Registry::get_instance(); |
203 | 203 | $features_registry->initialize_all_features(); |
@@ -208,27 +208,27 @@ discard block |
||
208 | 208 | add_action( |
209 | 209 | 'plugins_loaded', |
210 | 210 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
211 | - function () use ( $plugin ) { |
|
211 | + function() use ($plugin) { |
|
212 | 212 | |
213 | 213 | new Wordlift_Products_Navigator_Shortcode_REST(); |
214 | 214 | |
215 | 215 | // Register the Dataset module, requires `$api_service`. |
216 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
217 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
216 | + require_once plugin_dir_path(__FILE__).'wordlift/dataset/index.php'; |
|
217 | + require_once plugin_dir_path(__FILE__).'wordlift/shipping-data/index.php'; |
|
218 | 218 | |
219 | 219 | /* |
220 | 220 | * Require the Entity annotation cleanup module. |
221 | 221 | * |
222 | 222 | * @since 3.34.6 |
223 | 223 | */ |
224 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php'; |
|
224 | + require_once plugin_dir_path(__FILE__).'wordlift/cleanup/index.php'; |
|
225 | 225 | |
226 | 226 | /* |
227 | 227 | * Import LOD entities. |
228 | 228 | * |
229 | 229 | * @since 3.35.0 |
230 | 230 | */ |
231 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php'; |
|
231 | + require_once plugin_dir_path(__FILE__).'wordlift/lod-import/index.php'; |
|
232 | 232 | |
233 | 233 | } |
234 | 234 | ); |
@@ -246,23 +246,23 @@ discard block |
||
246 | 246 | function wordlift_plugin_autoload_register() { |
247 | 247 | |
248 | 248 | spl_autoload_register( |
249 | - function ( $class_name ) { |
|
249 | + function($class_name) { |
|
250 | 250 | |
251 | 251 | // Bail out if these are not our classes. |
252 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
252 | + if (0 !== strpos($class_name, 'Wordlift\\')) { |
|
253 | 253 | return false; |
254 | 254 | } |
255 | 255 | |
256 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
256 | + $class_name_lc = strtolower(str_replace('_', '-', $class_name)); |
|
257 | 257 | |
258 | - preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
258 | + preg_match('|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches); |
|
259 | 259 | |
260 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
261 | - $file = 'class-' . $matches[2] . '.php'; |
|
260 | + $path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]); |
|
261 | + $file = 'class-'.$matches[2].'.php'; |
|
262 | 262 | |
263 | - $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
263 | + $full_path = plugin_dir_path(__FILE__).$path.DIRECTORY_SEPARATOR.$file; |
|
264 | 264 | |
265 | - if ( ! file_exists( $full_path ) ) { |
|
265 | + if ( ! file_exists($full_path)) { |
|
266 | 266 | return false; |
267 | 267 | } |
268 | 268 | |
@@ -274,13 +274,13 @@ discard block |
||
274 | 274 | |
275 | 275 | } |
276 | 276 | |
277 | -function wl_block_categories( $categories ) { |
|
277 | +function wl_block_categories($categories) { |
|
278 | 278 | return array_merge( |
279 | 279 | $categories, |
280 | 280 | array( |
281 | 281 | array( |
282 | 282 | 'slug' => 'wordlift', |
283 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
283 | + 'title' => __('WordLift', 'wordlift'), |
|
284 | 284 | ), |
285 | 285 | ) |
286 | 286 | ); |
@@ -290,45 +290,45 @@ discard block |
||
290 | 290 | * This function is created temporarily to handle the legacy library, |
291 | 291 | * this has to be removed when removing the legacy fields from the ui. |
292 | 292 | */ |
293 | -function wl_enqueue_leaflet( $in_footer = false ) { |
|
293 | +function wl_enqueue_leaflet($in_footer = false) { |
|
294 | 294 | // Leaflet. |
295 | - wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
296 | - wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
295 | + wp_enqueue_style('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.css', array(), '1.6.0'); |
|
296 | + wp_enqueue_script('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer); |
|
297 | 297 | } |
298 | 298 | |
299 | -add_filter( 'block_categories', 'wl_block_categories', 10 ); |
|
299 | +add_filter('block_categories', 'wl_block_categories', 10); |
|
300 | 300 | |
301 | 301 | // Temporary fix for a typo in WooCommerce Extension. |
302 | 302 | add_filter( |
303 | 303 | 'wl_feature__enable__dataset', |
304 | - function ( $value ) { |
|
305 | - return apply_filters( 'wl_features__enable__dataset', $value ); |
|
304 | + function($value) { |
|
305 | + return apply_filters('wl_features__enable__dataset', $value); |
|
306 | 306 | } |
307 | 307 | ); |
308 | 308 | |
309 | -require_once __DIR__ . '/modules/food-kg/load.php'; |
|
310 | -require_once __DIR__ . '/modules/acf4so/load.php'; |
|
311 | -require_once __DIR__ . '/modules/pods/load.php'; |
|
312 | -require_once __DIR__ . '/modules/include-exclude-push-config/load.php'; |
|
309 | +require_once __DIR__.'/modules/food-kg/load.php'; |
|
310 | +require_once __DIR__.'/modules/acf4so/load.php'; |
|
311 | +require_once __DIR__.'/modules/pods/load.php'; |
|
312 | +require_once __DIR__.'/modules/include-exclude-push-config/load.php'; |
|
313 | 313 | |
314 | 314 | add_action( |
315 | 315 | 'update_plugins_adthrive.wordlift.io', |
316 | - function ( $update, $plugin_data, $plugin_file ) { |
|
316 | + function($update, $plugin_data, $plugin_file) { |
|
317 | 317 | // Bail out if it's not our plugin. |
318 | 318 | $update_uri = $plugin_data['UpdateURI']; |
319 | - if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) { |
|
319 | + if ('wordlift/wordlift.php' !== $plugin_file || ! isset($update_uri)) { |
|
320 | 320 | return $update; |
321 | 321 | } |
322 | 322 | |
323 | - $response = wp_remote_get( "$update_uri?nocache=" . time() ); |
|
323 | + $response = wp_remote_get("$update_uri?nocache=".time()); |
|
324 | 324 | |
325 | - if ( is_wp_error( $response ) ) { |
|
325 | + if (is_wp_error($response)) { |
|
326 | 326 | return $update; |
327 | 327 | } |
328 | 328 | |
329 | 329 | try { |
330 | - return json_decode( wp_remote_retrieve_body( $response ) ); |
|
331 | - } catch ( Exception $e ) { |
|
330 | + return json_decode(wp_remote_retrieve_body($response)); |
|
331 | + } catch (Exception $e) { |
|
332 | 332 | return $update; |
333 | 333 | } |
334 | 334 | }, |