@@ -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; |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | use Wordlift\Api\Default_Api_Service; |
| 14 | 14 | |
| 15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | - exit; |
|
| 16 | + exit; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -23,769 +23,769 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class Wordlift_Configuration_Service { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * The entity base path option name. |
|
| 28 | - * |
|
| 29 | - * @since 3.6.0 |
|
| 30 | - */ |
|
| 31 | - const ENTITY_BASE_PATH_KEY = 'wl_entity_base_path'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * The skip wizard (admin installation wizard) option name. |
|
| 35 | - * |
|
| 36 | - * @since 3.9.0 |
|
| 37 | - */ |
|
| 38 | - const SKIP_WIZARD = 'wl_skip_wizard'; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * WordLift's key option name. |
|
| 42 | - * |
|
| 43 | - * @since 3.9.0 |
|
| 44 | - */ |
|
| 45 | - const KEY = 'key'; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * WordLift's configured language option name. |
|
| 49 | - * |
|
| 50 | - * @since 3.9.0 |
|
| 51 | - */ |
|
| 52 | - const LANGUAGE = 'site_language'; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * WordLift's configured country code. |
|
| 56 | - * |
|
| 57 | - * @since 3.18.0 |
|
| 58 | - */ |
|
| 59 | - const COUNTRY_CODE = 'country_code'; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * The alternateName option name. |
|
| 63 | - * |
|
| 64 | - * @since 3.38.6 |
|
| 65 | - */ |
|
| 66 | - const ALTERNATE_NAME = 'wl-alternate-name'; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * The publisher entity post ID option name. |
|
| 70 | - * |
|
| 71 | - * @since 3.9.0 |
|
| 72 | - */ |
|
| 73 | - const PUBLISHER_ID = 'publisher_id'; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * The dataset URI option name |
|
| 77 | - * |
|
| 78 | - * @since 3.10.0 |
|
| 79 | - */ |
|
| 80 | - const DATASET_URI = 'redlink_dataset_uri'; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * The link by default option name. |
|
| 84 | - * |
|
| 85 | - * @since 3.11.0 |
|
| 86 | - */ |
|
| 87 | - const LINK_BY_DEFAULT = 'link_by_default'; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * The analytics enable option. |
|
| 91 | - * |
|
| 92 | - * @since 3.21.0 |
|
| 93 | - */ |
|
| 94 | - const ANALYTICS_ENABLE = 'analytics_enable'; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * The analytics entity uri dimension option. |
|
| 98 | - * |
|
| 99 | - * @since 3.21.0 |
|
| 100 | - */ |
|
| 101 | - const ANALYTICS_ENTITY_URI_DIMENSION = 'analytics_entity_uri_dimension'; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * The analytics entity type dimension option. |
|
| 105 | - * |
|
| 106 | - * @since 3.21.0 |
|
| 107 | - */ |
|
| 108 | - const ANALYTICS_ENTITY_TYPE_DIMENSION = 'analytics_entity_type_dimension'; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * The user preferences about sharing data option. |
|
| 112 | - * |
|
| 113 | - * @since 3.19.0 |
|
| 114 | - */ |
|
| 115 | - const SEND_DIAGNOSTIC = 'send_diagnostic'; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * The package type configuration key. |
|
| 119 | - * |
|
| 120 | - * @since 3.20.0 |
|
| 121 | - */ |
|
| 122 | - const PACKAGE_TYPE = 'package_type'; |
|
| 123 | - /** |
|
| 124 | - * The dataset ids connected to the current key |
|
| 125 | - * |
|
| 126 | - * @since 3.38.5 |
|
| 127 | - */ |
|
| 128 | - const NETWORK_DATASET_IDS = 'network_dataset_ids'; |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * The {@link Wordlift_Log_Service} instance. |
|
| 132 | - * |
|
| 133 | - * @since 3.16.0 |
|
| 134 | - * |
|
| 135 | - * @var \Wordlift_Log_Service $log The {@link Wordlift_Log_Service} instance. |
|
| 136 | - */ |
|
| 137 | - private $log; |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Create a Wordlift_Configuration_Service's instance. |
|
| 141 | - * |
|
| 142 | - * @since 3.6.0 |
|
| 143 | - */ |
|
| 144 | - protected function __construct() { |
|
| 145 | - |
|
| 146 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 147 | - |
|
| 148 | - // Sync some configuration properties when key is validated. |
|
| 149 | - add_action( 'wl_key_validation_response', array( $this, 'sync' ) ); |
|
| 150 | - |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param $response \Wordlift\Api\Response |
|
| 155 | - * |
|
| 156 | - * @return void |
|
| 157 | - */ |
|
| 158 | - public function sync( $response ) { |
|
| 159 | - if ( ! $response->is_success() ) { |
|
| 160 | - return; |
|
| 161 | - } |
|
| 162 | - $data = json_decode( $response->get_body(), true ); |
|
| 163 | - if ( ! is_array( $data ) || ! array_key_exists( 'networkDatasetId', $data ) ) { |
|
| 164 | - return; |
|
| 165 | - } |
|
| 166 | - $this->set_network_dataset_ids( $data['networkDatasetId'] ); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * The Wordlift_Configuration_Service's singleton instance. |
|
| 171 | - * |
|
| 172 | - * @since 3.6.0 |
|
| 173 | - * |
|
| 174 | - * @access private |
|
| 175 | - * @var \Wordlift_Configuration_Service $instance Wordlift_Configuration_Service's singleton instance. |
|
| 176 | - */ |
|
| 177 | - private static $instance = null; |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Get the singleton instance. |
|
| 181 | - * |
|
| 182 | - * @return \Wordlift_Configuration_Service |
|
| 183 | - * @since 3.6.0 |
|
| 184 | - */ |
|
| 185 | - public static function get_instance() { |
|
| 186 | - |
|
| 187 | - if ( ! isset( self::$instance ) ) { |
|
| 188 | - self::$instance = new self(); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return self::$instance; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Get a configuration given the option name and a key. The option value is |
|
| 196 | - * expected to be an array. |
|
| 197 | - * |
|
| 198 | - * @param string $option The option name. |
|
| 199 | - * @param string $key A key in the option value array. |
|
| 200 | - * @param string $default The default value in case the key is not found (by default an empty string). |
|
| 201 | - * |
|
| 202 | - * @return mixed The configuration value or the default value if not found. |
|
| 203 | - * @since 3.6.0 |
|
| 204 | - */ |
|
| 205 | - private function get( $option, $key, $default = '' ) { |
|
| 206 | - |
|
| 207 | - $options = get_option( $option, array() ); |
|
| 208 | - |
|
| 209 | - return isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Set a configuration parameter. |
|
| 214 | - * |
|
| 215 | - * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. |
|
| 216 | - * @param string $key The value key. |
|
| 217 | - * @param mixed $value The value. |
|
| 218 | - * |
|
| 219 | - * @since 3.9.0 |
|
| 220 | - */ |
|
| 221 | - private function set( $option, $key, $value ) { |
|
| 222 | - |
|
| 223 | - $values = get_option( $option ); |
|
| 224 | - $values = isset( $values ) ? $values : array(); |
|
| 225 | - $values[ $key ] = $value; |
|
| 226 | - update_option( $option, $values ); |
|
| 227 | - |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Get the entity base path, by default 'entity'. |
|
| 232 | - * |
|
| 233 | - * @return string The entity base path. |
|
| 234 | - * @since 3.6.0 |
|
| 235 | - */ |
|
| 236 | - public function get_entity_base_path() { |
|
| 237 | - |
|
| 238 | - return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' ); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Get the entity base path. |
|
| 243 | - * |
|
| 244 | - * @param string $value The entity base path. |
|
| 245 | - * |
|
| 246 | - * @since 3.9.0 |
|
| 247 | - */ |
|
| 248 | - public function set_entity_base_path( $value ) { |
|
| 249 | - |
|
| 250 | - $this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value ); |
|
| 251 | - |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Whether the installation skip wizard should be skipped. |
|
| 256 | - * |
|
| 257 | - * @return bool True if it should be skipped otherwise false. |
|
| 258 | - * @since 3.9.0 |
|
| 259 | - */ |
|
| 260 | - public function is_skip_wizard() { |
|
| 261 | - |
|
| 262 | - return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false ); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Set the skip wizard parameter. |
|
| 267 | - * |
|
| 268 | - * @param bool $value True to skip the wizard. We expect a boolean value. |
|
| 269 | - * |
|
| 270 | - * @since 3.9.0 |
|
| 271 | - */ |
|
| 272 | - public function set_skip_wizard( $value ) { |
|
| 273 | - |
|
| 274 | - $this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value ); |
|
| 275 | - |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Get WordLift's key. |
|
| 280 | - * |
|
| 281 | - * @return string WordLift's key or an empty string if not set. |
|
| 282 | - * @since 3.9.0 |
|
| 283 | - */ |
|
| 284 | - public function get_key() { |
|
| 285 | - |
|
| 286 | - return $this->get( 'wl_general_settings', self::KEY, '' ); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Set WordLift's key. |
|
| 291 | - * |
|
| 292 | - * @param string $value WordLift's key. |
|
| 293 | - * |
|
| 294 | - * @since 3.9.0 |
|
| 295 | - */ |
|
| 296 | - public function set_key( $value ) { |
|
| 297 | - |
|
| 298 | - $this->set( 'wl_general_settings', self::KEY, $value ); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Get WordLift's configured language, by default 'en'. |
|
| 303 | - * |
|
| 304 | - * Note that WordLift's language is used when writing strings to the Linked Data dataset, not for the analysis. |
|
| 305 | - * |
|
| 306 | - * @return string WordLift's configured language code ('en' by default). |
|
| 307 | - * @since 3.9.0 |
|
| 308 | - */ |
|
| 309 | - public function get_language_code() { |
|
| 310 | - |
|
| 311 | - $language = get_locale(); |
|
| 312 | - if ( ! $language ) { |
|
| 313 | - return 'en'; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - return substr( $language, 0, 2 ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * @param string $value WordLift's language code. |
|
| 321 | - * |
|
| 322 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1466 |
|
| 323 | - * |
|
| 324 | - * Set WordLift's language code, used when storing strings to the Linked Data dataset. |
|
| 325 | - * |
|
| 326 | - * @deprecated As of 3.32.7 this below method has no effect on setting the language, we use the |
|
| 327 | - * language code form WordPress directly. |
|
| 328 | - * |
|
| 329 | - * @since 3.9.0 |
|
| 330 | - */ |
|
| 331 | - public function set_language_code( $value ) { |
|
| 332 | - |
|
| 333 | - $this->set( 'wl_general_settings', self::LANGUAGE, $value ); |
|
| 334 | - |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Set the user preferences about sharing diagnostic with us. |
|
| 339 | - * |
|
| 340 | - * @param string $value The user preferences(yes/no). |
|
| 341 | - * |
|
| 342 | - * @since 3.19.0 |
|
| 343 | - */ |
|
| 344 | - public function set_diagnostic_preferences( $value ) { |
|
| 345 | - |
|
| 346 | - $this->set( 'wl_general_settings', self::SEND_DIAGNOSTIC, $value ); |
|
| 347 | - |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * Get the user preferences about sharing diagnostic. |
|
| 352 | - * |
|
| 353 | - * @since 3.19.0 |
|
| 354 | - */ |
|
| 355 | - public function get_diagnostic_preferences() { |
|
| 356 | - |
|
| 357 | - return $this->get( 'wl_general_settings', self::SEND_DIAGNOSTIC, 'no' ); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Get WordLift's configured country code, by default 'us'. |
|
| 362 | - * |
|
| 363 | - * @return string WordLift's configured country code ('us' by default). |
|
| 364 | - * @since 3.18.0 |
|
| 365 | - */ |
|
| 366 | - public function get_country_code() { |
|
| 367 | - |
|
| 368 | - return $this->get( 'wl_general_settings', self::COUNTRY_CODE, 'us' ); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Set WordLift's country code. |
|
| 373 | - * |
|
| 374 | - * @param string $value WordLift's country code. |
|
| 375 | - * |
|
| 376 | - * @since 3.18.0 |
|
| 377 | - */ |
|
| 378 | - public function set_country_code( $value ) { |
|
| 379 | - |
|
| 380 | - $this->set( 'wl_general_settings', self::COUNTRY_CODE, $value ); |
|
| 381 | - |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Get the alternateName. |
|
| 386 | - * |
|
| 387 | - * Website markup alternateName |
|
| 388 | - * |
|
| 389 | - * @return string|NULL alternateName or NULL if not set. |
|
| 390 | - * @since 3.38.6 |
|
| 391 | - */ |
|
| 392 | - public function get_alternate_name() { |
|
| 393 | - $alternate_name = $this->get( 'wl_general_settings', self::ALTERNATE_NAME, get_bloginfo( 'description' ) ); |
|
| 394 | - return wp_strip_all_tags( $alternate_name, true ); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Set the alternateName. |
|
| 399 | - * |
|
| 400 | - * @param int $value The alternateName value. |
|
| 401 | - * |
|
| 402 | - * @since 3.38.6 |
|
| 403 | - */ |
|
| 404 | - public function set_alternate_name( $value ) { |
|
| 405 | - |
|
| 406 | - $this->set( 'wl_general_settings', self::ALTERNATE_NAME, $value ); |
|
| 407 | - |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Get the publisher entity post id. |
|
| 412 | - * |
|
| 413 | - * The publisher entity post id points to an entity post which contains the data for the publisher used in schema.org |
|
| 414 | - * Article markup. |
|
| 415 | - * |
|
| 416 | - * @return int|NULL The publisher entity post id or NULL if not set. |
|
| 417 | - * @since 3.9.0 |
|
| 418 | - */ |
|
| 419 | - public function get_publisher_id() { |
|
| 420 | - |
|
| 421 | - return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null ); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Set the publisher entity post id. |
|
| 426 | - * |
|
| 427 | - * @param int $value The publisher entity post id. |
|
| 428 | - * |
|
| 429 | - * @since 3.9.0 |
|
| 430 | - */ |
|
| 431 | - public function set_publisher_id( $value ) { |
|
| 432 | - |
|
| 433 | - $this->set( 'wl_general_settings', self::PUBLISHER_ID, $value ); |
|
| 434 | - |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Get the dataset URI. |
|
| 439 | - * |
|
| 440 | - * @return string The dataset URI or an empty string if not set. |
|
| 441 | - * @since 3.10.0 |
|
| 442 | - * @since 3.27.7 Always return null if `wl_features__enable__dataset` is disabled. |
|
| 443 | - */ |
|
| 444 | - public function get_dataset_uri() { |
|
| 445 | - |
|
| 446 | - if ( apply_filters( 'wl_feature__enable__dataset', true ) ) { |
|
| 447 | - return $this->get( 'wl_advanced_settings', self::DATASET_URI, null ); |
|
| 448 | - } else { |
|
| 449 | - return null; |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Set the dataset URI. |
|
| 455 | - * |
|
| 456 | - * @param string $value The dataset URI. |
|
| 457 | - * |
|
| 458 | - * @since 3.10.0 |
|
| 459 | - */ |
|
| 460 | - public function set_dataset_uri( $value ) { |
|
| 461 | - |
|
| 462 | - $this->set( 'wl_advanced_settings', self::DATASET_URI, $value ); |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * Get the package type. |
|
| 467 | - * |
|
| 468 | - * @return string The package type or an empty string if not set. |
|
| 469 | - * @since 3.20.0 |
|
| 470 | - */ |
|
| 471 | - public function get_package_type() { |
|
| 472 | - |
|
| 473 | - return $this->get( 'wl_advanced_settings', self::PACKAGE_TYPE, null ); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * Set the package type. |
|
| 478 | - * |
|
| 479 | - * @param string $value The package type. |
|
| 480 | - * |
|
| 481 | - * @since 3.20.0 |
|
| 482 | - */ |
|
| 483 | - public function set_package_type( $value ) { |
|
| 484 | - $this->set( 'wl_advanced_settings', self::PACKAGE_TYPE, $value ); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Intercept the change of the WordLift key in order to set the dataset URI. |
|
| 489 | - * |
|
| 490 | - * @since 3.20.0 as of #761, we save settings every time a key is set, not only when the key changes, so to |
|
| 491 | - * store the configuration parameters such as country or language. |
|
| 492 | - * @since 3.11.0 |
|
| 493 | - * |
|
| 494 | - * @see https://github.com/insideout10/wordlift-plugin/issues/761 |
|
| 495 | - * |
|
| 496 | - * @param array $old_value The old settings. |
|
| 497 | - * @param array $new_value The new settings. |
|
| 498 | - */ |
|
| 499 | - public function update_key( $old_value, $new_value ) { |
|
| 500 | - |
|
| 501 | - // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed. |
|
| 502 | - // $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 503 | - $new_key = isset( $new_value['key'] ) ? $new_value['key'] : ''; |
|
| 504 | - |
|
| 505 | - // If the key hasn't changed, don't do anything. |
|
| 506 | - // WARN The 'update_option' hook is fired only if the new and old value are not equal. |
|
| 507 | - // if ( $old_key === $new_key ) { |
|
| 508 | - // return; |
|
| 509 | - // } |
|
| 510 | - |
|
| 511 | - // If the key is empty, empty the dataset URI. |
|
| 512 | - if ( '' === $new_key ) { |
|
| 513 | - $this->set_dataset_uri( '' ); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - // make the request to the remote server. |
|
| 517 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 518 | - |
|
| 519 | - do_action( 'wl_key_updated' ); |
|
| 520 | - |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * Handle retrieving the dataset uri from the remote server. |
|
| 525 | - * |
|
| 526 | - * If a valid dataset uri is returned it is stored in the appropriate option, |
|
| 527 | - * otherwise the option is set to empty string. |
|
| 528 | - * |
|
| 529 | - * @param string $key The key to be used. |
|
| 530 | - * |
|
| 531 | - * @since 3.12.0 |
|
| 532 | - * |
|
| 533 | - * @since 3.17.0 send the site URL and get the dataset URI. |
|
| 534 | - */ |
|
| 535 | - public function get_remote_dataset_uri( $key ) { |
|
| 536 | - |
|
| 537 | - $this->log->trace( 'Getting the remote dataset URI and package type...' ); |
|
| 538 | - |
|
| 539 | - if ( empty( $key ) ) { |
|
| 540 | - $this->log->warn( 'Key set to empty value.' ); |
|
| 541 | - |
|
| 542 | - $this->set_dataset_uri( '' ); |
|
| 543 | - $this->set_package_type( null ); |
|
| 544 | - |
|
| 545 | - return; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Allow 3rd parties to change the site_url. |
|
| 550 | - * |
|
| 551 | - * @param string $site_url The site url. |
|
| 552 | - * |
|
| 553 | - * @see https://github.com/insideout10/wordlift-plugin/issues/850 |
|
| 554 | - * |
|
| 555 | - * @since 3.20.0 |
|
| 556 | - */ |
|
| 557 | - $home_url = get_option( 'home' ); |
|
| 558 | - $site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) ); |
|
| 559 | - |
|
| 560 | - // Build the URL. |
|
| 561 | - $url = '/accounts' |
|
| 562 | - . '?key=' . rawurlencode( $key ) |
|
| 563 | - . '&url=' . rawurlencode( $site_url ) |
|
| 564 | - . '&country=' . $this->get_country_code() |
|
| 565 | - . '&language=' . $this->get_language_code(); |
|
| 566 | - |
|
| 567 | - $api_service = Default_Api_Service::get_instance(); |
|
| 568 | - /** |
|
| 569 | - * @since 3.27.7.1 |
|
| 570 | - * The Key should be passed to headers, otherwise api would return null. |
|
| 571 | - */ |
|
| 572 | - $headers = array( |
|
| 573 | - 'Authorization' => "Key $key", |
|
| 574 | - ); |
|
| 575 | - $response = $api_service->request( 'PUT', $url, $headers )->get_response(); |
|
| 576 | - |
|
| 577 | - // The response is an error. |
|
| 578 | - if ( is_wp_error( $response ) ) { |
|
| 579 | - $this->log->error( 'An error occurred setting the dataset URI: ' . $response->get_error_message() ); |
|
| 580 | - |
|
| 581 | - $this->set_dataset_uri( '' ); |
|
| 582 | - $this->set_package_type( null ); |
|
| 583 | - |
|
| 584 | - return; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - // The response is not OK. |
|
| 588 | - if ( ! is_array( $response ) || 200 !== (int) $response['response']['code'] ) { |
|
| 589 | - $base_url = $api_service->get_base_url(); |
|
| 590 | - |
|
| 591 | - if ( ! is_array( $response ) ) { |
|
| 592 | - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export |
|
| 593 | - $this->log->error( "Unexpected response when opening URL $base_url$url: " . var_export( $response, true ) ); |
|
| 594 | - } else { |
|
| 595 | - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export |
|
| 596 | - $this->log->error( "Unexpected status code when opening URL $base_url$url: " . $response['response']['code'] . "\n" . var_export( $response, true ) ); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - $this->set_dataset_uri( '' ); |
|
| 600 | - $this->set_package_type( null ); |
|
| 601 | - |
|
| 602 | - return; |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - /* |
|
| 26 | + /** |
|
| 27 | + * The entity base path option name. |
|
| 28 | + * |
|
| 29 | + * @since 3.6.0 |
|
| 30 | + */ |
|
| 31 | + const ENTITY_BASE_PATH_KEY = 'wl_entity_base_path'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * The skip wizard (admin installation wizard) option name. |
|
| 35 | + * |
|
| 36 | + * @since 3.9.0 |
|
| 37 | + */ |
|
| 38 | + const SKIP_WIZARD = 'wl_skip_wizard'; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * WordLift's key option name. |
|
| 42 | + * |
|
| 43 | + * @since 3.9.0 |
|
| 44 | + */ |
|
| 45 | + const KEY = 'key'; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * WordLift's configured language option name. |
|
| 49 | + * |
|
| 50 | + * @since 3.9.0 |
|
| 51 | + */ |
|
| 52 | + const LANGUAGE = 'site_language'; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * WordLift's configured country code. |
|
| 56 | + * |
|
| 57 | + * @since 3.18.0 |
|
| 58 | + */ |
|
| 59 | + const COUNTRY_CODE = 'country_code'; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * The alternateName option name. |
|
| 63 | + * |
|
| 64 | + * @since 3.38.6 |
|
| 65 | + */ |
|
| 66 | + const ALTERNATE_NAME = 'wl-alternate-name'; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * The publisher entity post ID option name. |
|
| 70 | + * |
|
| 71 | + * @since 3.9.0 |
|
| 72 | + */ |
|
| 73 | + const PUBLISHER_ID = 'publisher_id'; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * The dataset URI option name |
|
| 77 | + * |
|
| 78 | + * @since 3.10.0 |
|
| 79 | + */ |
|
| 80 | + const DATASET_URI = 'redlink_dataset_uri'; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * The link by default option name. |
|
| 84 | + * |
|
| 85 | + * @since 3.11.0 |
|
| 86 | + */ |
|
| 87 | + const LINK_BY_DEFAULT = 'link_by_default'; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * The analytics enable option. |
|
| 91 | + * |
|
| 92 | + * @since 3.21.0 |
|
| 93 | + */ |
|
| 94 | + const ANALYTICS_ENABLE = 'analytics_enable'; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * The analytics entity uri dimension option. |
|
| 98 | + * |
|
| 99 | + * @since 3.21.0 |
|
| 100 | + */ |
|
| 101 | + const ANALYTICS_ENTITY_URI_DIMENSION = 'analytics_entity_uri_dimension'; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * The analytics entity type dimension option. |
|
| 105 | + * |
|
| 106 | + * @since 3.21.0 |
|
| 107 | + */ |
|
| 108 | + const ANALYTICS_ENTITY_TYPE_DIMENSION = 'analytics_entity_type_dimension'; |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * The user preferences about sharing data option. |
|
| 112 | + * |
|
| 113 | + * @since 3.19.0 |
|
| 114 | + */ |
|
| 115 | + const SEND_DIAGNOSTIC = 'send_diagnostic'; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * The package type configuration key. |
|
| 119 | + * |
|
| 120 | + * @since 3.20.0 |
|
| 121 | + */ |
|
| 122 | + const PACKAGE_TYPE = 'package_type'; |
|
| 123 | + /** |
|
| 124 | + * The dataset ids connected to the current key |
|
| 125 | + * |
|
| 126 | + * @since 3.38.5 |
|
| 127 | + */ |
|
| 128 | + const NETWORK_DATASET_IDS = 'network_dataset_ids'; |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * The {@link Wordlift_Log_Service} instance. |
|
| 132 | + * |
|
| 133 | + * @since 3.16.0 |
|
| 134 | + * |
|
| 135 | + * @var \Wordlift_Log_Service $log The {@link Wordlift_Log_Service} instance. |
|
| 136 | + */ |
|
| 137 | + private $log; |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Create a Wordlift_Configuration_Service's instance. |
|
| 141 | + * |
|
| 142 | + * @since 3.6.0 |
|
| 143 | + */ |
|
| 144 | + protected function __construct() { |
|
| 145 | + |
|
| 146 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 147 | + |
|
| 148 | + // Sync some configuration properties when key is validated. |
|
| 149 | + add_action( 'wl_key_validation_response', array( $this, 'sync' ) ); |
|
| 150 | + |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param $response \Wordlift\Api\Response |
|
| 155 | + * |
|
| 156 | + * @return void |
|
| 157 | + */ |
|
| 158 | + public function sync( $response ) { |
|
| 159 | + if ( ! $response->is_success() ) { |
|
| 160 | + return; |
|
| 161 | + } |
|
| 162 | + $data = json_decode( $response->get_body(), true ); |
|
| 163 | + if ( ! is_array( $data ) || ! array_key_exists( 'networkDatasetId', $data ) ) { |
|
| 164 | + return; |
|
| 165 | + } |
|
| 166 | + $this->set_network_dataset_ids( $data['networkDatasetId'] ); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * The Wordlift_Configuration_Service's singleton instance. |
|
| 171 | + * |
|
| 172 | + * @since 3.6.0 |
|
| 173 | + * |
|
| 174 | + * @access private |
|
| 175 | + * @var \Wordlift_Configuration_Service $instance Wordlift_Configuration_Service's singleton instance. |
|
| 176 | + */ |
|
| 177 | + private static $instance = null; |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Get the singleton instance. |
|
| 181 | + * |
|
| 182 | + * @return \Wordlift_Configuration_Service |
|
| 183 | + * @since 3.6.0 |
|
| 184 | + */ |
|
| 185 | + public static function get_instance() { |
|
| 186 | + |
|
| 187 | + if ( ! isset( self::$instance ) ) { |
|
| 188 | + self::$instance = new self(); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return self::$instance; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Get a configuration given the option name and a key. The option value is |
|
| 196 | + * expected to be an array. |
|
| 197 | + * |
|
| 198 | + * @param string $option The option name. |
|
| 199 | + * @param string $key A key in the option value array. |
|
| 200 | + * @param string $default The default value in case the key is not found (by default an empty string). |
|
| 201 | + * |
|
| 202 | + * @return mixed The configuration value or the default value if not found. |
|
| 203 | + * @since 3.6.0 |
|
| 204 | + */ |
|
| 205 | + private function get( $option, $key, $default = '' ) { |
|
| 206 | + |
|
| 207 | + $options = get_option( $option, array() ); |
|
| 208 | + |
|
| 209 | + return isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Set a configuration parameter. |
|
| 214 | + * |
|
| 215 | + * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. |
|
| 216 | + * @param string $key The value key. |
|
| 217 | + * @param mixed $value The value. |
|
| 218 | + * |
|
| 219 | + * @since 3.9.0 |
|
| 220 | + */ |
|
| 221 | + private function set( $option, $key, $value ) { |
|
| 222 | + |
|
| 223 | + $values = get_option( $option ); |
|
| 224 | + $values = isset( $values ) ? $values : array(); |
|
| 225 | + $values[ $key ] = $value; |
|
| 226 | + update_option( $option, $values ); |
|
| 227 | + |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Get the entity base path, by default 'entity'. |
|
| 232 | + * |
|
| 233 | + * @return string The entity base path. |
|
| 234 | + * @since 3.6.0 |
|
| 235 | + */ |
|
| 236 | + public function get_entity_base_path() { |
|
| 237 | + |
|
| 238 | + return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' ); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Get the entity base path. |
|
| 243 | + * |
|
| 244 | + * @param string $value The entity base path. |
|
| 245 | + * |
|
| 246 | + * @since 3.9.0 |
|
| 247 | + */ |
|
| 248 | + public function set_entity_base_path( $value ) { |
|
| 249 | + |
|
| 250 | + $this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value ); |
|
| 251 | + |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Whether the installation skip wizard should be skipped. |
|
| 256 | + * |
|
| 257 | + * @return bool True if it should be skipped otherwise false. |
|
| 258 | + * @since 3.9.0 |
|
| 259 | + */ |
|
| 260 | + public function is_skip_wizard() { |
|
| 261 | + |
|
| 262 | + return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false ); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Set the skip wizard parameter. |
|
| 267 | + * |
|
| 268 | + * @param bool $value True to skip the wizard. We expect a boolean value. |
|
| 269 | + * |
|
| 270 | + * @since 3.9.0 |
|
| 271 | + */ |
|
| 272 | + public function set_skip_wizard( $value ) { |
|
| 273 | + |
|
| 274 | + $this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value ); |
|
| 275 | + |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Get WordLift's key. |
|
| 280 | + * |
|
| 281 | + * @return string WordLift's key or an empty string if not set. |
|
| 282 | + * @since 3.9.0 |
|
| 283 | + */ |
|
| 284 | + public function get_key() { |
|
| 285 | + |
|
| 286 | + return $this->get( 'wl_general_settings', self::KEY, '' ); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Set WordLift's key. |
|
| 291 | + * |
|
| 292 | + * @param string $value WordLift's key. |
|
| 293 | + * |
|
| 294 | + * @since 3.9.0 |
|
| 295 | + */ |
|
| 296 | + public function set_key( $value ) { |
|
| 297 | + |
|
| 298 | + $this->set( 'wl_general_settings', self::KEY, $value ); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Get WordLift's configured language, by default 'en'. |
|
| 303 | + * |
|
| 304 | + * Note that WordLift's language is used when writing strings to the Linked Data dataset, not for the analysis. |
|
| 305 | + * |
|
| 306 | + * @return string WordLift's configured language code ('en' by default). |
|
| 307 | + * @since 3.9.0 |
|
| 308 | + */ |
|
| 309 | + public function get_language_code() { |
|
| 310 | + |
|
| 311 | + $language = get_locale(); |
|
| 312 | + if ( ! $language ) { |
|
| 313 | + return 'en'; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + return substr( $language, 0, 2 ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * @param string $value WordLift's language code. |
|
| 321 | + * |
|
| 322 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1466 |
|
| 323 | + * |
|
| 324 | + * Set WordLift's language code, used when storing strings to the Linked Data dataset. |
|
| 325 | + * |
|
| 326 | + * @deprecated As of 3.32.7 this below method has no effect on setting the language, we use the |
|
| 327 | + * language code form WordPress directly. |
|
| 328 | + * |
|
| 329 | + * @since 3.9.0 |
|
| 330 | + */ |
|
| 331 | + public function set_language_code( $value ) { |
|
| 332 | + |
|
| 333 | + $this->set( 'wl_general_settings', self::LANGUAGE, $value ); |
|
| 334 | + |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Set the user preferences about sharing diagnostic with us. |
|
| 339 | + * |
|
| 340 | + * @param string $value The user preferences(yes/no). |
|
| 341 | + * |
|
| 342 | + * @since 3.19.0 |
|
| 343 | + */ |
|
| 344 | + public function set_diagnostic_preferences( $value ) { |
|
| 345 | + |
|
| 346 | + $this->set( 'wl_general_settings', self::SEND_DIAGNOSTIC, $value ); |
|
| 347 | + |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * Get the user preferences about sharing diagnostic. |
|
| 352 | + * |
|
| 353 | + * @since 3.19.0 |
|
| 354 | + */ |
|
| 355 | + public function get_diagnostic_preferences() { |
|
| 356 | + |
|
| 357 | + return $this->get( 'wl_general_settings', self::SEND_DIAGNOSTIC, 'no' ); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Get WordLift's configured country code, by default 'us'. |
|
| 362 | + * |
|
| 363 | + * @return string WordLift's configured country code ('us' by default). |
|
| 364 | + * @since 3.18.0 |
|
| 365 | + */ |
|
| 366 | + public function get_country_code() { |
|
| 367 | + |
|
| 368 | + return $this->get( 'wl_general_settings', self::COUNTRY_CODE, 'us' ); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Set WordLift's country code. |
|
| 373 | + * |
|
| 374 | + * @param string $value WordLift's country code. |
|
| 375 | + * |
|
| 376 | + * @since 3.18.0 |
|
| 377 | + */ |
|
| 378 | + public function set_country_code( $value ) { |
|
| 379 | + |
|
| 380 | + $this->set( 'wl_general_settings', self::COUNTRY_CODE, $value ); |
|
| 381 | + |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Get the alternateName. |
|
| 386 | + * |
|
| 387 | + * Website markup alternateName |
|
| 388 | + * |
|
| 389 | + * @return string|NULL alternateName or NULL if not set. |
|
| 390 | + * @since 3.38.6 |
|
| 391 | + */ |
|
| 392 | + public function get_alternate_name() { |
|
| 393 | + $alternate_name = $this->get( 'wl_general_settings', self::ALTERNATE_NAME, get_bloginfo( 'description' ) ); |
|
| 394 | + return wp_strip_all_tags( $alternate_name, true ); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Set the alternateName. |
|
| 399 | + * |
|
| 400 | + * @param int $value The alternateName value. |
|
| 401 | + * |
|
| 402 | + * @since 3.38.6 |
|
| 403 | + */ |
|
| 404 | + public function set_alternate_name( $value ) { |
|
| 405 | + |
|
| 406 | + $this->set( 'wl_general_settings', self::ALTERNATE_NAME, $value ); |
|
| 407 | + |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Get the publisher entity post id. |
|
| 412 | + * |
|
| 413 | + * The publisher entity post id points to an entity post which contains the data for the publisher used in schema.org |
|
| 414 | + * Article markup. |
|
| 415 | + * |
|
| 416 | + * @return int|NULL The publisher entity post id or NULL if not set. |
|
| 417 | + * @since 3.9.0 |
|
| 418 | + */ |
|
| 419 | + public function get_publisher_id() { |
|
| 420 | + |
|
| 421 | + return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null ); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Set the publisher entity post id. |
|
| 426 | + * |
|
| 427 | + * @param int $value The publisher entity post id. |
|
| 428 | + * |
|
| 429 | + * @since 3.9.0 |
|
| 430 | + */ |
|
| 431 | + public function set_publisher_id( $value ) { |
|
| 432 | + |
|
| 433 | + $this->set( 'wl_general_settings', self::PUBLISHER_ID, $value ); |
|
| 434 | + |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Get the dataset URI. |
|
| 439 | + * |
|
| 440 | + * @return string The dataset URI or an empty string if not set. |
|
| 441 | + * @since 3.10.0 |
|
| 442 | + * @since 3.27.7 Always return null if `wl_features__enable__dataset` is disabled. |
|
| 443 | + */ |
|
| 444 | + public function get_dataset_uri() { |
|
| 445 | + |
|
| 446 | + if ( apply_filters( 'wl_feature__enable__dataset', true ) ) { |
|
| 447 | + return $this->get( 'wl_advanced_settings', self::DATASET_URI, null ); |
|
| 448 | + } else { |
|
| 449 | + return null; |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Set the dataset URI. |
|
| 455 | + * |
|
| 456 | + * @param string $value The dataset URI. |
|
| 457 | + * |
|
| 458 | + * @since 3.10.0 |
|
| 459 | + */ |
|
| 460 | + public function set_dataset_uri( $value ) { |
|
| 461 | + |
|
| 462 | + $this->set( 'wl_advanced_settings', self::DATASET_URI, $value ); |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * Get the package type. |
|
| 467 | + * |
|
| 468 | + * @return string The package type or an empty string if not set. |
|
| 469 | + * @since 3.20.0 |
|
| 470 | + */ |
|
| 471 | + public function get_package_type() { |
|
| 472 | + |
|
| 473 | + return $this->get( 'wl_advanced_settings', self::PACKAGE_TYPE, null ); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * Set the package type. |
|
| 478 | + * |
|
| 479 | + * @param string $value The package type. |
|
| 480 | + * |
|
| 481 | + * @since 3.20.0 |
|
| 482 | + */ |
|
| 483 | + public function set_package_type( $value ) { |
|
| 484 | + $this->set( 'wl_advanced_settings', self::PACKAGE_TYPE, $value ); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Intercept the change of the WordLift key in order to set the dataset URI. |
|
| 489 | + * |
|
| 490 | + * @since 3.20.0 as of #761, we save settings every time a key is set, not only when the key changes, so to |
|
| 491 | + * store the configuration parameters such as country or language. |
|
| 492 | + * @since 3.11.0 |
|
| 493 | + * |
|
| 494 | + * @see https://github.com/insideout10/wordlift-plugin/issues/761 |
|
| 495 | + * |
|
| 496 | + * @param array $old_value The old settings. |
|
| 497 | + * @param array $new_value The new settings. |
|
| 498 | + */ |
|
| 499 | + public function update_key( $old_value, $new_value ) { |
|
| 500 | + |
|
| 501 | + // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed. |
|
| 502 | + // $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 503 | + $new_key = isset( $new_value['key'] ) ? $new_value['key'] : ''; |
|
| 504 | + |
|
| 505 | + // If the key hasn't changed, don't do anything. |
|
| 506 | + // WARN The 'update_option' hook is fired only if the new and old value are not equal. |
|
| 507 | + // if ( $old_key === $new_key ) { |
|
| 508 | + // return; |
|
| 509 | + // } |
|
| 510 | + |
|
| 511 | + // If the key is empty, empty the dataset URI. |
|
| 512 | + if ( '' === $new_key ) { |
|
| 513 | + $this->set_dataset_uri( '' ); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + // make the request to the remote server. |
|
| 517 | + $this->get_remote_dataset_uri( $new_key ); |
|
| 518 | + |
|
| 519 | + do_action( 'wl_key_updated' ); |
|
| 520 | + |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * Handle retrieving the dataset uri from the remote server. |
|
| 525 | + * |
|
| 526 | + * If a valid dataset uri is returned it is stored in the appropriate option, |
|
| 527 | + * otherwise the option is set to empty string. |
|
| 528 | + * |
|
| 529 | + * @param string $key The key to be used. |
|
| 530 | + * |
|
| 531 | + * @since 3.12.0 |
|
| 532 | + * |
|
| 533 | + * @since 3.17.0 send the site URL and get the dataset URI. |
|
| 534 | + */ |
|
| 535 | + public function get_remote_dataset_uri( $key ) { |
|
| 536 | + |
|
| 537 | + $this->log->trace( 'Getting the remote dataset URI and package type...' ); |
|
| 538 | + |
|
| 539 | + if ( empty( $key ) ) { |
|
| 540 | + $this->log->warn( 'Key set to empty value.' ); |
|
| 541 | + |
|
| 542 | + $this->set_dataset_uri( '' ); |
|
| 543 | + $this->set_package_type( null ); |
|
| 544 | + |
|
| 545 | + return; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Allow 3rd parties to change the site_url. |
|
| 550 | + * |
|
| 551 | + * @param string $site_url The site url. |
|
| 552 | + * |
|
| 553 | + * @see https://github.com/insideout10/wordlift-plugin/issues/850 |
|
| 554 | + * |
|
| 555 | + * @since 3.20.0 |
|
| 556 | + */ |
|
| 557 | + $home_url = get_option( 'home' ); |
|
| 558 | + $site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) ); |
|
| 559 | + |
|
| 560 | + // Build the URL. |
|
| 561 | + $url = '/accounts' |
|
| 562 | + . '?key=' . rawurlencode( $key ) |
|
| 563 | + . '&url=' . rawurlencode( $site_url ) |
|
| 564 | + . '&country=' . $this->get_country_code() |
|
| 565 | + . '&language=' . $this->get_language_code(); |
|
| 566 | + |
|
| 567 | + $api_service = Default_Api_Service::get_instance(); |
|
| 568 | + /** |
|
| 569 | + * @since 3.27.7.1 |
|
| 570 | + * The Key should be passed to headers, otherwise api would return null. |
|
| 571 | + */ |
|
| 572 | + $headers = array( |
|
| 573 | + 'Authorization' => "Key $key", |
|
| 574 | + ); |
|
| 575 | + $response = $api_service->request( 'PUT', $url, $headers )->get_response(); |
|
| 576 | + |
|
| 577 | + // The response is an error. |
|
| 578 | + if ( is_wp_error( $response ) ) { |
|
| 579 | + $this->log->error( 'An error occurred setting the dataset URI: ' . $response->get_error_message() ); |
|
| 580 | + |
|
| 581 | + $this->set_dataset_uri( '' ); |
|
| 582 | + $this->set_package_type( null ); |
|
| 583 | + |
|
| 584 | + return; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + // The response is not OK. |
|
| 588 | + if ( ! is_array( $response ) || 200 !== (int) $response['response']['code'] ) { |
|
| 589 | + $base_url = $api_service->get_base_url(); |
|
| 590 | + |
|
| 591 | + if ( ! is_array( $response ) ) { |
|
| 592 | + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export |
|
| 593 | + $this->log->error( "Unexpected response when opening URL $base_url$url: " . var_export( $response, true ) ); |
|
| 594 | + } else { |
|
| 595 | + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export |
|
| 596 | + $this->log->error( "Unexpected status code when opening URL $base_url$url: " . $response['response']['code'] . "\n" . var_export( $response, true ) ); |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + $this->set_dataset_uri( '' ); |
|
| 600 | + $this->set_package_type( null ); |
|
| 601 | + |
|
| 602 | + return; |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + /* |
|
| 606 | 606 | * We also store the package type. |
| 607 | 607 | * |
| 608 | 608 | * @since 3.20.0 |
| 609 | 609 | */ |
| 610 | - $json = json_decode( $response['body'] ); |
|
| 611 | - /** |
|
| 612 | - * @since 3.27.7 |
|
| 613 | - * Remove the trailing slash returned from the new platform api. |
|
| 614 | - */ |
|
| 615 | - // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 616 | - $dataset_uri = untrailingslashit( $json->datasetURI ); |
|
| 617 | - // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 618 | - $package_type = isset( $json->packageType ) ? $json->packageType : null; |
|
| 619 | - |
|
| 620 | - $this->log->info( "Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..." ); |
|
| 621 | - |
|
| 622 | - $this->set_dataset_uri( $dataset_uri ); |
|
| 623 | - $this->set_package_type( $package_type ); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * Handle the edge case where a user submits the same key again |
|
| 628 | - * when he does not have the dataset uri to regain it. |
|
| 629 | - * |
|
| 630 | - * This can not be handled in the normal option update hook because |
|
| 631 | - * it is not being triggered when the save value equals to the one already |
|
| 632 | - * in the DB. |
|
| 633 | - * |
|
| 634 | - * @param mixed $value The new, unserialized option value. |
|
| 635 | - * @param mixed $old_value The old option value. |
|
| 636 | - * |
|
| 637 | - * @return mixed The same value in the $value parameter |
|
| 638 | - * @since 3.12.0 |
|
| 639 | - */ |
|
| 640 | - public function maybe_update_dataset_uri( $value, $old_value ) { |
|
| 641 | - |
|
| 642 | - // Check the old key value and the new one. Here we're only handling the |
|
| 643 | - // case where the key hasn't changed and the dataset URI isn't set. The |
|
| 644 | - // other case, i.e. a new key is inserted, is handled at `update_key`. |
|
| 645 | - $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 646 | - $new_key = isset( $value['key'] ) ? $value['key'] : ''; |
|
| 647 | - |
|
| 648 | - $dataset_uri = $this->get_dataset_uri(); |
|
| 649 | - |
|
| 650 | - if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) { |
|
| 651 | - |
|
| 652 | - // make the request to the remote server to try to get the dataset uri. |
|
| 653 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - return $value; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * Get the API URI to retrieve the dataset URI using the WordLift Key. |
|
| 661 | - * |
|
| 662 | - * @param string $key The WordLift key to use. |
|
| 663 | - * |
|
| 664 | - * @return string The API URI. |
|
| 665 | - * @since 3.11.0 |
|
| 666 | - */ |
|
| 667 | - public function get_accounts_by_key_dataset_uri( $key ) { |
|
| 668 | - |
|
| 669 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - /** |
|
| 673 | - * Get the `accounts` end point. |
|
| 674 | - * |
|
| 675 | - * @return string The `accounts` end point. |
|
| 676 | - * @since 3.16.0 |
|
| 677 | - */ |
|
| 678 | - public function get_accounts() { |
|
| 679 | - |
|
| 680 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'accounts'; |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * Get the `link by default` option. |
|
| 685 | - * |
|
| 686 | - * @return bool True if entities must be linked by default otherwise false. |
|
| 687 | - * @since 3.13.0 |
|
| 688 | - */ |
|
| 689 | - public function is_link_by_default() { |
|
| 690 | - |
|
| 691 | - return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' ); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * Set the `link by default` option. |
|
| 696 | - * |
|
| 697 | - * @param bool $value True to enabling linking by default, otherwise false. |
|
| 698 | - * |
|
| 699 | - * @since 3.13.0 |
|
| 700 | - */ |
|
| 701 | - public function set_link_by_default( $value ) { |
|
| 702 | - |
|
| 703 | - $this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' ); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * Get the 'analytics-enable' option. |
|
| 708 | - * |
|
| 709 | - * @return string 'no' or 'yes' representing bool. |
|
| 710 | - * @since 3.21.0 |
|
| 711 | - */ |
|
| 712 | - public function is_analytics_enable() { |
|
| 713 | - return 'yes' === $this->get( 'wl_analytics_settings', self::ANALYTICS_ENABLE, 'no' ); |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - /** |
|
| 717 | - * Set the `analytics-enable` option. |
|
| 718 | - * |
|
| 719 | - * @param bool $value True to enabling analytics, otherwise false. |
|
| 720 | - * |
|
| 721 | - * @since 3.21.0 |
|
| 722 | - */ |
|
| 723 | - public function set_is_analytics_enable( $value ) { |
|
| 724 | - |
|
| 725 | - $this->set( 'wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no' ); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - /** |
|
| 729 | - * Get the 'analytics-entity-uri-dimention' option. |
|
| 730 | - * |
|
| 731 | - * @return int |
|
| 732 | - * @since 3.21.0 |
|
| 733 | - */ |
|
| 734 | - public function get_analytics_entity_uri_dimension() { |
|
| 735 | - return (int) $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1 ); |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - /** |
|
| 739 | - * Get the 'analytics-entity-type-dimension' option. |
|
| 740 | - * |
|
| 741 | - * @return int |
|
| 742 | - * @since 3.21.0 |
|
| 743 | - */ |
|
| 744 | - public function get_analytics_entity_type_dimension() { |
|
| 745 | - return $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2 ); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - /** |
|
| 749 | - * Get the URL to perform autocomplete request. |
|
| 750 | - * |
|
| 751 | - * @return string The URL to call to perform the autocomplete request. |
|
| 752 | - * @since 3.15.0 |
|
| 753 | - */ |
|
| 754 | - public function get_autocomplete_url() { |
|
| 755 | - |
|
| 756 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'autocomplete'; |
|
| 757 | - |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - /** |
|
| 761 | - * Get the URL to perform feedback deactivation request. |
|
| 762 | - * |
|
| 763 | - * @return string The URL to call to perform the feedback deactivation request. |
|
| 764 | - * @since 3.19.0 |
|
| 765 | - */ |
|
| 766 | - public function get_deactivation_feedback_url() { |
|
| 767 | - |
|
| 768 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'feedbacks'; |
|
| 769 | - |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - /** |
|
| 773 | - * Get the base API URL. |
|
| 774 | - * |
|
| 775 | - * @return string The base API URL. |
|
| 776 | - * @since 3.20.0 |
|
| 777 | - */ |
|
| 778 | - public function get_api_url() { |
|
| 779 | - |
|
| 780 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE; |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - public function get_network_dataset_ids() { |
|
| 784 | - return $this->get( 'wl_advanced_settings', self::NETWORK_DATASET_IDS, array() ); |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - public function set_network_dataset_ids( $network_dataset_ids ) { |
|
| 788 | - $this->set( 'wl_advanced_settings', self::NETWORK_DATASET_IDS, $network_dataset_ids ); |
|
| 789 | - } |
|
| 610 | + $json = json_decode( $response['body'] ); |
|
| 611 | + /** |
|
| 612 | + * @since 3.27.7 |
|
| 613 | + * Remove the trailing slash returned from the new platform api. |
|
| 614 | + */ |
|
| 615 | + // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 616 | + $dataset_uri = untrailingslashit( $json->datasetURI ); |
|
| 617 | + // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 618 | + $package_type = isset( $json->packageType ) ? $json->packageType : null; |
|
| 619 | + |
|
| 620 | + $this->log->info( "Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..." ); |
|
| 621 | + |
|
| 622 | + $this->set_dataset_uri( $dataset_uri ); |
|
| 623 | + $this->set_package_type( $package_type ); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * Handle the edge case where a user submits the same key again |
|
| 628 | + * when he does not have the dataset uri to regain it. |
|
| 629 | + * |
|
| 630 | + * This can not be handled in the normal option update hook because |
|
| 631 | + * it is not being triggered when the save value equals to the one already |
|
| 632 | + * in the DB. |
|
| 633 | + * |
|
| 634 | + * @param mixed $value The new, unserialized option value. |
|
| 635 | + * @param mixed $old_value The old option value. |
|
| 636 | + * |
|
| 637 | + * @return mixed The same value in the $value parameter |
|
| 638 | + * @since 3.12.0 |
|
| 639 | + */ |
|
| 640 | + public function maybe_update_dataset_uri( $value, $old_value ) { |
|
| 641 | + |
|
| 642 | + // Check the old key value and the new one. Here we're only handling the |
|
| 643 | + // case where the key hasn't changed and the dataset URI isn't set. The |
|
| 644 | + // other case, i.e. a new key is inserted, is handled at `update_key`. |
|
| 645 | + $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 646 | + $new_key = isset( $value['key'] ) ? $value['key'] : ''; |
|
| 647 | + |
|
| 648 | + $dataset_uri = $this->get_dataset_uri(); |
|
| 649 | + |
|
| 650 | + if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) { |
|
| 651 | + |
|
| 652 | + // make the request to the remote server to try to get the dataset uri. |
|
| 653 | + $this->get_remote_dataset_uri( $new_key ); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + return $value; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * Get the API URI to retrieve the dataset URI using the WordLift Key. |
|
| 661 | + * |
|
| 662 | + * @param string $key The WordLift key to use. |
|
| 663 | + * |
|
| 664 | + * @return string The API URI. |
|
| 665 | + * @since 3.11.0 |
|
| 666 | + */ |
|
| 667 | + public function get_accounts_by_key_dataset_uri( $key ) { |
|
| 668 | + |
|
| 669 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + /** |
|
| 673 | + * Get the `accounts` end point. |
|
| 674 | + * |
|
| 675 | + * @return string The `accounts` end point. |
|
| 676 | + * @since 3.16.0 |
|
| 677 | + */ |
|
| 678 | + public function get_accounts() { |
|
| 679 | + |
|
| 680 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'accounts'; |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * Get the `link by default` option. |
|
| 685 | + * |
|
| 686 | + * @return bool True if entities must be linked by default otherwise false. |
|
| 687 | + * @since 3.13.0 |
|
| 688 | + */ |
|
| 689 | + public function is_link_by_default() { |
|
| 690 | + |
|
| 691 | + return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' ); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * Set the `link by default` option. |
|
| 696 | + * |
|
| 697 | + * @param bool $value True to enabling linking by default, otherwise false. |
|
| 698 | + * |
|
| 699 | + * @since 3.13.0 |
|
| 700 | + */ |
|
| 701 | + public function set_link_by_default( $value ) { |
|
| 702 | + |
|
| 703 | + $this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' ); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * Get the 'analytics-enable' option. |
|
| 708 | + * |
|
| 709 | + * @return string 'no' or 'yes' representing bool. |
|
| 710 | + * @since 3.21.0 |
|
| 711 | + */ |
|
| 712 | + public function is_analytics_enable() { |
|
| 713 | + return 'yes' === $this->get( 'wl_analytics_settings', self::ANALYTICS_ENABLE, 'no' ); |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + /** |
|
| 717 | + * Set the `analytics-enable` option. |
|
| 718 | + * |
|
| 719 | + * @param bool $value True to enabling analytics, otherwise false. |
|
| 720 | + * |
|
| 721 | + * @since 3.21.0 |
|
| 722 | + */ |
|
| 723 | + public function set_is_analytics_enable( $value ) { |
|
| 724 | + |
|
| 725 | + $this->set( 'wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no' ); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + /** |
|
| 729 | + * Get the 'analytics-entity-uri-dimention' option. |
|
| 730 | + * |
|
| 731 | + * @return int |
|
| 732 | + * @since 3.21.0 |
|
| 733 | + */ |
|
| 734 | + public function get_analytics_entity_uri_dimension() { |
|
| 735 | + return (int) $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1 ); |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + /** |
|
| 739 | + * Get the 'analytics-entity-type-dimension' option. |
|
| 740 | + * |
|
| 741 | + * @return int |
|
| 742 | + * @since 3.21.0 |
|
| 743 | + */ |
|
| 744 | + public function get_analytics_entity_type_dimension() { |
|
| 745 | + return $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2 ); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + /** |
|
| 749 | + * Get the URL to perform autocomplete request. |
|
| 750 | + * |
|
| 751 | + * @return string The URL to call to perform the autocomplete request. |
|
| 752 | + * @since 3.15.0 |
|
| 753 | + */ |
|
| 754 | + public function get_autocomplete_url() { |
|
| 755 | + |
|
| 756 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'autocomplete'; |
|
| 757 | + |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + /** |
|
| 761 | + * Get the URL to perform feedback deactivation request. |
|
| 762 | + * |
|
| 763 | + * @return string The URL to call to perform the feedback deactivation request. |
|
| 764 | + * @since 3.19.0 |
|
| 765 | + */ |
|
| 766 | + public function get_deactivation_feedback_url() { |
|
| 767 | + |
|
| 768 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'feedbacks'; |
|
| 769 | + |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + /** |
|
| 773 | + * Get the base API URL. |
|
| 774 | + * |
|
| 775 | + * @return string The base API URL. |
|
| 776 | + * @since 3.20.0 |
|
| 777 | + */ |
|
| 778 | + public function get_api_url() { |
|
| 779 | + |
|
| 780 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE; |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + public function get_network_dataset_ids() { |
|
| 784 | + return $this->get( 'wl_advanced_settings', self::NETWORK_DATASET_IDS, array() ); |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + public function set_network_dataset_ids( $network_dataset_ids ) { |
|
| 788 | + $this->set( 'wl_advanced_settings', self::NETWORK_DATASET_IDS, $network_dataset_ids ); |
|
| 789 | + } |
|
| 790 | 790 | |
| 791 | 791 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | use Wordlift\Api\Default_Api_Service; |
| 14 | 14 | |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 15 | +if ( ! defined('ABSPATH')) { |
|
| 16 | 16 | exit; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | protected function __construct() { |
| 145 | 145 | |
| 146 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 146 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
| 147 | 147 | |
| 148 | 148 | // Sync some configuration properties when key is validated. |
| 149 | - add_action( 'wl_key_validation_response', array( $this, 'sync' ) ); |
|
| 149 | + add_action('wl_key_validation_response', array($this, 'sync')); |
|
| 150 | 150 | |
| 151 | 151 | } |
| 152 | 152 | |
@@ -155,15 +155,15 @@ discard block |
||
| 155 | 155 | * |
| 156 | 156 | * @return void |
| 157 | 157 | */ |
| 158 | - public function sync( $response ) { |
|
| 159 | - if ( ! $response->is_success() ) { |
|
| 158 | + public function sync($response) { |
|
| 159 | + if ( ! $response->is_success()) { |
|
| 160 | 160 | return; |
| 161 | 161 | } |
| 162 | - $data = json_decode( $response->get_body(), true ); |
|
| 163 | - if ( ! is_array( $data ) || ! array_key_exists( 'networkDatasetId', $data ) ) { |
|
| 162 | + $data = json_decode($response->get_body(), true); |
|
| 163 | + if ( ! is_array($data) || ! array_key_exists('networkDatasetId', $data)) { |
|
| 164 | 164 | return; |
| 165 | 165 | } |
| 166 | - $this->set_network_dataset_ids( $data['networkDatasetId'] ); |
|
| 166 | + $this->set_network_dataset_ids($data['networkDatasetId']); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | public static function get_instance() { |
| 186 | 186 | |
| 187 | - if ( ! isset( self::$instance ) ) { |
|
| 187 | + if ( ! isset(self::$instance)) { |
|
| 188 | 188 | self::$instance = new self(); |
| 189 | 189 | } |
| 190 | 190 | |
@@ -202,11 +202,11 @@ discard block |
||
| 202 | 202 | * @return mixed The configuration value or the default value if not found. |
| 203 | 203 | * @since 3.6.0 |
| 204 | 204 | */ |
| 205 | - private function get( $option, $key, $default = '' ) { |
|
| 205 | + private function get($option, $key, $default = '') { |
|
| 206 | 206 | |
| 207 | - $options = get_option( $option, array() ); |
|
| 207 | + $options = get_option($option, array()); |
|
| 208 | 208 | |
| 209 | - return isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
| 209 | + return isset($options[$key]) ? $options[$key] : $default; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
@@ -218,12 +218,12 @@ discard block |
||
| 218 | 218 | * |
| 219 | 219 | * @since 3.9.0 |
| 220 | 220 | */ |
| 221 | - private function set( $option, $key, $value ) { |
|
| 221 | + private function set($option, $key, $value) { |
|
| 222 | 222 | |
| 223 | - $values = get_option( $option ); |
|
| 224 | - $values = isset( $values ) ? $values : array(); |
|
| 225 | - $values[ $key ] = $value; |
|
| 226 | - update_option( $option, $values ); |
|
| 223 | + $values = get_option($option); |
|
| 224 | + $values = isset($values) ? $values : array(); |
|
| 225 | + $values[$key] = $value; |
|
| 226 | + update_option($option, $values); |
|
| 227 | 227 | |
| 228 | 228 | } |
| 229 | 229 | |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | */ |
| 236 | 236 | public function get_entity_base_path() { |
| 237 | 237 | |
| 238 | - return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' ); |
|
| 238 | + return $this->get('wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity'); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -245,9 +245,9 @@ discard block |
||
| 245 | 245 | * |
| 246 | 246 | * @since 3.9.0 |
| 247 | 247 | */ |
| 248 | - public function set_entity_base_path( $value ) { |
|
| 248 | + public function set_entity_base_path($value) { |
|
| 249 | 249 | |
| 250 | - $this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value ); |
|
| 250 | + $this->set('wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value); |
|
| 251 | 251 | |
| 252 | 252 | } |
| 253 | 253 | |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | public function is_skip_wizard() { |
| 261 | 261 | |
| 262 | - return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false ); |
|
| 262 | + return $this->get('wl_general_settings', self::SKIP_WIZARD, false); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
@@ -269,9 +269,9 @@ discard block |
||
| 269 | 269 | * |
| 270 | 270 | * @since 3.9.0 |
| 271 | 271 | */ |
| 272 | - public function set_skip_wizard( $value ) { |
|
| 272 | + public function set_skip_wizard($value) { |
|
| 273 | 273 | |
| 274 | - $this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value ); |
|
| 274 | + $this->set('wl_general_settings', self::SKIP_WIZARD, true === $value); |
|
| 275 | 275 | |
| 276 | 276 | } |
| 277 | 277 | |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | */ |
| 284 | 284 | public function get_key() { |
| 285 | 285 | |
| 286 | - return $this->get( 'wl_general_settings', self::KEY, '' ); |
|
| 286 | + return $this->get('wl_general_settings', self::KEY, ''); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /** |
@@ -293,9 +293,9 @@ discard block |
||
| 293 | 293 | * |
| 294 | 294 | * @since 3.9.0 |
| 295 | 295 | */ |
| 296 | - public function set_key( $value ) { |
|
| 296 | + public function set_key($value) { |
|
| 297 | 297 | |
| 298 | - $this->set( 'wl_general_settings', self::KEY, $value ); |
|
| 298 | + $this->set('wl_general_settings', self::KEY, $value); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -309,11 +309,11 @@ discard block |
||
| 309 | 309 | public function get_language_code() { |
| 310 | 310 | |
| 311 | 311 | $language = get_locale(); |
| 312 | - if ( ! $language ) { |
|
| 312 | + if ( ! $language) { |
|
| 313 | 313 | return 'en'; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - return substr( $language, 0, 2 ); |
|
| 316 | + return substr($language, 0, 2); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
@@ -328,9 +328,9 @@ discard block |
||
| 328 | 328 | * |
| 329 | 329 | * @since 3.9.0 |
| 330 | 330 | */ |
| 331 | - public function set_language_code( $value ) { |
|
| 331 | + public function set_language_code($value) { |
|
| 332 | 332 | |
| 333 | - $this->set( 'wl_general_settings', self::LANGUAGE, $value ); |
|
| 333 | + $this->set('wl_general_settings', self::LANGUAGE, $value); |
|
| 334 | 334 | |
| 335 | 335 | } |
| 336 | 336 | |
@@ -341,9 +341,9 @@ discard block |
||
| 341 | 341 | * |
| 342 | 342 | * @since 3.19.0 |
| 343 | 343 | */ |
| 344 | - public function set_diagnostic_preferences( $value ) { |
|
| 344 | + public function set_diagnostic_preferences($value) { |
|
| 345 | 345 | |
| 346 | - $this->set( 'wl_general_settings', self::SEND_DIAGNOSTIC, $value ); |
|
| 346 | + $this->set('wl_general_settings', self::SEND_DIAGNOSTIC, $value); |
|
| 347 | 347 | |
| 348 | 348 | } |
| 349 | 349 | |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | */ |
| 355 | 355 | public function get_diagnostic_preferences() { |
| 356 | 356 | |
| 357 | - return $this->get( 'wl_general_settings', self::SEND_DIAGNOSTIC, 'no' ); |
|
| 357 | + return $this->get('wl_general_settings', self::SEND_DIAGNOSTIC, 'no'); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | */ |
| 366 | 366 | public function get_country_code() { |
| 367 | 367 | |
| 368 | - return $this->get( 'wl_general_settings', self::COUNTRY_CODE, 'us' ); |
|
| 368 | + return $this->get('wl_general_settings', self::COUNTRY_CODE, 'us'); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | /** |
@@ -375,9 +375,9 @@ discard block |
||
| 375 | 375 | * |
| 376 | 376 | * @since 3.18.0 |
| 377 | 377 | */ |
| 378 | - public function set_country_code( $value ) { |
|
| 378 | + public function set_country_code($value) { |
|
| 379 | 379 | |
| 380 | - $this->set( 'wl_general_settings', self::COUNTRY_CODE, $value ); |
|
| 380 | + $this->set('wl_general_settings', self::COUNTRY_CODE, $value); |
|
| 381 | 381 | |
| 382 | 382 | } |
| 383 | 383 | |
@@ -390,8 +390,8 @@ discard block |
||
| 390 | 390 | * @since 3.38.6 |
| 391 | 391 | */ |
| 392 | 392 | public function get_alternate_name() { |
| 393 | - $alternate_name = $this->get( 'wl_general_settings', self::ALTERNATE_NAME, get_bloginfo( 'description' ) ); |
|
| 394 | - return wp_strip_all_tags( $alternate_name, true ); |
|
| 393 | + $alternate_name = $this->get('wl_general_settings', self::ALTERNATE_NAME, get_bloginfo('description')); |
|
| 394 | + return wp_strip_all_tags($alternate_name, true); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | /** |
@@ -401,9 +401,9 @@ discard block |
||
| 401 | 401 | * |
| 402 | 402 | * @since 3.38.6 |
| 403 | 403 | */ |
| 404 | - public function set_alternate_name( $value ) { |
|
| 404 | + public function set_alternate_name($value) { |
|
| 405 | 405 | |
| 406 | - $this->set( 'wl_general_settings', self::ALTERNATE_NAME, $value ); |
|
| 406 | + $this->set('wl_general_settings', self::ALTERNATE_NAME, $value); |
|
| 407 | 407 | |
| 408 | 408 | } |
| 409 | 409 | |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | */ |
| 419 | 419 | public function get_publisher_id() { |
| 420 | 420 | |
| 421 | - return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null ); |
|
| 421 | + return $this->get('wl_general_settings', self::PUBLISHER_ID, null); |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | /** |
@@ -428,9 +428,9 @@ discard block |
||
| 428 | 428 | * |
| 429 | 429 | * @since 3.9.0 |
| 430 | 430 | */ |
| 431 | - public function set_publisher_id( $value ) { |
|
| 431 | + public function set_publisher_id($value) { |
|
| 432 | 432 | |
| 433 | - $this->set( 'wl_general_settings', self::PUBLISHER_ID, $value ); |
|
| 433 | + $this->set('wl_general_settings', self::PUBLISHER_ID, $value); |
|
| 434 | 434 | |
| 435 | 435 | } |
| 436 | 436 | |
@@ -443,8 +443,8 @@ discard block |
||
| 443 | 443 | */ |
| 444 | 444 | public function get_dataset_uri() { |
| 445 | 445 | |
| 446 | - if ( apply_filters( 'wl_feature__enable__dataset', true ) ) { |
|
| 447 | - return $this->get( 'wl_advanced_settings', self::DATASET_URI, null ); |
|
| 446 | + if (apply_filters('wl_feature__enable__dataset', true)) { |
|
| 447 | + return $this->get('wl_advanced_settings', self::DATASET_URI, null); |
|
| 448 | 448 | } else { |
| 449 | 449 | return null; |
| 450 | 450 | } |
@@ -457,9 +457,9 @@ discard block |
||
| 457 | 457 | * |
| 458 | 458 | * @since 3.10.0 |
| 459 | 459 | */ |
| 460 | - public function set_dataset_uri( $value ) { |
|
| 460 | + public function set_dataset_uri($value) { |
|
| 461 | 461 | |
| 462 | - $this->set( 'wl_advanced_settings', self::DATASET_URI, $value ); |
|
| 462 | + $this->set('wl_advanced_settings', self::DATASET_URI, $value); |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | /** |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | */ |
| 471 | 471 | public function get_package_type() { |
| 472 | 472 | |
| 473 | - return $this->get( 'wl_advanced_settings', self::PACKAGE_TYPE, null ); |
|
| 473 | + return $this->get('wl_advanced_settings', self::PACKAGE_TYPE, null); |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | /** |
@@ -480,8 +480,8 @@ discard block |
||
| 480 | 480 | * |
| 481 | 481 | * @since 3.20.0 |
| 482 | 482 | */ |
| 483 | - public function set_package_type( $value ) { |
|
| 484 | - $this->set( 'wl_advanced_settings', self::PACKAGE_TYPE, $value ); |
|
| 483 | + public function set_package_type($value) { |
|
| 484 | + $this->set('wl_advanced_settings', self::PACKAGE_TYPE, $value); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
@@ -496,11 +496,11 @@ discard block |
||
| 496 | 496 | * @param array $old_value The old settings. |
| 497 | 497 | * @param array $new_value The new settings. |
| 498 | 498 | */ |
| 499 | - public function update_key( $old_value, $new_value ) { |
|
| 499 | + public function update_key($old_value, $new_value) { |
|
| 500 | 500 | |
| 501 | 501 | // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed. |
| 502 | 502 | // $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
| 503 | - $new_key = isset( $new_value['key'] ) ? $new_value['key'] : ''; |
|
| 503 | + $new_key = isset($new_value['key']) ? $new_value['key'] : ''; |
|
| 504 | 504 | |
| 505 | 505 | // If the key hasn't changed, don't do anything. |
| 506 | 506 | // WARN The 'update_option' hook is fired only if the new and old value are not equal. |
@@ -509,14 +509,14 @@ discard block |
||
| 509 | 509 | // } |
| 510 | 510 | |
| 511 | 511 | // If the key is empty, empty the dataset URI. |
| 512 | - if ( '' === $new_key ) { |
|
| 513 | - $this->set_dataset_uri( '' ); |
|
| 512 | + if ('' === $new_key) { |
|
| 513 | + $this->set_dataset_uri(''); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | // make the request to the remote server. |
| 517 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 517 | + $this->get_remote_dataset_uri($new_key); |
|
| 518 | 518 | |
| 519 | - do_action( 'wl_key_updated' ); |
|
| 519 | + do_action('wl_key_updated'); |
|
| 520 | 520 | |
| 521 | 521 | } |
| 522 | 522 | |
@@ -532,15 +532,15 @@ discard block |
||
| 532 | 532 | * |
| 533 | 533 | * @since 3.17.0 send the site URL and get the dataset URI. |
| 534 | 534 | */ |
| 535 | - public function get_remote_dataset_uri( $key ) { |
|
| 535 | + public function get_remote_dataset_uri($key) { |
|
| 536 | 536 | |
| 537 | - $this->log->trace( 'Getting the remote dataset URI and package type...' ); |
|
| 537 | + $this->log->trace('Getting the remote dataset URI and package type...'); |
|
| 538 | 538 | |
| 539 | - if ( empty( $key ) ) { |
|
| 540 | - $this->log->warn( 'Key set to empty value.' ); |
|
| 539 | + if (empty($key)) { |
|
| 540 | + $this->log->warn('Key set to empty value.'); |
|
| 541 | 541 | |
| 542 | - $this->set_dataset_uri( '' ); |
|
| 543 | - $this->set_package_type( null ); |
|
| 542 | + $this->set_dataset_uri(''); |
|
| 543 | + $this->set_package_type(null); |
|
| 544 | 544 | |
| 545 | 545 | return; |
| 546 | 546 | } |
@@ -554,15 +554,15 @@ discard block |
||
| 554 | 554 | * |
| 555 | 555 | * @since 3.20.0 |
| 556 | 556 | */ |
| 557 | - $home_url = get_option( 'home' ); |
|
| 558 | - $site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) ); |
|
| 557 | + $home_url = get_option('home'); |
|
| 558 | + $site_url = apply_filters('wl_production_site_url', untrailingslashit($home_url)); |
|
| 559 | 559 | |
| 560 | 560 | // Build the URL. |
| 561 | 561 | $url = '/accounts' |
| 562 | - . '?key=' . rawurlencode( $key ) |
|
| 563 | - . '&url=' . rawurlencode( $site_url ) |
|
| 564 | - . '&country=' . $this->get_country_code() |
|
| 565 | - . '&language=' . $this->get_language_code(); |
|
| 562 | + . '?key='.rawurlencode($key) |
|
| 563 | + . '&url='.rawurlencode($site_url) |
|
| 564 | + . '&country='.$this->get_country_code() |
|
| 565 | + . '&language='.$this->get_language_code(); |
|
| 566 | 566 | |
| 567 | 567 | $api_service = Default_Api_Service::get_instance(); |
| 568 | 568 | /** |
@@ -572,32 +572,32 @@ discard block |
||
| 572 | 572 | $headers = array( |
| 573 | 573 | 'Authorization' => "Key $key", |
| 574 | 574 | ); |
| 575 | - $response = $api_service->request( 'PUT', $url, $headers )->get_response(); |
|
| 575 | + $response = $api_service->request('PUT', $url, $headers)->get_response(); |
|
| 576 | 576 | |
| 577 | 577 | // The response is an error. |
| 578 | - if ( is_wp_error( $response ) ) { |
|
| 579 | - $this->log->error( 'An error occurred setting the dataset URI: ' . $response->get_error_message() ); |
|
| 578 | + if (is_wp_error($response)) { |
|
| 579 | + $this->log->error('An error occurred setting the dataset URI: '.$response->get_error_message()); |
|
| 580 | 580 | |
| 581 | - $this->set_dataset_uri( '' ); |
|
| 582 | - $this->set_package_type( null ); |
|
| 581 | + $this->set_dataset_uri(''); |
|
| 582 | + $this->set_package_type(null); |
|
| 583 | 583 | |
| 584 | 584 | return; |
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | // The response is not OK. |
| 588 | - if ( ! is_array( $response ) || 200 !== (int) $response['response']['code'] ) { |
|
| 588 | + if ( ! is_array($response) || 200 !== (int) $response['response']['code']) { |
|
| 589 | 589 | $base_url = $api_service->get_base_url(); |
| 590 | 590 | |
| 591 | - if ( ! is_array( $response ) ) { |
|
| 591 | + if ( ! is_array($response)) { |
|
| 592 | 592 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export |
| 593 | - $this->log->error( "Unexpected response when opening URL $base_url$url: " . var_export( $response, true ) ); |
|
| 593 | + $this->log->error("Unexpected response when opening URL $base_url$url: ".var_export($response, true)); |
|
| 594 | 594 | } else { |
| 595 | 595 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export |
| 596 | - $this->log->error( "Unexpected status code when opening URL $base_url$url: " . $response['response']['code'] . "\n" . var_export( $response, true ) ); |
|
| 596 | + $this->log->error("Unexpected status code when opening URL $base_url$url: ".$response['response']['code']."\n".var_export($response, true)); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | - $this->set_dataset_uri( '' ); |
|
| 600 | - $this->set_package_type( null ); |
|
| 599 | + $this->set_dataset_uri(''); |
|
| 600 | + $this->set_package_type(null); |
|
| 601 | 601 | |
| 602 | 602 | return; |
| 603 | 603 | } |
@@ -607,20 +607,20 @@ discard block |
||
| 607 | 607 | * |
| 608 | 608 | * @since 3.20.0 |
| 609 | 609 | */ |
| 610 | - $json = json_decode( $response['body'] ); |
|
| 610 | + $json = json_decode($response['body']); |
|
| 611 | 611 | /** |
| 612 | 612 | * @since 3.27.7 |
| 613 | 613 | * Remove the trailing slash returned from the new platform api. |
| 614 | 614 | */ |
| 615 | 615 | // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
| 616 | - $dataset_uri = untrailingslashit( $json->datasetURI ); |
|
| 616 | + $dataset_uri = untrailingslashit($json->datasetURI); |
|
| 617 | 617 | // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
| 618 | - $package_type = isset( $json->packageType ) ? $json->packageType : null; |
|
| 618 | + $package_type = isset($json->packageType) ? $json->packageType : null; |
|
| 619 | 619 | |
| 620 | - $this->log->info( "Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..." ); |
|
| 620 | + $this->log->info("Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..."); |
|
| 621 | 621 | |
| 622 | - $this->set_dataset_uri( $dataset_uri ); |
|
| 623 | - $this->set_package_type( $package_type ); |
|
| 622 | + $this->set_dataset_uri($dataset_uri); |
|
| 623 | + $this->set_package_type($package_type); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | /** |
@@ -637,20 +637,20 @@ discard block |
||
| 637 | 637 | * @return mixed The same value in the $value parameter |
| 638 | 638 | * @since 3.12.0 |
| 639 | 639 | */ |
| 640 | - public function maybe_update_dataset_uri( $value, $old_value ) { |
|
| 640 | + public function maybe_update_dataset_uri($value, $old_value) { |
|
| 641 | 641 | |
| 642 | 642 | // Check the old key value and the new one. Here we're only handling the |
| 643 | 643 | // case where the key hasn't changed and the dataset URI isn't set. The |
| 644 | 644 | // other case, i.e. a new key is inserted, is handled at `update_key`. |
| 645 | - $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 646 | - $new_key = isset( $value['key'] ) ? $value['key'] : ''; |
|
| 645 | + $old_key = isset($old_value['key']) ? $old_value['key'] : ''; |
|
| 646 | + $new_key = isset($value['key']) ? $value['key'] : ''; |
|
| 647 | 647 | |
| 648 | 648 | $dataset_uri = $this->get_dataset_uri(); |
| 649 | 649 | |
| 650 | - if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) { |
|
| 650 | + if ( ! empty($new_key) && $new_key === $old_key && empty($dataset_uri)) { |
|
| 651 | 651 | |
| 652 | 652 | // make the request to the remote server to try to get the dataset uri. |
| 653 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 653 | + $this->get_remote_dataset_uri($new_key); |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | return $value; |
@@ -664,9 +664,9 @@ discard block |
||
| 664 | 664 | * @return string The API URI. |
| 665 | 665 | * @since 3.11.0 |
| 666 | 666 | */ |
| 667 | - public function get_accounts_by_key_dataset_uri( $key ) { |
|
| 667 | + public function get_accounts_by_key_dataset_uri($key) { |
|
| 668 | 668 | |
| 669 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
|
| 669 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."accounts/key=$key/dataset_uri"; |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | /** |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | */ |
| 678 | 678 | public function get_accounts() { |
| 679 | 679 | |
| 680 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'accounts'; |
|
| 680 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE.'accounts'; |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | /** |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | */ |
| 689 | 689 | public function is_link_by_default() { |
| 690 | 690 | |
| 691 | - return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' ); |
|
| 691 | + return 'yes' === $this->get('wl_general_settings', self::LINK_BY_DEFAULT, 'yes'); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | /** |
@@ -698,9 +698,9 @@ discard block |
||
| 698 | 698 | * |
| 699 | 699 | * @since 3.13.0 |
| 700 | 700 | */ |
| 701 | - public function set_link_by_default( $value ) { |
|
| 701 | + public function set_link_by_default($value) { |
|
| 702 | 702 | |
| 703 | - $this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' ); |
|
| 703 | + $this->set('wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no'); |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | /** |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | * @since 3.21.0 |
| 711 | 711 | */ |
| 712 | 712 | public function is_analytics_enable() { |
| 713 | - return 'yes' === $this->get( 'wl_analytics_settings', self::ANALYTICS_ENABLE, 'no' ); |
|
| 713 | + return 'yes' === $this->get('wl_analytics_settings', self::ANALYTICS_ENABLE, 'no'); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | /** |
@@ -720,9 +720,9 @@ discard block |
||
| 720 | 720 | * |
| 721 | 721 | * @since 3.21.0 |
| 722 | 722 | */ |
| 723 | - public function set_is_analytics_enable( $value ) { |
|
| 723 | + public function set_is_analytics_enable($value) { |
|
| 724 | 724 | |
| 725 | - $this->set( 'wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no' ); |
|
| 725 | + $this->set('wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no'); |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | /** |
@@ -732,7 +732,7 @@ discard block |
||
| 732 | 732 | * @since 3.21.0 |
| 733 | 733 | */ |
| 734 | 734 | public function get_analytics_entity_uri_dimension() { |
| 735 | - return (int) $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1 ); |
|
| 735 | + return (int) $this->get('wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1); |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | /** |
@@ -742,7 +742,7 @@ discard block |
||
| 742 | 742 | * @since 3.21.0 |
| 743 | 743 | */ |
| 744 | 744 | public function get_analytics_entity_type_dimension() { |
| 745 | - return $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2 ); |
|
| 745 | + return $this->get('wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2); |
|
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | /** |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | */ |
| 754 | 754 | public function get_autocomplete_url() { |
| 755 | 755 | |
| 756 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'autocomplete'; |
|
| 756 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE.'autocomplete'; |
|
| 757 | 757 | |
| 758 | 758 | } |
| 759 | 759 | |
@@ -765,7 +765,7 @@ discard block |
||
| 765 | 765 | */ |
| 766 | 766 | public function get_deactivation_feedback_url() { |
| 767 | 767 | |
| 768 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'feedbacks'; |
|
| 768 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE.'feedbacks'; |
|
| 769 | 769 | |
| 770 | 770 | } |
| 771 | 771 | |
@@ -781,11 +781,11 @@ discard block |
||
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | public function get_network_dataset_ids() { |
| 784 | - return $this->get( 'wl_advanced_settings', self::NETWORK_DATASET_IDS, array() ); |
|
| 784 | + return $this->get('wl_advanced_settings', self::NETWORK_DATASET_IDS, array()); |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | - public function set_network_dataset_ids( $network_dataset_ids ) { |
|
| 788 | - $this->set( 'wl_advanced_settings', self::NETWORK_DATASET_IDS, $network_dataset_ids ); |
|
| 787 | + public function set_network_dataset_ids($network_dataset_ids) { |
|
| 788 | + $this->set('wl_advanced_settings', self::NETWORK_DATASET_IDS, $network_dataset_ids); |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | } |
@@ -15,67 +15,67 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Wordlift_Website_Jsonld_Converter extends Wordlift_Post_To_Jsonld_Converter { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Convert the home/blog page to a JSON-LD array. |
|
| 20 | - * |
|
| 21 | - * @return array A JSON-LD array. |
|
| 22 | - * @since 3.14.0 |
|
| 23 | - */ |
|
| 24 | - public function create_schema() { |
|
| 18 | + /** |
|
| 19 | + * Convert the home/blog page to a JSON-LD array. |
|
| 20 | + * |
|
| 21 | + * @return array A JSON-LD array. |
|
| 22 | + * @since 3.14.0 |
|
| 23 | + */ |
|
| 24 | + public function create_schema() { |
|
| 25 | 25 | |
| 26 | - // Create new jsonld. |
|
| 27 | - $home_url = home_url( '/' ); |
|
| 26 | + // Create new jsonld. |
|
| 27 | + $home_url = home_url( '/' ); |
|
| 28 | 28 | |
| 29 | - $jsonld = array( |
|
| 30 | - '@context' => 'http://schema.org', |
|
| 31 | - '@type' => 'WebSite', |
|
| 32 | - '@id' => "$home_url#website", |
|
| 33 | - 'name' => html_entity_decode( get_bloginfo( 'name' ), ENT_QUOTES ), |
|
| 34 | - 'alternateName' => Wordlift_Configuration_Service::get_instance()->get_alternate_name(), |
|
| 35 | - 'url' => $home_url, |
|
| 36 | - ); |
|
| 29 | + $jsonld = array( |
|
| 30 | + '@context' => 'http://schema.org', |
|
| 31 | + '@type' => 'WebSite', |
|
| 32 | + '@id' => "$home_url#website", |
|
| 33 | + 'name' => html_entity_decode( get_bloginfo( 'name' ), ENT_QUOTES ), |
|
| 34 | + 'alternateName' => Wordlift_Configuration_Service::get_instance()->get_alternate_name(), |
|
| 35 | + 'url' => $home_url, |
|
| 36 | + ); |
|
| 37 | 37 | |
| 38 | - // Add publisher information. |
|
| 39 | - $this->set_publisher( $jsonld ); |
|
| 38 | + // Add publisher information. |
|
| 39 | + $this->set_publisher( $jsonld ); |
|
| 40 | 40 | |
| 41 | - // Add search action. |
|
| 42 | - $this->set_search_action( $jsonld ); |
|
| 41 | + // Add search action. |
|
| 42 | + $this->set_search_action( $jsonld ); |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Call the `wl_website_jsonld` filter. |
|
| 46 | - * |
|
| 47 | - * @param array $jsonld The JSON-LD structure. |
|
| 48 | - * |
|
| 49 | - * @since 3.14.0 |
|
| 50 | - * |
|
| 51 | - * @api |
|
| 52 | - */ |
|
| 53 | - return apply_filters( 'wl_website_jsonld', $jsonld ); |
|
| 54 | - } |
|
| 44 | + /** |
|
| 45 | + * Call the `wl_website_jsonld` filter. |
|
| 46 | + * |
|
| 47 | + * @param array $jsonld The JSON-LD structure. |
|
| 48 | + * |
|
| 49 | + * @since 3.14.0 |
|
| 50 | + * |
|
| 51 | + * @api |
|
| 52 | + */ |
|
| 53 | + return apply_filters( 'wl_website_jsonld', $jsonld ); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Add SearchAction part to the schema |
|
| 58 | - * |
|
| 59 | - * @param array $params The parameters array. |
|
| 60 | - * |
|
| 61 | - * @since 3.14.0 |
|
| 62 | - */ |
|
| 63 | - private function set_search_action( &$params ) { |
|
| 64 | - /** |
|
| 65 | - * Filter: 'wl_jsonld_search_url' - Allows filtering of the search URL. |
|
| 66 | - * |
|
| 67 | - * @since 3.14.0 |
|
| 68 | - * @api string $search_url The search URL for this site with a `{search_term_string}` variable. |
|
| 69 | - */ |
|
| 70 | - $search_url = apply_filters( 'wl_jsonld_search_url', home_url( '/' ) . '?s={search_term_string}' ); |
|
| 56 | + /** |
|
| 57 | + * Add SearchAction part to the schema |
|
| 58 | + * |
|
| 59 | + * @param array $params The parameters array. |
|
| 60 | + * |
|
| 61 | + * @since 3.14.0 |
|
| 62 | + */ |
|
| 63 | + private function set_search_action( &$params ) { |
|
| 64 | + /** |
|
| 65 | + * Filter: 'wl_jsonld_search_url' - Allows filtering of the search URL. |
|
| 66 | + * |
|
| 67 | + * @since 3.14.0 |
|
| 68 | + * @api string $search_url The search URL for this site with a `{search_term_string}` variable. |
|
| 69 | + */ |
|
| 70 | + $search_url = apply_filters( 'wl_jsonld_search_url', home_url( '/' ) . '?s={search_term_string}' ); |
|
| 71 | 71 | |
| 72 | - // Add search action |
|
| 73 | - $params['potentialAction'] = array( |
|
| 74 | - '@type' => 'SearchAction', |
|
| 75 | - 'target' => $search_url, |
|
| 76 | - 'query-input' => 'required name=search_term_string', |
|
| 77 | - ); |
|
| 72 | + // Add search action |
|
| 73 | + $params['potentialAction'] = array( |
|
| 74 | + '@type' => 'SearchAction', |
|
| 75 | + 'target' => $search_url, |
|
| 76 | + 'query-input' => 'required name=search_term_string', |
|
| 77 | + ); |
|
| 78 | 78 | |
| 79 | - } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | } |
@@ -24,22 +24,22 @@ discard block |
||
| 24 | 24 | public function create_schema() { |
| 25 | 25 | |
| 26 | 26 | // Create new jsonld. |
| 27 | - $home_url = home_url( '/' ); |
|
| 27 | + $home_url = home_url('/'); |
|
| 28 | 28 | |
| 29 | 29 | $jsonld = array( |
| 30 | 30 | '@context' => 'http://schema.org', |
| 31 | 31 | '@type' => 'WebSite', |
| 32 | 32 | '@id' => "$home_url#website", |
| 33 | - 'name' => html_entity_decode( get_bloginfo( 'name' ), ENT_QUOTES ), |
|
| 33 | + 'name' => html_entity_decode(get_bloginfo('name'), ENT_QUOTES), |
|
| 34 | 34 | 'alternateName' => Wordlift_Configuration_Service::get_instance()->get_alternate_name(), |
| 35 | 35 | 'url' => $home_url, |
| 36 | 36 | ); |
| 37 | 37 | |
| 38 | 38 | // Add publisher information. |
| 39 | - $this->set_publisher( $jsonld ); |
|
| 39 | + $this->set_publisher($jsonld); |
|
| 40 | 40 | |
| 41 | 41 | // Add search action. |
| 42 | - $this->set_search_action( $jsonld ); |
|
| 42 | + $this->set_search_action($jsonld); |
|
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * Call the `wl_website_jsonld` filter. |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @api |
| 52 | 52 | */ |
| 53 | - return apply_filters( 'wl_website_jsonld', $jsonld ); |
|
| 53 | + return apply_filters('wl_website_jsonld', $jsonld); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -60,14 +60,14 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | * @since 3.14.0 |
| 62 | 62 | */ |
| 63 | - private function set_search_action( &$params ) { |
|
| 63 | + private function set_search_action(&$params) { |
|
| 64 | 64 | /** |
| 65 | 65 | * Filter: 'wl_jsonld_search_url' - Allows filtering of the search URL. |
| 66 | 66 | * |
| 67 | 67 | * @since 3.14.0 |
| 68 | 68 | * @api string $search_url The search URL for this site with a `{search_term_string}` variable. |
| 69 | 69 | */ |
| 70 | - $search_url = apply_filters( 'wl_jsonld_search_url', home_url( '/' ) . '?s={search_term_string}' ); |
|
| 70 | + $search_url = apply_filters('wl_jsonld_search_url', home_url('/').'?s={search_term_string}'); |
|
| 71 | 71 | |
| 72 | 72 | // Add search action |
| 73 | 73 | $params['potentialAction'] = array( |