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