@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | - exit; |
|
| 14 | + exit; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -21,400 +21,400 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class Wordlift_Configuration_Service { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * The entity base path option name. |
|
| 26 | - * |
|
| 27 | - * @since 3.6.0 |
|
| 28 | - */ |
|
| 29 | - const ENTITY_BASE_PATH_KEY = 'wl_entity_base_path'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * The skip wizard (admin installation wizard) option name. |
|
| 33 | - * |
|
| 34 | - * @since 3.9.0 |
|
| 35 | - */ |
|
| 36 | - const SKIP_WIZARD = 'wl_skip_wizard'; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * WordLift's key option name. |
|
| 40 | - * |
|
| 41 | - * @since 3.9.0 |
|
| 42 | - */ |
|
| 43 | - const KEY = 'key'; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * WordLift's configured language option name. |
|
| 47 | - * |
|
| 48 | - * @since 3.9.0 |
|
| 49 | - */ |
|
| 50 | - const LANGUAGE = 'site_language'; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * The publisher entity post ID option name. |
|
| 54 | - * |
|
| 55 | - * @since 3.9.0 |
|
| 56 | - */ |
|
| 57 | - const PUBLISHER_ID = 'publisher_id'; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * The dataset URI option name |
|
| 61 | - * |
|
| 62 | - * @since 3.10.0 |
|
| 63 | - */ |
|
| 64 | - const DATASET_URI = 'redlink_dataset_uri'; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * The link by default option name. |
|
| 68 | - * |
|
| 69 | - * @since 3.11.0 |
|
| 70 | - */ |
|
| 71 | - const LINK_BY_DEFAULT = 'link_by_default'; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * The Wordlift_Configuration_Service's singleton instance. |
|
| 75 | - * |
|
| 76 | - * @since 3.6.0 |
|
| 77 | - * |
|
| 78 | - * @access private |
|
| 79 | - * @var \Wordlift_Configuration_Service $instance Wordlift_Configuration_Service's singleton instance. |
|
| 80 | - */ |
|
| 81 | - private static $instance; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Create a Wordlift_Configuration_Service's instance. |
|
| 85 | - * |
|
| 86 | - * @since 3.6.0 |
|
| 87 | - */ |
|
| 88 | - public function __construct() { |
|
| 89 | - |
|
| 90 | - self::$instance = $this; |
|
| 91 | - |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Get the singleton instance. |
|
| 96 | - * |
|
| 97 | - * @since 3.6.0 |
|
| 98 | - * |
|
| 99 | - * @return \Wordlift_Configuration_Service |
|
| 100 | - */ |
|
| 101 | - public static function get_instance() { |
|
| 102 | - |
|
| 103 | - return self::$instance; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Get a configuration given the option name and a key. The option value is |
|
| 108 | - * expected to be an array. |
|
| 109 | - * |
|
| 110 | - * @since 3.6.0 |
|
| 111 | - * |
|
| 112 | - * @param string $option The option name. |
|
| 113 | - * @param string $key A key in the option value array. |
|
| 114 | - * @param string $default The default value in case the key is not found (by default an empty string). |
|
| 115 | - * |
|
| 116 | - * @return mixed The configuration value or the default value if not found. |
|
| 117 | - */ |
|
| 118 | - private function get( $option, $key, $default = '' ) { |
|
| 119 | - |
|
| 120 | - $options = get_option( $option, array() ); |
|
| 121 | - |
|
| 122 | - return isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Set a configuration parameter. |
|
| 127 | - * |
|
| 128 | - * @since 3.9.0 |
|
| 129 | - * |
|
| 130 | - * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. |
|
| 131 | - * @param string $key The value key. |
|
| 132 | - * @param mixed $value The value. |
|
| 133 | - */ |
|
| 134 | - private function set( $option, $key, $value ) { |
|
| 135 | - |
|
| 136 | - $values = get_option( $option ); |
|
| 137 | - $values = isset( $values ) ? $values : array(); |
|
| 138 | - $values[ $key ] = $value; |
|
| 139 | - update_option( $option, $values ); |
|
| 140 | - |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Get the entity base path, by default 'entity'. |
|
| 145 | - * |
|
| 146 | - * @since 3.6.0 |
|
| 147 | - * |
|
| 148 | - * @return string The entity base path. |
|
| 149 | - */ |
|
| 150 | - public function get_entity_base_path() { |
|
| 151 | - |
|
| 152 | - return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' ); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Get the entity base path. |
|
| 157 | - * |
|
| 158 | - * @since 3.9.0 |
|
| 159 | - * |
|
| 160 | - * @param string $value The entity base path. |
|
| 161 | - */ |
|
| 162 | - public function set_entity_base_path( $value ) { |
|
| 163 | - |
|
| 164 | - $this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value ); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Whether the installation skip wizard should be skipped. |
|
| 169 | - * |
|
| 170 | - * @since 3.9.0 |
|
| 171 | - * |
|
| 172 | - * @return bool True if it should be skipped otherwise false. |
|
| 173 | - */ |
|
| 174 | - public function is_skip_wizard() { |
|
| 175 | - |
|
| 176 | - return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false ); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Set the skip wizard parameter. |
|
| 181 | - * |
|
| 182 | - * @since 3.9.0 |
|
| 183 | - * |
|
| 184 | - * @param bool $value True to skip the wizard. We expect a boolean value. |
|
| 185 | - */ |
|
| 186 | - public function set_skip_wizard( $value ) { |
|
| 187 | - |
|
| 188 | - $this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value ); |
|
| 189 | - |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Get WordLift's key. |
|
| 194 | - * |
|
| 195 | - * @since 3.9.0 |
|
| 196 | - * |
|
| 197 | - * @return string WordLift's key or an empty string if not set. |
|
| 198 | - */ |
|
| 199 | - public function get_key() { |
|
| 200 | - |
|
| 201 | - return $this->get( 'wl_general_settings', self::KEY, '' ); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Set WordLift's key. |
|
| 206 | - * |
|
| 207 | - * @since 3.9.0 |
|
| 208 | - * |
|
| 209 | - * @param string $value WordLift's key. |
|
| 210 | - */ |
|
| 211 | - public function set_key( $value ) { |
|
| 212 | - |
|
| 213 | - $this->set( 'wl_general_settings', self::KEY, $value ); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Get WordLift's configured language, by default 'en'. |
|
| 218 | - * |
|
| 219 | - * Note that WordLift's language is used when writing strings to the Linked Data dataset, not for the analysis. |
|
| 220 | - * |
|
| 221 | - * @since 3.9.0 |
|
| 222 | - * |
|
| 223 | - * @return string WordLift's configured language code ('en' by default). |
|
| 224 | - */ |
|
| 225 | - public function get_language_code() { |
|
| 226 | - |
|
| 227 | - return $this->get( 'wl_general_settings', self::LANGUAGE, 'en' ); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Set WordLift's language code, used when storing strings to the Linked Data dataset. |
|
| 232 | - * |
|
| 233 | - * @since 3.9.0 |
|
| 234 | - * |
|
| 235 | - * @param string $value WordLift's language code. |
|
| 236 | - */ |
|
| 237 | - public function set_language_code( $value ) { |
|
| 238 | - |
|
| 239 | - $this->set( 'wl_general_settings', self::LANGUAGE, $value ); |
|
| 240 | - |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Get the publisher entity post id. |
|
| 245 | - * |
|
| 246 | - * The publisher entity post id points to an entity post which contains the data for the publisher used in schema.org |
|
| 247 | - * Article markup. |
|
| 248 | - * |
|
| 249 | - * @since 3.9.0 |
|
| 250 | - * |
|
| 251 | - * @return int|NULL The publisher entity post id or NULL if not set. |
|
| 252 | - */ |
|
| 253 | - public function get_publisher_id() { |
|
| 254 | - |
|
| 255 | - return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null ); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Set the publisher entity post id. |
|
| 260 | - * |
|
| 261 | - * @since 3.9.0 |
|
| 262 | - * |
|
| 263 | - * @param int $value The publisher entity post id. |
|
| 264 | - */ |
|
| 265 | - public function set_publisher_id( $value ) { |
|
| 266 | - |
|
| 267 | - $this->set( 'wl_general_settings', self::PUBLISHER_ID, $value ); |
|
| 268 | - |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Get the dataset URI. |
|
| 273 | - * |
|
| 274 | - * @since 3.10.0 |
|
| 275 | - * |
|
| 276 | - * @return string The dataset URI or an empty string if not set. |
|
| 277 | - */ |
|
| 278 | - public function get_dataset_uri() { |
|
| 279 | - |
|
| 280 | - return $this->get( 'wl_advanced_settings', self::DATASET_URI, null ); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Set the dataset URI. |
|
| 285 | - * |
|
| 286 | - * @since 3.10.0 |
|
| 287 | - * |
|
| 288 | - * @param string $value The dataset URI. |
|
| 289 | - */ |
|
| 290 | - public function set_dataset_uri( $value ) { |
|
| 291 | - |
|
| 292 | - $this->set( 'wl_advanced_settings', self::DATASET_URI, $value ); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Intercept the change of the WordLift key in order to set the dataset URI. |
|
| 297 | - * |
|
| 298 | - * @since 3.11.0 |
|
| 299 | - * |
|
| 300 | - * @param array $old_value The old settings. |
|
| 301 | - * @param array $new_value The new settings. |
|
| 302 | - */ |
|
| 303 | - public function update_key( $old_value, $new_value ) { |
|
| 304 | - |
|
| 305 | - // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed. |
|
| 306 | - $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 307 | - $new_key = isset( $new_value['key'] ) ? $new_value['key'] : ''; |
|
| 308 | - |
|
| 309 | - // If the key hasn't changed, don't do anything. |
|
| 310 | - // WARN The 'update_option' hook is fired only if the new and old value are not equal |
|
| 311 | - if ( $old_key === $new_key ) { |
|
| 312 | - return; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - // If the key is empty, empty the dataset URI. |
|
| 316 | - if ( '' === $new_key ) { |
|
| 317 | - $this->set_dataset_uri( '' ); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - // make the request to the remote server |
|
| 321 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * Handle retrieving the dataset uri from the remote server. |
|
| 326 | - * |
|
| 327 | - * If a valid dataset uri is returned it is stored in the appropriate option, |
|
| 328 | - * otherwise the option is set to empty string. |
|
| 329 | - * |
|
| 330 | - * @since 3.12.0 |
|
| 331 | - * |
|
| 332 | - * @param string $key The key to be used |
|
| 333 | - * |
|
| 334 | - */ |
|
| 335 | - private function get_remote_dataset_uri( $key ) { |
|
| 336 | - // Request the dataset URI. |
|
| 337 | - $response = wp_remote_get( $this->get_accounts_by_key_dataset_uri( $key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) ); |
|
| 338 | - |
|
| 339 | - // If the response is valid, then set the value. |
|
| 340 | - if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) { |
|
| 341 | - $this->set_dataset_uri( $response['body'] ); |
|
| 342 | - } else { |
|
| 343 | - $this->set_dataset_uri( '' ); |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * Handle the edge case where a user submits the same key again |
|
| 349 | - * when he does not have the dataset uri to regain it. |
|
| 350 | - * |
|
| 351 | - * This can not be handled in the normal option update hook because |
|
| 352 | - * it is not being triggered when the save value equals to the one already |
|
| 353 | - * in the DB. |
|
| 354 | - * |
|
| 355 | - * @since 3.12.0 |
|
| 356 | - * |
|
| 357 | - * @param mixed $value The new, unserialized option value. |
|
| 358 | - * @param mixed $old_value The old option value. |
|
| 359 | - * |
|
| 360 | - * @return mixed The same value in the $value parameter |
|
| 361 | - * |
|
| 362 | - */ |
|
| 363 | - function maybe_update_dataset_uri( $value, $old_value ) { |
|
| 364 | - |
|
| 365 | - // Check the old key value and the new one. Here we're only handling the |
|
| 366 | - // case where the key hasn't changed and the dataset URI isn't set. The |
|
| 367 | - // other case, i.e. a new key is inserted, is handled at `update_key`. |
|
| 368 | - $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 369 | - $new_key = isset( $value['key'] ) ? $value['key'] : ''; |
|
| 370 | - |
|
| 371 | - $dataset_uri = $this->get_dataset_uri(); |
|
| 372 | - |
|
| 373 | - if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) { |
|
| 374 | - |
|
| 375 | - // make the request to the remote server to try to get the dataset uri |
|
| 376 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - return $value; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Get the API URI to retrieve the dataset URI using the WordLift Key. |
|
| 384 | - * |
|
| 385 | - * @since 3.11.0 |
|
| 386 | - * |
|
| 387 | - * @param string $key The WordLift key to use. |
|
| 388 | - * |
|
| 389 | - * @return string The API URI. |
|
| 390 | - */ |
|
| 391 | - public function get_accounts_by_key_dataset_uri( $key ) { |
|
| 392 | - |
|
| 393 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Get the `link by default` option. |
|
| 398 | - * |
|
| 399 | - * @since 3.13.0 |
|
| 400 | - * |
|
| 401 | - * @return bool True if entities must be linked by default otherwise false. |
|
| 402 | - */ |
|
| 403 | - public function is_link_by_default() { |
|
| 404 | - |
|
| 405 | - return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' ); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * Set the `link by default` option. |
|
| 410 | - * |
|
| 411 | - * @since 3.13.0 |
|
| 412 | - * |
|
| 413 | - * @param bool $value True to enabling linking by default, otherwise false. |
|
| 414 | - */ |
|
| 415 | - public function set_link_by_default( $value ) { |
|
| 416 | - |
|
| 417 | - $this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' ); |
|
| 418 | - } |
|
| 24 | + /** |
|
| 25 | + * The entity base path option name. |
|
| 26 | + * |
|
| 27 | + * @since 3.6.0 |
|
| 28 | + */ |
|
| 29 | + const ENTITY_BASE_PATH_KEY = 'wl_entity_base_path'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * The skip wizard (admin installation wizard) option name. |
|
| 33 | + * |
|
| 34 | + * @since 3.9.0 |
|
| 35 | + */ |
|
| 36 | + const SKIP_WIZARD = 'wl_skip_wizard'; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * WordLift's key option name. |
|
| 40 | + * |
|
| 41 | + * @since 3.9.0 |
|
| 42 | + */ |
|
| 43 | + const KEY = 'key'; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * WordLift's configured language option name. |
|
| 47 | + * |
|
| 48 | + * @since 3.9.0 |
|
| 49 | + */ |
|
| 50 | + const LANGUAGE = 'site_language'; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * The publisher entity post ID option name. |
|
| 54 | + * |
|
| 55 | + * @since 3.9.0 |
|
| 56 | + */ |
|
| 57 | + const PUBLISHER_ID = 'publisher_id'; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * The dataset URI option name |
|
| 61 | + * |
|
| 62 | + * @since 3.10.0 |
|
| 63 | + */ |
|
| 64 | + const DATASET_URI = 'redlink_dataset_uri'; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * The link by default option name. |
|
| 68 | + * |
|
| 69 | + * @since 3.11.0 |
|
| 70 | + */ |
|
| 71 | + const LINK_BY_DEFAULT = 'link_by_default'; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * The Wordlift_Configuration_Service's singleton instance. |
|
| 75 | + * |
|
| 76 | + * @since 3.6.0 |
|
| 77 | + * |
|
| 78 | + * @access private |
|
| 79 | + * @var \Wordlift_Configuration_Service $instance Wordlift_Configuration_Service's singleton instance. |
|
| 80 | + */ |
|
| 81 | + private static $instance; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Create a Wordlift_Configuration_Service's instance. |
|
| 85 | + * |
|
| 86 | + * @since 3.6.0 |
|
| 87 | + */ |
|
| 88 | + public function __construct() { |
|
| 89 | + |
|
| 90 | + self::$instance = $this; |
|
| 91 | + |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Get the singleton instance. |
|
| 96 | + * |
|
| 97 | + * @since 3.6.0 |
|
| 98 | + * |
|
| 99 | + * @return \Wordlift_Configuration_Service |
|
| 100 | + */ |
|
| 101 | + public static function get_instance() { |
|
| 102 | + |
|
| 103 | + return self::$instance; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Get a configuration given the option name and a key. The option value is |
|
| 108 | + * expected to be an array. |
|
| 109 | + * |
|
| 110 | + * @since 3.6.0 |
|
| 111 | + * |
|
| 112 | + * @param string $option The option name. |
|
| 113 | + * @param string $key A key in the option value array. |
|
| 114 | + * @param string $default The default value in case the key is not found (by default an empty string). |
|
| 115 | + * |
|
| 116 | + * @return mixed The configuration value or the default value if not found. |
|
| 117 | + */ |
|
| 118 | + private function get( $option, $key, $default = '' ) { |
|
| 119 | + |
|
| 120 | + $options = get_option( $option, array() ); |
|
| 121 | + |
|
| 122 | + return isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Set a configuration parameter. |
|
| 127 | + * |
|
| 128 | + * @since 3.9.0 |
|
| 129 | + * |
|
| 130 | + * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. |
|
| 131 | + * @param string $key The value key. |
|
| 132 | + * @param mixed $value The value. |
|
| 133 | + */ |
|
| 134 | + private function set( $option, $key, $value ) { |
|
| 135 | + |
|
| 136 | + $values = get_option( $option ); |
|
| 137 | + $values = isset( $values ) ? $values : array(); |
|
| 138 | + $values[ $key ] = $value; |
|
| 139 | + update_option( $option, $values ); |
|
| 140 | + |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Get the entity base path, by default 'entity'. |
|
| 145 | + * |
|
| 146 | + * @since 3.6.0 |
|
| 147 | + * |
|
| 148 | + * @return string The entity base path. |
|
| 149 | + */ |
|
| 150 | + public function get_entity_base_path() { |
|
| 151 | + |
|
| 152 | + return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' ); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Get the entity base path. |
|
| 157 | + * |
|
| 158 | + * @since 3.9.0 |
|
| 159 | + * |
|
| 160 | + * @param string $value The entity base path. |
|
| 161 | + */ |
|
| 162 | + public function set_entity_base_path( $value ) { |
|
| 163 | + |
|
| 164 | + $this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value ); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Whether the installation skip wizard should be skipped. |
|
| 169 | + * |
|
| 170 | + * @since 3.9.0 |
|
| 171 | + * |
|
| 172 | + * @return bool True if it should be skipped otherwise false. |
|
| 173 | + */ |
|
| 174 | + public function is_skip_wizard() { |
|
| 175 | + |
|
| 176 | + return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false ); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Set the skip wizard parameter. |
|
| 181 | + * |
|
| 182 | + * @since 3.9.0 |
|
| 183 | + * |
|
| 184 | + * @param bool $value True to skip the wizard. We expect a boolean value. |
|
| 185 | + */ |
|
| 186 | + public function set_skip_wizard( $value ) { |
|
| 187 | + |
|
| 188 | + $this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value ); |
|
| 189 | + |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Get WordLift's key. |
|
| 194 | + * |
|
| 195 | + * @since 3.9.0 |
|
| 196 | + * |
|
| 197 | + * @return string WordLift's key or an empty string if not set. |
|
| 198 | + */ |
|
| 199 | + public function get_key() { |
|
| 200 | + |
|
| 201 | + return $this->get( 'wl_general_settings', self::KEY, '' ); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Set WordLift's key. |
|
| 206 | + * |
|
| 207 | + * @since 3.9.0 |
|
| 208 | + * |
|
| 209 | + * @param string $value WordLift's key. |
|
| 210 | + */ |
|
| 211 | + public function set_key( $value ) { |
|
| 212 | + |
|
| 213 | + $this->set( 'wl_general_settings', self::KEY, $value ); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Get WordLift's configured language, by default 'en'. |
|
| 218 | + * |
|
| 219 | + * Note that WordLift's language is used when writing strings to the Linked Data dataset, not for the analysis. |
|
| 220 | + * |
|
| 221 | + * @since 3.9.0 |
|
| 222 | + * |
|
| 223 | + * @return string WordLift's configured language code ('en' by default). |
|
| 224 | + */ |
|
| 225 | + public function get_language_code() { |
|
| 226 | + |
|
| 227 | + return $this->get( 'wl_general_settings', self::LANGUAGE, 'en' ); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Set WordLift's language code, used when storing strings to the Linked Data dataset. |
|
| 232 | + * |
|
| 233 | + * @since 3.9.0 |
|
| 234 | + * |
|
| 235 | + * @param string $value WordLift's language code. |
|
| 236 | + */ |
|
| 237 | + public function set_language_code( $value ) { |
|
| 238 | + |
|
| 239 | + $this->set( 'wl_general_settings', self::LANGUAGE, $value ); |
|
| 240 | + |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Get the publisher entity post id. |
|
| 245 | + * |
|
| 246 | + * The publisher entity post id points to an entity post which contains the data for the publisher used in schema.org |
|
| 247 | + * Article markup. |
|
| 248 | + * |
|
| 249 | + * @since 3.9.0 |
|
| 250 | + * |
|
| 251 | + * @return int|NULL The publisher entity post id or NULL if not set. |
|
| 252 | + */ |
|
| 253 | + public function get_publisher_id() { |
|
| 254 | + |
|
| 255 | + return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null ); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Set the publisher entity post id. |
|
| 260 | + * |
|
| 261 | + * @since 3.9.0 |
|
| 262 | + * |
|
| 263 | + * @param int $value The publisher entity post id. |
|
| 264 | + */ |
|
| 265 | + public function set_publisher_id( $value ) { |
|
| 266 | + |
|
| 267 | + $this->set( 'wl_general_settings', self::PUBLISHER_ID, $value ); |
|
| 268 | + |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Get the dataset URI. |
|
| 273 | + * |
|
| 274 | + * @since 3.10.0 |
|
| 275 | + * |
|
| 276 | + * @return string The dataset URI or an empty string if not set. |
|
| 277 | + */ |
|
| 278 | + public function get_dataset_uri() { |
|
| 279 | + |
|
| 280 | + return $this->get( 'wl_advanced_settings', self::DATASET_URI, null ); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Set the dataset URI. |
|
| 285 | + * |
|
| 286 | + * @since 3.10.0 |
|
| 287 | + * |
|
| 288 | + * @param string $value The dataset URI. |
|
| 289 | + */ |
|
| 290 | + public function set_dataset_uri( $value ) { |
|
| 291 | + |
|
| 292 | + $this->set( 'wl_advanced_settings', self::DATASET_URI, $value ); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Intercept the change of the WordLift key in order to set the dataset URI. |
|
| 297 | + * |
|
| 298 | + * @since 3.11.0 |
|
| 299 | + * |
|
| 300 | + * @param array $old_value The old settings. |
|
| 301 | + * @param array $new_value The new settings. |
|
| 302 | + */ |
|
| 303 | + public function update_key( $old_value, $new_value ) { |
|
| 304 | + |
|
| 305 | + // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed. |
|
| 306 | + $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 307 | + $new_key = isset( $new_value['key'] ) ? $new_value['key'] : ''; |
|
| 308 | + |
|
| 309 | + // If the key hasn't changed, don't do anything. |
|
| 310 | + // WARN The 'update_option' hook is fired only if the new and old value are not equal |
|
| 311 | + if ( $old_key === $new_key ) { |
|
| 312 | + return; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + // If the key is empty, empty the dataset URI. |
|
| 316 | + if ( '' === $new_key ) { |
|
| 317 | + $this->set_dataset_uri( '' ); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + // make the request to the remote server |
|
| 321 | + $this->get_remote_dataset_uri( $new_key ); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * Handle retrieving the dataset uri from the remote server. |
|
| 326 | + * |
|
| 327 | + * If a valid dataset uri is returned it is stored in the appropriate option, |
|
| 328 | + * otherwise the option is set to empty string. |
|
| 329 | + * |
|
| 330 | + * @since 3.12.0 |
|
| 331 | + * |
|
| 332 | + * @param string $key The key to be used |
|
| 333 | + * |
|
| 334 | + */ |
|
| 335 | + private function get_remote_dataset_uri( $key ) { |
|
| 336 | + // Request the dataset URI. |
|
| 337 | + $response = wp_remote_get( $this->get_accounts_by_key_dataset_uri( $key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) ); |
|
| 338 | + |
|
| 339 | + // If the response is valid, then set the value. |
|
| 340 | + if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) { |
|
| 341 | + $this->set_dataset_uri( $response['body'] ); |
|
| 342 | + } else { |
|
| 343 | + $this->set_dataset_uri( '' ); |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * Handle the edge case where a user submits the same key again |
|
| 349 | + * when he does not have the dataset uri to regain it. |
|
| 350 | + * |
|
| 351 | + * This can not be handled in the normal option update hook because |
|
| 352 | + * it is not being triggered when the save value equals to the one already |
|
| 353 | + * in the DB. |
|
| 354 | + * |
|
| 355 | + * @since 3.12.0 |
|
| 356 | + * |
|
| 357 | + * @param mixed $value The new, unserialized option value. |
|
| 358 | + * @param mixed $old_value The old option value. |
|
| 359 | + * |
|
| 360 | + * @return mixed The same value in the $value parameter |
|
| 361 | + * |
|
| 362 | + */ |
|
| 363 | + function maybe_update_dataset_uri( $value, $old_value ) { |
|
| 364 | + |
|
| 365 | + // Check the old key value and the new one. Here we're only handling the |
|
| 366 | + // case where the key hasn't changed and the dataset URI isn't set. The |
|
| 367 | + // other case, i.e. a new key is inserted, is handled at `update_key`. |
|
| 368 | + $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 369 | + $new_key = isset( $value['key'] ) ? $value['key'] : ''; |
|
| 370 | + |
|
| 371 | + $dataset_uri = $this->get_dataset_uri(); |
|
| 372 | + |
|
| 373 | + if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) { |
|
| 374 | + |
|
| 375 | + // make the request to the remote server to try to get the dataset uri |
|
| 376 | + $this->get_remote_dataset_uri( $new_key ); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + return $value; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Get the API URI to retrieve the dataset URI using the WordLift Key. |
|
| 384 | + * |
|
| 385 | + * @since 3.11.0 |
|
| 386 | + * |
|
| 387 | + * @param string $key The WordLift key to use. |
|
| 388 | + * |
|
| 389 | + * @return string The API URI. |
|
| 390 | + */ |
|
| 391 | + public function get_accounts_by_key_dataset_uri( $key ) { |
|
| 392 | + |
|
| 393 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Get the `link by default` option. |
|
| 398 | + * |
|
| 399 | + * @since 3.13.0 |
|
| 400 | + * |
|
| 401 | + * @return bool True if entities must be linked by default otherwise false. |
|
| 402 | + */ |
|
| 403 | + public function is_link_by_default() { |
|
| 404 | + |
|
| 405 | + return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' ); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * Set the `link by default` option. |
|
| 410 | + * |
|
| 411 | + * @since 3.13.0 |
|
| 412 | + * |
|
| 413 | + * @param bool $value True to enabling linking by default, otherwise false. |
|
| 414 | + */ |
|
| 415 | + public function set_link_by_default( $value ) { |
|
| 416 | + |
|
| 417 | + $this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' ); |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | 420 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * @since 3.6.0 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -115,11 +115,11 @@ discard block |
||
| 115 | 115 | * |
| 116 | 116 | * @return mixed The configuration value or the default value if not found. |
| 117 | 117 | */ |
| 118 | - private function get( $option, $key, $default = '' ) { |
|
| 118 | + private function get($option, $key, $default = '') { |
|
| 119 | 119 | |
| 120 | - $options = get_option( $option, array() ); |
|
| 120 | + $options = get_option($option, array()); |
|
| 121 | 121 | |
| 122 | - return isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
| 122 | + return isset($options[$key]) ? $options[$key] : $default; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -131,12 +131,12 @@ discard block |
||
| 131 | 131 | * @param string $key The value key. |
| 132 | 132 | * @param mixed $value The value. |
| 133 | 133 | */ |
| 134 | - private function set( $option, $key, $value ) { |
|
| 134 | + private function set($option, $key, $value) { |
|
| 135 | 135 | |
| 136 | - $values = get_option( $option ); |
|
| 137 | - $values = isset( $values ) ? $values : array(); |
|
| 138 | - $values[ $key ] = $value; |
|
| 139 | - update_option( $option, $values ); |
|
| 136 | + $values = get_option($option); |
|
| 137 | + $values = isset($values) ? $values : array(); |
|
| 138 | + $values[$key] = $value; |
|
| 139 | + update_option($option, $values); |
|
| 140 | 140 | |
| 141 | 141 | } |
| 142 | 142 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | public function get_entity_base_path() { |
| 151 | 151 | |
| 152 | - return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' ); |
|
| 152 | + return $this->get('wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity'); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -159,9 +159,9 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @param string $value The entity base path. |
| 161 | 161 | */ |
| 162 | - public function set_entity_base_path( $value ) { |
|
| 162 | + public function set_entity_base_path($value) { |
|
| 163 | 163 | |
| 164 | - $this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value ); |
|
| 164 | + $this->set('wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | public function is_skip_wizard() { |
| 175 | 175 | |
| 176 | - return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false ); |
|
| 176 | + return $this->get('wl_general_settings', self::SKIP_WIZARD, false); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -183,9 +183,9 @@ discard block |
||
| 183 | 183 | * |
| 184 | 184 | * @param bool $value True to skip the wizard. We expect a boolean value. |
| 185 | 185 | */ |
| 186 | - public function set_skip_wizard( $value ) { |
|
| 186 | + public function set_skip_wizard($value) { |
|
| 187 | 187 | |
| 188 | - $this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value ); |
|
| 188 | + $this->set('wl_general_settings', self::SKIP_WIZARD, true === $value); |
|
| 189 | 189 | |
| 190 | 190 | } |
| 191 | 191 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | public function get_key() { |
| 200 | 200 | |
| 201 | - return $this->get( 'wl_general_settings', self::KEY, '' ); |
|
| 201 | + return $this->get('wl_general_settings', self::KEY, ''); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -208,9 +208,9 @@ discard block |
||
| 208 | 208 | * |
| 209 | 209 | * @param string $value WordLift's key. |
| 210 | 210 | */ |
| 211 | - public function set_key( $value ) { |
|
| 211 | + public function set_key($value) { |
|
| 212 | 212 | |
| 213 | - $this->set( 'wl_general_settings', self::KEY, $value ); |
|
| 213 | + $this->set('wl_general_settings', self::KEY, $value); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | public function get_language_code() { |
| 226 | 226 | |
| 227 | - return $this->get( 'wl_general_settings', self::LANGUAGE, 'en' ); |
|
| 227 | + return $this->get('wl_general_settings', self::LANGUAGE, 'en'); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -234,9 +234,9 @@ discard block |
||
| 234 | 234 | * |
| 235 | 235 | * @param string $value WordLift's language code. |
| 236 | 236 | */ |
| 237 | - public function set_language_code( $value ) { |
|
| 237 | + public function set_language_code($value) { |
|
| 238 | 238 | |
| 239 | - $this->set( 'wl_general_settings', self::LANGUAGE, $value ); |
|
| 239 | + $this->set('wl_general_settings', self::LANGUAGE, $value); |
|
| 240 | 240 | |
| 241 | 241 | } |
| 242 | 242 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | public function get_publisher_id() { |
| 254 | 254 | |
| 255 | - return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null ); |
|
| 255 | + return $this->get('wl_general_settings', self::PUBLISHER_ID, null); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
@@ -262,9 +262,9 @@ discard block |
||
| 262 | 262 | * |
| 263 | 263 | * @param int $value The publisher entity post id. |
| 264 | 264 | */ |
| 265 | - public function set_publisher_id( $value ) { |
|
| 265 | + public function set_publisher_id($value) { |
|
| 266 | 266 | |
| 267 | - $this->set( 'wl_general_settings', self::PUBLISHER_ID, $value ); |
|
| 267 | + $this->set('wl_general_settings', self::PUBLISHER_ID, $value); |
|
| 268 | 268 | |
| 269 | 269 | } |
| 270 | 270 | |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | public function get_dataset_uri() { |
| 279 | 279 | |
| 280 | - return $this->get( 'wl_advanced_settings', self::DATASET_URI, null ); |
|
| 280 | + return $this->get('wl_advanced_settings', self::DATASET_URI, null); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -287,9 +287,9 @@ discard block |
||
| 287 | 287 | * |
| 288 | 288 | * @param string $value The dataset URI. |
| 289 | 289 | */ |
| 290 | - public function set_dataset_uri( $value ) { |
|
| 290 | + public function set_dataset_uri($value) { |
|
| 291 | 291 | |
| 292 | - $this->set( 'wl_advanced_settings', self::DATASET_URI, $value ); |
|
| 292 | + $this->set('wl_advanced_settings', self::DATASET_URI, $value); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -300,25 +300,25 @@ discard block |
||
| 300 | 300 | * @param array $old_value The old settings. |
| 301 | 301 | * @param array $new_value The new settings. |
| 302 | 302 | */ |
| 303 | - public function update_key( $old_value, $new_value ) { |
|
| 303 | + public function update_key($old_value, $new_value) { |
|
| 304 | 304 | |
| 305 | 305 | // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed. |
| 306 | - $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 307 | - $new_key = isset( $new_value['key'] ) ? $new_value['key'] : ''; |
|
| 306 | + $old_key = isset($old_value['key']) ? $old_value['key'] : ''; |
|
| 307 | + $new_key = isset($new_value['key']) ? $new_value['key'] : ''; |
|
| 308 | 308 | |
| 309 | 309 | // If the key hasn't changed, don't do anything. |
| 310 | 310 | // WARN The 'update_option' hook is fired only if the new and old value are not equal |
| 311 | - if ( $old_key === $new_key ) { |
|
| 311 | + if ($old_key === $new_key) { |
|
| 312 | 312 | return; |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | // If the key is empty, empty the dataset URI. |
| 316 | - if ( '' === $new_key ) { |
|
| 317 | - $this->set_dataset_uri( '' ); |
|
| 316 | + if ('' === $new_key) { |
|
| 317 | + $this->set_dataset_uri(''); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | // make the request to the remote server |
| 321 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 321 | + $this->get_remote_dataset_uri($new_key); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
@@ -332,15 +332,15 @@ discard block |
||
| 332 | 332 | * @param string $key The key to be used |
| 333 | 333 | * |
| 334 | 334 | */ |
| 335 | - private function get_remote_dataset_uri( $key ) { |
|
| 335 | + private function get_remote_dataset_uri($key) { |
|
| 336 | 336 | // Request the dataset URI. |
| 337 | - $response = wp_remote_get( $this->get_accounts_by_key_dataset_uri( $key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) ); |
|
| 337 | + $response = wp_remote_get($this->get_accounts_by_key_dataset_uri($key), unserialize(WL_REDLINK_API_HTTP_OPTIONS)); |
|
| 338 | 338 | |
| 339 | 339 | // If the response is valid, then set the value. |
| 340 | - if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) { |
|
| 341 | - $this->set_dataset_uri( $response['body'] ); |
|
| 340 | + if ( ! is_wp_error($response) && 200 === (int) $response['response']['code']) { |
|
| 341 | + $this->set_dataset_uri($response['body']); |
|
| 342 | 342 | } else { |
| 343 | - $this->set_dataset_uri( '' ); |
|
| 343 | + $this->set_dataset_uri(''); |
|
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | |
@@ -360,20 +360,20 @@ discard block |
||
| 360 | 360 | * @return mixed The same value in the $value parameter |
| 361 | 361 | * |
| 362 | 362 | */ |
| 363 | - function maybe_update_dataset_uri( $value, $old_value ) { |
|
| 363 | + function maybe_update_dataset_uri($value, $old_value) { |
|
| 364 | 364 | |
| 365 | 365 | // Check the old key value and the new one. Here we're only handling the |
| 366 | 366 | // case where the key hasn't changed and the dataset URI isn't set. The |
| 367 | 367 | // other case, i.e. a new key is inserted, is handled at `update_key`. |
| 368 | - $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
| 369 | - $new_key = isset( $value['key'] ) ? $value['key'] : ''; |
|
| 368 | + $old_key = isset($old_value['key']) ? $old_value['key'] : ''; |
|
| 369 | + $new_key = isset($value['key']) ? $value['key'] : ''; |
|
| 370 | 370 | |
| 371 | 371 | $dataset_uri = $this->get_dataset_uri(); |
| 372 | 372 | |
| 373 | - if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) { |
|
| 373 | + if ( ! empty($new_key) && $new_key === $old_key && empty($dataset_uri)) { |
|
| 374 | 374 | |
| 375 | 375 | // make the request to the remote server to try to get the dataset uri |
| 376 | - $this->get_remote_dataset_uri( $new_key ); |
|
| 376 | + $this->get_remote_dataset_uri($new_key); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | return $value; |
@@ -388,9 +388,9 @@ discard block |
||
| 388 | 388 | * |
| 389 | 389 | * @return string The API URI. |
| 390 | 390 | */ |
| 391 | - public function get_accounts_by_key_dataset_uri( $key ) { |
|
| 391 | + public function get_accounts_by_key_dataset_uri($key) { |
|
| 392 | 392 | |
| 393 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
|
| 393 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."accounts/key=$key/dataset_uri"; |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | */ |
| 403 | 403 | public function is_link_by_default() { |
| 404 | 404 | |
| 405 | - return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' ); |
|
| 405 | + return 'yes' === $this->get('wl_general_settings', self::LINK_BY_DEFAULT, 'yes'); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | /** |
@@ -412,9 +412,9 @@ discard block |
||
| 412 | 412 | * |
| 413 | 413 | * @param bool $value True to enabling linking by default, otherwise false. |
| 414 | 414 | */ |
| 415 | - public function set_link_by_default( $value ) { |
|
| 415 | + public function set_link_by_default($value) { |
|
| 416 | 416 | |
| 417 | - $this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' ); |
|
| 417 | + $this->set('wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no'); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | } |
@@ -22,37 +22,37 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class Wordlift_Activator { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Short Description. (use period) |
|
| 27 | - * |
|
| 28 | - * Long Description. |
|
| 29 | - * |
|
| 30 | - * @since 1.0.0 |
|
| 31 | - */ |
|
| 32 | - public static function activate() { |
|
| 33 | - |
|
| 34 | - // Do not let the plugin be activate on wordpress versions before 4.2. |
|
| 35 | - $version = get_bloginfo( 'version' ); |
|
| 36 | - if ( version_compare( $version, '4.2', '<' ) ) { |
|
| 37 | - die( __( 'The WordLift plugin requires WordPress version 4.2 or above.', 'wordlift' ) ); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 41 | - |
|
| 42 | - // Create a blank application key if there is none |
|
| 43 | - $key = $configuration_service->get_key(); |
|
| 44 | - if ( empty( $key ) ) { |
|
| 45 | - $configuration_service->set_key( '' ); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - // Intentionally go through the whole upgrade procedure to be DRY. |
|
| 49 | - wl_core_update_db_check(); |
|
| 50 | - |
|
| 51 | - // If WordLift's key is not configured, set `_wl_activation_redirect` transient. We won't redirect here, because we can't give |
|
| 52 | - // for granted that we're in a browser admin session. |
|
| 53 | - if ( '' === $configuration_service->get_key() ) { |
|
| 54 | - set_transient( '_wl_activation_redirect', true, 30 ); |
|
| 55 | - } |
|
| 56 | - } |
|
| 25 | + /** |
|
| 26 | + * Short Description. (use period) |
|
| 27 | + * |
|
| 28 | + * Long Description. |
|
| 29 | + * |
|
| 30 | + * @since 1.0.0 |
|
| 31 | + */ |
|
| 32 | + public static function activate() { |
|
| 33 | + |
|
| 34 | + // Do not let the plugin be activate on wordpress versions before 4.2. |
|
| 35 | + $version = get_bloginfo( 'version' ); |
|
| 36 | + if ( version_compare( $version, '4.2', '<' ) ) { |
|
| 37 | + die( __( 'The WordLift plugin requires WordPress version 4.2 or above.', 'wordlift' ) ); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 41 | + |
|
| 42 | + // Create a blank application key if there is none |
|
| 43 | + $key = $configuration_service->get_key(); |
|
| 44 | + if ( empty( $key ) ) { |
|
| 45 | + $configuration_service->set_key( '' ); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + // Intentionally go through the whole upgrade procedure to be DRY. |
|
| 49 | + wl_core_update_db_check(); |
|
| 50 | + |
|
| 51 | + // If WordLift's key is not configured, set `_wl_activation_redirect` transient. We won't redirect here, because we can't give |
|
| 52 | + // for granted that we're in a browser admin session. |
|
| 53 | + if ( '' === $configuration_service->get_key() ) { |
|
| 54 | + set_transient( '_wl_activation_redirect', true, 30 ); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | } |
@@ -32,17 +32,17 @@ discard block |
||
| 32 | 32 | public static function activate() { |
| 33 | 33 | |
| 34 | 34 | // Do not let the plugin be activate on wordpress versions before 4.2. |
| 35 | - $version = get_bloginfo( 'version' ); |
|
| 36 | - if ( version_compare( $version, '4.2', '<' ) ) { |
|
| 37 | - die( __( 'The WordLift plugin requires WordPress version 4.2 or above.', 'wordlift' ) ); |
|
| 35 | + $version = get_bloginfo('version'); |
|
| 36 | + if (version_compare($version, '4.2', '<')) { |
|
| 37 | + die(__('The WordLift plugin requires WordPress version 4.2 or above.', 'wordlift')); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $configuration_service = Wordlift_Configuration_Service::get_instance(); |
| 41 | 41 | |
| 42 | 42 | // Create a blank application key if there is none |
| 43 | 43 | $key = $configuration_service->get_key(); |
| 44 | - if ( empty( $key ) ) { |
|
| 45 | - $configuration_service->set_key( '' ); |
|
| 44 | + if (empty($key)) { |
|
| 45 | + $configuration_service->set_key(''); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // Intentionally go through the whole upgrade procedure to be DRY. |
@@ -50,8 +50,8 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | // If WordLift's key is not configured, set `_wl_activation_redirect` transient. We won't redirect here, because we can't give |
| 52 | 52 | // for granted that we're in a browser admin session. |
| 53 | - if ( '' === $configuration_service->get_key() ) { |
|
| 54 | - set_transient( '_wl_activation_redirect', true, 30 ); |
|
| 53 | + if ('' === $configuration_service->get_key()) { |
|
| 54 | + set_transient('_wl_activation_redirect', true, 30); |
|
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
@@ -11,95 +11,95 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | function wl_core_install_entity_type_data() { |
| 13 | 13 | |
| 14 | - // Ensure the custom type and the taxonomy are registered. |
|
| 15 | - Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
| 16 | - |
|
| 17 | - wl_entity_type_taxonomy_register(); |
|
| 18 | - |
|
| 19 | - // Ensure the custom taxonomy for dbpedia topics is registered |
|
| 20 | - Wordlift_Topic_Taxonomy_Service::get_instance()->init(); |
|
| 21 | - |
|
| 22 | - // Set the taxonomy data. |
|
| 23 | - // Note: parent types must be defined before child types. |
|
| 24 | - $terms = array( |
|
| 25 | - 'thing' => array( |
|
| 26 | - 'label' => 'Thing', |
|
| 27 | - 'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.', |
|
| 28 | - ), |
|
| 29 | - 'creative-work' => array( |
|
| 30 | - 'label' => 'CreativeWork', |
|
| 31 | - 'description' => 'A creative work (or a Music Album).', |
|
| 32 | - ), |
|
| 33 | - 'event' => array( |
|
| 34 | - 'label' => 'Event', |
|
| 35 | - 'description' => 'An event.', |
|
| 36 | - ), |
|
| 37 | - 'organization' => array( |
|
| 38 | - 'label' => 'Organization', |
|
| 39 | - 'description' => 'An organization, including a government or a newspaper.', |
|
| 40 | - ), |
|
| 41 | - 'person' => array( |
|
| 42 | - 'label' => 'Person', |
|
| 43 | - 'description' => 'A person (or a music artist).', |
|
| 44 | - ), |
|
| 45 | - 'place' => array( |
|
| 46 | - 'label' => 'Place', |
|
| 47 | - 'description' => 'A place.', |
|
| 48 | - ), |
|
| 49 | - 'localbusiness' => array( |
|
| 50 | - 'label' => 'LocalBusiness', |
|
| 51 | - 'description' => 'A local business.', |
|
| 52 | - ), |
|
| 53 | - ); |
|
| 54 | - |
|
| 55 | - foreach ( $terms as $slug => $term ) { |
|
| 56 | - |
|
| 57 | - // Create the term if it does not exist, then get its ID |
|
| 58 | - $term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 59 | - |
|
| 60 | - if ( 0 == $term_id || is_null( $term_id ) ) { |
|
| 61 | - $result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 62 | - } else { |
|
| 63 | - $term_id = $term_id['term_id']; |
|
| 64 | - $result = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A ); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - // Check for errors. |
|
| 68 | - if ( is_wp_error( $result ) ) { |
|
| 69 | - wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' ); |
|
| 70 | - continue; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - // Check if 'parent' corresponds to an actual term and get its ID. |
|
| 74 | - if ( ! isset( $term['parents'] ) ) { |
|
| 75 | - $term['parents'] = array(); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $parent_ids = array(); |
|
| 79 | - foreach ( $term['parents'] as $parent_slug ) { |
|
| 80 | - $parent_id = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 81 | - $parent_ids[] = intval( $parent_id->term_id ); // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - // Define a parent in the WP taxonomy style (not important for WL) |
|
| 85 | - if ( empty( $parent_ids ) ) { |
|
| 86 | - // No parent |
|
| 87 | - $parent_id = 0; |
|
| 88 | - } else { |
|
| 89 | - // Get first parent |
|
| 90 | - $parent_id = $parent_ids[0]; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // Update term with description, slug and parent |
|
| 94 | - wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 95 | - 'name' => $term['label'], |
|
| 96 | - 'slug' => $slug, |
|
| 97 | - 'description' => $term['description'], |
|
| 98 | - // We give to WP taxonomy just one parent. TODO: see if can give more than one |
|
| 99 | - 'parent' => $parent_id, |
|
| 100 | - ) ); |
|
| 101 | - |
|
| 102 | - } |
|
| 14 | + // Ensure the custom type and the taxonomy are registered. |
|
| 15 | + Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
| 16 | + |
|
| 17 | + wl_entity_type_taxonomy_register(); |
|
| 18 | + |
|
| 19 | + // Ensure the custom taxonomy for dbpedia topics is registered |
|
| 20 | + Wordlift_Topic_Taxonomy_Service::get_instance()->init(); |
|
| 21 | + |
|
| 22 | + // Set the taxonomy data. |
|
| 23 | + // Note: parent types must be defined before child types. |
|
| 24 | + $terms = array( |
|
| 25 | + 'thing' => array( |
|
| 26 | + 'label' => 'Thing', |
|
| 27 | + 'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.', |
|
| 28 | + ), |
|
| 29 | + 'creative-work' => array( |
|
| 30 | + 'label' => 'CreativeWork', |
|
| 31 | + 'description' => 'A creative work (or a Music Album).', |
|
| 32 | + ), |
|
| 33 | + 'event' => array( |
|
| 34 | + 'label' => 'Event', |
|
| 35 | + 'description' => 'An event.', |
|
| 36 | + ), |
|
| 37 | + 'organization' => array( |
|
| 38 | + 'label' => 'Organization', |
|
| 39 | + 'description' => 'An organization, including a government or a newspaper.', |
|
| 40 | + ), |
|
| 41 | + 'person' => array( |
|
| 42 | + 'label' => 'Person', |
|
| 43 | + 'description' => 'A person (or a music artist).', |
|
| 44 | + ), |
|
| 45 | + 'place' => array( |
|
| 46 | + 'label' => 'Place', |
|
| 47 | + 'description' => 'A place.', |
|
| 48 | + ), |
|
| 49 | + 'localbusiness' => array( |
|
| 50 | + 'label' => 'LocalBusiness', |
|
| 51 | + 'description' => 'A local business.', |
|
| 52 | + ), |
|
| 53 | + ); |
|
| 54 | + |
|
| 55 | + foreach ( $terms as $slug => $term ) { |
|
| 56 | + |
|
| 57 | + // Create the term if it does not exist, then get its ID |
|
| 58 | + $term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 59 | + |
|
| 60 | + if ( 0 == $term_id || is_null( $term_id ) ) { |
|
| 61 | + $result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 62 | + } else { |
|
| 63 | + $term_id = $term_id['term_id']; |
|
| 64 | + $result = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A ); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + // Check for errors. |
|
| 68 | + if ( is_wp_error( $result ) ) { |
|
| 69 | + wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' ); |
|
| 70 | + continue; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // Check if 'parent' corresponds to an actual term and get its ID. |
|
| 74 | + if ( ! isset( $term['parents'] ) ) { |
|
| 75 | + $term['parents'] = array(); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $parent_ids = array(); |
|
| 79 | + foreach ( $term['parents'] as $parent_slug ) { |
|
| 80 | + $parent_id = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 81 | + $parent_ids[] = intval( $parent_id->term_id ); // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + // Define a parent in the WP taxonomy style (not important for WL) |
|
| 85 | + if ( empty( $parent_ids ) ) { |
|
| 86 | + // No parent |
|
| 87 | + $parent_id = 0; |
|
| 88 | + } else { |
|
| 89 | + // Get first parent |
|
| 90 | + $parent_id = $parent_ids[0]; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // Update term with description, slug and parent |
|
| 94 | + wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 95 | + 'name' => $term['label'], |
|
| 96 | + 'slug' => $slug, |
|
| 97 | + 'description' => $term['description'], |
|
| 98 | + // We give to WP taxonomy just one parent. TODO: see if can give more than one |
|
| 99 | + 'parent' => $parent_id, |
|
| 100 | + ) ); |
|
| 101 | + |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | } |
| 105 | 105 | |
@@ -108,16 +108,16 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | function wl_core_install_create_relation_instance_table() { |
| 110 | 110 | |
| 111 | - global $wpdb; |
|
| 112 | - // global $wl_db_version; |
|
| 113 | - $installed_version = get_option( 'wl_db_version' ); |
|
| 111 | + global $wpdb; |
|
| 112 | + // global $wl_db_version; |
|
| 113 | + $installed_version = get_option( 'wl_db_version' ); |
|
| 114 | 114 | |
| 115 | - if ( WL_DB_VERSION != $installed_version ) { |
|
| 116 | - $table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 117 | - $charset_collate = $wpdb->get_charset_collate(); |
|
| 115 | + if ( WL_DB_VERSION != $installed_version ) { |
|
| 116 | + $table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 117 | + $charset_collate = $wpdb->get_charset_collate(); |
|
| 118 | 118 | |
| 119 | - // Sql statement for the relation instances custom table |
|
| 120 | - $sql = <<<EOF |
|
| 119 | + // Sql statement for the relation instances custom table |
|
| 120 | + $sql = <<<EOF |
|
| 121 | 121 | CREATE TABLE $table_name ( |
| 122 | 122 | id int(11) NOT NULL AUTO_INCREMENT, |
| 123 | 123 | subject_id int(11) NOT NULL, |
@@ -129,14 +129,14 @@ discard block |
||
| 129 | 129 | ) $charset_collate; |
| 130 | 130 | EOF; |
| 131 | 131 | |
| 132 | - // @see: https://codex.wordpress.org/Creating_Tables_with_Plugins |
|
| 133 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 134 | - $results = dbDelta( $sql ); |
|
| 132 | + // @see: https://codex.wordpress.org/Creating_Tables_with_Plugins |
|
| 133 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 134 | + $results = dbDelta( $sql ); |
|
| 135 | 135 | |
| 136 | - wl_write_log( $results ); |
|
| 136 | + wl_write_log( $results ); |
|
| 137 | 137 | |
| 138 | - update_option( 'wl_db_version', WL_DB_VERSION ); |
|
| 139 | - } |
|
| 138 | + update_option( 'wl_db_version', WL_DB_VERSION ); |
|
| 139 | + } |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -147,10 +147,10 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | function wl_core_upgrade_db_to_1_0() { |
| 149 | 149 | |
| 150 | - if ( ! get_option( 'wl_db_version' ) ) { |
|
| 151 | - wl_core_install_entity_type_data(); |
|
| 152 | - wl_core_install_create_relation_instance_table(); |
|
| 153 | - } |
|
| 150 | + if ( ! get_option( 'wl_db_version' ) ) { |
|
| 151 | + wl_core_install_entity_type_data(); |
|
| 152 | + wl_core_install_create_relation_instance_table(); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | 155 | } |
| 156 | 156 | |
@@ -163,31 +163,31 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | function wl_core_upgrade_db_1_0_to_3_10() { |
| 165 | 165 | |
| 166 | - // If the DB version is less than 3.10, than flatten the txonomy. |
|
| 167 | - if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) { |
|
| 166 | + // If the DB version is less than 3.10, than flatten the txonomy. |
|
| 167 | + if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) { |
|
| 168 | 168 | |
| 169 | - $term_slugs = array( |
|
| 170 | - 'thing', |
|
| 171 | - 'creative-work', |
|
| 172 | - 'event', |
|
| 173 | - 'organization', |
|
| 174 | - 'person', |
|
| 175 | - 'place', |
|
| 176 | - 'localbusiness', |
|
| 177 | - ); |
|
| 169 | + $term_slugs = array( |
|
| 170 | + 'thing', |
|
| 171 | + 'creative-work', |
|
| 172 | + 'event', |
|
| 173 | + 'organization', |
|
| 174 | + 'person', |
|
| 175 | + 'place', |
|
| 176 | + 'localbusiness', |
|
| 177 | + ); |
|
| 178 | 178 | |
| 179 | - foreach ( $term_slugs as $slug ) { |
|
| 179 | + foreach ( $term_slugs as $slug ) { |
|
| 180 | 180 | |
| 181 | - $term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 181 | + $term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 182 | 182 | |
| 183 | - // Set the term's parent to 0. |
|
| 184 | - if ( $term ) { |
|
| 185 | - wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 186 | - 'parent' => 0, |
|
| 187 | - ) ); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - } |
|
| 183 | + // Set the term's parent to 0. |
|
| 184 | + if ( $term ) { |
|
| 185 | + wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 186 | + 'parent' => 0, |
|
| 187 | + ) ); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | 192 | } |
| 193 | 193 | |
@@ -200,27 +200,27 @@ discard block |
||
| 200 | 200 | * @since 3.12.0 |
| 201 | 201 | */ |
| 202 | 202 | function wl_core_upgrade_db_3_10_3_12() { |
| 203 | - /* |
|
| 203 | + /* |
|
| 204 | 204 | * As this upgrade functionality runs on the init hook, and the AMP plugin |
| 205 | 205 | * initialization does the same, avoid possible race conditions by |
| 206 | 206 | * deferring the actual flush to a later hook. |
| 207 | 207 | */ |
| 208 | - add_action( 'wp_loaded', function () { |
|
| 209 | - flush_rewrite_rules(); |
|
| 210 | - } ); |
|
| 208 | + add_action( 'wp_loaded', function () { |
|
| 209 | + flush_rewrite_rules(); |
|
| 210 | + } ); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | // Check db status on automated plugins updates |
| 214 | 214 | function wl_core_update_db_check() { |
| 215 | 215 | |
| 216 | - if ( get_option( 'wl_db_version' ) != WL_DB_VERSION ) { |
|
| 216 | + if ( get_option( 'wl_db_version' ) != WL_DB_VERSION ) { |
|
| 217 | 217 | |
| 218 | - wl_core_upgrade_db_to_1_0(); |
|
| 219 | - wl_core_upgrade_db_1_0_to_3_10(); |
|
| 220 | - wl_core_upgrade_db_3_10_3_12(); |
|
| 221 | - update_option( 'wl_db_version', WL_DB_VERSION ); |
|
| 218 | + wl_core_upgrade_db_to_1_0(); |
|
| 219 | + wl_core_upgrade_db_1_0_to_3_10(); |
|
| 220 | + wl_core_upgrade_db_3_10_3_12(); |
|
| 221 | + update_option( 'wl_db_version', WL_DB_VERSION ); |
|
| 222 | 222 | |
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | 225 | } |
| 226 | 226 | |
@@ -52,37 +52,37 @@ discard block |
||
| 52 | 52 | ), |
| 53 | 53 | ); |
| 54 | 54 | |
| 55 | - foreach ( $terms as $slug => $term ) { |
|
| 55 | + foreach ($terms as $slug => $term) { |
|
| 56 | 56 | |
| 57 | 57 | // Create the term if it does not exist, then get its ID |
| 58 | - $term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 58 | + $term_id = term_exists($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME); |
|
| 59 | 59 | |
| 60 | - if ( 0 == $term_id || is_null( $term_id ) ) { |
|
| 61 | - $result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 60 | + if (0 == $term_id || is_null($term_id)) { |
|
| 61 | + $result = wp_insert_term($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME); |
|
| 62 | 62 | } else { |
| 63 | 63 | $term_id = $term_id['term_id']; |
| 64 | - $result = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A ); |
|
| 64 | + $result = get_term($term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // Check for errors. |
| 68 | - if ( is_wp_error( $result ) ) { |
|
| 69 | - wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' ); |
|
| 68 | + if (is_wp_error($result)) { |
|
| 69 | + wl_write_log('wl_install_entity_type_data [ '.$result->get_error_message().' ]'); |
|
| 70 | 70 | continue; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // Check if 'parent' corresponds to an actual term and get its ID. |
| 74 | - if ( ! isset( $term['parents'] ) ) { |
|
| 74 | + if ( ! isset($term['parents'])) { |
|
| 75 | 75 | $term['parents'] = array(); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $parent_ids = array(); |
| 79 | - foreach ( $term['parents'] as $parent_slug ) { |
|
| 80 | - $parent_id = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 81 | - $parent_ids[] = intval( $parent_id->term_id ); // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by |
|
| 79 | + foreach ($term['parents'] as $parent_slug) { |
|
| 80 | + $parent_id = get_term_by('slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME); |
|
| 81 | + $parent_ids[] = intval($parent_id->term_id); // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // Define a parent in the WP taxonomy style (not important for WL) |
| 85 | - if ( empty( $parent_ids ) ) { |
|
| 85 | + if (empty($parent_ids)) { |
|
| 86 | 86 | // No parent |
| 87 | 87 | $parent_id = 0; |
| 88 | 88 | } else { |
@@ -91,13 +91,13 @@ discard block |
||
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // Update term with description, slug and parent |
| 94 | - wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 94 | + wp_update_term($result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 95 | 95 | 'name' => $term['label'], |
| 96 | 96 | 'slug' => $slug, |
| 97 | 97 | 'description' => $term['description'], |
| 98 | 98 | // We give to WP taxonomy just one parent. TODO: see if can give more than one |
| 99 | 99 | 'parent' => $parent_id, |
| 100 | - ) ); |
|
| 100 | + )); |
|
| 101 | 101 | |
| 102 | 102 | } |
| 103 | 103 | |
@@ -110,10 +110,10 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | global $wpdb; |
| 112 | 112 | // global $wl_db_version; |
| 113 | - $installed_version = get_option( 'wl_db_version' ); |
|
| 113 | + $installed_version = get_option('wl_db_version'); |
|
| 114 | 114 | |
| 115 | - if ( WL_DB_VERSION != $installed_version ) { |
|
| 116 | - $table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 115 | + if (WL_DB_VERSION != $installed_version) { |
|
| 116 | + $table_name = $wpdb->prefix.WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 117 | 117 | $charset_collate = $wpdb->get_charset_collate(); |
| 118 | 118 | |
| 119 | 119 | // Sql statement for the relation instances custom table |
@@ -130,12 +130,12 @@ discard block |
||
| 130 | 130 | EOF; |
| 131 | 131 | |
| 132 | 132 | // @see: https://codex.wordpress.org/Creating_Tables_with_Plugins |
| 133 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 134 | - $results = dbDelta( $sql ); |
|
| 133 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
| 134 | + $results = dbDelta($sql); |
|
| 135 | 135 | |
| 136 | - wl_write_log( $results ); |
|
| 136 | + wl_write_log($results); |
|
| 137 | 137 | |
| 138 | - update_option( 'wl_db_version', WL_DB_VERSION ); |
|
| 138 | + update_option('wl_db_version', WL_DB_VERSION); |
|
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | function wl_core_upgrade_db_to_1_0() { |
| 149 | 149 | |
| 150 | - if ( ! get_option( 'wl_db_version' ) ) { |
|
| 150 | + if ( ! get_option('wl_db_version')) { |
|
| 151 | 151 | wl_core_install_entity_type_data(); |
| 152 | 152 | wl_core_install_create_relation_instance_table(); |
| 153 | 153 | } |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | function wl_core_upgrade_db_1_0_to_3_10() { |
| 165 | 165 | |
| 166 | 166 | // If the DB version is less than 3.10, than flatten the txonomy. |
| 167 | - if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) { |
|
| 167 | + if (version_compare(get_option('wl_db_version'), '3.9', '<=')) { |
|
| 168 | 168 | |
| 169 | 169 | $term_slugs = array( |
| 170 | 170 | 'thing', |
@@ -176,15 +176,15 @@ discard block |
||
| 176 | 176 | 'localbusiness', |
| 177 | 177 | ); |
| 178 | 178 | |
| 179 | - foreach ( $term_slugs as $slug ) { |
|
| 179 | + foreach ($term_slugs as $slug) { |
|
| 180 | 180 | |
| 181 | - $term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 181 | + $term = get_term_by('slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME); |
|
| 182 | 182 | |
| 183 | 183 | // Set the term's parent to 0. |
| 184 | - if ( $term ) { |
|
| 185 | - wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 184 | + if ($term) { |
|
| 185 | + wp_update_term($term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 186 | 186 | 'parent' => 0, |
| 187 | - ) ); |
|
| 187 | + )); |
|
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * initialization does the same, avoid possible race conditions by |
| 206 | 206 | * deferring the actual flush to a later hook. |
| 207 | 207 | */ |
| 208 | - add_action( 'wp_loaded', function () { |
|
| 208 | + add_action('wp_loaded', function() { |
|
| 209 | 209 | flush_rewrite_rules(); |
| 210 | 210 | } ); |
| 211 | 211 | } |
@@ -213,15 +213,15 @@ discard block |
||
| 213 | 213 | // Check db status on automated plugins updates |
| 214 | 214 | function wl_core_update_db_check() { |
| 215 | 215 | |
| 216 | - if ( get_option( 'wl_db_version' ) != WL_DB_VERSION ) { |
|
| 216 | + if (get_option('wl_db_version') != WL_DB_VERSION) { |
|
| 217 | 217 | |
| 218 | 218 | wl_core_upgrade_db_to_1_0(); |
| 219 | 219 | wl_core_upgrade_db_1_0_to_3_10(); |
| 220 | 220 | wl_core_upgrade_db_3_10_3_12(); |
| 221 | - update_option( 'wl_db_version', WL_DB_VERSION ); |
|
| 221 | + update_option('wl_db_version', WL_DB_VERSION); |
|
| 222 | 222 | |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | -add_action( 'init', 'wl_core_update_db_check', 11 ); // need taxonomies and post type to be defined first |
|
| 227 | +add_action('init', 'wl_core_update_db_check', 11); // need taxonomies and post type to be defined first |
|