@@ -19,66 +19,66 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | function wordlift_ajax_related_posts( $http_raw_data = null ) { |
| 21 | 21 | |
| 22 | - // Extract filtering conditions |
|
| 23 | - if ( ! isset( $_GET["post_id"] ) || ! is_numeric( $_GET["post_id"] ) ) { |
|
| 24 | - wp_die( 'Post id missing or invalid!' ); |
|
| 25 | - |
|
| 26 | - return; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - // Get the current post |
|
| 30 | - $post_id = (int) $_GET["post_id"]; |
|
| 31 | - $post = get_post( $post_id ); |
|
| 32 | - |
|
| 33 | - Wordlift_Log_Service::get_logger( 'wordlift_ajax_related_posts' )->trace( "Going to find posts related to current with post id: $post_id ..." ); |
|
| 34 | - |
|
| 35 | - // Extract filtering conditions |
|
| 36 | - $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data; |
|
| 37 | - $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
| 38 | - |
|
| 39 | - $content_service = Wordpress_Content_Service::get_instance(); |
|
| 40 | - $filtering_entity_ids = array_filter( array_map( function ( $uri ) use ( $content_service ) { |
|
| 41 | - $content = $content_service->get_by_entity_id( $uri ); |
|
| 42 | - if ( isset( $content ) && is_a( $content->get_bag(), '\WP_Post' ) ) { |
|
| 43 | - return $content->get_bag()->ID; |
|
| 44 | - } else { |
|
| 45 | - return null; |
|
| 46 | - } |
|
| 47 | - }, $filtering_entity_uris ) ); |
|
| 48 | - |
|
| 49 | - $related_posts = array(); |
|
| 50 | - |
|
| 51 | - // If the current post is an entity, related posts to the current entity are |
|
| 52 | - // returned. |
|
| 53 | - $entity_service = Wordlift_Entity_Service::get_instance(); |
|
| 54 | - |
|
| 55 | - if ( $entity_service->is_entity( $post->ID ) ) { |
|
| 56 | - $filtering_entity_ids = array( $post_id ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - if ( ! empty( $filtering_entity_ids ) ) { |
|
| 60 | - |
|
| 61 | - $related_posts = Wordlift_Relation_Service::get_instance() |
|
| 62 | - ->get_article_subjects( $filtering_entity_ids, '*', null, 'publish', array( $post_id ), 5 ); |
|
| 63 | - |
|
| 64 | - foreach ( $related_posts as $post_obj ) { |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Use the thumbnail. |
|
| 68 | - * |
|
| 69 | - * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue. |
|
| 70 | - * @see https://github.com/insideout10/wordlift-plugin/issues/837 |
|
| 71 | - * |
|
| 72 | - * @since 3.19.3 We're using the medium size image. |
|
| 73 | - */ |
|
| 74 | - $thumbnail = get_the_post_thumbnail_url( $post_obj, 'medium' ); |
|
| 75 | - $post_obj->thumbnail = ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 76 | - $post_obj->link = get_edit_post_link( $post_obj->ID, 'none' ); |
|
| 77 | - $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - wl_core_send_json( $related_posts ); |
|
| 22 | + // Extract filtering conditions |
|
| 23 | + if ( ! isset( $_GET["post_id"] ) || ! is_numeric( $_GET["post_id"] ) ) { |
|
| 24 | + wp_die( 'Post id missing or invalid!' ); |
|
| 25 | + |
|
| 26 | + return; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + // Get the current post |
|
| 30 | + $post_id = (int) $_GET["post_id"]; |
|
| 31 | + $post = get_post( $post_id ); |
|
| 32 | + |
|
| 33 | + Wordlift_Log_Service::get_logger( 'wordlift_ajax_related_posts' )->trace( "Going to find posts related to current with post id: $post_id ..." ); |
|
| 34 | + |
|
| 35 | + // Extract filtering conditions |
|
| 36 | + $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data; |
|
| 37 | + $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
| 38 | + |
|
| 39 | + $content_service = Wordpress_Content_Service::get_instance(); |
|
| 40 | + $filtering_entity_ids = array_filter( array_map( function ( $uri ) use ( $content_service ) { |
|
| 41 | + $content = $content_service->get_by_entity_id( $uri ); |
|
| 42 | + if ( isset( $content ) && is_a( $content->get_bag(), '\WP_Post' ) ) { |
|
| 43 | + return $content->get_bag()->ID; |
|
| 44 | + } else { |
|
| 45 | + return null; |
|
| 46 | + } |
|
| 47 | + }, $filtering_entity_uris ) ); |
|
| 48 | + |
|
| 49 | + $related_posts = array(); |
|
| 50 | + |
|
| 51 | + // If the current post is an entity, related posts to the current entity are |
|
| 52 | + // returned. |
|
| 53 | + $entity_service = Wordlift_Entity_Service::get_instance(); |
|
| 54 | + |
|
| 55 | + if ( $entity_service->is_entity( $post->ID ) ) { |
|
| 56 | + $filtering_entity_ids = array( $post_id ); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + if ( ! empty( $filtering_entity_ids ) ) { |
|
| 60 | + |
|
| 61 | + $related_posts = Wordlift_Relation_Service::get_instance() |
|
| 62 | + ->get_article_subjects( $filtering_entity_ids, '*', null, 'publish', array( $post_id ), 5 ); |
|
| 63 | + |
|
| 64 | + foreach ( $related_posts as $post_obj ) { |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Use the thumbnail. |
|
| 68 | + * |
|
| 69 | + * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue. |
|
| 70 | + * @see https://github.com/insideout10/wordlift-plugin/issues/837 |
|
| 71 | + * |
|
| 72 | + * @since 3.19.3 We're using the medium size image. |
|
| 73 | + */ |
|
| 74 | + $thumbnail = get_the_post_thumbnail_url( $post_obj, 'medium' ); |
|
| 75 | + $post_obj->thumbnail = ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 76 | + $post_obj->link = get_edit_post_link( $post_obj->ID, 'none' ); |
|
| 77 | + $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + wl_core_send_json( $related_posts ); |
|
| 82 | 82 | |
| 83 | 83 | } |
| 84 | 84 | |
@@ -17,34 +17,34 @@ discard block |
||
| 17 | 17 | * @since 3.0.0 |
| 18 | 18 | * |
| 19 | 19 | */ |
| 20 | -function wordlift_ajax_related_posts( $http_raw_data = null ) { |
|
| 20 | +function wordlift_ajax_related_posts($http_raw_data = null) { |
|
| 21 | 21 | |
| 22 | 22 | // Extract filtering conditions |
| 23 | - if ( ! isset( $_GET["post_id"] ) || ! is_numeric( $_GET["post_id"] ) ) { |
|
| 24 | - wp_die( 'Post id missing or invalid!' ); |
|
| 23 | + if ( ! isset($_GET["post_id"]) || ! is_numeric($_GET["post_id"])) { |
|
| 24 | + wp_die('Post id missing or invalid!'); |
|
| 25 | 25 | |
| 26 | 26 | return; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | // Get the current post |
| 30 | 30 | $post_id = (int) $_GET["post_id"]; |
| 31 | - $post = get_post( $post_id ); |
|
| 31 | + $post = get_post($post_id); |
|
| 32 | 32 | |
| 33 | - Wordlift_Log_Service::get_logger( 'wordlift_ajax_related_posts' )->trace( "Going to find posts related to current with post id: $post_id ..." ); |
|
| 33 | + Wordlift_Log_Service::get_logger('wordlift_ajax_related_posts')->trace("Going to find posts related to current with post id: $post_id ..."); |
|
| 34 | 34 | |
| 35 | 35 | // Extract filtering conditions |
| 36 | - $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data; |
|
| 37 | - $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
| 36 | + $filtering_entity_uris = (null == $http_raw_data) ? file_get_contents("php://input") : $http_raw_data; |
|
| 37 | + $filtering_entity_uris = json_decode($filtering_entity_uris); |
|
| 38 | 38 | |
| 39 | 39 | $content_service = Wordpress_Content_Service::get_instance(); |
| 40 | - $filtering_entity_ids = array_filter( array_map( function ( $uri ) use ( $content_service ) { |
|
| 41 | - $content = $content_service->get_by_entity_id( $uri ); |
|
| 42 | - if ( isset( $content ) && is_a( $content->get_bag(), '\WP_Post' ) ) { |
|
| 40 | + $filtering_entity_ids = array_filter(array_map(function($uri) use ($content_service) { |
|
| 41 | + $content = $content_service->get_by_entity_id($uri); |
|
| 42 | + if (isset($content) && is_a($content->get_bag(), '\WP_Post')) { |
|
| 43 | 43 | return $content->get_bag()->ID; |
| 44 | 44 | } else { |
| 45 | 45 | return null; |
| 46 | 46 | } |
| 47 | - }, $filtering_entity_uris ) ); |
|
| 47 | + }, $filtering_entity_uris)); |
|
| 48 | 48 | |
| 49 | 49 | $related_posts = array(); |
| 50 | 50 | |
@@ -52,16 +52,16 @@ discard block |
||
| 52 | 52 | // returned. |
| 53 | 53 | $entity_service = Wordlift_Entity_Service::get_instance(); |
| 54 | 54 | |
| 55 | - if ( $entity_service->is_entity( $post->ID ) ) { |
|
| 56 | - $filtering_entity_ids = array( $post_id ); |
|
| 55 | + if ($entity_service->is_entity($post->ID)) { |
|
| 56 | + $filtering_entity_ids = array($post_id); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - if ( ! empty( $filtering_entity_ids ) ) { |
|
| 59 | + if ( ! empty($filtering_entity_ids)) { |
|
| 60 | 60 | |
| 61 | 61 | $related_posts = Wordlift_Relation_Service::get_instance() |
| 62 | - ->get_article_subjects( $filtering_entity_ids, '*', null, 'publish', array( $post_id ), 5 ); |
|
| 62 | + ->get_article_subjects($filtering_entity_ids, '*', null, 'publish', array($post_id), 5); |
|
| 63 | 63 | |
| 64 | - foreach ( $related_posts as $post_obj ) { |
|
| 64 | + foreach ($related_posts as $post_obj) { |
|
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * Use the thumbnail. |
@@ -71,15 +71,15 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @since 3.19.3 We're using the medium size image. |
| 73 | 73 | */ |
| 74 | - $thumbnail = get_the_post_thumbnail_url( $post_obj, 'medium' ); |
|
| 75 | - $post_obj->thumbnail = ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 76 | - $post_obj->link = get_edit_post_link( $post_obj->ID, 'none' ); |
|
| 77 | - $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
| 74 | + $thumbnail = get_the_post_thumbnail_url($post_obj, 'medium'); |
|
| 75 | + $post_obj->thumbnail = ($thumbnail) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 76 | + $post_obj->link = get_edit_post_link($post_obj->ID, 'none'); |
|
| 77 | + $post_obj->permalink = get_post_permalink($post_obj->ID); |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - wl_core_send_json( $related_posts ); |
|
| 81 | + wl_core_send_json($related_posts); |
|
| 82 | 82 | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | -add_action( 'wp_ajax_wordlift_related_posts', 'wordlift_ajax_related_posts' ); |
|
| 85 | +add_action('wp_ajax_wordlift_related_posts', 'wordlift_ajax_related_posts'); |
|
@@ -16,40 +16,40 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | <?php |
| 18 | 18 | |
| 19 | - // Enqueue wp.media functions. |
|
| 20 | - wp_enqueue_media(); |
|
| 19 | + // Enqueue wp.media functions. |
|
| 20 | + wp_enqueue_media(); |
|
| 21 | 21 | |
| 22 | - // Enqueue styles and scripts. |
|
| 23 | - wp_enqueue_style( 'wl-font-awesome', plugin_dir_url( dirname( dirname( __FILE__ ) ) ) . 'css/font-awesome.min.css' ); |
|
| 24 | - wp_enqueue_style( 'wordlift-admin-setup', plugin_dir_url( dirname( __FILE__ ) ) . 'css/wordlift-admin-setup.css', array( |
|
| 25 | - 'wp-admin', |
|
| 26 | - 'wl-font-awesome', |
|
| 27 | - ) ); |
|
| 28 | - wp_enqueue_script( 'wordlift-admin-setup', plugin_dir_url( dirname( __FILE__ ) ) . 'js/1/setup.js', array( 'jquery' ) ); |
|
| 22 | + // Enqueue styles and scripts. |
|
| 23 | + wp_enqueue_style( 'wl-font-awesome', plugin_dir_url( dirname( dirname( __FILE__ ) ) ) . 'css/font-awesome.min.css' ); |
|
| 24 | + wp_enqueue_style( 'wordlift-admin-setup', plugin_dir_url( dirname( __FILE__ ) ) . 'css/wordlift-admin-setup.css', array( |
|
| 25 | + 'wp-admin', |
|
| 26 | + 'wl-font-awesome', |
|
| 27 | + ) ); |
|
| 28 | + wp_enqueue_script( 'wordlift-admin-setup', plugin_dir_url( dirname( __FILE__ ) ) . 'js/1/setup.js', array( 'jquery' ) ); |
|
| 29 | 29 | |
| 30 | - //Get wp_permalink structure |
|
| 31 | - $permalink_structure = get_option( 'permalink_structure' ); |
|
| 30 | + //Get wp_permalink structure |
|
| 31 | + $permalink_structure = get_option( 'permalink_structure' ); |
|
| 32 | 32 | |
| 33 | - // Set configuration settings. |
|
| 34 | - wp_localize_script( 'wordlift-admin-setup', '_wlAdminSetup', array( |
|
| 35 | - 'ajaxUrl' => parse_url( self_admin_url( 'admin-ajax.php' ), PHP_URL_PATH ), |
|
| 36 | - 'action' => 'wl_validate_key', |
|
| 37 | - 'permalink' => $permalink_structure, |
|
| 38 | - 'media' => array( |
|
| 39 | - 'title' => __( 'WordLift Choose Logo', 'wordlift' ), |
|
| 40 | - 'button' => array( 'text' => __( 'Choose Logo', 'wordlift' ) ), |
|
| 41 | - ), |
|
| 42 | - ) ); |
|
| 33 | + // Set configuration settings. |
|
| 34 | + wp_localize_script( 'wordlift-admin-setup', '_wlAdminSetup', array( |
|
| 35 | + 'ajaxUrl' => parse_url( self_admin_url( 'admin-ajax.php' ), PHP_URL_PATH ), |
|
| 36 | + 'action' => 'wl_validate_key', |
|
| 37 | + 'permalink' => $permalink_structure, |
|
| 38 | + 'media' => array( |
|
| 39 | + 'title' => __( 'WordLift Choose Logo', 'wordlift' ), |
|
| 40 | + 'button' => array( 'text' => __( 'Choose Logo', 'wordlift' ) ), |
|
| 41 | + ), |
|
| 42 | + ) ); |
|
| 43 | 43 | |
| 44 | - // Finally print styles and scripts. |
|
| 45 | - do_action( 'admin_print_scripts' ); |
|
| 46 | - wp_print_styles(); |
|
| 47 | - wp_print_scripts(); |
|
| 44 | + // Finally print styles and scripts. |
|
| 45 | + do_action( 'admin_print_scripts' ); |
|
| 46 | + wp_print_styles(); |
|
| 47 | + wp_print_scripts(); |
|
| 48 | 48 | |
| 49 | - for ( $i = 1; $i <= 6; $i ++ ) { |
|
| 50 | - include 'admin-setup/step-' . $i . '.php'; |
|
| 51 | - } |
|
| 52 | - ?> |
|
| 49 | + for ( $i = 1; $i <= 6; $i ++ ) { |
|
| 50 | + include 'admin-setup/step-' . $i . '.php'; |
|
| 51 | + } |
|
| 52 | + ?> |
|
| 53 | 53 | </head> |
| 54 | 54 | <body> |
| 55 | 55 | |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | <div class="viewport"></div> |
| 74 | 74 | </form> |
| 75 | 75 | <?php |
| 76 | - if ( function_exists( 'wp_print_media_templates' ) ) { |
|
| 77 | - wp_print_media_templates(); |
|
| 78 | - } |
|
| 79 | - ?> |
|
| 76 | + if ( function_exists( 'wp_print_media_templates' ) ) { |
|
| 77 | + wp_print_media_templates(); |
|
| 78 | + } |
|
| 79 | + ?> |
|
| 80 | 80 | </div> |
| 81 | 81 | |
| 82 | 82 | </body> |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | <!-- Defining responsive ambient. --> |
| 13 | 13 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 14 | 14 | |
| 15 | - <title><?php esc_html_e( 'WordLift Setup', 'wordlift' ); ?></title> |
|
| 15 | + <title><?php esc_html_e('WordLift Setup', 'wordlift'); ?></title> |
|
| 16 | 16 | |
| 17 | 17 | <?php |
| 18 | 18 | |
@@ -20,34 +20,34 @@ discard block |
||
| 20 | 20 | wp_enqueue_media(); |
| 21 | 21 | |
| 22 | 22 | // Enqueue styles and scripts. |
| 23 | - wp_enqueue_style( 'wl-font-awesome', plugin_dir_url( dirname( dirname( __FILE__ ) ) ) . 'css/font-awesome.min.css' ); |
|
| 24 | - wp_enqueue_style( 'wordlift-admin-setup', plugin_dir_url( dirname( __FILE__ ) ) . 'css/wordlift-admin-setup.css', array( |
|
| 23 | + wp_enqueue_style('wl-font-awesome', plugin_dir_url(dirname(dirname(__FILE__))).'css/font-awesome.min.css'); |
|
| 24 | + wp_enqueue_style('wordlift-admin-setup', plugin_dir_url(dirname(__FILE__)).'css/wordlift-admin-setup.css', array( |
|
| 25 | 25 | 'wp-admin', |
| 26 | 26 | 'wl-font-awesome', |
| 27 | - ) ); |
|
| 28 | - wp_enqueue_script( 'wordlift-admin-setup', plugin_dir_url( dirname( __FILE__ ) ) . 'js/1/setup.js', array( 'jquery' ) ); |
|
| 27 | + )); |
|
| 28 | + wp_enqueue_script('wordlift-admin-setup', plugin_dir_url(dirname(__FILE__)).'js/1/setup.js', array('jquery')); |
|
| 29 | 29 | |
| 30 | 30 | //Get wp_permalink structure |
| 31 | - $permalink_structure = get_option( 'permalink_structure' ); |
|
| 31 | + $permalink_structure = get_option('permalink_structure'); |
|
| 32 | 32 | |
| 33 | 33 | // Set configuration settings. |
| 34 | - wp_localize_script( 'wordlift-admin-setup', '_wlAdminSetup', array( |
|
| 35 | - 'ajaxUrl' => parse_url( self_admin_url( 'admin-ajax.php' ), PHP_URL_PATH ), |
|
| 34 | + wp_localize_script('wordlift-admin-setup', '_wlAdminSetup', array( |
|
| 35 | + 'ajaxUrl' => parse_url(self_admin_url('admin-ajax.php'), PHP_URL_PATH), |
|
| 36 | 36 | 'action' => 'wl_validate_key', |
| 37 | 37 | 'permalink' => $permalink_structure, |
| 38 | 38 | 'media' => array( |
| 39 | - 'title' => __( 'WordLift Choose Logo', 'wordlift' ), |
|
| 40 | - 'button' => array( 'text' => __( 'Choose Logo', 'wordlift' ) ), |
|
| 39 | + 'title' => __('WordLift Choose Logo', 'wordlift'), |
|
| 40 | + 'button' => array('text' => __('Choose Logo', 'wordlift')), |
|
| 41 | 41 | ), |
| 42 | - ) ); |
|
| 42 | + )); |
|
| 43 | 43 | |
| 44 | 44 | // Finally print styles and scripts. |
| 45 | - do_action( 'admin_print_scripts' ); |
|
| 45 | + do_action('admin_print_scripts'); |
|
| 46 | 46 | wp_print_styles(); |
| 47 | 47 | wp_print_scripts(); |
| 48 | 48 | |
| 49 | - for ( $i = 1; $i <= 6; $i ++ ) { |
|
| 50 | - include 'admin-setup/step-' . $i . '.php'; |
|
| 49 | + for ($i = 1; $i <= 6; $i++) { |
|
| 50 | + include 'admin-setup/step-'.$i.'.php'; |
|
| 51 | 51 | } |
| 52 | 52 | ?> |
| 53 | 53 | </head> |
@@ -55,25 +55,25 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | <div class="wl-container"> |
| 57 | 57 | |
| 58 | - <a href="<?php echo esc_url( admin_url() ); ?>" |
|
| 58 | + <a href="<?php echo esc_url(admin_url()); ?>" |
|
| 59 | 59 | class="fa fa-times wl-close"></a> |
| 60 | 60 | |
| 61 | 61 | <header> |
| 62 | 62 | <h1><img class="wizard-logo" |
| 63 | - src="<?php echo esc_attr( plugin_dir_url( dirname( dirname( __FILE__ ) ) ) . 'images/logo-wl-transparent-240x90.png' ); ?>"/> |
|
| 63 | + src="<?php echo esc_attr(plugin_dir_url(dirname(dirname(__FILE__))).'images/logo-wl-transparent-240x90.png'); ?>"/> |
|
| 64 | 64 | </h1> |
| 65 | 65 | <img class="shapes" |
| 66 | - src="<?php echo esc_attr( plugin_dir_url( dirname( dirname( __FILE__ ) ) ) . 'images/shapes.png' ); ?>"/> |
|
| 66 | + src="<?php echo esc_attr(plugin_dir_url(dirname(dirname(__FILE__))).'images/shapes.png'); ?>"/> |
|
| 67 | 67 | </header> |
| 68 | 68 | |
| 69 | 69 | |
| 70 | 70 | <form method="post"> |
| 71 | - <?php wp_nonce_field( 'wl-save-configuration' ); ?> |
|
| 71 | + <?php wp_nonce_field('wl-save-configuration'); ?> |
|
| 72 | 72 | <input type="hidden" name="action" value="wl-save-configuration"/> |
| 73 | 73 | <div class="viewport"></div> |
| 74 | 74 | </form> |
| 75 | 75 | <?php |
| 76 | - if ( function_exists( 'wp_print_media_templates' ) ) { |
|
| 76 | + if (function_exists('wp_print_media_templates')) { |
|
| 77 | 77 | wp_print_media_templates(); |
| 78 | 78 | } |
| 79 | 79 | ?> |
@@ -10,73 +10,73 @@ |
||
| 10 | 10 | |
| 11 | 11 | class Wordpress_Content implements Content { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * The actual content. |
|
| 15 | - * |
|
| 16 | - * @var WP_Post|WP_Term|WP_User $bag |
|
| 17 | - */ |
|
| 18 | - private $bag; |
|
| 13 | + /** |
|
| 14 | + * The actual content. |
|
| 15 | + * |
|
| 16 | + * @var WP_Post|WP_Term|WP_User $bag |
|
| 17 | + */ |
|
| 18 | + private $bag; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Creates a WordPress content instance. |
|
| 22 | - * |
|
| 23 | - * @param WP_Post|WP_Term|WP_User $bag |
|
| 24 | - */ |
|
| 25 | - public function __construct( $bag ) { |
|
| 26 | - $this->bag = $bag; |
|
| 27 | - } |
|
| 20 | + /** |
|
| 21 | + * Creates a WordPress content instance. |
|
| 22 | + * |
|
| 23 | + * @param WP_Post|WP_Term|WP_User $bag |
|
| 24 | + */ |
|
| 25 | + public function __construct( $bag ) { |
|
| 26 | + $this->bag = $bag; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * The actual content. |
|
| 31 | - * |
|
| 32 | - * @return WP_Post|WP_Term|WP_User |
|
| 33 | - */ |
|
| 34 | - function get_bag() { |
|
| 35 | - return $this->bag; |
|
| 36 | - } |
|
| 29 | + /** |
|
| 30 | + * The actual content. |
|
| 31 | + * |
|
| 32 | + * @return WP_Post|WP_Term|WP_User |
|
| 33 | + */ |
|
| 34 | + function get_bag() { |
|
| 35 | + return $this->bag; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - function get_id() { |
|
| 39 | - switch ( get_class( $this->bag ) ) { |
|
| 40 | - case 'WP_Post': |
|
| 41 | - case 'WP_User': |
|
| 42 | - return $this->bag->ID; |
|
| 43 | - case 'WP_Term': |
|
| 44 | - return $this->bag->term_id; |
|
| 45 | - } |
|
| 38 | + function get_id() { |
|
| 39 | + switch ( get_class( $this->bag ) ) { |
|
| 40 | + case 'WP_Post': |
|
| 41 | + case 'WP_User': |
|
| 42 | + return $this->bag->ID; |
|
| 43 | + case 'WP_Term': |
|
| 44 | + return $this->bag->term_id; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - return null; |
|
| 48 | - } |
|
| 47 | + return null; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - function get_object_type_enum() { |
|
| 51 | - return Object_Type_Enum::from_wordpress_instance( $this->bag ); |
|
| 52 | - } |
|
| 50 | + function get_object_type_enum() { |
|
| 51 | + return Object_Type_Enum::from_wordpress_instance( $this->bag ); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - function get_permalink() { |
|
| 55 | - switch ( get_class( $this->bag ) ) { |
|
| 56 | - case 'WP_Post': |
|
| 57 | - return get_permalink( $this->get_bag()->ID ); |
|
| 58 | - case 'WP_User': |
|
| 59 | - return get_author_posts_url( $this->get_bag()->ID ); |
|
| 60 | - case 'WP_Term': |
|
| 61 | - return get_term_link( $this->bag->term_id ); |
|
| 62 | - } |
|
| 54 | + function get_permalink() { |
|
| 55 | + switch ( get_class( $this->bag ) ) { |
|
| 56 | + case 'WP_Post': |
|
| 57 | + return get_permalink( $this->get_bag()->ID ); |
|
| 58 | + case 'WP_User': |
|
| 59 | + return get_author_posts_url( $this->get_bag()->ID ); |
|
| 60 | + case 'WP_Term': |
|
| 61 | + return get_term_link( $this->bag->term_id ); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return null; |
|
| 65 | - } |
|
| 64 | + return null; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - function get_edit_link() { |
|
| 68 | - switch ( get_class( $this->bag ) ) { |
|
| 69 | - case 'WP_Post': |
|
| 70 | - // We need to return & character as &, by default context is set to display. |
|
| 71 | - // so & will be returned as & breaking header location redirects. |
|
| 72 | - // By setting context to none we prevent this issue. |
|
| 73 | - return get_edit_post_link( $this->get_bag()->ID, 'none' ); |
|
| 74 | - case 'WP_User': |
|
| 75 | - return get_edit_user_link( $this->get_bag()->ID ); |
|
| 76 | - case 'WP_Term': |
|
| 77 | - return get_edit_term_link( $this->bag->term_id ); |
|
| 78 | - } |
|
| 67 | + function get_edit_link() { |
|
| 68 | + switch ( get_class( $this->bag ) ) { |
|
| 69 | + case 'WP_Post': |
|
| 70 | + // We need to return & character as &, by default context is set to display. |
|
| 71 | + // so & will be returned as & breaking header location redirects. |
|
| 72 | + // By setting context to none we prevent this issue. |
|
| 73 | + return get_edit_post_link( $this->get_bag()->ID, 'none' ); |
|
| 74 | + case 'WP_User': |
|
| 75 | + return get_edit_user_link( $this->get_bag()->ID ); |
|
| 76 | + case 'WP_Term': |
|
| 77 | + return get_edit_term_link( $this->bag->term_id ); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - return null; |
|
| 81 | - } |
|
| 80 | + return null; |
|
| 81 | + } |
|
| 82 | 82 | } |
| 83 | 83 | \ No newline at end of file |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @param WP_Post|WP_Term|WP_User $bag |
| 24 | 24 | */ |
| 25 | - public function __construct( $bag ) { |
|
| 25 | + public function __construct($bag) { |
|
| 26 | 26 | $this->bag = $bag; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | function get_id() { |
| 39 | - switch ( get_class( $this->bag ) ) { |
|
| 39 | + switch (get_class($this->bag)) { |
|
| 40 | 40 | case 'WP_Post': |
| 41 | 41 | case 'WP_User': |
| 42 | 42 | return $this->bag->ID; |
@@ -48,33 +48,33 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | function get_object_type_enum() { |
| 51 | - return Object_Type_Enum::from_wordpress_instance( $this->bag ); |
|
| 51 | + return Object_Type_Enum::from_wordpress_instance($this->bag); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | function get_permalink() { |
| 55 | - switch ( get_class( $this->bag ) ) { |
|
| 55 | + switch (get_class($this->bag)) { |
|
| 56 | 56 | case 'WP_Post': |
| 57 | - return get_permalink( $this->get_bag()->ID ); |
|
| 57 | + return get_permalink($this->get_bag()->ID); |
|
| 58 | 58 | case 'WP_User': |
| 59 | - return get_author_posts_url( $this->get_bag()->ID ); |
|
| 59 | + return get_author_posts_url($this->get_bag()->ID); |
|
| 60 | 60 | case 'WP_Term': |
| 61 | - return get_term_link( $this->bag->term_id ); |
|
| 61 | + return get_term_link($this->bag->term_id); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | return null; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | function get_edit_link() { |
| 68 | - switch ( get_class( $this->bag ) ) { |
|
| 68 | + switch (get_class($this->bag)) { |
|
| 69 | 69 | case 'WP_Post': |
| 70 | 70 | // We need to return & character as &, by default context is set to display. |
| 71 | 71 | // so & will be returned as & breaking header location redirects. |
| 72 | 72 | // By setting context to none we prevent this issue. |
| 73 | - return get_edit_post_link( $this->get_bag()->ID, 'none' ); |
|
| 73 | + return get_edit_post_link($this->get_bag()->ID, 'none'); |
|
| 74 | 74 | case 'WP_User': |
| 75 | - return get_edit_user_link( $this->get_bag()->ID ); |
|
| 75 | + return get_edit_user_link($this->get_bag()->ID); |
|
| 76 | 76 | case 'WP_Term': |
| 77 | - return get_edit_term_link( $this->bag->term_id ); |
|
| 77 | + return get_edit_term_link($this->bag->term_id); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | return null; |
@@ -18,172 +18,172 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Install_Service { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * A {@link Wordlift_Log_Service} instance. |
|
| 23 | - * |
|
| 24 | - * @since 3.18.0 |
|
| 25 | - * @access private |
|
| 26 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 27 | - */ |
|
| 28 | - private $log; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * The singleton instance. |
|
| 32 | - * |
|
| 33 | - * @since 3.18.0 |
|
| 34 | - * @access private |
|
| 35 | - * @var \Wordlift_Install_Service $instance A {@link Wordlift_Install_Service} instance. |
|
| 36 | - */ |
|
| 37 | - private static $instance; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - private $installs; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Wordlift_Install_Service constructor. |
|
| 46 | - * |
|
| 47 | - * @since 3.18.0 |
|
| 48 | - */ |
|
| 49 | - public function __construct() { |
|
| 50 | - |
|
| 51 | - /** Installs. */ |
|
| 52 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install.php'; |
|
| 53 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-1-0-0.php'; |
|
| 54 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-10-0.php'; |
|
| 55 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-12-0.php'; |
|
| 56 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-14-0.php'; |
|
| 57 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-15-0.php'; |
|
| 58 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-0.php'; |
|
| 59 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-3.php'; |
|
| 60 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-19-5.php'; |
|
| 61 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-20-0.php'; |
|
| 62 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-23-4.php'; |
|
| 63 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-24-2.php'; |
|
| 64 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-all-entity-types.php'; |
|
| 65 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-package-type.php'; |
|
| 66 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-25-0.php'; |
|
| 67 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-27-0.php'; |
|
| 68 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-27-1.php'; |
|
| 69 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-28-0.php'; |
|
| 70 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-32-0.php'; |
|
| 71 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-33-9.php'; |
|
| 72 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-36-0.php'; |
|
| 73 | - // Get the install services. |
|
| 74 | - $this->installs = array( |
|
| 75 | - new Wordlift_Install_1_0_0(), |
|
| 76 | - new Wordlift_Install_3_10_0(), |
|
| 77 | - new Wordlift_Install_3_12_0(), |
|
| 78 | - new Wordlift_Install_3_14_0(), |
|
| 79 | - new Wordlift_Install_3_15_0(), |
|
| 80 | - new Wordlift_Install_3_18_0(), |
|
| 81 | - new Wordlift_Install_3_18_3(), |
|
| 82 | - new Wordlift_Install_3_19_5(), |
|
| 83 | - new Wordlift_Install_3_20_0(), |
|
| 84 | - /* |
|
| 21 | + /** |
|
| 22 | + * A {@link Wordlift_Log_Service} instance. |
|
| 23 | + * |
|
| 24 | + * @since 3.18.0 |
|
| 25 | + * @access private |
|
| 26 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 27 | + */ |
|
| 28 | + private $log; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * The singleton instance. |
|
| 32 | + * |
|
| 33 | + * @since 3.18.0 |
|
| 34 | + * @access private |
|
| 35 | + * @var \Wordlift_Install_Service $instance A {@link Wordlift_Install_Service} instance. |
|
| 36 | + */ |
|
| 37 | + private static $instance; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + private $installs; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Wordlift_Install_Service constructor. |
|
| 46 | + * |
|
| 47 | + * @since 3.18.0 |
|
| 48 | + */ |
|
| 49 | + public function __construct() { |
|
| 50 | + |
|
| 51 | + /** Installs. */ |
|
| 52 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install.php'; |
|
| 53 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-1-0-0.php'; |
|
| 54 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-10-0.php'; |
|
| 55 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-12-0.php'; |
|
| 56 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-14-0.php'; |
|
| 57 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-15-0.php'; |
|
| 58 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-0.php'; |
|
| 59 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-3.php'; |
|
| 60 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-19-5.php'; |
|
| 61 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-20-0.php'; |
|
| 62 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-23-4.php'; |
|
| 63 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-24-2.php'; |
|
| 64 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-all-entity-types.php'; |
|
| 65 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-package-type.php'; |
|
| 66 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-25-0.php'; |
|
| 67 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-27-0.php'; |
|
| 68 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-27-1.php'; |
|
| 69 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-28-0.php'; |
|
| 70 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-32-0.php'; |
|
| 71 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-33-9.php'; |
|
| 72 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-36-0.php'; |
|
| 73 | + // Get the install services. |
|
| 74 | + $this->installs = array( |
|
| 75 | + new Wordlift_Install_1_0_0(), |
|
| 76 | + new Wordlift_Install_3_10_0(), |
|
| 77 | + new Wordlift_Install_3_12_0(), |
|
| 78 | + new Wordlift_Install_3_14_0(), |
|
| 79 | + new Wordlift_Install_3_15_0(), |
|
| 80 | + new Wordlift_Install_3_18_0(), |
|
| 81 | + new Wordlift_Install_3_18_3(), |
|
| 82 | + new Wordlift_Install_3_19_5(), |
|
| 83 | + new Wordlift_Install_3_20_0(), |
|
| 84 | + /* |
|
| 85 | 85 | * This should be enabled with #852. |
| 86 | 86 | */ |
| 87 | - // new Wordlift_Install_All_Entity_Types(), |
|
| 88 | - new Wordlift_Install_Package_Type(), |
|
| 89 | - new Wordlift_Install_3_23_4(), |
|
| 90 | - new Wordlift_Install_3_24_2(), |
|
| 91 | - new Wordlift_Install_3_25_0(), |
|
| 92 | - new Wordlift_Install_3_27_0(), |
|
| 93 | - new Wordlift_Install_3_27_1(), |
|
| 94 | - new Wordlift_Install_3_28_0(), |
|
| 95 | - // Add column to represent term |
|
| 96 | - new Wordlift_Install_3_32_0(), |
|
| 97 | - // Add the entities table. |
|
| 98 | - new Wordlift_Install_3_33_9(), |
|
| 99 | - // When woocommerce extension installed, acf4so should be installed automatically. |
|
| 100 | - new Wordlift_Install_3_36_0() |
|
| 101 | - ); |
|
| 102 | - self::$instance = $this; |
|
| 103 | - |
|
| 104 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 105 | - |
|
| 106 | - add_action( 'init', array( $this, 'install' ) ); |
|
| 107 | - |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Get the singleton instance. |
|
| 112 | - * |
|
| 113 | - * @since 3.18.0 |
|
| 114 | - */ |
|
| 115 | - public static function get_instance() { |
|
| 116 | - |
|
| 117 | - return self::$instance; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Loop thought all versions and install the updates. |
|
| 122 | - * |
|
| 123 | - * @return void |
|
| 124 | - * @since 3.18.0 |
|
| 125 | - * |
|
| 126 | - * @since 3.20.0 use a transient to avoid concurrent installation calls. |
|
| 127 | - */ |
|
| 128 | - public function install() { |
|
| 129 | - |
|
| 130 | - $version = null; |
|
| 131 | - |
|
| 132 | - if ( $this->install_required() && false === get_transient( '_wl_installing' ) ) { |
|
| 133 | - set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS ); |
|
| 134 | - /** @var Wordlift_Install $install */ |
|
| 135 | - foreach ( $this->installs as $install ) { |
|
| 136 | - // Get the install version. |
|
| 137 | - $version = $install->get_version(); |
|
| 138 | - |
|
| 139 | - if ( version_compare( $version, $this->get_current_version(), '>' ) |
|
| 140 | - || $install->must_install() ) { |
|
| 141 | - $class_name = get_class( $install ); |
|
| 142 | - |
|
| 143 | - $this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." ); |
|
| 144 | - // Install version. |
|
| 145 | - $install->install(); |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - $this->log->info( "$class_name installed." ); |
|
| 149 | - |
|
| 150 | - // Bump the version. |
|
| 151 | - update_option( 'wl_db_version', $version ); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - @delete_transient( '_wl_installing' ); |
|
| 157 | - |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - private function install_required() { |
|
| 163 | - |
|
| 164 | - /** @var Wordlift_Install $install */ |
|
| 165 | - foreach ( $this->installs as $install ) { |
|
| 166 | - // Get the install version. |
|
| 167 | - $version = $install->get_version(); |
|
| 168 | - |
|
| 169 | - if ( version_compare( $version, $this->get_current_version(), '>' ) |
|
| 170 | - || $install->must_install() ) { |
|
| 171 | - return true; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - return false; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Retrieve the current db version. |
|
| 181 | - * |
|
| 182 | - * @return type |
|
| 183 | - */ |
|
| 184 | - private function get_current_version() { |
|
| 185 | - return get_option( 'wl_db_version', '0.0.0' ); |
|
| 186 | - } |
|
| 87 | + // new Wordlift_Install_All_Entity_Types(), |
|
| 88 | + new Wordlift_Install_Package_Type(), |
|
| 89 | + new Wordlift_Install_3_23_4(), |
|
| 90 | + new Wordlift_Install_3_24_2(), |
|
| 91 | + new Wordlift_Install_3_25_0(), |
|
| 92 | + new Wordlift_Install_3_27_0(), |
|
| 93 | + new Wordlift_Install_3_27_1(), |
|
| 94 | + new Wordlift_Install_3_28_0(), |
|
| 95 | + // Add column to represent term |
|
| 96 | + new Wordlift_Install_3_32_0(), |
|
| 97 | + // Add the entities table. |
|
| 98 | + new Wordlift_Install_3_33_9(), |
|
| 99 | + // When woocommerce extension installed, acf4so should be installed automatically. |
|
| 100 | + new Wordlift_Install_3_36_0() |
|
| 101 | + ); |
|
| 102 | + self::$instance = $this; |
|
| 103 | + |
|
| 104 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 105 | + |
|
| 106 | + add_action( 'init', array( $this, 'install' ) ); |
|
| 107 | + |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Get the singleton instance. |
|
| 112 | + * |
|
| 113 | + * @since 3.18.0 |
|
| 114 | + */ |
|
| 115 | + public static function get_instance() { |
|
| 116 | + |
|
| 117 | + return self::$instance; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Loop thought all versions and install the updates. |
|
| 122 | + * |
|
| 123 | + * @return void |
|
| 124 | + * @since 3.18.0 |
|
| 125 | + * |
|
| 126 | + * @since 3.20.0 use a transient to avoid concurrent installation calls. |
|
| 127 | + */ |
|
| 128 | + public function install() { |
|
| 129 | + |
|
| 130 | + $version = null; |
|
| 131 | + |
|
| 132 | + if ( $this->install_required() && false === get_transient( '_wl_installing' ) ) { |
|
| 133 | + set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS ); |
|
| 134 | + /** @var Wordlift_Install $install */ |
|
| 135 | + foreach ( $this->installs as $install ) { |
|
| 136 | + // Get the install version. |
|
| 137 | + $version = $install->get_version(); |
|
| 138 | + |
|
| 139 | + if ( version_compare( $version, $this->get_current_version(), '>' ) |
|
| 140 | + || $install->must_install() ) { |
|
| 141 | + $class_name = get_class( $install ); |
|
| 142 | + |
|
| 143 | + $this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." ); |
|
| 144 | + // Install version. |
|
| 145 | + $install->install(); |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + $this->log->info( "$class_name installed." ); |
|
| 149 | + |
|
| 150 | + // Bump the version. |
|
| 151 | + update_option( 'wl_db_version', $version ); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + @delete_transient( '_wl_installing' ); |
|
| 157 | + |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + private function install_required() { |
|
| 163 | + |
|
| 164 | + /** @var Wordlift_Install $install */ |
|
| 165 | + foreach ( $this->installs as $install ) { |
|
| 166 | + // Get the install version. |
|
| 167 | + $version = $install->get_version(); |
|
| 168 | + |
|
| 169 | + if ( version_compare( $version, $this->get_current_version(), '>' ) |
|
| 170 | + || $install->must_install() ) { |
|
| 171 | + return true; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Retrieve the current db version. |
|
| 181 | + * |
|
| 182 | + * @return type |
|
| 183 | + */ |
|
| 184 | + private function get_current_version() { |
|
| 185 | + return get_option( 'wl_db_version', '0.0.0' ); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | 188 | |
| 189 | 189 | } |
@@ -49,27 +49,27 @@ discard block |
||
| 49 | 49 | public function __construct() { |
| 50 | 50 | |
| 51 | 51 | /** Installs. */ |
| 52 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install.php'; |
|
| 53 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-1-0-0.php'; |
|
| 54 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-10-0.php'; |
|
| 55 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-12-0.php'; |
|
| 56 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-14-0.php'; |
|
| 57 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-15-0.php'; |
|
| 58 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-0.php'; |
|
| 59 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-3.php'; |
|
| 60 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-19-5.php'; |
|
| 61 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-20-0.php'; |
|
| 62 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-23-4.php'; |
|
| 63 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-24-2.php'; |
|
| 64 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-all-entity-types.php'; |
|
| 65 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-package-type.php'; |
|
| 66 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-25-0.php'; |
|
| 67 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-27-0.php'; |
|
| 68 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-27-1.php'; |
|
| 69 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-28-0.php'; |
|
| 70 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-32-0.php'; |
|
| 71 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-33-9.php'; |
|
| 72 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-36-0.php'; |
|
| 52 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install.php'; |
|
| 53 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-1-0-0.php'; |
|
| 54 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-10-0.php'; |
|
| 55 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-12-0.php'; |
|
| 56 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-14-0.php'; |
|
| 57 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-15-0.php'; |
|
| 58 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-18-0.php'; |
|
| 59 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-18-3.php'; |
|
| 60 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-19-5.php'; |
|
| 61 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-20-0.php'; |
|
| 62 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-23-4.php'; |
|
| 63 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-24-2.php'; |
|
| 64 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-all-entity-types.php'; |
|
| 65 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-package-type.php'; |
|
| 66 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-25-0.php'; |
|
| 67 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-27-0.php'; |
|
| 68 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-27-1.php'; |
|
| 69 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-28-0.php'; |
|
| 70 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-32-0.php'; |
|
| 71 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-33-9.php'; |
|
| 72 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-36-0.php'; |
|
| 73 | 73 | // Get the install services. |
| 74 | 74 | $this->installs = array( |
| 75 | 75 | new Wordlift_Install_1_0_0(), |
@@ -101,9 +101,9 @@ discard block |
||
| 101 | 101 | ); |
| 102 | 102 | self::$instance = $this; |
| 103 | 103 | |
| 104 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 104 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
| 105 | 105 | |
| 106 | - add_action( 'init', array( $this, 'install' ) ); |
|
| 106 | + add_action('init', array($this, 'install')); |
|
| 107 | 107 | |
| 108 | 108 | } |
| 109 | 109 | |
@@ -129,31 +129,31 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | $version = null; |
| 131 | 131 | |
| 132 | - if ( $this->install_required() && false === get_transient( '_wl_installing' ) ) { |
|
| 133 | - set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS ); |
|
| 132 | + if ($this->install_required() && false === get_transient('_wl_installing')) { |
|
| 133 | + set_transient('_wl_installing', true, 5 * MINUTE_IN_SECONDS); |
|
| 134 | 134 | /** @var Wordlift_Install $install */ |
| 135 | - foreach ( $this->installs as $install ) { |
|
| 135 | + foreach ($this->installs as $install) { |
|
| 136 | 136 | // Get the install version. |
| 137 | 137 | $version = $install->get_version(); |
| 138 | 138 | |
| 139 | - if ( version_compare( $version, $this->get_current_version(), '>' ) |
|
| 140 | - || $install->must_install() ) { |
|
| 141 | - $class_name = get_class( $install ); |
|
| 139 | + if (version_compare($version, $this->get_current_version(), '>') |
|
| 140 | + || $install->must_install()) { |
|
| 141 | + $class_name = get_class($install); |
|
| 142 | 142 | |
| 143 | - $this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." ); |
|
| 143 | + $this->log->info("Current version is {$this->get_current_version()}, installing $class_name..."); |
|
| 144 | 144 | // Install version. |
| 145 | 145 | $install->install(); |
| 146 | 146 | |
| 147 | 147 | |
| 148 | - $this->log->info( "$class_name installed." ); |
|
| 148 | + $this->log->info("$class_name installed."); |
|
| 149 | 149 | |
| 150 | 150 | // Bump the version. |
| 151 | - update_option( 'wl_db_version', $version ); |
|
| 151 | + update_option('wl_db_version', $version); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - @delete_transient( '_wl_installing' ); |
|
| 156 | + @delete_transient('_wl_installing'); |
|
| 157 | 157 | |
| 158 | 158 | } |
| 159 | 159 | |
@@ -162,12 +162,12 @@ discard block |
||
| 162 | 162 | private function install_required() { |
| 163 | 163 | |
| 164 | 164 | /** @var Wordlift_Install $install */ |
| 165 | - foreach ( $this->installs as $install ) { |
|
| 165 | + foreach ($this->installs as $install) { |
|
| 166 | 166 | // Get the install version. |
| 167 | 167 | $version = $install->get_version(); |
| 168 | 168 | |
| 169 | - if ( version_compare( $version, $this->get_current_version(), '>' ) |
|
| 170 | - || $install->must_install() ) { |
|
| 169 | + if (version_compare($version, $this->get_current_version(), '>') |
|
| 170 | + || $install->must_install()) { |
|
| 171 | 171 | return true; |
| 172 | 172 | } |
| 173 | 173 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @return type |
| 183 | 183 | */ |
| 184 | 184 | private function get_current_version() { |
| 185 | - return get_option( 'wl_db_version', '0.0.0' ); |
|
| 185 | + return get_option('wl_db_version', '0.0.0'); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 3 | +require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * @since 3.36.0 |
@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | public function install() { |
| 17 | 17 | |
| 18 | - $is_woocommerce_extension_installed = defined( 'WL_WOO_VERSION' ); |
|
| 18 | + $is_woocommerce_extension_installed = defined('WL_WOO_VERSION'); |
|
| 19 | 19 | |
| 20 | - if ( $is_woocommerce_extension_installed ) { |
|
| 21 | - do_action( 'wl_install_and_activate_advanced-custom-fields-for-schema-org' ); |
|
| 20 | + if ($is_woocommerce_extension_installed) { |
|
| 21 | + do_action('wl_install_and_activate_advanced-custom-fields-for-schema-org'); |
|
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | |
@@ -8,18 +8,18 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Wordlift_Install_3_36_0 extends Wordlift_Install { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * {@inheritdoc} |
|
| 13 | - */ |
|
| 14 | - protected static $version = '3.36.1'; |
|
| 11 | + /** |
|
| 12 | + * {@inheritdoc} |
|
| 13 | + */ |
|
| 14 | + protected static $version = '3.36.1'; |
|
| 15 | 15 | |
| 16 | - public function install() { |
|
| 16 | + public function install() { |
|
| 17 | 17 | |
| 18 | - $is_woocommerce_extension_installed = defined( 'WL_WOO_VERSION' ); |
|
| 18 | + $is_woocommerce_extension_installed = defined( 'WL_WOO_VERSION' ); |
|
| 19 | 19 | |
| 20 | - if ( $is_woocommerce_extension_installed ) { |
|
| 21 | - do_action( 'wl_install_and_activate_advanced-custom-fields-for-schema-org' ); |
|
| 22 | - } |
|
| 23 | - } |
|
| 20 | + if ( $is_woocommerce_extension_installed ) { |
|
| 21 | + do_action( 'wl_install_and_activate_advanced-custom-fields-for-schema-org' ); |
|
| 22 | + } |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | } |
@@ -7,77 +7,77 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Installer { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * @var Plugin |
|
| 12 | - */ |
|
| 13 | - private $plugin; |
|
| 14 | - /** |
|
| 15 | - * @var Plugin_Upgrader |
|
| 16 | - */ |
|
| 17 | - private $upgrader; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @param $plugin Plugin |
|
| 21 | - * @param $upgrader Plugin_Upgrader |
|
| 22 | - */ |
|
| 23 | - function __construct( Plugin_Upgrader $upgrader, Plugin $plugin ) { |
|
| 24 | - $this->upgrader = $upgrader; |
|
| 25 | - $this->plugin = $plugin; |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - function install() { |
|
| 29 | - |
|
| 30 | - if ( $this->plugin->is_plugin_installed() ) { |
|
| 31 | - return; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - try { |
|
| 35 | - wp_cache_flush(); |
|
| 36 | - $this->upgrader->install( $this->plugin->get_zip_url() ); |
|
| 37 | - } catch ( \Exception $e ) { |
|
| 38 | - error_log( "Error caught when installing plugin " . $this->plugin->get_slug() . " error: " . $e->getMessage() ); |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - function activate() { |
|
| 43 | - if ( $this->plugin->is_plugin_activated() ) { |
|
| 44 | - return; |
|
| 45 | - } |
|
| 46 | - activate_plugin( $this->plugin->get_slug() ); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - public function install_and_activate_on_entity_type_change( $new_value, $old_value ) { |
|
| 50 | - if ( ! $new_value ) { |
|
| 51 | - return; |
|
| 52 | - } |
|
| 53 | - $this->install_and_activate(); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - public function install_and_activate() { |
|
| 57 | - ob_start(); |
|
| 58 | - $this->install(); |
|
| 59 | - $this->activate(); |
|
| 60 | - ob_end_clean(); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - public function admin_ajax_install_and_activate() { |
|
| 64 | - |
|
| 65 | - $this->install_and_activate(); |
|
| 66 | - |
|
| 67 | - if ( $this->plugin->is_plugin_installed() && $this->plugin->is_plugin_activated() ) { |
|
| 68 | - wp_send_json_success(null, 200); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - wp_send_json_error(null, 400); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - public function register_hooks() { |
|
| 76 | - add_action( 'wl_feature__change__entity-types-professional', [ $this, 'install_and_activate_on_entity_type_change' ], 10, 2 ); |
|
| 77 | - add_action( 'wl_feature__change__entity-types-business', [ $this, 'install_and_activate_on_entity_type_change' ], 10, 2 ); |
|
| 78 | - add_action( "wp_ajax_wl_install_and_activate_{$this->plugin->get_name()}", [ $this, 'admin_ajax_install_and_activate' ] ); |
|
| 79 | - add_action("wl_install_and_activate_{$this->plugin->get_name()}", [ $this, 'install_and_activate'] ); |
|
| 80 | - } |
|
| 10 | + /** |
|
| 11 | + * @var Plugin |
|
| 12 | + */ |
|
| 13 | + private $plugin; |
|
| 14 | + /** |
|
| 15 | + * @var Plugin_Upgrader |
|
| 16 | + */ |
|
| 17 | + private $upgrader; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @param $plugin Plugin |
|
| 21 | + * @param $upgrader Plugin_Upgrader |
|
| 22 | + */ |
|
| 23 | + function __construct( Plugin_Upgrader $upgrader, Plugin $plugin ) { |
|
| 24 | + $this->upgrader = $upgrader; |
|
| 25 | + $this->plugin = $plugin; |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + function install() { |
|
| 29 | + |
|
| 30 | + if ( $this->plugin->is_plugin_installed() ) { |
|
| 31 | + return; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + try { |
|
| 35 | + wp_cache_flush(); |
|
| 36 | + $this->upgrader->install( $this->plugin->get_zip_url() ); |
|
| 37 | + } catch ( \Exception $e ) { |
|
| 38 | + error_log( "Error caught when installing plugin " . $this->plugin->get_slug() . " error: " . $e->getMessage() ); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + function activate() { |
|
| 43 | + if ( $this->plugin->is_plugin_activated() ) { |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | + activate_plugin( $this->plugin->get_slug() ); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + public function install_and_activate_on_entity_type_change( $new_value, $old_value ) { |
|
| 50 | + if ( ! $new_value ) { |
|
| 51 | + return; |
|
| 52 | + } |
|
| 53 | + $this->install_and_activate(); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + public function install_and_activate() { |
|
| 57 | + ob_start(); |
|
| 58 | + $this->install(); |
|
| 59 | + $this->activate(); |
|
| 60 | + ob_end_clean(); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + public function admin_ajax_install_and_activate() { |
|
| 64 | + |
|
| 65 | + $this->install_and_activate(); |
|
| 66 | + |
|
| 67 | + if ( $this->plugin->is_plugin_installed() && $this->plugin->is_plugin_activated() ) { |
|
| 68 | + wp_send_json_success(null, 200); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + wp_send_json_error(null, 400); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + public function register_hooks() { |
|
| 76 | + add_action( 'wl_feature__change__entity-types-professional', [ $this, 'install_and_activate_on_entity_type_change' ], 10, 2 ); |
|
| 77 | + add_action( 'wl_feature__change__entity-types-business', [ $this, 'install_and_activate_on_entity_type_change' ], 10, 2 ); |
|
| 78 | + add_action( "wp_ajax_wl_install_and_activate_{$this->plugin->get_name()}", [ $this, 'admin_ajax_install_and_activate' ] ); |
|
| 79 | + add_action("wl_install_and_activate_{$this->plugin->get_name()}", [ $this, 'install_and_activate'] ); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | |
| 83 | 83 | } |
@@ -20,34 +20,34 @@ discard block |
||
| 20 | 20 | * @param $plugin Plugin |
| 21 | 21 | * @param $upgrader Plugin_Upgrader |
| 22 | 22 | */ |
| 23 | - function __construct( Plugin_Upgrader $upgrader, Plugin $plugin ) { |
|
| 23 | + function __construct(Plugin_Upgrader $upgrader, Plugin $plugin) { |
|
| 24 | 24 | $this->upgrader = $upgrader; |
| 25 | 25 | $this->plugin = $plugin; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | function install() { |
| 29 | 29 | |
| 30 | - if ( $this->plugin->is_plugin_installed() ) { |
|
| 30 | + if ($this->plugin->is_plugin_installed()) { |
|
| 31 | 31 | return; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | try { |
| 35 | 35 | wp_cache_flush(); |
| 36 | - $this->upgrader->install( $this->plugin->get_zip_url() ); |
|
| 37 | - } catch ( \Exception $e ) { |
|
| 38 | - error_log( "Error caught when installing plugin " . $this->plugin->get_slug() . " error: " . $e->getMessage() ); |
|
| 36 | + $this->upgrader->install($this->plugin->get_zip_url()); |
|
| 37 | + } catch (\Exception $e) { |
|
| 38 | + error_log("Error caught when installing plugin ".$this->plugin->get_slug()." error: ".$e->getMessage()); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | function activate() { |
| 43 | - if ( $this->plugin->is_plugin_activated() ) { |
|
| 43 | + if ($this->plugin->is_plugin_activated()) { |
|
| 44 | 44 | return; |
| 45 | 45 | } |
| 46 | - activate_plugin( $this->plugin->get_slug() ); |
|
| 46 | + activate_plugin($this->plugin->get_slug()); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - public function install_and_activate_on_entity_type_change( $new_value, $old_value ) { |
|
| 50 | - if ( ! $new_value ) { |
|
| 49 | + public function install_and_activate_on_entity_type_change($new_value, $old_value) { |
|
| 50 | + if ( ! $new_value) { |
|
| 51 | 51 | return; |
| 52 | 52 | } |
| 53 | 53 | $this->install_and_activate(); |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | $this->install_and_activate(); |
| 66 | 66 | |
| 67 | - if ( $this->plugin->is_plugin_installed() && $this->plugin->is_plugin_activated() ) { |
|
| 67 | + if ($this->plugin->is_plugin_installed() && $this->plugin->is_plugin_activated()) { |
|
| 68 | 68 | wp_send_json_success(null, 200); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | public function register_hooks() { |
| 76 | - add_action( 'wl_feature__change__entity-types-professional', [ $this, 'install_and_activate_on_entity_type_change' ], 10, 2 ); |
|
| 77 | - add_action( 'wl_feature__change__entity-types-business', [ $this, 'install_and_activate_on_entity_type_change' ], 10, 2 ); |
|
| 78 | - add_action( "wp_ajax_wl_install_and_activate_{$this->plugin->get_name()}", [ $this, 'admin_ajax_install_and_activate' ] ); |
|
| 79 | - add_action("wl_install_and_activate_{$this->plugin->get_name()}", [ $this, 'install_and_activate'] ); |
|
| 76 | + add_action('wl_feature__change__entity-types-professional', [$this, 'install_and_activate_on_entity_type_change'], 10, 2); |
|
| 77 | + add_action('wl_feature__change__entity-types-business', [$this, 'install_and_activate_on_entity_type_change'], 10, 2); |
|
| 78 | + add_action("wp_ajax_wl_install_and_activate_{$this->plugin->get_name()}", [$this, 'admin_ajax_install_and_activate']); |
|
| 79 | + add_action("wl_install_and_activate_{$this->plugin->get_name()}", [$this, 'install_and_activate']); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
@@ -4,68 +4,68 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | class Notices { |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * @var Plugin |
|
| 9 | - */ |
|
| 10 | - private $acf4so_plugin; |
|
| 7 | + /** |
|
| 8 | + * @var Plugin |
|
| 9 | + */ |
|
| 10 | + private $acf4so_plugin; |
|
| 11 | 11 | |
| 12 | - function __construct( Plugin $plugin ) { |
|
| 13 | - $this->acf4so_plugin = $plugin; |
|
| 14 | - } |
|
| 12 | + function __construct( Plugin $plugin ) { |
|
| 13 | + $this->acf4so_plugin = $plugin; |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - public function register_hooks() { |
|
| 17 | - add_action( 'admin_notices', [ $this, 'admin_notices' ] ); |
|
| 18 | - } |
|
| 16 | + public function register_hooks() { |
|
| 17 | + add_action( 'admin_notices', [ $this, 'admin_notices' ] ); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - public function admin_notices() { |
|
| 20 | + public function admin_notices() { |
|
| 21 | 21 | |
| 22 | - $is_package_type_supported = $this->is_package_type_supported(); |
|
| 22 | + $is_package_type_supported = $this->is_package_type_supported(); |
|
| 23 | 23 | |
| 24 | - $is_woocommerce_plugin_installed = defined( 'WL_WOO_VERSION' ); |
|
| 24 | + $is_woocommerce_plugin_installed = defined( 'WL_WOO_VERSION' ); |
|
| 25 | 25 | |
| 26 | - if ( ! $is_package_type_supported && ! $is_woocommerce_plugin_installed ) { |
|
| 27 | - // Dont display notice. |
|
| 28 | - return; |
|
| 29 | - } |
|
| 26 | + if ( ! $is_package_type_supported && ! $is_woocommerce_plugin_installed ) { |
|
| 27 | + // Dont display notice. |
|
| 28 | + return; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * 1. When package type is supported and acf4so not installed or activated then the notice should appear. |
|
| 33 | - * 2. When woocommerce plugin installed and acf4so not installed or activated then the notice should appear. |
|
| 34 | - */ |
|
| 35 | - if ( ! $this->acf4so_plugin->is_plugin_installed() ) { |
|
| 36 | - $this->display_notice( |
|
| 37 | - __( "WordLift detected that <b>Advanced Custom Fields for Schema.org</b> is not installed and, you're loosing out on full Schema.org support.", 'wordlift' ), |
|
| 38 | - __( 'Reinstall & Activate', 'wordlift' ) |
|
| 39 | - ); |
|
| 31 | + /** |
|
| 32 | + * 1. When package type is supported and acf4so not installed or activated then the notice should appear. |
|
| 33 | + * 2. When woocommerce plugin installed and acf4so not installed or activated then the notice should appear. |
|
| 34 | + */ |
|
| 35 | + if ( ! $this->acf4so_plugin->is_plugin_installed() ) { |
|
| 36 | + $this->display_notice( |
|
| 37 | + __( "WordLift detected that <b>Advanced Custom Fields for Schema.org</b> is not installed and, you're loosing out on full Schema.org support.", 'wordlift' ), |
|
| 38 | + __( 'Reinstall & Activate', 'wordlift' ) |
|
| 39 | + ); |
|
| 40 | 40 | |
| 41 | - // Dont display notice. |
|
| 42 | - return; |
|
| 43 | - } |
|
| 41 | + // Dont display notice. |
|
| 42 | + return; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - if ( ! $this->acf4so_plugin->is_plugin_activated() ) { |
|
| 46 | - $this->display_notice( |
|
| 47 | - __( "WordLift detected that <b>Advanced Custom Fields for Schema.org</b> is deactivated and, you're loosing out on full Schema.org support.", 'wordlift' ), |
|
| 48 | - __( 'Reactivate', 'wordlift' ) |
|
| 49 | - ); |
|
| 45 | + if ( ! $this->acf4so_plugin->is_plugin_activated() ) { |
|
| 46 | + $this->display_notice( |
|
| 47 | + __( "WordLift detected that <b>Advanced Custom Fields for Schema.org</b> is deactivated and, you're loosing out on full Schema.org support.", 'wordlift' ), |
|
| 48 | + __( 'Reactivate', 'wordlift' ) |
|
| 49 | + ); |
|
| 50 | 50 | |
| 51 | - return; |
|
| 52 | - } |
|
| 51 | + return; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - private function display_notice( $message, $button_text ) { |
|
| 57 | + private function display_notice( $message, $button_text ) { |
|
| 58 | 58 | |
| 59 | - $installation_success_message = __( |
|
| 60 | - '</p>WordLift: <b>Advanced Custom Fields for Schema.org</b> plugin installed and activated.</p>', |
|
| 61 | - 'wordlift' |
|
| 62 | - ); |
|
| 59 | + $installation_success_message = __( |
|
| 60 | + '</p>WordLift: <b>Advanced Custom Fields for Schema.org</b> plugin installed and activated.</p>', |
|
| 61 | + 'wordlift' |
|
| 62 | + ); |
|
| 63 | 63 | |
| 64 | - $installing_message = __( 'Installing <span class="spinner is-active"></span>', 'wordlift' ); |
|
| 65 | - $installation_failed_message = __( '<p>Wordlift: Advanced Custom Fields for Schema.org</b> Installation failed, please retry or contact [email protected]</p>' . |
|
| 66 | - '<button class="button action" onclick="wordliftInstallAcf4so(this)">Retry</button>', 'wordlift' ); |
|
| 64 | + $installing_message = __( 'Installing <span class="spinner is-active"></span>', 'wordlift' ); |
|
| 65 | + $installation_failed_message = __( '<p>Wordlift: Advanced Custom Fields for Schema.org</b> Installation failed, please retry or contact [email protected]</p>' . |
|
| 66 | + '<button class="button action" onclick="wordliftInstallAcf4so(this)">Retry</button>', 'wordlift' ); |
|
| 67 | 67 | |
| 68 | - ?> |
|
| 68 | + ?> |
|
| 69 | 69 | |
| 70 | 70 | <script> |
| 71 | 71 | window.addEventListener("load", function () { |
@@ -101,14 +101,14 @@ discard block |
||
| 101 | 101 | <br/> |
| 102 | 102 | </div> |
| 103 | 103 | <?php |
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @return bool |
|
| 108 | - */ |
|
| 109 | - private function is_package_type_supported() { |
|
| 110 | - return apply_filters( 'wl_feature__enable__entity-types-professional', false ) || |
|
| 111 | - apply_filters( 'wl_feature__enable__entity-types-business', false ); |
|
| 112 | - } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @return bool |
|
| 108 | + */ |
|
| 109 | + private function is_package_type_supported() { |
|
| 110 | + return apply_filters( 'wl_feature__enable__entity-types-professional', false ) || |
|
| 111 | + apply_filters( 'wl_feature__enable__entity-types-business', false ); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | 114 | } |
| 115 | 115 | \ No newline at end of file |
@@ -9,21 +9,21 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | private $acf4so_plugin; |
| 11 | 11 | |
| 12 | - function __construct( Plugin $plugin ) { |
|
| 12 | + function __construct(Plugin $plugin) { |
|
| 13 | 13 | $this->acf4so_plugin = $plugin; |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function register_hooks() { |
| 17 | - add_action( 'admin_notices', [ $this, 'admin_notices' ] ); |
|
| 17 | + add_action('admin_notices', [$this, 'admin_notices']); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function admin_notices() { |
| 21 | 21 | |
| 22 | 22 | $is_package_type_supported = $this->is_package_type_supported(); |
| 23 | 23 | |
| 24 | - $is_woocommerce_plugin_installed = defined( 'WL_WOO_VERSION' ); |
|
| 24 | + $is_woocommerce_plugin_installed = defined('WL_WOO_VERSION'); |
|
| 25 | 25 | |
| 26 | - if ( ! $is_package_type_supported && ! $is_woocommerce_plugin_installed ) { |
|
| 26 | + if ( ! $is_package_type_supported && ! $is_woocommerce_plugin_installed) { |
|
| 27 | 27 | // Dont display notice. |
| 28 | 28 | return; |
| 29 | 29 | } |
@@ -32,20 +32,20 @@ discard block |
||
| 32 | 32 | * 1. When package type is supported and acf4so not installed or activated then the notice should appear. |
| 33 | 33 | * 2. When woocommerce plugin installed and acf4so not installed or activated then the notice should appear. |
| 34 | 34 | */ |
| 35 | - if ( ! $this->acf4so_plugin->is_plugin_installed() ) { |
|
| 35 | + if ( ! $this->acf4so_plugin->is_plugin_installed()) { |
|
| 36 | 36 | $this->display_notice( |
| 37 | - __( "WordLift detected that <b>Advanced Custom Fields for Schema.org</b> is not installed and, you're loosing out on full Schema.org support.", 'wordlift' ), |
|
| 38 | - __( 'Reinstall & Activate', 'wordlift' ) |
|
| 37 | + __("WordLift detected that <b>Advanced Custom Fields for Schema.org</b> is not installed and, you're loosing out on full Schema.org support.", 'wordlift'), |
|
| 38 | + __('Reinstall & Activate', 'wordlift') |
|
| 39 | 39 | ); |
| 40 | 40 | |
| 41 | 41 | // Dont display notice. |
| 42 | 42 | return; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if ( ! $this->acf4so_plugin->is_plugin_activated() ) { |
|
| 45 | + if ( ! $this->acf4so_plugin->is_plugin_activated()) { |
|
| 46 | 46 | $this->display_notice( |
| 47 | - __( "WordLift detected that <b>Advanced Custom Fields for Schema.org</b> is deactivated and, you're loosing out on full Schema.org support.", 'wordlift' ), |
|
| 48 | - __( 'Reactivate', 'wordlift' ) |
|
| 47 | + __("WordLift detected that <b>Advanced Custom Fields for Schema.org</b> is deactivated and, you're loosing out on full Schema.org support.", 'wordlift'), |
|
| 48 | + __('Reactivate', 'wordlift') |
|
| 49 | 49 | ); |
| 50 | 50 | |
| 51 | 51 | return; |
@@ -54,16 +54,16 @@ discard block |
||
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
| 57 | - private function display_notice( $message, $button_text ) { |
|
| 57 | + private function display_notice($message, $button_text) { |
|
| 58 | 58 | |
| 59 | 59 | $installation_success_message = __( |
| 60 | 60 | '</p>WordLift: <b>Advanced Custom Fields for Schema.org</b> plugin installed and activated.</p>', |
| 61 | 61 | 'wordlift' |
| 62 | 62 | ); |
| 63 | 63 | |
| 64 | - $installing_message = __( 'Installing <span class="spinner is-active"></span>', 'wordlift' ); |
|
| 65 | - $installation_failed_message = __( '<p>Wordlift: Advanced Custom Fields for Schema.org</b> Installation failed, please retry or contact [email protected]</p>' . |
|
| 66 | - '<button class="button action" onclick="wordliftInstallAcf4so(this)">Retry</button>', 'wordlift' ); |
|
| 64 | + $installing_message = __('Installing <span class="spinner is-active"></span>', 'wordlift'); |
|
| 65 | + $installation_failed_message = __('<p>Wordlift: Advanced Custom Fields for Schema.org</b> Installation failed, please retry or contact [email protected]</p>'. |
|
| 66 | + '<button class="button action" onclick="wordliftInstallAcf4so(this)">Retry</button>', 'wordlift'); |
|
| 67 | 67 | |
| 68 | 68 | ?> |
| 69 | 69 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | const pluginInstallationNotice = document.getElementById("wordlift_acf4so_plugin_installation_notice") |
| 73 | 73 | const installPlugin = (ajaxUrl) => fetch(`${ajaxUrl}?action=wl_install_and_activate_advanced-custom-fields-for-schema-org`) |
| 74 | 74 | .then(response => response.ok ? response.json() : Promise.reject()) |
| 75 | - const ajaxUrl = "<?php echo esc_html( parse_url( admin_url( 'admin-ajax.php' ), PHP_URL_PATH ) ); ?>" |
|
| 75 | + const ajaxUrl = "<?php echo esc_html(parse_url(admin_url('admin-ajax.php'), PHP_URL_PATH)); ?>" |
|
| 76 | 76 | window.wordliftInstallAcf4so = function (installBtn) { |
| 77 | 77 | installBtn.innerHTML = `<?php echo $installing_message ?>` |
| 78 | 78 | installPlugin(ajaxUrl) |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | <p> |
| 95 | 95 | <?php echo $message; ?> |
| 96 | 96 | <button class="button action right" onclick="wordliftInstallAcf4so(this)"> |
| 97 | - <?php esc_html_e( $button_text ); ?> |
|
| 97 | + <?php esc_html_e($button_text); ?> |
|
| 98 | 98 | |
| 99 | 99 | </button> |
| 100 | 100 | </p> |
@@ -107,8 +107,8 @@ discard block |
||
| 107 | 107 | * @return bool |
| 108 | 108 | */ |
| 109 | 109 | private function is_package_type_supported() { |
| 110 | - return apply_filters( 'wl_feature__enable__entity-types-professional', false ) || |
|
| 111 | - apply_filters( 'wl_feature__enable__entity-types-business', false ); |
|
| 110 | + return apply_filters('wl_feature__enable__entity-types-professional', false) || |
|
| 111 | + apply_filters('wl_feature__enable__entity-types-business', false); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | } |
| 115 | 115 | \ No newline at end of file |
@@ -15,70 +15,70 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Wordlift_Website_Jsonld_Converter extends Wordlift_Post_To_Jsonld_Converter { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Convert the home/blog page to a JSON-LD array. |
|
| 20 | - * |
|
| 21 | - * @return array A JSON-LD array. |
|
| 22 | - * @since 3.14.0 |
|
| 23 | - * |
|
| 24 | - */ |
|
| 25 | - public function create_schema() { |
|
| 18 | + /** |
|
| 19 | + * Convert the home/blog page to a JSON-LD array. |
|
| 20 | + * |
|
| 21 | + * @return array A JSON-LD array. |
|
| 22 | + * @since 3.14.0 |
|
| 23 | + * |
|
| 24 | + */ |
|
| 25 | + public function create_schema() { |
|
| 26 | 26 | |
| 27 | - // Create new jsonld. |
|
| 28 | - $home_url = home_url( '/' ); |
|
| 27 | + // Create new jsonld. |
|
| 28 | + $home_url = home_url( '/' ); |
|
| 29 | 29 | |
| 30 | - $jsonld = array( |
|
| 31 | - '@context' => 'http://schema.org', |
|
| 32 | - '@type' => 'WebSite', |
|
| 33 | - '@id' => "$home_url#website", |
|
| 34 | - 'name' => html_entity_decode( get_bloginfo( 'name' ), ENT_QUOTES ), |
|
| 35 | - 'alternateName' => html_entity_decode( get_bloginfo( 'description' ), ENT_QUOTES ), |
|
| 36 | - 'url' => $home_url, |
|
| 37 | - ); |
|
| 30 | + $jsonld = array( |
|
| 31 | + '@context' => 'http://schema.org', |
|
| 32 | + '@type' => 'WebSite', |
|
| 33 | + '@id' => "$home_url#website", |
|
| 34 | + 'name' => html_entity_decode( get_bloginfo( 'name' ), ENT_QUOTES ), |
|
| 35 | + 'alternateName' => html_entity_decode( get_bloginfo( 'description' ), ENT_QUOTES ), |
|
| 36 | + 'url' => $home_url, |
|
| 37 | + ); |
|
| 38 | 38 | |
| 39 | - // Add publisher information. |
|
| 40 | - $this->set_publisher( $jsonld ); |
|
| 39 | + // Add publisher information. |
|
| 40 | + $this->set_publisher( $jsonld ); |
|
| 41 | 41 | |
| 42 | - // Add search action. |
|
| 43 | - $this->set_search_action( $jsonld ); |
|
| 42 | + // Add search action. |
|
| 43 | + $this->set_search_action( $jsonld ); |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Call the `wl_website_jsonld` filter. |
|
| 47 | - * |
|
| 48 | - * @param array $jsonld The JSON-LD structure. |
|
| 49 | - * |
|
| 50 | - * @since 3.14.0 |
|
| 51 | - * |
|
| 52 | - * @api |
|
| 53 | - * |
|
| 54 | - */ |
|
| 55 | - return apply_filters( 'wl_website_jsonld', $jsonld ); |
|
| 56 | - } |
|
| 45 | + /** |
|
| 46 | + * Call the `wl_website_jsonld` filter. |
|
| 47 | + * |
|
| 48 | + * @param array $jsonld The JSON-LD structure. |
|
| 49 | + * |
|
| 50 | + * @since 3.14.0 |
|
| 51 | + * |
|
| 52 | + * @api |
|
| 53 | + * |
|
| 54 | + */ |
|
| 55 | + return apply_filters( 'wl_website_jsonld', $jsonld ); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Add SearchAction part to the schema |
|
| 60 | - * |
|
| 61 | - * @param array $params The parameters array. |
|
| 62 | - * |
|
| 63 | - * @since 3.14.0 |
|
| 64 | - * |
|
| 65 | - */ |
|
| 66 | - private function set_search_action( &$params ) { |
|
| 67 | - /** |
|
| 68 | - * Filter: 'wl_jsonld_search_url' - Allows filtering of the search URL. |
|
| 69 | - * |
|
| 70 | - * @since 3.14.0 |
|
| 71 | - * @api string $search_url The search URL for this site with a `{search_term_string}` variable. |
|
| 72 | - */ |
|
| 73 | - $search_url = apply_filters( 'wl_jsonld_search_url', home_url( '/' ) . '?s={search_term_string}' ); |
|
| 58 | + /** |
|
| 59 | + * Add SearchAction part to the schema |
|
| 60 | + * |
|
| 61 | + * @param array $params The parameters array. |
|
| 62 | + * |
|
| 63 | + * @since 3.14.0 |
|
| 64 | + * |
|
| 65 | + */ |
|
| 66 | + private function set_search_action( &$params ) { |
|
| 67 | + /** |
|
| 68 | + * Filter: 'wl_jsonld_search_url' - Allows filtering of the search URL. |
|
| 69 | + * |
|
| 70 | + * @since 3.14.0 |
|
| 71 | + * @api string $search_url The search URL for this site with a `{search_term_string}` variable. |
|
| 72 | + */ |
|
| 73 | + $search_url = apply_filters( 'wl_jsonld_search_url', home_url( '/' ) . '?s={search_term_string}' ); |
|
| 74 | 74 | |
| 75 | - // Add search action |
|
| 76 | - $params['potentialAction'] = array( |
|
| 77 | - '@type' => 'SearchAction', |
|
| 78 | - 'target' => $search_url, |
|
| 79 | - 'query-input' => 'required name=search_term_string', |
|
| 80 | - ); |
|
| 75 | + // Add search action |
|
| 76 | + $params['potentialAction'] = array( |
|
| 77 | + '@type' => 'SearchAction', |
|
| 78 | + 'target' => $search_url, |
|
| 79 | + 'query-input' => 'required name=search_term_string', |
|
| 80 | + ); |
|
| 81 | 81 | |
| 82 | - } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | 84 | } |
@@ -25,22 +25,22 @@ discard block |
||
| 25 | 25 | public function create_schema() { |
| 26 | 26 | |
| 27 | 27 | // Create new jsonld. |
| 28 | - $home_url = home_url( '/' ); |
|
| 28 | + $home_url = home_url('/'); |
|
| 29 | 29 | |
| 30 | 30 | $jsonld = array( |
| 31 | 31 | '@context' => 'http://schema.org', |
| 32 | 32 | '@type' => 'WebSite', |
| 33 | 33 | '@id' => "$home_url#website", |
| 34 | - 'name' => html_entity_decode( get_bloginfo( 'name' ), ENT_QUOTES ), |
|
| 35 | - 'alternateName' => html_entity_decode( get_bloginfo( 'description' ), ENT_QUOTES ), |
|
| 34 | + 'name' => html_entity_decode(get_bloginfo('name'), ENT_QUOTES), |
|
| 35 | + 'alternateName' => html_entity_decode(get_bloginfo('description'), ENT_QUOTES), |
|
| 36 | 36 | 'url' => $home_url, |
| 37 | 37 | ); |
| 38 | 38 | |
| 39 | 39 | // Add publisher information. |
| 40 | - $this->set_publisher( $jsonld ); |
|
| 40 | + $this->set_publisher($jsonld); |
|
| 41 | 41 | |
| 42 | 42 | // Add search action. |
| 43 | - $this->set_search_action( $jsonld ); |
|
| 43 | + $this->set_search_action($jsonld); |
|
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * Call the `wl_website_jsonld` filter. |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @api |
| 53 | 53 | * |
| 54 | 54 | */ |
| 55 | - return apply_filters( 'wl_website_jsonld', $jsonld ); |
|
| 55 | + return apply_filters('wl_website_jsonld', $jsonld); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -63,14 +63,14 @@ discard block |
||
| 63 | 63 | * @since 3.14.0 |
| 64 | 64 | * |
| 65 | 65 | */ |
| 66 | - private function set_search_action( &$params ) { |
|
| 66 | + private function set_search_action(&$params) { |
|
| 67 | 67 | /** |
| 68 | 68 | * Filter: 'wl_jsonld_search_url' - Allows filtering of the search URL. |
| 69 | 69 | * |
| 70 | 70 | * @since 3.14.0 |
| 71 | 71 | * @api string $search_url The search URL for this site with a `{search_term_string}` variable. |
| 72 | 72 | */ |
| 73 | - $search_url = apply_filters( 'wl_jsonld_search_url', home_url( '/' ) . '?s={search_term_string}' ); |
|
| 73 | + $search_url = apply_filters('wl_jsonld_search_url', home_url('/').'?s={search_term_string}'); |
|
| 74 | 74 | |
| 75 | 75 | // Add search action |
| 76 | 76 | $params['potentialAction'] = array( |
@@ -23,400 +23,400 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | abstract class Wordlift_Abstract_Post_To_Jsonld_Converter implements Wordlift_Post_Converter { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * The JSON-LD context. |
|
| 28 | - * |
|
| 29 | - * @since 3.10.0 |
|
| 30 | - */ |
|
| 31 | - const CONTEXT = 'http://schema.org'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * A {@link Wordlift_Entity_Type_Service} instance. |
|
| 35 | - * |
|
| 36 | - * @since 3.10.0 |
|
| 37 | - * @access protected |
|
| 38 | - * @var \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 39 | - */ |
|
| 40 | - protected $entity_type_service; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * A {@link Wordlift_User_Service} instance. |
|
| 44 | - * |
|
| 45 | - * @since 3.10.0 |
|
| 46 | - * @access private |
|
| 47 | - * @var \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance. |
|
| 48 | - */ |
|
| 49 | - protected $user_service; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * A {@link Wordlift_Attachment_Service} instance. |
|
| 53 | - * |
|
| 54 | - * @since 3.10.0 |
|
| 55 | - * @access private |
|
| 56 | - * @var \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance. |
|
| 57 | - */ |
|
| 58 | - protected $attachment_service; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var Wordlift_Property_Getter |
|
| 62 | - */ |
|
| 63 | - private $property_getter; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Wordlift_Post_To_Jsonld_Converter constructor. |
|
| 67 | - * |
|
| 68 | - * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 69 | - * @param \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance. |
|
| 70 | - * @param \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance. |
|
| 71 | - * @param \Wordlift_Property_Getter $property_getter |
|
| 72 | - * |
|
| 73 | - * @since 3.10.0 |
|
| 74 | - * |
|
| 75 | - */ |
|
| 76 | - public function __construct( $entity_type_service, $user_service, $attachment_service, $property_getter ) { |
|
| 77 | - $this->entity_type_service = $entity_type_service; |
|
| 78 | - $this->user_service = $user_service; |
|
| 79 | - $this->attachment_service = $attachment_service; |
|
| 80 | - $this->property_getter = $property_getter; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference |
|
| 85 | - * found while processing the post is set in the $references array. |
|
| 86 | - * |
|
| 87 | - * @param int $post_id The post id. |
|
| 88 | - * @param array $references An array of entity references. |
|
| 89 | - * @param array $references_infos |
|
| 90 | - * |
|
| 91 | - * @return array A JSON-LD array. |
|
| 92 | - * @since 3.10.0 |
|
| 93 | - */ |
|
| 94 | - public function convert( $post_id, &$references = array(), &$references_infos = array() ) { |
|
| 95 | - |
|
| 96 | - // Get the post instance. |
|
| 97 | - $post = get_post( $post_id ); |
|
| 98 | - if ( null === $post ) { |
|
| 99 | - // Post not found. |
|
| 100 | - return null; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // Get the post URI @id. |
|
| 104 | - $id = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID ); |
|
| 105 | - if ( is_null( $id ) ) { |
|
| 106 | - $id = 'get_uri returned null, dataset is ' . wl_configuration_get_redlink_dataset_uri(); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /* |
|
| 26 | + /** |
|
| 27 | + * The JSON-LD context. |
|
| 28 | + * |
|
| 29 | + * @since 3.10.0 |
|
| 30 | + */ |
|
| 31 | + const CONTEXT = 'http://schema.org'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * A {@link Wordlift_Entity_Type_Service} instance. |
|
| 35 | + * |
|
| 36 | + * @since 3.10.0 |
|
| 37 | + * @access protected |
|
| 38 | + * @var \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 39 | + */ |
|
| 40 | + protected $entity_type_service; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * A {@link Wordlift_User_Service} instance. |
|
| 44 | + * |
|
| 45 | + * @since 3.10.0 |
|
| 46 | + * @access private |
|
| 47 | + * @var \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance. |
|
| 48 | + */ |
|
| 49 | + protected $user_service; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * A {@link Wordlift_Attachment_Service} instance. |
|
| 53 | + * |
|
| 54 | + * @since 3.10.0 |
|
| 55 | + * @access private |
|
| 56 | + * @var \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance. |
|
| 57 | + */ |
|
| 58 | + protected $attachment_service; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var Wordlift_Property_Getter |
|
| 62 | + */ |
|
| 63 | + private $property_getter; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Wordlift_Post_To_Jsonld_Converter constructor. |
|
| 67 | + * |
|
| 68 | + * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 69 | + * @param \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance. |
|
| 70 | + * @param \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance. |
|
| 71 | + * @param \Wordlift_Property_Getter $property_getter |
|
| 72 | + * |
|
| 73 | + * @since 3.10.0 |
|
| 74 | + * |
|
| 75 | + */ |
|
| 76 | + public function __construct( $entity_type_service, $user_service, $attachment_service, $property_getter ) { |
|
| 77 | + $this->entity_type_service = $entity_type_service; |
|
| 78 | + $this->user_service = $user_service; |
|
| 79 | + $this->attachment_service = $attachment_service; |
|
| 80 | + $this->property_getter = $property_getter; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference |
|
| 85 | + * found while processing the post is set in the $references array. |
|
| 86 | + * |
|
| 87 | + * @param int $post_id The post id. |
|
| 88 | + * @param array $references An array of entity references. |
|
| 89 | + * @param array $references_infos |
|
| 90 | + * |
|
| 91 | + * @return array A JSON-LD array. |
|
| 92 | + * @since 3.10.0 |
|
| 93 | + */ |
|
| 94 | + public function convert( $post_id, &$references = array(), &$references_infos = array() ) { |
|
| 95 | + |
|
| 96 | + // Get the post instance. |
|
| 97 | + $post = get_post( $post_id ); |
|
| 98 | + if ( null === $post ) { |
|
| 99 | + // Post not found. |
|
| 100 | + return null; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // Get the post URI @id. |
|
| 104 | + $id = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID ); |
|
| 105 | + if ( is_null( $id ) ) { |
|
| 106 | + $id = 'get_uri returned null, dataset is ' . wl_configuration_get_redlink_dataset_uri(); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /* |
|
| 110 | 110 | * The `types` variable holds one or more entity types. The `type` variable isn't used anymore. |
| 111 | 111 | * |
| 112 | 112 | * @since 3.20.0 We support more than one entity type. |
| 113 | 113 | * |
| 114 | 114 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
| 115 | 115 | */ |
| 116 | - // // Get the entity @type. We consider `post` BlogPostings. |
|
| 117 | - // $type = $this->entity_type_service->get( $post_id ); |
|
| 118 | - $types = $this->entity_type_service->get_names( $post_id ); |
|
| 119 | - $type = self::make_one( $types ); |
|
| 120 | - |
|
| 121 | - // Prepare the response. |
|
| 122 | - $jsonld = array( |
|
| 123 | - '@context' => self::CONTEXT, |
|
| 124 | - '@id' => $id, |
|
| 125 | - '@type' => $type, |
|
| 126 | - 'description' => Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post ), |
|
| 127 | - ); |
|
| 128 | - |
|
| 129 | - // Set the `mainEntityOfPage` property if the post has some contents. |
|
| 130 | - /* |
|
| 116 | + // // Get the entity @type. We consider `post` BlogPostings. |
|
| 117 | + // $type = $this->entity_type_service->get( $post_id ); |
|
| 118 | + $types = $this->entity_type_service->get_names( $post_id ); |
|
| 119 | + $type = self::make_one( $types ); |
|
| 120 | + |
|
| 121 | + // Prepare the response. |
|
| 122 | + $jsonld = array( |
|
| 123 | + '@context' => self::CONTEXT, |
|
| 124 | + '@id' => $id, |
|
| 125 | + '@type' => $type, |
|
| 126 | + 'description' => Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post ), |
|
| 127 | + ); |
|
| 128 | + |
|
| 129 | + // Set the `mainEntityOfPage` property if the post has some contents. |
|
| 130 | + /* |
|
| 131 | 131 | * Apply the `wl_post_content` filter, in case 3rd parties want to change the post content, e.g. |
| 132 | 132 | * because the content is written elsewhere. |
| 133 | 133 | * |
| 134 | 134 | * @since 3.20.0 |
| 135 | 135 | */ |
| 136 | - $post_content = apply_filters( 'wl_post_content', $post->post_content, $post ); |
|
| 137 | - if ( ! empty( $post_content ) ) { |
|
| 138 | - // We're setting the `mainEntityOfPage` to signal which one is the |
|
| 139 | - // main entity for the specified URL. It might be however that the |
|
| 140 | - // post/page is actually about another specific entity. How WL deals |
|
| 141 | - // with that hasn't been defined yet (see https://github.com/insideout10/wordlift-plugin/issues/451). |
|
| 142 | - // |
|
| 143 | - // See http://schema.org/mainEntityOfPage |
|
| 144 | - // |
|
| 145 | - // No need to specify `'@type' => 'WebPage'. |
|
| 146 | - // |
|
| 147 | - // See https://github.com/insideout10/wordlift-plugin/issues/451. |
|
| 148 | - $jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID ); |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1207 |
|
| 152 | - * |
|
| 153 | - * @since 3.27.7 |
|
| 154 | - */ |
|
| 155 | - if ( in_array( $type, array( 'Occupation', 'OccupationAggregationByEmployer' ) ) ) { |
|
| 156 | - $jsonld['mainEntityOfPage'] = array( |
|
| 157 | - '@type' => 'WebPage', |
|
| 158 | - 'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ) |
|
| 159 | - ); |
|
| 160 | - } |
|
| 161 | - }; |
|
| 162 | - |
|
| 163 | - $this->set_images( $this->attachment_service, $post, $jsonld ); |
|
| 164 | - |
|
| 165 | - // Get the entities referenced by this post and set it to the `references` |
|
| 166 | - // array so that the caller can do further processing, such as printing out |
|
| 167 | - // more of those references. |
|
| 168 | - $references_without_locations = Object_Relation_Service::get_instance() |
|
| 169 | - ->get_references( $post_id, Object_Type_Enum::POST ); |
|
| 170 | - |
|
| 171 | - /* |
|
| 136 | + $post_content = apply_filters( 'wl_post_content', $post->post_content, $post ); |
|
| 137 | + if ( ! empty( $post_content ) ) { |
|
| 138 | + // We're setting the `mainEntityOfPage` to signal which one is the |
|
| 139 | + // main entity for the specified URL. It might be however that the |
|
| 140 | + // post/page is actually about another specific entity. How WL deals |
|
| 141 | + // with that hasn't been defined yet (see https://github.com/insideout10/wordlift-plugin/issues/451). |
|
| 142 | + // |
|
| 143 | + // See http://schema.org/mainEntityOfPage |
|
| 144 | + // |
|
| 145 | + // No need to specify `'@type' => 'WebPage'. |
|
| 146 | + // |
|
| 147 | + // See https://github.com/insideout10/wordlift-plugin/issues/451. |
|
| 148 | + $jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID ); |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1207 |
|
| 152 | + * |
|
| 153 | + * @since 3.27.7 |
|
| 154 | + */ |
|
| 155 | + if ( in_array( $type, array( 'Occupation', 'OccupationAggregationByEmployer' ) ) ) { |
|
| 156 | + $jsonld['mainEntityOfPage'] = array( |
|
| 157 | + '@type' => 'WebPage', |
|
| 158 | + 'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ) |
|
| 159 | + ); |
|
| 160 | + } |
|
| 161 | + }; |
|
| 162 | + |
|
| 163 | + $this->set_images( $this->attachment_service, $post, $jsonld ); |
|
| 164 | + |
|
| 165 | + // Get the entities referenced by this post and set it to the `references` |
|
| 166 | + // array so that the caller can do further processing, such as printing out |
|
| 167 | + // more of those references. |
|
| 168 | + $references_without_locations = Object_Relation_Service::get_instance() |
|
| 169 | + ->get_references( $post_id, Object_Type_Enum::POST ); |
|
| 170 | + |
|
| 171 | + /* |
|
| 172 | 172 | * Add the locations to the references. |
| 173 | 173 | * |
| 174 | 174 | * @since 3.19.5 |
| 175 | 175 | * |
| 176 | 176 | * @see https://github.com/insideout10/wordlift-plugin/issues/858. |
| 177 | 177 | */ |
| 178 | - // A reference to use in closure. |
|
| 179 | - $entity_type_service = $this->entity_type_service; |
|
| 180 | - $locations = array_reduce( $references_without_locations, function ( $carry, $reference ) use ( $entity_type_service ) { |
|
| 181 | - /** |
|
| 182 | - * @var $reference Reference |
|
| 183 | - */ |
|
| 184 | - // @see https://schema.org/location for the schema.org types using the `location` property. |
|
| 185 | - if ( ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Action' ) |
|
| 186 | - && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Event' ) |
|
| 187 | - && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Organization' ) ) { |
|
| 188 | - |
|
| 189 | - return $carry; |
|
| 190 | - } |
|
| 191 | - $post_location_ids = get_post_meta( $reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION ); |
|
| 192 | - $post_location_references = array_map( function ( $post_id ) { |
|
| 193 | - return new Post_Reference( $post_id ); |
|
| 194 | - }, $post_location_ids ); |
|
| 195 | - |
|
| 196 | - return array_merge( $carry, $post_location_references ); |
|
| 197 | - }, array() ); |
|
| 198 | - |
|
| 199 | - // Merge the references with the referenced locations if any. |
|
| 200 | - $references = array_merge( $references_without_locations, $locations ); |
|
| 201 | - |
|
| 202 | - return $jsonld; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * If the provided value starts with the schema.org context, we remove the schema.org |
|
| 207 | - * part since it is set with the '@context'. |
|
| 208 | - * |
|
| 209 | - * @param string $value The property value. |
|
| 210 | - * |
|
| 211 | - * @return string The property value without the context. |
|
| 212 | - * @since 3.10.0 |
|
| 213 | - * |
|
| 214 | - */ |
|
| 215 | - public function relative_to_context( $value ) { |
|
| 216 | - |
|
| 217 | - return 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Set the images, by looking for embedded images, for images loaded via the |
|
| 222 | - * gallery and for the featured image. |
|
| 223 | - * |
|
| 224 | - * Uses the cache service to store the results of this function for a day. |
|
| 225 | - * |
|
| 226 | - * @param $attachment_service Wordlift_Attachment_Service |
|
| 227 | - * @param WP_Post $post The target {@link WP_Post}. |
|
| 228 | - * @param array $jsonld The JSON-LD array. |
|
| 229 | - * |
|
| 230 | - * @since 3.10.0 |
|
| 231 | - */ |
|
| 232 | - public static function set_images( $attachment_service, $post, &$jsonld ) { |
|
| 233 | - |
|
| 234 | - // Prepare the attachment ids array. |
|
| 235 | - $ids = array(); |
|
| 236 | - |
|
| 237 | - // Set the thumbnail id as first attachment id, if any. |
|
| 238 | - $thumbnail_id = get_post_thumbnail_id( $post->ID ); |
|
| 239 | - if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) { |
|
| 240 | - $ids[] = $thumbnail_id; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - // For the time being the following is being removed since the query |
|
| 244 | - // initiated by `get_image_embeds` is consuming lots of CPU. |
|
| 245 | - // |
|
| 246 | - // See https://github.com/insideout10/wordlift-plugin/issues/689. |
|
| 247 | - // |
|
| 248 | - // Get the embeds, removing existing ids. |
|
| 249 | - if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) { |
|
| 250 | - $embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids ); |
|
| 251 | - } else { |
|
| 252 | - $embeds = array(); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - // Get the gallery, removing existing ids. |
|
| 256 | - $gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds ); |
|
| 257 | - |
|
| 258 | - // Map the attachment ids to images' data structured for schema.org use. |
|
| 259 | - $images_with_sizes = array_filter( |
|
| 260 | - array_reduce( array_merge( $ids, $embeds, $gallery ), |
|
| 261 | - function ( $carry, $item ) { |
|
| 262 | - /* |
|
| 178 | + // A reference to use in closure. |
|
| 179 | + $entity_type_service = $this->entity_type_service; |
|
| 180 | + $locations = array_reduce( $references_without_locations, function ( $carry, $reference ) use ( $entity_type_service ) { |
|
| 181 | + /** |
|
| 182 | + * @var $reference Reference |
|
| 183 | + */ |
|
| 184 | + // @see https://schema.org/location for the schema.org types using the `location` property. |
|
| 185 | + if ( ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Action' ) |
|
| 186 | + && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Event' ) |
|
| 187 | + && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Organization' ) ) { |
|
| 188 | + |
|
| 189 | + return $carry; |
|
| 190 | + } |
|
| 191 | + $post_location_ids = get_post_meta( $reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION ); |
|
| 192 | + $post_location_references = array_map( function ( $post_id ) { |
|
| 193 | + return new Post_Reference( $post_id ); |
|
| 194 | + }, $post_location_ids ); |
|
| 195 | + |
|
| 196 | + return array_merge( $carry, $post_location_references ); |
|
| 197 | + }, array() ); |
|
| 198 | + |
|
| 199 | + // Merge the references with the referenced locations if any. |
|
| 200 | + $references = array_merge( $references_without_locations, $locations ); |
|
| 201 | + |
|
| 202 | + return $jsonld; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * If the provided value starts with the schema.org context, we remove the schema.org |
|
| 207 | + * part since it is set with the '@context'. |
|
| 208 | + * |
|
| 209 | + * @param string $value The property value. |
|
| 210 | + * |
|
| 211 | + * @return string The property value without the context. |
|
| 212 | + * @since 3.10.0 |
|
| 213 | + * |
|
| 214 | + */ |
|
| 215 | + public function relative_to_context( $value ) { |
|
| 216 | + |
|
| 217 | + return 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Set the images, by looking for embedded images, for images loaded via the |
|
| 222 | + * gallery and for the featured image. |
|
| 223 | + * |
|
| 224 | + * Uses the cache service to store the results of this function for a day. |
|
| 225 | + * |
|
| 226 | + * @param $attachment_service Wordlift_Attachment_Service |
|
| 227 | + * @param WP_Post $post The target {@link WP_Post}. |
|
| 228 | + * @param array $jsonld The JSON-LD array. |
|
| 229 | + * |
|
| 230 | + * @since 3.10.0 |
|
| 231 | + */ |
|
| 232 | + public static function set_images( $attachment_service, $post, &$jsonld ) { |
|
| 233 | + |
|
| 234 | + // Prepare the attachment ids array. |
|
| 235 | + $ids = array(); |
|
| 236 | + |
|
| 237 | + // Set the thumbnail id as first attachment id, if any. |
|
| 238 | + $thumbnail_id = get_post_thumbnail_id( $post->ID ); |
|
| 239 | + if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) { |
|
| 240 | + $ids[] = $thumbnail_id; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + // For the time being the following is being removed since the query |
|
| 244 | + // initiated by `get_image_embeds` is consuming lots of CPU. |
|
| 245 | + // |
|
| 246 | + // See https://github.com/insideout10/wordlift-plugin/issues/689. |
|
| 247 | + // |
|
| 248 | + // Get the embeds, removing existing ids. |
|
| 249 | + if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) { |
|
| 250 | + $embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids ); |
|
| 251 | + } else { |
|
| 252 | + $embeds = array(); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + // Get the gallery, removing existing ids. |
|
| 256 | + $gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds ); |
|
| 257 | + |
|
| 258 | + // Map the attachment ids to images' data structured for schema.org use. |
|
| 259 | + $images_with_sizes = array_filter( |
|
| 260 | + array_reduce( array_merge( $ids, $embeds, $gallery ), |
|
| 261 | + function ( $carry, $item ) { |
|
| 262 | + /* |
|
| 263 | 263 | * @todo: we're not sure that we're getting attachment data here, we |
| 264 | 264 | * should filter `false`s. |
| 265 | 265 | */ |
| 266 | 266 | |
| 267 | - $sources = array_merge( |
|
| 268 | - Wordlift_Image_Service::get_sources( $item ), |
|
| 269 | - array( wp_get_attachment_image_src( $item, 'full' ) ) |
|
| 270 | - ); |
|
| 271 | - |
|
| 272 | - $sources_with_image = array_filter( $sources, function ( $source ) { |
|
| 273 | - return ! empty( $source[0] ); |
|
| 274 | - } ); |
|
| 275 | - |
|
| 276 | - // Get the attachment data. |
|
| 277 | - // $attachment = wp_get_attachment_image_src( $item, 'full' ); |
|
| 278 | - |
|
| 279 | - // var_dump( array( "sources-$item" => Wordlift_Image_Service::get_sources( $item ) ) ); |
|
| 280 | - |
|
| 281 | - // Bail if image is not found. |
|
| 282 | - // In some cases, you can delete the image from the database |
|
| 283 | - // or from uploads dir, but the image id still exists as featured image |
|
| 284 | - // or in [gallery] shortcode. |
|
| 285 | - // if ( empty( $attachment[0] ) ) { |
|
| 286 | - if ( empty( $sources_with_image ) ) { |
|
| 287 | - return $carry; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - // Merge the arrays. |
|
| 291 | - return array_merge( |
|
| 292 | - $carry, |
|
| 293 | - $sources_with_image |
|
| 294 | - ); |
|
| 295 | - } |
|
| 296 | - // Initial array. |
|
| 297 | - , array() ) |
|
| 298 | - ); |
|
| 299 | - |
|
| 300 | - // Refactor data as per schema.org specifications. |
|
| 301 | - $images = array_map( function ( $attachment ) { |
|
| 302 | - return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size( |
|
| 303 | - array( |
|
| 304 | - '@type' => 'ImageObject', |
|
| 305 | - 'url' => $attachment[0], |
|
| 306 | - ), $attachment |
|
| 307 | - ); |
|
| 308 | - }, $images_with_sizes ); |
|
| 309 | - |
|
| 310 | - // Add images if present. |
|
| 311 | - if ( 0 < count( $images ) ) { |
|
| 312 | - $jsonld['image'] = $images; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * If the provided array of values contains only one value, then one single |
|
| 319 | - * value is returned, otherwise the original array is returned. |
|
| 320 | - * |
|
| 321 | - * @param array $value An array of values. |
|
| 322 | - * |
|
| 323 | - * @return mixed|array A single value or the original array. |
|
| 324 | - * @since 3.20.0 The function has been moved from {@link Wordlift_Entity_Post_To_Jsonld_Converter} to |
|
| 325 | - * {@link Wordlift_Abstract_Post_To_Jsonld_Converter}. |
|
| 326 | - * @since 3.8.0 |
|
| 327 | - * @access private |
|
| 328 | - * |
|
| 329 | - */ |
|
| 330 | - protected static function make_one( $value ) { |
|
| 331 | - |
|
| 332 | - return 1 === count( $value ) ? $value[0] : $value; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Process the provided array by adding the width / height if the values |
|
| 337 | - * are available and are greater than 0. |
|
| 338 | - * |
|
| 339 | - * @param array $image The `ImageObject` array. |
|
| 340 | - * @param array $attachment The attachment array. |
|
| 341 | - * |
|
| 342 | - * @return array The enriched `ImageObject` array. |
|
| 343 | - * @since 3.14.0 |
|
| 344 | - * |
|
| 345 | - */ |
|
| 346 | - public static function set_image_size( $image, $attachment ) { |
|
| 347 | - |
|
| 348 | - // If you specify a "width" or "height" value you should leave out |
|
| 349 | - // 'px'. For example: "width":"4608px" should be "width":"4608". |
|
| 350 | - // |
|
| 351 | - // See https://github.com/insideout10/wordlift-plugin/issues/451. |
|
| 352 | - if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) { |
|
| 353 | - $image['width'] = $attachment[1]; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) { |
|
| 357 | - $image['height'] = $attachment[2]; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - return $image; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Add data to the JSON-LD using the `custom_fields` array which contains the definitions of property |
|
| 366 | - * for the post entity type. |
|
| 367 | - * |
|
| 368 | - * @param array $jsonld The JSON-LD array. |
|
| 369 | - * @param array $fields The entity types field array. |
|
| 370 | - * @param WP_Post $post The target {@link WP_Post} instance. |
|
| 371 | - * @param array $references The references array. |
|
| 372 | - * |
|
| 373 | - * @since 3.20.0 This code moved from the above function `convert`, used for entity types defined in |
|
| 374 | - * the {@link Wordlift_Schema_Service} class. |
|
| 375 | - * |
|
| 376 | - */ |
|
| 377 | - protected function process_type_custom_fields( &$jsonld, $fields, $post, &$references, &$references_infos ) { |
|
| 378 | - |
|
| 379 | - // Set a reference to use in closures. |
|
| 380 | - $converter = $this; |
|
| 381 | - |
|
| 382 | - // Try each field on the entity. |
|
| 383 | - foreach ( $fields as $key => $value ) { |
|
| 384 | - |
|
| 385 | - // Get the predicate. |
|
| 386 | - $name = $this->relative_to_context( $value['predicate'] ); |
|
| 387 | - |
|
| 388 | - // Get the value, the property service will get the right extractor |
|
| 389 | - // for that property. |
|
| 390 | - $value = $this->property_getter->get( $post->ID, $key, Object_Type_Enum::POST ); |
|
| 391 | - |
|
| 392 | - if ( empty( $value ) ) { |
|
| 393 | - continue; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - // Map the value to the property name. |
|
| 397 | - // If we got an array with just one value, we return that one value. |
|
| 398 | - // If we got a Wordlift_Property_Entity_Reference we get the URL. |
|
| 399 | - $jsonld[ $name ] = self::make_one( array_map( function ( $item ) use ( $converter, &$references, &$references_infos ) { |
|
| 400 | - |
|
| 401 | - if ( $item instanceof Wordlift_Property_Entity_Reference ) { |
|
| 402 | - |
|
| 403 | - $url = $item->get_url(); |
|
| 404 | - |
|
| 405 | - // The refactored converters require the entity id. |
|
| 406 | - $references[] = $item->get_id(); |
|
| 407 | - |
|
| 408 | - $references_infos[] = array( 'reference' => $item ); |
|
| 409 | - |
|
| 410 | - return array( |
|
| 411 | - '@id' => $url, |
|
| 412 | - ); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - return $converter->relative_to_context( $item ); |
|
| 416 | - }, $value ) ); |
|
| 417 | - |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - } |
|
| 267 | + $sources = array_merge( |
|
| 268 | + Wordlift_Image_Service::get_sources( $item ), |
|
| 269 | + array( wp_get_attachment_image_src( $item, 'full' ) ) |
|
| 270 | + ); |
|
| 271 | + |
|
| 272 | + $sources_with_image = array_filter( $sources, function ( $source ) { |
|
| 273 | + return ! empty( $source[0] ); |
|
| 274 | + } ); |
|
| 275 | + |
|
| 276 | + // Get the attachment data. |
|
| 277 | + // $attachment = wp_get_attachment_image_src( $item, 'full' ); |
|
| 278 | + |
|
| 279 | + // var_dump( array( "sources-$item" => Wordlift_Image_Service::get_sources( $item ) ) ); |
|
| 280 | + |
|
| 281 | + // Bail if image is not found. |
|
| 282 | + // In some cases, you can delete the image from the database |
|
| 283 | + // or from uploads dir, but the image id still exists as featured image |
|
| 284 | + // or in [gallery] shortcode. |
|
| 285 | + // if ( empty( $attachment[0] ) ) { |
|
| 286 | + if ( empty( $sources_with_image ) ) { |
|
| 287 | + return $carry; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + // Merge the arrays. |
|
| 291 | + return array_merge( |
|
| 292 | + $carry, |
|
| 293 | + $sources_with_image |
|
| 294 | + ); |
|
| 295 | + } |
|
| 296 | + // Initial array. |
|
| 297 | + , array() ) |
|
| 298 | + ); |
|
| 299 | + |
|
| 300 | + // Refactor data as per schema.org specifications. |
|
| 301 | + $images = array_map( function ( $attachment ) { |
|
| 302 | + return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size( |
|
| 303 | + array( |
|
| 304 | + '@type' => 'ImageObject', |
|
| 305 | + 'url' => $attachment[0], |
|
| 306 | + ), $attachment |
|
| 307 | + ); |
|
| 308 | + }, $images_with_sizes ); |
|
| 309 | + |
|
| 310 | + // Add images if present. |
|
| 311 | + if ( 0 < count( $images ) ) { |
|
| 312 | + $jsonld['image'] = $images; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * If the provided array of values contains only one value, then one single |
|
| 319 | + * value is returned, otherwise the original array is returned. |
|
| 320 | + * |
|
| 321 | + * @param array $value An array of values. |
|
| 322 | + * |
|
| 323 | + * @return mixed|array A single value or the original array. |
|
| 324 | + * @since 3.20.0 The function has been moved from {@link Wordlift_Entity_Post_To_Jsonld_Converter} to |
|
| 325 | + * {@link Wordlift_Abstract_Post_To_Jsonld_Converter}. |
|
| 326 | + * @since 3.8.0 |
|
| 327 | + * @access private |
|
| 328 | + * |
|
| 329 | + */ |
|
| 330 | + protected static function make_one( $value ) { |
|
| 331 | + |
|
| 332 | + return 1 === count( $value ) ? $value[0] : $value; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Process the provided array by adding the width / height if the values |
|
| 337 | + * are available and are greater than 0. |
|
| 338 | + * |
|
| 339 | + * @param array $image The `ImageObject` array. |
|
| 340 | + * @param array $attachment The attachment array. |
|
| 341 | + * |
|
| 342 | + * @return array The enriched `ImageObject` array. |
|
| 343 | + * @since 3.14.0 |
|
| 344 | + * |
|
| 345 | + */ |
|
| 346 | + public static function set_image_size( $image, $attachment ) { |
|
| 347 | + |
|
| 348 | + // If you specify a "width" or "height" value you should leave out |
|
| 349 | + // 'px'. For example: "width":"4608px" should be "width":"4608". |
|
| 350 | + // |
|
| 351 | + // See https://github.com/insideout10/wordlift-plugin/issues/451. |
|
| 352 | + if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) { |
|
| 353 | + $image['width'] = $attachment[1]; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) { |
|
| 357 | + $image['height'] = $attachment[2]; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + return $image; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Add data to the JSON-LD using the `custom_fields` array which contains the definitions of property |
|
| 366 | + * for the post entity type. |
|
| 367 | + * |
|
| 368 | + * @param array $jsonld The JSON-LD array. |
|
| 369 | + * @param array $fields The entity types field array. |
|
| 370 | + * @param WP_Post $post The target {@link WP_Post} instance. |
|
| 371 | + * @param array $references The references array. |
|
| 372 | + * |
|
| 373 | + * @since 3.20.0 This code moved from the above function `convert`, used for entity types defined in |
|
| 374 | + * the {@link Wordlift_Schema_Service} class. |
|
| 375 | + * |
|
| 376 | + */ |
|
| 377 | + protected function process_type_custom_fields( &$jsonld, $fields, $post, &$references, &$references_infos ) { |
|
| 378 | + |
|
| 379 | + // Set a reference to use in closures. |
|
| 380 | + $converter = $this; |
|
| 381 | + |
|
| 382 | + // Try each field on the entity. |
|
| 383 | + foreach ( $fields as $key => $value ) { |
|
| 384 | + |
|
| 385 | + // Get the predicate. |
|
| 386 | + $name = $this->relative_to_context( $value['predicate'] ); |
|
| 387 | + |
|
| 388 | + // Get the value, the property service will get the right extractor |
|
| 389 | + // for that property. |
|
| 390 | + $value = $this->property_getter->get( $post->ID, $key, Object_Type_Enum::POST ); |
|
| 391 | + |
|
| 392 | + if ( empty( $value ) ) { |
|
| 393 | + continue; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + // Map the value to the property name. |
|
| 397 | + // If we got an array with just one value, we return that one value. |
|
| 398 | + // If we got a Wordlift_Property_Entity_Reference we get the URL. |
|
| 399 | + $jsonld[ $name ] = self::make_one( array_map( function ( $item ) use ( $converter, &$references, &$references_infos ) { |
|
| 400 | + |
|
| 401 | + if ( $item instanceof Wordlift_Property_Entity_Reference ) { |
|
| 402 | + |
|
| 403 | + $url = $item->get_url(); |
|
| 404 | + |
|
| 405 | + // The refactored converters require the entity id. |
|
| 406 | + $references[] = $item->get_id(); |
|
| 407 | + |
|
| 408 | + $references_infos[] = array( 'reference' => $item ); |
|
| 409 | + |
|
| 410 | + return array( |
|
| 411 | + '@id' => $url, |
|
| 412 | + ); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + return $converter->relative_to_context( $item ); |
|
| 416 | + }, $value ) ); |
|
| 417 | + |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + } |
|
| 421 | 421 | |
| 422 | 422 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @since 3.10.0 |
| 74 | 74 | * |
| 75 | 75 | */ |
| 76 | - public function __construct( $entity_type_service, $user_service, $attachment_service, $property_getter ) { |
|
| 76 | + public function __construct($entity_type_service, $user_service, $attachment_service, $property_getter) { |
|
| 77 | 77 | $this->entity_type_service = $entity_type_service; |
| 78 | 78 | $this->user_service = $user_service; |
| 79 | 79 | $this->attachment_service = $attachment_service; |
@@ -91,19 +91,19 @@ discard block |
||
| 91 | 91 | * @return array A JSON-LD array. |
| 92 | 92 | * @since 3.10.0 |
| 93 | 93 | */ |
| 94 | - public function convert( $post_id, &$references = array(), &$references_infos = array() ) { |
|
| 94 | + public function convert($post_id, &$references = array(), &$references_infos = array()) { |
|
| 95 | 95 | |
| 96 | 96 | // Get the post instance. |
| 97 | - $post = get_post( $post_id ); |
|
| 98 | - if ( null === $post ) { |
|
| 97 | + $post = get_post($post_id); |
|
| 98 | + if (null === $post) { |
|
| 99 | 99 | // Post not found. |
| 100 | 100 | return null; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | // Get the post URI @id. |
| 104 | - $id = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID ); |
|
| 105 | - if ( is_null( $id ) ) { |
|
| 106 | - $id = 'get_uri returned null, dataset is ' . wl_configuration_get_redlink_dataset_uri(); |
|
| 104 | + $id = Wordlift_Entity_Service::get_instance()->get_uri($post->ID); |
|
| 105 | + if (is_null($id)) { |
|
| 106 | + $id = 'get_uri returned null, dataset is '.wl_configuration_get_redlink_dataset_uri(); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /* |
@@ -115,15 +115,15 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | // // Get the entity @type. We consider `post` BlogPostings. |
| 117 | 117 | // $type = $this->entity_type_service->get( $post_id ); |
| 118 | - $types = $this->entity_type_service->get_names( $post_id ); |
|
| 119 | - $type = self::make_one( $types ); |
|
| 118 | + $types = $this->entity_type_service->get_names($post_id); |
|
| 119 | + $type = self::make_one($types); |
|
| 120 | 120 | |
| 121 | 121 | // Prepare the response. |
| 122 | 122 | $jsonld = array( |
| 123 | 123 | '@context' => self::CONTEXT, |
| 124 | 124 | '@id' => $id, |
| 125 | 125 | '@type' => $type, |
| 126 | - 'description' => Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post ), |
|
| 126 | + 'description' => Wordlift_Post_Excerpt_Helper::get_text_excerpt($post), |
|
| 127 | 127 | ); |
| 128 | 128 | |
| 129 | 129 | // Set the `mainEntityOfPage` property if the post has some contents. |
@@ -133,8 +133,8 @@ discard block |
||
| 133 | 133 | * |
| 134 | 134 | * @since 3.20.0 |
| 135 | 135 | */ |
| 136 | - $post_content = apply_filters( 'wl_post_content', $post->post_content, $post ); |
|
| 137 | - if ( ! empty( $post_content ) ) { |
|
| 136 | + $post_content = apply_filters('wl_post_content', $post->post_content, $post); |
|
| 137 | + if ( ! empty($post_content)) { |
|
| 138 | 138 | // We're setting the `mainEntityOfPage` to signal which one is the |
| 139 | 139 | // main entity for the specified URL. It might be however that the |
| 140 | 140 | // post/page is actually about another specific entity. How WL deals |
@@ -145,28 +145,28 @@ discard block |
||
| 145 | 145 | // No need to specify `'@type' => 'WebPage'. |
| 146 | 146 | // |
| 147 | 147 | // See https://github.com/insideout10/wordlift-plugin/issues/451. |
| 148 | - $jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID ); |
|
| 148 | + $jsonld['mainEntityOfPage'] = get_the_permalink($post->ID); |
|
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * @see https://github.com/insideout10/wordlift-plugin/issues/1207 |
| 152 | 152 | * |
| 153 | 153 | * @since 3.27.7 |
| 154 | 154 | */ |
| 155 | - if ( in_array( $type, array( 'Occupation', 'OccupationAggregationByEmployer' ) ) ) { |
|
| 155 | + if (in_array($type, array('Occupation', 'OccupationAggregationByEmployer'))) { |
|
| 156 | 156 | $jsonld['mainEntityOfPage'] = array( |
| 157 | 157 | '@type' => 'WebPage', |
| 158 | - 'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ) |
|
| 158 | + 'lastReviewed' => get_post_time('Y-m-d\TH:i:sP', true, $post, false) |
|
| 159 | 159 | ); |
| 160 | 160 | } |
| 161 | 161 | }; |
| 162 | 162 | |
| 163 | - $this->set_images( $this->attachment_service, $post, $jsonld ); |
|
| 163 | + $this->set_images($this->attachment_service, $post, $jsonld); |
|
| 164 | 164 | |
| 165 | 165 | // Get the entities referenced by this post and set it to the `references` |
| 166 | 166 | // array so that the caller can do further processing, such as printing out |
| 167 | 167 | // more of those references. |
| 168 | 168 | $references_without_locations = Object_Relation_Service::get_instance() |
| 169 | - ->get_references( $post_id, Object_Type_Enum::POST ); |
|
| 169 | + ->get_references($post_id, Object_Type_Enum::POST); |
|
| 170 | 170 | |
| 171 | 171 | /* |
| 172 | 172 | * Add the locations to the references. |
@@ -177,27 +177,27 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | // A reference to use in closure. |
| 179 | 179 | $entity_type_service = $this->entity_type_service; |
| 180 | - $locations = array_reduce( $references_without_locations, function ( $carry, $reference ) use ( $entity_type_service ) { |
|
| 180 | + $locations = array_reduce($references_without_locations, function($carry, $reference) use ($entity_type_service) { |
|
| 181 | 181 | /** |
| 182 | 182 | * @var $reference Reference |
| 183 | 183 | */ |
| 184 | 184 | // @see https://schema.org/location for the schema.org types using the `location` property. |
| 185 | - if ( ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Action' ) |
|
| 186 | - && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Event' ) |
|
| 187 | - && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Organization' ) ) { |
|
| 185 | + if ( ! $entity_type_service->has_entity_type($reference->get_id(), 'http://schema.org/Action') |
|
| 186 | + && ! $entity_type_service->has_entity_type($reference->get_id(), 'http://schema.org/Event') |
|
| 187 | + && ! $entity_type_service->has_entity_type($reference->get_id(), 'http://schema.org/Organization')) { |
|
| 188 | 188 | |
| 189 | 189 | return $carry; |
| 190 | 190 | } |
| 191 | - $post_location_ids = get_post_meta( $reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION ); |
|
| 192 | - $post_location_references = array_map( function ( $post_id ) { |
|
| 193 | - return new Post_Reference( $post_id ); |
|
| 194 | - }, $post_location_ids ); |
|
| 191 | + $post_location_ids = get_post_meta($reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION); |
|
| 192 | + $post_location_references = array_map(function($post_id) { |
|
| 193 | + return new Post_Reference($post_id); |
|
| 194 | + }, $post_location_ids); |
|
| 195 | 195 | |
| 196 | - return array_merge( $carry, $post_location_references ); |
|
| 197 | - }, array() ); |
|
| 196 | + return array_merge($carry, $post_location_references); |
|
| 197 | + }, array()); |
|
| 198 | 198 | |
| 199 | 199 | // Merge the references with the referenced locations if any. |
| 200 | - $references = array_merge( $references_without_locations, $locations ); |
|
| 200 | + $references = array_merge($references_without_locations, $locations); |
|
| 201 | 201 | |
| 202 | 202 | return $jsonld; |
| 203 | 203 | } |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | * @since 3.10.0 |
| 213 | 213 | * |
| 214 | 214 | */ |
| 215 | - public function relative_to_context( $value ) { |
|
| 215 | + public function relative_to_context($value) { |
|
| 216 | 216 | |
| 217 | - return 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value; |
|
| 217 | + return 0 === strpos($value, self::CONTEXT.'/') ? substr($value, strlen(self::CONTEXT) + 1) : $value; |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -229,14 +229,14 @@ discard block |
||
| 229 | 229 | * |
| 230 | 230 | * @since 3.10.0 |
| 231 | 231 | */ |
| 232 | - public static function set_images( $attachment_service, $post, &$jsonld ) { |
|
| 232 | + public static function set_images($attachment_service, $post, &$jsonld) { |
|
| 233 | 233 | |
| 234 | 234 | // Prepare the attachment ids array. |
| 235 | 235 | $ids = array(); |
| 236 | 236 | |
| 237 | 237 | // Set the thumbnail id as first attachment id, if any. |
| 238 | - $thumbnail_id = get_post_thumbnail_id( $post->ID ); |
|
| 239 | - if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) { |
|
| 238 | + $thumbnail_id = get_post_thumbnail_id($post->ID); |
|
| 239 | + if ('' !== $thumbnail_id && 0 !== $thumbnail_id) { |
|
| 240 | 240 | $ids[] = $thumbnail_id; |
| 241 | 241 | } |
| 242 | 242 | |
@@ -246,31 +246,31 @@ discard block |
||
| 246 | 246 | // See https://github.com/insideout10/wordlift-plugin/issues/689. |
| 247 | 247 | // |
| 248 | 248 | // Get the embeds, removing existing ids. |
| 249 | - if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) { |
|
| 250 | - $embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids ); |
|
| 249 | + if (apply_filters('wl_feature__enable__image-embeds', false)) { |
|
| 250 | + $embeds = array_diff($attachment_service->get_image_embeds($post->post_content), $ids); |
|
| 251 | 251 | } else { |
| 252 | 252 | $embeds = array(); |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | // Get the gallery, removing existing ids. |
| 256 | - $gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds ); |
|
| 256 | + $gallery = array_diff($attachment_service->get_gallery($post), $ids, $embeds); |
|
| 257 | 257 | |
| 258 | 258 | // Map the attachment ids to images' data structured for schema.org use. |
| 259 | 259 | $images_with_sizes = array_filter( |
| 260 | - array_reduce( array_merge( $ids, $embeds, $gallery ), |
|
| 261 | - function ( $carry, $item ) { |
|
| 260 | + array_reduce(array_merge($ids, $embeds, $gallery), |
|
| 261 | + function($carry, $item) { |
|
| 262 | 262 | /* |
| 263 | 263 | * @todo: we're not sure that we're getting attachment data here, we |
| 264 | 264 | * should filter `false`s. |
| 265 | 265 | */ |
| 266 | 266 | |
| 267 | 267 | $sources = array_merge( |
| 268 | - Wordlift_Image_Service::get_sources( $item ), |
|
| 269 | - array( wp_get_attachment_image_src( $item, 'full' ) ) |
|
| 268 | + Wordlift_Image_Service::get_sources($item), |
|
| 269 | + array(wp_get_attachment_image_src($item, 'full')) |
|
| 270 | 270 | ); |
| 271 | 271 | |
| 272 | - $sources_with_image = array_filter( $sources, function ( $source ) { |
|
| 273 | - return ! empty( $source[0] ); |
|
| 272 | + $sources_with_image = array_filter($sources, function($source) { |
|
| 273 | + return ! empty($source[0]); |
|
| 274 | 274 | } ); |
| 275 | 275 | |
| 276 | 276 | // Get the attachment data. |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | // or from uploads dir, but the image id still exists as featured image |
| 284 | 284 | // or in [gallery] shortcode. |
| 285 | 285 | // if ( empty( $attachment[0] ) ) { |
| 286 | - if ( empty( $sources_with_image ) ) { |
|
| 286 | + if (empty($sources_with_image)) { |
|
| 287 | 287 | return $carry; |
| 288 | 288 | } |
| 289 | 289 | |
@@ -294,21 +294,21 @@ discard block |
||
| 294 | 294 | ); |
| 295 | 295 | } |
| 296 | 296 | // Initial array. |
| 297 | - , array() ) |
|
| 297 | + , array()) |
|
| 298 | 298 | ); |
| 299 | 299 | |
| 300 | 300 | // Refactor data as per schema.org specifications. |
| 301 | - $images = array_map( function ( $attachment ) { |
|
| 301 | + $images = array_map(function($attachment) { |
|
| 302 | 302 | return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size( |
| 303 | 303 | array( |
| 304 | 304 | '@type' => 'ImageObject', |
| 305 | 305 | 'url' => $attachment[0], |
| 306 | 306 | ), $attachment |
| 307 | 307 | ); |
| 308 | - }, $images_with_sizes ); |
|
| 308 | + }, $images_with_sizes); |
|
| 309 | 309 | |
| 310 | 310 | // Add images if present. |
| 311 | - if ( 0 < count( $images ) ) { |
|
| 311 | + if (0 < count($images)) { |
|
| 312 | 312 | $jsonld['image'] = $images; |
| 313 | 313 | } |
| 314 | 314 | |
@@ -327,9 +327,9 @@ discard block |
||
| 327 | 327 | * @access private |
| 328 | 328 | * |
| 329 | 329 | */ |
| 330 | - protected static function make_one( $value ) { |
|
| 330 | + protected static function make_one($value) { |
|
| 331 | 331 | |
| 332 | - return 1 === count( $value ) ? $value[0] : $value; |
|
| 332 | + return 1 === count($value) ? $value[0] : $value; |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -343,17 +343,17 @@ discard block |
||
| 343 | 343 | * @since 3.14.0 |
| 344 | 344 | * |
| 345 | 345 | */ |
| 346 | - public static function set_image_size( $image, $attachment ) { |
|
| 346 | + public static function set_image_size($image, $attachment) { |
|
| 347 | 347 | |
| 348 | 348 | // If you specify a "width" or "height" value you should leave out |
| 349 | 349 | // 'px'. For example: "width":"4608px" should be "width":"4608". |
| 350 | 350 | // |
| 351 | 351 | // See https://github.com/insideout10/wordlift-plugin/issues/451. |
| 352 | - if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) { |
|
| 352 | + if (isset($attachment[1]) && is_numeric($attachment[1]) && 0 < $attachment[1]) { |
|
| 353 | 353 | $image['width'] = $attachment[1]; |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | - if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) { |
|
| 356 | + if (isset($attachment[2]) && is_numeric($attachment[2]) && 0 < $attachment[2]) { |
|
| 357 | 357 | $image['height'] = $attachment[2]; |
| 358 | 358 | } |
| 359 | 359 | |
@@ -374,46 +374,46 @@ discard block |
||
| 374 | 374 | * the {@link Wordlift_Schema_Service} class. |
| 375 | 375 | * |
| 376 | 376 | */ |
| 377 | - protected function process_type_custom_fields( &$jsonld, $fields, $post, &$references, &$references_infos ) { |
|
| 377 | + protected function process_type_custom_fields(&$jsonld, $fields, $post, &$references, &$references_infos) { |
|
| 378 | 378 | |
| 379 | 379 | // Set a reference to use in closures. |
| 380 | 380 | $converter = $this; |
| 381 | 381 | |
| 382 | 382 | // Try each field on the entity. |
| 383 | - foreach ( $fields as $key => $value ) { |
|
| 383 | + foreach ($fields as $key => $value) { |
|
| 384 | 384 | |
| 385 | 385 | // Get the predicate. |
| 386 | - $name = $this->relative_to_context( $value['predicate'] ); |
|
| 386 | + $name = $this->relative_to_context($value['predicate']); |
|
| 387 | 387 | |
| 388 | 388 | // Get the value, the property service will get the right extractor |
| 389 | 389 | // for that property. |
| 390 | - $value = $this->property_getter->get( $post->ID, $key, Object_Type_Enum::POST ); |
|
| 390 | + $value = $this->property_getter->get($post->ID, $key, Object_Type_Enum::POST); |
|
| 391 | 391 | |
| 392 | - if ( empty( $value ) ) { |
|
| 392 | + if (empty($value)) { |
|
| 393 | 393 | continue; |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | // Map the value to the property name. |
| 397 | 397 | // If we got an array with just one value, we return that one value. |
| 398 | 398 | // If we got a Wordlift_Property_Entity_Reference we get the URL. |
| 399 | - $jsonld[ $name ] = self::make_one( array_map( function ( $item ) use ( $converter, &$references, &$references_infos ) { |
|
| 399 | + $jsonld[$name] = self::make_one(array_map(function($item) use ($converter, &$references, &$references_infos) { |
|
| 400 | 400 | |
| 401 | - if ( $item instanceof Wordlift_Property_Entity_Reference ) { |
|
| 401 | + if ($item instanceof Wordlift_Property_Entity_Reference) { |
|
| 402 | 402 | |
| 403 | 403 | $url = $item->get_url(); |
| 404 | 404 | |
| 405 | 405 | // The refactored converters require the entity id. |
| 406 | 406 | $references[] = $item->get_id(); |
| 407 | 407 | |
| 408 | - $references_infos[] = array( 'reference' => $item ); |
|
| 408 | + $references_infos[] = array('reference' => $item); |
|
| 409 | 409 | |
| 410 | 410 | return array( |
| 411 | 411 | '@id' => $url, |
| 412 | 412 | ); |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - return $converter->relative_to_context( $item ); |
|
| 416 | - }, $value ) ); |
|
| 415 | + return $converter->relative_to_context($item); |
|
| 416 | + }, $value)); |
|
| 417 | 417 | |
| 418 | 418 | } |
| 419 | 419 | |