@@ -18,392 +18,392 @@ |
||
| 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', 'wordlift' ); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @inheritdoc |
|
| 156 | - */ |
|
| 157 | - public function get_menu_title() { |
|
| 158 | - |
|
| 159 | - return __( 'Settings', 'wordlift' ); |
|
| 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 `alternateName` field. |
|
| 296 | - add_settings_field( |
|
| 297 | - 'wl-alternate-name', |
|
| 298 | - __( 'Website Alternate Name', 'wordlift' ), |
|
| 299 | - array( $this->input_element, 'render' ), |
|
| 300 | - 'wl_general_settings', |
|
| 301 | - 'wl_general_settings_section', |
|
| 302 | - array( |
|
| 303 | - 'id' => 'wl-alternate-name', |
|
| 304 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ALTERNATE_NAME . ']', |
|
| 305 | - 'value' => Wordlift_Configuration_Service::get_instance()->get_alternate_name(), |
|
| 306 | - ) |
|
| 307 | - ); |
|
| 308 | - |
|
| 309 | - // Add the `publisher` field. |
|
| 310 | - add_settings_field( |
|
| 311 | - 'wl-publisher-id', |
|
| 312 | - __( 'Publisher', 'wordlift' ), |
|
| 313 | - array( $this->publisher_element, 'render' ), |
|
| 314 | - 'wl_general_settings', |
|
| 315 | - 'wl_general_settings_section', |
|
| 316 | - array( |
|
| 317 | - 'id' => 'wl-publisher-id', |
|
| 318 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 319 | - ) |
|
| 320 | - ); |
|
| 321 | - |
|
| 322 | - // Add the `link by default` field. |
|
| 323 | - add_settings_field( |
|
| 324 | - 'wl-link-by-default', |
|
| 325 | - __( 'Link by Default', 'wordlift' ), |
|
| 326 | - array( $this->radio_input_element, 'render' ), |
|
| 327 | - 'wl_general_settings', |
|
| 328 | - 'wl_general_settings_section', |
|
| 329 | - array( |
|
| 330 | - 'id' => 'wl-link-by-default', |
|
| 331 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 332 | - 'value' => Wordlift_Configuration_Service::get_instance()->is_link_by_default() ? 'yes' : 'no', |
|
| 333 | - 'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 334 | - ) |
|
| 335 | - ); |
|
| 336 | - |
|
| 337 | - // Add the `diagnostic data` field. |
|
| 338 | - add_settings_field( |
|
| 339 | - 'wl-send-diagnostic', |
|
| 340 | - __( 'Send Diagnostic Data', 'wordlift' ), |
|
| 341 | - array( $this->radio_input_element, 'render' ), |
|
| 342 | - 'wl_general_settings', |
|
| 343 | - 'wl_general_settings_section', |
|
| 344 | - array( |
|
| 345 | - 'id' => 'wl-send-diagnostic', |
|
| 346 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']', |
|
| 347 | - 'value' => 'yes' === Wordlift_Configuration_Service::get_instance()->get_diagnostic_preferences() ? 'yes' : 'no', |
|
| 348 | - 'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ), |
|
| 349 | - ) |
|
| 350 | - ); |
|
| 351 | - |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Filter the {@link Wordlift_Admin_Input_Element} in order to add the |
|
| 356 | - * `readonly` flag to the `wl-entity-base-path` input. |
|
| 357 | - * |
|
| 358 | - * @param array $args An array of {@link Wordlift_Admin_Input_Element} parameters. |
|
| 359 | - * |
|
| 360 | - * @return array The updated array. |
|
| 361 | - * @since 3.17.0 |
|
| 362 | - */ |
|
| 363 | - public function entity_path_input_element_params( $args ) { |
|
| 364 | - |
|
| 365 | - // Bail out if it's not the `wl-entity-base-path`). |
|
| 366 | - if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
| 367 | - return $args; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - // Set the readonly flag according to the entities count. |
|
| 371 | - $args['readonly'] = 0 < $this->entity_service->count(); |
|
| 372 | - |
|
| 373 | - // Return the updated args. |
|
| 374 | - return $args; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * Sanitize the configuration settings to be stored. |
|
| 379 | - * |
|
| 380 | - * If a new entity is being created for the publisher, create it and set The |
|
| 381 | - * publisher setting. |
|
| 382 | - * |
|
| 383 | - * @param array $input The configuration settings array. |
|
| 384 | - * |
|
| 385 | - * @return array The sanitized input array. |
|
| 386 | - * @since 3.11.0 |
|
| 387 | - */ |
|
| 388 | - public function sanitize_callback( $input ) { |
|
| 389 | - // No nonce verification since this callback is handled by settings api. |
|
| 390 | - // Check whether a publisher name has been set. |
|
| 391 | - // phpcs:ignore Standard.Category.SniffName.ErrorCode |
|
| 392 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 393 | - $name = isset( $_POST['wl_publisher']['name'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['wl_publisher']['name'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 394 | - $type = isset( $_POST['wl_publisher']['type'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['wl_publisher']['type'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 395 | - // phpcs:ignore Standard.Category.SniffName.ErrorCode |
|
| 396 | - $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 |
|
| 397 | - |
|
| 398 | - // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
| 399 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 400 | - |
|
| 401 | - // Create an entity for the publisher and assign it to the input |
|
| 402 | - // parameter which WordPress automatically saves into the settings. |
|
| 403 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - return $input; |
|
| 407 | - } |
|
| 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', 'wordlift' ); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @inheritdoc |
|
| 156 | + */ |
|
| 157 | + public function get_menu_title() { |
|
| 158 | + |
|
| 159 | + return __( 'Settings', 'wordlift' ); |
|
| 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 `alternateName` field. |
|
| 296 | + add_settings_field( |
|
| 297 | + 'wl-alternate-name', |
|
| 298 | + __( 'Website Alternate Name', 'wordlift' ), |
|
| 299 | + array( $this->input_element, 'render' ), |
|
| 300 | + 'wl_general_settings', |
|
| 301 | + 'wl_general_settings_section', |
|
| 302 | + array( |
|
| 303 | + 'id' => 'wl-alternate-name', |
|
| 304 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ALTERNATE_NAME . ']', |
|
| 305 | + 'value' => Wordlift_Configuration_Service::get_instance()->get_alternate_name(), |
|
| 306 | + ) |
|
| 307 | + ); |
|
| 308 | + |
|
| 309 | + // Add the `publisher` field. |
|
| 310 | + add_settings_field( |
|
| 311 | + 'wl-publisher-id', |
|
| 312 | + __( 'Publisher', 'wordlift' ), |
|
| 313 | + array( $this->publisher_element, 'render' ), |
|
| 314 | + 'wl_general_settings', |
|
| 315 | + 'wl_general_settings_section', |
|
| 316 | + array( |
|
| 317 | + 'id' => 'wl-publisher-id', |
|
| 318 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 319 | + ) |
|
| 320 | + ); |
|
| 321 | + |
|
| 322 | + // Add the `link by default` field. |
|
| 323 | + add_settings_field( |
|
| 324 | + 'wl-link-by-default', |
|
| 325 | + __( 'Link by Default', 'wordlift' ), |
|
| 326 | + array( $this->radio_input_element, 'render' ), |
|
| 327 | + 'wl_general_settings', |
|
| 328 | + 'wl_general_settings_section', |
|
| 329 | + array( |
|
| 330 | + 'id' => 'wl-link-by-default', |
|
| 331 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 332 | + 'value' => Wordlift_Configuration_Service::get_instance()->is_link_by_default() ? 'yes' : 'no', |
|
| 333 | + 'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 334 | + ) |
|
| 335 | + ); |
|
| 336 | + |
|
| 337 | + // Add the `diagnostic data` field. |
|
| 338 | + add_settings_field( |
|
| 339 | + 'wl-send-diagnostic', |
|
| 340 | + __( 'Send Diagnostic Data', 'wordlift' ), |
|
| 341 | + array( $this->radio_input_element, 'render' ), |
|
| 342 | + 'wl_general_settings', |
|
| 343 | + 'wl_general_settings_section', |
|
| 344 | + array( |
|
| 345 | + 'id' => 'wl-send-diagnostic', |
|
| 346 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']', |
|
| 347 | + 'value' => 'yes' === Wordlift_Configuration_Service::get_instance()->get_diagnostic_preferences() ? 'yes' : 'no', |
|
| 348 | + 'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ), |
|
| 349 | + ) |
|
| 350 | + ); |
|
| 351 | + |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Filter the {@link Wordlift_Admin_Input_Element} in order to add the |
|
| 356 | + * `readonly` flag to the `wl-entity-base-path` input. |
|
| 357 | + * |
|
| 358 | + * @param array $args An array of {@link Wordlift_Admin_Input_Element} parameters. |
|
| 359 | + * |
|
| 360 | + * @return array The updated array. |
|
| 361 | + * @since 3.17.0 |
|
| 362 | + */ |
|
| 363 | + public function entity_path_input_element_params( $args ) { |
|
| 364 | + |
|
| 365 | + // Bail out if it's not the `wl-entity-base-path`). |
|
| 366 | + if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
| 367 | + return $args; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + // Set the readonly flag according to the entities count. |
|
| 371 | + $args['readonly'] = 0 < $this->entity_service->count(); |
|
| 372 | + |
|
| 373 | + // Return the updated args. |
|
| 374 | + return $args; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * Sanitize the configuration settings to be stored. |
|
| 379 | + * |
|
| 380 | + * If a new entity is being created for the publisher, create it and set The |
|
| 381 | + * publisher setting. |
|
| 382 | + * |
|
| 383 | + * @param array $input The configuration settings array. |
|
| 384 | + * |
|
| 385 | + * @return array The sanitized input array. |
|
| 386 | + * @since 3.11.0 |
|
| 387 | + */ |
|
| 388 | + public function sanitize_callback( $input ) { |
|
| 389 | + // No nonce verification since this callback is handled by settings api. |
|
| 390 | + // Check whether a publisher name has been set. |
|
| 391 | + // phpcs:ignore Standard.Category.SniffName.ErrorCode |
|
| 392 | + if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 393 | + $name = isset( $_POST['wl_publisher']['name'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['wl_publisher']['name'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 394 | + $type = isset( $_POST['wl_publisher']['type'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['wl_publisher']['type'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 395 | + // phpcs:ignore Standard.Category.SniffName.ErrorCode |
|
| 396 | + $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 |
|
| 397 | + |
|
| 398 | + // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
| 399 | + $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 400 | + |
|
| 401 | + // Create an entity for the publisher and assign it to the input |
|
| 402 | + // parameter which WordPress automatically saves into the settings. |
|
| 403 | + $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + return $input; |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | 409 | } |
@@ -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(), |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public function get_page_title() { |
| 150 | 150 | |
| 151 | - return __( 'WordLift Settings', 'wordlift' ); |
|
| 151 | + return __('WordLift Settings', 'wordlift'); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | public function get_menu_title() { |
| 158 | 158 | |
| 159 | - return __( 'Settings', 'wordlift' ); |
|
| 159 | + return __('Settings', 'wordlift'); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -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,41 +267,41 @@ 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 `alternateName` field. |
| 296 | 296 | add_settings_field( |
| 297 | 297 | 'wl-alternate-name', |
| 298 | - __( 'Website Alternate Name', 'wordlift' ), |
|
| 299 | - array( $this->input_element, 'render' ), |
|
| 298 | + __('Website Alternate Name', 'wordlift'), |
|
| 299 | + array($this->input_element, 'render'), |
|
| 300 | 300 | 'wl_general_settings', |
| 301 | 301 | 'wl_general_settings_section', |
| 302 | 302 | array( |
| 303 | 303 | 'id' => 'wl-alternate-name', |
| 304 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ALTERNATE_NAME . ']', |
|
| 304 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::ALTERNATE_NAME.']', |
|
| 305 | 305 | 'value' => Wordlift_Configuration_Service::get_instance()->get_alternate_name(), |
| 306 | 306 | ) |
| 307 | 307 | ); |
@@ -309,43 +309,43 @@ discard block |
||
| 309 | 309 | // Add the `publisher` field. |
| 310 | 310 | add_settings_field( |
| 311 | 311 | 'wl-publisher-id', |
| 312 | - __( 'Publisher', 'wordlift' ), |
|
| 313 | - array( $this->publisher_element, 'render' ), |
|
| 312 | + __('Publisher', 'wordlift'), |
|
| 313 | + array($this->publisher_element, 'render'), |
|
| 314 | 314 | 'wl_general_settings', |
| 315 | 315 | 'wl_general_settings_section', |
| 316 | 316 | array( |
| 317 | 317 | 'id' => 'wl-publisher-id', |
| 318 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 318 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::PUBLISHER_ID.']', |
|
| 319 | 319 | ) |
| 320 | 320 | ); |
| 321 | 321 | |
| 322 | 322 | // Add the `link by default` field. |
| 323 | 323 | add_settings_field( |
| 324 | 324 | 'wl-link-by-default', |
| 325 | - __( 'Link by Default', 'wordlift' ), |
|
| 326 | - array( $this->radio_input_element, 'render' ), |
|
| 325 | + __('Link by Default', 'wordlift'), |
|
| 326 | + array($this->radio_input_element, 'render'), |
|
| 327 | 327 | 'wl_general_settings', |
| 328 | 328 | 'wl_general_settings_section', |
| 329 | 329 | array( |
| 330 | 330 | 'id' => 'wl-link-by-default', |
| 331 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 331 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::LINK_BY_DEFAULT.']', |
|
| 332 | 332 | 'value' => Wordlift_Configuration_Service::get_instance()->is_link_by_default() ? 'yes' : 'no', |
| 333 | - 'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 333 | + 'description' => __('Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift'), |
|
| 334 | 334 | ) |
| 335 | 335 | ); |
| 336 | 336 | |
| 337 | 337 | // Add the `diagnostic data` field. |
| 338 | 338 | add_settings_field( |
| 339 | 339 | 'wl-send-diagnostic', |
| 340 | - __( 'Send Diagnostic Data', 'wordlift' ), |
|
| 341 | - array( $this->radio_input_element, 'render' ), |
|
| 340 | + __('Send Diagnostic Data', 'wordlift'), |
|
| 341 | + array($this->radio_input_element, 'render'), |
|
| 342 | 342 | 'wl_general_settings', |
| 343 | 343 | 'wl_general_settings_section', |
| 344 | 344 | array( |
| 345 | 345 | 'id' => 'wl-send-diagnostic', |
| 346 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']', |
|
| 346 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::SEND_DIAGNOSTIC.']', |
|
| 347 | 347 | 'value' => 'yes' === Wordlift_Configuration_Service::get_instance()->get_diagnostic_preferences() ? 'yes' : 'no', |
| 348 | - 'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ), |
|
| 348 | + 'description' => __('Whether to send diagnostic data or not.', 'wordlift'), |
|
| 349 | 349 | ) |
| 350 | 350 | ); |
| 351 | 351 | |
@@ -360,10 +360,10 @@ discard block |
||
| 360 | 360 | * @return array The updated array. |
| 361 | 361 | * @since 3.17.0 |
| 362 | 362 | */ |
| 363 | - public function entity_path_input_element_params( $args ) { |
|
| 363 | + public function entity_path_input_element_params($args) { |
|
| 364 | 364 | |
| 365 | 365 | // Bail out if it's not the `wl-entity-base-path`). |
| 366 | - if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
| 366 | + if ('wl-entity-base-path' !== $args['id']) { |
|
| 367 | 367 | return $args; |
| 368 | 368 | } |
| 369 | 369 | |
@@ -385,22 +385,22 @@ discard block |
||
| 385 | 385 | * @return array The sanitized input array. |
| 386 | 386 | * @since 3.11.0 |
| 387 | 387 | */ |
| 388 | - public function sanitize_callback( $input ) { |
|
| 388 | + public function sanitize_callback($input) { |
|
| 389 | 389 | // No nonce verification since this callback is handled by settings api. |
| 390 | 390 | // Check whether a publisher name has been set. |
| 391 | 391 | // phpcs:ignore Standard.Category.SniffName.ErrorCode |
| 392 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 393 | - $name = isset( $_POST['wl_publisher']['name'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['wl_publisher']['name'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 394 | - $type = isset( $_POST['wl_publisher']['type'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['wl_publisher']['type'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 392 | + if (isset($_POST['wl_publisher']) && ! empty($_POST['wl_publisher']['name'])) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 393 | + $name = isset($_POST['wl_publisher']['name']) ? sanitize_text_field(wp_unslash((string) $_POST['wl_publisher']['name'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 394 | + $type = isset($_POST['wl_publisher']['type']) ? sanitize_text_field(wp_unslash((string) $_POST['wl_publisher']['type'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 395 | 395 | // phpcs:ignore Standard.Category.SniffName.ErrorCode |
| 396 | - $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 |
|
| 396 | + $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 |
|
| 397 | 397 | |
| 398 | 398 | // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
| 399 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 399 | + $type_uri = sprintf('http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person'); |
|
| 400 | 400 | |
| 401 | 401 | // Create an entity for the publisher and assign it to the input |
| 402 | 402 | // parameter which WordPress automatically saves into the settings. |
| 403 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 403 | + $input['publisher_id'] = $this->entity_service->create($name, $type_uri, $thumbnail_id, 'publish'); |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | return $input; |
@@ -4,58 +4,58 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Ingredients_Taxonomy_Recipe_Lift_Strategy implements Recipe_Lift_Strategy { |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * @var Ingredients_Client |
|
| 9 | - */ |
|
| 10 | - private $ingredients_client; |
|
| 11 | - |
|
| 12 | - /** |
|
| 13 | - * @var Notices |
|
| 14 | - */ |
|
| 15 | - private $notices; |
|
| 16 | - |
|
| 17 | - public function __construct( Ingredients_Client $ingredients_client, Notices $notices ) { |
|
| 18 | - $this->ingredients_client = $ingredients_client; |
|
| 19 | - $this->notices = $notices; |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - public function run() { |
|
| 23 | - $this->notices->queue( 'info', __( 'WordLift detected WP Recipe Maker and, it is lifting the ingredients...', 'wordlift' ) ); |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var string[] $terms |
|
| 27 | - */ |
|
| 28 | - $terms = get_terms( |
|
| 29 | - array( |
|
| 30 | - 'taxonomy' => 'wprm_ingredient', |
|
| 31 | - 'fields' => 'names', |
|
| 32 | - 'hide_empty' => false, |
|
| 33 | - ) |
|
| 34 | - ); |
|
| 35 | - $ingredients = $this->ingredients_client->ingredients( $terms ); |
|
| 36 | - |
|
| 37 | - foreach ( $ingredients as $key => $value ) { |
|
| 38 | - $term = get_term_by( 'name', $key, 'wprm_ingredient' ); |
|
| 39 | - if ( ! isset( $term ) ) { |
|
| 40 | - continue; |
|
| 41 | - } |
|
| 42 | - update_term_meta( $term->term_id, '_wl_jsonld', wp_slash( $value ) ); |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @@todo update notification with progress |
|
| 46 | - */ |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - // Clean up caches. |
|
| 50 | - do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @@todo add notification that procedure is complete, with information about the number of processed items vs |
|
| 54 | - * total items |
|
| 55 | - */ |
|
| 56 | - $count_terms = count( $terms ); |
|
| 57 | - $count_lifted_terms = count( $ingredients ); |
|
| 58 | - /* translators: 1: The number of lifted ingredients, 2: The total number of ingredients. */ |
|
| 59 | - $this->notices->queue( 'info', sprintf( __( 'WordLift detected WP Recipe Maker and, it lifted %1$d of %2$d ingredient(s).', 'wordlift' ), $count_lifted_terms, $count_terms ) ); |
|
| 60 | - } |
|
| 7 | + /** |
|
| 8 | + * @var Ingredients_Client |
|
| 9 | + */ |
|
| 10 | + private $ingredients_client; |
|
| 11 | + |
|
| 12 | + /** |
|
| 13 | + * @var Notices |
|
| 14 | + */ |
|
| 15 | + private $notices; |
|
| 16 | + |
|
| 17 | + public function __construct( Ingredients_Client $ingredients_client, Notices $notices ) { |
|
| 18 | + $this->ingredients_client = $ingredients_client; |
|
| 19 | + $this->notices = $notices; |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + public function run() { |
|
| 23 | + $this->notices->queue( 'info', __( 'WordLift detected WP Recipe Maker and, it is lifting the ingredients...', 'wordlift' ) ); |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var string[] $terms |
|
| 27 | + */ |
|
| 28 | + $terms = get_terms( |
|
| 29 | + array( |
|
| 30 | + 'taxonomy' => 'wprm_ingredient', |
|
| 31 | + 'fields' => 'names', |
|
| 32 | + 'hide_empty' => false, |
|
| 33 | + ) |
|
| 34 | + ); |
|
| 35 | + $ingredients = $this->ingredients_client->ingredients( $terms ); |
|
| 36 | + |
|
| 37 | + foreach ( $ingredients as $key => $value ) { |
|
| 38 | + $term = get_term_by( 'name', $key, 'wprm_ingredient' ); |
|
| 39 | + if ( ! isset( $term ) ) { |
|
| 40 | + continue; |
|
| 41 | + } |
|
| 42 | + update_term_meta( $term->term_id, '_wl_jsonld', wp_slash( $value ) ); |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @@todo update notification with progress |
|
| 46 | + */ |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + // Clean up caches. |
|
| 50 | + do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @@todo add notification that procedure is complete, with information about the number of processed items vs |
|
| 54 | + * total items |
|
| 55 | + */ |
|
| 56 | + $count_terms = count( $terms ); |
|
| 57 | + $count_lifted_terms = count( $ingredients ); |
|
| 58 | + /* translators: 1: The number of lifted ingredients, 2: The total number of ingredients. */ |
|
| 59 | + $this->notices->queue( 'info', sprintf( __( 'WordLift detected WP Recipe Maker and, it lifted %1$d of %2$d ingredient(s).', 'wordlift' ), $count_lifted_terms, $count_terms ) ); |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -14,32 +14,32 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | private $notices; |
| 16 | 16 | |
| 17 | - public function __construct( Ingredients_Client $ingredients_client, Notices $notices ) { |
|
| 17 | + public function __construct(Ingredients_Client $ingredients_client, Notices $notices) { |
|
| 18 | 18 | $this->ingredients_client = $ingredients_client; |
| 19 | 19 | $this->notices = $notices; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | public function run() { |
| 23 | - $this->notices->queue( 'info', __( 'WordLift detected WP Recipe Maker and, it is lifting the ingredients...', 'wordlift' ) ); |
|
| 23 | + $this->notices->queue('info', __('WordLift detected WP Recipe Maker and, it is lifting the ingredients...', 'wordlift')); |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @var string[] $terms |
| 27 | 27 | */ |
| 28 | - $terms = get_terms( |
|
| 28 | + $terms = get_terms( |
|
| 29 | 29 | array( |
| 30 | 30 | 'taxonomy' => 'wprm_ingredient', |
| 31 | 31 | 'fields' => 'names', |
| 32 | 32 | 'hide_empty' => false, |
| 33 | 33 | ) |
| 34 | 34 | ); |
| 35 | - $ingredients = $this->ingredients_client->ingredients( $terms ); |
|
| 35 | + $ingredients = $this->ingredients_client->ingredients($terms); |
|
| 36 | 36 | |
| 37 | - foreach ( $ingredients as $key => $value ) { |
|
| 38 | - $term = get_term_by( 'name', $key, 'wprm_ingredient' ); |
|
| 39 | - if ( ! isset( $term ) ) { |
|
| 37 | + foreach ($ingredients as $key => $value) { |
|
| 38 | + $term = get_term_by('name', $key, 'wprm_ingredient'); |
|
| 39 | + if ( ! isset($term)) { |
|
| 40 | 40 | continue; |
| 41 | 41 | } |
| 42 | - update_term_meta( $term->term_id, '_wl_jsonld', wp_slash( $value ) ); |
|
| 42 | + update_term_meta($term->term_id, '_wl_jsonld', wp_slash($value)); |
|
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * @@todo update notification with progress |
@@ -47,15 +47,15 @@ discard block |
||
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | // Clean up caches. |
| 50 | - do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
| 50 | + do_action('wl_ttl_cache_cleaner__flush'); |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * @@todo add notification that procedure is complete, with information about the number of processed items vs |
| 54 | 54 | * total items |
| 55 | 55 | */ |
| 56 | - $count_terms = count( $terms ); |
|
| 57 | - $count_lifted_terms = count( $ingredients ); |
|
| 56 | + $count_terms = count($terms); |
|
| 57 | + $count_lifted_terms = count($ingredients); |
|
| 58 | 58 | /* translators: 1: The number of lifted ingredients, 2: The total number of ingredients. */ |
| 59 | - $this->notices->queue( 'info', sprintf( __( 'WordLift detected WP Recipe Maker and, it lifted %1$d of %2$d ingredient(s).', 'wordlift' ), $count_lifted_terms, $count_terms ) ); |
|
| 59 | + $this->notices->queue('info', sprintf(__('WordLift detected WP Recipe Maker and, it lifted %1$d of %2$d ingredient(s).', 'wordlift'), $count_lifted_terms, $count_terms)); |
|
| 60 | 60 | } |
| 61 | 61 | } |
@@ -3,38 +3,38 @@ discard block |
||
| 3 | 3 | namespace Wordlift\Modules\Food_Kg\Admin; |
| 4 | 4 | |
| 5 | 5 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 6 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 6 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | use WP_List_Table; |
| 10 | 10 | |
| 11 | 11 | class Ingredients_List_Table extends WP_List_Table { |
| 12 | 12 | |
| 13 | - public function prepare_items() { |
|
| 14 | - global $wpdb; // This is used only if making any database queries |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * REQUIRED. Now we need to define our column headers. This includes a complete |
|
| 18 | - * array of columns to be displayed (slugs & titles), a list of columns |
|
| 19 | - * to keep hidden, and a list of columns that are sortable. Each of these |
|
| 20 | - * can be defined in another method (as we've done here) before being |
|
| 21 | - * used to build the value for our _column_headers property. |
|
| 22 | - */ |
|
| 23 | - $columns = $this->get_columns(); |
|
| 24 | - $hidden = array(); |
|
| 25 | - $sortable = $this->get_sortable_columns(); |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * REQUIRED. Finally, we build an array to be used by the class for column |
|
| 29 | - * headers. The $this->_column_headers property takes an array which contains |
|
| 30 | - * 3 other arrays. One for all columns, one for hidden columns, and one |
|
| 31 | - * for sortable columns. |
|
| 32 | - */ |
|
| 33 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 34 | - |
|
| 35 | - $this->items = $wpdb->get_results( |
|
| 36 | - $wpdb->prepare( |
|
| 37 | - "SELECT t.term_id, t.name, tm.meta_value |
|
| 13 | + public function prepare_items() { |
|
| 14 | + global $wpdb; // This is used only if making any database queries |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * REQUIRED. Now we need to define our column headers. This includes a complete |
|
| 18 | + * array of columns to be displayed (slugs & titles), a list of columns |
|
| 19 | + * to keep hidden, and a list of columns that are sortable. Each of these |
|
| 20 | + * can be defined in another method (as we've done here) before being |
|
| 21 | + * used to build the value for our _column_headers property. |
|
| 22 | + */ |
|
| 23 | + $columns = $this->get_columns(); |
|
| 24 | + $hidden = array(); |
|
| 25 | + $sortable = $this->get_sortable_columns(); |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * REQUIRED. Finally, we build an array to be used by the class for column |
|
| 29 | + * headers. The $this->_column_headers property takes an array which contains |
|
| 30 | + * 3 other arrays. One for all columns, one for hidden columns, and one |
|
| 31 | + * for sortable columns. |
|
| 32 | + */ |
|
| 33 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 34 | + |
|
| 35 | + $this->items = $wpdb->get_results( |
|
| 36 | + $wpdb->prepare( |
|
| 37 | + "SELECT t.term_id, t.name, tm.meta_value |
|
| 38 | 38 | FROM $wpdb->term_taxonomy tt |
| 39 | 39 | INNER JOIN $wpdb->terms t |
| 40 | 40 | ON t.term_id = tt.term_id |
@@ -42,44 +42,44 @@ discard block |
||
| 42 | 42 | ON tm.term_id = t.term_id |
| 43 | 43 | AND tm.meta_key = '_wl_jsonld' |
| 44 | 44 | WHERE tt.taxonomy = %s;", |
| 45 | - 'wprm_ingredient' |
|
| 46 | - ) |
|
| 47 | - ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public function no_items() { |
|
| 51 | - esc_html_e( 'No ingredients found.', 'wordlift' ); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public function get_columns() { |
|
| 55 | - return array( |
|
| 56 | - 'id' => __( 'ID', 'wordlift' ), |
|
| 57 | - 'name' => __( 'Name', 'wordlift' ), |
|
| 58 | - 'actions' => '', |
|
| 59 | - ); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - public function column_id( $item ) { |
|
| 63 | - return $item->term_id; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - public function column_name( $item ) { |
|
| 67 | - return $item->name; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function column_actions( $item ) { |
|
| 71 | - |
|
| 72 | - $url = admin_url( |
|
| 73 | - sprintf( 'admin.php?page=wl_ingredients&modal_window=true&term_id=%d&TB_iframe=true', $item->term_id ) |
|
| 74 | - ); |
|
| 75 | - |
|
| 76 | - return sprintf( |
|
| 77 | - '<a href="%s" class="button alignright thickbox open-plugin-details-modal" data-title="%s" type="button">%s</a>', |
|
| 78 | - $url, |
|
| 79 | - esc_attr( $item->name ), |
|
| 80 | - esc_html__( 'JSON-LD', 'wordlift' ) |
|
| 81 | - ); |
|
| 82 | - } |
|
| 45 | + 'wprm_ingredient' |
|
| 46 | + ) |
|
| 47 | + ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public function no_items() { |
|
| 51 | + esc_html_e( 'No ingredients found.', 'wordlift' ); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public function get_columns() { |
|
| 55 | + return array( |
|
| 56 | + 'id' => __( 'ID', 'wordlift' ), |
|
| 57 | + 'name' => __( 'Name', 'wordlift' ), |
|
| 58 | + 'actions' => '', |
|
| 59 | + ); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + public function column_id( $item ) { |
|
| 63 | + return $item->term_id; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + public function column_name( $item ) { |
|
| 67 | + return $item->name; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function column_actions( $item ) { |
|
| 71 | + |
|
| 72 | + $url = admin_url( |
|
| 73 | + sprintf( 'admin.php?page=wl_ingredients&modal_window=true&term_id=%d&TB_iframe=true', $item->term_id ) |
|
| 74 | + ); |
|
| 75 | + |
|
| 76 | + return sprintf( |
|
| 77 | + '<a href="%s" class="button alignright thickbox open-plugin-details-modal" data-title="%s" type="button">%s</a>', |
|
| 78 | + $url, |
|
| 79 | + esc_attr( $item->name ), |
|
| 80 | + esc_html__( 'JSON-LD', 'wordlift' ) |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | |
@@ -2,8 +2,8 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace Wordlift\Modules\Food_Kg\Admin; |
| 4 | 4 | |
| 5 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
| 6 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 5 | +if ( ! class_exists('WP_List_Table')) { |
|
| 6 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | use WP_List_Table; |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * 3 other arrays. One for all columns, one for hidden columns, and one |
| 31 | 31 | * for sortable columns. |
| 32 | 32 | */ |
| 33 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 33 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
| 34 | 34 | |
| 35 | 35 | $this->items = $wpdb->get_results( |
| 36 | 36 | $wpdb->prepare( |
@@ -48,36 +48,36 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | public function no_items() { |
| 51 | - esc_html_e( 'No ingredients found.', 'wordlift' ); |
|
| 51 | + esc_html_e('No ingredients found.', 'wordlift'); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | public function get_columns() { |
| 55 | 55 | return array( |
| 56 | - 'id' => __( 'ID', 'wordlift' ), |
|
| 57 | - 'name' => __( 'Name', 'wordlift' ), |
|
| 56 | + 'id' => __('ID', 'wordlift'), |
|
| 57 | + 'name' => __('Name', 'wordlift'), |
|
| 58 | 58 | 'actions' => '', |
| 59 | 59 | ); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - public function column_id( $item ) { |
|
| 62 | + public function column_id($item) { |
|
| 63 | 63 | return $item->term_id; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - public function column_name( $item ) { |
|
| 66 | + public function column_name($item) { |
|
| 67 | 67 | return $item->name; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public function column_actions( $item ) { |
|
| 70 | + public function column_actions($item) { |
|
| 71 | 71 | |
| 72 | 72 | $url = admin_url( |
| 73 | - sprintf( 'admin.php?page=wl_ingredients&modal_window=true&term_id=%d&TB_iframe=true', $item->term_id ) |
|
| 73 | + sprintf('admin.php?page=wl_ingredients&modal_window=true&term_id=%d&TB_iframe=true', $item->term_id) |
|
| 74 | 74 | ); |
| 75 | 75 | |
| 76 | 76 | return sprintf( |
| 77 | 77 | '<a href="%s" class="button alignright thickbox open-plugin-details-modal" data-title="%s" type="button">%s</a>', |
| 78 | 78 | $url, |
| 79 | - esc_attr( $item->name ), |
|
| 80 | - esc_html__( 'JSON-LD', 'wordlift' ) |
|
| 79 | + esc_attr($item->name), |
|
| 80 | + esc_html__('JSON-LD', 'wordlift') |
|
| 81 | 81 | ); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | class Jsonld { |
| 9 | 9 | |
| 10 | 10 | public function register_hooks() { |
| 11 | - add_action( 'wprm_recipe_metadata', array( $this, '__recipe_metadata' ), 10, 2 ); |
|
| 11 | + add_action('wprm_recipe_metadata', array($this, '__recipe_metadata'), 10, 2); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | /** |
@@ -17,19 +17,19 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | * @return array |
| 19 | 19 | */ |
| 20 | - public function __recipe_metadata( $metadata, $recipe ) { |
|
| 20 | + public function __recipe_metadata($metadata, $recipe) { |
|
| 21 | 21 | |
| 22 | - $ingredients = get_the_terms( $recipe->id(), 'wprm_ingredient' ); |
|
| 23 | - $jsonlds = array_filter( array_map( array( $this, '__term_id_to_jsonld' ), $ingredients ) ); |
|
| 22 | + $ingredients = get_the_terms($recipe->id(), 'wprm_ingredient'); |
|
| 23 | + $jsonlds = array_filter(array_map(array($this, '__term_id_to_jsonld'), $ingredients)); |
|
| 24 | 24 | |
| 25 | - if ( empty( $jsonlds ) ) { |
|
| 25 | + if (empty($jsonlds)) { |
|
| 26 | 26 | return $metadata; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | // We're embedding the full json-ld here because WL doesn't output its own markup, so it makes no sense |
| 30 | 30 | // to hook to wl_after_json_ld. |
| 31 | - $metadata['mentions'] = isset( $metadata['mentions'] ) ? $metadata['mentions'] : array(); |
|
| 32 | - $metadata['mentions'] = array_merge( $metadata['mentions'], $jsonlds ); |
|
| 31 | + $metadata['mentions'] = isset($metadata['mentions']) ? $metadata['mentions'] : array(); |
|
| 32 | + $metadata['mentions'] = array_merge($metadata['mentions'], $jsonlds); |
|
| 33 | 33 | |
| 34 | 34 | return $metadata; |
| 35 | 35 | } |
@@ -39,8 +39,8 @@ discard block |
||
| 39 | 39 | * |
| 40 | 40 | * @return array void |
| 41 | 41 | */ |
| 42 | - private function __term_id_to_jsonld( $ingredient ) { |
|
| 43 | - return json_decode( get_term_meta( $ingredient->term_id, '_wl_jsonld', true ), true ); |
|
| 42 | + private function __term_id_to_jsonld($ingredient) { |
|
| 43 | + return json_decode(get_term_meta($ingredient->term_id, '_wl_jsonld', true), true); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | } |
@@ -7,40 +7,40 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Jsonld { |
| 9 | 9 | |
| 10 | - public function register_hooks() { |
|
| 11 | - add_action( 'wprm_recipe_metadata', array( $this, '__recipe_metadata' ), 10, 2 ); |
|
| 12 | - } |
|
| 13 | - |
|
| 14 | - /** |
|
| 15 | - * @param array $metadata |
|
| 16 | - * @param WPRM_Recipe $recipe |
|
| 17 | - * |
|
| 18 | - * @return array |
|
| 19 | - */ |
|
| 20 | - public function __recipe_metadata( $metadata, $recipe ) { |
|
| 21 | - |
|
| 22 | - $ingredients = get_the_terms( $recipe->id(), 'wprm_ingredient' ); |
|
| 23 | - $jsonlds = array_filter( array_map( array( $this, '__term_id_to_jsonld' ), $ingredients ) ); |
|
| 24 | - |
|
| 25 | - if ( empty( $jsonlds ) ) { |
|
| 26 | - return $metadata; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - // We're embedding the full json-ld here because WL doesn't output its own markup, so it makes no sense |
|
| 30 | - // to hook to wl_after_json_ld. |
|
| 31 | - $metadata['mentions'] = isset( $metadata['mentions'] ) ? $metadata['mentions'] : array(); |
|
| 32 | - $metadata['mentions'] = array_merge( $metadata['mentions'], $jsonlds ); |
|
| 33 | - |
|
| 34 | - return $metadata; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @param WP_Term $ingredient |
|
| 39 | - * |
|
| 40 | - * @return array void |
|
| 41 | - */ |
|
| 42 | - private function __term_id_to_jsonld( $ingredient ) { |
|
| 43 | - return json_decode( get_term_meta( $ingredient->term_id, '_wl_jsonld', true ), true ); |
|
| 44 | - } |
|
| 10 | + public function register_hooks() { |
|
| 11 | + add_action( 'wprm_recipe_metadata', array( $this, '__recipe_metadata' ), 10, 2 ); |
|
| 12 | + } |
|
| 13 | + |
|
| 14 | + /** |
|
| 15 | + * @param array $metadata |
|
| 16 | + * @param WPRM_Recipe $recipe |
|
| 17 | + * |
|
| 18 | + * @return array |
|
| 19 | + */ |
|
| 20 | + public function __recipe_metadata( $metadata, $recipe ) { |
|
| 21 | + |
|
| 22 | + $ingredients = get_the_terms( $recipe->id(), 'wprm_ingredient' ); |
|
| 23 | + $jsonlds = array_filter( array_map( array( $this, '__term_id_to_jsonld' ), $ingredients ) ); |
|
| 24 | + |
|
| 25 | + if ( empty( $jsonlds ) ) { |
|
| 26 | + return $metadata; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + // We're embedding the full json-ld here because WL doesn't output its own markup, so it makes no sense |
|
| 30 | + // to hook to wl_after_json_ld. |
|
| 31 | + $metadata['mentions'] = isset( $metadata['mentions'] ) ? $metadata['mentions'] : array(); |
|
| 32 | + $metadata['mentions'] = array_merge( $metadata['mentions'], $jsonlds ); |
|
| 33 | + |
|
| 34 | + return $metadata; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @param WP_Term $ingredient |
|
| 39 | + * |
|
| 40 | + * @return array void |
|
| 41 | + */ |
|
| 42 | + private function __term_id_to_jsonld( $ingredient ) { |
|
| 43 | + return json_decode( get_term_meta( $ingredient->term_id, '_wl_jsonld', true ), true ); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | 46 | } |
@@ -6,38 +6,38 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ComposerStaticInitbaaf547b24d2757395578581da934187 |
| 8 | 8 | { |
| 9 | - public static $classMap = array ( |
|
| 10 | - 'ComposerAutoloaderInitbaaf547b24d2757395578581da934187' => __DIR__ . '/..' . '/composer/autoload_real.php', |
|
| 11 | - 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', |
|
| 12 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Download_Ingredients_Data' => __DIR__ . '/../..' . '/admin/Download_Ingredients_Data.php', |
|
| 13 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Full_Page_Delegate' => __DIR__ . '/../..' . '/admin/Full_Page_Delegate.php', |
|
| 14 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_Full_Page_Delegate' => __DIR__ . '/../..' . '/admin/Ingredients_Full_Page_Delegate.php', |
|
| 15 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_List_Table' => __DIR__ . '/../..' . '/admin/Ingredients_List_Table.php', |
|
| 16 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_Modal_Page_Delegate' => __DIR__ . '/../..' . '/admin/Ingredients_Modal_Page_Delegate.php', |
|
| 17 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_List_Table' => __DIR__ . '/../..' . '/admin/Main_Ingredient_List_Table.php', |
|
| 18 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_Modal_Page_Delegate' => __DIR__ . '/../..' . '/admin/Main_Ingredient_Modal_Page_Delegate.php', |
|
| 19 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Meta_Box' => __DIR__ . '/../..' . '/admin/Meta_Box.php', |
|
| 20 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Page' => __DIR__ . '/../..' . '/admin/Page.php', |
|
| 21 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Page_Delegate' => __DIR__ . '/../..' . '/admin/Page_Delegate.php', |
|
| 22 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients' => __DIR__ . '/../..' . '/Ingredients.php', |
|
| 23 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients_API' => __DIR__ . '/../..' . '/Ingredients_API.php', |
|
| 24 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients_Client' => __DIR__ . '/../..' . '/Ingredients_Client.php', |
|
| 25 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients_Taxonomy_Recipe_Lift_Strategy' => __DIR__ . '/../..' . '/Ingredients_Taxonomy_Recipe_Lift_Strategy.php', |
|
| 26 | - 'Wordlift\\Modules\\Food_Kg\\Jsonld' => __DIR__ . '/../..' . '/Jsonld.php', |
|
| 27 | - 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Jsonld' => __DIR__ . '/../..' . '/Main_Ingredient_Jsonld.php', |
|
| 28 | - 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Recipe_Lift_Strategy' => __DIR__ . '/../..' . '/Main_Ingredient_Recipe_Lift_Strategy.php', |
|
| 29 | - 'Wordlift\\Modules\\Food_Kg\\Module' => __DIR__ . '/../..' . '/Module.php', |
|
| 30 | - 'Wordlift\\Modules\\Food_Kg\\Notices' => __DIR__ . '/../..' . '/Notices.php', |
|
| 31 | - 'Wordlift\\Modules\\Food_Kg\\Preconditions' => __DIR__ . '/../..' . '/Preconditions.php', |
|
| 32 | - 'Wordlift\\Modules\\Food_Kg\\Recipe_Lift_Strategy' => __DIR__ . '/../..' . '/Recipe_Lift_Strategy.php', |
|
| 33 | - 'Wordlift\\Modules\\Food_Kg\\Services\\Ingredients' => __DIR__ . '/../..' . '/services/Ingredients.php', |
|
| 34 | - 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ClassLoader' => __DIR__ . '/..' . '/composer/ClassLoader.php', |
|
| 35 | - 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ComposerStaticInitbaaf547b24d2757395578581da934187' => __DIR__ . '/..' . '/composer/autoload_static.php', |
|
| 9 | + public static $classMap = array( |
|
| 10 | + 'ComposerAutoloaderInitbaaf547b24d2757395578581da934187' => __DIR__.'/..'.'/composer/autoload_real.php', |
|
| 11 | + 'Composer\\InstalledVersions' => __DIR__.'/..'.'/composer/InstalledVersions.php', |
|
| 12 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Download_Ingredients_Data' => __DIR__.'/../..'.'/admin/Download_Ingredients_Data.php', |
|
| 13 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Full_Page_Delegate' => __DIR__.'/../..'.'/admin/Full_Page_Delegate.php', |
|
| 14 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_Full_Page_Delegate' => __DIR__.'/../..'.'/admin/Ingredients_Full_Page_Delegate.php', |
|
| 15 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_List_Table' => __DIR__.'/../..'.'/admin/Ingredients_List_Table.php', |
|
| 16 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_Modal_Page_Delegate' => __DIR__.'/../..'.'/admin/Ingredients_Modal_Page_Delegate.php', |
|
| 17 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_List_Table' => __DIR__.'/../..'.'/admin/Main_Ingredient_List_Table.php', |
|
| 18 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_Modal_Page_Delegate' => __DIR__.'/../..'.'/admin/Main_Ingredient_Modal_Page_Delegate.php', |
|
| 19 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Meta_Box' => __DIR__.'/../..'.'/admin/Meta_Box.php', |
|
| 20 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Page' => __DIR__.'/../..'.'/admin/Page.php', |
|
| 21 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Page_Delegate' => __DIR__.'/../..'.'/admin/Page_Delegate.php', |
|
| 22 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients' => __DIR__.'/../..'.'/Ingredients.php', |
|
| 23 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients_API' => __DIR__.'/../..'.'/Ingredients_API.php', |
|
| 24 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients_Client' => __DIR__.'/../..'.'/Ingredients_Client.php', |
|
| 25 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients_Taxonomy_Recipe_Lift_Strategy' => __DIR__.'/../..'.'/Ingredients_Taxonomy_Recipe_Lift_Strategy.php', |
|
| 26 | + 'Wordlift\\Modules\\Food_Kg\\Jsonld' => __DIR__.'/../..'.'/Jsonld.php', |
|
| 27 | + 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Jsonld' => __DIR__.'/../..'.'/Main_Ingredient_Jsonld.php', |
|
| 28 | + 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Recipe_Lift_Strategy' => __DIR__.'/../..'.'/Main_Ingredient_Recipe_Lift_Strategy.php', |
|
| 29 | + 'Wordlift\\Modules\\Food_Kg\\Module' => __DIR__.'/../..'.'/Module.php', |
|
| 30 | + 'Wordlift\\Modules\\Food_Kg\\Notices' => __DIR__.'/../..'.'/Notices.php', |
|
| 31 | + 'Wordlift\\Modules\\Food_Kg\\Preconditions' => __DIR__.'/../..'.'/Preconditions.php', |
|
| 32 | + 'Wordlift\\Modules\\Food_Kg\\Recipe_Lift_Strategy' => __DIR__.'/../..'.'/Recipe_Lift_Strategy.php', |
|
| 33 | + 'Wordlift\\Modules\\Food_Kg\\Services\\Ingredients' => __DIR__.'/../..'.'/services/Ingredients.php', |
|
| 34 | + 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ClassLoader' => __DIR__.'/..'.'/composer/ClassLoader.php', |
|
| 35 | + 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ComposerStaticInitbaaf547b24d2757395578581da934187' => __DIR__.'/..'.'/composer/autoload_static.php', |
|
| 36 | 36 | ); |
| 37 | 37 | |
| 38 | 38 | public static function getInitializer(ClassLoader $loader) |
| 39 | 39 | { |
| 40 | - return \Closure::bind(function () use ($loader) { |
|
| 40 | + return \Closure::bind(function() use ($loader) { |
|
| 41 | 41 | $loader->classMap = ComposerStaticInitbaaf547b24d2757395578581da934187::$classMap; |
| 42 | 42 | |
| 43 | 43 | }, null, ClassLoader::class); |
@@ -6,30 +6,30 @@ |
||
| 6 | 6 | $baseDir = dirname($vendorDir); |
| 7 | 7 | |
| 8 | 8 | return array( |
| 9 | - 'ComposerAutoloaderInitbaaf547b24d2757395578581da934187' => $vendorDir . '/composer/autoload_real.php', |
|
| 10 | - 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', |
|
| 11 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Download_Ingredients_Data' => $baseDir . '/admin/Download_Ingredients_Data.php', |
|
| 12 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Full_Page_Delegate' => $baseDir . '/admin/Full_Page_Delegate.php', |
|
| 13 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_Full_Page_Delegate' => $baseDir . '/admin/Ingredients_Full_Page_Delegate.php', |
|
| 14 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_List_Table' => $baseDir . '/admin/Ingredients_List_Table.php', |
|
| 15 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_Modal_Page_Delegate' => $baseDir . '/admin/Ingredients_Modal_Page_Delegate.php', |
|
| 16 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_List_Table' => $baseDir . '/admin/Main_Ingredient_List_Table.php', |
|
| 17 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_Modal_Page_Delegate' => $baseDir . '/admin/Main_Ingredient_Modal_Page_Delegate.php', |
|
| 18 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Meta_Box' => $baseDir . '/admin/Meta_Box.php', |
|
| 19 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Page' => $baseDir . '/admin/Page.php', |
|
| 20 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Page_Delegate' => $baseDir . '/admin/Page_Delegate.php', |
|
| 21 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients' => $baseDir . '/Ingredients.php', |
|
| 22 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients_API' => $baseDir . '/Ingredients_API.php', |
|
| 23 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients_Client' => $baseDir . '/Ingredients_Client.php', |
|
| 24 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients_Taxonomy_Recipe_Lift_Strategy' => $baseDir . '/Ingredients_Taxonomy_Recipe_Lift_Strategy.php', |
|
| 25 | - 'Wordlift\\Modules\\Food_Kg\\Jsonld' => $baseDir . '/Jsonld.php', |
|
| 26 | - 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Jsonld' => $baseDir . '/Main_Ingredient_Jsonld.php', |
|
| 27 | - 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Recipe_Lift_Strategy' => $baseDir . '/Main_Ingredient_Recipe_Lift_Strategy.php', |
|
| 28 | - 'Wordlift\\Modules\\Food_Kg\\Module' => $baseDir . '/Module.php', |
|
| 29 | - 'Wordlift\\Modules\\Food_Kg\\Notices' => $baseDir . '/Notices.php', |
|
| 30 | - 'Wordlift\\Modules\\Food_Kg\\Preconditions' => $baseDir . '/Preconditions.php', |
|
| 31 | - 'Wordlift\\Modules\\Food_Kg\\Recipe_Lift_Strategy' => $baseDir . '/Recipe_Lift_Strategy.php', |
|
| 32 | - 'Wordlift\\Modules\\Food_Kg\\Services\\Ingredients' => $baseDir . '/services/Ingredients.php', |
|
| 33 | - 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ClassLoader' => $vendorDir . '/composer/ClassLoader.php', |
|
| 34 | - 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ComposerStaticInitbaaf547b24d2757395578581da934187' => $vendorDir . '/composer/autoload_static.php', |
|
| 9 | + 'ComposerAutoloaderInitbaaf547b24d2757395578581da934187' => $vendorDir.'/composer/autoload_real.php', |
|
| 10 | + 'Composer\\InstalledVersions' => $vendorDir.'/composer/InstalledVersions.php', |
|
| 11 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Download_Ingredients_Data' => $baseDir.'/admin/Download_Ingredients_Data.php', |
|
| 12 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Full_Page_Delegate' => $baseDir.'/admin/Full_Page_Delegate.php', |
|
| 13 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_Full_Page_Delegate' => $baseDir.'/admin/Ingredients_Full_Page_Delegate.php', |
|
| 14 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_List_Table' => $baseDir.'/admin/Ingredients_List_Table.php', |
|
| 15 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_Modal_Page_Delegate' => $baseDir.'/admin/Ingredients_Modal_Page_Delegate.php', |
|
| 16 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_List_Table' => $baseDir.'/admin/Main_Ingredient_List_Table.php', |
|
| 17 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_Modal_Page_Delegate' => $baseDir.'/admin/Main_Ingredient_Modal_Page_Delegate.php', |
|
| 18 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Meta_Box' => $baseDir.'/admin/Meta_Box.php', |
|
| 19 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Page' => $baseDir.'/admin/Page.php', |
|
| 20 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Page_Delegate' => $baseDir.'/admin/Page_Delegate.php', |
|
| 21 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients' => $baseDir.'/Ingredients.php', |
|
| 22 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients_API' => $baseDir.'/Ingredients_API.php', |
|
| 23 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients_Client' => $baseDir.'/Ingredients_Client.php', |
|
| 24 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients_Taxonomy_Recipe_Lift_Strategy' => $baseDir.'/Ingredients_Taxonomy_Recipe_Lift_Strategy.php', |
|
| 25 | + 'Wordlift\\Modules\\Food_Kg\\Jsonld' => $baseDir.'/Jsonld.php', |
|
| 26 | + 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Jsonld' => $baseDir.'/Main_Ingredient_Jsonld.php', |
|
| 27 | + 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Recipe_Lift_Strategy' => $baseDir.'/Main_Ingredient_Recipe_Lift_Strategy.php', |
|
| 28 | + 'Wordlift\\Modules\\Food_Kg\\Module' => $baseDir.'/Module.php', |
|
| 29 | + 'Wordlift\\Modules\\Food_Kg\\Notices' => $baseDir.'/Notices.php', |
|
| 30 | + 'Wordlift\\Modules\\Food_Kg\\Preconditions' => $baseDir.'/Preconditions.php', |
|
| 31 | + 'Wordlift\\Modules\\Food_Kg\\Recipe_Lift_Strategy' => $baseDir.'/Recipe_Lift_Strategy.php', |
|
| 32 | + 'Wordlift\\Modules\\Food_Kg\\Services\\Ingredients' => $baseDir.'/services/Ingredients.php', |
|
| 33 | + 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ClassLoader' => $vendorDir.'/composer/ClassLoader.php', |
|
| 34 | + 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ComposerStaticInitbaaf547b24d2757395578581da934187' => $vendorDir.'/composer/autoload_static.php', |
|
| 35 | 35 | ); |
@@ -14,24 +14,24 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Background_Task_Factory { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Create a {@link Background_Task} given the provided task and route. |
|
| 19 | - * |
|
| 20 | - * @param Task $task The target task. |
|
| 21 | - * @param string $route The route name. |
|
| 22 | - * @param string $page_id The page id. |
|
| 23 | - * @param string $page_title The page title. |
|
| 24 | - * |
|
| 25 | - * @return void |
|
| 26 | - * @throws Exception in case of invalid arguments. |
|
| 27 | - */ |
|
| 28 | - public static function create( $task, $route, $page_id, $page_title ) { |
|
| 29 | - Assertions::is_a( $task, 'Wordlift\Task\Task' ); |
|
| 30 | - Assertions::starts_with( $route, '/', __( 'The route must start with a slash.', 'wordlift' ) ); |
|
| 17 | + /** |
|
| 18 | + * Create a {@link Background_Task} given the provided task and route. |
|
| 19 | + * |
|
| 20 | + * @param Task $task The target task. |
|
| 21 | + * @param string $route The route name. |
|
| 22 | + * @param string $page_id The page id. |
|
| 23 | + * @param string $page_title The page title. |
|
| 24 | + * |
|
| 25 | + * @return void |
|
| 26 | + * @throws Exception in case of invalid arguments. |
|
| 27 | + */ |
|
| 28 | + public static function create( $task, $route, $page_id, $page_title ) { |
|
| 29 | + Assertions::is_a( $task, 'Wordlift\Task\Task' ); |
|
| 30 | + Assertions::starts_with( $route, '/', __( 'The route must start with a slash.', 'wordlift' ) ); |
|
| 31 | 31 | |
| 32 | - $background_task = Background_Task::create( $task ); |
|
| 33 | - $background_task_route = Background_Task_Route::create( $background_task, $route ); |
|
| 34 | - Background_Task_Page::create( $page_title, $page_id, $background_task_route ); |
|
| 35 | - } |
|
| 32 | + $background_task = Background_Task::create( $task ); |
|
| 33 | + $background_task_route = Background_Task_Route::create( $background_task, $route ); |
|
| 34 | + Background_Task_Page::create( $page_title, $page_id, $background_task_route ); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | 37 | } |
@@ -25,13 +25,13 @@ |
||
| 25 | 25 | * @return void |
| 26 | 26 | * @throws Exception in case of invalid arguments. |
| 27 | 27 | */ |
| 28 | - public static function create( $task, $route, $page_id, $page_title ) { |
|
| 29 | - Assertions::is_a( $task, 'Wordlift\Task\Task' ); |
|
| 30 | - Assertions::starts_with( $route, '/', __( 'The route must start with a slash.', 'wordlift' ) ); |
|
| 28 | + public static function create($task, $route, $page_id, $page_title) { |
|
| 29 | + Assertions::is_a($task, 'Wordlift\Task\Task'); |
|
| 30 | + Assertions::starts_with($route, '/', __('The route must start with a slash.', 'wordlift')); |
|
| 31 | 31 | |
| 32 | - $background_task = Background_Task::create( $task ); |
|
| 33 | - $background_task_route = Background_Task_Route::create( $background_task, $route ); |
|
| 34 | - Background_Task_Page::create( $page_title, $page_id, $background_task_route ); |
|
| 32 | + $background_task = Background_Task::create($task); |
|
| 33 | + $background_task_route = Background_Task_Route::create($background_task, $route); |
|
| 34 | + Background_Task_Page::create($page_title, $page_id, $background_task_route); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | } |
@@ -19,96 +19,96 @@ |
||
| 19 | 19 | use Wordlift\Task\Single_Call_Task; |
| 20 | 20 | |
| 21 | 21 | if ( ! defined( 'ABSPATH' ) ) { |
| 22 | - exit; |
|
| 22 | + exit; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | define( 'WL_FOOD_KG_FILE', __FILE__ ); |
| 26 | 26 | define( 'WL_FOOD_KG_DIR_PATH', dirname( WL_FOOD_KG_FILE ) ); |
| 27 | 27 | |
| 28 | 28 | function __wl_foodkg__load() { |
| 29 | - // Autoloader for dependencies. |
|
| 30 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php' ) ) { |
|
| 31 | - require WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php'; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - // Autoloader for plugin itself. |
|
| 35 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php' ) ) { |
|
| 36 | - require WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php'; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - $container_builder = new ContainerBuilder(); |
|
| 40 | - $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 41 | - $loader->load( 'services.yml' ); |
|
| 42 | - $container_builder->compile(); |
|
| 43 | - |
|
| 44 | - $notices = $container_builder->get( 'Wordlift\Modules\Food_Kg\Notices' ); |
|
| 45 | - $notices->register_hooks(); |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var Preconditions $preconditions |
|
| 49 | - */ |
|
| 50 | - $preconditions = $container_builder->get( 'Wordlift\Modules\Food_Kg\Preconditions' ); |
|
| 51 | - if ( ! $preconditions->pass() ) { |
|
| 52 | - return; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - // Meta Box. |
|
| 56 | - $meta_box = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Meta_Box' ); |
|
| 57 | - $meta_box->register_hooks(); |
|
| 58 | - |
|
| 59 | - $module = $container_builder->get( 'Wordlift\Modules\Food_Kg\Module' ); |
|
| 60 | - $module->register_hooks(); |
|
| 61 | - |
|
| 62 | - /** @var Jsonld $jsonld */ |
|
| 63 | - $jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Jsonld' ); |
|
| 64 | - $jsonld->register_hooks(); |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Ingredients API. |
|
| 68 | - */ |
|
| 69 | - $ingredients_api = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_API' ); |
|
| 70 | - $ingredients_api->register_hooks(); |
|
| 71 | - |
|
| 72 | - /** @var Main_Ingredient_Jsonld $jsonld */ |
|
| 73 | - $main_ingredient_jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld' ); |
|
| 74 | - $main_ingredient_jsonld->register_hooks(); |
|
| 75 | - |
|
| 76 | - // Main Ingredient Background Task. |
|
| 77 | - $main_ingredient_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy' ); |
|
| 78 | - Background_Task_Factory::create( |
|
| 79 | - new All_Posts_Task( |
|
| 80 | - array( $main_ingredient_recipe_lift, 'process' ), |
|
| 81 | - 'wprm_recipe', |
|
| 82 | - 'sync-main-ingredient' |
|
| 83 | - ), |
|
| 84 | - '/main-ingredient', |
|
| 85 | - 'sync-main-ingredient', |
|
| 86 | - __( 'Synchronize Main Ingredient', 'wordlift' ) |
|
| 87 | - ); |
|
| 88 | - |
|
| 89 | - // Ingredients Taxonomy Background Task. |
|
| 90 | - $ingredients_taxonomy_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_Taxonomy_Recipe_Lift_Strategy' ); |
|
| 91 | - Background_Task_Factory::create( |
|
| 92 | - new Single_Call_Task( |
|
| 93 | - array( $ingredients_taxonomy_recipe_lift, 'run' ), |
|
| 94 | - 'sync-ingredients-taxonomy' |
|
| 95 | - ), |
|
| 96 | - '/sync-ingredients-taxonomy', |
|
| 97 | - 'sync-ingredients-taxonomy', |
|
| 98 | - __( 'Synchronize Ingredients Taxonomy', 'wordlift' ) |
|
| 99 | - ); |
|
| 100 | - |
|
| 101 | - if ( is_admin() ) { |
|
| 102 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Page' ); |
|
| 103 | - $page->register_hooks(); |
|
| 104 | - |
|
| 105 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Ingredients_Taxonomy_Page' ); |
|
| 106 | - $page->register_hooks(); |
|
| 107 | - |
|
| 108 | - // Download Ingredients Data. |
|
| 109 | - $download_ingredients_data = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data' ); |
|
| 110 | - $download_ingredients_data->register_hooks(); |
|
| 111 | - } |
|
| 29 | + // Autoloader for dependencies. |
|
| 30 | + if ( file_exists( WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php' ) ) { |
|
| 31 | + require WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php'; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + // Autoloader for plugin itself. |
|
| 35 | + if ( file_exists( WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php' ) ) { |
|
| 36 | + require WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php'; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + $container_builder = new ContainerBuilder(); |
|
| 40 | + $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 41 | + $loader->load( 'services.yml' ); |
|
| 42 | + $container_builder->compile(); |
|
| 43 | + |
|
| 44 | + $notices = $container_builder->get( 'Wordlift\Modules\Food_Kg\Notices' ); |
|
| 45 | + $notices->register_hooks(); |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var Preconditions $preconditions |
|
| 49 | + */ |
|
| 50 | + $preconditions = $container_builder->get( 'Wordlift\Modules\Food_Kg\Preconditions' ); |
|
| 51 | + if ( ! $preconditions->pass() ) { |
|
| 52 | + return; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + // Meta Box. |
|
| 56 | + $meta_box = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Meta_Box' ); |
|
| 57 | + $meta_box->register_hooks(); |
|
| 58 | + |
|
| 59 | + $module = $container_builder->get( 'Wordlift\Modules\Food_Kg\Module' ); |
|
| 60 | + $module->register_hooks(); |
|
| 61 | + |
|
| 62 | + /** @var Jsonld $jsonld */ |
|
| 63 | + $jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Jsonld' ); |
|
| 64 | + $jsonld->register_hooks(); |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Ingredients API. |
|
| 68 | + */ |
|
| 69 | + $ingredients_api = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_API' ); |
|
| 70 | + $ingredients_api->register_hooks(); |
|
| 71 | + |
|
| 72 | + /** @var Main_Ingredient_Jsonld $jsonld */ |
|
| 73 | + $main_ingredient_jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld' ); |
|
| 74 | + $main_ingredient_jsonld->register_hooks(); |
|
| 75 | + |
|
| 76 | + // Main Ingredient Background Task. |
|
| 77 | + $main_ingredient_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy' ); |
|
| 78 | + Background_Task_Factory::create( |
|
| 79 | + new All_Posts_Task( |
|
| 80 | + array( $main_ingredient_recipe_lift, 'process' ), |
|
| 81 | + 'wprm_recipe', |
|
| 82 | + 'sync-main-ingredient' |
|
| 83 | + ), |
|
| 84 | + '/main-ingredient', |
|
| 85 | + 'sync-main-ingredient', |
|
| 86 | + __( 'Synchronize Main Ingredient', 'wordlift' ) |
|
| 87 | + ); |
|
| 88 | + |
|
| 89 | + // Ingredients Taxonomy Background Task. |
|
| 90 | + $ingredients_taxonomy_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_Taxonomy_Recipe_Lift_Strategy' ); |
|
| 91 | + Background_Task_Factory::create( |
|
| 92 | + new Single_Call_Task( |
|
| 93 | + array( $ingredients_taxonomy_recipe_lift, 'run' ), |
|
| 94 | + 'sync-ingredients-taxonomy' |
|
| 95 | + ), |
|
| 96 | + '/sync-ingredients-taxonomy', |
|
| 97 | + 'sync-ingredients-taxonomy', |
|
| 98 | + __( 'Synchronize Ingredients Taxonomy', 'wordlift' ) |
|
| 99 | + ); |
|
| 100 | + |
|
| 101 | + if ( is_admin() ) { |
|
| 102 | + $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Page' ); |
|
| 103 | + $page->register_hooks(); |
|
| 104 | + |
|
| 105 | + $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Ingredients_Taxonomy_Page' ); |
|
| 106 | + $page->register_hooks(); |
|
| 107 | + |
|
| 108 | + // Download Ingredients Data. |
|
| 109 | + $download_ingredients_data = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data' ); |
|
| 110 | + $download_ingredients_data->register_hooks(); |
|
| 111 | + } |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | add_action( 'plugins_loaded', '__wl_foodkg__load' ); |
@@ -18,98 +18,98 @@ |
||
| 18 | 18 | use Wordlift\Task\Background\Background_Task_Factory; |
| 19 | 19 | use Wordlift\Task\Single_Call_Task; |
| 20 | 20 | |
| 21 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 21 | +if ( ! defined('ABSPATH')) { |
|
| 22 | 22 | exit; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | -define( 'WL_FOOD_KG_FILE', __FILE__ ); |
|
| 26 | -define( 'WL_FOOD_KG_DIR_PATH', dirname( WL_FOOD_KG_FILE ) ); |
|
| 25 | +define('WL_FOOD_KG_FILE', __FILE__); |
|
| 26 | +define('WL_FOOD_KG_DIR_PATH', dirname(WL_FOOD_KG_FILE)); |
|
| 27 | 27 | |
| 28 | 28 | function __wl_foodkg__load() { |
| 29 | 29 | // Autoloader for dependencies. |
| 30 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php' ) ) { |
|
| 31 | - require WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php'; |
|
| 30 | + if (file_exists(WL_FOOD_KG_DIR_PATH.'/third-party/vendor/scoper-autoload.php')) { |
|
| 31 | + require WL_FOOD_KG_DIR_PATH.'/third-party/vendor/scoper-autoload.php'; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | // Autoloader for plugin itself. |
| 35 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php' ) ) { |
|
| 36 | - require WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php'; |
|
| 35 | + if (file_exists(WL_FOOD_KG_DIR_PATH.'/includes/vendor/autoload.php')) { |
|
| 36 | + require WL_FOOD_KG_DIR_PATH.'/includes/vendor/autoload.php'; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | $container_builder = new ContainerBuilder(); |
| 40 | - $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 41 | - $loader->load( 'services.yml' ); |
|
| 40 | + $loader = new YamlFileLoader($container_builder, new FileLocator(__DIR__)); |
|
| 41 | + $loader->load('services.yml'); |
|
| 42 | 42 | $container_builder->compile(); |
| 43 | 43 | |
| 44 | - $notices = $container_builder->get( 'Wordlift\Modules\Food_Kg\Notices' ); |
|
| 44 | + $notices = $container_builder->get('Wordlift\Modules\Food_Kg\Notices'); |
|
| 45 | 45 | $notices->register_hooks(); |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * @var Preconditions $preconditions |
| 49 | 49 | */ |
| 50 | - $preconditions = $container_builder->get( 'Wordlift\Modules\Food_Kg\Preconditions' ); |
|
| 51 | - if ( ! $preconditions->pass() ) { |
|
| 50 | + $preconditions = $container_builder->get('Wordlift\Modules\Food_Kg\Preconditions'); |
|
| 51 | + if ( ! $preconditions->pass()) { |
|
| 52 | 52 | return; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // Meta Box. |
| 56 | - $meta_box = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Meta_Box' ); |
|
| 56 | + $meta_box = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Meta_Box'); |
|
| 57 | 57 | $meta_box->register_hooks(); |
| 58 | 58 | |
| 59 | - $module = $container_builder->get( 'Wordlift\Modules\Food_Kg\Module' ); |
|
| 59 | + $module = $container_builder->get('Wordlift\Modules\Food_Kg\Module'); |
|
| 60 | 60 | $module->register_hooks(); |
| 61 | 61 | |
| 62 | 62 | /** @var Jsonld $jsonld */ |
| 63 | - $jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Jsonld' ); |
|
| 63 | + $jsonld = $container_builder->get('Wordlift\Modules\Food_Kg\Jsonld'); |
|
| 64 | 64 | $jsonld->register_hooks(); |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * Ingredients API. |
| 68 | 68 | */ |
| 69 | - $ingredients_api = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_API' ); |
|
| 69 | + $ingredients_api = $container_builder->get('Wordlift\Modules\Food_Kg\Ingredients_API'); |
|
| 70 | 70 | $ingredients_api->register_hooks(); |
| 71 | 71 | |
| 72 | 72 | /** @var Main_Ingredient_Jsonld $jsonld */ |
| 73 | - $main_ingredient_jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld' ); |
|
| 73 | + $main_ingredient_jsonld = $container_builder->get('Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld'); |
|
| 74 | 74 | $main_ingredient_jsonld->register_hooks(); |
| 75 | 75 | |
| 76 | 76 | // Main Ingredient Background Task. |
| 77 | - $main_ingredient_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy' ); |
|
| 77 | + $main_ingredient_recipe_lift = $container_builder->get('Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy'); |
|
| 78 | 78 | Background_Task_Factory::create( |
| 79 | 79 | new All_Posts_Task( |
| 80 | - array( $main_ingredient_recipe_lift, 'process' ), |
|
| 80 | + array($main_ingredient_recipe_lift, 'process'), |
|
| 81 | 81 | 'wprm_recipe', |
| 82 | 82 | 'sync-main-ingredient' |
| 83 | 83 | ), |
| 84 | 84 | '/main-ingredient', |
| 85 | 85 | 'sync-main-ingredient', |
| 86 | - __( 'Synchronize Main Ingredient', 'wordlift' ) |
|
| 86 | + __('Synchronize Main Ingredient', 'wordlift') |
|
| 87 | 87 | ); |
| 88 | 88 | |
| 89 | 89 | // Ingredients Taxonomy Background Task. |
| 90 | - $ingredients_taxonomy_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_Taxonomy_Recipe_Lift_Strategy' ); |
|
| 90 | + $ingredients_taxonomy_recipe_lift = $container_builder->get('Wordlift\Modules\Food_Kg\Ingredients_Taxonomy_Recipe_Lift_Strategy'); |
|
| 91 | 91 | Background_Task_Factory::create( |
| 92 | 92 | new Single_Call_Task( |
| 93 | - array( $ingredients_taxonomy_recipe_lift, 'run' ), |
|
| 93 | + array($ingredients_taxonomy_recipe_lift, 'run'), |
|
| 94 | 94 | 'sync-ingredients-taxonomy' |
| 95 | 95 | ), |
| 96 | 96 | '/sync-ingredients-taxonomy', |
| 97 | 97 | 'sync-ingredients-taxonomy', |
| 98 | - __( 'Synchronize Ingredients Taxonomy', 'wordlift' ) |
|
| 98 | + __('Synchronize Ingredients Taxonomy', 'wordlift') |
|
| 99 | 99 | ); |
| 100 | 100 | |
| 101 | - if ( is_admin() ) { |
|
| 102 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Page' ); |
|
| 101 | + if (is_admin()) { |
|
| 102 | + $page = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Page'); |
|
| 103 | 103 | $page->register_hooks(); |
| 104 | 104 | |
| 105 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Ingredients_Taxonomy_Page' ); |
|
| 105 | + $page = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Ingredients_Taxonomy_Page'); |
|
| 106 | 106 | $page->register_hooks(); |
| 107 | 107 | |
| 108 | 108 | // Download Ingredients Data. |
| 109 | - $download_ingredients_data = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data' ); |
|
| 109 | + $download_ingredients_data = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data'); |
|
| 110 | 110 | $download_ingredients_data->register_hooks(); |
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | -add_action( 'plugins_loaded', '__wl_foodkg__load' ); |
|
| 114 | +add_action('plugins_loaded', '__wl_foodkg__load'); |
|
| 115 | 115 | |
@@ -6,63 +6,63 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Module { |
| 8 | 8 | |
| 9 | - const RUN_EVENT = 'wl_food_kg__run'; |
|
| 9 | + const RUN_EVENT = 'wl_food_kg__run'; |
|
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @var Api_Service_Ext |
|
| 13 | - */ |
|
| 14 | - private $api_service; |
|
| 11 | + /** |
|
| 12 | + * @var Api_Service_Ext |
|
| 13 | + */ |
|
| 14 | + private $api_service; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var Recipe_Lift_Strategy |
|
| 18 | - */ |
|
| 19 | - private $recipe_lift_strategies; |
|
| 16 | + /** |
|
| 17 | + * @var Recipe_Lift_Strategy |
|
| 18 | + */ |
|
| 19 | + private $recipe_lift_strategies; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param Api_Service_Ext $api_service |
|
| 23 | - * @param Recipe_Lift_Strategy[] $recipe_lift_strategies |
|
| 24 | - */ |
|
| 25 | - public function __construct( Api_Service_Ext $api_service, array $recipe_lift_strategies ) { |
|
| 26 | - $this->api_service = $api_service; |
|
| 27 | - $this->recipe_lift_strategies = $recipe_lift_strategies; |
|
| 28 | - } |
|
| 21 | + /** |
|
| 22 | + * @param Api_Service_Ext $api_service |
|
| 23 | + * @param Recipe_Lift_Strategy[] $recipe_lift_strategies |
|
| 24 | + */ |
|
| 25 | + public function __construct( Api_Service_Ext $api_service, array $recipe_lift_strategies ) { |
|
| 26 | + $this->api_service = $api_service; |
|
| 27 | + $this->recipe_lift_strategies = $recipe_lift_strategies; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function register_hooks() { |
|
| 31 | - add_action( 'wl_key_updated', array( $this, '__key_updated' ) ); |
|
| 32 | - add_action( self::RUN_EVENT, array( $this, '__run' ) ); |
|
| 33 | - add_action( 'wp_ajax_wl_food_kg__run', array( $this, '__run' ) ); |
|
| 34 | - } |
|
| 30 | + public function register_hooks() { |
|
| 31 | + add_action( 'wl_key_updated', array( $this, '__key_updated' ) ); |
|
| 32 | + add_action( self::RUN_EVENT, array( $this, '__run' ) ); |
|
| 33 | + add_action( 'wp_ajax_wl_food_kg__run', array( $this, '__run' ) ); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public function __key_updated() { |
|
| 37 | - try { |
|
| 38 | - $me_response = $this->api_service->me(); |
|
| 39 | - $has_food_kg = isset( $me_response->networks ) |
|
| 40 | - && array_reduce( $me_response->networks, array( $this, '__has_food_kg' ), false ); |
|
| 41 | - $next_scheduled = wp_next_scheduled( self::RUN_EVENT ); |
|
| 36 | + public function __key_updated() { |
|
| 37 | + try { |
|
| 38 | + $me_response = $this->api_service->me(); |
|
| 39 | + $has_food_kg = isset( $me_response->networks ) |
|
| 40 | + && array_reduce( $me_response->networks, array( $this, '__has_food_kg' ), false ); |
|
| 41 | + $next_scheduled = wp_next_scheduled( self::RUN_EVENT ); |
|
| 42 | 42 | |
| 43 | - // We're connected to the Food KG, but not yet scheduled. |
|
| 44 | - if ( $has_food_kg && ! $next_scheduled ) { |
|
| 45 | - wp_schedule_event( time(), 'daily', self::RUN_EVENT ); |
|
| 46 | - } |
|
| 43 | + // We're connected to the Food KG, but not yet scheduled. |
|
| 44 | + if ( $has_food_kg && ! $next_scheduled ) { |
|
| 45 | + wp_schedule_event( time(), 'daily', self::RUN_EVENT ); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - // We're not connected to the Food KG, but we're scheduled. |
|
| 49 | - if ( ! $has_food_kg && $next_scheduled ) { |
|
| 50 | - wp_unschedule_event( $next_scheduled, self::RUN_EVENT ); |
|
| 51 | - } |
|
| 52 | - // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
|
| 53 | - } catch ( \Exception $e ) { |
|
| 54 | - // Do nothing. |
|
| 55 | - } |
|
| 56 | - } |
|
| 48 | + // We're not connected to the Food KG, but we're scheduled. |
|
| 49 | + if ( ! $has_food_kg && $next_scheduled ) { |
|
| 50 | + wp_unschedule_event( $next_scheduled, self::RUN_EVENT ); |
|
| 51 | + } |
|
| 52 | + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
|
| 53 | + } catch ( \Exception $e ) { |
|
| 54 | + // Do nothing. |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function __run() { |
|
| 59 | - foreach ( $this->recipe_lift_strategies as $recipe_lift_strategy ) { |
|
| 60 | - $recipe_lift_strategy->run(); |
|
| 61 | - } |
|
| 62 | - } |
|
| 58 | + public function __run() { |
|
| 59 | + foreach ( $this->recipe_lift_strategies as $recipe_lift_strategy ) { |
|
| 60 | + $recipe_lift_strategy->run(); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - private function __has_food_kg( $carry, $item ) { |
|
| 65 | - return $carry || 'https://knowledge.cafemedia.com/food/' === $item->dataset_uri; |
|
| 66 | - } |
|
| 64 | + private function __has_food_kg( $carry, $item ) { |
|
| 65 | + return $carry || 'https://knowledge.cafemedia.com/food/' === $item->dataset_uri; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | } |
@@ -22,46 +22,46 @@ |
||
| 22 | 22 | * @param Api_Service_Ext $api_service |
| 23 | 23 | * @param Recipe_Lift_Strategy[] $recipe_lift_strategies |
| 24 | 24 | */ |
| 25 | - public function __construct( Api_Service_Ext $api_service, array $recipe_lift_strategies ) { |
|
| 25 | + public function __construct(Api_Service_Ext $api_service, array $recipe_lift_strategies) { |
|
| 26 | 26 | $this->api_service = $api_service; |
| 27 | 27 | $this->recipe_lift_strategies = $recipe_lift_strategies; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | public function register_hooks() { |
| 31 | - add_action( 'wl_key_updated', array( $this, '__key_updated' ) ); |
|
| 32 | - add_action( self::RUN_EVENT, array( $this, '__run' ) ); |
|
| 33 | - add_action( 'wp_ajax_wl_food_kg__run', array( $this, '__run' ) ); |
|
| 31 | + add_action('wl_key_updated', array($this, '__key_updated')); |
|
| 32 | + add_action(self::RUN_EVENT, array($this, '__run')); |
|
| 33 | + add_action('wp_ajax_wl_food_kg__run', array($this, '__run')); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | public function __key_updated() { |
| 37 | 37 | try { |
| 38 | 38 | $me_response = $this->api_service->me(); |
| 39 | - $has_food_kg = isset( $me_response->networks ) |
|
| 40 | - && array_reduce( $me_response->networks, array( $this, '__has_food_kg' ), false ); |
|
| 41 | - $next_scheduled = wp_next_scheduled( self::RUN_EVENT ); |
|
| 39 | + $has_food_kg = isset($me_response->networks) |
|
| 40 | + && array_reduce($me_response->networks, array($this, '__has_food_kg'), false); |
|
| 41 | + $next_scheduled = wp_next_scheduled(self::RUN_EVENT); |
|
| 42 | 42 | |
| 43 | 43 | // We're connected to the Food KG, but not yet scheduled. |
| 44 | - if ( $has_food_kg && ! $next_scheduled ) { |
|
| 45 | - wp_schedule_event( time(), 'daily', self::RUN_EVENT ); |
|
| 44 | + if ($has_food_kg && ! $next_scheduled) { |
|
| 45 | + wp_schedule_event(time(), 'daily', self::RUN_EVENT); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // We're not connected to the Food KG, but we're scheduled. |
| 49 | - if ( ! $has_food_kg && $next_scheduled ) { |
|
| 50 | - wp_unschedule_event( $next_scheduled, self::RUN_EVENT ); |
|
| 49 | + if ( ! $has_food_kg && $next_scheduled) { |
|
| 50 | + wp_unschedule_event($next_scheduled, self::RUN_EVENT); |
|
| 51 | 51 | } |
| 52 | 52 | // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
| 53 | - } catch ( \Exception $e ) { |
|
| 53 | + } catch (\Exception $e) { |
|
| 54 | 54 | // Do nothing. |
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | public function __run() { |
| 59 | - foreach ( $this->recipe_lift_strategies as $recipe_lift_strategy ) { |
|
| 59 | + foreach ($this->recipe_lift_strategies as $recipe_lift_strategy) { |
|
| 60 | 60 | $recipe_lift_strategy->run(); |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - private function __has_food_kg( $carry, $item ) { |
|
| 64 | + private function __has_food_kg($carry, $item) { |
|
| 65 | 65 | return $carry || 'https://knowledge.cafemedia.com/food/' === $item->dataset_uri; |
| 66 | 66 | } |
| 67 | 67 | |