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