@@ -1,15 +1,15 @@ discard block |
||
| 1 | 1 | <!-- Pane 3 content --> |
| 2 | 2 | <script type="text/html" id="page-2"> |
| 3 | 3 | <h2 class="page-title"> |
| 4 | - <?php esc_html_e( 'License Key', 'wordlift' ); ?> |
|
| 4 | + <?php esc_html_e('License Key', 'wordlift'); ?> |
|
| 5 | 5 | </h2> |
| 6 | 6 | |
| 7 | 7 | <p class="page-txt"> |
| 8 | 8 | <?php |
| 9 | 9 | $grab_a_key_link = sprintf( |
| 10 | 10 | '<a target="_blank" href="%s">%s</a>', |
| 11 | - esc_attr__( 'https://wordlift.io/pricing', 'wordlift' ), |
|
| 12 | - esc_html__( 'grab a key', 'wordlift' ) |
|
| 11 | + esc_attr__('https://wordlift.io/pricing', 'wordlift'), |
|
| 12 | + esc_html__('grab a key', 'wordlift') |
|
| 13 | 13 | ); |
| 14 | 14 | |
| 15 | 15 | echo sprintf( |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | name="key" |
| 32 | 32 | value="" |
| 33 | 33 | autocomplete="off" |
| 34 | - placeholder="<?php echo esc_attr_x( 'License Key', 'Input text placeholder', 'wordlift' ); ?>" |
|
| 34 | + placeholder="<?php echo esc_attr_x('License Key', 'Input text placeholder', 'wordlift'); ?>" |
|
| 35 | 35 | > |
| 36 | 36 | <div> |
| 37 | 37 | <p class="wl-val-key-error"> |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | target="_tab" |
| 45 | 45 | class="button wl-default-action" |
| 46 | 46 | > |
| 47 | - <?php esc_html_e( 'Grab a Key!', 'wordlift' ); ?> |
|
| 47 | + <?php esc_html_e('Grab a Key!', 'wordlift'); ?> |
|
| 48 | 48 | </a> |
| 49 | 49 | |
| 50 | 50 | <input |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | type="button" |
| 53 | 53 | data-wl-next="wl-next" |
| 54 | 54 | class="button" |
| 55 | - value="<?php esc_attr_e( 'Next', 'wordlift' ); ?>" |
|
| 55 | + value="<?php esc_attr_e('Next', 'wordlift'); ?>" |
|
| 56 | 56 | > |
| 57 | 57 | </div> |
| 58 | 58 | </script> |
@@ -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,560 +21,560 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class Wordlift_Configuration_Service { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * The entity base path option name. |
|
| 26 | - * |
|
| 27 | - * @since 3.6.0 |
|
| 28 | - */ |
|
| 29 | - const ENTITY_BASE_PATH_KEY = 'wl_entity_base_path'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * The skip wizard (admin installation wizard) option name. |
|
| 33 | - * |
|
| 34 | - * @since 3.9.0 |
|
| 35 | - */ |
|
| 36 | - const SKIP_WIZARD = 'wl_skip_wizard'; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * WordLift's key option name. |
|
| 40 | - * |
|
| 41 | - * @since 3.9.0 |
|
| 42 | - */ |
|
| 43 | - const KEY = 'key'; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * WordLift's configured language option name. |
|
| 47 | - * |
|
| 48 | - * @since 3.9.0 |
|
| 49 | - */ |
|
| 50 | - const LANGUAGE = 'site_language'; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * WordLift's configured country code. |
|
| 54 | - * |
|
| 55 | - * @since 3.18.0 |
|
| 56 | - */ |
|
| 57 | - const COUNTRY_CODE = 'country_code'; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * The publisher entity post ID option name. |
|
| 61 | - * |
|
| 62 | - * @since 3.9.0 |
|
| 63 | - */ |
|
| 64 | - const PUBLISHER_ID = 'publisher_id'; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * The dataset URI option name |
|
| 68 | - * |
|
| 69 | - * @since 3.10.0 |
|
| 70 | - */ |
|
| 71 | - const DATASET_URI = 'redlink_dataset_uri'; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * The link by default option name. |
|
| 75 | - * |
|
| 76 | - * @since 3.11.0 |
|
| 77 | - */ |
|
| 78 | - const LINK_BY_DEFAULT = 'link_by_default'; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * The analytics enable option. |
|
| 82 | - * |
|
| 83 | - * @since 3.21.0 |
|
| 84 | - */ |
|
| 85 | - const ANALYTICS_ENABLE = 'analytics_enable'; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * The analytics entity uri dimension option. |
|
| 89 | - * |
|
| 90 | - * @since 3.21.0 |
|
| 91 | - */ |
|
| 92 | - const ANALYTICS_ENTITY_URI_DIMENSION = 'analytics_entity_uri_dimension'; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * The analytics entity type dimension option. |
|
| 96 | - * |
|
| 97 | - * @since 3.21.0 |
|
| 98 | - */ |
|
| 99 | - const ANALYTICS_ENTITY_TYPE_DIMENSION = 'analytics_entity_type_dimension'; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * The user preferences about sharing data option. |
|
| 103 | - * |
|
| 104 | - * @since 3.19.0 |
|
| 105 | - */ |
|
| 106 | - const SEND_DIAGNOSTIC = 'send_diagnostic'; |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * The package type configuration key. |
|
| 110 | - * |
|
| 111 | - * @since 3.20.0 |
|
| 112 | - */ |
|
| 113 | - const PACKAGE_TYPE = 'package_type'; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * The {@link Wordlift_Log_Service} instance. |
|
| 117 | - * |
|
| 118 | - * @since 3.16.0 |
|
| 119 | - * |
|
| 120 | - * @var \Wordlift_Log_Service $log The {@link Wordlift_Log_Service} instance. |
|
| 121 | - */ |
|
| 122 | - private $log; |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * The Wordlift_Configuration_Service's singleton instance. |
|
| 126 | - * |
|
| 127 | - * @since 3.6.0 |
|
| 128 | - * |
|
| 129 | - * @access private |
|
| 130 | - * @var \Wordlift_Configuration_Service $instance Wordlift_Configuration_Service's singleton instance. |
|
| 131 | - */ |
|
| 132 | - private static $instance; |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Create a Wordlift_Configuration_Service's instance. |
|
| 136 | - * |
|
| 137 | - * @since 3.6.0 |
|
| 138 | - */ |
|
| 139 | - public function __construct() { |
|
| 140 | - |
|
| 141 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 142 | - |
|
| 143 | - self::$instance = $this; |
|
| 144 | - |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Get the singleton instance. |
|
| 149 | - * |
|
| 150 | - * @since 3.6.0 |
|
| 151 | - * |
|
| 152 | - * @return \Wordlift_Configuration_Service |
|
| 153 | - */ |
|
| 154 | - public static function get_instance() { |
|
| 155 | - |
|
| 156 | - return self::$instance; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Get a configuration given the option name and a key. The option value is |
|
| 161 | - * expected to be an array. |
|
| 162 | - * |
|
| 163 | - * @since 3.6.0 |
|
| 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 | - */ |
|
| 171 | - private function get( $option, $key, $default = '' ) { |
|
| 172 | - |
|
| 173 | - $options = get_option( $option, array() ); |
|
| 174 | - |
|
| 175 | - return isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Set a configuration parameter. |
|
| 180 | - * |
|
| 181 | - * @since 3.9.0 |
|
| 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 | - private function set( $option, $key, $value ) { |
|
| 188 | - |
|
| 189 | - $values = get_option( $option ); |
|
| 190 | - $values = isset( $values ) ? $values : array(); |
|
| 191 | - $values[ $key ] = $value; |
|
| 192 | - update_option( $option, $values ); |
|
| 193 | - |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Get the entity base path, by default 'entity'. |
|
| 198 | - * |
|
| 199 | - * @since 3.6.0 |
|
| 200 | - * |
|
| 201 | - * @return string The entity base path. |
|
| 202 | - */ |
|
| 203 | - public function get_entity_base_path() { |
|
| 204 | - |
|
| 205 | - return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Get the entity base path. |
|
| 210 | - * |
|
| 211 | - * @since 3.9.0 |
|
| 212 | - * |
|
| 213 | - * @param string $value The entity base path. |
|
| 214 | - */ |
|
| 215 | - public function set_entity_base_path( $value ) { |
|
| 216 | - |
|
| 217 | - $this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value ); |
|
| 218 | - |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Whether the installation skip wizard should be skipped. |
|
| 223 | - * |
|
| 224 | - * @since 3.9.0 |
|
| 225 | - * |
|
| 226 | - * @return bool True if it should be skipped otherwise false. |
|
| 227 | - */ |
|
| 228 | - public function is_skip_wizard() { |
|
| 229 | - |
|
| 230 | - return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false ); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Set the skip wizard parameter. |
|
| 235 | - * |
|
| 236 | - * @since 3.9.0 |
|
| 237 | - * |
|
| 238 | - * @param bool $value True to skip the wizard. We expect a boolean value. |
|
| 239 | - */ |
|
| 240 | - public function set_skip_wizard( $value ) { |
|
| 241 | - |
|
| 242 | - $this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value ); |
|
| 243 | - |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Get WordLift's key. |
|
| 248 | - * |
|
| 249 | - * @since 3.9.0 |
|
| 250 | - * |
|
| 251 | - * @return string WordLift's key or an empty string if not set. |
|
| 252 | - */ |
|
| 253 | - public function get_key() { |
|
| 254 | - |
|
| 255 | - return $this->get( 'wl_general_settings', self::KEY, '' ); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Set WordLift's key. |
|
| 260 | - * |
|
| 261 | - * @since 3.9.0 |
|
| 262 | - * |
|
| 263 | - * @param string $value WordLift's key. |
|
| 264 | - */ |
|
| 265 | - public function set_key( $value ) { |
|
| 266 | - |
|
| 267 | - $this->set( 'wl_general_settings', self::KEY, $value ); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Get WordLift's configured language, by default 'en'. |
|
| 272 | - * |
|
| 273 | - * Note that WordLift's language is used when writing strings to the Linked Data dataset, not for the analysis. |
|
| 274 | - * |
|
| 275 | - * @since 3.9.0 |
|
| 276 | - * |
|
| 277 | - * @return string WordLift's configured language code ('en' by default). |
|
| 278 | - */ |
|
| 279 | - public function get_language_code() { |
|
| 280 | - |
|
| 281 | - return $this->get( 'wl_general_settings', self::LANGUAGE, 'en' ); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * Set WordLift's language code, used when storing strings to the Linked Data dataset. |
|
| 286 | - * |
|
| 287 | - * @since 3.9.0 |
|
| 288 | - * |
|
| 289 | - * @param string $value WordLift's language code. |
|
| 290 | - */ |
|
| 291 | - public function set_language_code( $value ) { |
|
| 292 | - |
|
| 293 | - $this->set( 'wl_general_settings', self::LANGUAGE, $value ); |
|
| 294 | - |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Set the user preferences about sharing diagnostic with us. |
|
| 299 | - * |
|
| 300 | - * @since 3.19.0 |
|
| 301 | - * |
|
| 302 | - * @param string $value The user preferences(yes/no). |
|
| 303 | - */ |
|
| 304 | - public function set_diagnostic_preferences( $value ) { |
|
| 305 | - |
|
| 306 | - $this->set( 'wl_general_settings', self::SEND_DIAGNOSTIC, $value ); |
|
| 307 | - |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Get the user preferences about sharing diagnostic. |
|
| 312 | - * |
|
| 313 | - * @since 3.19.0 |
|
| 314 | - */ |
|
| 315 | - public function get_diagnostic_preferences() { |
|
| 316 | - |
|
| 317 | - return $this->get( 'wl_general_settings', self::SEND_DIAGNOSTIC, 'no' ); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * Get WordLift's configured country code, by default 'us'. |
|
| 322 | - * |
|
| 323 | - * @since 3.18.0 |
|
| 324 | - * |
|
| 325 | - * @return string WordLift's configured country code ('us' by default). |
|
| 326 | - */ |
|
| 327 | - public function get_country_code() { |
|
| 328 | - |
|
| 329 | - return $this->get( 'wl_general_settings', self::COUNTRY_CODE, 'us' ); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Set WordLift's country code. |
|
| 334 | - * |
|
| 335 | - * @since 3.18.0 |
|
| 336 | - * |
|
| 337 | - * @param string $value WordLift's country code. |
|
| 338 | - */ |
|
| 339 | - public function set_country_code( $value ) { |
|
| 340 | - |
|
| 341 | - $this->set( 'wl_general_settings', self::COUNTRY_CODE, $value ); |
|
| 342 | - |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * Get the publisher entity post id. |
|
| 347 | - * |
|
| 348 | - * The publisher entity post id points to an entity post which contains the data for the publisher used in schema.org |
|
| 349 | - * Article markup. |
|
| 350 | - * |
|
| 351 | - * @since 3.9.0 |
|
| 352 | - * |
|
| 353 | - * @return int|NULL The publisher entity post id or NULL if not set. |
|
| 354 | - */ |
|
| 355 | - public function get_publisher_id() { |
|
| 356 | - |
|
| 357 | - return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null ); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Set the publisher entity post id. |
|
| 362 | - * |
|
| 363 | - * @since 3.9.0 |
|
| 364 | - * |
|
| 365 | - * @param int $value The publisher entity post id. |
|
| 366 | - */ |
|
| 367 | - public function set_publisher_id( $value ) { |
|
| 368 | - |
|
| 369 | - $this->set( 'wl_general_settings', self::PUBLISHER_ID, $value ); |
|
| 370 | - |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Get the dataset URI. |
|
| 375 | - * |
|
| 376 | - * @since 3.10.0 |
|
| 377 | - * |
|
| 378 | - * @return string The dataset URI or an empty string if not set. |
|
| 379 | - */ |
|
| 380 | - public function get_dataset_uri() { |
|
| 381 | - |
|
| 382 | - return $this->get( 'wl_advanced_settings', self::DATASET_URI, null ); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Set the dataset URI. |
|
| 387 | - * |
|
| 388 | - * @since 3.10.0 |
|
| 389 | - * |
|
| 390 | - * @param string $value The dataset URI. |
|
| 391 | - */ |
|
| 392 | - public function set_dataset_uri( $value ) { |
|
| 393 | - |
|
| 394 | - $this->set( 'wl_advanced_settings', self::DATASET_URI, $value ); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Get the package type. |
|
| 399 | - * |
|
| 400 | - * @since 3.20.0 |
|
| 401 | - * |
|
| 402 | - * @return string The package type or an empty string if not set. |
|
| 403 | - */ |
|
| 404 | - public function get_package_type() { |
|
| 405 | - |
|
| 406 | - return $this->get( 'wl_advanced_settings', self::PACKAGE_TYPE, null ); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Set the package type. |
|
| 411 | - * |
|
| 412 | - * @since 3.20.0 |
|
| 413 | - * |
|
| 414 | - * @param string $value The package type. |
|
| 415 | - */ |
|
| 416 | - public function set_package_type( $value ) { |
|
| 417 | - |
|
| 418 | - $this->set( 'wl_advanced_settings', self::PACKAGE_TYPE, $value ); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Intercept the change of the WordLift key in order to set the dataset URI. |
|
| 423 | - * |
|
| 424 | - * |
|
| 425 | - * @since 3.20.0 as of #761, we save settings every time a key is set, not only when the key changes, so to |
|
| 426 | - * store the configuration parameters such as country or language. |
|
| 427 | - * @since 3.11.0 |
|
| 428 | - * |
|
| 429 | - * @see https://github.com/insideout10/wordlift-plugin/issues/761 |
|
| 430 | - * |
|
| 431 | - * @param array $old_value The old settings. |
|
| 432 | - * @param array $new_value The new settings. |
|
| 433 | - */ |
|
| 434 | - public function update_key( $old_value, $new_value ) { |
|
| 435 | - |
|
| 436 | - // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed. |
|
| 437 | - // $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 438 | - $new_key = isset( $new_value['key'] ) ? $new_value['key'] : ''; |
|
| 439 | - |
|
| 440 | - // If the key hasn't changed, don't do anything. |
|
| 441 | - // WARN The 'update_option' hook is fired only if the new and old value are not equal. |
|
| 442 | - // if ( $old_key === $new_key ) { |
|
| 443 | - // return; |
|
| 444 | - // } |
|
| 445 | - |
|
| 446 | - // If the key is empty, empty the dataset URI. |
|
| 447 | - if ( '' === $new_key ) { |
|
| 448 | - $this->set_dataset_uri( '' ); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - // make the request to the remote server. |
|
| 452 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 453 | - |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * Handle retrieving the dataset uri from the remote server. |
|
| 458 | - * |
|
| 459 | - * If a valid dataset uri is returned it is stored in the appropriate option, |
|
| 460 | - * otherwise the option is set to empty string. |
|
| 461 | - * |
|
| 462 | - * @since 3.17.0 send the site URL and get the dataset URI. |
|
| 463 | - * @since 3.12.0 |
|
| 464 | - * |
|
| 465 | - * @param string $key The key to be used. |
|
| 466 | - */ |
|
| 467 | - public function get_remote_dataset_uri( $key ) { |
|
| 468 | - |
|
| 469 | - $this->log->trace( 'Getting the remote dataset URI and package type...' ); |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * Allow 3rd parties to change the site_url. |
|
| 473 | - * |
|
| 474 | - * @since 3.20.0 |
|
| 475 | - * |
|
| 476 | - * @see https://github.com/insideout10/wordlift-plugin/issues/850 |
|
| 477 | - * |
|
| 478 | - * @param string $site_url The site url. |
|
| 479 | - */ |
|
| 480 | - $site_url = apply_filters( 'wl_production_site_url', site_url() ); |
|
| 24 | + /** |
|
| 25 | + * The entity base path option name. |
|
| 26 | + * |
|
| 27 | + * @since 3.6.0 |
|
| 28 | + */ |
|
| 29 | + const ENTITY_BASE_PATH_KEY = 'wl_entity_base_path'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * The skip wizard (admin installation wizard) option name. |
|
| 33 | + * |
|
| 34 | + * @since 3.9.0 |
|
| 35 | + */ |
|
| 36 | + const SKIP_WIZARD = 'wl_skip_wizard'; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * WordLift's key option name. |
|
| 40 | + * |
|
| 41 | + * @since 3.9.0 |
|
| 42 | + */ |
|
| 43 | + const KEY = 'key'; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * WordLift's configured language option name. |
|
| 47 | + * |
|
| 48 | + * @since 3.9.0 |
|
| 49 | + */ |
|
| 50 | + const LANGUAGE = 'site_language'; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * WordLift's configured country code. |
|
| 54 | + * |
|
| 55 | + * @since 3.18.0 |
|
| 56 | + */ |
|
| 57 | + const COUNTRY_CODE = 'country_code'; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * The publisher entity post ID option name. |
|
| 61 | + * |
|
| 62 | + * @since 3.9.0 |
|
| 63 | + */ |
|
| 64 | + const PUBLISHER_ID = 'publisher_id'; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * The dataset URI option name |
|
| 68 | + * |
|
| 69 | + * @since 3.10.0 |
|
| 70 | + */ |
|
| 71 | + const DATASET_URI = 'redlink_dataset_uri'; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * The link by default option name. |
|
| 75 | + * |
|
| 76 | + * @since 3.11.0 |
|
| 77 | + */ |
|
| 78 | + const LINK_BY_DEFAULT = 'link_by_default'; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * The analytics enable option. |
|
| 82 | + * |
|
| 83 | + * @since 3.21.0 |
|
| 84 | + */ |
|
| 85 | + const ANALYTICS_ENABLE = 'analytics_enable'; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * The analytics entity uri dimension option. |
|
| 89 | + * |
|
| 90 | + * @since 3.21.0 |
|
| 91 | + */ |
|
| 92 | + const ANALYTICS_ENTITY_URI_DIMENSION = 'analytics_entity_uri_dimension'; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * The analytics entity type dimension option. |
|
| 96 | + * |
|
| 97 | + * @since 3.21.0 |
|
| 98 | + */ |
|
| 99 | + const ANALYTICS_ENTITY_TYPE_DIMENSION = 'analytics_entity_type_dimension'; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * The user preferences about sharing data option. |
|
| 103 | + * |
|
| 104 | + * @since 3.19.0 |
|
| 105 | + */ |
|
| 106 | + const SEND_DIAGNOSTIC = 'send_diagnostic'; |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * The package type configuration key. |
|
| 110 | + * |
|
| 111 | + * @since 3.20.0 |
|
| 112 | + */ |
|
| 113 | + const PACKAGE_TYPE = 'package_type'; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * The {@link Wordlift_Log_Service} instance. |
|
| 117 | + * |
|
| 118 | + * @since 3.16.0 |
|
| 119 | + * |
|
| 120 | + * @var \Wordlift_Log_Service $log The {@link Wordlift_Log_Service} instance. |
|
| 121 | + */ |
|
| 122 | + private $log; |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * The Wordlift_Configuration_Service's singleton instance. |
|
| 126 | + * |
|
| 127 | + * @since 3.6.0 |
|
| 128 | + * |
|
| 129 | + * @access private |
|
| 130 | + * @var \Wordlift_Configuration_Service $instance Wordlift_Configuration_Service's singleton instance. |
|
| 131 | + */ |
|
| 132 | + private static $instance; |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Create a Wordlift_Configuration_Service's instance. |
|
| 136 | + * |
|
| 137 | + * @since 3.6.0 |
|
| 138 | + */ |
|
| 139 | + public function __construct() { |
|
| 140 | + |
|
| 141 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 142 | + |
|
| 143 | + self::$instance = $this; |
|
| 144 | + |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Get the singleton instance. |
|
| 149 | + * |
|
| 150 | + * @since 3.6.0 |
|
| 151 | + * |
|
| 152 | + * @return \Wordlift_Configuration_Service |
|
| 153 | + */ |
|
| 154 | + public static function get_instance() { |
|
| 155 | + |
|
| 156 | + return self::$instance; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Get a configuration given the option name and a key. The option value is |
|
| 161 | + * expected to be an array. |
|
| 162 | + * |
|
| 163 | + * @since 3.6.0 |
|
| 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 | + */ |
|
| 171 | + private function get( $option, $key, $default = '' ) { |
|
| 481 | 172 | |
| 482 | - // Build the URL. |
|
| 483 | - $url = $this->get_accounts() |
|
| 484 | - . '?key=' . rawurlencode( $key ) |
|
| 485 | - . '&url=' . rawurlencode( $site_url ) |
|
| 486 | - . '&country=' . $this->get_country_code() |
|
| 487 | - . '&language=' . $this->get_language_code(); |
|
| 173 | + $options = get_option( $option, array() ); |
|
| 488 | 174 | |
| 489 | - $args = wp_parse_args( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array( |
|
| 490 | - 'method' => 'PUT', |
|
| 491 | - ) ); |
|
| 175 | + return isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Set a configuration parameter. |
|
| 180 | + * |
|
| 181 | + * @since 3.9.0 |
|
| 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 | + private function set( $option, $key, $value ) { |
|
| 188 | + |
|
| 189 | + $values = get_option( $option ); |
|
| 190 | + $values = isset( $values ) ? $values : array(); |
|
| 191 | + $values[ $key ] = $value; |
|
| 192 | + update_option( $option, $values ); |
|
| 193 | + |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Get the entity base path, by default 'entity'. |
|
| 198 | + * |
|
| 199 | + * @since 3.6.0 |
|
| 200 | + * |
|
| 201 | + * @return string The entity base path. |
|
| 202 | + */ |
|
| 203 | + public function get_entity_base_path() { |
|
| 204 | + |
|
| 205 | + return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Get the entity base path. |
|
| 210 | + * |
|
| 211 | + * @since 3.9.0 |
|
| 212 | + * |
|
| 213 | + * @param string $value The entity base path. |
|
| 214 | + */ |
|
| 215 | + public function set_entity_base_path( $value ) { |
|
| 216 | + |
|
| 217 | + $this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value ); |
|
| 492 | 218 | |
| 493 | - $response = wp_remote_request( $url, $args ); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Whether the installation skip wizard should be skipped. |
|
| 223 | + * |
|
| 224 | + * @since 3.9.0 |
|
| 225 | + * |
|
| 226 | + * @return bool True if it should be skipped otherwise false. |
|
| 227 | + */ |
|
| 228 | + public function is_skip_wizard() { |
|
| 494 | 229 | |
| 495 | - // The response is an error. |
|
| 496 | - if ( is_wp_error( $response ) ) { |
|
| 497 | - $this->log->error( 'An error occurred setting the dataset URI: ' . $response->get_error_message() ); |
|
| 230 | + return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false ); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Set the skip wizard parameter. |
|
| 235 | + * |
|
| 236 | + * @since 3.9.0 |
|
| 237 | + * |
|
| 238 | + * @param bool $value True to skip the wizard. We expect a boolean value. |
|
| 239 | + */ |
|
| 240 | + public function set_skip_wizard( $value ) { |
|
| 498 | 241 | |
| 499 | - $this->set_dataset_uri( '' ); |
|
| 500 | - $this->set_package_type( null ); |
|
| 242 | + $this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value ); |
|
| 501 | 243 | |
| 502 | - return; |
|
| 503 | - } |
|
| 244 | + } |
|
| 504 | 245 | |
| 505 | - // The response is not OK. |
|
| 506 | - if ( 200 !== (int) $response['response']['code'] ) { |
|
| 507 | - $this->log->error( "Unexpected status code when opening URL $url: " . $response['response']['code'] ); |
|
| 246 | + /** |
|
| 247 | + * Get WordLift's key. |
|
| 248 | + * |
|
| 249 | + * @since 3.9.0 |
|
| 250 | + * |
|
| 251 | + * @return string WordLift's key or an empty string if not set. |
|
| 252 | + */ |
|
| 253 | + public function get_key() { |
|
| 508 | 254 | |
| 509 | - $this->set_dataset_uri( '' ); |
|
| 510 | - $this->set_package_type( null ); |
|
| 255 | + return $this->get( 'wl_general_settings', self::KEY, '' ); |
|
| 256 | + } |
|
| 511 | 257 | |
| 512 | - return; |
|
| 513 | - } |
|
| 258 | + /** |
|
| 259 | + * Set WordLift's key. |
|
| 260 | + * |
|
| 261 | + * @since 3.9.0 |
|
| 262 | + * |
|
| 263 | + * @param string $value WordLift's key. |
|
| 264 | + */ |
|
| 265 | + public function set_key( $value ) { |
|
| 514 | 266 | |
| 515 | - /* |
|
| 267 | + $this->set( 'wl_general_settings', self::KEY, $value ); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Get WordLift's configured language, by default 'en'. |
|
| 272 | + * |
|
| 273 | + * Note that WordLift's language is used when writing strings to the Linked Data dataset, not for the analysis. |
|
| 274 | + * |
|
| 275 | + * @since 3.9.0 |
|
| 276 | + * |
|
| 277 | + * @return string WordLift's configured language code ('en' by default). |
|
| 278 | + */ |
|
| 279 | + public function get_language_code() { |
|
| 280 | + |
|
| 281 | + return $this->get( 'wl_general_settings', self::LANGUAGE, 'en' ); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Set WordLift's language code, used when storing strings to the Linked Data dataset. |
|
| 286 | + * |
|
| 287 | + * @since 3.9.0 |
|
| 288 | + * |
|
| 289 | + * @param string $value WordLift's language code. |
|
| 290 | + */ |
|
| 291 | + public function set_language_code( $value ) { |
|
| 292 | + |
|
| 293 | + $this->set( 'wl_general_settings', self::LANGUAGE, $value ); |
|
| 294 | + |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Set the user preferences about sharing diagnostic with us. |
|
| 299 | + * |
|
| 300 | + * @since 3.19.0 |
|
| 301 | + * |
|
| 302 | + * @param string $value The user preferences(yes/no). |
|
| 303 | + */ |
|
| 304 | + public function set_diagnostic_preferences( $value ) { |
|
| 305 | + |
|
| 306 | + $this->set( 'wl_general_settings', self::SEND_DIAGNOSTIC, $value ); |
|
| 307 | + |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Get the user preferences about sharing diagnostic. |
|
| 312 | + * |
|
| 313 | + * @since 3.19.0 |
|
| 314 | + */ |
|
| 315 | + public function get_diagnostic_preferences() { |
|
| 316 | + |
|
| 317 | + return $this->get( 'wl_general_settings', self::SEND_DIAGNOSTIC, 'no' ); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * Get WordLift's configured country code, by default 'us'. |
|
| 322 | + * |
|
| 323 | + * @since 3.18.0 |
|
| 324 | + * |
|
| 325 | + * @return string WordLift's configured country code ('us' by default). |
|
| 326 | + */ |
|
| 327 | + public function get_country_code() { |
|
| 328 | + |
|
| 329 | + return $this->get( 'wl_general_settings', self::COUNTRY_CODE, 'us' ); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Set WordLift's country code. |
|
| 334 | + * |
|
| 335 | + * @since 3.18.0 |
|
| 336 | + * |
|
| 337 | + * @param string $value WordLift's country code. |
|
| 338 | + */ |
|
| 339 | + public function set_country_code( $value ) { |
|
| 340 | + |
|
| 341 | + $this->set( 'wl_general_settings', self::COUNTRY_CODE, $value ); |
|
| 342 | + |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * Get the publisher entity post id. |
|
| 347 | + * |
|
| 348 | + * The publisher entity post id points to an entity post which contains the data for the publisher used in schema.org |
|
| 349 | + * Article markup. |
|
| 350 | + * |
|
| 351 | + * @since 3.9.0 |
|
| 352 | + * |
|
| 353 | + * @return int|NULL The publisher entity post id or NULL if not set. |
|
| 354 | + */ |
|
| 355 | + public function get_publisher_id() { |
|
| 356 | + |
|
| 357 | + return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null ); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Set the publisher entity post id. |
|
| 362 | + * |
|
| 363 | + * @since 3.9.0 |
|
| 364 | + * |
|
| 365 | + * @param int $value The publisher entity post id. |
|
| 366 | + */ |
|
| 367 | + public function set_publisher_id( $value ) { |
|
| 368 | + |
|
| 369 | + $this->set( 'wl_general_settings', self::PUBLISHER_ID, $value ); |
|
| 370 | + |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Get the dataset URI. |
|
| 375 | + * |
|
| 376 | + * @since 3.10.0 |
|
| 377 | + * |
|
| 378 | + * @return string The dataset URI or an empty string if not set. |
|
| 379 | + */ |
|
| 380 | + public function get_dataset_uri() { |
|
| 381 | + |
|
| 382 | + return $this->get( 'wl_advanced_settings', self::DATASET_URI, null ); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Set the dataset URI. |
|
| 387 | + * |
|
| 388 | + * @since 3.10.0 |
|
| 389 | + * |
|
| 390 | + * @param string $value The dataset URI. |
|
| 391 | + */ |
|
| 392 | + public function set_dataset_uri( $value ) { |
|
| 393 | + |
|
| 394 | + $this->set( 'wl_advanced_settings', self::DATASET_URI, $value ); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Get the package type. |
|
| 399 | + * |
|
| 400 | + * @since 3.20.0 |
|
| 401 | + * |
|
| 402 | + * @return string The package type or an empty string if not set. |
|
| 403 | + */ |
|
| 404 | + public function get_package_type() { |
|
| 405 | + |
|
| 406 | + return $this->get( 'wl_advanced_settings', self::PACKAGE_TYPE, null ); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Set the package type. |
|
| 411 | + * |
|
| 412 | + * @since 3.20.0 |
|
| 413 | + * |
|
| 414 | + * @param string $value The package type. |
|
| 415 | + */ |
|
| 416 | + public function set_package_type( $value ) { |
|
| 417 | + |
|
| 418 | + $this->set( 'wl_advanced_settings', self::PACKAGE_TYPE, $value ); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Intercept the change of the WordLift key in order to set the dataset URI. |
|
| 423 | + * |
|
| 424 | + * |
|
| 425 | + * @since 3.20.0 as of #761, we save settings every time a key is set, not only when the key changes, so to |
|
| 426 | + * store the configuration parameters such as country or language. |
|
| 427 | + * @since 3.11.0 |
|
| 428 | + * |
|
| 429 | + * @see https://github.com/insideout10/wordlift-plugin/issues/761 |
|
| 430 | + * |
|
| 431 | + * @param array $old_value The old settings. |
|
| 432 | + * @param array $new_value The new settings. |
|
| 433 | + */ |
|
| 434 | + public function update_key( $old_value, $new_value ) { |
|
| 435 | + |
|
| 436 | + // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed. |
|
| 437 | + // $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 438 | + $new_key = isset( $new_value['key'] ) ? $new_value['key'] : ''; |
|
| 439 | + |
|
| 440 | + // If the key hasn't changed, don't do anything. |
|
| 441 | + // WARN The 'update_option' hook is fired only if the new and old value are not equal. |
|
| 442 | + // if ( $old_key === $new_key ) { |
|
| 443 | + // return; |
|
| 444 | + // } |
|
| 445 | + |
|
| 446 | + // If the key is empty, empty the dataset URI. |
|
| 447 | + if ( '' === $new_key ) { |
|
| 448 | + $this->set_dataset_uri( '' ); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + // make the request to the remote server. |
|
| 452 | + $this->get_remote_dataset_uri( $new_key ); |
|
| 453 | + |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * Handle retrieving the dataset uri from the remote server. |
|
| 458 | + * |
|
| 459 | + * If a valid dataset uri is returned it is stored in the appropriate option, |
|
| 460 | + * otherwise the option is set to empty string. |
|
| 461 | + * |
|
| 462 | + * @since 3.17.0 send the site URL and get the dataset URI. |
|
| 463 | + * @since 3.12.0 |
|
| 464 | + * |
|
| 465 | + * @param string $key The key to be used. |
|
| 466 | + */ |
|
| 467 | + public function get_remote_dataset_uri( $key ) { |
|
| 468 | + |
|
| 469 | + $this->log->trace( 'Getting the remote dataset URI and package type...' ); |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * Allow 3rd parties to change the site_url. |
|
| 473 | + * |
|
| 474 | + * @since 3.20.0 |
|
| 475 | + * |
|
| 476 | + * @see https://github.com/insideout10/wordlift-plugin/issues/850 |
|
| 477 | + * |
|
| 478 | + * @param string $site_url The site url. |
|
| 479 | + */ |
|
| 480 | + $site_url = apply_filters( 'wl_production_site_url', site_url() ); |
|
| 481 | + |
|
| 482 | + // Build the URL. |
|
| 483 | + $url = $this->get_accounts() |
|
| 484 | + . '?key=' . rawurlencode( $key ) |
|
| 485 | + . '&url=' . rawurlencode( $site_url ) |
|
| 486 | + . '&country=' . $this->get_country_code() |
|
| 487 | + . '&language=' . $this->get_language_code(); |
|
| 488 | + |
|
| 489 | + $args = wp_parse_args( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array( |
|
| 490 | + 'method' => 'PUT', |
|
| 491 | + ) ); |
|
| 492 | + |
|
| 493 | + $response = wp_remote_request( $url, $args ); |
|
| 494 | + |
|
| 495 | + // The response is an error. |
|
| 496 | + if ( is_wp_error( $response ) ) { |
|
| 497 | + $this->log->error( 'An error occurred setting the dataset URI: ' . $response->get_error_message() ); |
|
| 498 | + |
|
| 499 | + $this->set_dataset_uri( '' ); |
|
| 500 | + $this->set_package_type( null ); |
|
| 501 | + |
|
| 502 | + return; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + // The response is not OK. |
|
| 506 | + if ( 200 !== (int) $response['response']['code'] ) { |
|
| 507 | + $this->log->error( "Unexpected status code when opening URL $url: " . $response['response']['code'] ); |
|
| 508 | + |
|
| 509 | + $this->set_dataset_uri( '' ); |
|
| 510 | + $this->set_package_type( null ); |
|
| 511 | + |
|
| 512 | + return; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /* |
|
| 516 | 516 | * We also store the package type. |
| 517 | 517 | * |
| 518 | 518 | * @since 3.20.0 |
| 519 | 519 | */ |
| 520 | - $json = json_decode( $response['body'] ); |
|
| 521 | - $dataset_uri = $json->datasetURI; |
|
| 522 | - $package_type = isset( $json->packageType ) ? $json->packageType : null; |
|
| 523 | - |
|
| 524 | - $this->log->info( "Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..." ); |
|
| 525 | - |
|
| 526 | - $this->set_dataset_uri( $dataset_uri ); |
|
| 527 | - $this->set_package_type( $package_type ); |
|
| 528 | - |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * Handle the edge case where a user submits the same key again |
|
| 533 | - * when he does not have the dataset uri to regain it. |
|
| 534 | - * |
|
| 535 | - * This can not be handled in the normal option update hook because |
|
| 536 | - * it is not being triggered when the save value equals to the one already |
|
| 537 | - * in the DB. |
|
| 538 | - * |
|
| 539 | - * @since 3.12.0 |
|
| 540 | - * |
|
| 541 | - * @param mixed $value The new, unserialized option value. |
|
| 542 | - * @param mixed $old_value The old option value. |
|
| 543 | - * |
|
| 544 | - * @return mixed The same value in the $value parameter |
|
| 545 | - */ |
|
| 546 | - function maybe_update_dataset_uri( $value, $old_value ) { |
|
| 547 | - |
|
| 548 | - // Check the old key value and the new one. Here we're only handling the |
|
| 549 | - // case where the key hasn't changed and the dataset URI isn't set. The |
|
| 550 | - // other case, i.e. a new key is inserted, is handled at `update_key`. |
|
| 551 | - $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 552 | - $new_key = isset( $value['key'] ) ? $value['key'] : ''; |
|
| 553 | - |
|
| 554 | - $dataset_uri = $this->get_dataset_uri(); |
|
| 555 | - |
|
| 556 | - if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) { |
|
| 557 | - |
|
| 558 | - // make the request to the remote server to try to get the dataset uri. |
|
| 559 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - return $value; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Get the API URI to retrieve the dataset URI using the WordLift Key. |
|
| 567 | - * |
|
| 568 | - * @since 3.11.0 |
|
| 569 | - * |
|
| 570 | - * @param string $key The WordLift key to use. |
|
| 571 | - * |
|
| 572 | - * @return string The API URI. |
|
| 573 | - */ |
|
| 574 | - public function get_accounts_by_key_dataset_uri( $key ) { |
|
| 575 | - |
|
| 576 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
|
| 577 | - } |
|
| 520 | + $json = json_decode( $response['body'] ); |
|
| 521 | + $dataset_uri = $json->datasetURI; |
|
| 522 | + $package_type = isset( $json->packageType ) ? $json->packageType : null; |
|
| 523 | + |
|
| 524 | + $this->log->info( "Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..." ); |
|
| 525 | + |
|
| 526 | + $this->set_dataset_uri( $dataset_uri ); |
|
| 527 | + $this->set_package_type( $package_type ); |
|
| 528 | + |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * Handle the edge case where a user submits the same key again |
|
| 533 | + * when he does not have the dataset uri to regain it. |
|
| 534 | + * |
|
| 535 | + * This can not be handled in the normal option update hook because |
|
| 536 | + * it is not being triggered when the save value equals to the one already |
|
| 537 | + * in the DB. |
|
| 538 | + * |
|
| 539 | + * @since 3.12.0 |
|
| 540 | + * |
|
| 541 | + * @param mixed $value The new, unserialized option value. |
|
| 542 | + * @param mixed $old_value The old option value. |
|
| 543 | + * |
|
| 544 | + * @return mixed The same value in the $value parameter |
|
| 545 | + */ |
|
| 546 | + function maybe_update_dataset_uri( $value, $old_value ) { |
|
| 547 | + |
|
| 548 | + // Check the old key value and the new one. Here we're only handling the |
|
| 549 | + // case where the key hasn't changed and the dataset URI isn't set. The |
|
| 550 | + // other case, i.e. a new key is inserted, is handled at `update_key`. |
|
| 551 | + $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 552 | + $new_key = isset( $value['key'] ) ? $value['key'] : ''; |
|
| 553 | + |
|
| 554 | + $dataset_uri = $this->get_dataset_uri(); |
|
| 555 | + |
|
| 556 | + if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) { |
|
| 557 | + |
|
| 558 | + // make the request to the remote server to try to get the dataset uri. |
|
| 559 | + $this->get_remote_dataset_uri( $new_key ); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + return $value; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * Get the API URI to retrieve the dataset URI using the WordLift Key. |
|
| 567 | + * |
|
| 568 | + * @since 3.11.0 |
|
| 569 | + * |
|
| 570 | + * @param string $key The WordLift key to use. |
|
| 571 | + * |
|
| 572 | + * @return string The API URI. |
|
| 573 | + */ |
|
| 574 | + public function get_accounts_by_key_dataset_uri( $key ) { |
|
| 575 | + |
|
| 576 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
|
| 577 | + } |
|
| 578 | 578 | |
| 579 | 579 | /** |
| 580 | 580 | * Get the API URI to retrieve the account info using the WordLift Key. |
@@ -590,123 +590,123 @@ discard block |
||
| 590 | 590 | return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/info"; |
| 591 | 591 | } |
| 592 | 592 | |
| 593 | - /** |
|
| 594 | - * Get the `accounts` end point. |
|
| 595 | - * |
|
| 596 | - * @since 3.16.0 |
|
| 597 | - * |
|
| 598 | - * @return string The `accounts` end point. |
|
| 599 | - */ |
|
| 600 | - public function get_accounts() { |
|
| 601 | - |
|
| 602 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'accounts'; |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - /** |
|
| 606 | - * Get the `link by default` option. |
|
| 607 | - * |
|
| 608 | - * @since 3.13.0 |
|
| 609 | - * |
|
| 610 | - * @return bool True if entities must be linked by default otherwise false. |
|
| 611 | - */ |
|
| 612 | - public function is_link_by_default() { |
|
| 613 | - |
|
| 614 | - return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Set the `link by default` option. |
|
| 619 | - * |
|
| 620 | - * @since 3.13.0 |
|
| 621 | - * |
|
| 622 | - * @param bool $value True to enabling linking by default, otherwise false. |
|
| 623 | - */ |
|
| 624 | - public function set_link_by_default( $value ) { |
|
| 625 | - |
|
| 626 | - $this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' ); |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * Get the 'analytics-enable' option. |
|
| 631 | - * |
|
| 632 | - * @since 3.21.0 |
|
| 633 | - * |
|
| 634 | - * @return string 'no' or 'yes' representing bool. |
|
| 635 | - */ |
|
| 636 | - public function is_analytics_enable() { |
|
| 637 | - return 'yes' === $this->get( 'wl_analytics_settings', self::ANALYTICS_ENABLE, 'no' ); |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * Set the `analytics-enable` option. |
|
| 642 | - * |
|
| 643 | - * @since 3.21.0 |
|
| 644 | - * |
|
| 645 | - * @param bool $value True to enabling analytics, otherwise false. |
|
| 646 | - */ |
|
| 647 | - public function set_is_analytics_enable( $value ) { |
|
| 648 | - |
|
| 649 | - $this->set( 'wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no' ); |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * Get the 'analytics-entity-uri-dimention' option. |
|
| 654 | - * |
|
| 655 | - * @since 3.21.0 |
|
| 656 | - * |
|
| 657 | - * @return int |
|
| 658 | - */ |
|
| 659 | - public function get_analytics_entity_uri_dimension() { |
|
| 660 | - return (int) $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1 ); |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Get the 'analytics-entity-type-dimension' option. |
|
| 665 | - * |
|
| 666 | - * @since 3.21.0 |
|
| 667 | - * |
|
| 668 | - * @return int |
|
| 669 | - */ |
|
| 670 | - public function get_analytics_entity_type_dimension() { |
|
| 671 | - return $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2 ); |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - /** |
|
| 675 | - * Get the URL to perform autocomplete request. |
|
| 676 | - * |
|
| 677 | - * @since 3.15.0 |
|
| 678 | - * |
|
| 679 | - * @return string The URL to call to perform the autocomplete request. |
|
| 680 | - */ |
|
| 681 | - public function get_autocomplete_url() { |
|
| 682 | - |
|
| 683 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'autocomplete'; |
|
| 684 | - |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - /** |
|
| 688 | - * Get the URL to perform feedback deactivation request. |
|
| 689 | - * |
|
| 690 | - * @since 3.19.0 |
|
| 691 | - * |
|
| 692 | - * @return string The URL to call to perform the feedback deactivation request. |
|
| 693 | - */ |
|
| 694 | - public function get_deactivation_feedback_url() { |
|
| 695 | - |
|
| 696 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'feedbacks'; |
|
| 697 | - |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - /** |
|
| 701 | - * Get the base API URL. |
|
| 702 | - * |
|
| 703 | - * @since 3.20.0 |
|
| 704 | - * |
|
| 705 | - * @return string The base API URL. |
|
| 706 | - */ |
|
| 707 | - public function get_api_url() { |
|
| 708 | - |
|
| 709 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE; |
|
| 710 | - } |
|
| 593 | + /** |
|
| 594 | + * Get the `accounts` end point. |
|
| 595 | + * |
|
| 596 | + * @since 3.16.0 |
|
| 597 | + * |
|
| 598 | + * @return string The `accounts` end point. |
|
| 599 | + */ |
|
| 600 | + public function get_accounts() { |
|
| 601 | + |
|
| 602 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'accounts'; |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + /** |
|
| 606 | + * Get the `link by default` option. |
|
| 607 | + * |
|
| 608 | + * @since 3.13.0 |
|
| 609 | + * |
|
| 610 | + * @return bool True if entities must be linked by default otherwise false. |
|
| 611 | + */ |
|
| 612 | + public function is_link_by_default() { |
|
| 613 | + |
|
| 614 | + return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' ); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Set the `link by default` option. |
|
| 619 | + * |
|
| 620 | + * @since 3.13.0 |
|
| 621 | + * |
|
| 622 | + * @param bool $value True to enabling linking by default, otherwise false. |
|
| 623 | + */ |
|
| 624 | + public function set_link_by_default( $value ) { |
|
| 625 | + |
|
| 626 | + $this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' ); |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * Get the 'analytics-enable' option. |
|
| 631 | + * |
|
| 632 | + * @since 3.21.0 |
|
| 633 | + * |
|
| 634 | + * @return string 'no' or 'yes' representing bool. |
|
| 635 | + */ |
|
| 636 | + public function is_analytics_enable() { |
|
| 637 | + return 'yes' === $this->get( 'wl_analytics_settings', self::ANALYTICS_ENABLE, 'no' ); |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * Set the `analytics-enable` option. |
|
| 642 | + * |
|
| 643 | + * @since 3.21.0 |
|
| 644 | + * |
|
| 645 | + * @param bool $value True to enabling analytics, otherwise false. |
|
| 646 | + */ |
|
| 647 | + public function set_is_analytics_enable( $value ) { |
|
| 648 | + |
|
| 649 | + $this->set( 'wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no' ); |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * Get the 'analytics-entity-uri-dimention' option. |
|
| 654 | + * |
|
| 655 | + * @since 3.21.0 |
|
| 656 | + * |
|
| 657 | + * @return int |
|
| 658 | + */ |
|
| 659 | + public function get_analytics_entity_uri_dimension() { |
|
| 660 | + return (int) $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1 ); |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * Get the 'analytics-entity-type-dimension' option. |
|
| 665 | + * |
|
| 666 | + * @since 3.21.0 |
|
| 667 | + * |
|
| 668 | + * @return int |
|
| 669 | + */ |
|
| 670 | + public function get_analytics_entity_type_dimension() { |
|
| 671 | + return $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2 ); |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + /** |
|
| 675 | + * Get the URL to perform autocomplete request. |
|
| 676 | + * |
|
| 677 | + * @since 3.15.0 |
|
| 678 | + * |
|
| 679 | + * @return string The URL to call to perform the autocomplete request. |
|
| 680 | + */ |
|
| 681 | + public function get_autocomplete_url() { |
|
| 682 | + |
|
| 683 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'autocomplete'; |
|
| 684 | + |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + /** |
|
| 688 | + * Get the URL to perform feedback deactivation request. |
|
| 689 | + * |
|
| 690 | + * @since 3.19.0 |
|
| 691 | + * |
|
| 692 | + * @return string The URL to call to perform the feedback deactivation request. |
|
| 693 | + */ |
|
| 694 | + public function get_deactivation_feedback_url() { |
|
| 695 | + |
|
| 696 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'feedbacks'; |
|
| 697 | + |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + /** |
|
| 701 | + * Get the base API URL. |
|
| 702 | + * |
|
| 703 | + * @since 3.20.0 |
|
| 704 | + * |
|
| 705 | + * @return string The base API URL. |
|
| 706 | + */ |
|
| 707 | + public function get_api_url() { |
|
| 708 | + |
|
| 709 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE; |
|
| 710 | + } |
|
| 711 | 711 | |
| 712 | 712 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * @since 3.6.0 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | public function __construct() { |
| 140 | 140 | |
| 141 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 141 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
| 142 | 142 | |
| 143 | 143 | self::$instance = $this; |
| 144 | 144 | |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | * |
| 169 | 169 | * @return mixed The configuration value or the default value if not found. |
| 170 | 170 | */ |
| 171 | - private function get( $option, $key, $default = '' ) { |
|
| 171 | + private function get($option, $key, $default = '') { |
|
| 172 | 172 | |
| 173 | - $options = get_option( $option, array() ); |
|
| 173 | + $options = get_option($option, array()); |
|
| 174 | 174 | |
| 175 | - return isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
| 175 | + return isset($options[$key]) ? $options[$key] : $default; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -184,12 +184,12 @@ discard block |
||
| 184 | 184 | * @param string $key The value key. |
| 185 | 185 | * @param mixed $value The value. |
| 186 | 186 | */ |
| 187 | - private function set( $option, $key, $value ) { |
|
| 187 | + private function set($option, $key, $value) { |
|
| 188 | 188 | |
| 189 | - $values = get_option( $option ); |
|
| 190 | - $values = isset( $values ) ? $values : array(); |
|
| 191 | - $values[ $key ] = $value; |
|
| 192 | - update_option( $option, $values ); |
|
| 189 | + $values = get_option($option); |
|
| 190 | + $values = isset($values) ? $values : array(); |
|
| 191 | + $values[$key] = $value; |
|
| 192 | + update_option($option, $values); |
|
| 193 | 193 | |
| 194 | 194 | } |
| 195 | 195 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | public function get_entity_base_path() { |
| 204 | 204 | |
| 205 | - return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' ); |
|
| 205 | + return $this->get('wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity'); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | * |
| 213 | 213 | * @param string $value The entity base path. |
| 214 | 214 | */ |
| 215 | - public function set_entity_base_path( $value ) { |
|
| 215 | + public function set_entity_base_path($value) { |
|
| 216 | 216 | |
| 217 | - $this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value ); |
|
| 217 | + $this->set('wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value); |
|
| 218 | 218 | |
| 219 | 219 | } |
| 220 | 220 | |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | */ |
| 228 | 228 | public function is_skip_wizard() { |
| 229 | 229 | |
| 230 | - return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false ); |
|
| 230 | + return $this->get('wl_general_settings', self::SKIP_WIZARD, false); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -237,9 +237,9 @@ discard block |
||
| 237 | 237 | * |
| 238 | 238 | * @param bool $value True to skip the wizard. We expect a boolean value. |
| 239 | 239 | */ |
| 240 | - public function set_skip_wizard( $value ) { |
|
| 240 | + public function set_skip_wizard($value) { |
|
| 241 | 241 | |
| 242 | - $this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value ); |
|
| 242 | + $this->set('wl_general_settings', self::SKIP_WIZARD, true === $value); |
|
| 243 | 243 | |
| 244 | 244 | } |
| 245 | 245 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | public function get_key() { |
| 254 | 254 | |
| 255 | - return $this->get( 'wl_general_settings', self::KEY, '' ); |
|
| 255 | + return $this->get('wl_general_settings', self::KEY, ''); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
@@ -262,9 +262,9 @@ discard block |
||
| 262 | 262 | * |
| 263 | 263 | * @param string $value WordLift's key. |
| 264 | 264 | */ |
| 265 | - public function set_key( $value ) { |
|
| 265 | + public function set_key($value) { |
|
| 266 | 266 | |
| 267 | - $this->set( 'wl_general_settings', self::KEY, $value ); |
|
| 267 | + $this->set('wl_general_settings', self::KEY, $value); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | */ |
| 279 | 279 | public function get_language_code() { |
| 280 | 280 | |
| 281 | - return $this->get( 'wl_general_settings', self::LANGUAGE, 'en' ); |
|
| 281 | + return $this->get('wl_general_settings', self::LANGUAGE, 'en'); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -288,9 +288,9 @@ discard block |
||
| 288 | 288 | * |
| 289 | 289 | * @param string $value WordLift's language code. |
| 290 | 290 | */ |
| 291 | - public function set_language_code( $value ) { |
|
| 291 | + public function set_language_code($value) { |
|
| 292 | 292 | |
| 293 | - $this->set( 'wl_general_settings', self::LANGUAGE, $value ); |
|
| 293 | + $this->set('wl_general_settings', self::LANGUAGE, $value); |
|
| 294 | 294 | |
| 295 | 295 | } |
| 296 | 296 | |
@@ -301,9 +301,9 @@ discard block |
||
| 301 | 301 | * |
| 302 | 302 | * @param string $value The user preferences(yes/no). |
| 303 | 303 | */ |
| 304 | - public function set_diagnostic_preferences( $value ) { |
|
| 304 | + public function set_diagnostic_preferences($value) { |
|
| 305 | 305 | |
| 306 | - $this->set( 'wl_general_settings', self::SEND_DIAGNOSTIC, $value ); |
|
| 306 | + $this->set('wl_general_settings', self::SEND_DIAGNOSTIC, $value); |
|
| 307 | 307 | |
| 308 | 308 | } |
| 309 | 309 | |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | */ |
| 315 | 315 | public function get_diagnostic_preferences() { |
| 316 | 316 | |
| 317 | - return $this->get( 'wl_general_settings', self::SEND_DIAGNOSTIC, 'no' ); |
|
| 317 | + return $this->get('wl_general_settings', self::SEND_DIAGNOSTIC, 'no'); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | */ |
| 327 | 327 | public function get_country_code() { |
| 328 | 328 | |
| 329 | - return $this->get( 'wl_general_settings', self::COUNTRY_CODE, 'us' ); |
|
| 329 | + return $this->get('wl_general_settings', self::COUNTRY_CODE, 'us'); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /** |
@@ -336,9 +336,9 @@ discard block |
||
| 336 | 336 | * |
| 337 | 337 | * @param string $value WordLift's country code. |
| 338 | 338 | */ |
| 339 | - public function set_country_code( $value ) { |
|
| 339 | + public function set_country_code($value) { |
|
| 340 | 340 | |
| 341 | - $this->set( 'wl_general_settings', self::COUNTRY_CODE, $value ); |
|
| 341 | + $this->set('wl_general_settings', self::COUNTRY_CODE, $value); |
|
| 342 | 342 | |
| 343 | 343 | } |
| 344 | 344 | |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | */ |
| 355 | 355 | public function get_publisher_id() { |
| 356 | 356 | |
| 357 | - return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null ); |
|
| 357 | + return $this->get('wl_general_settings', self::PUBLISHER_ID, null); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -364,9 +364,9 @@ discard block |
||
| 364 | 364 | * |
| 365 | 365 | * @param int $value The publisher entity post id. |
| 366 | 366 | */ |
| 367 | - public function set_publisher_id( $value ) { |
|
| 367 | + public function set_publisher_id($value) { |
|
| 368 | 368 | |
| 369 | - $this->set( 'wl_general_settings', self::PUBLISHER_ID, $value ); |
|
| 369 | + $this->set('wl_general_settings', self::PUBLISHER_ID, $value); |
|
| 370 | 370 | |
| 371 | 371 | } |
| 372 | 372 | |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | */ |
| 380 | 380 | public function get_dataset_uri() { |
| 381 | 381 | |
| 382 | - return $this->get( 'wl_advanced_settings', self::DATASET_URI, null ); |
|
| 382 | + return $this->get('wl_advanced_settings', self::DATASET_URI, null); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -389,9 +389,9 @@ discard block |
||
| 389 | 389 | * |
| 390 | 390 | * @param string $value The dataset URI. |
| 391 | 391 | */ |
| 392 | - public function set_dataset_uri( $value ) { |
|
| 392 | + public function set_dataset_uri($value) { |
|
| 393 | 393 | |
| 394 | - $this->set( 'wl_advanced_settings', self::DATASET_URI, $value ); |
|
| 394 | + $this->set('wl_advanced_settings', self::DATASET_URI, $value); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | /** |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | */ |
| 404 | 404 | public function get_package_type() { |
| 405 | 405 | |
| 406 | - return $this->get( 'wl_advanced_settings', self::PACKAGE_TYPE, null ); |
|
| 406 | + return $this->get('wl_advanced_settings', self::PACKAGE_TYPE, null); |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -413,9 +413,9 @@ discard block |
||
| 413 | 413 | * |
| 414 | 414 | * @param string $value The package type. |
| 415 | 415 | */ |
| 416 | - public function set_package_type( $value ) { |
|
| 416 | + public function set_package_type($value) { |
|
| 417 | 417 | |
| 418 | - $this->set( 'wl_advanced_settings', self::PACKAGE_TYPE, $value ); |
|
| 418 | + $this->set('wl_advanced_settings', self::PACKAGE_TYPE, $value); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | /** |
@@ -431,11 +431,11 @@ discard block |
||
| 431 | 431 | * @param array $old_value The old settings. |
| 432 | 432 | * @param array $new_value The new settings. |
| 433 | 433 | */ |
| 434 | - public function update_key( $old_value, $new_value ) { |
|
| 434 | + public function update_key($old_value, $new_value) { |
|
| 435 | 435 | |
| 436 | 436 | // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed. |
| 437 | 437 | // $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
| 438 | - $new_key = isset( $new_value['key'] ) ? $new_value['key'] : ''; |
|
| 438 | + $new_key = isset($new_value['key']) ? $new_value['key'] : ''; |
|
| 439 | 439 | |
| 440 | 440 | // If the key hasn't changed, don't do anything. |
| 441 | 441 | // WARN The 'update_option' hook is fired only if the new and old value are not equal. |
@@ -444,12 +444,12 @@ discard block |
||
| 444 | 444 | // } |
| 445 | 445 | |
| 446 | 446 | // If the key is empty, empty the dataset URI. |
| 447 | - if ( '' === $new_key ) { |
|
| 448 | - $this->set_dataset_uri( '' ); |
|
| 447 | + if ('' === $new_key) { |
|
| 448 | + $this->set_dataset_uri(''); |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | // make the request to the remote server. |
| 452 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 452 | + $this->get_remote_dataset_uri($new_key); |
|
| 453 | 453 | |
| 454 | 454 | } |
| 455 | 455 | |
@@ -464,9 +464,9 @@ discard block |
||
| 464 | 464 | * |
| 465 | 465 | * @param string $key The key to be used. |
| 466 | 466 | */ |
| 467 | - public function get_remote_dataset_uri( $key ) { |
|
| 467 | + public function get_remote_dataset_uri($key) { |
|
| 468 | 468 | |
| 469 | - $this->log->trace( 'Getting the remote dataset URI and package type...' ); |
|
| 469 | + $this->log->trace('Getting the remote dataset URI and package type...'); |
|
| 470 | 470 | |
| 471 | 471 | /** |
| 472 | 472 | * Allow 3rd parties to change the site_url. |
@@ -477,37 +477,37 @@ discard block |
||
| 477 | 477 | * |
| 478 | 478 | * @param string $site_url The site url. |
| 479 | 479 | */ |
| 480 | - $site_url = apply_filters( 'wl_production_site_url', site_url() ); |
|
| 480 | + $site_url = apply_filters('wl_production_site_url', site_url()); |
|
| 481 | 481 | |
| 482 | 482 | // Build the URL. |
| 483 | 483 | $url = $this->get_accounts() |
| 484 | - . '?key=' . rawurlencode( $key ) |
|
| 485 | - . '&url=' . rawurlencode( $site_url ) |
|
| 486 | - . '&country=' . $this->get_country_code() |
|
| 487 | - . '&language=' . $this->get_language_code(); |
|
| 484 | + . '?key='.rawurlencode($key) |
|
| 485 | + . '&url='.rawurlencode($site_url) |
|
| 486 | + . '&country='.$this->get_country_code() |
|
| 487 | + . '&language='.$this->get_language_code(); |
|
| 488 | 488 | |
| 489 | - $args = wp_parse_args( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array( |
|
| 489 | + $args = wp_parse_args(unserialize(WL_REDLINK_API_HTTP_OPTIONS), array( |
|
| 490 | 490 | 'method' => 'PUT', |
| 491 | - ) ); |
|
| 491 | + )); |
|
| 492 | 492 | |
| 493 | - $response = wp_remote_request( $url, $args ); |
|
| 493 | + $response = wp_remote_request($url, $args); |
|
| 494 | 494 | |
| 495 | 495 | // The response is an error. |
| 496 | - if ( is_wp_error( $response ) ) { |
|
| 497 | - $this->log->error( 'An error occurred setting the dataset URI: ' . $response->get_error_message() ); |
|
| 496 | + if (is_wp_error($response)) { |
|
| 497 | + $this->log->error('An error occurred setting the dataset URI: '.$response->get_error_message()); |
|
| 498 | 498 | |
| 499 | - $this->set_dataset_uri( '' ); |
|
| 500 | - $this->set_package_type( null ); |
|
| 499 | + $this->set_dataset_uri(''); |
|
| 500 | + $this->set_package_type(null); |
|
| 501 | 501 | |
| 502 | 502 | return; |
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | // The response is not OK. |
| 506 | - if ( 200 !== (int) $response['response']['code'] ) { |
|
| 507 | - $this->log->error( "Unexpected status code when opening URL $url: " . $response['response']['code'] ); |
|
| 506 | + if (200 !== (int) $response['response']['code']) { |
|
| 507 | + $this->log->error("Unexpected status code when opening URL $url: ".$response['response']['code']); |
|
| 508 | 508 | |
| 509 | - $this->set_dataset_uri( '' ); |
|
| 510 | - $this->set_package_type( null ); |
|
| 509 | + $this->set_dataset_uri(''); |
|
| 510 | + $this->set_package_type(null); |
|
| 511 | 511 | |
| 512 | 512 | return; |
| 513 | 513 | } |
@@ -517,14 +517,14 @@ discard block |
||
| 517 | 517 | * |
| 518 | 518 | * @since 3.20.0 |
| 519 | 519 | */ |
| 520 | - $json = json_decode( $response['body'] ); |
|
| 520 | + $json = json_decode($response['body']); |
|
| 521 | 521 | $dataset_uri = $json->datasetURI; |
| 522 | - $package_type = isset( $json->packageType ) ? $json->packageType : null; |
|
| 522 | + $package_type = isset($json->packageType) ? $json->packageType : null; |
|
| 523 | 523 | |
| 524 | - $this->log->info( "Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..." ); |
|
| 524 | + $this->log->info("Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..."); |
|
| 525 | 525 | |
| 526 | - $this->set_dataset_uri( $dataset_uri ); |
|
| 527 | - $this->set_package_type( $package_type ); |
|
| 526 | + $this->set_dataset_uri($dataset_uri); |
|
| 527 | + $this->set_package_type($package_type); |
|
| 528 | 528 | |
| 529 | 529 | } |
| 530 | 530 | |
@@ -543,20 +543,20 @@ discard block |
||
| 543 | 543 | * |
| 544 | 544 | * @return mixed The same value in the $value parameter |
| 545 | 545 | */ |
| 546 | - function maybe_update_dataset_uri( $value, $old_value ) { |
|
| 546 | + function maybe_update_dataset_uri($value, $old_value) { |
|
| 547 | 547 | |
| 548 | 548 | // Check the old key value and the new one. Here we're only handling the |
| 549 | 549 | // case where the key hasn't changed and the dataset URI isn't set. The |
| 550 | 550 | // other case, i.e. a new key is inserted, is handled at `update_key`. |
| 551 | - $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 552 | - $new_key = isset( $value['key'] ) ? $value['key'] : ''; |
|
| 551 | + $old_key = isset($old_value['key']) ? $old_value['key'] : ''; |
|
| 552 | + $new_key = isset($value['key']) ? $value['key'] : ''; |
|
| 553 | 553 | |
| 554 | 554 | $dataset_uri = $this->get_dataset_uri(); |
| 555 | 555 | |
| 556 | - if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) { |
|
| 556 | + if ( ! empty($new_key) && $new_key === $old_key && empty($dataset_uri)) { |
|
| 557 | 557 | |
| 558 | 558 | // make the request to the remote server to try to get the dataset uri. |
| 559 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 559 | + $this->get_remote_dataset_uri($new_key); |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | return $value; |
@@ -571,9 +571,9 @@ discard block |
||
| 571 | 571 | * |
| 572 | 572 | * @return string The API URI. |
| 573 | 573 | */ |
| 574 | - public function get_accounts_by_key_dataset_uri( $key ) { |
|
| 574 | + public function get_accounts_by_key_dataset_uri($key) { |
|
| 575 | 575 | |
| 576 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
|
| 576 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."accounts/key=$key/dataset_uri"; |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
@@ -585,9 +585,9 @@ discard block |
||
| 585 | 585 | * |
| 586 | 586 | * @return string The API URI. |
| 587 | 587 | */ |
| 588 | - public function get_accounts_info_by_key( $key ) { |
|
| 588 | + public function get_accounts_info_by_key($key) { |
|
| 589 | 589 | |
| 590 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/info"; |
|
| 590 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."accounts/info"; |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -599,7 +599,7 @@ discard block |
||
| 599 | 599 | */ |
| 600 | 600 | public function get_accounts() { |
| 601 | 601 | |
| 602 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'accounts'; |
|
| 602 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE.'accounts'; |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | */ |
| 612 | 612 | public function is_link_by_default() { |
| 613 | 613 | |
| 614 | - return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' ); |
|
| 614 | + return 'yes' === $this->get('wl_general_settings', self::LINK_BY_DEFAULT, 'yes'); |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
@@ -621,9 +621,9 @@ discard block |
||
| 621 | 621 | * |
| 622 | 622 | * @param bool $value True to enabling linking by default, otherwise false. |
| 623 | 623 | */ |
| 624 | - public function set_link_by_default( $value ) { |
|
| 624 | + public function set_link_by_default($value) { |
|
| 625 | 625 | |
| 626 | - $this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' ); |
|
| 626 | + $this->set('wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no'); |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | /** |
@@ -634,7 +634,7 @@ discard block |
||
| 634 | 634 | * @return string 'no' or 'yes' representing bool. |
| 635 | 635 | */ |
| 636 | 636 | public function is_analytics_enable() { |
| 637 | - return 'yes' === $this->get( 'wl_analytics_settings', self::ANALYTICS_ENABLE, 'no' ); |
|
| 637 | + return 'yes' === $this->get('wl_analytics_settings', self::ANALYTICS_ENABLE, 'no'); |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | /** |
@@ -644,9 +644,9 @@ discard block |
||
| 644 | 644 | * |
| 645 | 645 | * @param bool $value True to enabling analytics, otherwise false. |
| 646 | 646 | */ |
| 647 | - public function set_is_analytics_enable( $value ) { |
|
| 647 | + public function set_is_analytics_enable($value) { |
|
| 648 | 648 | |
| 649 | - $this->set( 'wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no' ); |
|
| 649 | + $this->set('wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no'); |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | /** |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | * @return int |
| 658 | 658 | */ |
| 659 | 659 | public function get_analytics_entity_uri_dimension() { |
| 660 | - return (int) $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1 ); |
|
| 660 | + return (int) $this->get('wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1); |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | /** |
@@ -668,7 +668,7 @@ discard block |
||
| 668 | 668 | * @return int |
| 669 | 669 | */ |
| 670 | 670 | public function get_analytics_entity_type_dimension() { |
| 671 | - return $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2 ); |
|
| 671 | + return $this->get('wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2); |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | /** |
@@ -680,7 +680,7 @@ discard block |
||
| 680 | 680 | */ |
| 681 | 681 | public function get_autocomplete_url() { |
| 682 | 682 | |
| 683 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'autocomplete'; |
|
| 683 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE.'autocomplete'; |
|
| 684 | 684 | |
| 685 | 685 | } |
| 686 | 686 | |
@@ -693,7 +693,7 @@ discard block |
||
| 693 | 693 | */ |
| 694 | 694 | public function get_deactivation_feedback_url() { |
| 695 | 695 | |
| 696 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'feedbacks'; |
|
| 696 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE.'feedbacks'; |
|
| 697 | 697 | |
| 698 | 698 | } |
| 699 | 699 | |
@@ -17,55 +17,55 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | class Wordlift_Key_Validation_Service { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * A {@link Wordlift_Log_Service} instance. |
|
| 22 | - * |
|
| 23 | - * @since 3.14.0 |
|
| 24 | - * @access private |
|
| 25 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 26 | - */ |
|
| 27 | - private $log; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * The {@link Wordlift_Configuration_Service} instance. |
|
| 31 | - * |
|
| 32 | - * @since 3.14.0 |
|
| 33 | - * @access private |
|
| 34 | - * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
|
| 35 | - */ |
|
| 36 | - private $configuration_service; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Create a {@link Wordlift_Key_Validation_Service} instance. |
|
| 40 | - * |
|
| 41 | - * @since 3.14.0 |
|
| 42 | - * |
|
| 43 | - * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
|
| 44 | - */ |
|
| 45 | - public function __construct( $configuration_service ) { |
|
| 46 | - |
|
| 47 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' ); |
|
| 48 | - |
|
| 49 | - $this->configuration_service = $configuration_service; |
|
| 20 | + /** |
|
| 21 | + * A {@link Wordlift_Log_Service} instance. |
|
| 22 | + * |
|
| 23 | + * @since 3.14.0 |
|
| 24 | + * @access private |
|
| 25 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 26 | + */ |
|
| 27 | + private $log; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * The {@link Wordlift_Configuration_Service} instance. |
|
| 31 | + * |
|
| 32 | + * @since 3.14.0 |
|
| 33 | + * @access private |
|
| 34 | + * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
|
| 35 | + */ |
|
| 36 | + private $configuration_service; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Create a {@link Wordlift_Key_Validation_Service} instance. |
|
| 40 | + * |
|
| 41 | + * @since 3.14.0 |
|
| 42 | + * |
|
| 43 | + * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
|
| 44 | + */ |
|
| 45 | + public function __construct( $configuration_service ) { |
|
| 46 | + |
|
| 47 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' ); |
|
| 48 | + |
|
| 49 | + $this->configuration_service = $configuration_service; |
|
| 50 | 50 | add_action( 'admin_init', array( $this, 'wl_load_plugin' ) ); |
| 51 | 51 | add_action( 'admin_notices', array( $this, 'wl_key_update_notice' ) ); |
| 52 | 52 | |
| 53 | - } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Validate the provided key. |
|
| 57 | - * |
|
| 58 | - * @since 3.9.0 |
|
| 59 | - * |
|
| 60 | - * @param string $key WordLift's key to validate. |
|
| 61 | - * |
|
| 62 | - * @return bool True if the key is valid, otherwise false. |
|
| 63 | - */ |
|
| 64 | - public function is_valid( $key ) { |
|
| 55 | + /** |
|
| 56 | + * Validate the provided key. |
|
| 57 | + * |
|
| 58 | + * @since 3.9.0 |
|
| 59 | + * |
|
| 60 | + * @param string $key WordLift's key to validate. |
|
| 61 | + * |
|
| 62 | + * @return bool True if the key is valid, otherwise false. |
|
| 63 | + */ |
|
| 64 | + public function is_valid( $key ) { |
|
| 65 | 65 | |
| 66 | - $this->log->debug( 'Validating key...' ); |
|
| 66 | + $this->log->debug( 'Validating key...' ); |
|
| 67 | 67 | |
| 68 | - // Request the account info as a way to validate the key |
|
| 68 | + // Request the account info as a way to validate the key |
|
| 69 | 69 | |
| 70 | 70 | $args = array_merge_recursive( |
| 71 | 71 | unserialize( WL_REDLINK_API_HTTP_OPTIONS ), |
@@ -79,22 +79,22 @@ discard block |
||
| 79 | 79 | $response = wp_remote_get( $this->configuration_service->get_accounts_info_by_key( $key ), $args ); |
| 80 | 80 | |
| 81 | 81 | return $response; |
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * This function is hooked to the `wl_validate_key` AJAX call. |
|
| 86 | - * |
|
| 87 | - * @since 3.9.0 |
|
| 88 | - */ |
|
| 89 | - public function validate_key() { |
|
| 90 | - |
|
| 91 | - // Ensure we don't have garbage before us. |
|
| 92 | - ob_clean(); |
|
| 93 | - |
|
| 94 | - // Check if we have a key. |
|
| 95 | - if ( ! isset( $_POST['key'] ) ) { |
|
| 96 | - wp_send_json_error( 'The key parameter is required.' ); |
|
| 97 | - } |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * This function is hooked to the `wl_validate_key` AJAX call. |
|
| 86 | + * |
|
| 87 | + * @since 3.9.0 |
|
| 88 | + */ |
|
| 89 | + public function validate_key() { |
|
| 90 | + |
|
| 91 | + // Ensure we don't have garbage before us. |
|
| 92 | + ob_clean(); |
|
| 93 | + |
|
| 94 | + // Check if we have a key. |
|
| 95 | + if ( ! isset( $_POST['key'] ) ) { |
|
| 96 | + wp_send_json_error( 'The key parameter is required.' ); |
|
| 97 | + } |
|
| 98 | 98 | $response = $this->is_valid( $_POST['key'] ); |
| 99 | 99 | $res_body = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 100 | 100 | $url = $res_body['url']; |
@@ -116,10 +116,10 @@ discard block |
||
| 116 | 116 | $message = ""; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - // Set a response with valid set to true or false according to the key validity with message. |
|
| 120 | - wp_send_json_success( array( 'valid' => $is_valid, 'message' => $message ) ); |
|
| 119 | + // Set a response with valid set to true or false according to the key validity with message. |
|
| 120 | + wp_send_json_success( array( 'valid' => $is_valid, 'message' => $message ) ); |
|
| 121 | 121 | |
| 122 | - } |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * This function is hooked `admin_init` to check _wl_blog_url. |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | { |
| 130 | 130 | $wl_blog_url = get_option( '_wl_blog_url' ); |
| 131 | 131 | if ( !$wl_blog_url ) { |
| 132 | - update_option( '_wl_blog_url', site_url(), true ); |
|
| 132 | + update_option( '_wl_blog_url', site_url(), true ); |
|
| 133 | 133 | } |
| 134 | 134 | if ( $wl_blog_url != site_url() ) { |
| 135 | 135 | Wordlift_Configuration_Service::get_instance()->set_key( '' ); |
@@ -42,13 +42,13 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
| 44 | 44 | */ |
| 45 | - public function __construct( $configuration_service ) { |
|
| 45 | + public function __construct($configuration_service) { |
|
| 46 | 46 | |
| 47 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' ); |
|
| 47 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Key_Validation_Service'); |
|
| 48 | 48 | |
| 49 | 49 | $this->configuration_service = $configuration_service; |
| 50 | - add_action( 'admin_init', array( $this, 'wl_load_plugin' ) ); |
|
| 51 | - add_action( 'admin_notices', array( $this, 'wl_key_update_notice' ) ); |
|
| 50 | + add_action('admin_init', array($this, 'wl_load_plugin')); |
|
| 51 | + add_action('admin_notices', array($this, 'wl_key_update_notice')); |
|
| 52 | 52 | |
| 53 | 53 | } |
| 54 | 54 | |
@@ -61,14 +61,14 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @return bool True if the key is valid, otherwise false. |
| 63 | 63 | */ |
| 64 | - public function is_valid( $key ) { |
|
| 64 | + public function is_valid($key) { |
|
| 65 | 65 | |
| 66 | - $this->log->debug( 'Validating key...' ); |
|
| 66 | + $this->log->debug('Validating key...'); |
|
| 67 | 67 | |
| 68 | 68 | // Request the account info as a way to validate the key |
| 69 | 69 | |
| 70 | 70 | $args = array_merge_recursive( |
| 71 | - unserialize( WL_REDLINK_API_HTTP_OPTIONS ), |
|
| 71 | + unserialize(WL_REDLINK_API_HTTP_OPTIONS), |
|
| 72 | 72 | array( |
| 73 | 73 | 'headers' => array( |
| 74 | 74 | 'Content-Type' => 'application/json; charset=utf-8', |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | ) |
| 77 | 77 | ); |
| 78 | 78 | |
| 79 | - $response = wp_remote_get( $this->configuration_service->get_accounts_info_by_key( $key ), $args ); |
|
| 79 | + $response = wp_remote_get($this->configuration_service->get_accounts_info_by_key($key), $args); |
|
| 80 | 80 | |
| 81 | 81 | return $response; |
| 82 | 82 | } |
@@ -92,32 +92,32 @@ discard block |
||
| 92 | 92 | ob_clean(); |
| 93 | 93 | |
| 94 | 94 | // Check if we have a key. |
| 95 | - if ( ! isset( $_POST['key'] ) ) { |
|
| 96 | - wp_send_json_error( 'The key parameter is required.' ); |
|
| 95 | + if ( ! isset($_POST['key'])) { |
|
| 96 | + wp_send_json_error('The key parameter is required.'); |
|
| 97 | 97 | } |
| 98 | - $response = $this->is_valid( $_POST['key'] ); |
|
| 99 | - $res_body = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 98 | + $response = $this->is_valid($_POST['key']); |
|
| 99 | + $res_body = json_decode(wp_remote_retrieve_body($response), true); |
|
| 100 | 100 | $url = $res_body['url']; |
| 101 | 101 | |
| 102 | 102 | //Set a response with valid set to true and messgae according to the key validity with url match |
| 103 | - if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] && $url == site_url() ) { |
|
| 103 | + if ( ! is_wp_error($response) && 200 === (int) $response['response']['code'] && $url == site_url()) { |
|
| 104 | 104 | $is_valid = true; |
| 105 | 105 | $message = " "; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] && $url != site_url() ) { |
|
| 108 | + if ( ! is_wp_error($response) && 200 === (int) $response['response']['code'] && $url != site_url()) { |
|
| 109 | 109 | $is_valid = false; |
| 110 | - $message = __( "The key is already used on another site, please contact us at [email protected] to move the key to another site.", 'wordlift' ); |
|
| 111 | - Wordlift_Configuration_Service::get_instance()->set_key( '' ); |
|
| 110 | + $message = __("The key is already used on another site, please contact us at [email protected] to move the key to another site.", 'wordlift'); |
|
| 111 | + Wordlift_Configuration_Service::get_instance()->set_key(''); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if ( is_wp_error( $response ) || 500 === (int) $response['response']['code'] ) { |
|
| 114 | + if (is_wp_error($response) || 500 === (int) $response['response']['code']) { |
|
| 115 | 115 | $is_valid = false; |
| 116 | 116 | $message = ""; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | // Set a response with valid set to true or false according to the key validity with message. |
| 120 | - wp_send_json_success( array( 'valid' => $is_valid, 'message' => $message ) ); |
|
| 120 | + wp_send_json_success(array('valid' => $is_valid, 'message' => $message)); |
|
| 121 | 121 | |
| 122 | 122 | } |
| 123 | 123 | |
@@ -127,13 +127,13 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | public function wl_load_plugin() |
| 129 | 129 | { |
| 130 | - $wl_blog_url = get_option( '_wl_blog_url' ); |
|
| 131 | - if ( !$wl_blog_url ) { |
|
| 132 | - update_option( '_wl_blog_url', site_url(), true ); |
|
| 130 | + $wl_blog_url = get_option('_wl_blog_url'); |
|
| 131 | + if ( ! $wl_blog_url) { |
|
| 132 | + update_option('_wl_blog_url', site_url(), true); |
|
| 133 | 133 | } |
| 134 | - if ( $wl_blog_url != site_url() ) { |
|
| 135 | - Wordlift_Configuration_Service::get_instance()->set_key( '' ); |
|
| 136 | - set_transient( 'wl-key-error-msg' , __( "Your web site URL has changed. To avoid data corruption, WordLift's key has been removed. Please provide a new key in WordLift Settings. If you believe this to be an error, please contact us at [email protected]", 'wordlift' ), 10 ); |
|
| 134 | + if ($wl_blog_url != site_url()) { |
|
| 135 | + Wordlift_Configuration_Service::get_instance()->set_key(''); |
|
| 136 | + set_transient('wl-key-error-msg', __("Your web site URL has changed. To avoid data corruption, WordLift's key has been removed. Please provide a new key in WordLift Settings. If you believe this to be an error, please contact us at [email protected]", 'wordlift'), 10); |
|
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | * |
| 143 | 143 | */ |
| 144 | 144 | public function wl_key_update_notice() { |
| 145 | - if ( get_transient( 'wl-key-error-msg' ) ) { |
|
| 145 | + if (get_transient('wl-key-error-msg')) { |
|
| 146 | 146 | ?> |
| 147 | 147 | <div class="updated notice is-dismissible error"> |
| 148 | - <p><?php _e( get_transient('wl-key-error-msg'), 'wordlift' ); ?></p> |
|
| 148 | + <p><?php _e(get_transient('wl-key-error-msg'), 'wordlift'); ?></p> |
|
| 149 | 149 | </div> |
| 150 | 150 | <?php |
| 151 | 151 | } |