@@ -18,442 +18,442 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Settings_Page extends Wordlift_Admin_Page { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * A singleton instance of the Notice service. |
|
| 23 | - * |
|
| 24 | - * @since 3.2.0 |
|
| 25 | - * @access private |
|
| 26 | - * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service. |
|
| 27 | - */ |
|
| 28 | - private static $instance; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * A {@link Wordlift_Entity_Service} instance. |
|
| 32 | - * |
|
| 33 | - * @since 3.11.0 |
|
| 34 | - * @access private |
|
| 35 | - * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 36 | - */ |
|
| 37 | - private $entity_service; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * A {@link Wordlift_Configuration_Service} instance. |
|
| 41 | - * |
|
| 42 | - * @since 3.11.0 |
|
| 43 | - * @access private |
|
| 44 | - * @var \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 45 | - */ |
|
| 46 | - private $configuration_service; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * A {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 50 | - * |
|
| 51 | - * @since 3.11.0 |
|
| 52 | - * @access private |
|
| 53 | - * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 54 | - */ |
|
| 55 | - private $input_element; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 59 | - * |
|
| 60 | - * @since 3.13.0 |
|
| 61 | - * @access protected |
|
| 62 | - * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 63 | - */ |
|
| 64 | - private $radio_input_element; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 68 | - * |
|
| 69 | - * @since 3.11.0 |
|
| 70 | - * @access private |
|
| 71 | - * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 72 | - */ |
|
| 73 | - private $language_select_element; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 77 | - * |
|
| 78 | - * @since 3.18.0 |
|
| 79 | - * @access private |
|
| 80 | - * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 81 | - */ |
|
| 82 | - private $country_select_element; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 86 | - * |
|
| 87 | - * @since 3.11.0 |
|
| 88 | - * @access private |
|
| 89 | - * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 90 | - */ |
|
| 91 | - private $publisher_element; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Create a {@link Wordlift_Admin_Settings_Page} instance. |
|
| 95 | - * |
|
| 96 | - * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 97 | - * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 98 | - * @param \Wordlift_Admin_Input_Element $input_element A {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 99 | - * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 100 | - * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 101 | - * @param \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 102 | - * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 103 | - * |
|
| 104 | - * @since 3.11.0 |
|
| 105 | - * |
|
| 106 | - */ |
|
| 107 | - function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element ) { |
|
| 108 | - |
|
| 109 | - $this->configuration_service = $configuration_service; |
|
| 110 | - $this->entity_service = $entity_service; |
|
| 111 | - |
|
| 112 | - // Set a reference to the UI elements. |
|
| 113 | - $this->input_element = $input_element; |
|
| 114 | - $this->radio_input_element = $radio_input_element; |
|
| 115 | - $this->language_select_element = $language_select_element; |
|
| 116 | - $this->country_select_element = $country_select_element; |
|
| 117 | - $this->publisher_element = $publisher_element; |
|
| 118 | - |
|
| 119 | - self::$instance = $this; |
|
| 120 | - |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Get the singleton instance of the Notice service. |
|
| 125 | - * |
|
| 126 | - * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service. |
|
| 127 | - * @since 3.14.0 |
|
| 128 | - */ |
|
| 129 | - public static function get_instance() { |
|
| 130 | - |
|
| 131 | - return self::$instance; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @inheritdoc |
|
| 136 | - */ |
|
| 137 | - function get_parent_slug() { |
|
| 138 | - |
|
| 139 | - return 'wl_admin_menu'; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @inheritdoc |
|
| 144 | - */ |
|
| 145 | - function get_capability() { |
|
| 146 | - |
|
| 147 | - return 'manage_options'; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @inheritdoc |
|
| 152 | - */ |
|
| 153 | - function get_page_title() { |
|
| 154 | - |
|
| 155 | - return 'WordLift Settings'; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @inheritdoc |
|
| 160 | - */ |
|
| 161 | - function get_menu_title() { |
|
| 162 | - |
|
| 163 | - return 'Settings'; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @inheritdoc |
|
| 168 | - */ |
|
| 169 | - function get_menu_slug() { |
|
| 170 | - |
|
| 171 | - return 'wl_configuration_admin_menu'; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @inheritdoc |
|
| 176 | - */ |
|
| 177 | - function get_partial_name() { |
|
| 178 | - |
|
| 179 | - return 'wordlift-admin-settings-page.php'; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * @inheritdoc |
|
| 184 | - */ |
|
| 185 | - public function enqueue_scripts() { |
|
| 186 | - |
|
| 187 | - // Enqueue the media scripts to be used for the publisher's logo selection. |
|
| 188 | - wp_enqueue_media(); |
|
| 189 | - |
|
| 190 | - // JavaScript required for the settings page. |
|
| 191 | - // @todo: try to move to the `wordlift-admin.bundle.js`. |
|
| 192 | - wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.js', array( 'wp-util' ) ); |
|
| 193 | - wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.css' ); |
|
| 194 | - |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Configure all the configuration parameters. |
|
| 199 | - * |
|
| 200 | - * Called by the *admin_init* hook. |
|
| 201 | - * |
|
| 202 | - * @since 3.11.0 |
|
| 203 | - */ |
|
| 204 | - function admin_init() { |
|
| 205 | - // Register WordLift's general settings, providing our own sanitize callback |
|
| 206 | - // which will also check whether the user filled the WL Publisher form. |
|
| 207 | - register_setting( |
|
| 208 | - 'wl_general_settings', |
|
| 209 | - 'wl_general_settings', |
|
| 210 | - array( $this, 'sanitize_callback' ) |
|
| 211 | - ); |
|
| 212 | - |
|
| 213 | - // Add the general settings section. |
|
| 214 | - add_settings_section( |
|
| 215 | - 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
|
| 216 | - '', // Section header. |
|
| 217 | - '', // Callback used to render the description of the section. |
|
| 218 | - 'wl_general_settings' // Page on which to add this section of options. |
|
| 219 | - ); |
|
| 220 | - |
|
| 221 | - $key_args = array( |
|
| 222 | - 'id' => 'wl-key', |
|
| 223 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 224 | - 'value' => $this->configuration_service->get_key(), |
|
| 225 | - 'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ) |
|
| 226 | - . ' [' . get_option( 'home' ) . ']', |
|
| 227 | - ); |
|
| 228 | - |
|
| 229 | - // Before we were used to validate the key beforehand, but this means |
|
| 230 | - // an http call whenever a page is opened in the admin area. Therefore |
|
| 231 | - // we now leave the input `untouched`, leaving to the client to update |
|
| 232 | - // the `css_class`. |
|
| 233 | - // |
|
| 234 | - // See https://github.com/insideout10/wordlift-plugin/issues/669. |
|
| 235 | - $key_args['css_class'] = 'untouched'; |
|
| 236 | - |
|
| 237 | - // Add the `key` field. |
|
| 238 | - add_settings_field( |
|
| 239 | - 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 240 | - __( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 241 | - // The name of the function responsible for rendering the option interface. |
|
| 242 | - array( $this->input_element, 'render' ), |
|
| 243 | - 'wl_general_settings', // The page on which this option will be displayed. |
|
| 244 | - 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 245 | - $key_args // The array of arguments to pass to the callback. In this case, just a description. |
|
| 246 | - ); |
|
| 247 | - |
|
| 248 | - // Entity Base Path input. |
|
| 249 | - $entity_base_path_args = array( |
|
| 250 | - // The array of arguments to pass to the callback. In this case, just a description. |
|
| 251 | - 'id' => 'wl-entity-base-path', |
|
| 252 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 253 | - 'value' => $this->configuration_service->get_entity_base_path(), |
|
| 254 | - /* translators: Placeholders: %s - a link to FAQ's page. */ |
|
| 255 | - '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' ), |
|
| 256 | - ); |
|
| 257 | - |
|
| 258 | - // The following call is very heavy on large web sites and is always run |
|
| 259 | - // also when not needed: |
|
| 260 | - // $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
|
| 261 | - // |
|
| 262 | - // It is now replaced by a filter to add the `readonly` flag to the |
|
| 263 | - // input element when this is actually rendered. |
|
| 264 | - add_filter( 'wl_admin_input_element_params', array( |
|
| 265 | - $this, |
|
| 266 | - 'entity_path_input_element_params', |
|
| 267 | - ) ); |
|
| 268 | - |
|
| 269 | - // Add the `wl_entity_base_path` field. |
|
| 270 | - add_settings_field( |
|
| 271 | - 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 272 | - __( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 273 | - // The name of the function responsible for rendering the option interface |
|
| 274 | - array( $this->input_element, 'render', ), |
|
| 275 | - 'wl_general_settings', // The page on which this option will be displayed |
|
| 276 | - 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 277 | - $entity_base_path_args |
|
| 278 | - ); |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - $language_name = Wordlift_Languages::get_language_name( |
|
| 282 | - $this->configuration_service->get_language_code() |
|
| 283 | - ); |
|
| 284 | - |
|
| 285 | - // Add the `language_name` field. |
|
| 286 | - add_settings_field( |
|
| 287 | - 'wl-site-language', |
|
| 288 | - __( 'Site Language', 'wordlift' ), |
|
| 289 | - array( $this->input_element, 'render' ), |
|
| 290 | - 'wl_general_settings', |
|
| 291 | - 'wl_general_settings_section', |
|
| 292 | - array( |
|
| 293 | - // The array of arguments to pass to the callback. In this case, just a description. |
|
| 294 | - 'id' => 'wl-site-language', |
|
| 295 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']', |
|
| 296 | - 'value' => $language_name, |
|
| 297 | - 'description' => sprintf( __( |
|
| 298 | - 'WordLift uses the site language, You can change the language from <a href="%s">settings</a>.', 'wordlift' ), |
|
| 299 | - admin_url('options-general.php/#WPLANG') |
|
| 300 | - ), |
|
| 301 | - 'readonly' => true |
|
| 302 | - ) |
|
| 303 | - ); |
|
| 304 | - |
|
| 305 | - // Add the `country_code` field. |
|
| 306 | - add_settings_field( |
|
| 307 | - 'wl-country-code', |
|
| 308 | - _x( 'Country', 'wordlift' ), |
|
| 309 | - array( $this->country_select_element, 'render' ), |
|
| 310 | - 'wl_general_settings', |
|
| 311 | - 'wl_general_settings_section', |
|
| 312 | - array( |
|
| 313 | - 'id' => 'wl-country-code', |
|
| 314 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::COUNTRY_CODE . ']', |
|
| 315 | - 'value' => $this->configuration_service->get_country_code(), |
|
| 316 | - 'description' => __( 'Please select a country.', 'wordlift' ), |
|
| 317 | - 'notice' => __( 'The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift' ), |
|
| 318 | - ) |
|
| 319 | - ); |
|
| 320 | - |
|
| 321 | - // Add the `publisher` field. |
|
| 322 | - add_settings_field( |
|
| 323 | - 'wl-publisher-id', |
|
| 324 | - __( 'Publisher', 'wordlift' ), |
|
| 325 | - array( $this->publisher_element, 'render' ), |
|
| 326 | - 'wl_general_settings', |
|
| 327 | - 'wl_general_settings_section', |
|
| 328 | - array( |
|
| 329 | - 'id' => 'wl-publisher-id', |
|
| 330 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 331 | - ) |
|
| 332 | - ); |
|
| 333 | - |
|
| 334 | - // Add the `link by default` field. |
|
| 335 | - add_settings_field( |
|
| 336 | - 'wl-link-by-default', |
|
| 337 | - __( 'Link by Default', 'wordlift' ), |
|
| 338 | - array( $this->radio_input_element, 'render' ), |
|
| 339 | - 'wl_general_settings', |
|
| 340 | - 'wl_general_settings_section', |
|
| 341 | - array( |
|
| 342 | - 'id' => 'wl-link-by-default', |
|
| 343 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 344 | - 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
|
| 345 | - 'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 346 | - ) |
|
| 347 | - ); |
|
| 348 | - |
|
| 349 | - // Add the `diagnostic data` field. |
|
| 350 | - add_settings_field( |
|
| 351 | - 'wl-send-diagnostic', |
|
| 352 | - __( 'Send Diagnostic Data', 'wordlift' ), |
|
| 353 | - array( $this->radio_input_element, 'render' ), |
|
| 354 | - 'wl_general_settings', |
|
| 355 | - 'wl_general_settings_section', |
|
| 356 | - array( |
|
| 357 | - 'id' => 'wl-send-diagnostic', |
|
| 358 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']', |
|
| 359 | - 'value' => 'yes' === $this->configuration_service->get_diagnostic_preferences() ? 'yes' : 'no', |
|
| 360 | - 'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ), |
|
| 361 | - ) |
|
| 362 | - ); |
|
| 363 | - |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Filter the {@link Wordlift_Admin_Input_Element} in order to add the |
|
| 368 | - * `readonly` flag to the `wl-entity-base-path` input. |
|
| 369 | - * |
|
| 370 | - * @param array $args An array of {@link Wordlift_Admin_Input_Element} parameters. |
|
| 371 | - * |
|
| 372 | - * @return array The updated array. |
|
| 373 | - * @since 3.17.0 |
|
| 374 | - * |
|
| 375 | - */ |
|
| 376 | - public function entity_path_input_element_params( $args ) { |
|
| 377 | - |
|
| 378 | - // Bail out if it's not the `wl-entity-base-path`). |
|
| 379 | - if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
| 380 | - return $args; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - // Set the readonly flag according to the entities count. |
|
| 384 | - $args['readonly'] = 0 < $this->entity_service->count(); |
|
| 385 | - |
|
| 386 | - // Return the updated args. |
|
| 387 | - return $args; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Sanitize the configuration settings to be stored. |
|
| 392 | - * |
|
| 393 | - * If a new entity is being created for the publisher, create it and set The |
|
| 394 | - * publisher setting. |
|
| 395 | - * |
|
| 396 | - * @param array $input The configuration settings array. |
|
| 397 | - * |
|
| 398 | - * @return array The sanitized input array. |
|
| 399 | - * @since 3.11.0 |
|
| 400 | - * |
|
| 401 | - */ |
|
| 402 | - function sanitize_callback( $input ) { |
|
| 403 | - |
|
| 404 | - // Validate the selected country. |
|
| 405 | - $this->validate_country(); |
|
| 406 | - |
|
| 407 | - // Check whether a publisher name has been set. |
|
| 408 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { // WPCS: CSRF, input var, sanitization ok. |
|
| 409 | - $name = $_POST['wl_publisher']['name']; // WPCS: CSRF, input var, sanitization ok. |
|
| 410 | - $type = $_POST['wl_publisher']['type']; // WPCS: CSRF, input var, sanitization ok. |
|
| 411 | - $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null; // WPCS: CSRF, input var, sanitization ok. |
|
| 412 | - |
|
| 413 | - // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
| 414 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 415 | - |
|
| 416 | - // Create an entity for the publisher and assign it to the input |
|
| 417 | - // parameter which WordPress automatically saves into the settings. |
|
| 418 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - return $input; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Check whether the currently selected country supports the site language. |
|
| 426 | - * |
|
| 427 | - * @since 3.18.0 |
|
| 428 | - */ |
|
| 429 | - private function validate_country() { |
|
| 430 | - |
|
| 431 | - // Bail out if for some reason the country and language are not set. |
|
| 432 | - if ( |
|
| 433 | - empty( $_POST['wl_general_settings']['site_language'] ) && // WPCS: CSRF, input var, sanitization ok. |
|
| 434 | - empty( $_POST['wl_general_settings']['country_code'] ) // WPCS: CSRF, input var, sanitization ok. |
|
| 435 | - ) { |
|
| 436 | - return; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // Get the values. |
|
| 440 | - $language = $_POST['wl_general_settings']['site_language']; // WPCS: CSRF, input var, sanitization ok. |
|
| 441 | - $country = $_POST['wl_general_settings']['country_code']; // WPCS: CSRF, input var, sanitization ok. |
|
| 442 | - $codes = Wordlift_Countries::get_codes(); |
|
| 443 | - |
|
| 444 | - // Check whether the chosen country has language limitations |
|
| 445 | - // and whether the chosen language is supported for that country. |
|
| 446 | - if ( |
|
| 447 | - ! empty( $codes[ $country ] ) && |
|
| 448 | - ! in_array( $language, $codes[ $country ] ) |
|
| 449 | - ) { |
|
| 450 | - // Otherwise add an error. |
|
| 451 | - add_settings_error( |
|
| 452 | - 'wl-country-code', |
|
| 453 | - esc_attr( 'settings_updated' ), |
|
| 454 | - _x( 'The selected language is not supported for the currently chosen country. Please choose another country or language.', 'wordlift' ) |
|
| 455 | - ); |
|
| 456 | - } |
|
| 457 | - } |
|
| 21 | + /** |
|
| 22 | + * A singleton instance of the Notice service. |
|
| 23 | + * |
|
| 24 | + * @since 3.2.0 |
|
| 25 | + * @access private |
|
| 26 | + * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service. |
|
| 27 | + */ |
|
| 28 | + private static $instance; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * A {@link Wordlift_Entity_Service} instance. |
|
| 32 | + * |
|
| 33 | + * @since 3.11.0 |
|
| 34 | + * @access private |
|
| 35 | + * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 36 | + */ |
|
| 37 | + private $entity_service; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * A {@link Wordlift_Configuration_Service} instance. |
|
| 41 | + * |
|
| 42 | + * @since 3.11.0 |
|
| 43 | + * @access private |
|
| 44 | + * @var \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 45 | + */ |
|
| 46 | + private $configuration_service; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * A {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 50 | + * |
|
| 51 | + * @since 3.11.0 |
|
| 52 | + * @access private |
|
| 53 | + * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 54 | + */ |
|
| 55 | + private $input_element; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 59 | + * |
|
| 60 | + * @since 3.13.0 |
|
| 61 | + * @access protected |
|
| 62 | + * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 63 | + */ |
|
| 64 | + private $radio_input_element; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 68 | + * |
|
| 69 | + * @since 3.11.0 |
|
| 70 | + * @access private |
|
| 71 | + * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 72 | + */ |
|
| 73 | + private $language_select_element; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 77 | + * |
|
| 78 | + * @since 3.18.0 |
|
| 79 | + * @access private |
|
| 80 | + * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 81 | + */ |
|
| 82 | + private $country_select_element; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 86 | + * |
|
| 87 | + * @since 3.11.0 |
|
| 88 | + * @access private |
|
| 89 | + * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 90 | + */ |
|
| 91 | + private $publisher_element; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Create a {@link Wordlift_Admin_Settings_Page} instance. |
|
| 95 | + * |
|
| 96 | + * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 97 | + * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 98 | + * @param \Wordlift_Admin_Input_Element $input_element A {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 99 | + * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 100 | + * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 101 | + * @param \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 102 | + * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 103 | + * |
|
| 104 | + * @since 3.11.0 |
|
| 105 | + * |
|
| 106 | + */ |
|
| 107 | + function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element ) { |
|
| 108 | + |
|
| 109 | + $this->configuration_service = $configuration_service; |
|
| 110 | + $this->entity_service = $entity_service; |
|
| 111 | + |
|
| 112 | + // Set a reference to the UI elements. |
|
| 113 | + $this->input_element = $input_element; |
|
| 114 | + $this->radio_input_element = $radio_input_element; |
|
| 115 | + $this->language_select_element = $language_select_element; |
|
| 116 | + $this->country_select_element = $country_select_element; |
|
| 117 | + $this->publisher_element = $publisher_element; |
|
| 118 | + |
|
| 119 | + self::$instance = $this; |
|
| 120 | + |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Get the singleton instance of the Notice service. |
|
| 125 | + * |
|
| 126 | + * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service. |
|
| 127 | + * @since 3.14.0 |
|
| 128 | + */ |
|
| 129 | + public static function get_instance() { |
|
| 130 | + |
|
| 131 | + return self::$instance; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @inheritdoc |
|
| 136 | + */ |
|
| 137 | + function get_parent_slug() { |
|
| 138 | + |
|
| 139 | + return 'wl_admin_menu'; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @inheritdoc |
|
| 144 | + */ |
|
| 145 | + function get_capability() { |
|
| 146 | + |
|
| 147 | + return 'manage_options'; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @inheritdoc |
|
| 152 | + */ |
|
| 153 | + function get_page_title() { |
|
| 154 | + |
|
| 155 | + return 'WordLift Settings'; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @inheritdoc |
|
| 160 | + */ |
|
| 161 | + function get_menu_title() { |
|
| 162 | + |
|
| 163 | + return 'Settings'; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @inheritdoc |
|
| 168 | + */ |
|
| 169 | + function get_menu_slug() { |
|
| 170 | + |
|
| 171 | + return 'wl_configuration_admin_menu'; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @inheritdoc |
|
| 176 | + */ |
|
| 177 | + function get_partial_name() { |
|
| 178 | + |
|
| 179 | + return 'wordlift-admin-settings-page.php'; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * @inheritdoc |
|
| 184 | + */ |
|
| 185 | + public function enqueue_scripts() { |
|
| 186 | + |
|
| 187 | + // Enqueue the media scripts to be used for the publisher's logo selection. |
|
| 188 | + wp_enqueue_media(); |
|
| 189 | + |
|
| 190 | + // JavaScript required for the settings page. |
|
| 191 | + // @todo: try to move to the `wordlift-admin.bundle.js`. |
|
| 192 | + wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.js', array( 'wp-util' ) ); |
|
| 193 | + wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.css' ); |
|
| 194 | + |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Configure all the configuration parameters. |
|
| 199 | + * |
|
| 200 | + * Called by the *admin_init* hook. |
|
| 201 | + * |
|
| 202 | + * @since 3.11.0 |
|
| 203 | + */ |
|
| 204 | + function admin_init() { |
|
| 205 | + // Register WordLift's general settings, providing our own sanitize callback |
|
| 206 | + // which will also check whether the user filled the WL Publisher form. |
|
| 207 | + register_setting( |
|
| 208 | + 'wl_general_settings', |
|
| 209 | + 'wl_general_settings', |
|
| 210 | + array( $this, 'sanitize_callback' ) |
|
| 211 | + ); |
|
| 212 | + |
|
| 213 | + // Add the general settings section. |
|
| 214 | + add_settings_section( |
|
| 215 | + 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
|
| 216 | + '', // Section header. |
|
| 217 | + '', // Callback used to render the description of the section. |
|
| 218 | + 'wl_general_settings' // Page on which to add this section of options. |
|
| 219 | + ); |
|
| 220 | + |
|
| 221 | + $key_args = array( |
|
| 222 | + 'id' => 'wl-key', |
|
| 223 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 224 | + 'value' => $this->configuration_service->get_key(), |
|
| 225 | + 'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ) |
|
| 226 | + . ' [' . get_option( 'home' ) . ']', |
|
| 227 | + ); |
|
| 228 | + |
|
| 229 | + // Before we were used to validate the key beforehand, but this means |
|
| 230 | + // an http call whenever a page is opened in the admin area. Therefore |
|
| 231 | + // we now leave the input `untouched`, leaving to the client to update |
|
| 232 | + // the `css_class`. |
|
| 233 | + // |
|
| 234 | + // See https://github.com/insideout10/wordlift-plugin/issues/669. |
|
| 235 | + $key_args['css_class'] = 'untouched'; |
|
| 236 | + |
|
| 237 | + // Add the `key` field. |
|
| 238 | + add_settings_field( |
|
| 239 | + 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 240 | + __( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 241 | + // The name of the function responsible for rendering the option interface. |
|
| 242 | + array( $this->input_element, 'render' ), |
|
| 243 | + 'wl_general_settings', // The page on which this option will be displayed. |
|
| 244 | + 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 245 | + $key_args // The array of arguments to pass to the callback. In this case, just a description. |
|
| 246 | + ); |
|
| 247 | + |
|
| 248 | + // Entity Base Path input. |
|
| 249 | + $entity_base_path_args = array( |
|
| 250 | + // The array of arguments to pass to the callback. In this case, just a description. |
|
| 251 | + 'id' => 'wl-entity-base-path', |
|
| 252 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 253 | + 'value' => $this->configuration_service->get_entity_base_path(), |
|
| 254 | + /* translators: Placeholders: %s - a link to FAQ's page. */ |
|
| 255 | + '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' ), |
|
| 256 | + ); |
|
| 257 | + |
|
| 258 | + // The following call is very heavy on large web sites and is always run |
|
| 259 | + // also when not needed: |
|
| 260 | + // $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
|
| 261 | + // |
|
| 262 | + // It is now replaced by a filter to add the `readonly` flag to the |
|
| 263 | + // input element when this is actually rendered. |
|
| 264 | + add_filter( 'wl_admin_input_element_params', array( |
|
| 265 | + $this, |
|
| 266 | + 'entity_path_input_element_params', |
|
| 267 | + ) ); |
|
| 268 | + |
|
| 269 | + // Add the `wl_entity_base_path` field. |
|
| 270 | + add_settings_field( |
|
| 271 | + 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 272 | + __( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 273 | + // The name of the function responsible for rendering the option interface |
|
| 274 | + array( $this->input_element, 'render', ), |
|
| 275 | + 'wl_general_settings', // The page on which this option will be displayed |
|
| 276 | + 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 277 | + $entity_base_path_args |
|
| 278 | + ); |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + $language_name = Wordlift_Languages::get_language_name( |
|
| 282 | + $this->configuration_service->get_language_code() |
|
| 283 | + ); |
|
| 284 | + |
|
| 285 | + // Add the `language_name` field. |
|
| 286 | + add_settings_field( |
|
| 287 | + 'wl-site-language', |
|
| 288 | + __( 'Site Language', 'wordlift' ), |
|
| 289 | + array( $this->input_element, 'render' ), |
|
| 290 | + 'wl_general_settings', |
|
| 291 | + 'wl_general_settings_section', |
|
| 292 | + array( |
|
| 293 | + // The array of arguments to pass to the callback. In this case, just a description. |
|
| 294 | + 'id' => 'wl-site-language', |
|
| 295 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']', |
|
| 296 | + 'value' => $language_name, |
|
| 297 | + 'description' => sprintf( __( |
|
| 298 | + 'WordLift uses the site language, You can change the language from <a href="%s">settings</a>.', 'wordlift' ), |
|
| 299 | + admin_url('options-general.php/#WPLANG') |
|
| 300 | + ), |
|
| 301 | + 'readonly' => true |
|
| 302 | + ) |
|
| 303 | + ); |
|
| 304 | + |
|
| 305 | + // Add the `country_code` field. |
|
| 306 | + add_settings_field( |
|
| 307 | + 'wl-country-code', |
|
| 308 | + _x( 'Country', 'wordlift' ), |
|
| 309 | + array( $this->country_select_element, 'render' ), |
|
| 310 | + 'wl_general_settings', |
|
| 311 | + 'wl_general_settings_section', |
|
| 312 | + array( |
|
| 313 | + 'id' => 'wl-country-code', |
|
| 314 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::COUNTRY_CODE . ']', |
|
| 315 | + 'value' => $this->configuration_service->get_country_code(), |
|
| 316 | + 'description' => __( 'Please select a country.', 'wordlift' ), |
|
| 317 | + 'notice' => __( 'The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift' ), |
|
| 318 | + ) |
|
| 319 | + ); |
|
| 320 | + |
|
| 321 | + // Add the `publisher` field. |
|
| 322 | + add_settings_field( |
|
| 323 | + 'wl-publisher-id', |
|
| 324 | + __( 'Publisher', 'wordlift' ), |
|
| 325 | + array( $this->publisher_element, 'render' ), |
|
| 326 | + 'wl_general_settings', |
|
| 327 | + 'wl_general_settings_section', |
|
| 328 | + array( |
|
| 329 | + 'id' => 'wl-publisher-id', |
|
| 330 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 331 | + ) |
|
| 332 | + ); |
|
| 333 | + |
|
| 334 | + // Add the `link by default` field. |
|
| 335 | + add_settings_field( |
|
| 336 | + 'wl-link-by-default', |
|
| 337 | + __( 'Link by Default', 'wordlift' ), |
|
| 338 | + array( $this->radio_input_element, 'render' ), |
|
| 339 | + 'wl_general_settings', |
|
| 340 | + 'wl_general_settings_section', |
|
| 341 | + array( |
|
| 342 | + 'id' => 'wl-link-by-default', |
|
| 343 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 344 | + 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
|
| 345 | + 'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 346 | + ) |
|
| 347 | + ); |
|
| 348 | + |
|
| 349 | + // Add the `diagnostic data` field. |
|
| 350 | + add_settings_field( |
|
| 351 | + 'wl-send-diagnostic', |
|
| 352 | + __( 'Send Diagnostic Data', 'wordlift' ), |
|
| 353 | + array( $this->radio_input_element, 'render' ), |
|
| 354 | + 'wl_general_settings', |
|
| 355 | + 'wl_general_settings_section', |
|
| 356 | + array( |
|
| 357 | + 'id' => 'wl-send-diagnostic', |
|
| 358 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']', |
|
| 359 | + 'value' => 'yes' === $this->configuration_service->get_diagnostic_preferences() ? 'yes' : 'no', |
|
| 360 | + 'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ), |
|
| 361 | + ) |
|
| 362 | + ); |
|
| 363 | + |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Filter the {@link Wordlift_Admin_Input_Element} in order to add the |
|
| 368 | + * `readonly` flag to the `wl-entity-base-path` input. |
|
| 369 | + * |
|
| 370 | + * @param array $args An array of {@link Wordlift_Admin_Input_Element} parameters. |
|
| 371 | + * |
|
| 372 | + * @return array The updated array. |
|
| 373 | + * @since 3.17.0 |
|
| 374 | + * |
|
| 375 | + */ |
|
| 376 | + public function entity_path_input_element_params( $args ) { |
|
| 377 | + |
|
| 378 | + // Bail out if it's not the `wl-entity-base-path`). |
|
| 379 | + if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
| 380 | + return $args; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + // Set the readonly flag according to the entities count. |
|
| 384 | + $args['readonly'] = 0 < $this->entity_service->count(); |
|
| 385 | + |
|
| 386 | + // Return the updated args. |
|
| 387 | + return $args; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Sanitize the configuration settings to be stored. |
|
| 392 | + * |
|
| 393 | + * If a new entity is being created for the publisher, create it and set The |
|
| 394 | + * publisher setting. |
|
| 395 | + * |
|
| 396 | + * @param array $input The configuration settings array. |
|
| 397 | + * |
|
| 398 | + * @return array The sanitized input array. |
|
| 399 | + * @since 3.11.0 |
|
| 400 | + * |
|
| 401 | + */ |
|
| 402 | + function sanitize_callback( $input ) { |
|
| 403 | + |
|
| 404 | + // Validate the selected country. |
|
| 405 | + $this->validate_country(); |
|
| 406 | + |
|
| 407 | + // Check whether a publisher name has been set. |
|
| 408 | + if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { // WPCS: CSRF, input var, sanitization ok. |
|
| 409 | + $name = $_POST['wl_publisher']['name']; // WPCS: CSRF, input var, sanitization ok. |
|
| 410 | + $type = $_POST['wl_publisher']['type']; // WPCS: CSRF, input var, sanitization ok. |
|
| 411 | + $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null; // WPCS: CSRF, input var, sanitization ok. |
|
| 412 | + |
|
| 413 | + // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
| 414 | + $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 415 | + |
|
| 416 | + // Create an entity for the publisher and assign it to the input |
|
| 417 | + // parameter which WordPress automatically saves into the settings. |
|
| 418 | + $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + return $input; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Check whether the currently selected country supports the site language. |
|
| 426 | + * |
|
| 427 | + * @since 3.18.0 |
|
| 428 | + */ |
|
| 429 | + private function validate_country() { |
|
| 430 | + |
|
| 431 | + // Bail out if for some reason the country and language are not set. |
|
| 432 | + if ( |
|
| 433 | + empty( $_POST['wl_general_settings']['site_language'] ) && // WPCS: CSRF, input var, sanitization ok. |
|
| 434 | + empty( $_POST['wl_general_settings']['country_code'] ) // WPCS: CSRF, input var, sanitization ok. |
|
| 435 | + ) { |
|
| 436 | + return; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // Get the values. |
|
| 440 | + $language = $_POST['wl_general_settings']['site_language']; // WPCS: CSRF, input var, sanitization ok. |
|
| 441 | + $country = $_POST['wl_general_settings']['country_code']; // WPCS: CSRF, input var, sanitization ok. |
|
| 442 | + $codes = Wordlift_Countries::get_codes(); |
|
| 443 | + |
|
| 444 | + // Check whether the chosen country has language limitations |
|
| 445 | + // and whether the chosen language is supported for that country. |
|
| 446 | + if ( |
|
| 447 | + ! empty( $codes[ $country ] ) && |
|
| 448 | + ! in_array( $language, $codes[ $country ] ) |
|
| 449 | + ) { |
|
| 450 | + // Otherwise add an error. |
|
| 451 | + add_settings_error( |
|
| 452 | + 'wl-country-code', |
|
| 453 | + esc_attr( 'settings_updated' ), |
|
| 454 | + _x( 'The selected language is not supported for the currently chosen country. Please choose another country or language.', 'wordlift' ) |
|
| 455 | + ); |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | 458 | |
| 459 | 459 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @since 3.11.0 |
| 105 | 105 | * |
| 106 | 106 | */ |
| 107 | - function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element ) { |
|
| 107 | + function __construct($configuration_service, $entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element) { |
|
| 108 | 108 | |
| 109 | 109 | $this->configuration_service = $configuration_service; |
| 110 | 110 | $this->entity_service = $entity_service; |
@@ -189,8 +189,8 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | // JavaScript required for the settings page. |
| 191 | 191 | // @todo: try to move to the `wordlift-admin.bundle.js`. |
| 192 | - wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.js', array( 'wp-util' ) ); |
|
| 193 | - wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.css' ); |
|
| 192 | + wp_enqueue_script('wordlift-admin-settings-page', plugin_dir_url(dirname(__FILE__)).'admin/js/1/settings.js', array('wp-util')); |
|
| 193 | + wp_enqueue_style('wordlift-admin-settings-page', plugin_dir_url(dirname(__FILE__)).'admin/js/1/settings.css'); |
|
| 194 | 194 | |
| 195 | 195 | } |
| 196 | 196 | |
@@ -207,23 +207,23 @@ discard block |
||
| 207 | 207 | register_setting( |
| 208 | 208 | 'wl_general_settings', |
| 209 | 209 | 'wl_general_settings', |
| 210 | - array( $this, 'sanitize_callback' ) |
|
| 210 | + array($this, 'sanitize_callback') |
|
| 211 | 211 | ); |
| 212 | 212 | |
| 213 | 213 | // Add the general settings section. |
| 214 | 214 | add_settings_section( |
| 215 | 215 | 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
| 216 | - '', // Section header. |
|
| 217 | - '', // Callback used to render the description of the section. |
|
| 216 | + '', // Section header. |
|
| 217 | + '', // Callback used to render the description of the section. |
|
| 218 | 218 | 'wl_general_settings' // Page on which to add this section of options. |
| 219 | 219 | ); |
| 220 | 220 | |
| 221 | 221 | $key_args = array( |
| 222 | 222 | 'id' => 'wl-key', |
| 223 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 223 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::KEY.']', |
|
| 224 | 224 | 'value' => $this->configuration_service->get_key(), |
| 225 | - 'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ) |
|
| 226 | - . ' [' . get_option( 'home' ) . ']', |
|
| 225 | + 'description' => __('Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift') |
|
| 226 | + . ' ['.get_option('home').']', |
|
| 227 | 227 | ); |
| 228 | 228 | |
| 229 | 229 | // Before we were used to validate the key beforehand, but this means |
@@ -236,12 +236,12 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | // Add the `key` field. |
| 238 | 238 | add_settings_field( |
| 239 | - 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 240 | - __( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 239 | + 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 240 | + __('WordLift Key', 'wordlift'), // The label to the left of the option interface element. |
|
| 241 | 241 | // The name of the function responsible for rendering the option interface. |
| 242 | - array( $this->input_element, 'render' ), |
|
| 243 | - 'wl_general_settings', // The page on which this option will be displayed. |
|
| 244 | - 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 242 | + array($this->input_element, 'render'), |
|
| 243 | + 'wl_general_settings', // The page on which this option will be displayed. |
|
| 244 | + 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 245 | 245 | $key_args // The array of arguments to pass to the callback. In this case, just a description. |
| 246 | 246 | ); |
| 247 | 247 | |
@@ -249,10 +249,10 @@ discard block |
||
| 249 | 249 | $entity_base_path_args = array( |
| 250 | 250 | // The array of arguments to pass to the callback. In this case, just a description. |
| 251 | 251 | 'id' => 'wl-entity-base-path', |
| 252 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 252 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY.']', |
|
| 253 | 253 | 'value' => $this->configuration_service->get_entity_base_path(), |
| 254 | 254 | /* translators: Placeholders: %s - a link to FAQ's page. */ |
| 255 | - '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' ), |
|
| 255 | + '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'), |
|
| 256 | 256 | ); |
| 257 | 257 | |
| 258 | 258 | // The following call is very heavy on large web sites and is always run |
@@ -261,19 +261,19 @@ discard block |
||
| 261 | 261 | // |
| 262 | 262 | // It is now replaced by a filter to add the `readonly` flag to the |
| 263 | 263 | // input element when this is actually rendered. |
| 264 | - add_filter( 'wl_admin_input_element_params', array( |
|
| 264 | + add_filter('wl_admin_input_element_params', array( |
|
| 265 | 265 | $this, |
| 266 | 266 | 'entity_path_input_element_params', |
| 267 | - ) ); |
|
| 267 | + )); |
|
| 268 | 268 | |
| 269 | 269 | // Add the `wl_entity_base_path` field. |
| 270 | 270 | add_settings_field( |
| 271 | - 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 272 | - __( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 271 | + 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 272 | + __('Entity Base Path', 'wordlift'), // The label to the left of the option interface element |
|
| 273 | 273 | // The name of the function responsible for rendering the option interface |
| 274 | - array( $this->input_element, 'render', ), |
|
| 275 | - 'wl_general_settings', // The page on which this option will be displayed |
|
| 276 | - 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 274 | + array($this->input_element, 'render',), |
|
| 275 | + 'wl_general_settings', // The page on which this option will be displayed |
|
| 276 | + 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 277 | 277 | $entity_base_path_args |
| 278 | 278 | ); |
| 279 | 279 | |
@@ -285,16 +285,16 @@ discard block |
||
| 285 | 285 | // Add the `language_name` field. |
| 286 | 286 | add_settings_field( |
| 287 | 287 | 'wl-site-language', |
| 288 | - __( 'Site Language', 'wordlift' ), |
|
| 289 | - array( $this->input_element, 'render' ), |
|
| 288 | + __('Site Language', 'wordlift'), |
|
| 289 | + array($this->input_element, 'render'), |
|
| 290 | 290 | 'wl_general_settings', |
| 291 | 291 | 'wl_general_settings_section', |
| 292 | 292 | array( |
| 293 | 293 | // The array of arguments to pass to the callback. In this case, just a description. |
| 294 | 294 | 'id' => 'wl-site-language', |
| 295 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']', |
|
| 295 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::LANGUAGE.']', |
|
| 296 | 296 | 'value' => $language_name, |
| 297 | - 'description' => sprintf( __( |
|
| 297 | + 'description' => sprintf(__( |
|
| 298 | 298 | 'WordLift uses the site language, You can change the language from <a href="%s">settings</a>.', 'wordlift' ), |
| 299 | 299 | admin_url('options-general.php/#WPLANG') |
| 300 | 300 | ), |
@@ -305,59 +305,59 @@ discard block |
||
| 305 | 305 | // Add the `country_code` field. |
| 306 | 306 | add_settings_field( |
| 307 | 307 | 'wl-country-code', |
| 308 | - _x( 'Country', 'wordlift' ), |
|
| 309 | - array( $this->country_select_element, 'render' ), |
|
| 308 | + _x('Country', 'wordlift'), |
|
| 309 | + array($this->country_select_element, 'render'), |
|
| 310 | 310 | 'wl_general_settings', |
| 311 | 311 | 'wl_general_settings_section', |
| 312 | 312 | array( |
| 313 | 313 | 'id' => 'wl-country-code', |
| 314 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::COUNTRY_CODE . ']', |
|
| 314 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::COUNTRY_CODE.']', |
|
| 315 | 315 | 'value' => $this->configuration_service->get_country_code(), |
| 316 | - 'description' => __( 'Please select a country.', 'wordlift' ), |
|
| 317 | - 'notice' => __( 'The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift' ), |
|
| 316 | + 'description' => __('Please select a country.', 'wordlift'), |
|
| 317 | + 'notice' => __('The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift'), |
|
| 318 | 318 | ) |
| 319 | 319 | ); |
| 320 | 320 | |
| 321 | 321 | // Add the `publisher` field. |
| 322 | 322 | add_settings_field( |
| 323 | 323 | 'wl-publisher-id', |
| 324 | - __( 'Publisher', 'wordlift' ), |
|
| 325 | - array( $this->publisher_element, 'render' ), |
|
| 324 | + __('Publisher', 'wordlift'), |
|
| 325 | + array($this->publisher_element, 'render'), |
|
| 326 | 326 | 'wl_general_settings', |
| 327 | 327 | 'wl_general_settings_section', |
| 328 | 328 | array( |
| 329 | 329 | 'id' => 'wl-publisher-id', |
| 330 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 330 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::PUBLISHER_ID.']', |
|
| 331 | 331 | ) |
| 332 | 332 | ); |
| 333 | 333 | |
| 334 | 334 | // Add the `link by default` field. |
| 335 | 335 | add_settings_field( |
| 336 | 336 | 'wl-link-by-default', |
| 337 | - __( 'Link by Default', 'wordlift' ), |
|
| 338 | - array( $this->radio_input_element, 'render' ), |
|
| 337 | + __('Link by Default', 'wordlift'), |
|
| 338 | + array($this->radio_input_element, 'render'), |
|
| 339 | 339 | 'wl_general_settings', |
| 340 | 340 | 'wl_general_settings_section', |
| 341 | 341 | array( |
| 342 | 342 | 'id' => 'wl-link-by-default', |
| 343 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 343 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::LINK_BY_DEFAULT.']', |
|
| 344 | 344 | 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
| 345 | - 'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 345 | + 'description' => __('Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift'), |
|
| 346 | 346 | ) |
| 347 | 347 | ); |
| 348 | 348 | |
| 349 | 349 | // Add the `diagnostic data` field. |
| 350 | 350 | add_settings_field( |
| 351 | 351 | 'wl-send-diagnostic', |
| 352 | - __( 'Send Diagnostic Data', 'wordlift' ), |
|
| 353 | - array( $this->radio_input_element, 'render' ), |
|
| 352 | + __('Send Diagnostic Data', 'wordlift'), |
|
| 353 | + array($this->radio_input_element, 'render'), |
|
| 354 | 354 | 'wl_general_settings', |
| 355 | 355 | 'wl_general_settings_section', |
| 356 | 356 | array( |
| 357 | 357 | 'id' => 'wl-send-diagnostic', |
| 358 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']', |
|
| 358 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::SEND_DIAGNOSTIC.']', |
|
| 359 | 359 | 'value' => 'yes' === $this->configuration_service->get_diagnostic_preferences() ? 'yes' : 'no', |
| 360 | - 'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ), |
|
| 360 | + 'description' => __('Whether to send diagnostic data or not.', 'wordlift'), |
|
| 361 | 361 | ) |
| 362 | 362 | ); |
| 363 | 363 | |
@@ -373,10 +373,10 @@ discard block |
||
| 373 | 373 | * @since 3.17.0 |
| 374 | 374 | * |
| 375 | 375 | */ |
| 376 | - public function entity_path_input_element_params( $args ) { |
|
| 376 | + public function entity_path_input_element_params($args) { |
|
| 377 | 377 | |
| 378 | 378 | // Bail out if it's not the `wl-entity-base-path`). |
| 379 | - if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
| 379 | + if ('wl-entity-base-path' !== $args['id']) { |
|
| 380 | 380 | return $args; |
| 381 | 381 | } |
| 382 | 382 | |
@@ -399,23 +399,23 @@ discard block |
||
| 399 | 399 | * @since 3.11.0 |
| 400 | 400 | * |
| 401 | 401 | */ |
| 402 | - function sanitize_callback( $input ) { |
|
| 402 | + function sanitize_callback($input) { |
|
| 403 | 403 | |
| 404 | 404 | // Validate the selected country. |
| 405 | 405 | $this->validate_country(); |
| 406 | 406 | |
| 407 | 407 | // Check whether a publisher name has been set. |
| 408 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { // WPCS: CSRF, input var, sanitization ok. |
|
| 408 | + if (isset($_POST['wl_publisher']) && ! empty($_POST['wl_publisher']['name'])) { // WPCS: CSRF, input var, sanitization ok. |
|
| 409 | 409 | $name = $_POST['wl_publisher']['name']; // WPCS: CSRF, input var, sanitization ok. |
| 410 | 410 | $type = $_POST['wl_publisher']['type']; // WPCS: CSRF, input var, sanitization ok. |
| 411 | 411 | $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null; // WPCS: CSRF, input var, sanitization ok. |
| 412 | 412 | |
| 413 | 413 | // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
| 414 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 414 | + $type_uri = sprintf('http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person'); |
|
| 415 | 415 | |
| 416 | 416 | // Create an entity for the publisher and assign it to the input |
| 417 | 417 | // parameter which WordPress automatically saves into the settings. |
| 418 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 418 | + $input['publisher_id'] = $this->entity_service->create($name, $type_uri, $thumbnail_id, 'publish'); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | return $input; |
@@ -430,8 +430,8 @@ discard block |
||
| 430 | 430 | |
| 431 | 431 | // Bail out if for some reason the country and language are not set. |
| 432 | 432 | if ( |
| 433 | - empty( $_POST['wl_general_settings']['site_language'] ) && // WPCS: CSRF, input var, sanitization ok. |
|
| 434 | - empty( $_POST['wl_general_settings']['country_code'] ) // WPCS: CSRF, input var, sanitization ok. |
|
| 433 | + empty($_POST['wl_general_settings']['site_language']) && // WPCS: CSRF, input var, sanitization ok. |
|
| 434 | + empty($_POST['wl_general_settings']['country_code']) // WPCS: CSRF, input var, sanitization ok. |
|
| 435 | 435 | ) { |
| 436 | 436 | return; |
| 437 | 437 | } |
@@ -444,14 +444,14 @@ discard block |
||
| 444 | 444 | // Check whether the chosen country has language limitations |
| 445 | 445 | // and whether the chosen language is supported for that country. |
| 446 | 446 | if ( |
| 447 | - ! empty( $codes[ $country ] ) && |
|
| 448 | - ! in_array( $language, $codes[ $country ] ) |
|
| 447 | + ! empty($codes[$country]) && |
|
| 448 | + ! in_array($language, $codes[$country]) |
|
| 449 | 449 | ) { |
| 450 | 450 | // Otherwise add an error. |
| 451 | 451 | add_settings_error( |
| 452 | 452 | 'wl-country-code', |
| 453 | - esc_attr( 'settings_updated' ), |
|
| 454 | - _x( 'The selected language is not supported for the currently chosen country. Please choose another country or language.', 'wordlift' ) |
|
| 453 | + esc_attr('settings_updated'), |
|
| 454 | + _x('The selected language is not supported for the currently chosen country. Please choose another country or language.', 'wordlift') |
|
| 455 | 455 | ); |
| 456 | 456 | } |
| 457 | 457 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | - exit; |
|
| 14 | + exit; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -21,295 +21,295 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class Wordlift_Languages { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * An array that will contain language codes => language names pairs. It gets lazily loaded the first time by the |
|
| 26 | - * `get_languages` function. |
|
| 27 | - * |
|
| 28 | - * @since 3.9.0 |
|
| 29 | - * @var array|null An array of language codes => language names pairs or NULL if not initialized yet. |
|
| 30 | - */ |
|
| 31 | - private static $languages = null; |
|
| 24 | + /** |
|
| 25 | + * An array that will contain language codes => language names pairs. It gets lazily loaded the first time by the |
|
| 26 | + * `get_languages` function. |
|
| 27 | + * |
|
| 28 | + * @since 3.9.0 |
|
| 29 | + * @var array|null An array of language codes => language names pairs or NULL if not initialized yet. |
|
| 30 | + */ |
|
| 31 | + private static $languages = null; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * The list of supported language codes. |
|
| 35 | - * |
|
| 36 | - * @since 3.9.0 |
|
| 37 | - * |
|
| 38 | - * @var array An array of language codes. |
|
| 39 | - */ |
|
| 40 | - private static $codes = array( |
|
| 41 | - 'ar', |
|
| 42 | - 'be', |
|
| 43 | - 'bg', |
|
| 44 | - 'ca', |
|
| 45 | - 'cs', |
|
| 46 | - 'da', |
|
| 47 | - 'de', |
|
| 48 | - 'el', |
|
| 49 | - 'en', |
|
| 50 | - 'es', |
|
| 51 | - 'et', |
|
| 52 | - 'fi', |
|
| 53 | - 'fr', |
|
| 54 | - 'he', |
|
| 55 | - 'hr', |
|
| 56 | - 'hu', |
|
| 57 | - 'id', |
|
| 58 | - 'is', |
|
| 59 | - 'it', |
|
| 60 | - 'lt', |
|
| 61 | - 'lv', |
|
| 62 | - 'nl', |
|
| 63 | - 'no', |
|
| 64 | - 'pl', |
|
| 65 | - 'pt', |
|
| 66 | - 'ro', |
|
| 67 | - 'ru', |
|
| 68 | - 'sk', |
|
| 69 | - 'sl', |
|
| 70 | - 'sq', |
|
| 71 | - 'sr', |
|
| 72 | - 'sv', |
|
| 73 | - 'tr', |
|
| 74 | - 'uk', |
|
| 75 | - 'zh-cn', |
|
| 76 | - ); |
|
| 33 | + /** |
|
| 34 | + * The list of supported language codes. |
|
| 35 | + * |
|
| 36 | + * @since 3.9.0 |
|
| 37 | + * |
|
| 38 | + * @var array An array of language codes. |
|
| 39 | + */ |
|
| 40 | + private static $codes = array( |
|
| 41 | + 'ar', |
|
| 42 | + 'be', |
|
| 43 | + 'bg', |
|
| 44 | + 'ca', |
|
| 45 | + 'cs', |
|
| 46 | + 'da', |
|
| 47 | + 'de', |
|
| 48 | + 'el', |
|
| 49 | + 'en', |
|
| 50 | + 'es', |
|
| 51 | + 'et', |
|
| 52 | + 'fi', |
|
| 53 | + 'fr', |
|
| 54 | + 'he', |
|
| 55 | + 'hr', |
|
| 56 | + 'hu', |
|
| 57 | + 'id', |
|
| 58 | + 'is', |
|
| 59 | + 'it', |
|
| 60 | + 'lt', |
|
| 61 | + 'lv', |
|
| 62 | + 'nl', |
|
| 63 | + 'no', |
|
| 64 | + 'pl', |
|
| 65 | + 'pt', |
|
| 66 | + 'ro', |
|
| 67 | + 'ru', |
|
| 68 | + 'sk', |
|
| 69 | + 'sl', |
|
| 70 | + 'sq', |
|
| 71 | + 'sr', |
|
| 72 | + 'sv', |
|
| 73 | + 'tr', |
|
| 74 | + 'uk', |
|
| 75 | + 'zh-cn', |
|
| 76 | + ); |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Get the list of WordLift's supported languages in an array with language code => language name pairs. |
|
| 80 | - * |
|
| 81 | - * @since 3.9.0 |
|
| 82 | - * |
|
| 83 | - * @return array An array with language code => language name pairs. |
|
| 84 | - */ |
|
| 85 | - public static function get_languages() { |
|
| 78 | + /** |
|
| 79 | + * Get the list of WordLift's supported languages in an array with language code => language name pairs. |
|
| 80 | + * |
|
| 81 | + * @since 3.9.0 |
|
| 82 | + * |
|
| 83 | + * @return array An array with language code => language name pairs. |
|
| 84 | + */ |
|
| 85 | + public static function get_languages() { |
|
| 86 | 86 | |
| 87 | - // Lazily load the languages. |
|
| 88 | - if ( null === self::$languages ) { |
|
| 87 | + // Lazily load the languages. |
|
| 88 | + if ( null === self::$languages ) { |
|
| 89 | 89 | |
| 90 | - // Get the language names from WP's own (multisite) function. |
|
| 91 | - foreach ( self::$codes as $key ) { |
|
| 92 | - self::$languages[ $key ] = self::get_language_name( $key ); |
|
| 93 | - } |
|
| 90 | + // Get the language names from WP's own (multisite) function. |
|
| 91 | + foreach ( self::$codes as $key ) { |
|
| 92 | + self::$languages[ $key ] = self::get_language_name( $key ); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - // Sort by language name. |
|
| 96 | - asort( self::$languages ); |
|
| 97 | - } |
|
| 95 | + // Sort by language name. |
|
| 96 | + asort( self::$languages ); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - return self::$languages; |
|
| 100 | - } |
|
| 99 | + return self::$languages; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Returns the language for a language code. This function is a clone of WP's function provided in `ms.php`. |
|
| 104 | - * |
|
| 105 | - * @since 3.9.3 |
|
| 106 | - * |
|
| 107 | - * @param string $code Optional. The two-letter language code. Default empty. |
|
| 108 | - * |
|
| 109 | - * @return string The language corresponding to $code if it exists. If it does not exist, |
|
| 110 | - * then the first two letters of $code is returned. |
|
| 111 | - */ |
|
| 112 | - public static function get_language_name( $code = '' ) { |
|
| 113 | - $code = strtolower( substr( $code, 0, 2 ) ); |
|
| 114 | - $lang_codes = array( |
|
| 115 | - 'aa' => 'Afar', |
|
| 116 | - 'ab' => 'Abkhazian', |
|
| 117 | - 'af' => 'Afrikaans', |
|
| 118 | - 'ak' => 'Akan', |
|
| 119 | - 'sq' => 'Albanian', |
|
| 120 | - 'am' => 'Amharic', |
|
| 121 | - 'ar' => 'Arabic', |
|
| 122 | - 'an' => 'Aragonese', |
|
| 123 | - 'hy' => 'Armenian', |
|
| 124 | - 'as' => 'Assamese', |
|
| 125 | - 'av' => 'Avaric', |
|
| 126 | - 'ae' => 'Avestan', |
|
| 127 | - 'ay' => 'Aymara', |
|
| 128 | - 'az' => 'Azerbaijani', |
|
| 129 | - 'ba' => 'Bashkir', |
|
| 130 | - 'bm' => 'Bambara', |
|
| 131 | - 'eu' => 'Basque', |
|
| 132 | - 'be' => 'Belarusian', |
|
| 133 | - 'bn' => 'Bengali', |
|
| 134 | - 'bh' => 'Bihari', |
|
| 135 | - 'bi' => 'Bislama', |
|
| 136 | - 'bs' => 'Bosnian', |
|
| 137 | - 'br' => 'Breton', |
|
| 138 | - 'bg' => 'Bulgarian', |
|
| 139 | - 'my' => 'Burmese', |
|
| 140 | - 'ca' => 'Catalan; Valencian', |
|
| 141 | - 'ch' => 'Chamorro', |
|
| 142 | - 'ce' => 'Chechen', |
|
| 143 | - 'zh' => 'Chinese', |
|
| 144 | - 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', |
|
| 145 | - 'cv' => 'Chuvash', |
|
| 146 | - 'kw' => 'Cornish', |
|
| 147 | - 'co' => 'Corsican', |
|
| 148 | - 'cr' => 'Cree', |
|
| 149 | - 'cs' => 'Czech', |
|
| 150 | - 'da' => 'Danish', |
|
| 151 | - 'dv' => 'Divehi; Dhivehi; Maldivian', |
|
| 152 | - 'nl' => 'Dutch; Flemish', |
|
| 153 | - 'dz' => 'Dzongkha', |
|
| 154 | - 'en' => 'English', |
|
| 155 | - 'eo' => 'Esperanto', |
|
| 156 | - 'et' => 'Estonian', |
|
| 157 | - 'ee' => 'Ewe', |
|
| 158 | - 'fo' => 'Faroese', |
|
| 159 | - 'fj' => 'Fijjian', |
|
| 160 | - 'fi' => 'Finnish', |
|
| 161 | - 'fr' => 'French', |
|
| 162 | - 'fy' => 'Western Frisian', |
|
| 163 | - 'ff' => 'Fulah', |
|
| 164 | - 'ka' => 'Georgian', |
|
| 165 | - 'de' => 'German', |
|
| 166 | - 'gd' => 'Gaelic; Scottish Gaelic', |
|
| 167 | - 'ga' => 'Irish', |
|
| 168 | - 'gl' => 'Galician', |
|
| 169 | - 'gv' => 'Manx', |
|
| 170 | - 'el' => 'Greek, Modern', |
|
| 171 | - 'gn' => 'Guarani', |
|
| 172 | - 'gu' => 'Gujarati', |
|
| 173 | - 'ht' => 'Haitian; Haitian Creole', |
|
| 174 | - 'ha' => 'Hausa', |
|
| 175 | - 'he' => 'Hebrew', |
|
| 176 | - 'hz' => 'Herero', |
|
| 177 | - 'hi' => 'Hindi', |
|
| 178 | - 'ho' => 'Hiri Motu', |
|
| 179 | - 'hu' => 'Hungarian', |
|
| 180 | - 'ig' => 'Igbo', |
|
| 181 | - 'is' => 'Icelandic', |
|
| 182 | - 'io' => 'Ido', |
|
| 183 | - 'ii' => 'Sichuan Yi', |
|
| 184 | - 'iu' => 'Inuktitut', |
|
| 185 | - 'ie' => 'Interlingue', |
|
| 186 | - 'ia' => 'Interlingua (International Auxiliary Language Association)', |
|
| 187 | - 'id' => 'Indonesian', |
|
| 188 | - 'ik' => 'Inupiaq', |
|
| 189 | - 'it' => 'Italian', |
|
| 190 | - 'jv' => 'Javanese', |
|
| 191 | - 'ja' => 'Japanese', |
|
| 192 | - 'kl' => 'Kalaallisut; Greenlandic', |
|
| 193 | - 'kn' => 'Kannada', |
|
| 194 | - 'ks' => 'Kashmiri', |
|
| 195 | - 'kr' => 'Kanuri', |
|
| 196 | - 'kk' => 'Kazakh', |
|
| 197 | - 'km' => 'Central Khmer', |
|
| 198 | - 'ki' => 'Kikuyu; Gikuyu', |
|
| 199 | - 'rw' => 'Kinyarwanda', |
|
| 200 | - 'ky' => 'Kirghiz; Kyrgyz', |
|
| 201 | - 'kv' => 'Komi', |
|
| 202 | - 'kg' => 'Kongo', |
|
| 203 | - 'ko' => 'Korean', |
|
| 204 | - 'kj' => 'Kuanyama; Kwanyama', |
|
| 205 | - 'ku' => 'Kurdish', |
|
| 206 | - 'lo' => 'Lao', |
|
| 207 | - 'la' => 'Latin', |
|
| 208 | - 'lv' => 'Latvian', |
|
| 209 | - 'li' => 'Limburgan; Limburger; Limburgish', |
|
| 210 | - 'ln' => 'Lingala', |
|
| 211 | - 'lt' => 'Lithuanian', |
|
| 212 | - 'lb' => 'Luxembourgish; Letzeburgesch', |
|
| 213 | - 'lu' => 'Luba-Katanga', |
|
| 214 | - 'lg' => 'Ganda', |
|
| 215 | - 'mk' => 'Macedonian', |
|
| 216 | - 'mh' => 'Marshallese', |
|
| 217 | - 'ml' => 'Malayalam', |
|
| 218 | - 'mi' => 'Maori', |
|
| 219 | - 'mr' => 'Marathi', |
|
| 220 | - 'ms' => 'Malay', |
|
| 221 | - 'mg' => 'Malagasy', |
|
| 222 | - 'mt' => 'Maltese', |
|
| 223 | - 'mo' => 'Moldavian', |
|
| 224 | - 'mn' => 'Mongolian', |
|
| 225 | - 'na' => 'Nauru', |
|
| 226 | - 'nv' => 'Navajo; Navaho', |
|
| 227 | - 'nr' => 'Ndebele, South; South Ndebele', |
|
| 228 | - 'nd' => 'Ndebele, North; North Ndebele', |
|
| 229 | - 'ng' => 'Ndonga', |
|
| 230 | - 'ne' => 'Nepali', |
|
| 231 | - 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', |
|
| 232 | - 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål', |
|
| 233 | - 'no' => 'Norwegian', |
|
| 234 | - 'ny' => 'Chichewa; Chewa; Nyanja', |
|
| 235 | - 'oc' => 'Occitan, Provençal', |
|
| 236 | - 'oj' => 'Ojibwa', |
|
| 237 | - 'or' => 'Oriya', |
|
| 238 | - 'om' => 'Oromo', |
|
| 239 | - 'os' => 'Ossetian; Ossetic', |
|
| 240 | - 'pa' => 'Panjabi; Punjabi', |
|
| 241 | - 'fa' => 'Persian', |
|
| 242 | - 'pi' => 'Pali', |
|
| 243 | - 'pl' => 'Polish', |
|
| 244 | - 'pt' => 'Portuguese', |
|
| 245 | - 'ps' => 'Pushto', |
|
| 246 | - 'qu' => 'Quechua', |
|
| 247 | - 'rm' => 'Romansh', |
|
| 248 | - 'ro' => 'Romanian', |
|
| 249 | - 'rn' => 'Rundi', |
|
| 250 | - 'ru' => 'Russian', |
|
| 251 | - 'sg' => 'Sango', |
|
| 252 | - 'sa' => 'Sanskrit', |
|
| 253 | - 'sr' => 'Serbian', |
|
| 254 | - 'hr' => 'Croatian', |
|
| 255 | - 'si' => 'Sinhala; Sinhalese', |
|
| 256 | - 'sk' => 'Slovak', |
|
| 257 | - 'sl' => 'Slovenian', |
|
| 258 | - 'se' => 'Northern Sami', |
|
| 259 | - 'sm' => 'Samoan', |
|
| 260 | - 'sn' => 'Shona', |
|
| 261 | - 'sd' => 'Sindhi', |
|
| 262 | - 'so' => 'Somali', |
|
| 263 | - 'st' => 'Sotho, Southern', |
|
| 264 | - 'es' => 'Spanish; Castilian', |
|
| 265 | - 'sc' => 'Sardinian', |
|
| 266 | - 'ss' => 'Swati', |
|
| 267 | - 'su' => 'Sundanese', |
|
| 268 | - 'sw' => 'Swahili', |
|
| 269 | - 'sv' => 'Swedish', |
|
| 270 | - 'ty' => 'Tahitian', |
|
| 271 | - 'ta' => 'Tamil', |
|
| 272 | - 'tt' => 'Tatar', |
|
| 273 | - 'te' => 'Telugu', |
|
| 274 | - 'tg' => 'Tajik', |
|
| 275 | - 'tl' => 'Tagalog', |
|
| 276 | - 'th' => 'Thai', |
|
| 277 | - 'bo' => 'Tibetan', |
|
| 278 | - 'ti' => 'Tigrinya', |
|
| 279 | - 'to' => 'Tonga (Tonga Islands)', |
|
| 280 | - 'tn' => 'Tswana', |
|
| 281 | - 'ts' => 'Tsonga', |
|
| 282 | - 'tk' => 'Turkmen', |
|
| 283 | - 'tr' => 'Turkish', |
|
| 284 | - 'tw' => 'Twi', |
|
| 285 | - 'ug' => 'Uighur; Uyghur', |
|
| 286 | - 'uk' => 'Ukrainian', |
|
| 287 | - 'ur' => 'Urdu', |
|
| 288 | - 'uz' => 'Uzbek', |
|
| 289 | - 've' => 'Venda', |
|
| 290 | - 'vi' => 'Vietnamese', |
|
| 291 | - 'vo' => 'Volapük', |
|
| 292 | - 'cy' => 'Welsh', |
|
| 293 | - 'wa' => 'Walloon', |
|
| 294 | - 'wo' => 'Wolof', |
|
| 295 | - 'xh' => 'Xhosa', |
|
| 296 | - 'yi' => 'Yiddish', |
|
| 297 | - 'yo' => 'Yoruba', |
|
| 298 | - 'za' => 'Zhuang; Chuang', |
|
| 299 | - 'zu' => 'Zulu' |
|
| 300 | - ); |
|
| 102 | + /** |
|
| 103 | + * Returns the language for a language code. This function is a clone of WP's function provided in `ms.php`. |
|
| 104 | + * |
|
| 105 | + * @since 3.9.3 |
|
| 106 | + * |
|
| 107 | + * @param string $code Optional. The two-letter language code. Default empty. |
|
| 108 | + * |
|
| 109 | + * @return string The language corresponding to $code if it exists. If it does not exist, |
|
| 110 | + * then the first two letters of $code is returned. |
|
| 111 | + */ |
|
| 112 | + public static function get_language_name( $code = '' ) { |
|
| 113 | + $code = strtolower( substr( $code, 0, 2 ) ); |
|
| 114 | + $lang_codes = array( |
|
| 115 | + 'aa' => 'Afar', |
|
| 116 | + 'ab' => 'Abkhazian', |
|
| 117 | + 'af' => 'Afrikaans', |
|
| 118 | + 'ak' => 'Akan', |
|
| 119 | + 'sq' => 'Albanian', |
|
| 120 | + 'am' => 'Amharic', |
|
| 121 | + 'ar' => 'Arabic', |
|
| 122 | + 'an' => 'Aragonese', |
|
| 123 | + 'hy' => 'Armenian', |
|
| 124 | + 'as' => 'Assamese', |
|
| 125 | + 'av' => 'Avaric', |
|
| 126 | + 'ae' => 'Avestan', |
|
| 127 | + 'ay' => 'Aymara', |
|
| 128 | + 'az' => 'Azerbaijani', |
|
| 129 | + 'ba' => 'Bashkir', |
|
| 130 | + 'bm' => 'Bambara', |
|
| 131 | + 'eu' => 'Basque', |
|
| 132 | + 'be' => 'Belarusian', |
|
| 133 | + 'bn' => 'Bengali', |
|
| 134 | + 'bh' => 'Bihari', |
|
| 135 | + 'bi' => 'Bislama', |
|
| 136 | + 'bs' => 'Bosnian', |
|
| 137 | + 'br' => 'Breton', |
|
| 138 | + 'bg' => 'Bulgarian', |
|
| 139 | + 'my' => 'Burmese', |
|
| 140 | + 'ca' => 'Catalan; Valencian', |
|
| 141 | + 'ch' => 'Chamorro', |
|
| 142 | + 'ce' => 'Chechen', |
|
| 143 | + 'zh' => 'Chinese', |
|
| 144 | + 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', |
|
| 145 | + 'cv' => 'Chuvash', |
|
| 146 | + 'kw' => 'Cornish', |
|
| 147 | + 'co' => 'Corsican', |
|
| 148 | + 'cr' => 'Cree', |
|
| 149 | + 'cs' => 'Czech', |
|
| 150 | + 'da' => 'Danish', |
|
| 151 | + 'dv' => 'Divehi; Dhivehi; Maldivian', |
|
| 152 | + 'nl' => 'Dutch; Flemish', |
|
| 153 | + 'dz' => 'Dzongkha', |
|
| 154 | + 'en' => 'English', |
|
| 155 | + 'eo' => 'Esperanto', |
|
| 156 | + 'et' => 'Estonian', |
|
| 157 | + 'ee' => 'Ewe', |
|
| 158 | + 'fo' => 'Faroese', |
|
| 159 | + 'fj' => 'Fijjian', |
|
| 160 | + 'fi' => 'Finnish', |
|
| 161 | + 'fr' => 'French', |
|
| 162 | + 'fy' => 'Western Frisian', |
|
| 163 | + 'ff' => 'Fulah', |
|
| 164 | + 'ka' => 'Georgian', |
|
| 165 | + 'de' => 'German', |
|
| 166 | + 'gd' => 'Gaelic; Scottish Gaelic', |
|
| 167 | + 'ga' => 'Irish', |
|
| 168 | + 'gl' => 'Galician', |
|
| 169 | + 'gv' => 'Manx', |
|
| 170 | + 'el' => 'Greek, Modern', |
|
| 171 | + 'gn' => 'Guarani', |
|
| 172 | + 'gu' => 'Gujarati', |
|
| 173 | + 'ht' => 'Haitian; Haitian Creole', |
|
| 174 | + 'ha' => 'Hausa', |
|
| 175 | + 'he' => 'Hebrew', |
|
| 176 | + 'hz' => 'Herero', |
|
| 177 | + 'hi' => 'Hindi', |
|
| 178 | + 'ho' => 'Hiri Motu', |
|
| 179 | + 'hu' => 'Hungarian', |
|
| 180 | + 'ig' => 'Igbo', |
|
| 181 | + 'is' => 'Icelandic', |
|
| 182 | + 'io' => 'Ido', |
|
| 183 | + 'ii' => 'Sichuan Yi', |
|
| 184 | + 'iu' => 'Inuktitut', |
|
| 185 | + 'ie' => 'Interlingue', |
|
| 186 | + 'ia' => 'Interlingua (International Auxiliary Language Association)', |
|
| 187 | + 'id' => 'Indonesian', |
|
| 188 | + 'ik' => 'Inupiaq', |
|
| 189 | + 'it' => 'Italian', |
|
| 190 | + 'jv' => 'Javanese', |
|
| 191 | + 'ja' => 'Japanese', |
|
| 192 | + 'kl' => 'Kalaallisut; Greenlandic', |
|
| 193 | + 'kn' => 'Kannada', |
|
| 194 | + 'ks' => 'Kashmiri', |
|
| 195 | + 'kr' => 'Kanuri', |
|
| 196 | + 'kk' => 'Kazakh', |
|
| 197 | + 'km' => 'Central Khmer', |
|
| 198 | + 'ki' => 'Kikuyu; Gikuyu', |
|
| 199 | + 'rw' => 'Kinyarwanda', |
|
| 200 | + 'ky' => 'Kirghiz; Kyrgyz', |
|
| 201 | + 'kv' => 'Komi', |
|
| 202 | + 'kg' => 'Kongo', |
|
| 203 | + 'ko' => 'Korean', |
|
| 204 | + 'kj' => 'Kuanyama; Kwanyama', |
|
| 205 | + 'ku' => 'Kurdish', |
|
| 206 | + 'lo' => 'Lao', |
|
| 207 | + 'la' => 'Latin', |
|
| 208 | + 'lv' => 'Latvian', |
|
| 209 | + 'li' => 'Limburgan; Limburger; Limburgish', |
|
| 210 | + 'ln' => 'Lingala', |
|
| 211 | + 'lt' => 'Lithuanian', |
|
| 212 | + 'lb' => 'Luxembourgish; Letzeburgesch', |
|
| 213 | + 'lu' => 'Luba-Katanga', |
|
| 214 | + 'lg' => 'Ganda', |
|
| 215 | + 'mk' => 'Macedonian', |
|
| 216 | + 'mh' => 'Marshallese', |
|
| 217 | + 'ml' => 'Malayalam', |
|
| 218 | + 'mi' => 'Maori', |
|
| 219 | + 'mr' => 'Marathi', |
|
| 220 | + 'ms' => 'Malay', |
|
| 221 | + 'mg' => 'Malagasy', |
|
| 222 | + 'mt' => 'Maltese', |
|
| 223 | + 'mo' => 'Moldavian', |
|
| 224 | + 'mn' => 'Mongolian', |
|
| 225 | + 'na' => 'Nauru', |
|
| 226 | + 'nv' => 'Navajo; Navaho', |
|
| 227 | + 'nr' => 'Ndebele, South; South Ndebele', |
|
| 228 | + 'nd' => 'Ndebele, North; North Ndebele', |
|
| 229 | + 'ng' => 'Ndonga', |
|
| 230 | + 'ne' => 'Nepali', |
|
| 231 | + 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', |
|
| 232 | + 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål', |
|
| 233 | + 'no' => 'Norwegian', |
|
| 234 | + 'ny' => 'Chichewa; Chewa; Nyanja', |
|
| 235 | + 'oc' => 'Occitan, Provençal', |
|
| 236 | + 'oj' => 'Ojibwa', |
|
| 237 | + 'or' => 'Oriya', |
|
| 238 | + 'om' => 'Oromo', |
|
| 239 | + 'os' => 'Ossetian; Ossetic', |
|
| 240 | + 'pa' => 'Panjabi; Punjabi', |
|
| 241 | + 'fa' => 'Persian', |
|
| 242 | + 'pi' => 'Pali', |
|
| 243 | + 'pl' => 'Polish', |
|
| 244 | + 'pt' => 'Portuguese', |
|
| 245 | + 'ps' => 'Pushto', |
|
| 246 | + 'qu' => 'Quechua', |
|
| 247 | + 'rm' => 'Romansh', |
|
| 248 | + 'ro' => 'Romanian', |
|
| 249 | + 'rn' => 'Rundi', |
|
| 250 | + 'ru' => 'Russian', |
|
| 251 | + 'sg' => 'Sango', |
|
| 252 | + 'sa' => 'Sanskrit', |
|
| 253 | + 'sr' => 'Serbian', |
|
| 254 | + 'hr' => 'Croatian', |
|
| 255 | + 'si' => 'Sinhala; Sinhalese', |
|
| 256 | + 'sk' => 'Slovak', |
|
| 257 | + 'sl' => 'Slovenian', |
|
| 258 | + 'se' => 'Northern Sami', |
|
| 259 | + 'sm' => 'Samoan', |
|
| 260 | + 'sn' => 'Shona', |
|
| 261 | + 'sd' => 'Sindhi', |
|
| 262 | + 'so' => 'Somali', |
|
| 263 | + 'st' => 'Sotho, Southern', |
|
| 264 | + 'es' => 'Spanish; Castilian', |
|
| 265 | + 'sc' => 'Sardinian', |
|
| 266 | + 'ss' => 'Swati', |
|
| 267 | + 'su' => 'Sundanese', |
|
| 268 | + 'sw' => 'Swahili', |
|
| 269 | + 'sv' => 'Swedish', |
|
| 270 | + 'ty' => 'Tahitian', |
|
| 271 | + 'ta' => 'Tamil', |
|
| 272 | + 'tt' => 'Tatar', |
|
| 273 | + 'te' => 'Telugu', |
|
| 274 | + 'tg' => 'Tajik', |
|
| 275 | + 'tl' => 'Tagalog', |
|
| 276 | + 'th' => 'Thai', |
|
| 277 | + 'bo' => 'Tibetan', |
|
| 278 | + 'ti' => 'Tigrinya', |
|
| 279 | + 'to' => 'Tonga (Tonga Islands)', |
|
| 280 | + 'tn' => 'Tswana', |
|
| 281 | + 'ts' => 'Tsonga', |
|
| 282 | + 'tk' => 'Turkmen', |
|
| 283 | + 'tr' => 'Turkish', |
|
| 284 | + 'tw' => 'Twi', |
|
| 285 | + 'ug' => 'Uighur; Uyghur', |
|
| 286 | + 'uk' => 'Ukrainian', |
|
| 287 | + 'ur' => 'Urdu', |
|
| 288 | + 'uz' => 'Uzbek', |
|
| 289 | + 've' => 'Venda', |
|
| 290 | + 'vi' => 'Vietnamese', |
|
| 291 | + 'vo' => 'Volapük', |
|
| 292 | + 'cy' => 'Welsh', |
|
| 293 | + 'wa' => 'Walloon', |
|
| 294 | + 'wo' => 'Wolof', |
|
| 295 | + 'xh' => 'Xhosa', |
|
| 296 | + 'yi' => 'Yiddish', |
|
| 297 | + 'yo' => 'Yoruba', |
|
| 298 | + 'za' => 'Zhuang; Chuang', |
|
| 299 | + 'zu' => 'Zulu' |
|
| 300 | + ); |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Filters the language codes. |
|
| 304 | - * |
|
| 305 | - * @since MU |
|
| 306 | - * |
|
| 307 | - * @param array $lang_codes Key/value pair of language codes where key is the short version. |
|
| 308 | - * @param string $code A two-letter designation of the language. |
|
| 309 | - */ |
|
| 310 | - $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); |
|
| 302 | + /** |
|
| 303 | + * Filters the language codes. |
|
| 304 | + * |
|
| 305 | + * @since MU |
|
| 306 | + * |
|
| 307 | + * @param array $lang_codes Key/value pair of language codes where key is the short version. |
|
| 308 | + * @param string $code A two-letter designation of the language. |
|
| 309 | + */ |
|
| 310 | + $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); |
|
| 311 | 311 | |
| 312 | - return strtr( $code, $lang_codes ); |
|
| 313 | - } |
|
| 312 | + return strtr( $code, $lang_codes ); |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | 315 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * @since 3.9.0 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -85,15 +85,15 @@ discard block |
||
| 85 | 85 | public static function get_languages() { |
| 86 | 86 | |
| 87 | 87 | // Lazily load the languages. |
| 88 | - if ( null === self::$languages ) { |
|
| 88 | + if (null === self::$languages) { |
|
| 89 | 89 | |
| 90 | 90 | // Get the language names from WP's own (multisite) function. |
| 91 | - foreach ( self::$codes as $key ) { |
|
| 92 | - self::$languages[ $key ] = self::get_language_name( $key ); |
|
| 91 | + foreach (self::$codes as $key) { |
|
| 92 | + self::$languages[$key] = self::get_language_name($key); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // Sort by language name. |
| 96 | - asort( self::$languages ); |
|
| 96 | + asort(self::$languages); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | return self::$languages; |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | * @return string The language corresponding to $code if it exists. If it does not exist, |
| 110 | 110 | * then the first two letters of $code is returned. |
| 111 | 111 | */ |
| 112 | - public static function get_language_name( $code = '' ) { |
|
| 113 | - $code = strtolower( substr( $code, 0, 2 ) ); |
|
| 112 | + public static function get_language_name($code = '') { |
|
| 113 | + $code = strtolower(substr($code, 0, 2)); |
|
| 114 | 114 | $lang_codes = array( |
| 115 | 115 | 'aa' => 'Afar', |
| 116 | 116 | 'ab' => 'Abkhazian', |
@@ -307,9 +307,9 @@ discard block |
||
| 307 | 307 | * @param array $lang_codes Key/value pair of language codes where key is the short version. |
| 308 | 308 | * @param string $code A two-letter designation of the language. |
| 309 | 309 | */ |
| 310 | - $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); |
|
| 310 | + $lang_codes = apply_filters('lang_codes', $lang_codes, $code); |
|
| 311 | 311 | |
| 312 | - return strtr( $code, $lang_codes ); |
|
| 312 | + return strtr($code, $lang_codes); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | } |
@@ -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,729 +23,729 @@ 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 publisher entity post ID option name. |
|
| 63 | - * |
|
| 64 | - * @since 3.9.0 |
|
| 65 | - */ |
|
| 66 | - const PUBLISHER_ID = 'publisher_id'; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * The dataset URI option name |
|
| 70 | - * |
|
| 71 | - * @since 3.10.0 |
|
| 72 | - */ |
|
| 73 | - const DATASET_URI = 'redlink_dataset_uri'; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * The link by default option name. |
|
| 77 | - * |
|
| 78 | - * @since 3.11.0 |
|
| 79 | - */ |
|
| 80 | - const LINK_BY_DEFAULT = 'link_by_default'; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * The analytics enable option. |
|
| 84 | - * |
|
| 85 | - * @since 3.21.0 |
|
| 86 | - */ |
|
| 87 | - const ANALYTICS_ENABLE = 'analytics_enable'; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * The analytics entity uri dimension option. |
|
| 91 | - * |
|
| 92 | - * @since 3.21.0 |
|
| 93 | - */ |
|
| 94 | - const ANALYTICS_ENTITY_URI_DIMENSION = 'analytics_entity_uri_dimension'; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * The analytics entity type dimension option. |
|
| 98 | - * |
|
| 99 | - * @since 3.21.0 |
|
| 100 | - */ |
|
| 101 | - const ANALYTICS_ENTITY_TYPE_DIMENSION = 'analytics_entity_type_dimension'; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * The user preferences about sharing data option. |
|
| 105 | - * |
|
| 106 | - * @since 3.19.0 |
|
| 107 | - */ |
|
| 108 | - const SEND_DIAGNOSTIC = 'send_diagnostic'; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * The package type configuration key. |
|
| 112 | - * |
|
| 113 | - * @since 3.20.0 |
|
| 114 | - */ |
|
| 115 | - const PACKAGE_TYPE = 'package_type'; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * The {@link Wordlift_Log_Service} instance. |
|
| 119 | - * |
|
| 120 | - * @since 3.16.0 |
|
| 121 | - * |
|
| 122 | - * @var \Wordlift_Log_Service $log The {@link Wordlift_Log_Service} instance. |
|
| 123 | - */ |
|
| 124 | - private $log; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * The Wordlift_Configuration_Service's singleton instance. |
|
| 128 | - * |
|
| 129 | - * @since 3.6.0 |
|
| 130 | - * |
|
| 131 | - * @access private |
|
| 132 | - * @var \Wordlift_Configuration_Service $instance Wordlift_Configuration_Service's singleton instance. |
|
| 133 | - */ |
|
| 134 | - private static $instance; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Create a Wordlift_Configuration_Service's instance. |
|
| 138 | - * |
|
| 139 | - * @since 3.6.0 |
|
| 140 | - */ |
|
| 141 | - public function __construct() { |
|
| 142 | - |
|
| 143 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 144 | - |
|
| 145 | - self::$instance = $this; |
|
| 146 | - |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Get the singleton instance. |
|
| 151 | - * |
|
| 152 | - * @return \Wordlift_Configuration_Service |
|
| 153 | - * @since 3.6.0 |
|
| 154 | - * |
|
| 155 | - */ |
|
| 156 | - public static function get_instance() { |
|
| 157 | - |
|
| 158 | - return self::$instance; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Get a configuration given the option name and a key. The option value is |
|
| 163 | - * expected to be an array. |
|
| 164 | - * |
|
| 165 | - * @param string $option The option name. |
|
| 166 | - * @param string $key A key in the option value array. |
|
| 167 | - * @param string $default The default value in case the key is not found (by default an empty string). |
|
| 168 | - * |
|
| 169 | - * @return mixed The configuration value or the default value if not found. |
|
| 170 | - * @since 3.6.0 |
|
| 171 | - * |
|
| 172 | - */ |
|
| 173 | - private function get( $option, $key, $default = '' ) { |
|
| 174 | - |
|
| 175 | - $options = get_option( $option, array() ); |
|
| 176 | - |
|
| 177 | - return isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Set a configuration parameter. |
|
| 182 | - * |
|
| 183 | - * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. |
|
| 184 | - * @param string $key The value key. |
|
| 185 | - * @param mixed $value The value. |
|
| 186 | - * |
|
| 187 | - * @since 3.9.0 |
|
| 188 | - * |
|
| 189 | - */ |
|
| 190 | - private function set( $option, $key, $value ) { |
|
| 191 | - |
|
| 192 | - $values = get_option( $option ); |
|
| 193 | - $values = isset( $values ) ? $values : array(); |
|
| 194 | - $values[ $key ] = $value; |
|
| 195 | - update_option( $option, $values ); |
|
| 196 | - |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Get the entity base path, by default 'entity'. |
|
| 201 | - * |
|
| 202 | - * @return string The entity base path. |
|
| 203 | - * @since 3.6.0 |
|
| 204 | - * |
|
| 205 | - */ |
|
| 206 | - public function get_entity_base_path() { |
|
| 207 | - |
|
| 208 | - return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' ); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * Get the entity base path. |
|
| 213 | - * |
|
| 214 | - * @param string $value The entity base path. |
|
| 215 | - * |
|
| 216 | - * @since 3.9.0 |
|
| 217 | - * |
|
| 218 | - */ |
|
| 219 | - public function set_entity_base_path( $value ) { |
|
| 220 | - |
|
| 221 | - $this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value ); |
|
| 222 | - |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Whether the installation skip wizard should be skipped. |
|
| 227 | - * |
|
| 228 | - * @return bool True if it should be skipped otherwise false. |
|
| 229 | - * @since 3.9.0 |
|
| 230 | - * |
|
| 231 | - */ |
|
| 232 | - public function is_skip_wizard() { |
|
| 233 | - |
|
| 234 | - return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false ); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Set the skip wizard parameter. |
|
| 239 | - * |
|
| 240 | - * @param bool $value True to skip the wizard. We expect a boolean value. |
|
| 241 | - * |
|
| 242 | - * @since 3.9.0 |
|
| 243 | - * |
|
| 244 | - */ |
|
| 245 | - public function set_skip_wizard( $value ) { |
|
| 246 | - |
|
| 247 | - $this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value ); |
|
| 248 | - |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Get WordLift's key. |
|
| 253 | - * |
|
| 254 | - * @return string WordLift's key or an empty string if not set. |
|
| 255 | - * @since 3.9.0 |
|
| 256 | - * |
|
| 257 | - */ |
|
| 258 | - public function get_key() { |
|
| 259 | - |
|
| 260 | - return $this->get( 'wl_general_settings', self::KEY, '' ); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Set WordLift's key. |
|
| 265 | - * |
|
| 266 | - * @param string $value WordLift's key. |
|
| 267 | - * |
|
| 268 | - * @since 3.9.0 |
|
| 269 | - * |
|
| 270 | - */ |
|
| 271 | - public function set_key( $value ) { |
|
| 272 | - |
|
| 273 | - $this->set( 'wl_general_settings', self::KEY, $value ); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Get WordLift's configured language, by default 'en'. |
|
| 278 | - * |
|
| 279 | - * Note that WordLift's language is used when writing strings to the Linked Data dataset, not for the analysis. |
|
| 280 | - * |
|
| 281 | - * @return string WordLift's configured language code ('en' by default). |
|
| 282 | - * @since 3.9.0 |
|
| 283 | - * |
|
| 284 | - */ |
|
| 285 | - public function get_language_code() { |
|
| 286 | - |
|
| 287 | - $language = get_bloginfo('language'); |
|
| 288 | - if ( ! $language ) { |
|
| 289 | - return 'en'; |
|
| 290 | - } |
|
| 291 | - return substr( $language, 0, 2); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * @deprecated As of 3.32.7 this below method has no effect on setting the language, we use the |
|
| 296 | - * language code form wordpress directly. |
|
| 297 | - * |
|
| 298 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1466 |
|
| 299 | - * |
|
| 300 | - * Set WordLift's language code, used when storing strings to the Linked Data dataset. |
|
| 301 | - * |
|
| 302 | - * @param string $value WordLift's language code. |
|
| 303 | - * |
|
| 304 | - * @since 3.9.0 |
|
| 305 | - * |
|
| 306 | - */ |
|
| 307 | - public function set_language_code( $value ) { |
|
| 308 | - |
|
| 309 | - $this->set( 'wl_general_settings', self::LANGUAGE, $value ); |
|
| 310 | - |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Set the user preferences about sharing diagnostic with us. |
|
| 315 | - * |
|
| 316 | - * @param string $value The user preferences(yes/no). |
|
| 317 | - * |
|
| 318 | - * @since 3.19.0 |
|
| 319 | - * |
|
| 320 | - */ |
|
| 321 | - public function set_diagnostic_preferences( $value ) { |
|
| 322 | - |
|
| 323 | - $this->set( 'wl_general_settings', self::SEND_DIAGNOSTIC, $value ); |
|
| 324 | - |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * Get the user preferences about sharing diagnostic. |
|
| 329 | - * |
|
| 330 | - * @since 3.19.0 |
|
| 331 | - */ |
|
| 332 | - public function get_diagnostic_preferences() { |
|
| 333 | - |
|
| 334 | - return $this->get( 'wl_general_settings', self::SEND_DIAGNOSTIC, 'no' ); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Get WordLift's configured country code, by default 'us'. |
|
| 339 | - * |
|
| 340 | - * @return string WordLift's configured country code ('us' by default). |
|
| 341 | - * @since 3.18.0 |
|
| 342 | - * |
|
| 343 | - */ |
|
| 344 | - public function get_country_code() { |
|
| 345 | - |
|
| 346 | - return $this->get( 'wl_general_settings', self::COUNTRY_CODE, 'us' ); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Set WordLift's country code. |
|
| 351 | - * |
|
| 352 | - * @param string $value WordLift's country code. |
|
| 353 | - * |
|
| 354 | - * @since 3.18.0 |
|
| 355 | - * |
|
| 356 | - */ |
|
| 357 | - public function set_country_code( $value ) { |
|
| 358 | - |
|
| 359 | - $this->set( 'wl_general_settings', self::COUNTRY_CODE, $value ); |
|
| 360 | - |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Get the publisher entity post id. |
|
| 365 | - * |
|
| 366 | - * The publisher entity post id points to an entity post which contains the data for the publisher used in schema.org |
|
| 367 | - * Article markup. |
|
| 368 | - * |
|
| 369 | - * @return int|NULL The publisher entity post id or NULL if not set. |
|
| 370 | - * @since 3.9.0 |
|
| 371 | - * |
|
| 372 | - */ |
|
| 373 | - public function get_publisher_id() { |
|
| 374 | - |
|
| 375 | - return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null ); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * Set the publisher entity post id. |
|
| 380 | - * |
|
| 381 | - * @param int $value The publisher entity post id. |
|
| 382 | - * |
|
| 383 | - * @since 3.9.0 |
|
| 384 | - * |
|
| 385 | - */ |
|
| 386 | - public function set_publisher_id( $value ) { |
|
| 387 | - |
|
| 388 | - $this->set( 'wl_general_settings', self::PUBLISHER_ID, $value ); |
|
| 389 | - |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Get the dataset URI. |
|
| 394 | - * |
|
| 395 | - * @return string The dataset URI or an empty string if not set. |
|
| 396 | - * @since 3.10.0 |
|
| 397 | - * @since 3.27.7 Always return null if `wl_features__enable__dataset` is disabled. |
|
| 398 | - * |
|
| 399 | - */ |
|
| 400 | - public function get_dataset_uri() { |
|
| 401 | - |
|
| 402 | - if ( apply_filters( 'wl_features__enable__dataset', true ) ) { |
|
| 403 | - return $this->get( 'wl_advanced_settings', self::DATASET_URI, null ); |
|
| 404 | - } else { |
|
| 405 | - return null; |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Set the dataset URI. |
|
| 411 | - * |
|
| 412 | - * @param string $value The dataset URI. |
|
| 413 | - * |
|
| 414 | - * @since 3.10.0 |
|
| 415 | - * |
|
| 416 | - */ |
|
| 417 | - public function set_dataset_uri( $value ) { |
|
| 418 | - |
|
| 419 | - $this->set( 'wl_advanced_settings', self::DATASET_URI, $value ); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Get the package type. |
|
| 424 | - * |
|
| 425 | - * @return string The package type or an empty string if not set. |
|
| 426 | - * @since 3.20.0 |
|
| 427 | - * |
|
| 428 | - */ |
|
| 429 | - public function get_package_type() { |
|
| 430 | - |
|
| 431 | - return $this->get( 'wl_advanced_settings', self::PACKAGE_TYPE, null ); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Set the package type. |
|
| 436 | - * |
|
| 437 | - * @param string $value The package type. |
|
| 438 | - * |
|
| 439 | - * @since 3.20.0 |
|
| 440 | - * |
|
| 441 | - */ |
|
| 442 | - public function set_package_type( $value ) { |
|
| 443 | - $this->set( 'wl_advanced_settings', self::PACKAGE_TYPE, $value ); |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * Intercept the change of the WordLift key in order to set the dataset URI. |
|
| 448 | - * |
|
| 449 | - * |
|
| 450 | - * @since 3.20.0 as of #761, we save settings every time a key is set, not only when the key changes, so to |
|
| 451 | - * store the configuration parameters such as country or language. |
|
| 452 | - * @since 3.11.0 |
|
| 453 | - * |
|
| 454 | - * @see https://github.com/insideout10/wordlift-plugin/issues/761 |
|
| 455 | - * |
|
| 456 | - * @param array $old_value The old settings. |
|
| 457 | - * @param array $new_value The new settings. |
|
| 458 | - */ |
|
| 459 | - public function update_key( $old_value, $new_value ) { |
|
| 460 | - |
|
| 461 | - // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed. |
|
| 462 | - // $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 463 | - $new_key = isset( $new_value['key'] ) ? $new_value['key'] : ''; |
|
| 464 | - |
|
| 465 | - // If the key hasn't changed, don't do anything. |
|
| 466 | - // WARN The 'update_option' hook is fired only if the new and old value are not equal. |
|
| 467 | - // if ( $old_key === $new_key ) { |
|
| 468 | - // return; |
|
| 469 | - // } |
|
| 470 | - |
|
| 471 | - // If the key is empty, empty the dataset URI. |
|
| 472 | - if ( '' === $new_key ) { |
|
| 473 | - $this->set_dataset_uri( '' ); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - // make the request to the remote server. |
|
| 477 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 478 | - |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * Handle retrieving the dataset uri from the remote server. |
|
| 483 | - * |
|
| 484 | - * If a valid dataset uri is returned it is stored in the appropriate option, |
|
| 485 | - * otherwise the option is set to empty string. |
|
| 486 | - * |
|
| 487 | - * @param string $key The key to be used. |
|
| 488 | - * |
|
| 489 | - * @since 3.12.0 |
|
| 490 | - * |
|
| 491 | - * @since 3.17.0 send the site URL and get the dataset URI. |
|
| 492 | - */ |
|
| 493 | - public function get_remote_dataset_uri( $key ) { |
|
| 494 | - |
|
| 495 | - $this->log->trace( 'Getting the remote dataset URI and package type...' ); |
|
| 496 | - |
|
| 497 | - if ( empty( $key ) ) { |
|
| 498 | - $this->log->warn( 'Key set to empty value.' ); |
|
| 499 | - |
|
| 500 | - $this->set_dataset_uri( '' ); |
|
| 501 | - $this->set_package_type( null ); |
|
| 502 | - |
|
| 503 | - return; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * Allow 3rd parties to change the site_url. |
|
| 508 | - * |
|
| 509 | - * @param string $site_url The site url. |
|
| 510 | - * |
|
| 511 | - * @see https://github.com/insideout10/wordlift-plugin/issues/850 |
|
| 512 | - * |
|
| 513 | - * @since 3.20.0 |
|
| 514 | - * |
|
| 515 | - */ |
|
| 516 | - $home_url = get_option( 'home' ); |
|
| 517 | - $site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) ); |
|
| 518 | - |
|
| 519 | - // Build the URL. |
|
| 520 | - $url = '/accounts' |
|
| 521 | - . '?key=' . rawurlencode( $key ) |
|
| 522 | - . '&url=' . rawurlencode( $site_url ) |
|
| 523 | - . '&country=' . $this->get_country_code() |
|
| 524 | - . '&language=' . $this->get_language_code(); |
|
| 525 | - |
|
| 526 | - $api_service = Default_Api_Service::get_instance(); |
|
| 527 | - /** |
|
| 528 | - * @since 3.27.7.1 |
|
| 529 | - * The Key should be passed to headers, otherwise api would return null. |
|
| 530 | - */ |
|
| 531 | - $headers = array( |
|
| 532 | - 'Authorization' => "Key $key", |
|
| 533 | - ); |
|
| 534 | - $response = $api_service->request( 'PUT', $url, $headers )->get_response(); |
|
| 535 | - |
|
| 536 | - // The response is an error. |
|
| 537 | - if ( is_wp_error( $response ) ) { |
|
| 538 | - $this->log->error( 'An error occurred setting the dataset URI: ' . $response->get_error_message() ); |
|
| 539 | - |
|
| 540 | - $this->set_dataset_uri( '' ); |
|
| 541 | - $this->set_package_type( null ); |
|
| 542 | - |
|
| 543 | - return; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - // The response is not OK. |
|
| 547 | - if ( ! is_array( $response ) || 200 !== (int) $response['response']['code'] ) { |
|
| 548 | - $base_url = $api_service->get_base_url(); |
|
| 549 | - |
|
| 550 | - if ( ! is_array( $response ) ) { |
|
| 551 | - $this->log->error( "Unexpected response when opening URL $base_url$url: " . var_export( $response, true ) ); |
|
| 552 | - } else { |
|
| 553 | - $this->log->error( "Unexpected status code when opening URL $base_url$url: " . $response['response']['code'] . "\n" . var_export( $response, true ) ); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - |
|
| 557 | - $this->set_dataset_uri( '' ); |
|
| 558 | - $this->set_package_type( null ); |
|
| 559 | - |
|
| 560 | - return; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - /* |
|
| 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 publisher entity post ID option name. |
|
| 63 | + * |
|
| 64 | + * @since 3.9.0 |
|
| 65 | + */ |
|
| 66 | + const PUBLISHER_ID = 'publisher_id'; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * The dataset URI option name |
|
| 70 | + * |
|
| 71 | + * @since 3.10.0 |
|
| 72 | + */ |
|
| 73 | + const DATASET_URI = 'redlink_dataset_uri'; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * The link by default option name. |
|
| 77 | + * |
|
| 78 | + * @since 3.11.0 |
|
| 79 | + */ |
|
| 80 | + const LINK_BY_DEFAULT = 'link_by_default'; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * The analytics enable option. |
|
| 84 | + * |
|
| 85 | + * @since 3.21.0 |
|
| 86 | + */ |
|
| 87 | + const ANALYTICS_ENABLE = 'analytics_enable'; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * The analytics entity uri dimension option. |
|
| 91 | + * |
|
| 92 | + * @since 3.21.0 |
|
| 93 | + */ |
|
| 94 | + const ANALYTICS_ENTITY_URI_DIMENSION = 'analytics_entity_uri_dimension'; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * The analytics entity type dimension option. |
|
| 98 | + * |
|
| 99 | + * @since 3.21.0 |
|
| 100 | + */ |
|
| 101 | + const ANALYTICS_ENTITY_TYPE_DIMENSION = 'analytics_entity_type_dimension'; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * The user preferences about sharing data option. |
|
| 105 | + * |
|
| 106 | + * @since 3.19.0 |
|
| 107 | + */ |
|
| 108 | + const SEND_DIAGNOSTIC = 'send_diagnostic'; |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * The package type configuration key. |
|
| 112 | + * |
|
| 113 | + * @since 3.20.0 |
|
| 114 | + */ |
|
| 115 | + const PACKAGE_TYPE = 'package_type'; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * The {@link Wordlift_Log_Service} instance. |
|
| 119 | + * |
|
| 120 | + * @since 3.16.0 |
|
| 121 | + * |
|
| 122 | + * @var \Wordlift_Log_Service $log The {@link Wordlift_Log_Service} instance. |
|
| 123 | + */ |
|
| 124 | + private $log; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * The Wordlift_Configuration_Service's singleton instance. |
|
| 128 | + * |
|
| 129 | + * @since 3.6.0 |
|
| 130 | + * |
|
| 131 | + * @access private |
|
| 132 | + * @var \Wordlift_Configuration_Service $instance Wordlift_Configuration_Service's singleton instance. |
|
| 133 | + */ |
|
| 134 | + private static $instance; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Create a Wordlift_Configuration_Service's instance. |
|
| 138 | + * |
|
| 139 | + * @since 3.6.0 |
|
| 140 | + */ |
|
| 141 | + public function __construct() { |
|
| 142 | + |
|
| 143 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 144 | + |
|
| 145 | + self::$instance = $this; |
|
| 146 | + |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Get the singleton instance. |
|
| 151 | + * |
|
| 152 | + * @return \Wordlift_Configuration_Service |
|
| 153 | + * @since 3.6.0 |
|
| 154 | + * |
|
| 155 | + */ |
|
| 156 | + public static function get_instance() { |
|
| 157 | + |
|
| 158 | + return self::$instance; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Get a configuration given the option name and a key. The option value is |
|
| 163 | + * expected to be an array. |
|
| 164 | + * |
|
| 165 | + * @param string $option The option name. |
|
| 166 | + * @param string $key A key in the option value array. |
|
| 167 | + * @param string $default The default value in case the key is not found (by default an empty string). |
|
| 168 | + * |
|
| 169 | + * @return mixed The configuration value or the default value if not found. |
|
| 170 | + * @since 3.6.0 |
|
| 171 | + * |
|
| 172 | + */ |
|
| 173 | + private function get( $option, $key, $default = '' ) { |
|
| 174 | + |
|
| 175 | + $options = get_option( $option, array() ); |
|
| 176 | + |
|
| 177 | + return isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Set a configuration parameter. |
|
| 182 | + * |
|
| 183 | + * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. |
|
| 184 | + * @param string $key The value key. |
|
| 185 | + * @param mixed $value The value. |
|
| 186 | + * |
|
| 187 | + * @since 3.9.0 |
|
| 188 | + * |
|
| 189 | + */ |
|
| 190 | + private function set( $option, $key, $value ) { |
|
| 191 | + |
|
| 192 | + $values = get_option( $option ); |
|
| 193 | + $values = isset( $values ) ? $values : array(); |
|
| 194 | + $values[ $key ] = $value; |
|
| 195 | + update_option( $option, $values ); |
|
| 196 | + |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Get the entity base path, by default 'entity'. |
|
| 201 | + * |
|
| 202 | + * @return string The entity base path. |
|
| 203 | + * @since 3.6.0 |
|
| 204 | + * |
|
| 205 | + */ |
|
| 206 | + public function get_entity_base_path() { |
|
| 207 | + |
|
| 208 | + return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' ); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * Get the entity base path. |
|
| 213 | + * |
|
| 214 | + * @param string $value The entity base path. |
|
| 215 | + * |
|
| 216 | + * @since 3.9.0 |
|
| 217 | + * |
|
| 218 | + */ |
|
| 219 | + public function set_entity_base_path( $value ) { |
|
| 220 | + |
|
| 221 | + $this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value ); |
|
| 222 | + |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Whether the installation skip wizard should be skipped. |
|
| 227 | + * |
|
| 228 | + * @return bool True if it should be skipped otherwise false. |
|
| 229 | + * @since 3.9.0 |
|
| 230 | + * |
|
| 231 | + */ |
|
| 232 | + public function is_skip_wizard() { |
|
| 233 | + |
|
| 234 | + return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false ); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Set the skip wizard parameter. |
|
| 239 | + * |
|
| 240 | + * @param bool $value True to skip the wizard. We expect a boolean value. |
|
| 241 | + * |
|
| 242 | + * @since 3.9.0 |
|
| 243 | + * |
|
| 244 | + */ |
|
| 245 | + public function set_skip_wizard( $value ) { |
|
| 246 | + |
|
| 247 | + $this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value ); |
|
| 248 | + |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Get WordLift's key. |
|
| 253 | + * |
|
| 254 | + * @return string WordLift's key or an empty string if not set. |
|
| 255 | + * @since 3.9.0 |
|
| 256 | + * |
|
| 257 | + */ |
|
| 258 | + public function get_key() { |
|
| 259 | + |
|
| 260 | + return $this->get( 'wl_general_settings', self::KEY, '' ); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Set WordLift's key. |
|
| 265 | + * |
|
| 266 | + * @param string $value WordLift's key. |
|
| 267 | + * |
|
| 268 | + * @since 3.9.0 |
|
| 269 | + * |
|
| 270 | + */ |
|
| 271 | + public function set_key( $value ) { |
|
| 272 | + |
|
| 273 | + $this->set( 'wl_general_settings', self::KEY, $value ); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Get WordLift's configured language, by default 'en'. |
|
| 278 | + * |
|
| 279 | + * Note that WordLift's language is used when writing strings to the Linked Data dataset, not for the analysis. |
|
| 280 | + * |
|
| 281 | + * @return string WordLift's configured language code ('en' by default). |
|
| 282 | + * @since 3.9.0 |
|
| 283 | + * |
|
| 284 | + */ |
|
| 285 | + public function get_language_code() { |
|
| 286 | + |
|
| 287 | + $language = get_bloginfo('language'); |
|
| 288 | + if ( ! $language ) { |
|
| 289 | + return 'en'; |
|
| 290 | + } |
|
| 291 | + return substr( $language, 0, 2); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * @deprecated As of 3.32.7 this below method has no effect on setting the language, we use the |
|
| 296 | + * language code form wordpress directly. |
|
| 297 | + * |
|
| 298 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1466 |
|
| 299 | + * |
|
| 300 | + * Set WordLift's language code, used when storing strings to the Linked Data dataset. |
|
| 301 | + * |
|
| 302 | + * @param string $value WordLift's language code. |
|
| 303 | + * |
|
| 304 | + * @since 3.9.0 |
|
| 305 | + * |
|
| 306 | + */ |
|
| 307 | + public function set_language_code( $value ) { |
|
| 308 | + |
|
| 309 | + $this->set( 'wl_general_settings', self::LANGUAGE, $value ); |
|
| 310 | + |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Set the user preferences about sharing diagnostic with us. |
|
| 315 | + * |
|
| 316 | + * @param string $value The user preferences(yes/no). |
|
| 317 | + * |
|
| 318 | + * @since 3.19.0 |
|
| 319 | + * |
|
| 320 | + */ |
|
| 321 | + public function set_diagnostic_preferences( $value ) { |
|
| 322 | + |
|
| 323 | + $this->set( 'wl_general_settings', self::SEND_DIAGNOSTIC, $value ); |
|
| 324 | + |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * Get the user preferences about sharing diagnostic. |
|
| 329 | + * |
|
| 330 | + * @since 3.19.0 |
|
| 331 | + */ |
|
| 332 | + public function get_diagnostic_preferences() { |
|
| 333 | + |
|
| 334 | + return $this->get( 'wl_general_settings', self::SEND_DIAGNOSTIC, 'no' ); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Get WordLift's configured country code, by default 'us'. |
|
| 339 | + * |
|
| 340 | + * @return string WordLift's configured country code ('us' by default). |
|
| 341 | + * @since 3.18.0 |
|
| 342 | + * |
|
| 343 | + */ |
|
| 344 | + public function get_country_code() { |
|
| 345 | + |
|
| 346 | + return $this->get( 'wl_general_settings', self::COUNTRY_CODE, 'us' ); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Set WordLift's country code. |
|
| 351 | + * |
|
| 352 | + * @param string $value WordLift's country code. |
|
| 353 | + * |
|
| 354 | + * @since 3.18.0 |
|
| 355 | + * |
|
| 356 | + */ |
|
| 357 | + public function set_country_code( $value ) { |
|
| 358 | + |
|
| 359 | + $this->set( 'wl_general_settings', self::COUNTRY_CODE, $value ); |
|
| 360 | + |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Get the publisher entity post id. |
|
| 365 | + * |
|
| 366 | + * The publisher entity post id points to an entity post which contains the data for the publisher used in schema.org |
|
| 367 | + * Article markup. |
|
| 368 | + * |
|
| 369 | + * @return int|NULL The publisher entity post id or NULL if not set. |
|
| 370 | + * @since 3.9.0 |
|
| 371 | + * |
|
| 372 | + */ |
|
| 373 | + public function get_publisher_id() { |
|
| 374 | + |
|
| 375 | + return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null ); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * Set the publisher entity post id. |
|
| 380 | + * |
|
| 381 | + * @param int $value The publisher entity post id. |
|
| 382 | + * |
|
| 383 | + * @since 3.9.0 |
|
| 384 | + * |
|
| 385 | + */ |
|
| 386 | + public function set_publisher_id( $value ) { |
|
| 387 | + |
|
| 388 | + $this->set( 'wl_general_settings', self::PUBLISHER_ID, $value ); |
|
| 389 | + |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Get the dataset URI. |
|
| 394 | + * |
|
| 395 | + * @return string The dataset URI or an empty string if not set. |
|
| 396 | + * @since 3.10.0 |
|
| 397 | + * @since 3.27.7 Always return null if `wl_features__enable__dataset` is disabled. |
|
| 398 | + * |
|
| 399 | + */ |
|
| 400 | + public function get_dataset_uri() { |
|
| 401 | + |
|
| 402 | + if ( apply_filters( 'wl_features__enable__dataset', true ) ) { |
|
| 403 | + return $this->get( 'wl_advanced_settings', self::DATASET_URI, null ); |
|
| 404 | + } else { |
|
| 405 | + return null; |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Set the dataset URI. |
|
| 411 | + * |
|
| 412 | + * @param string $value The dataset URI. |
|
| 413 | + * |
|
| 414 | + * @since 3.10.0 |
|
| 415 | + * |
|
| 416 | + */ |
|
| 417 | + public function set_dataset_uri( $value ) { |
|
| 418 | + |
|
| 419 | + $this->set( 'wl_advanced_settings', self::DATASET_URI, $value ); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Get the package type. |
|
| 424 | + * |
|
| 425 | + * @return string The package type or an empty string if not set. |
|
| 426 | + * @since 3.20.0 |
|
| 427 | + * |
|
| 428 | + */ |
|
| 429 | + public function get_package_type() { |
|
| 430 | + |
|
| 431 | + return $this->get( 'wl_advanced_settings', self::PACKAGE_TYPE, null ); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Set the package type. |
|
| 436 | + * |
|
| 437 | + * @param string $value The package type. |
|
| 438 | + * |
|
| 439 | + * @since 3.20.0 |
|
| 440 | + * |
|
| 441 | + */ |
|
| 442 | + public function set_package_type( $value ) { |
|
| 443 | + $this->set( 'wl_advanced_settings', self::PACKAGE_TYPE, $value ); |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * Intercept the change of the WordLift key in order to set the dataset URI. |
|
| 448 | + * |
|
| 449 | + * |
|
| 450 | + * @since 3.20.0 as of #761, we save settings every time a key is set, not only when the key changes, so to |
|
| 451 | + * store the configuration parameters such as country or language. |
|
| 452 | + * @since 3.11.0 |
|
| 453 | + * |
|
| 454 | + * @see https://github.com/insideout10/wordlift-plugin/issues/761 |
|
| 455 | + * |
|
| 456 | + * @param array $old_value The old settings. |
|
| 457 | + * @param array $new_value The new settings. |
|
| 458 | + */ |
|
| 459 | + public function update_key( $old_value, $new_value ) { |
|
| 460 | + |
|
| 461 | + // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed. |
|
| 462 | + // $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 463 | + $new_key = isset( $new_value['key'] ) ? $new_value['key'] : ''; |
|
| 464 | + |
|
| 465 | + // If the key hasn't changed, don't do anything. |
|
| 466 | + // WARN The 'update_option' hook is fired only if the new and old value are not equal. |
|
| 467 | + // if ( $old_key === $new_key ) { |
|
| 468 | + // return; |
|
| 469 | + // } |
|
| 470 | + |
|
| 471 | + // If the key is empty, empty the dataset URI. |
|
| 472 | + if ( '' === $new_key ) { |
|
| 473 | + $this->set_dataset_uri( '' ); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + // make the request to the remote server. |
|
| 477 | + $this->get_remote_dataset_uri( $new_key ); |
|
| 478 | + |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * Handle retrieving the dataset uri from the remote server. |
|
| 483 | + * |
|
| 484 | + * If a valid dataset uri is returned it is stored in the appropriate option, |
|
| 485 | + * otherwise the option is set to empty string. |
|
| 486 | + * |
|
| 487 | + * @param string $key The key to be used. |
|
| 488 | + * |
|
| 489 | + * @since 3.12.0 |
|
| 490 | + * |
|
| 491 | + * @since 3.17.0 send the site URL and get the dataset URI. |
|
| 492 | + */ |
|
| 493 | + public function get_remote_dataset_uri( $key ) { |
|
| 494 | + |
|
| 495 | + $this->log->trace( 'Getting the remote dataset URI and package type...' ); |
|
| 496 | + |
|
| 497 | + if ( empty( $key ) ) { |
|
| 498 | + $this->log->warn( 'Key set to empty value.' ); |
|
| 499 | + |
|
| 500 | + $this->set_dataset_uri( '' ); |
|
| 501 | + $this->set_package_type( null ); |
|
| 502 | + |
|
| 503 | + return; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Allow 3rd parties to change the site_url. |
|
| 508 | + * |
|
| 509 | + * @param string $site_url The site url. |
|
| 510 | + * |
|
| 511 | + * @see https://github.com/insideout10/wordlift-plugin/issues/850 |
|
| 512 | + * |
|
| 513 | + * @since 3.20.0 |
|
| 514 | + * |
|
| 515 | + */ |
|
| 516 | + $home_url = get_option( 'home' ); |
|
| 517 | + $site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) ); |
|
| 518 | + |
|
| 519 | + // Build the URL. |
|
| 520 | + $url = '/accounts' |
|
| 521 | + . '?key=' . rawurlencode( $key ) |
|
| 522 | + . '&url=' . rawurlencode( $site_url ) |
|
| 523 | + . '&country=' . $this->get_country_code() |
|
| 524 | + . '&language=' . $this->get_language_code(); |
|
| 525 | + |
|
| 526 | + $api_service = Default_Api_Service::get_instance(); |
|
| 527 | + /** |
|
| 528 | + * @since 3.27.7.1 |
|
| 529 | + * The Key should be passed to headers, otherwise api would return null. |
|
| 530 | + */ |
|
| 531 | + $headers = array( |
|
| 532 | + 'Authorization' => "Key $key", |
|
| 533 | + ); |
|
| 534 | + $response = $api_service->request( 'PUT', $url, $headers )->get_response(); |
|
| 535 | + |
|
| 536 | + // The response is an error. |
|
| 537 | + if ( is_wp_error( $response ) ) { |
|
| 538 | + $this->log->error( 'An error occurred setting the dataset URI: ' . $response->get_error_message() ); |
|
| 539 | + |
|
| 540 | + $this->set_dataset_uri( '' ); |
|
| 541 | + $this->set_package_type( null ); |
|
| 542 | + |
|
| 543 | + return; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + // The response is not OK. |
|
| 547 | + if ( ! is_array( $response ) || 200 !== (int) $response['response']['code'] ) { |
|
| 548 | + $base_url = $api_service->get_base_url(); |
|
| 549 | + |
|
| 550 | + if ( ! is_array( $response ) ) { |
|
| 551 | + $this->log->error( "Unexpected response when opening URL $base_url$url: " . var_export( $response, true ) ); |
|
| 552 | + } else { |
|
| 553 | + $this->log->error( "Unexpected status code when opening URL $base_url$url: " . $response['response']['code'] . "\n" . var_export( $response, true ) ); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + |
|
| 557 | + $this->set_dataset_uri( '' ); |
|
| 558 | + $this->set_package_type( null ); |
|
| 559 | + |
|
| 560 | + return; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + /* |
|
| 564 | 564 | * We also store the package type. |
| 565 | 565 | * |
| 566 | 566 | * @since 3.20.0 |
| 567 | 567 | */ |
| 568 | - $json = json_decode( $response['body'] ); |
|
| 569 | - /** |
|
| 570 | - * @since 3.27.7 |
|
| 571 | - * Remove the trailing slash returned from the new platform api. |
|
| 572 | - */ |
|
| 573 | - $dataset_uri = untrailingslashit( $json->datasetURI ); |
|
| 574 | - $package_type = isset( $json->packageType ) ? $json->packageType : null; |
|
| 575 | - |
|
| 576 | - $this->log->info( "Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..." ); |
|
| 577 | - |
|
| 578 | - $this->set_dataset_uri( $dataset_uri ); |
|
| 579 | - $this->set_package_type( $package_type ); |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * Handle the edge case where a user submits the same key again |
|
| 584 | - * when he does not have the dataset uri to regain it. |
|
| 585 | - * |
|
| 586 | - * This can not be handled in the normal option update hook because |
|
| 587 | - * it is not being triggered when the save value equals to the one already |
|
| 588 | - * in the DB. |
|
| 589 | - * |
|
| 590 | - * @param mixed $value The new, unserialized option value. |
|
| 591 | - * @param mixed $old_value The old option value. |
|
| 592 | - * |
|
| 593 | - * @return mixed The same value in the $value parameter |
|
| 594 | - * @since 3.12.0 |
|
| 595 | - * |
|
| 596 | - */ |
|
| 597 | - function maybe_update_dataset_uri( $value, $old_value ) { |
|
| 598 | - |
|
| 599 | - // Check the old key value and the new one. Here we're only handling the |
|
| 600 | - // case where the key hasn't changed and the dataset URI isn't set. The |
|
| 601 | - // other case, i.e. a new key is inserted, is handled at `update_key`. |
|
| 602 | - $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 603 | - $new_key = isset( $value['key'] ) ? $value['key'] : ''; |
|
| 604 | - |
|
| 605 | - $dataset_uri = $this->get_dataset_uri(); |
|
| 606 | - |
|
| 607 | - if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) { |
|
| 608 | - |
|
| 609 | - // make the request to the remote server to try to get the dataset uri. |
|
| 610 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - return $value; |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * Get the API URI to retrieve the dataset URI using the WordLift Key. |
|
| 618 | - * |
|
| 619 | - * @param string $key The WordLift key to use. |
|
| 620 | - * |
|
| 621 | - * @return string The API URI. |
|
| 622 | - * @since 3.11.0 |
|
| 623 | - * |
|
| 624 | - */ |
|
| 625 | - public function get_accounts_by_key_dataset_uri( $key ) { |
|
| 626 | - |
|
| 627 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * Get the `accounts` end point. |
|
| 632 | - * |
|
| 633 | - * @return string The `accounts` end point. |
|
| 634 | - * @since 3.16.0 |
|
| 635 | - * |
|
| 636 | - */ |
|
| 637 | - public function get_accounts() { |
|
| 638 | - |
|
| 639 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'accounts'; |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - /** |
|
| 643 | - * Get the `link by default` option. |
|
| 644 | - * |
|
| 645 | - * @return bool True if entities must be linked by default otherwise false. |
|
| 646 | - * @since 3.13.0 |
|
| 647 | - * |
|
| 648 | - */ |
|
| 649 | - public function is_link_by_default() { |
|
| 650 | - |
|
| 651 | - return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' ); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * Set the `link by default` option. |
|
| 656 | - * |
|
| 657 | - * @param bool $value True to enabling linking by default, otherwise false. |
|
| 658 | - * |
|
| 659 | - * @since 3.13.0 |
|
| 660 | - * |
|
| 661 | - */ |
|
| 662 | - public function set_link_by_default( $value ) { |
|
| 663 | - |
|
| 664 | - $this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' ); |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * Get the 'analytics-enable' option. |
|
| 669 | - * |
|
| 670 | - * @return string 'no' or 'yes' representing bool. |
|
| 671 | - * @since 3.21.0 |
|
| 672 | - * |
|
| 673 | - */ |
|
| 674 | - public function is_analytics_enable() { |
|
| 675 | - return 'yes' === $this->get( 'wl_analytics_settings', self::ANALYTICS_ENABLE, 'no' ); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * Set the `analytics-enable` option. |
|
| 680 | - * |
|
| 681 | - * @param bool $value True to enabling analytics, otherwise false. |
|
| 682 | - * |
|
| 683 | - * @since 3.21.0 |
|
| 684 | - * |
|
| 685 | - */ |
|
| 686 | - public function set_is_analytics_enable( $value ) { |
|
| 687 | - |
|
| 688 | - $this->set( 'wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no' ); |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * Get the 'analytics-entity-uri-dimention' option. |
|
| 693 | - * |
|
| 694 | - * @return int |
|
| 695 | - * @since 3.21.0 |
|
| 696 | - * |
|
| 697 | - */ |
|
| 698 | - public function get_analytics_entity_uri_dimension() { |
|
| 699 | - return (int) $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1 ); |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * Get the 'analytics-entity-type-dimension' option. |
|
| 704 | - * |
|
| 705 | - * @return int |
|
| 706 | - * @since 3.21.0 |
|
| 707 | - * |
|
| 708 | - */ |
|
| 709 | - public function get_analytics_entity_type_dimension() { |
|
| 710 | - return $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2 ); |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - /** |
|
| 714 | - * Get the URL to perform autocomplete request. |
|
| 715 | - * |
|
| 716 | - * @return string The URL to call to perform the autocomplete request. |
|
| 717 | - * @since 3.15.0 |
|
| 718 | - * |
|
| 719 | - */ |
|
| 720 | - public function get_autocomplete_url() { |
|
| 721 | - |
|
| 722 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'autocomplete'; |
|
| 723 | - |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - /** |
|
| 727 | - * Get the URL to perform feedback deactivation request. |
|
| 728 | - * |
|
| 729 | - * @return string The URL to call to perform the feedback deactivation request. |
|
| 730 | - * @since 3.19.0 |
|
| 731 | - * |
|
| 732 | - */ |
|
| 733 | - public function get_deactivation_feedback_url() { |
|
| 734 | - |
|
| 735 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'feedbacks'; |
|
| 736 | - |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * Get the base API URL. |
|
| 741 | - * |
|
| 742 | - * @return string The base API URL. |
|
| 743 | - * @since 3.20.0 |
|
| 744 | - * |
|
| 745 | - */ |
|
| 746 | - public function get_api_url() { |
|
| 747 | - |
|
| 748 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE; |
|
| 749 | - } |
|
| 568 | + $json = json_decode( $response['body'] ); |
|
| 569 | + /** |
|
| 570 | + * @since 3.27.7 |
|
| 571 | + * Remove the trailing slash returned from the new platform api. |
|
| 572 | + */ |
|
| 573 | + $dataset_uri = untrailingslashit( $json->datasetURI ); |
|
| 574 | + $package_type = isset( $json->packageType ) ? $json->packageType : null; |
|
| 575 | + |
|
| 576 | + $this->log->info( "Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..." ); |
|
| 577 | + |
|
| 578 | + $this->set_dataset_uri( $dataset_uri ); |
|
| 579 | + $this->set_package_type( $package_type ); |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * Handle the edge case where a user submits the same key again |
|
| 584 | + * when he does not have the dataset uri to regain it. |
|
| 585 | + * |
|
| 586 | + * This can not be handled in the normal option update hook because |
|
| 587 | + * it is not being triggered when the save value equals to the one already |
|
| 588 | + * in the DB. |
|
| 589 | + * |
|
| 590 | + * @param mixed $value The new, unserialized option value. |
|
| 591 | + * @param mixed $old_value The old option value. |
|
| 592 | + * |
|
| 593 | + * @return mixed The same value in the $value parameter |
|
| 594 | + * @since 3.12.0 |
|
| 595 | + * |
|
| 596 | + */ |
|
| 597 | + function maybe_update_dataset_uri( $value, $old_value ) { |
|
| 598 | + |
|
| 599 | + // Check the old key value and the new one. Here we're only handling the |
|
| 600 | + // case where the key hasn't changed and the dataset URI isn't set. The |
|
| 601 | + // other case, i.e. a new key is inserted, is handled at `update_key`. |
|
| 602 | + $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 603 | + $new_key = isset( $value['key'] ) ? $value['key'] : ''; |
|
| 604 | + |
|
| 605 | + $dataset_uri = $this->get_dataset_uri(); |
|
| 606 | + |
|
| 607 | + if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) { |
|
| 608 | + |
|
| 609 | + // make the request to the remote server to try to get the dataset uri. |
|
| 610 | + $this->get_remote_dataset_uri( $new_key ); |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + return $value; |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * Get the API URI to retrieve the dataset URI using the WordLift Key. |
|
| 618 | + * |
|
| 619 | + * @param string $key The WordLift key to use. |
|
| 620 | + * |
|
| 621 | + * @return string The API URI. |
|
| 622 | + * @since 3.11.0 |
|
| 623 | + * |
|
| 624 | + */ |
|
| 625 | + public function get_accounts_by_key_dataset_uri( $key ) { |
|
| 626 | + |
|
| 627 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * Get the `accounts` end point. |
|
| 632 | + * |
|
| 633 | + * @return string The `accounts` end point. |
|
| 634 | + * @since 3.16.0 |
|
| 635 | + * |
|
| 636 | + */ |
|
| 637 | + public function get_accounts() { |
|
| 638 | + |
|
| 639 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'accounts'; |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + /** |
|
| 643 | + * Get the `link by default` option. |
|
| 644 | + * |
|
| 645 | + * @return bool True if entities must be linked by default otherwise false. |
|
| 646 | + * @since 3.13.0 |
|
| 647 | + * |
|
| 648 | + */ |
|
| 649 | + public function is_link_by_default() { |
|
| 650 | + |
|
| 651 | + return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' ); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * Set the `link by default` option. |
|
| 656 | + * |
|
| 657 | + * @param bool $value True to enabling linking by default, otherwise false. |
|
| 658 | + * |
|
| 659 | + * @since 3.13.0 |
|
| 660 | + * |
|
| 661 | + */ |
|
| 662 | + public function set_link_by_default( $value ) { |
|
| 663 | + |
|
| 664 | + $this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' ); |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * Get the 'analytics-enable' option. |
|
| 669 | + * |
|
| 670 | + * @return string 'no' or 'yes' representing bool. |
|
| 671 | + * @since 3.21.0 |
|
| 672 | + * |
|
| 673 | + */ |
|
| 674 | + public function is_analytics_enable() { |
|
| 675 | + return 'yes' === $this->get( 'wl_analytics_settings', self::ANALYTICS_ENABLE, 'no' ); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * Set the `analytics-enable` option. |
|
| 680 | + * |
|
| 681 | + * @param bool $value True to enabling analytics, otherwise false. |
|
| 682 | + * |
|
| 683 | + * @since 3.21.0 |
|
| 684 | + * |
|
| 685 | + */ |
|
| 686 | + public function set_is_analytics_enable( $value ) { |
|
| 687 | + |
|
| 688 | + $this->set( 'wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no' ); |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * Get the 'analytics-entity-uri-dimention' option. |
|
| 693 | + * |
|
| 694 | + * @return int |
|
| 695 | + * @since 3.21.0 |
|
| 696 | + * |
|
| 697 | + */ |
|
| 698 | + public function get_analytics_entity_uri_dimension() { |
|
| 699 | + return (int) $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1 ); |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * Get the 'analytics-entity-type-dimension' option. |
|
| 704 | + * |
|
| 705 | + * @return int |
|
| 706 | + * @since 3.21.0 |
|
| 707 | + * |
|
| 708 | + */ |
|
| 709 | + public function get_analytics_entity_type_dimension() { |
|
| 710 | + return $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2 ); |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + /** |
|
| 714 | + * Get the URL to perform autocomplete request. |
|
| 715 | + * |
|
| 716 | + * @return string The URL to call to perform the autocomplete request. |
|
| 717 | + * @since 3.15.0 |
|
| 718 | + * |
|
| 719 | + */ |
|
| 720 | + public function get_autocomplete_url() { |
|
| 721 | + |
|
| 722 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'autocomplete'; |
|
| 723 | + |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + /** |
|
| 727 | + * Get the URL to perform feedback deactivation request. |
|
| 728 | + * |
|
| 729 | + * @return string The URL to call to perform the feedback deactivation request. |
|
| 730 | + * @since 3.19.0 |
|
| 731 | + * |
|
| 732 | + */ |
|
| 733 | + public function get_deactivation_feedback_url() { |
|
| 734 | + |
|
| 735 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'feedbacks'; |
|
| 736 | + |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * Get the base API URL. |
|
| 741 | + * |
|
| 742 | + * @return string The base API URL. |
|
| 743 | + * @since 3.20.0 |
|
| 744 | + * |
|
| 745 | + */ |
|
| 746 | + public function get_api_url() { |
|
| 747 | + |
|
| 748 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE; |
|
| 749 | + } |
|
| 750 | 750 | |
| 751 | 751 | } |
@@ -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 | |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | public function __construct() { |
| 142 | 142 | |
| 143 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 143 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
| 144 | 144 | |
| 145 | 145 | self::$instance = $this; |
| 146 | 146 | |
@@ -170,11 +170,11 @@ discard block |
||
| 170 | 170 | * @since 3.6.0 |
| 171 | 171 | * |
| 172 | 172 | */ |
| 173 | - private function get( $option, $key, $default = '' ) { |
|
| 173 | + private function get($option, $key, $default = '') { |
|
| 174 | 174 | |
| 175 | - $options = get_option( $option, array() ); |
|
| 175 | + $options = get_option($option, array()); |
|
| 176 | 176 | |
| 177 | - return isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
| 177 | + return isset($options[$key]) ? $options[$key] : $default; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -187,12 +187,12 @@ discard block |
||
| 187 | 187 | * @since 3.9.0 |
| 188 | 188 | * |
| 189 | 189 | */ |
| 190 | - private function set( $option, $key, $value ) { |
|
| 190 | + private function set($option, $key, $value) { |
|
| 191 | 191 | |
| 192 | - $values = get_option( $option ); |
|
| 193 | - $values = isset( $values ) ? $values : array(); |
|
| 194 | - $values[ $key ] = $value; |
|
| 195 | - update_option( $option, $values ); |
|
| 192 | + $values = get_option($option); |
|
| 193 | + $values = isset($values) ? $values : array(); |
|
| 194 | + $values[$key] = $value; |
|
| 195 | + update_option($option, $values); |
|
| 196 | 196 | |
| 197 | 197 | } |
| 198 | 198 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | public function get_entity_base_path() { |
| 207 | 207 | |
| 208 | - return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' ); |
|
| 208 | + return $this->get('wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity'); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -216,9 +216,9 @@ discard block |
||
| 216 | 216 | * @since 3.9.0 |
| 217 | 217 | * |
| 218 | 218 | */ |
| 219 | - public function set_entity_base_path( $value ) { |
|
| 219 | + public function set_entity_base_path($value) { |
|
| 220 | 220 | |
| 221 | - $this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value ); |
|
| 221 | + $this->set('wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value); |
|
| 222 | 222 | |
| 223 | 223 | } |
| 224 | 224 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | */ |
| 232 | 232 | public function is_skip_wizard() { |
| 233 | 233 | |
| 234 | - return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false ); |
|
| 234 | + return $this->get('wl_general_settings', self::SKIP_WIZARD, false); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -242,9 +242,9 @@ discard block |
||
| 242 | 242 | * @since 3.9.0 |
| 243 | 243 | * |
| 244 | 244 | */ |
| 245 | - public function set_skip_wizard( $value ) { |
|
| 245 | + public function set_skip_wizard($value) { |
|
| 246 | 246 | |
| 247 | - $this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value ); |
|
| 247 | + $this->set('wl_general_settings', self::SKIP_WIZARD, true === $value); |
|
| 248 | 248 | |
| 249 | 249 | } |
| 250 | 250 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public function get_key() { |
| 259 | 259 | |
| 260 | - return $this->get( 'wl_general_settings', self::KEY, '' ); |
|
| 260 | + return $this->get('wl_general_settings', self::KEY, ''); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -268,9 +268,9 @@ discard block |
||
| 268 | 268 | * @since 3.9.0 |
| 269 | 269 | * |
| 270 | 270 | */ |
| 271 | - public function set_key( $value ) { |
|
| 271 | + public function set_key($value) { |
|
| 272 | 272 | |
| 273 | - $this->set( 'wl_general_settings', self::KEY, $value ); |
|
| 273 | + $this->set('wl_general_settings', self::KEY, $value); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -285,10 +285,10 @@ discard block |
||
| 285 | 285 | public function get_language_code() { |
| 286 | 286 | |
| 287 | 287 | $language = get_bloginfo('language'); |
| 288 | - if ( ! $language ) { |
|
| 288 | + if ( ! $language) { |
|
| 289 | 289 | return 'en'; |
| 290 | 290 | } |
| 291 | - return substr( $language, 0, 2); |
|
| 291 | + return substr($language, 0, 2); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -304,9 +304,9 @@ discard block |
||
| 304 | 304 | * @since 3.9.0 |
| 305 | 305 | * |
| 306 | 306 | */ |
| 307 | - public function set_language_code( $value ) { |
|
| 307 | + public function set_language_code($value) { |
|
| 308 | 308 | |
| 309 | - $this->set( 'wl_general_settings', self::LANGUAGE, $value ); |
|
| 309 | + $this->set('wl_general_settings', self::LANGUAGE, $value); |
|
| 310 | 310 | |
| 311 | 311 | } |
| 312 | 312 | |
@@ -318,9 +318,9 @@ discard block |
||
| 318 | 318 | * @since 3.19.0 |
| 319 | 319 | * |
| 320 | 320 | */ |
| 321 | - public function set_diagnostic_preferences( $value ) { |
|
| 321 | + public function set_diagnostic_preferences($value) { |
|
| 322 | 322 | |
| 323 | - $this->set( 'wl_general_settings', self::SEND_DIAGNOSTIC, $value ); |
|
| 323 | + $this->set('wl_general_settings', self::SEND_DIAGNOSTIC, $value); |
|
| 324 | 324 | |
| 325 | 325 | } |
| 326 | 326 | |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | */ |
| 332 | 332 | public function get_diagnostic_preferences() { |
| 333 | 333 | |
| 334 | - return $this->get( 'wl_general_settings', self::SEND_DIAGNOSTIC, 'no' ); |
|
| 334 | + return $this->get('wl_general_settings', self::SEND_DIAGNOSTIC, 'no'); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | */ |
| 344 | 344 | public function get_country_code() { |
| 345 | 345 | |
| 346 | - return $this->get( 'wl_general_settings', self::COUNTRY_CODE, 'us' ); |
|
| 346 | + return $this->get('wl_general_settings', self::COUNTRY_CODE, 'us'); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -354,9 +354,9 @@ discard block |
||
| 354 | 354 | * @since 3.18.0 |
| 355 | 355 | * |
| 356 | 356 | */ |
| 357 | - public function set_country_code( $value ) { |
|
| 357 | + public function set_country_code($value) { |
|
| 358 | 358 | |
| 359 | - $this->set( 'wl_general_settings', self::COUNTRY_CODE, $value ); |
|
| 359 | + $this->set('wl_general_settings', self::COUNTRY_CODE, $value); |
|
| 360 | 360 | |
| 361 | 361 | } |
| 362 | 362 | |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | public function get_publisher_id() { |
| 374 | 374 | |
| 375 | - return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null ); |
|
| 375 | + return $this->get('wl_general_settings', self::PUBLISHER_ID, null); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | /** |
@@ -383,9 +383,9 @@ discard block |
||
| 383 | 383 | * @since 3.9.0 |
| 384 | 384 | * |
| 385 | 385 | */ |
| 386 | - public function set_publisher_id( $value ) { |
|
| 386 | + public function set_publisher_id($value) { |
|
| 387 | 387 | |
| 388 | - $this->set( 'wl_general_settings', self::PUBLISHER_ID, $value ); |
|
| 388 | + $this->set('wl_general_settings', self::PUBLISHER_ID, $value); |
|
| 389 | 389 | |
| 390 | 390 | } |
| 391 | 391 | |
@@ -399,8 +399,8 @@ discard block |
||
| 399 | 399 | */ |
| 400 | 400 | public function get_dataset_uri() { |
| 401 | 401 | |
| 402 | - if ( apply_filters( 'wl_features__enable__dataset', true ) ) { |
|
| 403 | - return $this->get( 'wl_advanced_settings', self::DATASET_URI, null ); |
|
| 402 | + if (apply_filters('wl_features__enable__dataset', true)) { |
|
| 403 | + return $this->get('wl_advanced_settings', self::DATASET_URI, null); |
|
| 404 | 404 | } else { |
| 405 | 405 | return null; |
| 406 | 406 | } |
@@ -414,9 +414,9 @@ discard block |
||
| 414 | 414 | * @since 3.10.0 |
| 415 | 415 | * |
| 416 | 416 | */ |
| 417 | - public function set_dataset_uri( $value ) { |
|
| 417 | + public function set_dataset_uri($value) { |
|
| 418 | 418 | |
| 419 | - $this->set( 'wl_advanced_settings', self::DATASET_URI, $value ); |
|
| 419 | + $this->set('wl_advanced_settings', self::DATASET_URI, $value); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | */ |
| 429 | 429 | public function get_package_type() { |
| 430 | 430 | |
| 431 | - return $this->get( 'wl_advanced_settings', self::PACKAGE_TYPE, null ); |
|
| 431 | + return $this->get('wl_advanced_settings', self::PACKAGE_TYPE, null); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
@@ -439,8 +439,8 @@ discard block |
||
| 439 | 439 | * @since 3.20.0 |
| 440 | 440 | * |
| 441 | 441 | */ |
| 442 | - public function set_package_type( $value ) { |
|
| 443 | - $this->set( 'wl_advanced_settings', self::PACKAGE_TYPE, $value ); |
|
| 442 | + public function set_package_type($value) { |
|
| 443 | + $this->set('wl_advanced_settings', self::PACKAGE_TYPE, $value); |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | /** |
@@ -456,11 +456,11 @@ discard block |
||
| 456 | 456 | * @param array $old_value The old settings. |
| 457 | 457 | * @param array $new_value The new settings. |
| 458 | 458 | */ |
| 459 | - public function update_key( $old_value, $new_value ) { |
|
| 459 | + public function update_key($old_value, $new_value) { |
|
| 460 | 460 | |
| 461 | 461 | // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed. |
| 462 | 462 | // $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
| 463 | - $new_key = isset( $new_value['key'] ) ? $new_value['key'] : ''; |
|
| 463 | + $new_key = isset($new_value['key']) ? $new_value['key'] : ''; |
|
| 464 | 464 | |
| 465 | 465 | // If the key hasn't changed, don't do anything. |
| 466 | 466 | // WARN The 'update_option' hook is fired only if the new and old value are not equal. |
@@ -469,12 +469,12 @@ discard block |
||
| 469 | 469 | // } |
| 470 | 470 | |
| 471 | 471 | // If the key is empty, empty the dataset URI. |
| 472 | - if ( '' === $new_key ) { |
|
| 473 | - $this->set_dataset_uri( '' ); |
|
| 472 | + if ('' === $new_key) { |
|
| 473 | + $this->set_dataset_uri(''); |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | // make the request to the remote server. |
| 477 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 477 | + $this->get_remote_dataset_uri($new_key); |
|
| 478 | 478 | |
| 479 | 479 | } |
| 480 | 480 | |
@@ -490,15 +490,15 @@ discard block |
||
| 490 | 490 | * |
| 491 | 491 | * @since 3.17.0 send the site URL and get the dataset URI. |
| 492 | 492 | */ |
| 493 | - public function get_remote_dataset_uri( $key ) { |
|
| 493 | + public function get_remote_dataset_uri($key) { |
|
| 494 | 494 | |
| 495 | - $this->log->trace( 'Getting the remote dataset URI and package type...' ); |
|
| 495 | + $this->log->trace('Getting the remote dataset URI and package type...'); |
|
| 496 | 496 | |
| 497 | - if ( empty( $key ) ) { |
|
| 498 | - $this->log->warn( 'Key set to empty value.' ); |
|
| 497 | + if (empty($key)) { |
|
| 498 | + $this->log->warn('Key set to empty value.'); |
|
| 499 | 499 | |
| 500 | - $this->set_dataset_uri( '' ); |
|
| 501 | - $this->set_package_type( null ); |
|
| 500 | + $this->set_dataset_uri(''); |
|
| 501 | + $this->set_package_type(null); |
|
| 502 | 502 | |
| 503 | 503 | return; |
| 504 | 504 | } |
@@ -513,15 +513,15 @@ discard block |
||
| 513 | 513 | * @since 3.20.0 |
| 514 | 514 | * |
| 515 | 515 | */ |
| 516 | - $home_url = get_option( 'home' ); |
|
| 517 | - $site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) ); |
|
| 516 | + $home_url = get_option('home'); |
|
| 517 | + $site_url = apply_filters('wl_production_site_url', untrailingslashit($home_url)); |
|
| 518 | 518 | |
| 519 | 519 | // Build the URL. |
| 520 | 520 | $url = '/accounts' |
| 521 | - . '?key=' . rawurlencode( $key ) |
|
| 522 | - . '&url=' . rawurlencode( $site_url ) |
|
| 523 | - . '&country=' . $this->get_country_code() |
|
| 524 | - . '&language=' . $this->get_language_code(); |
|
| 521 | + . '?key='.rawurlencode($key) |
|
| 522 | + . '&url='.rawurlencode($site_url) |
|
| 523 | + . '&country='.$this->get_country_code() |
|
| 524 | + . '&language='.$this->get_language_code(); |
|
| 525 | 525 | |
| 526 | 526 | $api_service = Default_Api_Service::get_instance(); |
| 527 | 527 | /** |
@@ -531,31 +531,31 @@ discard block |
||
| 531 | 531 | $headers = array( |
| 532 | 532 | 'Authorization' => "Key $key", |
| 533 | 533 | ); |
| 534 | - $response = $api_service->request( 'PUT', $url, $headers )->get_response(); |
|
| 534 | + $response = $api_service->request('PUT', $url, $headers)->get_response(); |
|
| 535 | 535 | |
| 536 | 536 | // The response is an error. |
| 537 | - if ( is_wp_error( $response ) ) { |
|
| 538 | - $this->log->error( 'An error occurred setting the dataset URI: ' . $response->get_error_message() ); |
|
| 537 | + if (is_wp_error($response)) { |
|
| 538 | + $this->log->error('An error occurred setting the dataset URI: '.$response->get_error_message()); |
|
| 539 | 539 | |
| 540 | - $this->set_dataset_uri( '' ); |
|
| 541 | - $this->set_package_type( null ); |
|
| 540 | + $this->set_dataset_uri(''); |
|
| 541 | + $this->set_package_type(null); |
|
| 542 | 542 | |
| 543 | 543 | return; |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | // The response is not OK. |
| 547 | - if ( ! is_array( $response ) || 200 !== (int) $response['response']['code'] ) { |
|
| 547 | + if ( ! is_array($response) || 200 !== (int) $response['response']['code']) { |
|
| 548 | 548 | $base_url = $api_service->get_base_url(); |
| 549 | 549 | |
| 550 | - if ( ! is_array( $response ) ) { |
|
| 551 | - $this->log->error( "Unexpected response when opening URL $base_url$url: " . var_export( $response, true ) ); |
|
| 550 | + if ( ! is_array($response)) { |
|
| 551 | + $this->log->error("Unexpected response when opening URL $base_url$url: ".var_export($response, true)); |
|
| 552 | 552 | } else { |
| 553 | - $this->log->error( "Unexpected status code when opening URL $base_url$url: " . $response['response']['code'] . "\n" . var_export( $response, true ) ); |
|
| 553 | + $this->log->error("Unexpected status code when opening URL $base_url$url: ".$response['response']['code']."\n".var_export($response, true)); |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | |
| 557 | - $this->set_dataset_uri( '' ); |
|
| 558 | - $this->set_package_type( null ); |
|
| 557 | + $this->set_dataset_uri(''); |
|
| 558 | + $this->set_package_type(null); |
|
| 559 | 559 | |
| 560 | 560 | return; |
| 561 | 561 | } |
@@ -565,18 +565,18 @@ discard block |
||
| 565 | 565 | * |
| 566 | 566 | * @since 3.20.0 |
| 567 | 567 | */ |
| 568 | - $json = json_decode( $response['body'] ); |
|
| 568 | + $json = json_decode($response['body']); |
|
| 569 | 569 | /** |
| 570 | 570 | * @since 3.27.7 |
| 571 | 571 | * Remove the trailing slash returned from the new platform api. |
| 572 | 572 | */ |
| 573 | - $dataset_uri = untrailingslashit( $json->datasetURI ); |
|
| 574 | - $package_type = isset( $json->packageType ) ? $json->packageType : null; |
|
| 573 | + $dataset_uri = untrailingslashit($json->datasetURI); |
|
| 574 | + $package_type = isset($json->packageType) ? $json->packageType : null; |
|
| 575 | 575 | |
| 576 | - $this->log->info( "Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..." ); |
|
| 576 | + $this->log->info("Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..."); |
|
| 577 | 577 | |
| 578 | - $this->set_dataset_uri( $dataset_uri ); |
|
| 579 | - $this->set_package_type( $package_type ); |
|
| 578 | + $this->set_dataset_uri($dataset_uri); |
|
| 579 | + $this->set_package_type($package_type); |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | /** |
@@ -594,20 +594,20 @@ discard block |
||
| 594 | 594 | * @since 3.12.0 |
| 595 | 595 | * |
| 596 | 596 | */ |
| 597 | - function maybe_update_dataset_uri( $value, $old_value ) { |
|
| 597 | + function maybe_update_dataset_uri($value, $old_value) { |
|
| 598 | 598 | |
| 599 | 599 | // Check the old key value and the new one. Here we're only handling the |
| 600 | 600 | // case where the key hasn't changed and the dataset URI isn't set. The |
| 601 | 601 | // other case, i.e. a new key is inserted, is handled at `update_key`. |
| 602 | - $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 603 | - $new_key = isset( $value['key'] ) ? $value['key'] : ''; |
|
| 602 | + $old_key = isset($old_value['key']) ? $old_value['key'] : ''; |
|
| 603 | + $new_key = isset($value['key']) ? $value['key'] : ''; |
|
| 604 | 604 | |
| 605 | 605 | $dataset_uri = $this->get_dataset_uri(); |
| 606 | 606 | |
| 607 | - if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) { |
|
| 607 | + if ( ! empty($new_key) && $new_key === $old_key && empty($dataset_uri)) { |
|
| 608 | 608 | |
| 609 | 609 | // make the request to the remote server to try to get the dataset uri. |
| 610 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 610 | + $this->get_remote_dataset_uri($new_key); |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | return $value; |
@@ -622,9 +622,9 @@ discard block |
||
| 622 | 622 | * @since 3.11.0 |
| 623 | 623 | * |
| 624 | 624 | */ |
| 625 | - public function get_accounts_by_key_dataset_uri( $key ) { |
|
| 625 | + public function get_accounts_by_key_dataset_uri($key) { |
|
| 626 | 626 | |
| 627 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
|
| 627 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."accounts/key=$key/dataset_uri"; |
|
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | /** |
@@ -636,7 +636,7 @@ discard block |
||
| 636 | 636 | */ |
| 637 | 637 | public function get_accounts() { |
| 638 | 638 | |
| 639 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'accounts'; |
|
| 639 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE.'accounts'; |
|
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | /** |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | */ |
| 649 | 649 | public function is_link_by_default() { |
| 650 | 650 | |
| 651 | - return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' ); |
|
| 651 | + return 'yes' === $this->get('wl_general_settings', self::LINK_BY_DEFAULT, 'yes'); |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | /** |
@@ -659,9 +659,9 @@ discard block |
||
| 659 | 659 | * @since 3.13.0 |
| 660 | 660 | * |
| 661 | 661 | */ |
| 662 | - public function set_link_by_default( $value ) { |
|
| 662 | + public function set_link_by_default($value) { |
|
| 663 | 663 | |
| 664 | - $this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' ); |
|
| 664 | + $this->set('wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no'); |
|
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | /** |
@@ -672,7 +672,7 @@ discard block |
||
| 672 | 672 | * |
| 673 | 673 | */ |
| 674 | 674 | public function is_analytics_enable() { |
| 675 | - return 'yes' === $this->get( 'wl_analytics_settings', self::ANALYTICS_ENABLE, 'no' ); |
|
| 675 | + return 'yes' === $this->get('wl_analytics_settings', self::ANALYTICS_ENABLE, 'no'); |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /** |
@@ -683,9 +683,9 @@ discard block |
||
| 683 | 683 | * @since 3.21.0 |
| 684 | 684 | * |
| 685 | 685 | */ |
| 686 | - public function set_is_analytics_enable( $value ) { |
|
| 686 | + public function set_is_analytics_enable($value) { |
|
| 687 | 687 | |
| 688 | - $this->set( 'wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no' ); |
|
| 688 | + $this->set('wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no'); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
@@ -696,7 +696,7 @@ discard block |
||
| 696 | 696 | * |
| 697 | 697 | */ |
| 698 | 698 | public function get_analytics_entity_uri_dimension() { |
| 699 | - return (int) $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1 ); |
|
| 699 | + return (int) $this->get('wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1); |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | /** |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | * |
| 708 | 708 | */ |
| 709 | 709 | public function get_analytics_entity_type_dimension() { |
| 710 | - return $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2 ); |
|
| 710 | + return $this->get('wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2); |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | /** |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | */ |
| 720 | 720 | public function get_autocomplete_url() { |
| 721 | 721 | |
| 722 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'autocomplete'; |
|
| 722 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE.'autocomplete'; |
|
| 723 | 723 | |
| 724 | 724 | } |
| 725 | 725 | |
@@ -732,7 +732,7 @@ discard block |
||
| 732 | 732 | */ |
| 733 | 733 | public function get_deactivation_feedback_url() { |
| 734 | 734 | |
| 735 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'feedbacks'; |
|
| 735 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE.'feedbacks'; |
|
| 736 | 736 | |
| 737 | 737 | } |
| 738 | 738 | |