@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | // If this file is called directly, abort. |
| 53 | 53 | if ( ! defined( 'WPINC' ) ) { |
| 54 | - die; |
|
| 54 | + die; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | */ |
| 62 | 62 | if ( ! apply_filters( 'wl_is_enabled', true ) ) { |
| 63 | - return; |
|
| 63 | + return; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | function wl_write_log( $log ) { |
| 85 | 85 | |
| 86 | - Wordlift_Log_Service::get_instance()->debug( $log ); |
|
| 86 | + Wordlift_Log_Service::get_instance()->debug( $log ); |
|
| 87 | 87 | |
| 88 | 88 | } |
| 89 | 89 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | function wl_write_log_hide_key( $text ) { |
| 102 | 102 | |
| 103 | - return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 103 | + return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -108,21 +108,21 @@ discard block |
||
| 108 | 108 | * see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/ |
| 109 | 109 | */ |
| 110 | 110 | function wordlift_allowed_post_tags() { |
| 111 | - global $allowedposttags; |
|
| 112 | - |
|
| 113 | - $tags = array( 'span' ); |
|
| 114 | - $new_attributes = array( |
|
| 115 | - 'itemscope' => array(), |
|
| 116 | - 'itemtype' => array(), |
|
| 117 | - 'itemprop' => array(), |
|
| 118 | - 'itemid' => array(), |
|
| 119 | - ); |
|
| 120 | - |
|
| 121 | - foreach ( $tags as $tag ) { |
|
| 122 | - if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 123 | - $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 124 | - } |
|
| 125 | - } |
|
| 111 | + global $allowedposttags; |
|
| 112 | + |
|
| 113 | + $tags = array( 'span' ); |
|
| 114 | + $new_attributes = array( |
|
| 115 | + 'itemscope' => array(), |
|
| 116 | + 'itemtype' => array(), |
|
| 117 | + 'itemprop' => array(), |
|
| 118 | + 'itemid' => array(), |
|
| 119 | + ); |
|
| 120 | + |
|
| 121 | + foreach ( $tags as $tag ) { |
|
| 122 | + if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 123 | + $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // add allowed post tags. |
@@ -133,18 +133,18 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | function wordlift_admin_enqueue_scripts() { |
| 135 | 135 | |
| 136 | - // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
|
| 137 | - wp_enqueue_script( 'wpdialogs' ); |
|
| 138 | - wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 136 | + // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
|
| 137 | + wp_enqueue_script( 'wpdialogs' ); |
|
| 138 | + wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 139 | 139 | |
| 140 | - wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 140 | + wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 141 | 141 | |
| 142 | - wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 142 | + wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 143 | 143 | |
| 144 | - // Disable auto-save for custom entity posts only |
|
| 145 | - if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) { |
|
| 146 | - wp_dequeue_script( 'autosave' ); |
|
| 147 | - } |
|
| 144 | + // Disable auto-save for custom entity posts only |
|
| 145 | + if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) { |
|
| 146 | + wp_dequeue_script( 'autosave' ); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | 149 | } |
| 150 | 150 | |
@@ -160,18 +160,18 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | function wordlift_allowed_html( $allowedtags, $context ) { |
| 162 | 162 | |
| 163 | - if ( 'post' !== $context ) { |
|
| 164 | - return $allowedtags; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - return array_merge_recursive( $allowedtags, array( |
|
| 168 | - 'span' => array( |
|
| 169 | - 'itemscope' => true, |
|
| 170 | - 'itemtype' => true, |
|
| 171 | - 'itemid' => true, |
|
| 172 | - 'itemprop' => true, |
|
| 173 | - ), |
|
| 174 | - ) ); |
|
| 163 | + if ( 'post' !== $context ) { |
|
| 164 | + return $allowedtags; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + return array_merge_recursive( $allowedtags, array( |
|
| 168 | + 'span' => array( |
|
| 169 | + 'itemscope' => true, |
|
| 170 | + 'itemtype' => true, |
|
| 171 | + 'itemid' => true, |
|
| 172 | + 'itemprop' => true, |
|
| 173 | + ), |
|
| 174 | + ) ); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 ); |
@@ -185,16 +185,16 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | function wl_get_coordinates( $post_id ) { |
| 187 | 187 | |
| 188 | - $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 189 | - $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 188 | + $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 189 | + $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 190 | 190 | |
| 191 | - // DO NOT set latitude/longitude to 0/0 as default values. It's a specific |
|
| 192 | - // place on the globe:"The zero/zero point of this system is located in the |
|
| 193 | - // Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 194 | - return array( |
|
| 195 | - 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 196 | - 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 197 | - ); |
|
| 191 | + // DO NOT set latitude/longitude to 0/0 as default values. It's a specific |
|
| 192 | + // place on the globe:"The zero/zero point of this system is located in the |
|
| 193 | + // Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 194 | + return array( |
|
| 195 | + 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 196 | + 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 197 | + ); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -208,9 +208,9 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | function wl_get_image_urls( $post_id ) { |
| 210 | 210 | |
| 211 | - return Wordlift_Storage_Factory::get_instance() |
|
| 212 | - ->post_images() |
|
| 213 | - ->get( $post_id ); |
|
| 211 | + return Wordlift_Storage_Factory::get_instance() |
|
| 212 | + ->post_images() |
|
| 213 | + ->get( $post_id ); |
|
| 214 | 214 | |
| 215 | 215 | } |
| 216 | 216 | |
@@ -224,24 +224,24 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) { |
| 226 | 226 | |
| 227 | - // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
|
| 227 | + // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
|
| 228 | 228 | |
| 229 | - $posts = get_posts( array( |
|
| 230 | - 'post_type' => 'attachment', |
|
| 231 | - 'posts_per_page' => 1, |
|
| 232 | - 'post_status' => 'any', |
|
| 233 | - 'post_parent' => $parent_post_id, |
|
| 234 | - 'meta_key' => 'wl_source_url', |
|
| 235 | - 'meta_value' => $source_url, |
|
| 236 | - ) ); |
|
| 229 | + $posts = get_posts( array( |
|
| 230 | + 'post_type' => 'attachment', |
|
| 231 | + 'posts_per_page' => 1, |
|
| 232 | + 'post_status' => 'any', |
|
| 233 | + 'post_parent' => $parent_post_id, |
|
| 234 | + 'meta_key' => 'wl_source_url', |
|
| 235 | + 'meta_value' => $source_url, |
|
| 236 | + ) ); |
|
| 237 | 237 | |
| 238 | - // Return the found post. |
|
| 239 | - if ( 1 === count( $posts ) ) { |
|
| 240 | - return $posts[0]; |
|
| 241 | - } |
|
| 238 | + // Return the found post. |
|
| 239 | + if ( 1 === count( $posts ) ) { |
|
| 240 | + return $posts[0]; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - // Return null. |
|
| 244 | - return null; |
|
| 243 | + // Return null. |
|
| 244 | + return null; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -252,8 +252,8 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | function wl_set_source_url( $post_id, $source_url ) { |
| 254 | 254 | |
| 255 | - delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 256 | - add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 255 | + delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 256 | + add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | */ |
| 271 | 271 | function wl_sanitize_uri_path( $path, $char = '_' ) { |
| 272 | 272 | |
| 273 | - return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char ); |
|
| 273 | + return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char ); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -282,47 +282,47 @@ discard block |
||
| 282 | 282 | */ |
| 283 | 283 | function wl_replace_item_id_with_uri( $content ) { |
| 284 | 284 | |
| 285 | - $log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' ); |
|
| 286 | - $log->trace( 'Replacing item IDs with URIs...' ); |
|
| 285 | + $log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' ); |
|
| 286 | + $log->trace( 'Replacing item IDs with URIs...' ); |
|
| 287 | 287 | |
| 288 | - // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
|
| 289 | - $content = stripslashes( $content ); |
|
| 288 | + // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
|
| 289 | + $content = stripslashes( $content ); |
|
| 290 | 290 | |
| 291 | - // If any match are found. |
|
| 292 | - $matches = array(); |
|
| 293 | - if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 291 | + // If any match are found. |
|
| 292 | + $matches = array(); |
|
| 293 | + if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 294 | 294 | |
| 295 | - foreach ( $matches as $match ) { |
|
| 295 | + foreach ( $matches as $match ) { |
|
| 296 | 296 | |
| 297 | - // Get the item ID. |
|
| 298 | - $item_id = $match[1]; |
|
| 297 | + // Get the item ID. |
|
| 298 | + $item_id = $match[1]; |
|
| 299 | 299 | |
| 300 | - // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
|
| 301 | - $post = Wordlift_Entity_Service::get_instance() |
|
| 302 | - ->get_entity_post_by_uri( $item_id ); |
|
| 300 | + // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
|
| 301 | + $post = Wordlift_Entity_Service::get_instance() |
|
| 302 | + ->get_entity_post_by_uri( $item_id ); |
|
| 303 | 303 | |
| 304 | - // If no entity is found, continue to the next one. |
|
| 305 | - if ( null === $post ) { |
|
| 306 | - continue; |
|
| 307 | - } |
|
| 304 | + // If no entity is found, continue to the next one. |
|
| 305 | + if ( null === $post ) { |
|
| 306 | + continue; |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - // Get the URI for that post. |
|
| 310 | - $uri = wl_get_entity_uri( $post->ID ); |
|
| 309 | + // Get the URI for that post. |
|
| 310 | + $uri = wl_get_entity_uri( $post->ID ); |
|
| 311 | 311 | |
| 312 | - // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
|
| 312 | + // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
|
| 313 | 313 | |
| 314 | - // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
|
| 315 | - if ( ! empty( $uri ) && $item_id !== $uri ) { |
|
| 316 | - $uri_e = esc_html( $uri ); |
|
| 317 | - $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - } |
|
| 314 | + // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
|
| 315 | + if ( ! empty( $uri ) && $item_id !== $uri ) { |
|
| 316 | + $uri_e = esc_html( $uri ); |
|
| 317 | + $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | - // Reapply slashes. |
|
| 323 | - $content = addslashes( $content ); |
|
| 322 | + // Reapply slashes. |
|
| 323 | + $content = addslashes( $content ); |
|
| 324 | 324 | |
| 325 | - return $content; |
|
| 325 | + return $content; |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 ); |
@@ -385,29 +385,29 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | function activate_wordlift() { |
| 387 | 387 | |
| 388 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
| 389 | - |
|
| 390 | - $log->info( 'Activating WordLift...' ); |
|
| 391 | - |
|
| 392 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 393 | - Wordlift_Activator::activate(); |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
| 397 | - * |
|
| 398 | - * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
| 399 | - * @since 3.19.2 |
|
| 400 | - */ |
|
| 401 | - Wordlift_Http_Api::activate(); |
|
| 402 | - |
|
| 403 | - // Ensure the post type is registered before flushing the rewrite rules. |
|
| 404 | - Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
| 405 | - flush_rewrite_rules(); |
|
| 406 | - /** |
|
| 407 | - * @since 3.27.7 |
|
| 408 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
| 409 | - */ |
|
| 410 | - Top_Entities::activate(); |
|
| 388 | + $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
| 389 | + |
|
| 390 | + $log->info( 'Activating WordLift...' ); |
|
| 391 | + |
|
| 392 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 393 | + Wordlift_Activator::activate(); |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
| 397 | + * |
|
| 398 | + * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
| 399 | + * @since 3.19.2 |
|
| 400 | + */ |
|
| 401 | + Wordlift_Http_Api::activate(); |
|
| 402 | + |
|
| 403 | + // Ensure the post type is registered before flushing the rewrite rules. |
|
| 404 | + Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
| 405 | + flush_rewrite_rules(); |
|
| 406 | + /** |
|
| 407 | + * @since 3.27.7 |
|
| 408 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
| 409 | + */ |
|
| 410 | + Top_Entities::activate(); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -416,21 +416,21 @@ discard block |
||
| 416 | 416 | */ |
| 417 | 417 | function deactivate_wordlift() { |
| 418 | 418 | |
| 419 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 420 | - Wordlift_Deactivator::deactivate(); |
|
| 421 | - Wordlift_Http_Api::deactivate(); |
|
| 422 | - Ttl_Cache_Cleaner::deactivate(); |
|
| 423 | - /** |
|
| 424 | - * @since 3.27.7 |
|
| 425 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
| 426 | - */ |
|
| 427 | - Top_Entities::deactivate(); |
|
| 428 | - /** |
|
| 429 | - * @since 3.27.8 |
|
| 430 | - * Remove notification flag on deactivation. |
|
| 431 | - */ |
|
| 432 | - Key_Validation_Notice::remove_notification_flag(); |
|
| 433 | - flush_rewrite_rules(); |
|
| 419 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 420 | + Wordlift_Deactivator::deactivate(); |
|
| 421 | + Wordlift_Http_Api::deactivate(); |
|
| 422 | + Ttl_Cache_Cleaner::deactivate(); |
|
| 423 | + /** |
|
| 424 | + * @since 3.27.7 |
|
| 425 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
| 426 | + */ |
|
| 427 | + Top_Entities::deactivate(); |
|
| 428 | + /** |
|
| 429 | + * @since 3.27.8 |
|
| 430 | + * Remove notification flag on deactivation. |
|
| 431 | + */ |
|
| 432 | + Key_Validation_Notice::remove_notification_flag(); |
|
| 433 | + flush_rewrite_rules(); |
|
| 434 | 434 | |
| 435 | 435 | } |
| 436 | 436 | |
@@ -453,105 +453,105 @@ discard block |
||
| 453 | 453 | * @since 1.0.0 |
| 454 | 454 | */ |
| 455 | 455 | function run_wordlift() { |
| 456 | - /** |
|
| 457 | - * Filter: wl_feature__enable__widgets. |
|
| 458 | - * |
|
| 459 | - * @param bool whether the widgets needed to be registered, defaults to true. |
|
| 460 | - * |
|
| 461 | - * @return bool |
|
| 462 | - * @since 3.27.6 |
|
| 463 | - */ |
|
| 464 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
| 465 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
| 466 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
| 467 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
| 468 | - } |
|
| 469 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
| 470 | - |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * Filter: wl_feature__enable__analysis |
|
| 474 | - * |
|
| 475 | - * @param bool Whether to send api request to analysis or not |
|
| 476 | - * |
|
| 477 | - * @return bool |
|
| 478 | - * @since 3.27.6 |
|
| 479 | - */ |
|
| 480 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
| 481 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
| 482 | - } else { |
|
| 483 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /* |
|
| 456 | + /** |
|
| 457 | + * Filter: wl_feature__enable__widgets. |
|
| 458 | + * |
|
| 459 | + * @param bool whether the widgets needed to be registered, defaults to true. |
|
| 460 | + * |
|
| 461 | + * @return bool |
|
| 462 | + * @since 3.27.6 |
|
| 463 | + */ |
|
| 464 | + if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
| 465 | + add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
| 466 | + add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
| 467 | + add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
| 468 | + } |
|
| 469 | + add_filter( 'widget_text', 'do_shortcode' ); |
|
| 470 | + |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * Filter: wl_feature__enable__analysis |
|
| 474 | + * |
|
| 475 | + * @param bool Whether to send api request to analysis or not |
|
| 476 | + * |
|
| 477 | + * @return bool |
|
| 478 | + * @since 3.27.6 |
|
| 479 | + */ |
|
| 480 | + if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
| 481 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
| 482 | + } else { |
|
| 483 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /* |
|
| 487 | 487 | * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http. |
| 488 | 488 | * |
| 489 | 489 | * @since 3.21.2 |
| 490 | 490 | */ |
| 491 | - wordlift_plugin_autoload_register(); |
|
| 491 | + wordlift_plugin_autoload_register(); |
|
| 492 | 492 | |
| 493 | - $plugin = new Wordlift(); |
|
| 494 | - $plugin->run(); |
|
| 493 | + $plugin = new Wordlift(); |
|
| 494 | + $plugin->run(); |
|
| 495 | 495 | |
| 496 | - // Initialize the TTL Cache Cleaner. |
|
| 497 | - new Ttl_Cache_Cleaner(); |
|
| 496 | + // Initialize the TTL Cache Cleaner. |
|
| 497 | + new Ttl_Cache_Cleaner(); |
|
| 498 | 498 | |
| 499 | - // Load the new Post Adapter. |
|
| 500 | - new Post_Adapter(); |
|
| 499 | + // Load the new Post Adapter. |
|
| 500 | + new Post_Adapter(); |
|
| 501 | 501 | |
| 502 | - // Load the API Data Hooks. |
|
| 503 | - new Api_Data_Hooks( Wordlift_Configuration_Service::get_instance() ); |
|
| 502 | + // Load the API Data Hooks. |
|
| 503 | + new Api_Data_Hooks( Wordlift_Configuration_Service::get_instance() ); |
|
| 504 | 504 | |
| 505 | - add_action( 'plugins_loaded', function () { |
|
| 506 | - // Load early. **PLEASE NOTE** that features are applied only to calls that happen **AFTER** the `plugins_loaded` |
|
| 507 | - // action. |
|
| 508 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php'; |
|
| 505 | + add_action( 'plugins_loaded', function () { |
|
| 506 | + // Load early. **PLEASE NOTE** that features are applied only to calls that happen **AFTER** the `plugins_loaded` |
|
| 507 | + // action. |
|
| 508 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php'; |
|
| 509 | 509 | |
| 510 | - // All features from registry should be initialized here. |
|
| 511 | - $features_registry = Features_Registry::get_instance(); |
|
| 512 | - $features_registry->initialize_all_features(); |
|
| 513 | - }, 1 ); |
|
| 510 | + // All features from registry should be initialized here. |
|
| 511 | + $features_registry = Features_Registry::get_instance(); |
|
| 512 | + $features_registry->initialize_all_features(); |
|
| 513 | + }, 1 ); |
|
| 514 | 514 | |
| 515 | - add_action( 'plugins_loaded', function () use ( $plugin ) { |
|
| 516 | - // Licenses Images. |
|
| 517 | - $user_agent = User_Agent::get_user_agent(); |
|
| 518 | - $wordlift_key = Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 519 | - $api_service = new Default_Api_Service( apply_filters( 'wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ), 60, $user_agent, $wordlift_key ); |
|
| 520 | - $image_license_factory = new Image_License_Factory(); |
|
| 521 | - $image_license_service = new Image_License_Service( $api_service, $image_license_factory ); |
|
| 522 | - $image_license_cache = new Ttl_Cache( 'image-license', 86400 * 30 ); // 30 days. |
|
| 523 | - $cached_image_license_service = new Cached_Image_License_Service( $image_license_service, $image_license_cache ); |
|
| 515 | + add_action( 'plugins_loaded', function () use ( $plugin ) { |
|
| 516 | + // Licenses Images. |
|
| 517 | + $user_agent = User_Agent::get_user_agent(); |
|
| 518 | + $wordlift_key = Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 519 | + $api_service = new Default_Api_Service( apply_filters( 'wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ), 60, $user_agent, $wordlift_key ); |
|
| 520 | + $image_license_factory = new Image_License_Factory(); |
|
| 521 | + $image_license_service = new Image_License_Service( $api_service, $image_license_factory ); |
|
| 522 | + $image_license_cache = new Ttl_Cache( 'image-license', 86400 * 30 ); // 30 days. |
|
| 523 | + $cached_image_license_service = new Cached_Image_License_Service( $image_license_service, $image_license_cache ); |
|
| 524 | 524 | |
| 525 | - $image_license_scheduler = new Image_License_Scheduler( $image_license_service, $image_license_cache ); |
|
| 526 | - $image_license_cleanup_service = new Image_License_Cleanup_Service(); |
|
| 525 | + $image_license_scheduler = new Image_License_Scheduler( $image_license_service, $image_license_cache ); |
|
| 526 | + $image_license_cleanup_service = new Image_License_Cleanup_Service(); |
|
| 527 | 527 | |
| 528 | - // Get the cached data. If we have cached data, we load the notifier. |
|
| 529 | - $image_license_data = $image_license_cache->get( Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES ); |
|
| 530 | - if ( null !== $image_license_data ) { |
|
| 531 | - $image_license_page = new Image_License_Page( $image_license_data, Wordlift::get_instance()->get_version() ); |
|
| 532 | - new Image_License_Notifier( $image_license_data, $image_license_page ); |
|
| 533 | - } |
|
| 528 | + // Get the cached data. If we have cached data, we load the notifier. |
|
| 529 | + $image_license_data = $image_license_cache->get( Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES ); |
|
| 530 | + if ( null !== $image_license_data ) { |
|
| 531 | + $image_license_page = new Image_License_Page( $image_license_data, Wordlift::get_instance()->get_version() ); |
|
| 532 | + new Image_License_Notifier( $image_license_data, $image_license_page ); |
|
| 533 | + } |
|
| 534 | 534 | |
| 535 | - $remove_all_images_task = new Remove_All_Images_Task( $cached_image_license_service ); |
|
| 536 | - $remove_all_images_task_adapter = new Task_Ajax_Adapter( $remove_all_images_task ); |
|
| 535 | + $remove_all_images_task = new Remove_All_Images_Task( $cached_image_license_service ); |
|
| 536 | + $remove_all_images_task_adapter = new Task_Ajax_Adapter( $remove_all_images_task ); |
|
| 537 | 537 | |
| 538 | - $reload_data_task = new Reload_Data_Task(); |
|
| 539 | - $reload_data_task_adapter = new Task_Ajax_Adapter( $reload_data_task ); |
|
| 538 | + $reload_data_task = new Reload_Data_Task(); |
|
| 539 | + $reload_data_task_adapter = new Task_Ajax_Adapter( $reload_data_task ); |
|
| 540 | 540 | |
| 541 | - $add_license_caption_or_remove_task = new Add_License_Caption_Or_Remove_Task( $cached_image_license_service ); |
|
| 542 | - $add_license_caption_or_remove_task_adapter = new Task_Ajax_Adapter( $add_license_caption_or_remove_task ); |
|
| 541 | + $add_license_caption_or_remove_task = new Add_License_Caption_Or_Remove_Task( $cached_image_license_service ); |
|
| 542 | + $add_license_caption_or_remove_task_adapter = new Task_Ajax_Adapter( $add_license_caption_or_remove_task ); |
|
| 543 | 543 | |
| 544 | - $remove_all_images_task_page = new Remove_All_Images_Page( new Task_Ajax_Adapters_Registry( $remove_all_images_task_adapter ), $plugin->get_version() ); |
|
| 545 | - $reload_data_task_page = new Reload_Data_Page( new Task_Ajax_Adapters_Registry( $reload_data_task_adapter ), $plugin->get_version() ); |
|
| 546 | - $add_license_caption_or_remove_task_page = new Add_License_Caption_Or_Remove_Page( new Task_Ajax_Adapters_Registry( $add_license_caption_or_remove_task_adapter ), $plugin->get_version() ); |
|
| 544 | + $remove_all_images_task_page = new Remove_All_Images_Page( new Task_Ajax_Adapters_Registry( $remove_all_images_task_adapter ), $plugin->get_version() ); |
|
| 545 | + $reload_data_task_page = new Reload_Data_Page( new Task_Ajax_Adapters_Registry( $reload_data_task_adapter ), $plugin->get_version() ); |
|
| 546 | + $add_license_caption_or_remove_task_page = new Add_License_Caption_Or_Remove_Page( new Task_Ajax_Adapters_Registry( $add_license_caption_or_remove_task_adapter ), $plugin->get_version() ); |
|
| 547 | 547 | |
| 548 | - new Wordlift_Products_Navigator_Shortcode_REST(); |
|
| 548 | + new Wordlift_Products_Navigator_Shortcode_REST(); |
|
| 549 | 549 | |
| 550 | - // Register the Dataset module, requires `$api_service`. |
|
| 551 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
| 552 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
| 550 | + // Register the Dataset module, requires `$api_service`. |
|
| 551 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
| 552 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
| 553 | 553 | |
| 554 | - } ); |
|
| 554 | + } ); |
|
| 555 | 555 | |
| 556 | 556 | } |
| 557 | 557 | |
@@ -565,45 +565,45 @@ discard block |
||
| 565 | 565 | */ |
| 566 | 566 | function wordlift_plugin_autoload_register() { |
| 567 | 567 | |
| 568 | - spl_autoload_register( function ( $class_name ) { |
|
| 568 | + spl_autoload_register( function ( $class_name ) { |
|
| 569 | 569 | |
| 570 | - // Bail out if these are not our classes. |
|
| 571 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
| 572 | - return false; |
|
| 573 | - } |
|
| 570 | + // Bail out if these are not our classes. |
|
| 571 | + if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
| 572 | + return false; |
|
| 573 | + } |
|
| 574 | 574 | |
| 575 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
| 575 | + $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
| 576 | 576 | |
| 577 | - preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
| 577 | + preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
| 578 | 578 | |
| 579 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
| 580 | - $file = 'class-' . $matches[2] . '.php'; |
|
| 579 | + $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
| 580 | + $file = 'class-' . $matches[2] . '.php'; |
|
| 581 | 581 | |
| 582 | - $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
| 582 | + $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
| 583 | 583 | |
| 584 | - if ( ! file_exists( $full_path ) ) { |
|
| 585 | - echo esc_html( "Class $class_name not found at $full_path." ); |
|
| 584 | + if ( ! file_exists( $full_path ) ) { |
|
| 585 | + echo esc_html( "Class $class_name not found at $full_path." ); |
|
| 586 | 586 | |
| 587 | - return false; |
|
| 588 | - } |
|
| 587 | + return false; |
|
| 588 | + } |
|
| 589 | 589 | |
| 590 | - require_once $full_path; |
|
| 590 | + require_once $full_path; |
|
| 591 | 591 | |
| 592 | - return true; |
|
| 593 | - } ); |
|
| 592 | + return true; |
|
| 593 | + } ); |
|
| 594 | 594 | |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | function wl_block_categories( $categories, $post ) { |
| 598 | - return array_merge( |
|
| 599 | - $categories, |
|
| 600 | - array( |
|
| 601 | - array( |
|
| 602 | - 'slug' => 'wordlift', |
|
| 603 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
| 604 | - ), |
|
| 605 | - ) |
|
| 606 | - ); |
|
| 598 | + return array_merge( |
|
| 599 | + $categories, |
|
| 600 | + array( |
|
| 601 | + array( |
|
| 602 | + 'slug' => 'wordlift', |
|
| 603 | + 'title' => __( 'WordLift', 'wordlift' ), |
|
| 604 | + ), |
|
| 605 | + ) |
|
| 606 | + ); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | add_filter( 'block_categories', 'wl_block_categories', 10, 2 ); |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | use Wordlift\Tasks\Task_Ajax_Adapters_Registry; |
| 51 | 51 | |
| 52 | 52 | // If this file is called directly, abort. |
| 53 | -if ( ! defined( 'WPINC' ) ) { |
|
| 53 | +if ( ! defined('WPINC')) { |
|
| 54 | 54 | die; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -59,17 +59,17 @@ discard block |
||
| 59 | 59 | * @since 3.33.6 |
| 60 | 60 | * |
| 61 | 61 | */ |
| 62 | -if ( ! apply_filters( 'wl_is_enabled', true ) ) { |
|
| 62 | +if ( ! apply_filters('wl_is_enabled', true)) { |
|
| 63 | 63 | return; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | -require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
|
| 66 | +require_once plugin_dir_path(__FILE__).'vendor/autoload.php'; |
|
| 67 | 67 | |
| 68 | 68 | // Include WordLift constants. |
| 69 | -require_once( 'wordlift_constants.php' ); |
|
| 69 | +require_once('wordlift_constants.php'); |
|
| 70 | 70 | |
| 71 | 71 | // Load modules. |
| 72 | -require_once( 'modules/core/wordlift_core.php' ); |
|
| 72 | +require_once('modules/core/wordlift_core.php'); |
|
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * Log to the debug.log file. |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | * @deprecated use Wordlift_Log_Service::get_instance()->info( $log ); |
| 82 | 82 | * |
| 83 | 83 | */ |
| 84 | -function wl_write_log( $log ) { |
|
| 84 | +function wl_write_log($log) { |
|
| 85 | 85 | |
| 86 | - Wordlift_Log_Service::get_instance()->debug( $log ); |
|
| 86 | + Wordlift_Log_Service::get_instance()->debug($log); |
|
| 87 | 87 | |
| 88 | 88 | } |
| 89 | 89 | |
@@ -98,9 +98,9 @@ discard block |
||
| 98 | 98 | * @since 3.0.0 |
| 99 | 99 | * |
| 100 | 100 | */ |
| 101 | -function wl_write_log_hide_key( $text ) { |
|
| 101 | +function wl_write_log_hide_key($text) { |
|
| 102 | 102 | |
| 103 | - return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 103 | + return str_ireplace(wl_configuration_get_key(), '<hidden>', $text); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | function wordlift_allowed_post_tags() { |
| 111 | 111 | global $allowedposttags; |
| 112 | 112 | |
| 113 | - $tags = array( 'span' ); |
|
| 113 | + $tags = array('span'); |
|
| 114 | 114 | $new_attributes = array( |
| 115 | 115 | 'itemscope' => array(), |
| 116 | 116 | 'itemtype' => array(), |
@@ -118,15 +118,15 @@ discard block |
||
| 118 | 118 | 'itemid' => array(), |
| 119 | 119 | ); |
| 120 | 120 | |
| 121 | - foreach ( $tags as $tag ) { |
|
| 122 | - if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 123 | - $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 121 | + foreach ($tags as $tag) { |
|
| 122 | + if (isset($allowedposttags[$tag]) && is_array($allowedposttags[$tag])) { |
|
| 123 | + $allowedposttags[$tag] = array_merge($allowedposttags[$tag], $new_attributes); |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // add allowed post tags. |
| 129 | -add_action( 'init', 'wordlift_allowed_post_tags' ); |
|
| 129 | +add_action('init', 'wordlift_allowed_post_tags'); |
|
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | 132 | * Register additional scripts for the admin UI. |
@@ -134,21 +134,21 @@ discard block |
||
| 134 | 134 | function wordlift_admin_enqueue_scripts() { |
| 135 | 135 | |
| 136 | 136 | // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
| 137 | - wp_enqueue_script( 'wpdialogs' ); |
|
| 138 | - wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 137 | + wp_enqueue_script('wpdialogs'); |
|
| 138 | + wp_enqueue_style('wp-jquery-ui-dialog'); |
|
| 139 | 139 | |
| 140 | - wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 140 | + wp_enqueue_style('wordlift-reloaded', plugin_dir_url(__FILE__).'css/wordlift-reloaded.min.css'); |
|
| 141 | 141 | |
| 142 | - wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 142 | + wp_enqueue_script('jquery-ui-autocomplete'); |
|
| 143 | 143 | |
| 144 | 144 | // Disable auto-save for custom entity posts only |
| 145 | - if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) { |
|
| 146 | - wp_dequeue_script( 'autosave' ); |
|
| 145 | + if (Wordlift_Entity_Service::TYPE_NAME === get_post_type()) { |
|
| 146 | + wp_dequeue_script('autosave'); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | -add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' ); |
|
| 151 | +add_action('admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts'); |
|
| 152 | 152 | |
| 153 | 153 | /** |
| 154 | 154 | * Hooked to *wp_kses_allowed_html* filter, adds microdata attributes. |
@@ -158,23 +158,23 @@ discard block |
||
| 158 | 158 | * |
| 159 | 159 | * @return array An array which contains allowed microdata attributes. |
| 160 | 160 | */ |
| 161 | -function wordlift_allowed_html( $allowedtags, $context ) { |
|
| 161 | +function wordlift_allowed_html($allowedtags, $context) { |
|
| 162 | 162 | |
| 163 | - if ( 'post' !== $context ) { |
|
| 163 | + if ('post' !== $context) { |
|
| 164 | 164 | return $allowedtags; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - return array_merge_recursive( $allowedtags, array( |
|
| 167 | + return array_merge_recursive($allowedtags, array( |
|
| 168 | 168 | 'span' => array( |
| 169 | 169 | 'itemscope' => true, |
| 170 | 170 | 'itemtype' => true, |
| 171 | 171 | 'itemid' => true, |
| 172 | 172 | 'itemprop' => true, |
| 173 | 173 | ), |
| 174 | - ) ); |
|
| 174 | + )); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | -add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 ); |
|
| 177 | +add_filter('wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2); |
|
| 178 | 178 | |
| 179 | 179 | /** |
| 180 | 180 | * Get the coordinates for the specified post ID. |
@@ -183,17 +183,17 @@ discard block |
||
| 183 | 183 | * |
| 184 | 184 | * @return array|null An array of coordinates or null. |
| 185 | 185 | */ |
| 186 | -function wl_get_coordinates( $post_id ) { |
|
| 186 | +function wl_get_coordinates($post_id) { |
|
| 187 | 187 | |
| 188 | - $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 189 | - $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 188 | + $latitude = wl_schema_get_value($post_id, 'latitude'); |
|
| 189 | + $longitude = wl_schema_get_value($post_id, 'longitude'); |
|
| 190 | 190 | |
| 191 | 191 | // DO NOT set latitude/longitude to 0/0 as default values. It's a specific |
| 192 | 192 | // place on the globe:"The zero/zero point of this system is located in the |
| 193 | 193 | // Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
| 194 | 194 | return array( |
| 195 | - 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 196 | - 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 195 | + 'latitude' => isset($latitude[0]) && is_numeric($latitude[0]) ? $latitude[0] : '', |
|
| 196 | + 'longitude' => isset($longitude[0]) && is_numeric($longitude[0]) ? $longitude[0] : '', |
|
| 197 | 197 | ); |
| 198 | 198 | } |
| 199 | 199 | |
@@ -206,11 +206,11 @@ discard block |
||
| 206 | 206 | * @deprecated use Wordlift_Storage_Factory::get_instance()->post_images()->get( $post_id ) |
| 207 | 207 | * |
| 208 | 208 | */ |
| 209 | -function wl_get_image_urls( $post_id ) { |
|
| 209 | +function wl_get_image_urls($post_id) { |
|
| 210 | 210 | |
| 211 | 211 | return Wordlift_Storage_Factory::get_instance() |
| 212 | 212 | ->post_images() |
| 213 | - ->get( $post_id ); |
|
| 213 | + ->get($post_id); |
|
| 214 | 214 | |
| 215 | 215 | } |
| 216 | 216 | |
@@ -222,21 +222,21 @@ discard block |
||
| 222 | 222 | * |
| 223 | 223 | * @return WP_Post|null A post instance or null if not found. |
| 224 | 224 | */ |
| 225 | -function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) { |
|
| 225 | +function wl_get_attachment_for_source_url($parent_post_id, $source_url) { |
|
| 226 | 226 | |
| 227 | 227 | // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
| 228 | 228 | |
| 229 | - $posts = get_posts( array( |
|
| 229 | + $posts = get_posts(array( |
|
| 230 | 230 | 'post_type' => 'attachment', |
| 231 | 231 | 'posts_per_page' => 1, |
| 232 | 232 | 'post_status' => 'any', |
| 233 | 233 | 'post_parent' => $parent_post_id, |
| 234 | 234 | 'meta_key' => 'wl_source_url', |
| 235 | 235 | 'meta_value' => $source_url, |
| 236 | - ) ); |
|
| 236 | + )); |
|
| 237 | 237 | |
| 238 | 238 | // Return the found post. |
| 239 | - if ( 1 === count( $posts ) ) { |
|
| 239 | + if (1 === count($posts)) { |
|
| 240 | 240 | return $posts[0]; |
| 241 | 241 | } |
| 242 | 242 | |
@@ -250,10 +250,10 @@ discard block |
||
| 250 | 250 | * @param int $post_id The post ID. |
| 251 | 251 | * @param string $source_url The source URL. |
| 252 | 252 | */ |
| 253 | -function wl_set_source_url( $post_id, $source_url ) { |
|
| 253 | +function wl_set_source_url($post_id, $source_url) { |
|
| 254 | 254 | |
| 255 | - delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 256 | - add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 255 | + delete_post_meta($post_id, 'wl_source_url'); |
|
| 256 | + add_post_meta($post_id, 'wl_source_url', $source_url); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -268,9 +268,9 @@ discard block |
||
| 268 | 268 | * @see https://codex.wordpress.org/Function_Reference/sanitize_title |
| 269 | 269 | * |
| 270 | 270 | */ |
| 271 | -function wl_sanitize_uri_path( $path, $char = '_' ) { |
|
| 271 | +function wl_sanitize_uri_path($path, $char = '_') { |
|
| 272 | 272 | |
| 273 | - return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char ); |
|
| 273 | + return Wordlift_Uri_Service::get_instance()->sanitize_path($path, $char); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -280,104 +280,104 @@ discard block |
||
| 280 | 280 | * |
| 281 | 281 | * @return string The updated post content. |
| 282 | 282 | */ |
| 283 | -function wl_replace_item_id_with_uri( $content ) { |
|
| 283 | +function wl_replace_item_id_with_uri($content) { |
|
| 284 | 284 | |
| 285 | - $log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' ); |
|
| 286 | - $log->trace( 'Replacing item IDs with URIs...' ); |
|
| 285 | + $log = Wordlift_Log_Service::get_logger('wl_replace_item_id_with_uri'); |
|
| 286 | + $log->trace('Replacing item IDs with URIs...'); |
|
| 287 | 287 | |
| 288 | 288 | // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
| 289 | - $content = stripslashes( $content ); |
|
| 289 | + $content = stripslashes($content); |
|
| 290 | 290 | |
| 291 | 291 | // If any match are found. |
| 292 | 292 | $matches = array(); |
| 293 | - if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 293 | + if (0 < preg_match_all('/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER)) { |
|
| 294 | 294 | |
| 295 | - foreach ( $matches as $match ) { |
|
| 295 | + foreach ($matches as $match) { |
|
| 296 | 296 | |
| 297 | 297 | // Get the item ID. |
| 298 | 298 | $item_id = $match[1]; |
| 299 | 299 | |
| 300 | 300 | // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
| 301 | 301 | $post = Wordlift_Entity_Service::get_instance() |
| 302 | - ->get_entity_post_by_uri( $item_id ); |
|
| 302 | + ->get_entity_post_by_uri($item_id); |
|
| 303 | 303 | |
| 304 | 304 | // If no entity is found, continue to the next one. |
| 305 | - if ( null === $post ) { |
|
| 305 | + if (null === $post) { |
|
| 306 | 306 | continue; |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | // Get the URI for that post. |
| 310 | - $uri = wl_get_entity_uri( $post->ID ); |
|
| 310 | + $uri = wl_get_entity_uri($post->ID); |
|
| 311 | 311 | |
| 312 | 312 | // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
| 313 | 313 | |
| 314 | 314 | // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
| 315 | - if ( ! empty( $uri ) && $item_id !== $uri ) { |
|
| 316 | - $uri_e = esc_html( $uri ); |
|
| 317 | - $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 315 | + if ( ! empty($uri) && $item_id !== $uri) { |
|
| 316 | + $uri_e = esc_html($uri); |
|
| 317 | + $content = str_replace(" itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content); |
|
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | // Reapply slashes. |
| 323 | - $content = addslashes( $content ); |
|
| 323 | + $content = addslashes($content); |
|
| 324 | 324 | |
| 325 | 325 | return $content; |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | -add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 ); |
|
| 328 | +add_filter('content_save_pre', 'wl_replace_item_id_with_uri', 1, 1); |
|
| 329 | 329 | |
| 330 | -require_once( 'wordlift_entity_functions.php' ); |
|
| 330 | +require_once('wordlift_entity_functions.php'); |
|
| 331 | 331 | |
| 332 | 332 | // add editor related methods. |
| 333 | -require_once( 'wordlift_editor.php' ); |
|
| 333 | +require_once('wordlift_editor.php'); |
|
| 334 | 334 | |
| 335 | 335 | // add the WordLift entity custom type. |
| 336 | -require_once( 'wordlift_entity_type.php' ); |
|
| 336 | +require_once('wordlift_entity_type.php'); |
|
| 337 | 337 | |
| 338 | 338 | // add callbacks on post save to notify data changes from wp to redlink triple store |
| 339 | -require_once( 'wordlift_to_redlink_data_push_callbacks.php' ); |
|
| 339 | +require_once('wordlift_to_redlink_data_push_callbacks.php'); |
|
| 340 | 340 | |
| 341 | -require_once( 'modules/configuration/wordlift_configuration_settings.php' ); |
|
| 341 | +require_once('modules/configuration/wordlift_configuration_settings.php'); |
|
| 342 | 342 | |
| 343 | 343 | // Load modules |
| 344 | -require_once( 'modules/analyzer/wordlift_analyzer.php' ); |
|
| 345 | -require_once( 'modules/linked_data/wordlift_linked_data.php' ); |
|
| 346 | -require_once( 'modules/prefixes/wordlift_prefixes.php' ); |
|
| 344 | +require_once('modules/analyzer/wordlift_analyzer.php'); |
|
| 345 | +require_once('modules/linked_data/wordlift_linked_data.php'); |
|
| 346 | +require_once('modules/prefixes/wordlift_prefixes.php'); |
|
| 347 | 347 | |
| 348 | 348 | // Shortcodes |
| 349 | 349 | |
| 350 | -require_once( 'modules/geo_widget/wordlift_geo_widget.php' ); |
|
| 351 | -require_once( 'shortcodes/class-wordlift-shortcode-rest.php' ); |
|
| 352 | -require_once( 'shortcodes/wordlift_shortcode_chord.php' ); |
|
| 353 | -require_once( 'shortcodes/wordlift_shortcode_geomap.php' ); |
|
| 354 | -require_once( 'shortcodes/wordlift_shortcode_field.php' ); |
|
| 355 | -require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' ); |
|
| 356 | -require_once( 'shortcodes/wordlift_shortcode_navigator.php' ); |
|
| 357 | -require_once( 'shortcodes/class-wordlift-products-navigator-shortcode-rest.php' ); |
|
| 350 | +require_once('modules/geo_widget/wordlift_geo_widget.php'); |
|
| 351 | +require_once('shortcodes/class-wordlift-shortcode-rest.php'); |
|
| 352 | +require_once('shortcodes/wordlift_shortcode_chord.php'); |
|
| 353 | +require_once('shortcodes/wordlift_shortcode_geomap.php'); |
|
| 354 | +require_once('shortcodes/wordlift_shortcode_field.php'); |
|
| 355 | +require_once('shortcodes/wordlift_shortcode_faceted_search.php'); |
|
| 356 | +require_once('shortcodes/wordlift_shortcode_navigator.php'); |
|
| 357 | +require_once('shortcodes/class-wordlift-products-navigator-shortcode-rest.php'); |
|
| 358 | 358 | |
| 359 | -require_once( 'widgets/wordlift_widget_geo.php' ); |
|
| 360 | -require_once( 'widgets/class-wordlift-chord-widget.php' ); |
|
| 361 | -require_once( 'widgets/wordlift_widget_timeline.php' ); |
|
| 359 | +require_once('widgets/wordlift_widget_geo.php'); |
|
| 360 | +require_once('widgets/class-wordlift-chord-widget.php'); |
|
| 361 | +require_once('widgets/wordlift_widget_timeline.php'); |
|
| 362 | 362 | |
| 363 | -require_once( 'wordlift_redlink.php' ); |
|
| 363 | +require_once('wordlift_redlink.php'); |
|
| 364 | 364 | |
| 365 | 365 | // Add admin functions. |
| 366 | 366 | // TODO: find a way to make 'admin' UI tests work. |
| 367 | 367 | //if ( is_admin() ) { |
| 368 | 368 | |
| 369 | -require_once( 'admin/wordlift_admin.php' ); |
|
| 370 | -require_once( 'admin/wordlift_admin_edit_post.php' ); |
|
| 371 | -require_once( 'admin/wordlift_admin_save_post.php' ); |
|
| 369 | +require_once('admin/wordlift_admin.php'); |
|
| 370 | +require_once('admin/wordlift_admin_edit_post.php'); |
|
| 371 | +require_once('admin/wordlift_admin_save_post.php'); |
|
| 372 | 372 | |
| 373 | 373 | // add the entities meta box. |
| 374 | -require_once( 'admin/wordlift_admin_meta_box_entities.php' ); |
|
| 374 | +require_once('admin/wordlift_admin_meta_box_entities.php'); |
|
| 375 | 375 | |
| 376 | 376 | // add the entity creation AJAX. |
| 377 | -require_once( 'admin/wordlift_admin_ajax_related_posts.php' ); |
|
| 377 | +require_once('admin/wordlift_admin_ajax_related_posts.php'); |
|
| 378 | 378 | |
| 379 | 379 | // Load the wl_chord TinyMCE button and configuration dialog. |
| 380 | -require_once( 'admin/wordlift_admin_shortcodes.php' ); |
|
| 380 | +require_once('admin/wordlift_admin_shortcodes.php'); |
|
| 381 | 381 | |
| 382 | 382 | /** |
| 383 | 383 | * The code that runs during plugin activation. |
@@ -385,11 +385,11 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | function activate_wordlift() { |
| 387 | 387 | |
| 388 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
| 388 | + $log = Wordlift_Log_Service::get_logger('activate_wordlift'); |
|
| 389 | 389 | |
| 390 | - $log->info( 'Activating WordLift...' ); |
|
| 390 | + $log->info('Activating WordLift...'); |
|
| 391 | 391 | |
| 392 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 392 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php'; |
|
| 393 | 393 | Wordlift_Activator::activate(); |
| 394 | 394 | |
| 395 | 395 | /** |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | */ |
| 417 | 417 | function deactivate_wordlift() { |
| 418 | 418 | |
| 419 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 419 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php'; |
|
| 420 | 420 | Wordlift_Deactivator::deactivate(); |
| 421 | 421 | Wordlift_Http_Api::deactivate(); |
| 422 | 422 | Ttl_Cache_Cleaner::deactivate(); |
@@ -434,14 +434,14 @@ discard block |
||
| 434 | 434 | |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | -register_activation_hook( __FILE__, 'activate_wordlift' ); |
|
| 438 | -register_deactivation_hook( __FILE__, 'deactivate_wordlift' ); |
|
| 437 | +register_activation_hook(__FILE__, 'activate_wordlift'); |
|
| 438 | +register_deactivation_hook(__FILE__, 'deactivate_wordlift'); |
|
| 439 | 439 | |
| 440 | 440 | /** |
| 441 | 441 | * The core plugin class that is used to define internationalization, |
| 442 | 442 | * admin-specific hooks, and public-facing site hooks. |
| 443 | 443 | */ |
| 444 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php'; |
|
| 444 | +require plugin_dir_path(__FILE__).'includes/class-wordlift.php'; |
|
| 445 | 445 | |
| 446 | 446 | /** |
| 447 | 447 | * Begins execution of the plugin. |
@@ -461,12 +461,12 @@ discard block |
||
| 461 | 461 | * @return bool |
| 462 | 462 | * @since 3.27.6 |
| 463 | 463 | */ |
| 464 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
| 465 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
| 466 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
| 467 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
| 464 | + if (apply_filters('wl_feature__enable__widgets', true)) { |
|
| 465 | + add_action('widgets_init', 'wl_register_chord_widget'); |
|
| 466 | + add_action('widgets_init', 'wl_register_geo_widget'); |
|
| 467 | + add_action('widgets_init', 'wl_register_timeline_widget'); |
|
| 468 | 468 | } |
| 469 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
| 469 | + add_filter('widget_text', 'do_shortcode'); |
|
| 470 | 470 | |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -477,10 +477,10 @@ discard block |
||
| 477 | 477 | * @return bool |
| 478 | 478 | * @since 3.27.6 |
| 479 | 479 | */ |
| 480 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
| 481 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
| 480 | + if (apply_filters('wl_feature__enable__analysis', true)) { |
|
| 481 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action'); |
|
| 482 | 482 | } else { |
| 483 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
| 483 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action'); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | /* |
@@ -500,56 +500,56 @@ discard block |
||
| 500 | 500 | new Post_Adapter(); |
| 501 | 501 | |
| 502 | 502 | // Load the API Data Hooks. |
| 503 | - new Api_Data_Hooks( Wordlift_Configuration_Service::get_instance() ); |
|
| 503 | + new Api_Data_Hooks(Wordlift_Configuration_Service::get_instance()); |
|
| 504 | 504 | |
| 505 | - add_action( 'plugins_loaded', function () { |
|
| 505 | + add_action('plugins_loaded', function() { |
|
| 506 | 506 | // Load early. **PLEASE NOTE** that features are applied only to calls that happen **AFTER** the `plugins_loaded` |
| 507 | 507 | // action. |
| 508 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php'; |
|
| 508 | + require_once plugin_dir_path(__FILE__).'wordlift/features/index.php'; |
|
| 509 | 509 | |
| 510 | 510 | // All features from registry should be initialized here. |
| 511 | 511 | $features_registry = Features_Registry::get_instance(); |
| 512 | 512 | $features_registry->initialize_all_features(); |
| 513 | - }, 1 ); |
|
| 513 | + }, 1); |
|
| 514 | 514 | |
| 515 | - add_action( 'plugins_loaded', function () use ( $plugin ) { |
|
| 515 | + add_action('plugins_loaded', function() use ($plugin) { |
|
| 516 | 516 | // Licenses Images. |
| 517 | 517 | $user_agent = User_Agent::get_user_agent(); |
| 518 | 518 | $wordlift_key = Wordlift_Configuration_Service::get_instance()->get_key(); |
| 519 | - $api_service = new Default_Api_Service( apply_filters( 'wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ), 60, $user_agent, $wordlift_key ); |
|
| 519 | + $api_service = new Default_Api_Service(apply_filters('wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE), 60, $user_agent, $wordlift_key); |
|
| 520 | 520 | $image_license_factory = new Image_License_Factory(); |
| 521 | - $image_license_service = new Image_License_Service( $api_service, $image_license_factory ); |
|
| 522 | - $image_license_cache = new Ttl_Cache( 'image-license', 86400 * 30 ); // 30 days. |
|
| 523 | - $cached_image_license_service = new Cached_Image_License_Service( $image_license_service, $image_license_cache ); |
|
| 521 | + $image_license_service = new Image_License_Service($api_service, $image_license_factory); |
|
| 522 | + $image_license_cache = new Ttl_Cache('image-license', 86400 * 30); // 30 days. |
|
| 523 | + $cached_image_license_service = new Cached_Image_License_Service($image_license_service, $image_license_cache); |
|
| 524 | 524 | |
| 525 | - $image_license_scheduler = new Image_License_Scheduler( $image_license_service, $image_license_cache ); |
|
| 525 | + $image_license_scheduler = new Image_License_Scheduler($image_license_service, $image_license_cache); |
|
| 526 | 526 | $image_license_cleanup_service = new Image_License_Cleanup_Service(); |
| 527 | 527 | |
| 528 | 528 | // Get the cached data. If we have cached data, we load the notifier. |
| 529 | - $image_license_data = $image_license_cache->get( Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES ); |
|
| 530 | - if ( null !== $image_license_data ) { |
|
| 531 | - $image_license_page = new Image_License_Page( $image_license_data, Wordlift::get_instance()->get_version() ); |
|
| 532 | - new Image_License_Notifier( $image_license_data, $image_license_page ); |
|
| 529 | + $image_license_data = $image_license_cache->get(Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES); |
|
| 530 | + if (null !== $image_license_data) { |
|
| 531 | + $image_license_page = new Image_License_Page($image_license_data, Wordlift::get_instance()->get_version()); |
|
| 532 | + new Image_License_Notifier($image_license_data, $image_license_page); |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | - $remove_all_images_task = new Remove_All_Images_Task( $cached_image_license_service ); |
|
| 536 | - $remove_all_images_task_adapter = new Task_Ajax_Adapter( $remove_all_images_task ); |
|
| 535 | + $remove_all_images_task = new Remove_All_Images_Task($cached_image_license_service); |
|
| 536 | + $remove_all_images_task_adapter = new Task_Ajax_Adapter($remove_all_images_task); |
|
| 537 | 537 | |
| 538 | 538 | $reload_data_task = new Reload_Data_Task(); |
| 539 | - $reload_data_task_adapter = new Task_Ajax_Adapter( $reload_data_task ); |
|
| 539 | + $reload_data_task_adapter = new Task_Ajax_Adapter($reload_data_task); |
|
| 540 | 540 | |
| 541 | - $add_license_caption_or_remove_task = new Add_License_Caption_Or_Remove_Task( $cached_image_license_service ); |
|
| 542 | - $add_license_caption_or_remove_task_adapter = new Task_Ajax_Adapter( $add_license_caption_or_remove_task ); |
|
| 541 | + $add_license_caption_or_remove_task = new Add_License_Caption_Or_Remove_Task($cached_image_license_service); |
|
| 542 | + $add_license_caption_or_remove_task_adapter = new Task_Ajax_Adapter($add_license_caption_or_remove_task); |
|
| 543 | 543 | |
| 544 | - $remove_all_images_task_page = new Remove_All_Images_Page( new Task_Ajax_Adapters_Registry( $remove_all_images_task_adapter ), $plugin->get_version() ); |
|
| 545 | - $reload_data_task_page = new Reload_Data_Page( new Task_Ajax_Adapters_Registry( $reload_data_task_adapter ), $plugin->get_version() ); |
|
| 546 | - $add_license_caption_or_remove_task_page = new Add_License_Caption_Or_Remove_Page( new Task_Ajax_Adapters_Registry( $add_license_caption_or_remove_task_adapter ), $plugin->get_version() ); |
|
| 544 | + $remove_all_images_task_page = new Remove_All_Images_Page(new Task_Ajax_Adapters_Registry($remove_all_images_task_adapter), $plugin->get_version()); |
|
| 545 | + $reload_data_task_page = new Reload_Data_Page(new Task_Ajax_Adapters_Registry($reload_data_task_adapter), $plugin->get_version()); |
|
| 546 | + $add_license_caption_or_remove_task_page = new Add_License_Caption_Or_Remove_Page(new Task_Ajax_Adapters_Registry($add_license_caption_or_remove_task_adapter), $plugin->get_version()); |
|
| 547 | 547 | |
| 548 | 548 | new Wordlift_Products_Navigator_Shortcode_REST(); |
| 549 | 549 | |
| 550 | 550 | // Register the Dataset module, requires `$api_service`. |
| 551 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
| 552 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
| 551 | + require_once plugin_dir_path(__FILE__).'wordlift/dataset/index.php'; |
|
| 552 | + require_once plugin_dir_path(__FILE__).'wordlift/shipping-data/index.php'; |
|
| 553 | 553 | |
| 554 | 554 | } ); |
| 555 | 555 | |
@@ -565,24 +565,24 @@ discard block |
||
| 565 | 565 | */ |
| 566 | 566 | function wordlift_plugin_autoload_register() { |
| 567 | 567 | |
| 568 | - spl_autoload_register( function ( $class_name ) { |
|
| 568 | + spl_autoload_register(function($class_name) { |
|
| 569 | 569 | |
| 570 | 570 | // Bail out if these are not our classes. |
| 571 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
| 571 | + if (0 !== strpos($class_name, 'Wordlift\\')) { |
|
| 572 | 572 | return false; |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
| 575 | + $class_name_lc = strtolower(str_replace('_', '-', $class_name)); |
|
| 576 | 576 | |
| 577 | - preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
| 577 | + preg_match('|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches); |
|
| 578 | 578 | |
| 579 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
| 580 | - $file = 'class-' . $matches[2] . '.php'; |
|
| 579 | + $path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]); |
|
| 580 | + $file = 'class-'.$matches[2].'.php'; |
|
| 581 | 581 | |
| 582 | - $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
| 582 | + $full_path = plugin_dir_path(__FILE__).$path.DIRECTORY_SEPARATOR.$file; |
|
| 583 | 583 | |
| 584 | - if ( ! file_exists( $full_path ) ) { |
|
| 585 | - echo esc_html( "Class $class_name not found at $full_path." ); |
|
| 584 | + if ( ! file_exists($full_path)) { |
|
| 585 | + echo esc_html("Class $class_name not found at $full_path."); |
|
| 586 | 586 | |
| 587 | 587 | return false; |
| 588 | 588 | } |
@@ -594,16 +594,16 @@ discard block |
||
| 594 | 594 | |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | -function wl_block_categories( $categories, $post ) { |
|
| 597 | +function wl_block_categories($categories, $post) { |
|
| 598 | 598 | return array_merge( |
| 599 | 599 | $categories, |
| 600 | 600 | array( |
| 601 | 601 | array( |
| 602 | 602 | 'slug' => 'wordlift', |
| 603 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
| 603 | + 'title' => __('WordLift', 'wordlift'), |
|
| 604 | 604 | ), |
| 605 | 605 | ) |
| 606 | 606 | ); |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | -add_filter( 'block_categories', 'wl_block_categories', 10, 2 ); |
|
| 609 | +add_filter('block_categories', 'wl_block_categories', 10, 2); |
|
@@ -28,143 +28,143 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class Entity_Store { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * A singleton instance. |
|
| 33 | - * |
|
| 34 | - * @access private |
|
| 35 | - * @var Entity_Store $instance A singleton instance. |
|
| 36 | - */ |
|
| 37 | - private static $instance; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * A {@link Wordlift_Entity_Service} instance. |
|
| 41 | - * |
|
| 42 | - * @access private |
|
| 43 | - * @var \Wordlift_Entity_Service A {@link Wordlift_Entity_Service} instance. |
|
| 44 | - */ |
|
| 45 | - private $entity_service; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Create an Entity Store instance. |
|
| 49 | - */ |
|
| 50 | - public function __construct() { |
|
| 51 | - |
|
| 52 | - $this->entity_service = \Wordlift_Entity_Service::get_instance(); |
|
| 53 | - |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Get the Entity_Store singleton, lazily initialized. |
|
| 58 | - * |
|
| 59 | - * @return Entity_Store The singleton. |
|
| 60 | - */ |
|
| 61 | - public static function get_instance() { |
|
| 62 | - |
|
| 63 | - if ( isset( self::$instance ) ) { |
|
| 64 | - return self::$instance; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - self::$instance = new Entity_Store(); |
|
| 68 | - |
|
| 69 | - return self::$instance; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Create and persist an entity. |
|
| 74 | - * |
|
| 75 | - * @param array $params { |
|
| 76 | - * The entity parameters. |
|
| 77 | - * |
|
| 78 | - * @type string|array $labels A label, or an array of labels. The first label is set as post title. |
|
| 79 | - * @type string $description The entity description, stored in the post content. |
|
| 80 | - * @type string|array $same_as One or more entity URIs, stored in the sameAs post meta. |
|
| 81 | - * } |
|
| 82 | - * |
|
| 83 | - * @param string $post_status The post status, by default `draft`. |
|
| 84 | - * |
|
| 85 | - * @return int|\WP_Error |
|
| 86 | - * @throws \Exception |
|
| 87 | - */ |
|
| 88 | - public function create( $params, $post_status = 'draft' ) { |
|
| 89 | - |
|
| 90 | - $args = wp_parse_args( $params, array( |
|
| 91 | - 'labels' => array(), |
|
| 92 | - 'description' => '', |
|
| 93 | - 'same_as' => array(), |
|
| 94 | - ) ); |
|
| 95 | - |
|
| 96 | - // Use the first label as `post_title`. |
|
| 97 | - $labels = (array) $args['labels']; |
|
| 98 | - $label = array_shift( $labels ); |
|
| 99 | - |
|
| 100 | - $post_id = wp_insert_post( array( |
|
| 101 | - 'post_type' => \Wordlift_Entity_Service::TYPE_NAME, |
|
| 102 | - 'post_status' => $post_status, |
|
| 103 | - 'post_title' => $label, |
|
| 104 | - 'post_name' => sanitize_title( $label ), |
|
| 105 | - 'post_content' => $args['description'], |
|
| 106 | - ) ); |
|
| 107 | - |
|
| 108 | - // Bail out if we've got an error. |
|
| 109 | - if ( empty( $post_id ) || is_wp_error( $post_id ) ) { |
|
| 110 | - throw new \Exception( "An error occurred while creating an entity." ); |
|
| 111 | - } |
|
| 112 | - // Save synonyms except title. |
|
| 113 | - $this->entity_service->set_alternative_labels( $post_id, array_diff( $labels, array( $label ) ) ); |
|
| 114 | - $this->merge_post_meta( $post_id, \Wordlift_Schema_Service::FIELD_SAME_AS, (array) $args['same_as'], get_post_meta( $post_id, WL_ENTITY_URL_META_NAME ) ); |
|
| 115 | - |
|
| 116 | - return $post_id; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Update an entity. |
|
| 121 | - * |
|
| 122 | - * @param array $params { |
|
| 123 | - * |
|
| 124 | - * @type int $ID The post ID. |
|
| 125 | - * @type string|array One or more labels to add to the synonyms. |
|
| 126 | - * @type string|array One or more URIs to add to the sameAs. |
|
| 127 | - * } |
|
| 128 | - * |
|
| 129 | - * @return int The post id. |
|
| 130 | - */ |
|
| 131 | - public function update( $params ) { |
|
| 132 | - |
|
| 133 | - $args = wp_parse_args( $params, array( |
|
| 134 | - 'ID' => 0, |
|
| 135 | - 'labels' => array(), |
|
| 136 | - 'same_as' => array(), |
|
| 137 | - ) ); |
|
| 138 | - |
|
| 139 | - $post_id = $args['ID']; |
|
| 140 | - |
|
| 141 | - // Save synonyms except title. |
|
| 142 | - $this->entity_service->set_alternative_labels( $post_id, array_diff( (array) $args['labels'], array( get_the_title( $post_id ) ) ) ); |
|
| 143 | - $this->merge_post_meta( $post_id, \Wordlift_Schema_Service::FIELD_SAME_AS, (array) $args['same_as'], get_post_meta( $post_id, WL_ENTITY_URL_META_NAME ) ); |
|
| 144 | - |
|
| 145 | - return $post_id; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Merge the post meta. |
|
| 150 | - * |
|
| 151 | - * @param int $post_id The post ID. |
|
| 152 | - * @param string $meta_key The post meta key. |
|
| 153 | - * @param string|array $values One or more values to add. |
|
| 154 | - * @param string|array $exclusions An additional list of values to exclude. |
|
| 155 | - */ |
|
| 156 | - private function merge_post_meta( $post_id, $meta_key, $values, $exclusions = array() ) { |
|
| 157 | - |
|
| 158 | - $existing = array_merge( |
|
| 159 | - (array) $exclusions, |
|
| 160 | - get_post_meta( $post_id, $meta_key ) |
|
| 161 | - ); |
|
| 162 | - |
|
| 163 | - foreach ( (array) $values as $value ) { |
|
| 164 | - if ( ! in_array( $value, $existing ) ) { |
|
| 165 | - add_post_meta( $post_id, $meta_key, $value ); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - } |
|
| 31 | + /** |
|
| 32 | + * A singleton instance. |
|
| 33 | + * |
|
| 34 | + * @access private |
|
| 35 | + * @var Entity_Store $instance A singleton instance. |
|
| 36 | + */ |
|
| 37 | + private static $instance; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * A {@link Wordlift_Entity_Service} instance. |
|
| 41 | + * |
|
| 42 | + * @access private |
|
| 43 | + * @var \Wordlift_Entity_Service A {@link Wordlift_Entity_Service} instance. |
|
| 44 | + */ |
|
| 45 | + private $entity_service; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Create an Entity Store instance. |
|
| 49 | + */ |
|
| 50 | + public function __construct() { |
|
| 51 | + |
|
| 52 | + $this->entity_service = \Wordlift_Entity_Service::get_instance(); |
|
| 53 | + |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Get the Entity_Store singleton, lazily initialized. |
|
| 58 | + * |
|
| 59 | + * @return Entity_Store The singleton. |
|
| 60 | + */ |
|
| 61 | + public static function get_instance() { |
|
| 62 | + |
|
| 63 | + if ( isset( self::$instance ) ) { |
|
| 64 | + return self::$instance; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + self::$instance = new Entity_Store(); |
|
| 68 | + |
|
| 69 | + return self::$instance; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Create and persist an entity. |
|
| 74 | + * |
|
| 75 | + * @param array $params { |
|
| 76 | + * The entity parameters. |
|
| 77 | + * |
|
| 78 | + * @type string|array $labels A label, or an array of labels. The first label is set as post title. |
|
| 79 | + * @type string $description The entity description, stored in the post content. |
|
| 80 | + * @type string|array $same_as One or more entity URIs, stored in the sameAs post meta. |
|
| 81 | + * } |
|
| 82 | + * |
|
| 83 | + * @param string $post_status The post status, by default `draft`. |
|
| 84 | + * |
|
| 85 | + * @return int|\WP_Error |
|
| 86 | + * @throws \Exception |
|
| 87 | + */ |
|
| 88 | + public function create( $params, $post_status = 'draft' ) { |
|
| 89 | + |
|
| 90 | + $args = wp_parse_args( $params, array( |
|
| 91 | + 'labels' => array(), |
|
| 92 | + 'description' => '', |
|
| 93 | + 'same_as' => array(), |
|
| 94 | + ) ); |
|
| 95 | + |
|
| 96 | + // Use the first label as `post_title`. |
|
| 97 | + $labels = (array) $args['labels']; |
|
| 98 | + $label = array_shift( $labels ); |
|
| 99 | + |
|
| 100 | + $post_id = wp_insert_post( array( |
|
| 101 | + 'post_type' => \Wordlift_Entity_Service::TYPE_NAME, |
|
| 102 | + 'post_status' => $post_status, |
|
| 103 | + 'post_title' => $label, |
|
| 104 | + 'post_name' => sanitize_title( $label ), |
|
| 105 | + 'post_content' => $args['description'], |
|
| 106 | + ) ); |
|
| 107 | + |
|
| 108 | + // Bail out if we've got an error. |
|
| 109 | + if ( empty( $post_id ) || is_wp_error( $post_id ) ) { |
|
| 110 | + throw new \Exception( "An error occurred while creating an entity." ); |
|
| 111 | + } |
|
| 112 | + // Save synonyms except title. |
|
| 113 | + $this->entity_service->set_alternative_labels( $post_id, array_diff( $labels, array( $label ) ) ); |
|
| 114 | + $this->merge_post_meta( $post_id, \Wordlift_Schema_Service::FIELD_SAME_AS, (array) $args['same_as'], get_post_meta( $post_id, WL_ENTITY_URL_META_NAME ) ); |
|
| 115 | + |
|
| 116 | + return $post_id; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Update an entity. |
|
| 121 | + * |
|
| 122 | + * @param array $params { |
|
| 123 | + * |
|
| 124 | + * @type int $ID The post ID. |
|
| 125 | + * @type string|array One or more labels to add to the synonyms. |
|
| 126 | + * @type string|array One or more URIs to add to the sameAs. |
|
| 127 | + * } |
|
| 128 | + * |
|
| 129 | + * @return int The post id. |
|
| 130 | + */ |
|
| 131 | + public function update( $params ) { |
|
| 132 | + |
|
| 133 | + $args = wp_parse_args( $params, array( |
|
| 134 | + 'ID' => 0, |
|
| 135 | + 'labels' => array(), |
|
| 136 | + 'same_as' => array(), |
|
| 137 | + ) ); |
|
| 138 | + |
|
| 139 | + $post_id = $args['ID']; |
|
| 140 | + |
|
| 141 | + // Save synonyms except title. |
|
| 142 | + $this->entity_service->set_alternative_labels( $post_id, array_diff( (array) $args['labels'], array( get_the_title( $post_id ) ) ) ); |
|
| 143 | + $this->merge_post_meta( $post_id, \Wordlift_Schema_Service::FIELD_SAME_AS, (array) $args['same_as'], get_post_meta( $post_id, WL_ENTITY_URL_META_NAME ) ); |
|
| 144 | + |
|
| 145 | + return $post_id; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Merge the post meta. |
|
| 150 | + * |
|
| 151 | + * @param int $post_id The post ID. |
|
| 152 | + * @param string $meta_key The post meta key. |
|
| 153 | + * @param string|array $values One or more values to add. |
|
| 154 | + * @param string|array $exclusions An additional list of values to exclude. |
|
| 155 | + */ |
|
| 156 | + private function merge_post_meta( $post_id, $meta_key, $values, $exclusions = array() ) { |
|
| 157 | + |
|
| 158 | + $existing = array_merge( |
|
| 159 | + (array) $exclusions, |
|
| 160 | + get_post_meta( $post_id, $meta_key ) |
|
| 161 | + ); |
|
| 162 | + |
|
| 163 | + foreach ( (array) $values as $value ) { |
|
| 164 | + if ( ! in_array( $value, $existing ) ) { |
|
| 165 | + add_post_meta( $post_id, $meta_key, $value ); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | 170 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | public static function get_instance() { |
| 62 | 62 | |
| 63 | - if ( isset( self::$instance ) ) { |
|
| 63 | + if (isset(self::$instance)) { |
|
| 64 | 64 | return self::$instance; |
| 65 | 65 | } |
| 66 | 66 | |
@@ -85,33 +85,33 @@ discard block |
||
| 85 | 85 | * @return int|\WP_Error |
| 86 | 86 | * @throws \Exception |
| 87 | 87 | */ |
| 88 | - public function create( $params, $post_status = 'draft' ) { |
|
| 88 | + public function create($params, $post_status = 'draft') { |
|
| 89 | 89 | |
| 90 | - $args = wp_parse_args( $params, array( |
|
| 90 | + $args = wp_parse_args($params, array( |
|
| 91 | 91 | 'labels' => array(), |
| 92 | 92 | 'description' => '', |
| 93 | 93 | 'same_as' => array(), |
| 94 | - ) ); |
|
| 94 | + )); |
|
| 95 | 95 | |
| 96 | 96 | // Use the first label as `post_title`. |
| 97 | 97 | $labels = (array) $args['labels']; |
| 98 | - $label = array_shift( $labels ); |
|
| 98 | + $label = array_shift($labels); |
|
| 99 | 99 | |
| 100 | - $post_id = wp_insert_post( array( |
|
| 100 | + $post_id = wp_insert_post(array( |
|
| 101 | 101 | 'post_type' => \Wordlift_Entity_Service::TYPE_NAME, |
| 102 | 102 | 'post_status' => $post_status, |
| 103 | 103 | 'post_title' => $label, |
| 104 | - 'post_name' => sanitize_title( $label ), |
|
| 104 | + 'post_name' => sanitize_title($label), |
|
| 105 | 105 | 'post_content' => $args['description'], |
| 106 | - ) ); |
|
| 106 | + )); |
|
| 107 | 107 | |
| 108 | 108 | // Bail out if we've got an error. |
| 109 | - if ( empty( $post_id ) || is_wp_error( $post_id ) ) { |
|
| 110 | - throw new \Exception( "An error occurred while creating an entity." ); |
|
| 109 | + if (empty($post_id) || is_wp_error($post_id)) { |
|
| 110 | + throw new \Exception("An error occurred while creating an entity."); |
|
| 111 | 111 | } |
| 112 | 112 | // Save synonyms except title. |
| 113 | - $this->entity_service->set_alternative_labels( $post_id, array_diff( $labels, array( $label ) ) ); |
|
| 114 | - $this->merge_post_meta( $post_id, \Wordlift_Schema_Service::FIELD_SAME_AS, (array) $args['same_as'], get_post_meta( $post_id, WL_ENTITY_URL_META_NAME ) ); |
|
| 113 | + $this->entity_service->set_alternative_labels($post_id, array_diff($labels, array($label))); |
|
| 114 | + $this->merge_post_meta($post_id, \Wordlift_Schema_Service::FIELD_SAME_AS, (array) $args['same_as'], get_post_meta($post_id, WL_ENTITY_URL_META_NAME)); |
|
| 115 | 115 | |
| 116 | 116 | return $post_id; |
| 117 | 117 | } |
@@ -128,19 +128,19 @@ discard block |
||
| 128 | 128 | * |
| 129 | 129 | * @return int The post id. |
| 130 | 130 | */ |
| 131 | - public function update( $params ) { |
|
| 131 | + public function update($params) { |
|
| 132 | 132 | |
| 133 | - $args = wp_parse_args( $params, array( |
|
| 133 | + $args = wp_parse_args($params, array( |
|
| 134 | 134 | 'ID' => 0, |
| 135 | 135 | 'labels' => array(), |
| 136 | 136 | 'same_as' => array(), |
| 137 | - ) ); |
|
| 137 | + )); |
|
| 138 | 138 | |
| 139 | 139 | $post_id = $args['ID']; |
| 140 | 140 | |
| 141 | 141 | // Save synonyms except title. |
| 142 | - $this->entity_service->set_alternative_labels( $post_id, array_diff( (array) $args['labels'], array( get_the_title( $post_id ) ) ) ); |
|
| 143 | - $this->merge_post_meta( $post_id, \Wordlift_Schema_Service::FIELD_SAME_AS, (array) $args['same_as'], get_post_meta( $post_id, WL_ENTITY_URL_META_NAME ) ); |
|
| 142 | + $this->entity_service->set_alternative_labels($post_id, array_diff((array) $args['labels'], array(get_the_title($post_id)))); |
|
| 143 | + $this->merge_post_meta($post_id, \Wordlift_Schema_Service::FIELD_SAME_AS, (array) $args['same_as'], get_post_meta($post_id, WL_ENTITY_URL_META_NAME)); |
|
| 144 | 144 | |
| 145 | 145 | return $post_id; |
| 146 | 146 | } |
@@ -153,16 +153,16 @@ discard block |
||
| 153 | 153 | * @param string|array $values One or more values to add. |
| 154 | 154 | * @param string|array $exclusions An additional list of values to exclude. |
| 155 | 155 | */ |
| 156 | - private function merge_post_meta( $post_id, $meta_key, $values, $exclusions = array() ) { |
|
| 156 | + private function merge_post_meta($post_id, $meta_key, $values, $exclusions = array()) { |
|
| 157 | 157 | |
| 158 | 158 | $existing = array_merge( |
| 159 | 159 | (array) $exclusions, |
| 160 | - get_post_meta( $post_id, $meta_key ) |
|
| 160 | + get_post_meta($post_id, $meta_key) |
|
| 161 | 161 | ); |
| 162 | 162 | |
| 163 | - foreach ( (array) $values as $value ) { |
|
| 164 | - if ( ! in_array( $value, $existing ) ) { |
|
| 165 | - add_post_meta( $post_id, $meta_key, $value ); |
|
| 163 | + foreach ((array) $values as $value) { |
|
| 164 | + if ( ! in_array($value, $existing)) { |
|
| 165 | + add_post_meta($post_id, $meta_key, $value); |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | } |