@@ -18,378 +18,378 @@ |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Admin_Settings_Page extends Wordlift_Admin_Page { |
20 | 20 | |
21 | - /** |
|
22 | - * A {@link Wordlift_Entity_Service} instance. |
|
23 | - * |
|
24 | - * @since 3.11.0 |
|
25 | - * @access private |
|
26 | - * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
27 | - */ |
|
28 | - private $entity_service; |
|
29 | - |
|
30 | - /** |
|
31 | - * A {@link Wordlift_Admin_Input_Element} element renderer. |
|
32 | - * |
|
33 | - * @since 3.11.0 |
|
34 | - * @access private |
|
35 | - * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer. |
|
36 | - */ |
|
37 | - private $input_element; |
|
38 | - |
|
39 | - /** |
|
40 | - * A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
41 | - * |
|
42 | - * @since 3.13.0 |
|
43 | - * @access protected |
|
44 | - * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
45 | - */ |
|
46 | - private $radio_input_element; |
|
47 | - |
|
48 | - /** |
|
49 | - * A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
50 | - * |
|
51 | - * @since 3.11.0 |
|
52 | - * @access private |
|
53 | - * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
54 | - */ |
|
55 | - private $language_select_element; |
|
56 | - |
|
57 | - /** |
|
58 | - * A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
59 | - * |
|
60 | - * @since 3.18.0 |
|
61 | - * @access private |
|
62 | - * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
63 | - */ |
|
64 | - private $country_select_element; |
|
65 | - |
|
66 | - /** |
|
67 | - * A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
68 | - * |
|
69 | - * @since 3.11.0 |
|
70 | - * @access private |
|
71 | - * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
72 | - */ |
|
73 | - private $publisher_element; |
|
74 | - |
|
75 | - /** |
|
76 | - * Create a {@link Wordlift_Admin_Settings_Page} instance. |
|
77 | - * |
|
78 | - * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
79 | - * @param \Wordlift_Admin_Input_Element $input_element A {@link Wordlift_Admin_Input_Element} element renderer. |
|
80 | - * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
81 | - * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
82 | - * @param \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
83 | - * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
84 | - * |
|
85 | - * @since 3.11.0 |
|
86 | - */ |
|
87 | - public function __construct( $entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element ) { |
|
88 | - |
|
89 | - $this->entity_service = $entity_service; |
|
90 | - |
|
91 | - // Set a reference to the UI elements. |
|
92 | - $this->input_element = $input_element; |
|
93 | - $this->radio_input_element = $radio_input_element; |
|
94 | - $this->language_select_element = $language_select_element; |
|
95 | - $this->country_select_element = $country_select_element; |
|
96 | - $this->publisher_element = $publisher_element; |
|
97 | - |
|
98 | - } |
|
99 | - |
|
100 | - private static $instance; |
|
101 | - |
|
102 | - /** |
|
103 | - * Get the singleton instance of the Notice service. |
|
104 | - * |
|
105 | - * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service. |
|
106 | - * @since 3.14.0 |
|
107 | - */ |
|
108 | - public static function get_instance() { |
|
109 | - |
|
110 | - if ( ! isset( self::$instance ) ) { |
|
111 | - $publisher_element = new Wordlift_Admin_Publisher_Element( |
|
112 | - Wordlift_Publisher_Service::get_instance(), |
|
113 | - new Wordlift_Admin_Tabs_Element(), |
|
114 | - new Wordlift_Admin_Select2_Element() |
|
115 | - ); |
|
116 | - |
|
117 | - self::$instance = new self( |
|
118 | - Wordlift_Entity_Service::get_instance(), |
|
119 | - new Wordlift_Admin_Input_Element(), |
|
120 | - new Wordlift_Admin_Language_Select_Element(), |
|
121 | - new Wordlift_Admin_Country_Select_Element(), |
|
122 | - $publisher_element, |
|
123 | - new Wordlift_Admin_Radio_Input_Element() |
|
124 | - ); |
|
125 | - } |
|
126 | - |
|
127 | - return self::$instance; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @inheritdoc |
|
132 | - */ |
|
133 | - public function get_parent_slug() { |
|
134 | - |
|
135 | - return 'wl_admin_menu'; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @inheritdoc |
|
140 | - */ |
|
141 | - public function get_capability() { |
|
142 | - |
|
143 | - return 'manage_options'; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @inheritdoc |
|
148 | - */ |
|
149 | - public function get_page_title() { |
|
150 | - |
|
151 | - return 'WordLift Settings'; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * @inheritdoc |
|
156 | - */ |
|
157 | - public function get_menu_title() { |
|
158 | - |
|
159 | - return 'Settings'; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * @inheritdoc |
|
164 | - */ |
|
165 | - public function get_menu_slug() { |
|
166 | - |
|
167 | - return 'wl_configuration_admin_menu'; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @inheritdoc |
|
172 | - */ |
|
173 | - public function get_partial_name() { |
|
174 | - |
|
175 | - return 'wordlift-admin-settings-page.php'; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @inheritdoc |
|
180 | - */ |
|
181 | - public function enqueue_scripts() { |
|
182 | - |
|
183 | - // Enqueue the media scripts to be used for the publisher's logo selection. |
|
184 | - wp_enqueue_media(); |
|
185 | - |
|
186 | - // JavaScript required for the settings page. |
|
187 | - // @todo: try to move to the `wordlift-admin.bundle.js`. |
|
188 | - wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( __DIR__ ) . 'admin/js/1/settings.js', array( 'wp-util' ), WORDLIFT_VERSION, false ); |
|
189 | - wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( __DIR__ ) . 'admin/js/1/settings.css', array(), WORDLIFT_VERSION ); |
|
190 | - |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Configure all the configuration parameters. |
|
195 | - * |
|
196 | - * Called by the *admin_init* hook. |
|
197 | - * |
|
198 | - * @since 3.11.0 |
|
199 | - */ |
|
200 | - public function admin_init() { |
|
201 | - // Register WordLift's general settings, providing our own sanitize callback |
|
202 | - // which will also check whether the user filled the WL Publisher form. |
|
203 | - register_setting( |
|
204 | - 'wl_general_settings', |
|
205 | - 'wl_general_settings', |
|
206 | - array( $this, 'sanitize_callback' ) |
|
207 | - ); |
|
208 | - |
|
209 | - // Add the general settings section. |
|
210 | - add_settings_section( |
|
211 | - 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
|
212 | - '', // Section header. |
|
213 | - '', // Callback used to render the description of the section. |
|
214 | - 'wl_general_settings' // Page on which to add this section of options. |
|
215 | - ); |
|
216 | - |
|
217 | - $key_args = array( |
|
218 | - 'id' => 'wl-key', |
|
219 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
220 | - 'value' => Wordlift_Configuration_Service::get_instance()->get_key(), |
|
221 | - 'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ) |
|
222 | - . ' [' . get_option( 'home' ) . ']', |
|
223 | - ); |
|
224 | - |
|
225 | - // Before we were used to validate the key beforehand, but this means |
|
226 | - // an http call whenever a page is opened in the admin area. Therefore |
|
227 | - // we now leave the input `untouched`, leaving to the client to update |
|
228 | - // the `css_class`. |
|
229 | - // |
|
230 | - // See https://github.com/insideout10/wordlift-plugin/issues/669. |
|
231 | - $key_args['css_class'] = 'untouched'; |
|
232 | - |
|
233 | - // Add the `key` field. |
|
234 | - add_settings_field( |
|
235 | - 'wl-key', // Element id used to identify the field throughout the theme. |
|
236 | - __( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
237 | - // The name of the function responsible for rendering the option interface. |
|
238 | - array( $this->input_element, 'render' ), |
|
239 | - 'wl_general_settings', // The page on which this option will be displayed. |
|
240 | - 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
241 | - $key_args // The array of arguments to pass to the callback. In this case, just a description. |
|
242 | - ); |
|
243 | - |
|
244 | - // Entity Base Path input. |
|
245 | - $entity_base_path_args = array( |
|
246 | - // The array of arguments to pass to the callback. In this case, just a description. |
|
247 | - 'id' => 'wl-entity-base-path', |
|
248 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
249 | - 'value' => Wordlift_Configuration_Service::get_instance()->get_entity_base_path(), |
|
250 | - /* translators: Placeholders: %s - a link to FAQ's page. */ |
|
251 | - 'description' => sprintf( __( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ), |
|
252 | - ); |
|
253 | - |
|
254 | - // The following call is very heavy on large web sites and is always run |
|
255 | - // also when not needed: |
|
256 | - // $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
|
257 | - // |
|
258 | - // It is now replaced by a filter to add the `readonly` flag to the |
|
259 | - // input element when this is actually rendered. |
|
260 | - add_filter( |
|
261 | - 'wl_admin_input_element_params', |
|
262 | - array( |
|
263 | - $this, |
|
264 | - 'entity_path_input_element_params', |
|
265 | - ) |
|
266 | - ); |
|
267 | - |
|
268 | - // Add the `wl_entity_base_path` field. |
|
269 | - add_settings_field( |
|
270 | - 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
271 | - __( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
272 | - // The name of the function responsible for rendering the option interface |
|
273 | - array( $this->input_element, 'render' ), |
|
274 | - 'wl_general_settings', // The page on which this option will be displayed |
|
275 | - 'wl_general_settings_section', // The name of the section to which this field belongs |
|
276 | - $entity_base_path_args |
|
277 | - ); |
|
278 | - |
|
279 | - // Add the `country_code` field. |
|
280 | - add_settings_field( |
|
281 | - 'wl-country-code', |
|
282 | - __( 'Country', 'wordlift' ), |
|
283 | - array( $this->country_select_element, 'render' ), |
|
284 | - 'wl_general_settings', |
|
285 | - 'wl_general_settings_section', |
|
286 | - array( |
|
287 | - 'id' => 'wl-country-code', |
|
288 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::COUNTRY_CODE . ']', |
|
289 | - 'value' => Wordlift_Configuration_Service::get_instance()->get_country_code(), |
|
290 | - 'description' => __( 'Please select a country.', 'wordlift' ), |
|
291 | - 'notice' => __( 'The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift' ), |
|
292 | - ) |
|
293 | - ); |
|
294 | - |
|
295 | - // Add the `publisher` field. |
|
296 | - add_settings_field( |
|
297 | - 'wl-publisher-id', |
|
298 | - __( 'Publisher', 'wordlift' ), |
|
299 | - array( $this->publisher_element, 'render' ), |
|
300 | - 'wl_general_settings', |
|
301 | - 'wl_general_settings_section', |
|
302 | - array( |
|
303 | - 'id' => 'wl-publisher-id', |
|
304 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
305 | - ) |
|
306 | - ); |
|
307 | - |
|
308 | - // Add the `link by default` field. |
|
309 | - add_settings_field( |
|
310 | - 'wl-link-by-default', |
|
311 | - __( 'Link by Default', 'wordlift' ), |
|
312 | - array( $this->radio_input_element, 'render' ), |
|
313 | - 'wl_general_settings', |
|
314 | - 'wl_general_settings_section', |
|
315 | - array( |
|
316 | - 'id' => 'wl-link-by-default', |
|
317 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
318 | - 'value' => Wordlift_Configuration_Service::get_instance()->is_link_by_default() ? 'yes' : 'no', |
|
319 | - 'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
320 | - ) |
|
321 | - ); |
|
322 | - |
|
323 | - // Add the `diagnostic data` field. |
|
324 | - add_settings_field( |
|
325 | - 'wl-send-diagnostic', |
|
326 | - __( 'Send Diagnostic Data', 'wordlift' ), |
|
327 | - array( $this->radio_input_element, 'render' ), |
|
328 | - 'wl_general_settings', |
|
329 | - 'wl_general_settings_section', |
|
330 | - array( |
|
331 | - 'id' => 'wl-send-diagnostic', |
|
332 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']', |
|
333 | - 'value' => 'yes' === Wordlift_Configuration_Service::get_instance()->get_diagnostic_preferences() ? 'yes' : 'no', |
|
334 | - 'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ), |
|
335 | - ) |
|
336 | - ); |
|
337 | - |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Filter the {@link Wordlift_Admin_Input_Element} in order to add the |
|
342 | - * `readonly` flag to the `wl-entity-base-path` input. |
|
343 | - * |
|
344 | - * @param array $args An array of {@link Wordlift_Admin_Input_Element} parameters. |
|
345 | - * |
|
346 | - * @return array The updated array. |
|
347 | - * @since 3.17.0 |
|
348 | - */ |
|
349 | - public function entity_path_input_element_params( $args ) { |
|
350 | - |
|
351 | - // Bail out if it's not the `wl-entity-base-path`). |
|
352 | - if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
353 | - return $args; |
|
354 | - } |
|
355 | - |
|
356 | - // Set the readonly flag according to the entities count. |
|
357 | - $args['readonly'] = 0 < $this->entity_service->count(); |
|
358 | - |
|
359 | - // Return the updated args. |
|
360 | - return $args; |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Sanitize the configuration settings to be stored. |
|
365 | - * |
|
366 | - * If a new entity is being created for the publisher, create it and set The |
|
367 | - * publisher setting. |
|
368 | - * |
|
369 | - * @param array $input The configuration settings array. |
|
370 | - * |
|
371 | - * @return array The sanitized input array. |
|
372 | - * @since 3.11.0 |
|
373 | - */ |
|
374 | - public function sanitize_callback( $input ) { |
|
375 | - // No nonce verification since this callback is handled by settings api. |
|
376 | - // Check whether a publisher name has been set. |
|
377 | - // phpcs:ignore Standard.Category.SniffName.ErrorCode |
|
378 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
379 | - $name = isset( $_POST['wl_publisher']['name'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['wl_publisher']['name'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
380 | - $type = isset( $_POST['wl_publisher']['type'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['wl_publisher']['type'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
381 | - // phpcs:ignore Standard.Category.SniffName.ErrorCode |
|
382 | - $thumbnail_id = isset( $_POST['wl_publisher']['thumbnail_id'] ) ? sanitize_text_field( wp_unslash( $_POST['wl_publisher']['thumbnail_id'] ) ) : null; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
383 | - |
|
384 | - // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
385 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
386 | - |
|
387 | - // Create an entity for the publisher and assign it to the input |
|
388 | - // parameter which WordPress automatically saves into the settings. |
|
389 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
390 | - } |
|
391 | - |
|
392 | - return $input; |
|
393 | - } |
|
21 | + /** |
|
22 | + * A {@link Wordlift_Entity_Service} instance. |
|
23 | + * |
|
24 | + * @since 3.11.0 |
|
25 | + * @access private |
|
26 | + * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
27 | + */ |
|
28 | + private $entity_service; |
|
29 | + |
|
30 | + /** |
|
31 | + * A {@link Wordlift_Admin_Input_Element} element renderer. |
|
32 | + * |
|
33 | + * @since 3.11.0 |
|
34 | + * @access private |
|
35 | + * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer. |
|
36 | + */ |
|
37 | + private $input_element; |
|
38 | + |
|
39 | + /** |
|
40 | + * A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
41 | + * |
|
42 | + * @since 3.13.0 |
|
43 | + * @access protected |
|
44 | + * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
45 | + */ |
|
46 | + private $radio_input_element; |
|
47 | + |
|
48 | + /** |
|
49 | + * A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
50 | + * |
|
51 | + * @since 3.11.0 |
|
52 | + * @access private |
|
53 | + * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
54 | + */ |
|
55 | + private $language_select_element; |
|
56 | + |
|
57 | + /** |
|
58 | + * A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
59 | + * |
|
60 | + * @since 3.18.0 |
|
61 | + * @access private |
|
62 | + * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
63 | + */ |
|
64 | + private $country_select_element; |
|
65 | + |
|
66 | + /** |
|
67 | + * A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
68 | + * |
|
69 | + * @since 3.11.0 |
|
70 | + * @access private |
|
71 | + * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
72 | + */ |
|
73 | + private $publisher_element; |
|
74 | + |
|
75 | + /** |
|
76 | + * Create a {@link Wordlift_Admin_Settings_Page} instance. |
|
77 | + * |
|
78 | + * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
79 | + * @param \Wordlift_Admin_Input_Element $input_element A {@link Wordlift_Admin_Input_Element} element renderer. |
|
80 | + * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
81 | + * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
82 | + * @param \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
83 | + * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
84 | + * |
|
85 | + * @since 3.11.0 |
|
86 | + */ |
|
87 | + public function __construct( $entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element ) { |
|
88 | + |
|
89 | + $this->entity_service = $entity_service; |
|
90 | + |
|
91 | + // Set a reference to the UI elements. |
|
92 | + $this->input_element = $input_element; |
|
93 | + $this->radio_input_element = $radio_input_element; |
|
94 | + $this->language_select_element = $language_select_element; |
|
95 | + $this->country_select_element = $country_select_element; |
|
96 | + $this->publisher_element = $publisher_element; |
|
97 | + |
|
98 | + } |
|
99 | + |
|
100 | + private static $instance; |
|
101 | + |
|
102 | + /** |
|
103 | + * Get the singleton instance of the Notice service. |
|
104 | + * |
|
105 | + * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service. |
|
106 | + * @since 3.14.0 |
|
107 | + */ |
|
108 | + public static function get_instance() { |
|
109 | + |
|
110 | + if ( ! isset( self::$instance ) ) { |
|
111 | + $publisher_element = new Wordlift_Admin_Publisher_Element( |
|
112 | + Wordlift_Publisher_Service::get_instance(), |
|
113 | + new Wordlift_Admin_Tabs_Element(), |
|
114 | + new Wordlift_Admin_Select2_Element() |
|
115 | + ); |
|
116 | + |
|
117 | + self::$instance = new self( |
|
118 | + Wordlift_Entity_Service::get_instance(), |
|
119 | + new Wordlift_Admin_Input_Element(), |
|
120 | + new Wordlift_Admin_Language_Select_Element(), |
|
121 | + new Wordlift_Admin_Country_Select_Element(), |
|
122 | + $publisher_element, |
|
123 | + new Wordlift_Admin_Radio_Input_Element() |
|
124 | + ); |
|
125 | + } |
|
126 | + |
|
127 | + return self::$instance; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @inheritdoc |
|
132 | + */ |
|
133 | + public function get_parent_slug() { |
|
134 | + |
|
135 | + return 'wl_admin_menu'; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @inheritdoc |
|
140 | + */ |
|
141 | + public function get_capability() { |
|
142 | + |
|
143 | + return 'manage_options'; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @inheritdoc |
|
148 | + */ |
|
149 | + public function get_page_title() { |
|
150 | + |
|
151 | + return 'WordLift Settings'; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * @inheritdoc |
|
156 | + */ |
|
157 | + public function get_menu_title() { |
|
158 | + |
|
159 | + return 'Settings'; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * @inheritdoc |
|
164 | + */ |
|
165 | + public function get_menu_slug() { |
|
166 | + |
|
167 | + return 'wl_configuration_admin_menu'; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @inheritdoc |
|
172 | + */ |
|
173 | + public function get_partial_name() { |
|
174 | + |
|
175 | + return 'wordlift-admin-settings-page.php'; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @inheritdoc |
|
180 | + */ |
|
181 | + public function enqueue_scripts() { |
|
182 | + |
|
183 | + // Enqueue the media scripts to be used for the publisher's logo selection. |
|
184 | + wp_enqueue_media(); |
|
185 | + |
|
186 | + // JavaScript required for the settings page. |
|
187 | + // @todo: try to move to the `wordlift-admin.bundle.js`. |
|
188 | + wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( __DIR__ ) . 'admin/js/1/settings.js', array( 'wp-util' ), WORDLIFT_VERSION, false ); |
|
189 | + wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( __DIR__ ) . 'admin/js/1/settings.css', array(), WORDLIFT_VERSION ); |
|
190 | + |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Configure all the configuration parameters. |
|
195 | + * |
|
196 | + * Called by the *admin_init* hook. |
|
197 | + * |
|
198 | + * @since 3.11.0 |
|
199 | + */ |
|
200 | + public function admin_init() { |
|
201 | + // Register WordLift's general settings, providing our own sanitize callback |
|
202 | + // which will also check whether the user filled the WL Publisher form. |
|
203 | + register_setting( |
|
204 | + 'wl_general_settings', |
|
205 | + 'wl_general_settings', |
|
206 | + array( $this, 'sanitize_callback' ) |
|
207 | + ); |
|
208 | + |
|
209 | + // Add the general settings section. |
|
210 | + add_settings_section( |
|
211 | + 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
|
212 | + '', // Section header. |
|
213 | + '', // Callback used to render the description of the section. |
|
214 | + 'wl_general_settings' // Page on which to add this section of options. |
|
215 | + ); |
|
216 | + |
|
217 | + $key_args = array( |
|
218 | + 'id' => 'wl-key', |
|
219 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
220 | + 'value' => Wordlift_Configuration_Service::get_instance()->get_key(), |
|
221 | + 'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ) |
|
222 | + . ' [' . get_option( 'home' ) . ']', |
|
223 | + ); |
|
224 | + |
|
225 | + // Before we were used to validate the key beforehand, but this means |
|
226 | + // an http call whenever a page is opened in the admin area. Therefore |
|
227 | + // we now leave the input `untouched`, leaving to the client to update |
|
228 | + // the `css_class`. |
|
229 | + // |
|
230 | + // See https://github.com/insideout10/wordlift-plugin/issues/669. |
|
231 | + $key_args['css_class'] = 'untouched'; |
|
232 | + |
|
233 | + // Add the `key` field. |
|
234 | + add_settings_field( |
|
235 | + 'wl-key', // Element id used to identify the field throughout the theme. |
|
236 | + __( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
237 | + // The name of the function responsible for rendering the option interface. |
|
238 | + array( $this->input_element, 'render' ), |
|
239 | + 'wl_general_settings', // The page on which this option will be displayed. |
|
240 | + 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
241 | + $key_args // The array of arguments to pass to the callback. In this case, just a description. |
|
242 | + ); |
|
243 | + |
|
244 | + // Entity Base Path input. |
|
245 | + $entity_base_path_args = array( |
|
246 | + // The array of arguments to pass to the callback. In this case, just a description. |
|
247 | + 'id' => 'wl-entity-base-path', |
|
248 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
249 | + 'value' => Wordlift_Configuration_Service::get_instance()->get_entity_base_path(), |
|
250 | + /* translators: Placeholders: %s - a link to FAQ's page. */ |
|
251 | + 'description' => sprintf( __( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ), |
|
252 | + ); |
|
253 | + |
|
254 | + // The following call is very heavy on large web sites and is always run |
|
255 | + // also when not needed: |
|
256 | + // $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
|
257 | + // |
|
258 | + // It is now replaced by a filter to add the `readonly` flag to the |
|
259 | + // input element when this is actually rendered. |
|
260 | + add_filter( |
|
261 | + 'wl_admin_input_element_params', |
|
262 | + array( |
|
263 | + $this, |
|
264 | + 'entity_path_input_element_params', |
|
265 | + ) |
|
266 | + ); |
|
267 | + |
|
268 | + // Add the `wl_entity_base_path` field. |
|
269 | + add_settings_field( |
|
270 | + 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
271 | + __( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
272 | + // The name of the function responsible for rendering the option interface |
|
273 | + array( $this->input_element, 'render' ), |
|
274 | + 'wl_general_settings', // The page on which this option will be displayed |
|
275 | + 'wl_general_settings_section', // The name of the section to which this field belongs |
|
276 | + $entity_base_path_args |
|
277 | + ); |
|
278 | + |
|
279 | + // Add the `country_code` field. |
|
280 | + add_settings_field( |
|
281 | + 'wl-country-code', |
|
282 | + __( 'Country', 'wordlift' ), |
|
283 | + array( $this->country_select_element, 'render' ), |
|
284 | + 'wl_general_settings', |
|
285 | + 'wl_general_settings_section', |
|
286 | + array( |
|
287 | + 'id' => 'wl-country-code', |
|
288 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::COUNTRY_CODE . ']', |
|
289 | + 'value' => Wordlift_Configuration_Service::get_instance()->get_country_code(), |
|
290 | + 'description' => __( 'Please select a country.', 'wordlift' ), |
|
291 | + 'notice' => __( 'The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift' ), |
|
292 | + ) |
|
293 | + ); |
|
294 | + |
|
295 | + // Add the `publisher` field. |
|
296 | + add_settings_field( |
|
297 | + 'wl-publisher-id', |
|
298 | + __( 'Publisher', 'wordlift' ), |
|
299 | + array( $this->publisher_element, 'render' ), |
|
300 | + 'wl_general_settings', |
|
301 | + 'wl_general_settings_section', |
|
302 | + array( |
|
303 | + 'id' => 'wl-publisher-id', |
|
304 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
305 | + ) |
|
306 | + ); |
|
307 | + |
|
308 | + // Add the `link by default` field. |
|
309 | + add_settings_field( |
|
310 | + 'wl-link-by-default', |
|
311 | + __( 'Link by Default', 'wordlift' ), |
|
312 | + array( $this->radio_input_element, 'render' ), |
|
313 | + 'wl_general_settings', |
|
314 | + 'wl_general_settings_section', |
|
315 | + array( |
|
316 | + 'id' => 'wl-link-by-default', |
|
317 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
318 | + 'value' => Wordlift_Configuration_Service::get_instance()->is_link_by_default() ? 'yes' : 'no', |
|
319 | + 'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
320 | + ) |
|
321 | + ); |
|
322 | + |
|
323 | + // Add the `diagnostic data` field. |
|
324 | + add_settings_field( |
|
325 | + 'wl-send-diagnostic', |
|
326 | + __( 'Send Diagnostic Data', 'wordlift' ), |
|
327 | + array( $this->radio_input_element, 'render' ), |
|
328 | + 'wl_general_settings', |
|
329 | + 'wl_general_settings_section', |
|
330 | + array( |
|
331 | + 'id' => 'wl-send-diagnostic', |
|
332 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']', |
|
333 | + 'value' => 'yes' === Wordlift_Configuration_Service::get_instance()->get_diagnostic_preferences() ? 'yes' : 'no', |
|
334 | + 'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ), |
|
335 | + ) |
|
336 | + ); |
|
337 | + |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * Filter the {@link Wordlift_Admin_Input_Element} in order to add the |
|
342 | + * `readonly` flag to the `wl-entity-base-path` input. |
|
343 | + * |
|
344 | + * @param array $args An array of {@link Wordlift_Admin_Input_Element} parameters. |
|
345 | + * |
|
346 | + * @return array The updated array. |
|
347 | + * @since 3.17.0 |
|
348 | + */ |
|
349 | + public function entity_path_input_element_params( $args ) { |
|
350 | + |
|
351 | + // Bail out if it's not the `wl-entity-base-path`). |
|
352 | + if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
353 | + return $args; |
|
354 | + } |
|
355 | + |
|
356 | + // Set the readonly flag according to the entities count. |
|
357 | + $args['readonly'] = 0 < $this->entity_service->count(); |
|
358 | + |
|
359 | + // Return the updated args. |
|
360 | + return $args; |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Sanitize the configuration settings to be stored. |
|
365 | + * |
|
366 | + * If a new entity is being created for the publisher, create it and set The |
|
367 | + * publisher setting. |
|
368 | + * |
|
369 | + * @param array $input The configuration settings array. |
|
370 | + * |
|
371 | + * @return array The sanitized input array. |
|
372 | + * @since 3.11.0 |
|
373 | + */ |
|
374 | + public function sanitize_callback( $input ) { |
|
375 | + // No nonce verification since this callback is handled by settings api. |
|
376 | + // Check whether a publisher name has been set. |
|
377 | + // phpcs:ignore Standard.Category.SniffName.ErrorCode |
|
378 | + if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
379 | + $name = isset( $_POST['wl_publisher']['name'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['wl_publisher']['name'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
380 | + $type = isset( $_POST['wl_publisher']['type'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['wl_publisher']['type'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
381 | + // phpcs:ignore Standard.Category.SniffName.ErrorCode |
|
382 | + $thumbnail_id = isset( $_POST['wl_publisher']['thumbnail_id'] ) ? sanitize_text_field( wp_unslash( $_POST['wl_publisher']['thumbnail_id'] ) ) : null; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
383 | + |
|
384 | + // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
385 | + $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
386 | + |
|
387 | + // Create an entity for the publisher and assign it to the input |
|
388 | + // parameter which WordPress automatically saves into the settings. |
|
389 | + $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
390 | + } |
|
391 | + |
|
392 | + return $input; |
|
393 | + } |
|
394 | 394 | |
395 | 395 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @since 3.11.0 |
86 | 86 | */ |
87 | - public function __construct( $entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element ) { |
|
87 | + public function __construct($entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element) { |
|
88 | 88 | |
89 | 89 | $this->entity_service = $entity_service; |
90 | 90 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public static function get_instance() { |
109 | 109 | |
110 | - if ( ! isset( self::$instance ) ) { |
|
110 | + if ( ! isset(self::$instance)) { |
|
111 | 111 | $publisher_element = new Wordlift_Admin_Publisher_Element( |
112 | 112 | Wordlift_Publisher_Service::get_instance(), |
113 | 113 | new Wordlift_Admin_Tabs_Element(), |
@@ -185,8 +185,8 @@ discard block |
||
185 | 185 | |
186 | 186 | // JavaScript required for the settings page. |
187 | 187 | // @todo: try to move to the `wordlift-admin.bundle.js`. |
188 | - wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( __DIR__ ) . 'admin/js/1/settings.js', array( 'wp-util' ), WORDLIFT_VERSION, false ); |
|
189 | - wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( __DIR__ ) . 'admin/js/1/settings.css', array(), WORDLIFT_VERSION ); |
|
188 | + wp_enqueue_script('wordlift-admin-settings-page', plugin_dir_url(__DIR__).'admin/js/1/settings.js', array('wp-util'), WORDLIFT_VERSION, false); |
|
189 | + wp_enqueue_style('wordlift-admin-settings-page', plugin_dir_url(__DIR__).'admin/js/1/settings.css', array(), WORDLIFT_VERSION); |
|
190 | 190 | |
191 | 191 | } |
192 | 192 | |
@@ -203,23 +203,23 @@ discard block |
||
203 | 203 | register_setting( |
204 | 204 | 'wl_general_settings', |
205 | 205 | 'wl_general_settings', |
206 | - array( $this, 'sanitize_callback' ) |
|
206 | + array($this, 'sanitize_callback') |
|
207 | 207 | ); |
208 | 208 | |
209 | 209 | // Add the general settings section. |
210 | 210 | add_settings_section( |
211 | 211 | 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
212 | - '', // Section header. |
|
213 | - '', // Callback used to render the description of the section. |
|
212 | + '', // Section header. |
|
213 | + '', // Callback used to render the description of the section. |
|
214 | 214 | 'wl_general_settings' // Page on which to add this section of options. |
215 | 215 | ); |
216 | 216 | |
217 | 217 | $key_args = array( |
218 | 218 | 'id' => 'wl-key', |
219 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
219 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::KEY.']', |
|
220 | 220 | 'value' => Wordlift_Configuration_Service::get_instance()->get_key(), |
221 | - 'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ) |
|
222 | - . ' [' . get_option( 'home' ) . ']', |
|
221 | + 'description' => __('Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift') |
|
222 | + . ' ['.get_option('home').']', |
|
223 | 223 | ); |
224 | 224 | |
225 | 225 | // Before we were used to validate the key beforehand, but this means |
@@ -232,12 +232,12 @@ discard block |
||
232 | 232 | |
233 | 233 | // Add the `key` field. |
234 | 234 | add_settings_field( |
235 | - 'wl-key', // Element id used to identify the field throughout the theme. |
|
236 | - __( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
235 | + 'wl-key', // Element id used to identify the field throughout the theme. |
|
236 | + __('WordLift Key', 'wordlift'), // The label to the left of the option interface element. |
|
237 | 237 | // The name of the function responsible for rendering the option interface. |
238 | - array( $this->input_element, 'render' ), |
|
239 | - 'wl_general_settings', // The page on which this option will be displayed. |
|
240 | - 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
238 | + array($this->input_element, 'render'), |
|
239 | + 'wl_general_settings', // The page on which this option will be displayed. |
|
240 | + 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
241 | 241 | $key_args // The array of arguments to pass to the callback. In this case, just a description. |
242 | 242 | ); |
243 | 243 | |
@@ -245,10 +245,10 @@ discard block |
||
245 | 245 | $entity_base_path_args = array( |
246 | 246 | // The array of arguments to pass to the callback. In this case, just a description. |
247 | 247 | 'id' => 'wl-entity-base-path', |
248 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
248 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY.']', |
|
249 | 249 | 'value' => Wordlift_Configuration_Service::get_instance()->get_entity_base_path(), |
250 | 250 | /* translators: Placeholders: %s - a link to FAQ's page. */ |
251 | - 'description' => sprintf( __( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ), |
|
251 | + 'description' => sprintf(__('All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift'), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary'), |
|
252 | 252 | ); |
253 | 253 | |
254 | 254 | // The following call is very heavy on large web sites and is always run |
@@ -267,71 +267,71 @@ discard block |
||
267 | 267 | |
268 | 268 | // Add the `wl_entity_base_path` field. |
269 | 269 | add_settings_field( |
270 | - 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
271 | - __( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
270 | + 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
271 | + __('Entity Base Path', 'wordlift'), // The label to the left of the option interface element |
|
272 | 272 | // The name of the function responsible for rendering the option interface |
273 | - array( $this->input_element, 'render' ), |
|
274 | - 'wl_general_settings', // The page on which this option will be displayed |
|
275 | - 'wl_general_settings_section', // The name of the section to which this field belongs |
|
273 | + array($this->input_element, 'render'), |
|
274 | + 'wl_general_settings', // The page on which this option will be displayed |
|
275 | + 'wl_general_settings_section', // The name of the section to which this field belongs |
|
276 | 276 | $entity_base_path_args |
277 | 277 | ); |
278 | 278 | |
279 | 279 | // Add the `country_code` field. |
280 | 280 | add_settings_field( |
281 | 281 | 'wl-country-code', |
282 | - __( 'Country', 'wordlift' ), |
|
283 | - array( $this->country_select_element, 'render' ), |
|
282 | + __('Country', 'wordlift'), |
|
283 | + array($this->country_select_element, 'render'), |
|
284 | 284 | 'wl_general_settings', |
285 | 285 | 'wl_general_settings_section', |
286 | 286 | array( |
287 | 287 | 'id' => 'wl-country-code', |
288 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::COUNTRY_CODE . ']', |
|
288 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::COUNTRY_CODE.']', |
|
289 | 289 | 'value' => Wordlift_Configuration_Service::get_instance()->get_country_code(), |
290 | - 'description' => __( 'Please select a country.', 'wordlift' ), |
|
291 | - 'notice' => __( 'The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift' ), |
|
290 | + 'description' => __('Please select a country.', 'wordlift'), |
|
291 | + 'notice' => __('The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift'), |
|
292 | 292 | ) |
293 | 293 | ); |
294 | 294 | |
295 | 295 | // Add the `publisher` field. |
296 | 296 | add_settings_field( |
297 | 297 | 'wl-publisher-id', |
298 | - __( 'Publisher', 'wordlift' ), |
|
299 | - array( $this->publisher_element, 'render' ), |
|
298 | + __('Publisher', 'wordlift'), |
|
299 | + array($this->publisher_element, 'render'), |
|
300 | 300 | 'wl_general_settings', |
301 | 301 | 'wl_general_settings_section', |
302 | 302 | array( |
303 | 303 | 'id' => 'wl-publisher-id', |
304 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
304 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::PUBLISHER_ID.']', |
|
305 | 305 | ) |
306 | 306 | ); |
307 | 307 | |
308 | 308 | // Add the `link by default` field. |
309 | 309 | add_settings_field( |
310 | 310 | 'wl-link-by-default', |
311 | - __( 'Link by Default', 'wordlift' ), |
|
312 | - array( $this->radio_input_element, 'render' ), |
|
311 | + __('Link by Default', 'wordlift'), |
|
312 | + array($this->radio_input_element, 'render'), |
|
313 | 313 | 'wl_general_settings', |
314 | 314 | 'wl_general_settings_section', |
315 | 315 | array( |
316 | 316 | 'id' => 'wl-link-by-default', |
317 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
317 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::LINK_BY_DEFAULT.']', |
|
318 | 318 | 'value' => Wordlift_Configuration_Service::get_instance()->is_link_by_default() ? 'yes' : 'no', |
319 | - 'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
319 | + 'description' => __('Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift'), |
|
320 | 320 | ) |
321 | 321 | ); |
322 | 322 | |
323 | 323 | // Add the `diagnostic data` field. |
324 | 324 | add_settings_field( |
325 | 325 | 'wl-send-diagnostic', |
326 | - __( 'Send Diagnostic Data', 'wordlift' ), |
|
327 | - array( $this->radio_input_element, 'render' ), |
|
326 | + __('Send Diagnostic Data', 'wordlift'), |
|
327 | + array($this->radio_input_element, 'render'), |
|
328 | 328 | 'wl_general_settings', |
329 | 329 | 'wl_general_settings_section', |
330 | 330 | array( |
331 | 331 | 'id' => 'wl-send-diagnostic', |
332 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']', |
|
332 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::SEND_DIAGNOSTIC.']', |
|
333 | 333 | 'value' => 'yes' === Wordlift_Configuration_Service::get_instance()->get_diagnostic_preferences() ? 'yes' : 'no', |
334 | - 'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ), |
|
334 | + 'description' => __('Whether to send diagnostic data or not.', 'wordlift'), |
|
335 | 335 | ) |
336 | 336 | ); |
337 | 337 | |
@@ -346,10 +346,10 @@ discard block |
||
346 | 346 | * @return array The updated array. |
347 | 347 | * @since 3.17.0 |
348 | 348 | */ |
349 | - public function entity_path_input_element_params( $args ) { |
|
349 | + public function entity_path_input_element_params($args) { |
|
350 | 350 | |
351 | 351 | // Bail out if it's not the `wl-entity-base-path`). |
352 | - if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
352 | + if ('wl-entity-base-path' !== $args['id']) { |
|
353 | 353 | return $args; |
354 | 354 | } |
355 | 355 | |
@@ -371,22 +371,22 @@ discard block |
||
371 | 371 | * @return array The sanitized input array. |
372 | 372 | * @since 3.11.0 |
373 | 373 | */ |
374 | - public function sanitize_callback( $input ) { |
|
374 | + public function sanitize_callback($input) { |
|
375 | 375 | // No nonce verification since this callback is handled by settings api. |
376 | 376 | // Check whether a publisher name has been set. |
377 | 377 | // phpcs:ignore Standard.Category.SniffName.ErrorCode |
378 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
379 | - $name = isset( $_POST['wl_publisher']['name'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['wl_publisher']['name'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
380 | - $type = isset( $_POST['wl_publisher']['type'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['wl_publisher']['type'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
378 | + if (isset($_POST['wl_publisher']) && ! empty($_POST['wl_publisher']['name'])) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
379 | + $name = isset($_POST['wl_publisher']['name']) ? sanitize_text_field(wp_unslash((string) $_POST['wl_publisher']['name'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
380 | + $type = isset($_POST['wl_publisher']['type']) ? sanitize_text_field(wp_unslash((string) $_POST['wl_publisher']['type'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
381 | 381 | // phpcs:ignore Standard.Category.SniffName.ErrorCode |
382 | - $thumbnail_id = isset( $_POST['wl_publisher']['thumbnail_id'] ) ? sanitize_text_field( wp_unslash( $_POST['wl_publisher']['thumbnail_id'] ) ) : null; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
382 | + $thumbnail_id = isset($_POST['wl_publisher']['thumbnail_id']) ? sanitize_text_field(wp_unslash($_POST['wl_publisher']['thumbnail_id'])) : null; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
383 | 383 | |
384 | 384 | // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
385 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
385 | + $type_uri = sprintf('http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person'); |
|
386 | 386 | |
387 | 387 | // Create an entity for the publisher and assign it to the input |
388 | 388 | // parameter which WordPress automatically saves into the settings. |
389 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
389 | + $input['publisher_id'] = $this->entity_service->create($name, $type_uri, $thumbnail_id, 'publish'); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | return $input; |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | */ |
14 | 14 | |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -28,107 +28,107 @@ discard block |
||
28 | 28 | */ |
29 | 29 | class Wordlift_Admin_Entity_Taxonomy_List_Page { |
30 | 30 | |
31 | - /** |
|
32 | - * Hook to `wl_entity_type_row_actions` to add an "action" link to Thread |
|
33 | - * SEO related settings for the term. |
|
34 | - * |
|
35 | - * @see https://developer.wordpress.org/reference/hooks/taxonomy_row_actions/ |
|
36 | - * |
|
37 | - * @since 3.11.0 |
|
38 | - * |
|
39 | - * @param array $actions An array of action links to be displayed. Default |
|
40 | - * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
|
41 | - * @param object $term Term object. |
|
42 | - * |
|
43 | - * @return array $actions An array of action links to be displayed. Default |
|
44 | - * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
|
45 | - */ |
|
46 | - public function wl_entity_type_row_actions( $actions, $term ) { |
|
47 | - |
|
48 | - $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id" ); |
|
49 | - $actions['wl-seo'] = '<a href="' . esc_url( $url ) . '">' . __( 'SEO Settings', 'wordlift' ) . '</a>'; |
|
50 | - |
|
51 | - // Hacks for pre 4.7 compatibility: |
|
52 | - // * remove the quick edit. |
|
53 | - unset( $actions['inline hide-if-no-js'] ); |
|
54 | - // * remove the edit link. |
|
55 | - unset( $actions['edit'] ); |
|
56 | - |
|
57 | - return $actions; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Override the capabilities related to managing the entity type terms |
|
62 | - * for multisite super admin to prevent it from manipulating it in any |
|
63 | - * way. |
|
64 | - * |
|
65 | - * @since 3.12.0 |
|
66 | - * |
|
67 | - * @param array $caps The user's current capabilities. |
|
68 | - * @param string $cap Capability name. |
|
69 | - * |
|
70 | - * @return array Array containing the do_not_allow capability for super admin |
|
71 | - * when editing and deleting entity type terms capabilities |
|
72 | - * are being "approved" |
|
73 | - */ |
|
74 | - public function restrict_super_admin( $caps, $cap ) { |
|
75 | - |
|
76 | - switch ( $cap ) { |
|
77 | - case 'wl_entity_type_edit_term': |
|
78 | - case 'wl_entity_type_delete_term': |
|
79 | - $caps[] = 'do_not_allow'; |
|
80 | - } |
|
81 | - |
|
82 | - return $caps; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Override the capabilities related to managing the entity type terms |
|
87 | - * required for WordPress < 4.7 to get access to the admin page. |
|
88 | - * |
|
89 | - * Before 4.7, WordPress checks whether the user has permission to access |
|
90 | - * the `edit-tags.php` page. So we need to provide temporary the permission |
|
91 | - * otherwise the user will get an `access not allowed` when trying to access |
|
92 | - * the page. |
|
93 | - * |
|
94 | - * @see https://github.com/insideout10/wordlift-plugin/issues/512 |
|
95 | - * |
|
96 | - * @since 3.12.0 |
|
97 | - * |
|
98 | - * @param array $caps The user's current capabilities. |
|
99 | - * @param string $cap Capability name. |
|
100 | - * |
|
101 | - * @return array Array containing the manage_options capability |
|
102 | - */ |
|
103 | - public function enable_admin_access_pre_47( $caps, $cap ) { |
|
104 | - |
|
105 | - // Bail out if we're not dealing with the `wl_entity_type_edit_term` |
|
106 | - // capability. |
|
107 | - if ( 'wl_entity_type_edit_term' !== $cap || ! isset( $_SERVER['REQUEST_URI'] ) ) { |
|
108 | - return $caps; |
|
109 | - } |
|
110 | - |
|
111 | - $path = wp_parse_url( esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) ) ); |
|
112 | - |
|
113 | - // Bail out if the `path` cannot be determined. |
|
114 | - if ( null === $path ) { |
|
115 | - return $caps; |
|
116 | - } |
|
117 | - |
|
118 | - // Bail out if a specific term is being handled. |
|
119 | - if ( isset( $_REQUEST['action'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
120 | - return $caps; |
|
121 | - } |
|
122 | - |
|
123 | - // Split the path and check if the page is the `edit-tags.php`. We can't |
|
124 | - // use WP's own function because this is called very early. |
|
125 | - $components = explode( '/', $path ); |
|
126 | - if ( 'edit-tags.php' !== $components[ count( $components ) - 1 ] ) { |
|
127 | - return $caps; |
|
128 | - } |
|
129 | - |
|
130 | - // Give permission to the user. |
|
131 | - return array( 'manage_options' ); |
|
132 | - } |
|
31 | + /** |
|
32 | + * Hook to `wl_entity_type_row_actions` to add an "action" link to Thread |
|
33 | + * SEO related settings for the term. |
|
34 | + * |
|
35 | + * @see https://developer.wordpress.org/reference/hooks/taxonomy_row_actions/ |
|
36 | + * |
|
37 | + * @since 3.11.0 |
|
38 | + * |
|
39 | + * @param array $actions An array of action links to be displayed. Default |
|
40 | + * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
|
41 | + * @param object $term Term object. |
|
42 | + * |
|
43 | + * @return array $actions An array of action links to be displayed. Default |
|
44 | + * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
|
45 | + */ |
|
46 | + public function wl_entity_type_row_actions( $actions, $term ) { |
|
47 | + |
|
48 | + $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id" ); |
|
49 | + $actions['wl-seo'] = '<a href="' . esc_url( $url ) . '">' . __( 'SEO Settings', 'wordlift' ) . '</a>'; |
|
50 | + |
|
51 | + // Hacks for pre 4.7 compatibility: |
|
52 | + // * remove the quick edit. |
|
53 | + unset( $actions['inline hide-if-no-js'] ); |
|
54 | + // * remove the edit link. |
|
55 | + unset( $actions['edit'] ); |
|
56 | + |
|
57 | + return $actions; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Override the capabilities related to managing the entity type terms |
|
62 | + * for multisite super admin to prevent it from manipulating it in any |
|
63 | + * way. |
|
64 | + * |
|
65 | + * @since 3.12.0 |
|
66 | + * |
|
67 | + * @param array $caps The user's current capabilities. |
|
68 | + * @param string $cap Capability name. |
|
69 | + * |
|
70 | + * @return array Array containing the do_not_allow capability for super admin |
|
71 | + * when editing and deleting entity type terms capabilities |
|
72 | + * are being "approved" |
|
73 | + */ |
|
74 | + public function restrict_super_admin( $caps, $cap ) { |
|
75 | + |
|
76 | + switch ( $cap ) { |
|
77 | + case 'wl_entity_type_edit_term': |
|
78 | + case 'wl_entity_type_delete_term': |
|
79 | + $caps[] = 'do_not_allow'; |
|
80 | + } |
|
81 | + |
|
82 | + return $caps; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Override the capabilities related to managing the entity type terms |
|
87 | + * required for WordPress < 4.7 to get access to the admin page. |
|
88 | + * |
|
89 | + * Before 4.7, WordPress checks whether the user has permission to access |
|
90 | + * the `edit-tags.php` page. So we need to provide temporary the permission |
|
91 | + * otherwise the user will get an `access not allowed` when trying to access |
|
92 | + * the page. |
|
93 | + * |
|
94 | + * @see https://github.com/insideout10/wordlift-plugin/issues/512 |
|
95 | + * |
|
96 | + * @since 3.12.0 |
|
97 | + * |
|
98 | + * @param array $caps The user's current capabilities. |
|
99 | + * @param string $cap Capability name. |
|
100 | + * |
|
101 | + * @return array Array containing the manage_options capability |
|
102 | + */ |
|
103 | + public function enable_admin_access_pre_47( $caps, $cap ) { |
|
104 | + |
|
105 | + // Bail out if we're not dealing with the `wl_entity_type_edit_term` |
|
106 | + // capability. |
|
107 | + if ( 'wl_entity_type_edit_term' !== $cap || ! isset( $_SERVER['REQUEST_URI'] ) ) { |
|
108 | + return $caps; |
|
109 | + } |
|
110 | + |
|
111 | + $path = wp_parse_url( esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) ) ); |
|
112 | + |
|
113 | + // Bail out if the `path` cannot be determined. |
|
114 | + if ( null === $path ) { |
|
115 | + return $caps; |
|
116 | + } |
|
117 | + |
|
118 | + // Bail out if a specific term is being handled. |
|
119 | + if ( isset( $_REQUEST['action'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
120 | + return $caps; |
|
121 | + } |
|
122 | + |
|
123 | + // Split the path and check if the page is the `edit-tags.php`. We can't |
|
124 | + // use WP's own function because this is called very early. |
|
125 | + $components = explode( '/', $path ); |
|
126 | + if ( 'edit-tags.php' !== $components[ count( $components ) - 1 ] ) { |
|
127 | + return $caps; |
|
128 | + } |
|
129 | + |
|
130 | + // Give permission to the user. |
|
131 | + return array( 'manage_options' ); |
|
132 | + } |
|
133 | 133 | |
134 | 134 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @since 3.11.0 |
13 | 13 | */ |
14 | 14 | |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -43,16 +43,16 @@ discard block |
||
43 | 43 | * @return array $actions An array of action links to be displayed. Default |
44 | 44 | * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
45 | 45 | */ |
46 | - public function wl_entity_type_row_actions( $actions, $term ) { |
|
46 | + public function wl_entity_type_row_actions($actions, $term) { |
|
47 | 47 | |
48 | - $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id" ); |
|
49 | - $actions['wl-seo'] = '<a href="' . esc_url( $url ) . '">' . __( 'SEO Settings', 'wordlift' ) . '</a>'; |
|
48 | + $url = admin_url("admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id"); |
|
49 | + $actions['wl-seo'] = '<a href="'.esc_url($url).'">'.__('SEO Settings', 'wordlift').'</a>'; |
|
50 | 50 | |
51 | 51 | // Hacks for pre 4.7 compatibility: |
52 | 52 | // * remove the quick edit. |
53 | - unset( $actions['inline hide-if-no-js'] ); |
|
53 | + unset($actions['inline hide-if-no-js']); |
|
54 | 54 | // * remove the edit link. |
55 | - unset( $actions['edit'] ); |
|
55 | + unset($actions['edit']); |
|
56 | 56 | |
57 | 57 | return $actions; |
58 | 58 | } |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | * when editing and deleting entity type terms capabilities |
72 | 72 | * are being "approved" |
73 | 73 | */ |
74 | - public function restrict_super_admin( $caps, $cap ) { |
|
74 | + public function restrict_super_admin($caps, $cap) { |
|
75 | 75 | |
76 | - switch ( $cap ) { |
|
76 | + switch ($cap) { |
|
77 | 77 | case 'wl_entity_type_edit_term': |
78 | 78 | case 'wl_entity_type_delete_term': |
79 | 79 | $caps[] = 'do_not_allow'; |
@@ -100,35 +100,35 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @return array Array containing the manage_options capability |
102 | 102 | */ |
103 | - public function enable_admin_access_pre_47( $caps, $cap ) { |
|
103 | + public function enable_admin_access_pre_47($caps, $cap) { |
|
104 | 104 | |
105 | 105 | // Bail out if we're not dealing with the `wl_entity_type_edit_term` |
106 | 106 | // capability. |
107 | - if ( 'wl_entity_type_edit_term' !== $cap || ! isset( $_SERVER['REQUEST_URI'] ) ) { |
|
107 | + if ('wl_entity_type_edit_term' !== $cap || ! isset($_SERVER['REQUEST_URI'])) { |
|
108 | 108 | return $caps; |
109 | 109 | } |
110 | 110 | |
111 | - $path = wp_parse_url( esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) ) ); |
|
111 | + $path = wp_parse_url(esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'], PHP_URL_PATH))); |
|
112 | 112 | |
113 | 113 | // Bail out if the `path` cannot be determined. |
114 | - if ( null === $path ) { |
|
114 | + if (null === $path) { |
|
115 | 115 | return $caps; |
116 | 116 | } |
117 | 117 | |
118 | 118 | // Bail out if a specific term is being handled. |
119 | - if ( isset( $_REQUEST['action'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
119 | + if (isset($_REQUEST['action'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
120 | 120 | return $caps; |
121 | 121 | } |
122 | 122 | |
123 | 123 | // Split the path and check if the page is the `edit-tags.php`. We can't |
124 | 124 | // use WP's own function because this is called very early. |
125 | - $components = explode( '/', $path ); |
|
126 | - if ( 'edit-tags.php' !== $components[ count( $components ) - 1 ] ) { |
|
125 | + $components = explode('/', $path); |
|
126 | + if ('edit-tags.php' !== $components[count($components) - 1]) { |
|
127 | 127 | return $caps; |
128 | 128 | } |
129 | 129 | |
130 | 130 | // Give permission to the user. |
131 | - return array( 'manage_options' ); |
|
131 | + return array('manage_options'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | */ |
14 | 14 | |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -30,217 +30,217 @@ discard block |
||
30 | 30 | */ |
31 | 31 | class Wordlift_Admin_Entity_Type_Settings { |
32 | 32 | |
33 | - /** |
|
34 | - * A {@link Wordlift_Log_Service} instance. |
|
35 | - * |
|
36 | - * @since 3.14.0 |
|
37 | - * @access private |
|
38 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
39 | - */ |
|
40 | - private $log; |
|
41 | - |
|
42 | - /** |
|
43 | - * Create a {@link Wordlift_Admin_Entity_Type_Settings} instance. |
|
44 | - * |
|
45 | - * @since 3.14.0 |
|
46 | - */ |
|
47 | - public function __construct() { |
|
48 | - |
|
49 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Admin_Entity_Type_Settings' ); |
|
50 | - |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Handle menu registration. |
|
55 | - * |
|
56 | - * The registration is required, although we do not want to actually to add |
|
57 | - * an item to the menu, in order to "whitelist" the access to the settings page in |
|
58 | - * the admin. |
|
59 | - * |
|
60 | - * @since 3.11.0 |
|
61 | - */ |
|
62 | - public function admin_menu() { |
|
63 | - |
|
64 | - /* |
|
33 | + /** |
|
34 | + * A {@link Wordlift_Log_Service} instance. |
|
35 | + * |
|
36 | + * @since 3.14.0 |
|
37 | + * @access private |
|
38 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
39 | + */ |
|
40 | + private $log; |
|
41 | + |
|
42 | + /** |
|
43 | + * Create a {@link Wordlift_Admin_Entity_Type_Settings} instance. |
|
44 | + * |
|
45 | + * @since 3.14.0 |
|
46 | + */ |
|
47 | + public function __construct() { |
|
48 | + |
|
49 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Admin_Entity_Type_Settings' ); |
|
50 | + |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Handle menu registration. |
|
55 | + * |
|
56 | + * The registration is required, although we do not want to actually to add |
|
57 | + * an item to the menu, in order to "whitelist" the access to the settings page in |
|
58 | + * the admin. |
|
59 | + * |
|
60 | + * @since 3.11.0 |
|
61 | + */ |
|
62 | + public function admin_menu() { |
|
63 | + |
|
64 | + /* |
|
65 | 65 | * Before anything else check if an settings form was submitted. |
66 | 66 | * This has to be done before any output happens in order to be able to |
67 | 67 | * display proper "die" error messages and redirect. |
68 | 68 | */ |
69 | - if ( isset( $_GET['page'] ) && ( 'wl_entity_type_settings' === $_GET['page'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
70 | - |
|
71 | - // Validate inputs. Do not return on invalid parameters or capabilities. |
|
72 | - $this->validate_proper_term(); |
|
73 | - |
|
74 | - // If proper form submission, handle it and redirect back to the settings page. |
|
75 | - if ( isset( $_POST['action'] ) && ( 'wl_edit_entity_type_term' === $_POST['action'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
76 | - $this->handle_form_submission(); |
|
77 | - } |
|
78 | - /** |
|
79 | - * Filter: wl_feature__enable__notices. |
|
80 | - * |
|
81 | - * @param bool whether the notices needs to be enabled or not. |
|
82 | - * |
|
83 | - * @return bool |
|
84 | - * @since 3.27.6 |
|
85 | - */ |
|
86 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
87 | - // Register admin notices handler. |
|
88 | - add_action( 'admin_notices', array( $this, 'admin_notice' ) ); |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - /* |
|
69 | + if ( isset( $_GET['page'] ) && ( 'wl_entity_type_settings' === $_GET['page'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
70 | + |
|
71 | + // Validate inputs. Do not return on invalid parameters or capabilities. |
|
72 | + $this->validate_proper_term(); |
|
73 | + |
|
74 | + // If proper form submission, handle it and redirect back to the settings page. |
|
75 | + if ( isset( $_POST['action'] ) && ( 'wl_edit_entity_type_term' === $_POST['action'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
76 | + $this->handle_form_submission(); |
|
77 | + } |
|
78 | + /** |
|
79 | + * Filter: wl_feature__enable__notices. |
|
80 | + * |
|
81 | + * @param bool whether the notices needs to be enabled or not. |
|
82 | + * |
|
83 | + * @return bool |
|
84 | + * @since 3.27.6 |
|
85 | + */ |
|
86 | + if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
87 | + // Register admin notices handler. |
|
88 | + add_action( 'admin_notices', array( $this, 'admin_notice' ) ); |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + /* |
|
93 | 93 | * Use a null parent slug to prevent the menu from actually appearing |
94 | 94 | * in the admin menu. |
95 | 95 | */ |
96 | - // @todo: use the new {@link Wordlift_Admin_Page}. |
|
97 | - add_submenu_page( |
|
98 | - null, |
|
99 | - __( 'Edit Entity term', 'wordlift' ), |
|
100 | - __( 'Edit Entity term', 'wordlift' ), |
|
101 | - 'manage_options', |
|
102 | - 'wl_entity_type_settings', |
|
103 | - array( $this, 'render' ) |
|
104 | - ); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Output admin notices if needed, based on the message url parameter. |
|
109 | - * A value of 1 indicates that a successful save was done. |
|
110 | - * |
|
111 | - * @since 3.11.0 |
|
112 | - */ |
|
113 | - public function admin_notice() { |
|
114 | - if ( isset( $_GET['message'] ) && ( '1' === $_GET['message'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
115 | - ?> |
|
96 | + // @todo: use the new {@link Wordlift_Admin_Page}. |
|
97 | + add_submenu_page( |
|
98 | + null, |
|
99 | + __( 'Edit Entity term', 'wordlift' ), |
|
100 | + __( 'Edit Entity term', 'wordlift' ), |
|
101 | + 'manage_options', |
|
102 | + 'wl_entity_type_settings', |
|
103 | + array( $this, 'render' ) |
|
104 | + ); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Output admin notices if needed, based on the message url parameter. |
|
109 | + * A value of 1 indicates that a successful save was done. |
|
110 | + * |
|
111 | + * @since 3.11.0 |
|
112 | + */ |
|
113 | + public function admin_notice() { |
|
114 | + if ( isset( $_GET['message'] ) && ( '1' === $_GET['message'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
115 | + ?> |
|
116 | 116 | <div class="notice notice-success is-dismissible"> |
117 | 117 | <p><?php esc_html_e( 'Settings saved', 'wordlift' ); ?></p> |
118 | 118 | </div> |
119 | 119 | <?php |
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Validate the existence of the entity type indicated by the tag_ID url |
|
125 | - * parameter before doing any processing. Done before any output to mimic |
|
126 | - * the way WordPress handles same situation with "normal" term editing screens. |
|
127 | - * |
|
128 | - * @since 3.11.0 |
|
129 | - */ |
|
130 | - public function validate_proper_term() { |
|
131 | - |
|
132 | - // Validate capabilities. |
|
133 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
134 | - wp_die( |
|
135 | - '<h1>' . esc_html__( 'Cheatin’ uh?', 'default' ) . '</h1>' . |
|
136 | - '<p>' . esc_html__( 'Sorry, you are not allowed to edit this item.', 'default' ) . '</p>', |
|
137 | - 403 |
|
138 | - ); |
|
139 | - } |
|
140 | - |
|
141 | - // Get the term id and the actual term. |
|
142 | - $term_id = isset( $_REQUEST['tag_ID'] ) ? (int) $_REQUEST['tag_ID'] : 0; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
143 | - |
|
144 | - if ( ! term_exists( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) ) { |
|
145 | - wp_die( esc_html__( 'You attempted to edit an entity type term that doesn’t exist.', 'wordlift' ) ); |
|
146 | - } |
|
147 | - |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Handle the form submission of the settings form. On successful |
|
152 | - * handling redirect tp the setting edit page. |
|
153 | - * |
|
154 | - * @since 3.11.0 |
|
155 | - */ |
|
156 | - public function handle_form_submission() { |
|
157 | - |
|
158 | - $term_id = isset( $_POST['tag_ID'] ) ? (int) $_POST['tag_ID'] : 0; |
|
159 | - |
|
160 | - // Check the nonce. |
|
161 | - check_admin_referer( 'update-entity_type_term_' . $term_id ); |
|
162 | - |
|
163 | - $term = get_term( $term_id, 'wl_entity_type' ); |
|
164 | - |
|
165 | - $title = isset( $_POST['title'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['title'] ) ) : ''; |
|
166 | - $description = isset( $_POST['description'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['description'] ) ) : ''; |
|
167 | - $this->set_setting( |
|
168 | - $term_id, |
|
169 | - trim( wp_unslash( $title ) ), |
|
170 | - wp_unslash( $description ) |
|
171 | - ); |
|
172 | - |
|
173 | - // Redirect back to the term settings page and indicate a save was done. |
|
174 | - $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1" ); |
|
175 | - |
|
176 | - wp_safe_redirect( $url ); |
|
177 | - exit(); |
|
178 | - |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Render the settings page for the term. |
|
183 | - * |
|
184 | - * Access and parameter validity is assumed to be done earlier. |
|
185 | - * |
|
186 | - * @since 3.11.0 |
|
187 | - */ |
|
188 | - public function render() { |
|
189 | - |
|
190 | - // Set variables used by the partial |
|
191 | - $term_id = isset( $_REQUEST['tag_ID'] ) ? absint( $_REQUEST['tag_ID'] ) : 0; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Validate the existence of the entity type indicated by the tag_ID url |
|
125 | + * parameter before doing any processing. Done before any output to mimic |
|
126 | + * the way WordPress handles same situation with "normal" term editing screens. |
|
127 | + * |
|
128 | + * @since 3.11.0 |
|
129 | + */ |
|
130 | + public function validate_proper_term() { |
|
131 | + |
|
132 | + // Validate capabilities. |
|
133 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
134 | + wp_die( |
|
135 | + '<h1>' . esc_html__( 'Cheatin’ uh?', 'default' ) . '</h1>' . |
|
136 | + '<p>' . esc_html__( 'Sorry, you are not allowed to edit this item.', 'default' ) . '</p>', |
|
137 | + 403 |
|
138 | + ); |
|
139 | + } |
|
140 | + |
|
141 | + // Get the term id and the actual term. |
|
142 | + $term_id = isset( $_REQUEST['tag_ID'] ) ? (int) $_REQUEST['tag_ID'] : 0; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
143 | + |
|
144 | + if ( ! term_exists( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) ) { |
|
145 | + wp_die( esc_html__( 'You attempted to edit an entity type term that doesn’t exist.', 'wordlift' ) ); |
|
146 | + } |
|
147 | + |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Handle the form submission of the settings form. On successful |
|
152 | + * handling redirect tp the setting edit page. |
|
153 | + * |
|
154 | + * @since 3.11.0 |
|
155 | + */ |
|
156 | + public function handle_form_submission() { |
|
157 | + |
|
158 | + $term_id = isset( $_POST['tag_ID'] ) ? (int) $_POST['tag_ID'] : 0; |
|
159 | + |
|
160 | + // Check the nonce. |
|
161 | + check_admin_referer( 'update-entity_type_term_' . $term_id ); |
|
162 | + |
|
163 | + $term = get_term( $term_id, 'wl_entity_type' ); |
|
164 | + |
|
165 | + $title = isset( $_POST['title'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['title'] ) ) : ''; |
|
166 | + $description = isset( $_POST['description'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['description'] ) ) : ''; |
|
167 | + $this->set_setting( |
|
168 | + $term_id, |
|
169 | + trim( wp_unslash( $title ) ), |
|
170 | + wp_unslash( $description ) |
|
171 | + ); |
|
172 | + |
|
173 | + // Redirect back to the term settings page and indicate a save was done. |
|
174 | + $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1" ); |
|
175 | + |
|
176 | + wp_safe_redirect( $url ); |
|
177 | + exit(); |
|
178 | + |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Render the settings page for the term. |
|
183 | + * |
|
184 | + * Access and parameter validity is assumed to be done earlier. |
|
185 | + * |
|
186 | + * @since 3.11.0 |
|
187 | + */ |
|
188 | + public function render() { |
|
189 | + |
|
190 | + // Set variables used by the partial |
|
191 | + $term_id = isset( $_REQUEST['tag_ID'] ) ? absint( $_REQUEST['tag_ID'] ) : 0; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
192 | 192 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
193 | - $settings = $this->get_setting( $term_id ); |
|
194 | - |
|
195 | - include plugin_dir_path( __DIR__ ) . 'admin/partials/wordlift-admin-entity-type-settings.php'; |
|
196 | - |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Store the entity type term settings in the DB |
|
201 | - * |
|
202 | - * @param integer $term_id The ID of the entity type term |
|
203 | - * @param string $title The override for the terms title. |
|
204 | - * @param string $description The override for the terms description. |
|
205 | - * |
|
206 | - * @since 3.11.0 |
|
207 | - */ |
|
208 | - public function set_setting( $term_id, $title, $description ) { |
|
209 | - |
|
210 | - $settings = get_option( 'wl_entity_type_settings', array() ); |
|
211 | - $settings[ $term_id ] = array( |
|
212 | - 'title' => $title, |
|
213 | - 'description' => $description, |
|
214 | - ); |
|
215 | - update_option( 'wl_entity_type_settings', $settings ); |
|
216 | - |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Retrieve the entity type term settings from the DB |
|
221 | - * |
|
222 | - * @param integer $term_id The ID of the entity type term |
|
223 | - * |
|
224 | - * @return null|array { |
|
225 | - * null is returned when there are no settings otherwise |
|
226 | - * an array is returned with following fields |
|
227 | - * |
|
228 | - * @type string title The overriding title for the term |
|
229 | - * @type string description The overriding description for the term |
|
230 | - * } |
|
231 | - * @since 3.11.0 |
|
232 | - */ |
|
233 | - public function get_setting( $term_id ) { |
|
234 | - |
|
235 | - $settings = get_option( 'wl_entity_type_settings', array() ); |
|
236 | - |
|
237 | - if ( isset( $settings[ $term_id ] ) ) { |
|
238 | - return $settings[ $term_id ]; |
|
239 | - } |
|
240 | - |
|
241 | - $this->log->warn( "No settings found for term id $term_id." ); |
|
242 | - |
|
243 | - return null; |
|
244 | - } |
|
193 | + $settings = $this->get_setting( $term_id ); |
|
194 | + |
|
195 | + include plugin_dir_path( __DIR__ ) . 'admin/partials/wordlift-admin-entity-type-settings.php'; |
|
196 | + |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Store the entity type term settings in the DB |
|
201 | + * |
|
202 | + * @param integer $term_id The ID of the entity type term |
|
203 | + * @param string $title The override for the terms title. |
|
204 | + * @param string $description The override for the terms description. |
|
205 | + * |
|
206 | + * @since 3.11.0 |
|
207 | + */ |
|
208 | + public function set_setting( $term_id, $title, $description ) { |
|
209 | + |
|
210 | + $settings = get_option( 'wl_entity_type_settings', array() ); |
|
211 | + $settings[ $term_id ] = array( |
|
212 | + 'title' => $title, |
|
213 | + 'description' => $description, |
|
214 | + ); |
|
215 | + update_option( 'wl_entity_type_settings', $settings ); |
|
216 | + |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Retrieve the entity type term settings from the DB |
|
221 | + * |
|
222 | + * @param integer $term_id The ID of the entity type term |
|
223 | + * |
|
224 | + * @return null|array { |
|
225 | + * null is returned when there are no settings otherwise |
|
226 | + * an array is returned with following fields |
|
227 | + * |
|
228 | + * @type string title The overriding title for the term |
|
229 | + * @type string description The overriding description for the term |
|
230 | + * } |
|
231 | + * @since 3.11.0 |
|
232 | + */ |
|
233 | + public function get_setting( $term_id ) { |
|
234 | + |
|
235 | + $settings = get_option( 'wl_entity_type_settings', array() ); |
|
236 | + |
|
237 | + if ( isset( $settings[ $term_id ] ) ) { |
|
238 | + return $settings[ $term_id ]; |
|
239 | + } |
|
240 | + |
|
241 | + $this->log->warn( "No settings found for term id $term_id." ); |
|
242 | + |
|
243 | + return null; |
|
244 | + } |
|
245 | 245 | |
246 | 246 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @since 3.11.0 |
13 | 13 | */ |
14 | 14 | |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function __construct() { |
48 | 48 | |
49 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Admin_Entity_Type_Settings' ); |
|
49 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Admin_Entity_Type_Settings'); |
|
50 | 50 | |
51 | 51 | } |
52 | 52 | |
@@ -66,13 +66,13 @@ discard block |
||
66 | 66 | * This has to be done before any output happens in order to be able to |
67 | 67 | * display proper "die" error messages and redirect. |
68 | 68 | */ |
69 | - if ( isset( $_GET['page'] ) && ( 'wl_entity_type_settings' === $_GET['page'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
69 | + if (isset($_GET['page']) && ('wl_entity_type_settings' === $_GET['page'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
70 | 70 | |
71 | 71 | // Validate inputs. Do not return on invalid parameters or capabilities. |
72 | 72 | $this->validate_proper_term(); |
73 | 73 | |
74 | 74 | // If proper form submission, handle it and redirect back to the settings page. |
75 | - if ( isset( $_POST['action'] ) && ( 'wl_edit_entity_type_term' === $_POST['action'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
75 | + if (isset($_POST['action']) && ('wl_edit_entity_type_term' === $_POST['action'])) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
76 | 76 | $this->handle_form_submission(); |
77 | 77 | } |
78 | 78 | /** |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * @return bool |
84 | 84 | * @since 3.27.6 |
85 | 85 | */ |
86 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
86 | + if (apply_filters('wl_feature__enable__notices', true)) { |
|
87 | 87 | // Register admin notices handler. |
88 | - add_action( 'admin_notices', array( $this, 'admin_notice' ) ); |
|
88 | + add_action('admin_notices', array($this, 'admin_notice')); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | // @todo: use the new {@link Wordlift_Admin_Page}. |
97 | 97 | add_submenu_page( |
98 | 98 | null, |
99 | - __( 'Edit Entity term', 'wordlift' ), |
|
100 | - __( 'Edit Entity term', 'wordlift' ), |
|
99 | + __('Edit Entity term', 'wordlift'), |
|
100 | + __('Edit Entity term', 'wordlift'), |
|
101 | 101 | 'manage_options', |
102 | 102 | 'wl_entity_type_settings', |
103 | - array( $this, 'render' ) |
|
103 | + array($this, 'render') |
|
104 | 104 | ); |
105 | 105 | } |
106 | 106 | |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | * @since 3.11.0 |
112 | 112 | */ |
113 | 113 | public function admin_notice() { |
114 | - if ( isset( $_GET['message'] ) && ( '1' === $_GET['message'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
114 | + if (isset($_GET['message']) && ('1' === $_GET['message'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
115 | 115 | ?> |
116 | 116 | <div class="notice notice-success is-dismissible"> |
117 | - <p><?php esc_html_e( 'Settings saved', 'wordlift' ); ?></p> |
|
117 | + <p><?php esc_html_e('Settings saved', 'wordlift'); ?></p> |
|
118 | 118 | </div> |
119 | 119 | <?php |
120 | 120 | } |
@@ -130,19 +130,19 @@ discard block |
||
130 | 130 | public function validate_proper_term() { |
131 | 131 | |
132 | 132 | // Validate capabilities. |
133 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
133 | + if ( ! current_user_can('manage_options')) { |
|
134 | 134 | wp_die( |
135 | - '<h1>' . esc_html__( 'Cheatin’ uh?', 'default' ) . '</h1>' . |
|
136 | - '<p>' . esc_html__( 'Sorry, you are not allowed to edit this item.', 'default' ) . '</p>', |
|
135 | + '<h1>'.esc_html__('Cheatin’ uh?', 'default').'</h1>'. |
|
136 | + '<p>'.esc_html__('Sorry, you are not allowed to edit this item.', 'default').'</p>', |
|
137 | 137 | 403 |
138 | 138 | ); |
139 | 139 | } |
140 | 140 | |
141 | 141 | // Get the term id and the actual term. |
142 | - $term_id = isset( $_REQUEST['tag_ID'] ) ? (int) $_REQUEST['tag_ID'] : 0; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
142 | + $term_id = isset($_REQUEST['tag_ID']) ? (int) $_REQUEST['tag_ID'] : 0; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
143 | 143 | |
144 | - if ( ! term_exists( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) ) { |
|
145 | - wp_die( esc_html__( 'You attempted to edit an entity type term that doesn’t exist.', 'wordlift' ) ); |
|
144 | + if ( ! term_exists($term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME)) { |
|
145 | + wp_die(esc_html__('You attempted to edit an entity type term that doesn’t exist.', 'wordlift')); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | } |
@@ -155,25 +155,25 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public function handle_form_submission() { |
157 | 157 | |
158 | - $term_id = isset( $_POST['tag_ID'] ) ? (int) $_POST['tag_ID'] : 0; |
|
158 | + $term_id = isset($_POST['tag_ID']) ? (int) $_POST['tag_ID'] : 0; |
|
159 | 159 | |
160 | 160 | // Check the nonce. |
161 | - check_admin_referer( 'update-entity_type_term_' . $term_id ); |
|
161 | + check_admin_referer('update-entity_type_term_'.$term_id); |
|
162 | 162 | |
163 | - $term = get_term( $term_id, 'wl_entity_type' ); |
|
163 | + $term = get_term($term_id, 'wl_entity_type'); |
|
164 | 164 | |
165 | - $title = isset( $_POST['title'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['title'] ) ) : ''; |
|
166 | - $description = isset( $_POST['description'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['description'] ) ) : ''; |
|
165 | + $title = isset($_POST['title']) ? sanitize_text_field(wp_unslash((string) $_POST['title'])) : ''; |
|
166 | + $description = isset($_POST['description']) ? sanitize_text_field(wp_unslash((string) $_POST['description'])) : ''; |
|
167 | 167 | $this->set_setting( |
168 | 168 | $term_id, |
169 | - trim( wp_unslash( $title ) ), |
|
170 | - wp_unslash( $description ) |
|
169 | + trim(wp_unslash($title)), |
|
170 | + wp_unslash($description) |
|
171 | 171 | ); |
172 | 172 | |
173 | 173 | // Redirect back to the term settings page and indicate a save was done. |
174 | - $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1" ); |
|
174 | + $url = admin_url("admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1"); |
|
175 | 175 | |
176 | - wp_safe_redirect( $url ); |
|
176 | + wp_safe_redirect($url); |
|
177 | 177 | exit(); |
178 | 178 | |
179 | 179 | } |
@@ -188,11 +188,11 @@ discard block |
||
188 | 188 | public function render() { |
189 | 189 | |
190 | 190 | // Set variables used by the partial |
191 | - $term_id = isset( $_REQUEST['tag_ID'] ) ? absint( $_REQUEST['tag_ID'] ) : 0; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
191 | + $term_id = isset($_REQUEST['tag_ID']) ? absint($_REQUEST['tag_ID']) : 0; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
192 | 192 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
193 | - $settings = $this->get_setting( $term_id ); |
|
193 | + $settings = $this->get_setting($term_id); |
|
194 | 194 | |
195 | - include plugin_dir_path( __DIR__ ) . 'admin/partials/wordlift-admin-entity-type-settings.php'; |
|
195 | + include plugin_dir_path(__DIR__).'admin/partials/wordlift-admin-entity-type-settings.php'; |
|
196 | 196 | |
197 | 197 | } |
198 | 198 | |
@@ -205,14 +205,14 @@ discard block |
||
205 | 205 | * |
206 | 206 | * @since 3.11.0 |
207 | 207 | */ |
208 | - public function set_setting( $term_id, $title, $description ) { |
|
208 | + public function set_setting($term_id, $title, $description) { |
|
209 | 209 | |
210 | - $settings = get_option( 'wl_entity_type_settings', array() ); |
|
211 | - $settings[ $term_id ] = array( |
|
210 | + $settings = get_option('wl_entity_type_settings', array()); |
|
211 | + $settings[$term_id] = array( |
|
212 | 212 | 'title' => $title, |
213 | 213 | 'description' => $description, |
214 | 214 | ); |
215 | - update_option( 'wl_entity_type_settings', $settings ); |
|
215 | + update_option('wl_entity_type_settings', $settings); |
|
216 | 216 | |
217 | 217 | } |
218 | 218 | |
@@ -230,15 +230,15 @@ discard block |
||
230 | 230 | * } |
231 | 231 | * @since 3.11.0 |
232 | 232 | */ |
233 | - public function get_setting( $term_id ) { |
|
233 | + public function get_setting($term_id) { |
|
234 | 234 | |
235 | - $settings = get_option( 'wl_entity_type_settings', array() ); |
|
235 | + $settings = get_option('wl_entity_type_settings', array()); |
|
236 | 236 | |
237 | - if ( isset( $settings[ $term_id ] ) ) { |
|
238 | - return $settings[ $term_id ]; |
|
237 | + if (isset($settings[$term_id])) { |
|
238 | + return $settings[$term_id]; |
|
239 | 239 | } |
240 | 240 | |
241 | - $this->log->warn( "No settings found for term id $term_id." ); |
|
241 | + $this->log->warn("No settings found for term id $term_id."); |
|
242 | 242 | |
243 | 243 | return null; |
244 | 244 | } |
@@ -2,60 +2,60 @@ |
||
2 | 2 | |
3 | 3 | class Wordlift_Admin_Not_Enriched_Filter { |
4 | 4 | |
5 | - const PARAMETER_NAME = 'wl_enriched'; |
|
5 | + const PARAMETER_NAME = 'wl_enriched'; |
|
6 | 6 | |
7 | - public function __construct() { |
|
7 | + public function __construct() { |
|
8 | 8 | |
9 | - // Hook to `views_edit-post`. |
|
10 | - add_filter( 'views_edit-post', array( $this, 'view_edit' ) ); |
|
9 | + // Hook to `views_edit-post`. |
|
10 | + add_filter( 'views_edit-post', array( $this, 'view_edit' ) ); |
|
11 | 11 | |
12 | - // Add the `posts_where` filter if the filter is active. |
|
13 | - if ( $this->is_filter_active() ) { |
|
14 | - add_filter( 'posts_where', array( $this, 'posts_where' ) ); |
|
15 | - } |
|
12 | + // Add the `posts_where` filter if the filter is active. |
|
13 | + if ( $this->is_filter_active() ) { |
|
14 | + add_filter( 'posts_where', array( $this, 'posts_where' ) ); |
|
15 | + } |
|
16 | 16 | |
17 | - } |
|
17 | + } |
|
18 | 18 | |
19 | - public function posts_where( $where ) { |
|
20 | - global $wpdb; |
|
19 | + public function posts_where( $where ) { |
|
20 | + global $wpdb; |
|
21 | 21 | |
22 | - return $where . |
|
23 | - " AND {$wpdb->posts}.ID NOT IN ( SELECT DISTINCT subject_id FROM {$wpdb->prefix}wl_relation_instances )"; |
|
24 | - } |
|
22 | + return $where . |
|
23 | + " AND {$wpdb->posts}.ID NOT IN ( SELECT DISTINCT subject_id FROM {$wpdb->prefix}wl_relation_instances )"; |
|
24 | + } |
|
25 | 25 | |
26 | - public function view_edit( $views ) { |
|
27 | - global $wpdb; |
|
26 | + public function view_edit( $views ) { |
|
27 | + global $wpdb; |
|
28 | 28 | |
29 | - $url = add_query_arg( |
|
30 | - array( |
|
31 | - self::PARAMETER_NAME => 'no', |
|
32 | - 'post_type' => 'post', |
|
33 | - ), |
|
34 | - 'edit.php' |
|
35 | - ); |
|
29 | + $url = add_query_arg( |
|
30 | + array( |
|
31 | + self::PARAMETER_NAME => 'no', |
|
32 | + 'post_type' => 'post', |
|
33 | + ), |
|
34 | + 'edit.php' |
|
35 | + ); |
|
36 | 36 | |
37 | - $not_enriched_count = $wpdb->get_var( |
|
38 | - " |
|
37 | + $not_enriched_count = $wpdb->get_var( |
|
38 | + " |
|
39 | 39 | SELECT COUNT( 1 ) FROM $wpdb->posts p |
40 | 40 | WHERE p.post_type = 'post' |
41 | 41 | AND p.post_status <> 'trash' |
42 | 42 | AND p.post_status <> 'auto-draft' |
43 | 43 | AND p.ID NOT IN ( SELECT DISTINCT subject_id FROM {$wpdb->prefix}wl_relation_instances ) |
44 | 44 | " |
45 | - ); |
|
45 | + ); |
|
46 | 46 | |
47 | - $link = '<a href="' |
|
48 | - . esc_url( $url ) . '"' |
|
49 | - . ( $this->is_filter_active() ? ' class="current" aria-current="page"' : '' ) |
|
50 | - . '>' . esc_html( __( 'Not enriched', 'wordlift' ) ) . '</a> (' . $not_enriched_count . ')'; |
|
47 | + $link = '<a href="' |
|
48 | + . esc_url( $url ) . '"' |
|
49 | + . ( $this->is_filter_active() ? ' class="current" aria-current="page"' : '' ) |
|
50 | + . '>' . esc_html( __( 'Not enriched', 'wordlift' ) ) . '</a> (' . $not_enriched_count . ')'; |
|
51 | 51 | |
52 | - $views['wl_not_enriched'] = $link; |
|
52 | + $views['wl_not_enriched'] = $link; |
|
53 | 53 | |
54 | - return $views; |
|
55 | - } |
|
54 | + return $views; |
|
55 | + } |
|
56 | 56 | |
57 | - public function is_filter_active() { |
|
58 | - return 'no' === filter_input( INPUT_GET, self::PARAMETER_NAME ); |
|
59 | - } |
|
57 | + public function is_filter_active() { |
|
58 | + return 'no' === filter_input( INPUT_GET, self::PARAMETER_NAME ); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | } |
@@ -7,23 +7,23 @@ discard block |
||
7 | 7 | public function __construct() { |
8 | 8 | |
9 | 9 | // Hook to `views_edit-post`. |
10 | - add_filter( 'views_edit-post', array( $this, 'view_edit' ) ); |
|
10 | + add_filter('views_edit-post', array($this, 'view_edit')); |
|
11 | 11 | |
12 | 12 | // Add the `posts_where` filter if the filter is active. |
13 | - if ( $this->is_filter_active() ) { |
|
14 | - add_filter( 'posts_where', array( $this, 'posts_where' ) ); |
|
13 | + if ($this->is_filter_active()) { |
|
14 | + add_filter('posts_where', array($this, 'posts_where')); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | } |
18 | 18 | |
19 | - public function posts_where( $where ) { |
|
19 | + public function posts_where($where) { |
|
20 | 20 | global $wpdb; |
21 | 21 | |
22 | - return $where . |
|
22 | + return $where. |
|
23 | 23 | " AND {$wpdb->posts}.ID NOT IN ( SELECT DISTINCT subject_id FROM {$wpdb->prefix}wl_relation_instances )"; |
24 | 24 | } |
25 | 25 | |
26 | - public function view_edit( $views ) { |
|
26 | + public function view_edit($views) { |
|
27 | 27 | global $wpdb; |
28 | 28 | |
29 | 29 | $url = add_query_arg( |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | ); |
46 | 46 | |
47 | 47 | $link = '<a href="' |
48 | - . esc_url( $url ) . '"' |
|
49 | - . ( $this->is_filter_active() ? ' class="current" aria-current="page"' : '' ) |
|
50 | - . '>' . esc_html( __( 'Not enriched', 'wordlift' ) ) . '</a> (' . $not_enriched_count . ')'; |
|
48 | + . esc_url($url).'"' |
|
49 | + . ($this->is_filter_active() ? ' class="current" aria-current="page"' : '') |
|
50 | + . '>'.esc_html(__('Not enriched', 'wordlift')).'</a> ('.$not_enriched_count.')'; |
|
51 | 51 | |
52 | 52 | $views['wl_not_enriched'] = $link; |
53 | 53 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | } |
56 | 56 | |
57 | 57 | public function is_filter_active() { |
58 | - return 'no' === filter_input( INPUT_GET, self::PARAMETER_NAME ); |
|
58 | + return 'no' === filter_input(INPUT_GET, self::PARAMETER_NAME); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | } |
@@ -16,82 +16,82 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class Wordlift_Admin_Term_Adapter { |
18 | 18 | |
19 | - /** |
|
20 | - * The meta key holding the entity id. |
|
21 | - * |
|
22 | - * @since 3.20.0 |
|
23 | - */ |
|
24 | - const META_KEY = '_wl_entity_id'; |
|
25 | - |
|
26 | - /** |
|
27 | - * Create a Wordlift_Admin_Term_Adapter instance. |
|
28 | - * |
|
29 | - * @since 3.20.0 |
|
30 | - */ |
|
31 | - public function __construct() { |
|
32 | - |
|
33 | - add_action( 'registered_taxonomy', array( $this, 'add_action' ) ); |
|
34 | - add_action( 'edit_term', array( $this, 'edit_term' ), 10 ); |
|
35 | - $this->add_settings(); |
|
36 | - |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Hook in to WordLift admin settings and add the term page specific |
|
41 | - * settings. |
|
42 | - * |
|
43 | - * @since 3.26.1 |
|
44 | - */ |
|
45 | - public function add_settings() { |
|
46 | - add_filter( |
|
47 | - 'wl_admin_settings', |
|
48 | - function ( $params ) { |
|
49 | - $params['show_local_entities'] = true; |
|
50 | - |
|
51 | - return $params; |
|
52 | - } |
|
53 | - ); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Add the form fields to the entity edit screen. |
|
58 | - * |
|
59 | - * @param object $tag Current taxonomy term object. |
|
60 | - * |
|
61 | - * @since 3.20.0 |
|
62 | - */ |
|
63 | - public function edit_form_fields( $tag ) { |
|
64 | - |
|
65 | - // If disabled via filter, return; |
|
66 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
67 | - if ( ! apply_filters( 'wl_feature__enable__term-entity', true ) ) { |
|
68 | - return; |
|
69 | - } |
|
70 | - |
|
71 | - global $wp_version; |
|
72 | - |
|
73 | - // Enqueue the JavaScript app. |
|
74 | - if ( version_compare( $wp_version, '5.0', '>=' ) ) { |
|
75 | - $term_asset = include plugin_dir_path( __DIR__ ) . 'js/dist/term.asset.php'; |
|
76 | - wp_enqueue_script( 'wl-term', plugin_dir_url( __DIR__ ) . 'js/dist/term.js', array_merge( array( 'wp-util' ), $term_asset['dependencies'] ), Wordlift::get_instance()->get_version(), true ); |
|
77 | - } else { |
|
78 | - wp_enqueue_script( 'wl-term', plugin_dir_url( __DIR__ ) . 'js/dist/term.full.js', array( 'wp-util' ), Wordlift::get_instance()->get_version(), true ); |
|
79 | - } |
|
80 | - |
|
81 | - wp_enqueue_style( 'wl-term', plugin_dir_url( __DIR__ ) . 'js/dist/term.css', array(), Wordlift::get_instance()->get_version() ); |
|
82 | - |
|
83 | - $values = get_term_meta( $tag->term_id, self::META_KEY ); |
|
84 | - |
|
85 | - /** |
|
86 | - * @since 3.31.3 |
|
87 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1446 |
|
88 | - * This field should be hidden by default |
|
89 | - */ |
|
90 | - if ( ! $values ) { |
|
91 | - return; |
|
92 | - } |
|
93 | - |
|
94 | - ?> |
|
19 | + /** |
|
20 | + * The meta key holding the entity id. |
|
21 | + * |
|
22 | + * @since 3.20.0 |
|
23 | + */ |
|
24 | + const META_KEY = '_wl_entity_id'; |
|
25 | + |
|
26 | + /** |
|
27 | + * Create a Wordlift_Admin_Term_Adapter instance. |
|
28 | + * |
|
29 | + * @since 3.20.0 |
|
30 | + */ |
|
31 | + public function __construct() { |
|
32 | + |
|
33 | + add_action( 'registered_taxonomy', array( $this, 'add_action' ) ); |
|
34 | + add_action( 'edit_term', array( $this, 'edit_term' ), 10 ); |
|
35 | + $this->add_settings(); |
|
36 | + |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Hook in to WordLift admin settings and add the term page specific |
|
41 | + * settings. |
|
42 | + * |
|
43 | + * @since 3.26.1 |
|
44 | + */ |
|
45 | + public function add_settings() { |
|
46 | + add_filter( |
|
47 | + 'wl_admin_settings', |
|
48 | + function ( $params ) { |
|
49 | + $params['show_local_entities'] = true; |
|
50 | + |
|
51 | + return $params; |
|
52 | + } |
|
53 | + ); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Add the form fields to the entity edit screen. |
|
58 | + * |
|
59 | + * @param object $tag Current taxonomy term object. |
|
60 | + * |
|
61 | + * @since 3.20.0 |
|
62 | + */ |
|
63 | + public function edit_form_fields( $tag ) { |
|
64 | + |
|
65 | + // If disabled via filter, return; |
|
66 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
67 | + if ( ! apply_filters( 'wl_feature__enable__term-entity', true ) ) { |
|
68 | + return; |
|
69 | + } |
|
70 | + |
|
71 | + global $wp_version; |
|
72 | + |
|
73 | + // Enqueue the JavaScript app. |
|
74 | + if ( version_compare( $wp_version, '5.0', '>=' ) ) { |
|
75 | + $term_asset = include plugin_dir_path( __DIR__ ) . 'js/dist/term.asset.php'; |
|
76 | + wp_enqueue_script( 'wl-term', plugin_dir_url( __DIR__ ) . 'js/dist/term.js', array_merge( array( 'wp-util' ), $term_asset['dependencies'] ), Wordlift::get_instance()->get_version(), true ); |
|
77 | + } else { |
|
78 | + wp_enqueue_script( 'wl-term', plugin_dir_url( __DIR__ ) . 'js/dist/term.full.js', array( 'wp-util' ), Wordlift::get_instance()->get_version(), true ); |
|
79 | + } |
|
80 | + |
|
81 | + wp_enqueue_style( 'wl-term', plugin_dir_url( __DIR__ ) . 'js/dist/term.css', array(), Wordlift::get_instance()->get_version() ); |
|
82 | + |
|
83 | + $values = get_term_meta( $tag->term_id, self::META_KEY ); |
|
84 | + |
|
85 | + /** |
|
86 | + * @since 3.31.3 |
|
87 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1446 |
|
88 | + * This field should be hidden by default |
|
89 | + */ |
|
90 | + if ( ! $values ) { |
|
91 | + return; |
|
92 | + } |
|
93 | + |
|
94 | + ?> |
|
95 | 95 | <tr class="form-field term-name-wrap"> |
96 | 96 | <th scope="row"><label |
97 | 97 | for="wl-entity-id"><?php echo esc_html_x( 'Entity', 'term entity', 'wordlift' ); ?></label></th> |
@@ -105,80 +105,80 @@ discard block |
||
105 | 105 | </tr> |
106 | 106 | <?php wp_nonce_field( 'wordlift_term_entity_edit', 'wordlift_term_entity_edit_nonce' ); ?> |
107 | 107 | <?php |
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Bind the new fields to the edit term screen. |
|
112 | - * |
|
113 | - * @param string $taxonomy The taxonomy name. |
|
114 | - * |
|
115 | - * @since 3.20.0 |
|
116 | - * |
|
117 | - */ |
|
118 | - public function add_action( $taxonomy ) { |
|
119 | - /** |
|
120 | - * Filter wl_feature__enable__taxonomy_term_entity_mapping renamed to wl_feature__enable__term-entity. |
|
121 | - */ |
|
122 | - |
|
123 | - add_action( "{$taxonomy}_edit_form_fields", array( $this, 'edit_form_fields' ), 10 ); |
|
124 | - |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Hook to the edit term to handle our own custom fields. |
|
129 | - * |
|
130 | - * @param int $term_id The term id. |
|
131 | - * |
|
132 | - * @since 3.20.0 |
|
133 | - * |
|
134 | - */ |
|
135 | - public function edit_term( $term_id ) { |
|
136 | - |
|
137 | - check_admin_referer( 'wordlift_term_entity_edit', 'wordlift_term_entity_edit_nonce' ); |
|
138 | - |
|
139 | - // Bail if the action isn't related to the term currently being edited. |
|
140 | - if ( ! isset( $_POST['tag_ID'] ) || $term_id !== (int) $_POST['tag_ID'] ) { |
|
141 | - return; |
|
142 | - } |
|
143 | - |
|
144 | - // Delete. |
|
145 | - if ( ! isset( $_POST['wl_entity_id'] ) || ! is_array( $_POST['wl_entity_id'] ) || empty( $_POST['wl_entity_id'] ) ) { |
|
146 | - delete_term_meta( $term_id, self::META_KEY ); |
|
147 | - |
|
148 | - return; |
|
149 | - } |
|
150 | - |
|
151 | - $entity_ids = array_map( 'esc_url_raw', wp_unslash( $_POST['wl_entity_id'] ) ); |
|
152 | - // Update. |
|
153 | - // |
|
154 | - // Only use mb_* functions when mbstring is available. |
|
155 | - // |
|
156 | - // See https://github.com/insideout10/wordlift-plugin/issues/693. |
|
157 | - if ( extension_loaded( 'mbstring' ) ) { |
|
158 | - mb_regex_encoding( 'UTF-8' ); |
|
159 | - |
|
160 | - $merged = array_reduce( |
|
161 | - $entity_ids, |
|
162 | - function ( $carry, $item ) { |
|
163 | - return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) ); |
|
164 | - }, |
|
165 | - array() |
|
166 | - ); |
|
167 | - } else { |
|
168 | - $merged = array_reduce( |
|
169 | - $entity_ids, |
|
170 | - function ( $carry, $item ) { |
|
171 | - return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) ); |
|
172 | - }, |
|
173 | - array() |
|
174 | - ); |
|
175 | - } |
|
176 | - |
|
177 | - delete_term_meta( $term_id, self::META_KEY ); |
|
178 | - foreach ( array_unique( array_filter( $merged ) ) as $single ) { |
|
179 | - add_term_meta( $term_id, self::META_KEY, $single ); |
|
180 | - } |
|
181 | - |
|
182 | - } |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Bind the new fields to the edit term screen. |
|
112 | + * |
|
113 | + * @param string $taxonomy The taxonomy name. |
|
114 | + * |
|
115 | + * @since 3.20.0 |
|
116 | + * |
|
117 | + */ |
|
118 | + public function add_action( $taxonomy ) { |
|
119 | + /** |
|
120 | + * Filter wl_feature__enable__taxonomy_term_entity_mapping renamed to wl_feature__enable__term-entity. |
|
121 | + */ |
|
122 | + |
|
123 | + add_action( "{$taxonomy}_edit_form_fields", array( $this, 'edit_form_fields' ), 10 ); |
|
124 | + |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Hook to the edit term to handle our own custom fields. |
|
129 | + * |
|
130 | + * @param int $term_id The term id. |
|
131 | + * |
|
132 | + * @since 3.20.0 |
|
133 | + * |
|
134 | + */ |
|
135 | + public function edit_term( $term_id ) { |
|
136 | + |
|
137 | + check_admin_referer( 'wordlift_term_entity_edit', 'wordlift_term_entity_edit_nonce' ); |
|
138 | + |
|
139 | + // Bail if the action isn't related to the term currently being edited. |
|
140 | + if ( ! isset( $_POST['tag_ID'] ) || $term_id !== (int) $_POST['tag_ID'] ) { |
|
141 | + return; |
|
142 | + } |
|
143 | + |
|
144 | + // Delete. |
|
145 | + if ( ! isset( $_POST['wl_entity_id'] ) || ! is_array( $_POST['wl_entity_id'] ) || empty( $_POST['wl_entity_id'] ) ) { |
|
146 | + delete_term_meta( $term_id, self::META_KEY ); |
|
147 | + |
|
148 | + return; |
|
149 | + } |
|
150 | + |
|
151 | + $entity_ids = array_map( 'esc_url_raw', wp_unslash( $_POST['wl_entity_id'] ) ); |
|
152 | + // Update. |
|
153 | + // |
|
154 | + // Only use mb_* functions when mbstring is available. |
|
155 | + // |
|
156 | + // See https://github.com/insideout10/wordlift-plugin/issues/693. |
|
157 | + if ( extension_loaded( 'mbstring' ) ) { |
|
158 | + mb_regex_encoding( 'UTF-8' ); |
|
159 | + |
|
160 | + $merged = array_reduce( |
|
161 | + $entity_ids, |
|
162 | + function ( $carry, $item ) { |
|
163 | + return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) ); |
|
164 | + }, |
|
165 | + array() |
|
166 | + ); |
|
167 | + } else { |
|
168 | + $merged = array_reduce( |
|
169 | + $entity_ids, |
|
170 | + function ( $carry, $item ) { |
|
171 | + return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) ); |
|
172 | + }, |
|
173 | + array() |
|
174 | + ); |
|
175 | + } |
|
176 | + |
|
177 | + delete_term_meta( $term_id, self::META_KEY ); |
|
178 | + foreach ( array_unique( array_filter( $merged ) ) as $single ) { |
|
179 | + add_term_meta( $term_id, self::META_KEY, $single ); |
|
180 | + } |
|
181 | + |
|
182 | + } |
|
183 | 183 | |
184 | 184 | } |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function __construct() { |
32 | 32 | |
33 | - add_action( 'registered_taxonomy', array( $this, 'add_action' ) ); |
|
34 | - add_action( 'edit_term', array( $this, 'edit_term' ), 10 ); |
|
33 | + add_action('registered_taxonomy', array($this, 'add_action')); |
|
34 | + add_action('edit_term', array($this, 'edit_term'), 10); |
|
35 | 35 | $this->add_settings(); |
36 | 36 | |
37 | 37 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | public function add_settings() { |
46 | 46 | add_filter( |
47 | 47 | 'wl_admin_settings', |
48 | - function ( $params ) { |
|
48 | + function($params) { |
|
49 | 49 | $params['show_local_entities'] = true; |
50 | 50 | |
51 | 51 | return $params; |
@@ -60,50 +60,50 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @since 3.20.0 |
62 | 62 | */ |
63 | - public function edit_form_fields( $tag ) { |
|
63 | + public function edit_form_fields($tag) { |
|
64 | 64 | |
65 | 65 | // If disabled via filter, return; |
66 | 66 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
67 | - if ( ! apply_filters( 'wl_feature__enable__term-entity', true ) ) { |
|
67 | + if ( ! apply_filters('wl_feature__enable__term-entity', true)) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | 71 | global $wp_version; |
72 | 72 | |
73 | 73 | // Enqueue the JavaScript app. |
74 | - if ( version_compare( $wp_version, '5.0', '>=' ) ) { |
|
75 | - $term_asset = include plugin_dir_path( __DIR__ ) . 'js/dist/term.asset.php'; |
|
76 | - wp_enqueue_script( 'wl-term', plugin_dir_url( __DIR__ ) . 'js/dist/term.js', array_merge( array( 'wp-util' ), $term_asset['dependencies'] ), Wordlift::get_instance()->get_version(), true ); |
|
74 | + if (version_compare($wp_version, '5.0', '>=')) { |
|
75 | + $term_asset = include plugin_dir_path(__DIR__).'js/dist/term.asset.php'; |
|
76 | + wp_enqueue_script('wl-term', plugin_dir_url(__DIR__).'js/dist/term.js', array_merge(array('wp-util'), $term_asset['dependencies']), Wordlift::get_instance()->get_version(), true); |
|
77 | 77 | } else { |
78 | - wp_enqueue_script( 'wl-term', plugin_dir_url( __DIR__ ) . 'js/dist/term.full.js', array( 'wp-util' ), Wordlift::get_instance()->get_version(), true ); |
|
78 | + wp_enqueue_script('wl-term', plugin_dir_url(__DIR__).'js/dist/term.full.js', array('wp-util'), Wordlift::get_instance()->get_version(), true); |
|
79 | 79 | } |
80 | 80 | |
81 | - wp_enqueue_style( 'wl-term', plugin_dir_url( __DIR__ ) . 'js/dist/term.css', array(), Wordlift::get_instance()->get_version() ); |
|
81 | + wp_enqueue_style('wl-term', plugin_dir_url(__DIR__).'js/dist/term.css', array(), Wordlift::get_instance()->get_version()); |
|
82 | 82 | |
83 | - $values = get_term_meta( $tag->term_id, self::META_KEY ); |
|
83 | + $values = get_term_meta($tag->term_id, self::META_KEY); |
|
84 | 84 | |
85 | 85 | /** |
86 | 86 | * @since 3.31.3 |
87 | 87 | * @see https://github.com/insideout10/wordlift-plugin/issues/1446 |
88 | 88 | * This field should be hidden by default |
89 | 89 | */ |
90 | - if ( ! $values ) { |
|
90 | + if ( ! $values) { |
|
91 | 91 | return; |
92 | 92 | } |
93 | 93 | |
94 | 94 | ?> |
95 | 95 | <tr class="form-field term-name-wrap"> |
96 | 96 | <th scope="row"><label |
97 | - for="wl-entity-id"><?php echo esc_html_x( 'Entity', 'term entity', 'wordlift' ); ?></label></th> |
|
97 | + for="wl-entity-id"><?php echo esc_html_x('Entity', 'term entity', 'wordlift'); ?></label></th> |
|
98 | 98 | <td> |
99 | - <?php foreach ( $values as $value ) { ?> |
|
100 | - <input type="text" name="wl_entity_id[]" value="<?php echo esc_attr( $value ); ?>"/> |
|
99 | + <?php foreach ($values as $value) { ?> |
|
100 | + <input type="text" name="wl_entity_id[]" value="<?php echo esc_attr($value); ?>"/> |
|
101 | 101 | <?php } ?> |
102 | 102 | <div id="wl-term-entity-id"></div> |
103 | - <p class="description"><?php esc_html_e( 'The entity bound to the term.', 'wordlift' ); ?></p> |
|
103 | + <p class="description"><?php esc_html_e('The entity bound to the term.', 'wordlift'); ?></p> |
|
104 | 104 | </td> |
105 | 105 | </tr> |
106 | - <?php wp_nonce_field( 'wordlift_term_entity_edit', 'wordlift_term_entity_edit_nonce' ); ?> |
|
106 | + <?php wp_nonce_field('wordlift_term_entity_edit', 'wordlift_term_entity_edit_nonce'); ?> |
|
107 | 107 | <?php |
108 | 108 | } |
109 | 109 | |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | * @since 3.20.0 |
116 | 116 | * |
117 | 117 | */ |
118 | - public function add_action( $taxonomy ) { |
|
118 | + public function add_action($taxonomy) { |
|
119 | 119 | /** |
120 | 120 | * Filter wl_feature__enable__taxonomy_term_entity_mapping renamed to wl_feature__enable__term-entity. |
121 | 121 | */ |
122 | 122 | |
123 | - add_action( "{$taxonomy}_edit_form_fields", array( $this, 'edit_form_fields' ), 10 ); |
|
123 | + add_action("{$taxonomy}_edit_form_fields", array($this, 'edit_form_fields'), 10); |
|
124 | 124 | |
125 | 125 | } |
126 | 126 | |
@@ -132,51 +132,51 @@ discard block |
||
132 | 132 | * @since 3.20.0 |
133 | 133 | * |
134 | 134 | */ |
135 | - public function edit_term( $term_id ) { |
|
135 | + public function edit_term($term_id) { |
|
136 | 136 | |
137 | - check_admin_referer( 'wordlift_term_entity_edit', 'wordlift_term_entity_edit_nonce' ); |
|
137 | + check_admin_referer('wordlift_term_entity_edit', 'wordlift_term_entity_edit_nonce'); |
|
138 | 138 | |
139 | 139 | // Bail if the action isn't related to the term currently being edited. |
140 | - if ( ! isset( $_POST['tag_ID'] ) || $term_id !== (int) $_POST['tag_ID'] ) { |
|
140 | + if ( ! isset($_POST['tag_ID']) || $term_id !== (int) $_POST['tag_ID']) { |
|
141 | 141 | return; |
142 | 142 | } |
143 | 143 | |
144 | 144 | // Delete. |
145 | - if ( ! isset( $_POST['wl_entity_id'] ) || ! is_array( $_POST['wl_entity_id'] ) || empty( $_POST['wl_entity_id'] ) ) { |
|
146 | - delete_term_meta( $term_id, self::META_KEY ); |
|
145 | + if ( ! isset($_POST['wl_entity_id']) || ! is_array($_POST['wl_entity_id']) || empty($_POST['wl_entity_id'])) { |
|
146 | + delete_term_meta($term_id, self::META_KEY); |
|
147 | 147 | |
148 | 148 | return; |
149 | 149 | } |
150 | 150 | |
151 | - $entity_ids = array_map( 'esc_url_raw', wp_unslash( $_POST['wl_entity_id'] ) ); |
|
151 | + $entity_ids = array_map('esc_url_raw', wp_unslash($_POST['wl_entity_id'])); |
|
152 | 152 | // Update. |
153 | 153 | // |
154 | 154 | // Only use mb_* functions when mbstring is available. |
155 | 155 | // |
156 | 156 | // See https://github.com/insideout10/wordlift-plugin/issues/693. |
157 | - if ( extension_loaded( 'mbstring' ) ) { |
|
158 | - mb_regex_encoding( 'UTF-8' ); |
|
157 | + if (extension_loaded('mbstring')) { |
|
158 | + mb_regex_encoding('UTF-8'); |
|
159 | 159 | |
160 | 160 | $merged = array_reduce( |
161 | 161 | $entity_ids, |
162 | - function ( $carry, $item ) { |
|
163 | - return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) ); |
|
162 | + function($carry, $item) { |
|
163 | + return array_merge($carry, mb_split("\x{2063}", wp_unslash($item))); |
|
164 | 164 | }, |
165 | 165 | array() |
166 | 166 | ); |
167 | 167 | } else { |
168 | 168 | $merged = array_reduce( |
169 | 169 | $entity_ids, |
170 | - function ( $carry, $item ) { |
|
171 | - return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) ); |
|
170 | + function($carry, $item) { |
|
171 | + return array_merge($carry, preg_split("/\x{2063}/u", wp_unslash($item))); |
|
172 | 172 | }, |
173 | 173 | array() |
174 | 174 | ); |
175 | 175 | } |
176 | 176 | |
177 | - delete_term_meta( $term_id, self::META_KEY ); |
|
178 | - foreach ( array_unique( array_filter( $merged ) ) as $single ) { |
|
179 | - add_term_meta( $term_id, self::META_KEY, $single ); |
|
177 | + delete_term_meta($term_id, self::META_KEY); |
|
178 | + foreach (array_unique(array_filter($merged)) as $single) { |
|
179 | + add_term_meta($term_id, self::META_KEY, $single); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | } |
@@ -17,71 +17,71 @@ |
||
17 | 17 | */ |
18 | 18 | function wordlift_ajax_related_posts( $http_raw_data = null ) { |
19 | 19 | |
20 | - // Extract filtering conditions |
|
21 | - if ( ! isset( $_GET['post_id'] ) || ! is_numeric( $_GET['post_id'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
22 | - wp_die( 'Post id missing or invalid!' ); |
|
23 | - |
|
24 | - return; |
|
25 | - } |
|
26 | - |
|
27 | - // Get the current post |
|
28 | - $post_id = (int) $_GET['post_id']; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
29 | - $post = get_post( $post_id ); |
|
30 | - |
|
31 | - Wordlift_Log_Service::get_logger( 'wordlift_ajax_related_posts' )->trace( "Going to find posts related to current with post id: $post_id ..." ); |
|
32 | - |
|
33 | - // Extract filtering conditions |
|
34 | - $filtering_entity_uris = empty( $http_raw_data ) ? file_get_contents( 'php://input' ) : $http_raw_data; |
|
35 | - $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
36 | - |
|
37 | - $content_service = Wordpress_Content_Service::get_instance(); |
|
38 | - $filtering_entity_ids = array_filter( |
|
39 | - array_map( |
|
40 | - function ( $uri ) use ( $content_service ) { |
|
41 | - $content = $content_service->get_by_entity_id( $uri ); |
|
42 | - if ( isset( $content ) && is_a( $content->get_bag(), '\WP_Post' ) ) { |
|
43 | - return $content->get_bag()->ID; |
|
44 | - } else { |
|
45 | - return null; |
|
46 | - } |
|
47 | - }, |
|
48 | - $filtering_entity_uris |
|
49 | - ) |
|
50 | - ); |
|
51 | - |
|
52 | - $related_posts = array(); |
|
53 | - |
|
54 | - // If the current post is an entity, related posts to the current entity are |
|
55 | - // returned. |
|
56 | - $entity_service = Wordlift_Entity_Service::get_instance(); |
|
57 | - |
|
58 | - if ( $entity_service->is_entity( $post->ID ) ) { |
|
59 | - $filtering_entity_ids = array( $post_id ); |
|
60 | - } |
|
61 | - |
|
62 | - if ( ! empty( $filtering_entity_ids ) ) { |
|
63 | - |
|
64 | - $related_posts = Wordlift_Relation_Service::get_instance() |
|
65 | - ->get_article_subjects( $filtering_entity_ids, '*', null, 'publish', array( $post_id ), 5 ); |
|
66 | - |
|
67 | - foreach ( $related_posts as $post_obj ) { |
|
68 | - |
|
69 | - /** |
|
70 | - * Use the thumbnail. |
|
71 | - * |
|
72 | - * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue. |
|
73 | - * @see https://github.com/insideout10/wordlift-plugin/issues/837 |
|
74 | - * |
|
75 | - * @since 3.19.3 We're using the medium size image. |
|
76 | - */ |
|
77 | - $thumbnail = get_the_post_thumbnail_url( $post_obj, 'medium' ); |
|
78 | - $post_obj->thumbnail = ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
79 | - $post_obj->link = get_edit_post_link( $post_obj->ID, 'none' ); |
|
80 | - $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - wl_core_send_json( $related_posts ); |
|
20 | + // Extract filtering conditions |
|
21 | + if ( ! isset( $_GET['post_id'] ) || ! is_numeric( $_GET['post_id'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
22 | + wp_die( 'Post id missing or invalid!' ); |
|
23 | + |
|
24 | + return; |
|
25 | + } |
|
26 | + |
|
27 | + // Get the current post |
|
28 | + $post_id = (int) $_GET['post_id']; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
29 | + $post = get_post( $post_id ); |
|
30 | + |
|
31 | + Wordlift_Log_Service::get_logger( 'wordlift_ajax_related_posts' )->trace( "Going to find posts related to current with post id: $post_id ..." ); |
|
32 | + |
|
33 | + // Extract filtering conditions |
|
34 | + $filtering_entity_uris = empty( $http_raw_data ) ? file_get_contents( 'php://input' ) : $http_raw_data; |
|
35 | + $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
36 | + |
|
37 | + $content_service = Wordpress_Content_Service::get_instance(); |
|
38 | + $filtering_entity_ids = array_filter( |
|
39 | + array_map( |
|
40 | + function ( $uri ) use ( $content_service ) { |
|
41 | + $content = $content_service->get_by_entity_id( $uri ); |
|
42 | + if ( isset( $content ) && is_a( $content->get_bag(), '\WP_Post' ) ) { |
|
43 | + return $content->get_bag()->ID; |
|
44 | + } else { |
|
45 | + return null; |
|
46 | + } |
|
47 | + }, |
|
48 | + $filtering_entity_uris |
|
49 | + ) |
|
50 | + ); |
|
51 | + |
|
52 | + $related_posts = array(); |
|
53 | + |
|
54 | + // If the current post is an entity, related posts to the current entity are |
|
55 | + // returned. |
|
56 | + $entity_service = Wordlift_Entity_Service::get_instance(); |
|
57 | + |
|
58 | + if ( $entity_service->is_entity( $post->ID ) ) { |
|
59 | + $filtering_entity_ids = array( $post_id ); |
|
60 | + } |
|
61 | + |
|
62 | + if ( ! empty( $filtering_entity_ids ) ) { |
|
63 | + |
|
64 | + $related_posts = Wordlift_Relation_Service::get_instance() |
|
65 | + ->get_article_subjects( $filtering_entity_ids, '*', null, 'publish', array( $post_id ), 5 ); |
|
66 | + |
|
67 | + foreach ( $related_posts as $post_obj ) { |
|
68 | + |
|
69 | + /** |
|
70 | + * Use the thumbnail. |
|
71 | + * |
|
72 | + * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue. |
|
73 | + * @see https://github.com/insideout10/wordlift-plugin/issues/837 |
|
74 | + * |
|
75 | + * @since 3.19.3 We're using the medium size image. |
|
76 | + */ |
|
77 | + $thumbnail = get_the_post_thumbnail_url( $post_obj, 'medium' ); |
|
78 | + $post_obj->thumbnail = ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
79 | + $post_obj->link = get_edit_post_link( $post_obj->ID, 'none' ); |
|
80 | + $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + wl_core_send_json( $related_posts ); |
|
85 | 85 | |
86 | 86 | } |
87 | 87 |
@@ -15,31 +15,31 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @since 3.0.0 |
17 | 17 | */ |
18 | -function wordlift_ajax_related_posts( $http_raw_data = null ) { |
|
18 | +function wordlift_ajax_related_posts($http_raw_data = null) { |
|
19 | 19 | |
20 | 20 | // Extract filtering conditions |
21 | - if ( ! isset( $_GET['post_id'] ) || ! is_numeric( $_GET['post_id'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
22 | - wp_die( 'Post id missing or invalid!' ); |
|
21 | + if ( ! isset($_GET['post_id']) || ! is_numeric($_GET['post_id'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
22 | + wp_die('Post id missing or invalid!'); |
|
23 | 23 | |
24 | 24 | return; |
25 | 25 | } |
26 | 26 | |
27 | 27 | // Get the current post |
28 | 28 | $post_id = (int) $_GET['post_id']; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
29 | - $post = get_post( $post_id ); |
|
29 | + $post = get_post($post_id); |
|
30 | 30 | |
31 | - Wordlift_Log_Service::get_logger( 'wordlift_ajax_related_posts' )->trace( "Going to find posts related to current with post id: $post_id ..." ); |
|
31 | + Wordlift_Log_Service::get_logger('wordlift_ajax_related_posts')->trace("Going to find posts related to current with post id: $post_id ..."); |
|
32 | 32 | |
33 | 33 | // Extract filtering conditions |
34 | - $filtering_entity_uris = empty( $http_raw_data ) ? file_get_contents( 'php://input' ) : $http_raw_data; |
|
35 | - $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
34 | + $filtering_entity_uris = empty($http_raw_data) ? file_get_contents('php://input') : $http_raw_data; |
|
35 | + $filtering_entity_uris = json_decode($filtering_entity_uris); |
|
36 | 36 | |
37 | 37 | $content_service = Wordpress_Content_Service::get_instance(); |
38 | 38 | $filtering_entity_ids = array_filter( |
39 | 39 | array_map( |
40 | - function ( $uri ) use ( $content_service ) { |
|
41 | - $content = $content_service->get_by_entity_id( $uri ); |
|
42 | - if ( isset( $content ) && is_a( $content->get_bag(), '\WP_Post' ) ) { |
|
40 | + function($uri) use ($content_service) { |
|
41 | + $content = $content_service->get_by_entity_id($uri); |
|
42 | + if (isset($content) && is_a($content->get_bag(), '\WP_Post')) { |
|
43 | 43 | return $content->get_bag()->ID; |
44 | 44 | } else { |
45 | 45 | return null; |
@@ -55,16 +55,16 @@ discard block |
||
55 | 55 | // returned. |
56 | 56 | $entity_service = Wordlift_Entity_Service::get_instance(); |
57 | 57 | |
58 | - if ( $entity_service->is_entity( $post->ID ) ) { |
|
59 | - $filtering_entity_ids = array( $post_id ); |
|
58 | + if ($entity_service->is_entity($post->ID)) { |
|
59 | + $filtering_entity_ids = array($post_id); |
|
60 | 60 | } |
61 | 61 | |
62 | - if ( ! empty( $filtering_entity_ids ) ) { |
|
62 | + if ( ! empty($filtering_entity_ids)) { |
|
63 | 63 | |
64 | 64 | $related_posts = Wordlift_Relation_Service::get_instance() |
65 | - ->get_article_subjects( $filtering_entity_ids, '*', null, 'publish', array( $post_id ), 5 ); |
|
65 | + ->get_article_subjects($filtering_entity_ids, '*', null, 'publish', array($post_id), 5); |
|
66 | 66 | |
67 | - foreach ( $related_posts as $post_obj ) { |
|
67 | + foreach ($related_posts as $post_obj) { |
|
68 | 68 | |
69 | 69 | /** |
70 | 70 | * Use the thumbnail. |
@@ -74,15 +74,15 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @since 3.19.3 We're using the medium size image. |
76 | 76 | */ |
77 | - $thumbnail = get_the_post_thumbnail_url( $post_obj, 'medium' ); |
|
78 | - $post_obj->thumbnail = ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
79 | - $post_obj->link = get_edit_post_link( $post_obj->ID, 'none' ); |
|
80 | - $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
77 | + $thumbnail = get_the_post_thumbnail_url($post_obj, 'medium'); |
|
78 | + $post_obj->thumbnail = ($thumbnail) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
79 | + $post_obj->link = get_edit_post_link($post_obj->ID, 'none'); |
|
80 | + $post_obj->permalink = get_post_permalink($post_obj->ID); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
84 | - wl_core_send_json( $related_posts ); |
|
84 | + wl_core_send_json($related_posts); |
|
85 | 85 | |
86 | 86 | } |
87 | 87 | |
88 | -add_action( 'wp_ajax_wordlift_related_posts', 'wordlift_ajax_related_posts' ); |
|
88 | +add_action('wp_ajax_wordlift_related_posts', 'wordlift_ajax_related_posts'); |
@@ -16,36 +16,36 @@ |
||
16 | 16 | */ |
17 | 17 | class Wordlift_Admin_Mappings_Page extends Wordlift_Admin_Page { |
18 | 18 | |
19 | - /** |
|
20 | - * {@inheritdoc} |
|
21 | - */ |
|
22 | - public function get_page_title() { |
|
19 | + /** |
|
20 | + * {@inheritdoc} |
|
21 | + */ |
|
22 | + public function get_page_title() { |
|
23 | 23 | |
24 | - return __( 'Schema.org Types', 'wordlift' ); |
|
25 | - } |
|
24 | + return __( 'Schema.org Types', 'wordlift' ); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * {@inheritdoc} |
|
29 | - */ |
|
30 | - public function get_menu_title() { |
|
27 | + /** |
|
28 | + * {@inheritdoc} |
|
29 | + */ |
|
30 | + public function get_menu_title() { |
|
31 | 31 | |
32 | - return __( 'Schema.org Types', 'wordlift' ); |
|
33 | - } |
|
32 | + return __( 'Schema.org Types', 'wordlift' ); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - public function get_menu_slug() { |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + public function get_menu_slug() { |
|
39 | 39 | |
40 | - return 'wl_mappings'; |
|
41 | - } |
|
40 | + return 'wl_mappings'; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * {@inheritdoc} |
|
45 | - */ |
|
46 | - public function get_partial_name() { |
|
43 | + /** |
|
44 | + * {@inheritdoc} |
|
45 | + */ |
|
46 | + public function get_partial_name() { |
|
47 | 47 | |
48 | - return 'wordlift-admin-mappings-page.php'; |
|
49 | - } |
|
48 | + return 'wordlift-admin-mappings-page.php'; |
|
49 | + } |
|
50 | 50 | |
51 | 51 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function get_page_title() { |
23 | 23 | |
24 | - return __( 'Schema.org Types', 'wordlift' ); |
|
24 | + return __('Schema.org Types', 'wordlift'); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function get_menu_title() { |
31 | 31 | |
32 | - return __( 'Schema.org Types', 'wordlift' ); |
|
32 | + return __('Schema.org Types', 'wordlift'); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -18,107 +18,107 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Dashboard_Service { |
20 | 20 | |
21 | - /** |
|
22 | - * Transient Name |
|
23 | - * |
|
24 | - * @since 3.4.0 |
|
25 | - */ |
|
26 | - const TRANSIENT_NAME = 'wl_dashboard_stats'; |
|
27 | - |
|
28 | - /** |
|
29 | - * Transient Expiration (in seconds) |
|
30 | - * |
|
31 | - * @since 3.4.0 |
|
32 | - */ |
|
33 | - const TRANSIENT_EXPIRATION = 86400; |
|
34 | - |
|
35 | - /** |
|
36 | - * A {@link Wordlift_Rating_Service} instance. |
|
37 | - * |
|
38 | - * @since 3.10.0 |
|
39 | - * @access private |
|
40 | - * @var \Wordlift_Rating_Service $rating_service A {@link Wordlift_Rating_Service} instance. |
|
41 | - */ |
|
42 | - private $rating_service; |
|
43 | - |
|
44 | - /** |
|
45 | - * The {@link Wordlift_Entity_Service} instance. |
|
46 | - * |
|
47 | - * @since 3.15.0 |
|
48 | - * @access private |
|
49 | - * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
50 | - */ |
|
51 | - private $entity_service; |
|
52 | - |
|
53 | - /** |
|
54 | - * Create a Wordlift_Entity_List_Service. |
|
55 | - * |
|
56 | - * @since 3.4.0 |
|
57 | - */ |
|
58 | - protected function __construct() { |
|
59 | - |
|
60 | - $this->rating_service = Wordlift_Rating_Service::get_instance(); |
|
61 | - $this->entity_service = Wordlift_Entity_Service::get_instance(); |
|
62 | - |
|
63 | - } |
|
64 | - |
|
65 | - private static $instance; |
|
66 | - |
|
67 | - public static function get_instance() { |
|
68 | - if ( ! isset( self::$instance ) ) { |
|
69 | - self::$instance = new self(); |
|
70 | - } |
|
71 | - |
|
72 | - return self::$instance; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Return stats layout |
|
77 | - * |
|
78 | - * @since 3.4.0 |
|
79 | - */ |
|
21 | + /** |
|
22 | + * Transient Name |
|
23 | + * |
|
24 | + * @since 3.4.0 |
|
25 | + */ |
|
26 | + const TRANSIENT_NAME = 'wl_dashboard_stats'; |
|
27 | + |
|
28 | + /** |
|
29 | + * Transient Expiration (in seconds) |
|
30 | + * |
|
31 | + * @since 3.4.0 |
|
32 | + */ |
|
33 | + const TRANSIENT_EXPIRATION = 86400; |
|
34 | + |
|
35 | + /** |
|
36 | + * A {@link Wordlift_Rating_Service} instance. |
|
37 | + * |
|
38 | + * @since 3.10.0 |
|
39 | + * @access private |
|
40 | + * @var \Wordlift_Rating_Service $rating_service A {@link Wordlift_Rating_Service} instance. |
|
41 | + */ |
|
42 | + private $rating_service; |
|
43 | + |
|
44 | + /** |
|
45 | + * The {@link Wordlift_Entity_Service} instance. |
|
46 | + * |
|
47 | + * @since 3.15.0 |
|
48 | + * @access private |
|
49 | + * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
50 | + */ |
|
51 | + private $entity_service; |
|
52 | + |
|
53 | + /** |
|
54 | + * Create a Wordlift_Entity_List_Service. |
|
55 | + * |
|
56 | + * @since 3.4.0 |
|
57 | + */ |
|
58 | + protected function __construct() { |
|
59 | + |
|
60 | + $this->rating_service = Wordlift_Rating_Service::get_instance(); |
|
61 | + $this->entity_service = Wordlift_Entity_Service::get_instance(); |
|
62 | + |
|
63 | + } |
|
64 | + |
|
65 | + private static $instance; |
|
66 | + |
|
67 | + public static function get_instance() { |
|
68 | + if ( ! isset( self::$instance ) ) { |
|
69 | + self::$instance = new self(); |
|
70 | + } |
|
71 | + |
|
72 | + return self::$instance; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Return stats layout |
|
77 | + * |
|
78 | + * @since 3.4.0 |
|
79 | + */ |
|
80 | 80 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
81 | - public function dashboard_widget_callback( $post ) { |
|
82 | - $caption_kses = array( 'a' => array( 'href' => array() ) ); |
|
83 | - $enriched_posts_title = __( 'enriched posts', 'wordlift' ); |
|
84 | - $enriched_posts_caption = sprintf( |
|
85 | - wp_kses( |
|
86 | - /* translators: 1: Percentage of annotated posts, 2: Link to the edit screen, 3: Number of annotated posts, 4: Total posts. */ |
|
87 | - __( '%1$s, of your <a href="%2$s">posts</a> are annotated. This means %3$s annotated posts on %4$s.', 'wordlift' ), |
|
88 | - array( 'a' => array( 'href' => array() ) ) |
|
89 | - ), |
|
90 | - $this->render_stat_param( 'annotatedPostsPercentage' ), |
|
91 | - esc_url( admin_url( 'edit.php' ) ), |
|
92 | - $this->render_stat_param( 'annotated_posts' ), |
|
93 | - $this->render_stat_param( 'posts' ) |
|
94 | - ); |
|
95 | - |
|
96 | - $rating_title = __( 'average entity rating', 'wordlift' ); |
|
97 | - $rating_caption = sprintf( |
|
98 | - wp_kses( |
|
99 | - /* translators: 1: The entities count, 2: The link to the vocabulary, 3: The average rating. */ |
|
100 | - __( 'You have %1$s entities in your <a href="%2$s">vocabulary</a> with an average rating of %3$s.', 'wordlift' ), |
|
101 | - array( 'a' => array( 'href' => array() ) ) |
|
102 | - ), |
|
103 | - $this->render_stat_param( 'entities' ), |
|
104 | - esc_url( admin_url( 'edit.php?post_type=entity' ) ), |
|
105 | - $this->render_stat_param( 'rating' ) |
|
106 | - ); |
|
107 | - |
|
108 | - $graph_title = __( 'triples in your graph', 'wordlift' ); |
|
109 | - $graph_caption = sprintf( |
|
110 | - wp_kses( |
|
111 | - /* translators: 1: The percentage of the graph size compared to Wikidata, 2: The link to Wikidata. */ |
|
112 | - __( 'Your graphs size corresponds to %1$s of <a href="%2$s">Wikidata</a>.', 'wordlift' ), |
|
113 | - array( 'a' => array( 'href' => array() ) ) |
|
114 | - ), |
|
115 | - $this->render_stat_param( 'wikidata' ), |
|
116 | - esc_url( 'https://www.wikidata.org/' ) |
|
117 | - ); |
|
118 | - |
|
119 | - $triples_label = __( 'triples', 'wordlift' ); |
|
120 | - |
|
121 | - ?> |
|
81 | + public function dashboard_widget_callback( $post ) { |
|
82 | + $caption_kses = array( 'a' => array( 'href' => array() ) ); |
|
83 | + $enriched_posts_title = __( 'enriched posts', 'wordlift' ); |
|
84 | + $enriched_posts_caption = sprintf( |
|
85 | + wp_kses( |
|
86 | + /* translators: 1: Percentage of annotated posts, 2: Link to the edit screen, 3: Number of annotated posts, 4: Total posts. */ |
|
87 | + __( '%1$s, of your <a href="%2$s">posts</a> are annotated. This means %3$s annotated posts on %4$s.', 'wordlift' ), |
|
88 | + array( 'a' => array( 'href' => array() ) ) |
|
89 | + ), |
|
90 | + $this->render_stat_param( 'annotatedPostsPercentage' ), |
|
91 | + esc_url( admin_url( 'edit.php' ) ), |
|
92 | + $this->render_stat_param( 'annotated_posts' ), |
|
93 | + $this->render_stat_param( 'posts' ) |
|
94 | + ); |
|
95 | + |
|
96 | + $rating_title = __( 'average entity rating', 'wordlift' ); |
|
97 | + $rating_caption = sprintf( |
|
98 | + wp_kses( |
|
99 | + /* translators: 1: The entities count, 2: The link to the vocabulary, 3: The average rating. */ |
|
100 | + __( 'You have %1$s entities in your <a href="%2$s">vocabulary</a> with an average rating of %3$s.', 'wordlift' ), |
|
101 | + array( 'a' => array( 'href' => array() ) ) |
|
102 | + ), |
|
103 | + $this->render_stat_param( 'entities' ), |
|
104 | + esc_url( admin_url( 'edit.php?post_type=entity' ) ), |
|
105 | + $this->render_stat_param( 'rating' ) |
|
106 | + ); |
|
107 | + |
|
108 | + $graph_title = __( 'triples in your graph', 'wordlift' ); |
|
109 | + $graph_caption = sprintf( |
|
110 | + wp_kses( |
|
111 | + /* translators: 1: The percentage of the graph size compared to Wikidata, 2: The link to Wikidata. */ |
|
112 | + __( 'Your graphs size corresponds to %1$s of <a href="%2$s">Wikidata</a>.', 'wordlift' ), |
|
113 | + array( 'a' => array( 'href' => array() ) ) |
|
114 | + ), |
|
115 | + $this->render_stat_param( 'wikidata' ), |
|
116 | + esc_url( 'https://www.wikidata.org/' ) |
|
117 | + ); |
|
118 | + |
|
119 | + $triples_label = __( 'triples', 'wordlift' ); |
|
120 | + |
|
121 | + ?> |
|
122 | 122 | <div id="wl-dashboard-widget-inner-wrapper"> |
123 | 123 | <div class="wl-stat-card"> |
124 | 124 | <div class="wl-stat-graph-wrapper"> |
@@ -157,114 +157,114 @@ discard block |
||
157 | 157 | </div> |
158 | 158 | <?php |
159 | 159 | |
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Return stats |
|
164 | - * |
|
165 | - * @since 3.4.0 |
|
166 | - */ |
|
167 | - public function add_dashboard_widgets() { |
|
168 | - wp_add_dashboard_widget( |
|
169 | - 'wordlift-dashboard-widget', |
|
170 | - 'WordLift Dashboard', |
|
171 | - array( |
|
172 | - $this, |
|
173 | - 'dashboard_widget_callback', |
|
174 | - ) |
|
175 | - ); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Return stats |
|
180 | - * |
|
181 | - * @uses https://codex.wordpress.org/Function_Reference/set_transient |
|
182 | - * |
|
183 | - * @since 3.4.0 |
|
184 | - */ |
|
185 | - public function ajax_get_stats() { |
|
186 | - |
|
187 | - // If needed, the transient is force to reloaded. |
|
188 | - if ( isset( $_GET['force_reload'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
189 | - delete_transient( self::TRANSIENT_NAME ); |
|
190 | - } |
|
191 | - |
|
192 | - // Try to retrieve the transient |
|
193 | - $stats = get_transient( self::TRANSIENT_NAME ); |
|
194 | - |
|
195 | - if ( ! $stats ) { |
|
196 | - // Calculate stats |
|
197 | - $count_triples = $this->count_triples(); |
|
198 | - $stats = array( |
|
199 | - 'entities' => $this->entity_service->count(), |
|
200 | - 'posts' => $this->count_posts(), |
|
201 | - 'annotated_posts' => $this->count_annotated_posts(), |
|
202 | - 'triples' => $count_triples ? $count_triples : '-', |
|
203 | - 'rating' => $this->average_entities_rating(), |
|
204 | - ); |
|
205 | - // Cache stats results trough transient |
|
206 | - set_transient( self::TRANSIENT_NAME, $stats, self::TRANSIENT_EXPIRATION ); |
|
207 | - } |
|
208 | - // Return stats as json object |
|
209 | - wl_core_send_json( $stats ); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Calculate total number of published posts |
|
214 | - * |
|
215 | - * @uses https://codex.wordpress.org/it:Riferimento_funzioni/wp_count_posts |
|
216 | - * @since 3.4.0 |
|
217 | - * |
|
218 | - * @return int Total number of published posts. |
|
219 | - */ |
|
220 | - public function count_posts() { |
|
221 | - |
|
222 | - return (int) wp_count_posts()->publish; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Calculate total number of annotated published posts |
|
227 | - * |
|
228 | - * @return int Total number of annotated published posts. |
|
229 | - * @since 3.4.0 |
|
230 | - */ |
|
231 | - public function count_annotated_posts() { |
|
232 | - |
|
233 | - // Prepare interaction with db |
|
234 | - global $wpdb; |
|
235 | - // Retrieve Wordlift relation instances table name |
|
236 | - // $table_name = wl_core_get_relation_instances_table_name(); |
|
237 | - // Calculate sql statement |
|
238 | - |
|
239 | - // Perform the query |
|
240 | - return (int) $wpdb->get_var( |
|
241 | - "SELECT COUNT(distinct(p.id)) FROM $wpdb->posts as p JOIN {$wpdb->prefix}wl_relation_instances as r ON p.id = r.subject_id AND p.post_type = 'post' AND p.post_status = 'publish'" |
|
242 | - ); |
|
243 | - |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Calculate the average entities rating. |
|
248 | - * |
|
249 | - * @return int Average entities rating. |
|
250 | - * @since 3.4.0 |
|
251 | - * |
|
252 | - * @since 3.20.0 this method is public. |
|
253 | - */ |
|
254 | - public function average_entities_rating() { |
|
255 | - |
|
256 | - // Prepare interaction with db |
|
257 | - global $wpdb; |
|
258 | - |
|
259 | - // Perform the query. |
|
260 | - return $this->rating_service->convert_raw_score_to_percentage( |
|
261 | - $wpdb->get_var( |
|
262 | - $wpdb->prepare( |
|
263 | - "SELECT AVG(meta_value) FROM $wpdb->postmeta where meta_key = %s", |
|
264 | - Wordlift_Rating_Service::RATING_RAW_SCORE_META_KEY |
|
265 | - ) |
|
266 | - ) |
|
267 | - ); |
|
268 | - } |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Return stats |
|
164 | + * |
|
165 | + * @since 3.4.0 |
|
166 | + */ |
|
167 | + public function add_dashboard_widgets() { |
|
168 | + wp_add_dashboard_widget( |
|
169 | + 'wordlift-dashboard-widget', |
|
170 | + 'WordLift Dashboard', |
|
171 | + array( |
|
172 | + $this, |
|
173 | + 'dashboard_widget_callback', |
|
174 | + ) |
|
175 | + ); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Return stats |
|
180 | + * |
|
181 | + * @uses https://codex.wordpress.org/Function_Reference/set_transient |
|
182 | + * |
|
183 | + * @since 3.4.0 |
|
184 | + */ |
|
185 | + public function ajax_get_stats() { |
|
186 | + |
|
187 | + // If needed, the transient is force to reloaded. |
|
188 | + if ( isset( $_GET['force_reload'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
189 | + delete_transient( self::TRANSIENT_NAME ); |
|
190 | + } |
|
191 | + |
|
192 | + // Try to retrieve the transient |
|
193 | + $stats = get_transient( self::TRANSIENT_NAME ); |
|
194 | + |
|
195 | + if ( ! $stats ) { |
|
196 | + // Calculate stats |
|
197 | + $count_triples = $this->count_triples(); |
|
198 | + $stats = array( |
|
199 | + 'entities' => $this->entity_service->count(), |
|
200 | + 'posts' => $this->count_posts(), |
|
201 | + 'annotated_posts' => $this->count_annotated_posts(), |
|
202 | + 'triples' => $count_triples ? $count_triples : '-', |
|
203 | + 'rating' => $this->average_entities_rating(), |
|
204 | + ); |
|
205 | + // Cache stats results trough transient |
|
206 | + set_transient( self::TRANSIENT_NAME, $stats, self::TRANSIENT_EXPIRATION ); |
|
207 | + } |
|
208 | + // Return stats as json object |
|
209 | + wl_core_send_json( $stats ); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Calculate total number of published posts |
|
214 | + * |
|
215 | + * @uses https://codex.wordpress.org/it:Riferimento_funzioni/wp_count_posts |
|
216 | + * @since 3.4.0 |
|
217 | + * |
|
218 | + * @return int Total number of published posts. |
|
219 | + */ |
|
220 | + public function count_posts() { |
|
221 | + |
|
222 | + return (int) wp_count_posts()->publish; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Calculate total number of annotated published posts |
|
227 | + * |
|
228 | + * @return int Total number of annotated published posts. |
|
229 | + * @since 3.4.0 |
|
230 | + */ |
|
231 | + public function count_annotated_posts() { |
|
232 | + |
|
233 | + // Prepare interaction with db |
|
234 | + global $wpdb; |
|
235 | + // Retrieve Wordlift relation instances table name |
|
236 | + // $table_name = wl_core_get_relation_instances_table_name(); |
|
237 | + // Calculate sql statement |
|
238 | + |
|
239 | + // Perform the query |
|
240 | + return (int) $wpdb->get_var( |
|
241 | + "SELECT COUNT(distinct(p.id)) FROM $wpdb->posts as p JOIN {$wpdb->prefix}wl_relation_instances as r ON p.id = r.subject_id AND p.post_type = 'post' AND p.post_status = 'publish'" |
|
242 | + ); |
|
243 | + |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Calculate the average entities rating. |
|
248 | + * |
|
249 | + * @return int Average entities rating. |
|
250 | + * @since 3.4.0 |
|
251 | + * |
|
252 | + * @since 3.20.0 this method is public. |
|
253 | + */ |
|
254 | + public function average_entities_rating() { |
|
255 | + |
|
256 | + // Prepare interaction with db |
|
257 | + global $wpdb; |
|
258 | + |
|
259 | + // Perform the query. |
|
260 | + return $this->rating_service->convert_raw_score_to_percentage( |
|
261 | + $wpdb->get_var( |
|
262 | + $wpdb->prepare( |
|
263 | + "SELECT AVG(meta_value) FROM $wpdb->postmeta where meta_key = %s", |
|
264 | + Wordlift_Rating_Service::RATING_RAW_SCORE_META_KEY |
|
265 | + ) |
|
266 | + ) |
|
267 | + ); |
|
268 | + } |
|
269 | 269 | |
270 | 270 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | private static $instance; |
66 | 66 | |
67 | 67 | public static function get_instance() { |
68 | - if ( ! isset( self::$instance ) ) { |
|
68 | + if ( ! isset(self::$instance)) { |
|
69 | 69 | self::$instance = new self(); |
70 | 70 | } |
71 | 71 | |
@@ -78,62 +78,62 @@ discard block |
||
78 | 78 | * @since 3.4.0 |
79 | 79 | */ |
80 | 80 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
81 | - public function dashboard_widget_callback( $post ) { |
|
82 | - $caption_kses = array( 'a' => array( 'href' => array() ) ); |
|
83 | - $enriched_posts_title = __( 'enriched posts', 'wordlift' ); |
|
81 | + public function dashboard_widget_callback($post) { |
|
82 | + $caption_kses = array('a' => array('href' => array())); |
|
83 | + $enriched_posts_title = __('enriched posts', 'wordlift'); |
|
84 | 84 | $enriched_posts_caption = sprintf( |
85 | 85 | wp_kses( |
86 | 86 | /* translators: 1: Percentage of annotated posts, 2: Link to the edit screen, 3: Number of annotated posts, 4: Total posts. */ |
87 | - __( '%1$s, of your <a href="%2$s">posts</a> are annotated. This means %3$s annotated posts on %4$s.', 'wordlift' ), |
|
88 | - array( 'a' => array( 'href' => array() ) ) |
|
87 | + __('%1$s, of your <a href="%2$s">posts</a> are annotated. This means %3$s annotated posts on %4$s.', 'wordlift'), |
|
88 | + array('a' => array('href' => array())) |
|
89 | 89 | ), |
90 | - $this->render_stat_param( 'annotatedPostsPercentage' ), |
|
91 | - esc_url( admin_url( 'edit.php' ) ), |
|
92 | - $this->render_stat_param( 'annotated_posts' ), |
|
93 | - $this->render_stat_param( 'posts' ) |
|
90 | + $this->render_stat_param('annotatedPostsPercentage'), |
|
91 | + esc_url(admin_url('edit.php')), |
|
92 | + $this->render_stat_param('annotated_posts'), |
|
93 | + $this->render_stat_param('posts') |
|
94 | 94 | ); |
95 | 95 | |
96 | - $rating_title = __( 'average entity rating', 'wordlift' ); |
|
96 | + $rating_title = __('average entity rating', 'wordlift'); |
|
97 | 97 | $rating_caption = sprintf( |
98 | 98 | wp_kses( |
99 | 99 | /* translators: 1: The entities count, 2: The link to the vocabulary, 3: The average rating. */ |
100 | - __( 'You have %1$s entities in your <a href="%2$s">vocabulary</a> with an average rating of %3$s.', 'wordlift' ), |
|
101 | - array( 'a' => array( 'href' => array() ) ) |
|
100 | + __('You have %1$s entities in your <a href="%2$s">vocabulary</a> with an average rating of %3$s.', 'wordlift'), |
|
101 | + array('a' => array('href' => array())) |
|
102 | 102 | ), |
103 | - $this->render_stat_param( 'entities' ), |
|
104 | - esc_url( admin_url( 'edit.php?post_type=entity' ) ), |
|
105 | - $this->render_stat_param( 'rating' ) |
|
103 | + $this->render_stat_param('entities'), |
|
104 | + esc_url(admin_url('edit.php?post_type=entity')), |
|
105 | + $this->render_stat_param('rating') |
|
106 | 106 | ); |
107 | 107 | |
108 | - $graph_title = __( 'triples in your graph', 'wordlift' ); |
|
108 | + $graph_title = __('triples in your graph', 'wordlift'); |
|
109 | 109 | $graph_caption = sprintf( |
110 | 110 | wp_kses( |
111 | 111 | /* translators: 1: The percentage of the graph size compared to Wikidata, 2: The link to Wikidata. */ |
112 | - __( 'Your graphs size corresponds to %1$s of <a href="%2$s">Wikidata</a>.', 'wordlift' ), |
|
113 | - array( 'a' => array( 'href' => array() ) ) |
|
112 | + __('Your graphs size corresponds to %1$s of <a href="%2$s">Wikidata</a>.', 'wordlift'), |
|
113 | + array('a' => array('href' => array())) |
|
114 | 114 | ), |
115 | - $this->render_stat_param( 'wikidata' ), |
|
116 | - esc_url( 'https://www.wikidata.org/' ) |
|
115 | + $this->render_stat_param('wikidata'), |
|
116 | + esc_url('https://www.wikidata.org/') |
|
117 | 117 | ); |
118 | 118 | |
119 | - $triples_label = __( 'triples', 'wordlift' ); |
|
119 | + $triples_label = __('triples', 'wordlift'); |
|
120 | 120 | |
121 | 121 | ?> |
122 | 122 | <div id="wl-dashboard-widget-inner-wrapper"> |
123 | 123 | <div class="wl-stat-card"> |
124 | 124 | <div class="wl-stat-graph-wrapper"> |
125 | - <h4><?php echo esc_html( $enriched_posts_title ); ?> <a |
|
125 | + <h4><?php echo esc_html($enriched_posts_title); ?> <a |
|
126 | 126 | href="http://docs.wordlift.it/en/latest/faq.html#what-is-content-enrichment" |
127 | 127 | target="_blank"><i class="wl-info"></i></a></h4> |
128 | 128 | <svg id="wl-posts-pie-chart" viewBox="0 0 32 32"> |
129 | 129 | <circle r="16" cx="16" cy="16"/> |
130 | 130 | </svg> |
131 | 131 | </div> |
132 | - <p><?php echo wp_kses( $enriched_posts_caption, $caption_kses ); ?> </p> |
|
132 | + <p><?php echo wp_kses($enriched_posts_caption, $caption_kses); ?> </p> |
|
133 | 133 | </div> |
134 | 134 | <div class="wl-stat-card"> |
135 | 135 | <div class="wl-stat-graph-wrapper"> |
136 | - <h4><?php echo esc_html( $rating_title ); ?> <a |
|
136 | + <h4><?php echo esc_html($rating_title); ?> <a |
|
137 | 137 | href="http://docs.wordlift.it/en/latest/faq.html#what-factors-determine-the-rating-of-an-entity" |
138 | 138 | target="_blank"><i class="wl-info"></i></a></h4> |
139 | 139 | <svg id="wl-entities-gauge-chart" viewBox="0 0 32 32"> |
@@ -141,18 +141,18 @@ discard block |
||
141 | 141 | <circle r="16" cx="16" cy="16" class="stat"/> |
142 | 142 | </svg> |
143 | 143 | </div> |
144 | - <p><?php echo wp_kses( $rating_caption, $caption_kses ); ?></p> |
|
144 | + <p><?php echo wp_kses($rating_caption, $caption_kses); ?></p> |
|
145 | 145 | </div> |
146 | 146 | <div class="wl-stat-card"> |
147 | 147 | <div class="wl-stat-graph-wrapper"> |
148 | - <h4><?php echo esc_html( $graph_title ); ?><a href="http://docs.wordlift.it/en/latest/faq.html#what-is-a-triple" |
|
148 | + <h4><?php echo esc_html($graph_title); ?><a href="http://docs.wordlift.it/en/latest/faq.html#what-is-a-triple" |
|
149 | 149 | target="_blank"><i class="wl-info"></i></a></h4> |
150 | 150 | <div class="wl-triples"> |
151 | 151 | <span id="wl-dashboard-widget-triples"></span> |
152 | - <span class="wl-triples-label"><?php echo esc_html( $triples_label ); ?></span> |
|
152 | + <span class="wl-triples-label"><?php echo esc_html($triples_label); ?></span> |
|
153 | 153 | </div> |
154 | 154 | </div> |
155 | - <p><?php echo wp_kses( $graph_caption, $caption_kses ); ?></p> |
|
155 | + <p><?php echo wp_kses($graph_caption, $caption_kses); ?></p> |
|
156 | 156 | </div> |
157 | 157 | </div> |
158 | 158 | <?php |
@@ -185,14 +185,14 @@ discard block |
||
185 | 185 | public function ajax_get_stats() { |
186 | 186 | |
187 | 187 | // If needed, the transient is force to reloaded. |
188 | - if ( isset( $_GET['force_reload'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
189 | - delete_transient( self::TRANSIENT_NAME ); |
|
188 | + if (isset($_GET['force_reload'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
189 | + delete_transient(self::TRANSIENT_NAME); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | // Try to retrieve the transient |
193 | - $stats = get_transient( self::TRANSIENT_NAME ); |
|
193 | + $stats = get_transient(self::TRANSIENT_NAME); |
|
194 | 194 | |
195 | - if ( ! $stats ) { |
|
195 | + if ( ! $stats) { |
|
196 | 196 | // Calculate stats |
197 | 197 | $count_triples = $this->count_triples(); |
198 | 198 | $stats = array( |
@@ -203,10 +203,10 @@ discard block |
||
203 | 203 | 'rating' => $this->average_entities_rating(), |
204 | 204 | ); |
205 | 205 | // Cache stats results trough transient |
206 | - set_transient( self::TRANSIENT_NAME, $stats, self::TRANSIENT_EXPIRATION ); |
|
206 | + set_transient(self::TRANSIENT_NAME, $stats, self::TRANSIENT_EXPIRATION); |
|
207 | 207 | } |
208 | 208 | // Return stats as json object |
209 | - wl_core_send_json( $stats ); |
|
209 | + wl_core_send_json($stats); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -7,32 +7,32 @@ |
||
7 | 7 | */ |
8 | 8 | class Wordlift_PrimaShop_Adapter { |
9 | 9 | |
10 | - /** |
|
11 | - * Create a Wordlift_PrimaShop_Adapter instance. |
|
12 | - * |
|
13 | - * @since 3.2.3 |
|
14 | - */ |
|
15 | - public function __construct() { |
|
10 | + /** |
|
11 | + * Create a Wordlift_PrimaShop_Adapter instance. |
|
12 | + * |
|
13 | + * @since 3.2.3 |
|
14 | + */ |
|
15 | + public function __construct() { |
|
16 | 16 | |
17 | - // Tell WP (and PrimaShop) that we support the *prima-layout-settings*. This will display the Content Settings |
|
18 | - // in the entity edit page. |
|
19 | - add_post_type_support( Wordlift_Entity_Service::TYPE_NAME, 'prima-layout-settings' ); |
|
17 | + // Tell WP (and PrimaShop) that we support the *prima-layout-settings*. This will display the Content Settings |
|
18 | + // in the entity edit page. |
|
19 | + add_post_type_support( Wordlift_Entity_Service::TYPE_NAME, 'prima-layout-settings' ); |
|
20 | 20 | |
21 | - } |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * Intercept the <em>prima_metabox_entity_header_args</em> filter and return what a call to the related <em>post</em> |
|
25 | - * would have returned. |
|
26 | - * |
|
27 | - * @since 3.2.3 |
|
28 | - * |
|
29 | - * @param array $meta The meta array. |
|
30 | - * |
|
31 | - * @return array A meta array. |
|
32 | - */ |
|
33 | - public function prima_metabox_entity_header_args( $meta ) { |
|
23 | + /** |
|
24 | + * Intercept the <em>prima_metabox_entity_header_args</em> filter and return what a call to the related <em>post</em> |
|
25 | + * would have returned. |
|
26 | + * |
|
27 | + * @since 3.2.3 |
|
28 | + * |
|
29 | + * @param array $meta The meta array. |
|
30 | + * |
|
31 | + * @return array A meta array. |
|
32 | + */ |
|
33 | + public function prima_metabox_entity_header_args( $meta ) { |
|
34 | 34 | |
35 | - return apply_filters( 'prima_metabox_post_header_args', $meta, 'post' ); |
|
36 | - } |
|
35 | + return apply_filters( 'prima_metabox_post_header_args', $meta, 'post' ); |
|
36 | + } |
|
37 | 37 | |
38 | 38 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | |
17 | 17 | // Tell WP (and PrimaShop) that we support the *prima-layout-settings*. This will display the Content Settings |
18 | 18 | // in the entity edit page. |
19 | - add_post_type_support( Wordlift_Entity_Service::TYPE_NAME, 'prima-layout-settings' ); |
|
19 | + add_post_type_support(Wordlift_Entity_Service::TYPE_NAME, 'prima-layout-settings'); |
|
20 | 20 | |
21 | 21 | } |
22 | 22 | |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return array A meta array. |
32 | 32 | */ |
33 | - public function prima_metabox_entity_header_args( $meta ) { |
|
33 | + public function prima_metabox_entity_header_args($meta) { |
|
34 | 34 | |
35 | - return apply_filters( 'prima_metabox_post_header_args', $meta, 'post' ); |
|
35 | + return apply_filters('prima_metabox_post_header_args', $meta, 'post'); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | } |