@@ -16,57 +16,57 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | function wordlift_ajax_related_posts( $http_raw_data = null ) { |
| 18 | 18 | |
| 19 | - // Extract filtering conditions |
|
| 20 | - if ( ! isset( $_GET["post_id"] ) || ! is_numeric( $_GET["post_id"] ) ) { |
|
| 21 | - wp_die( 'Post id missing or invalid!' ); |
|
| 19 | + // Extract filtering conditions |
|
| 20 | + if ( ! isset( $_GET["post_id"] ) || ! is_numeric( $_GET["post_id"] ) ) { |
|
| 21 | + wp_die( 'Post id missing or invalid!' ); |
|
| 22 | 22 | |
| 23 | - return; |
|
| 24 | - } |
|
| 23 | + return; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - // Get the current post |
|
| 27 | - $post_id = $_GET["post_id"]; |
|
| 28 | - $post = get_post( $post_id ); |
|
| 26 | + // Get the current post |
|
| 27 | + $post_id = $_GET["post_id"]; |
|
| 28 | + $post = get_post( $post_id ); |
|
| 29 | 29 | |
| 30 | - Wordlift_Log_Service::get_logger( 'wordlift_ajax_related_posts' )->trace( "Going to find posts related to current with post id: $post_id ..." ); |
|
| 30 | + Wordlift_Log_Service::get_logger( 'wordlift_ajax_related_posts' )->trace( "Going to find posts related to current with post id: $post_id ..." ); |
|
| 31 | 31 | |
| 32 | - // Extract filtering conditions |
|
| 33 | - $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data; |
|
| 34 | - $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
| 32 | + // Extract filtering conditions |
|
| 33 | + $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data; |
|
| 34 | + $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
| 35 | 35 | |
| 36 | - $filtering_entity_ids = wl_get_entity_post_ids_by_uris( $filtering_entity_uris ); |
|
| 37 | - $related_posts = array(); |
|
| 36 | + $filtering_entity_ids = wl_get_entity_post_ids_by_uris( $filtering_entity_uris ); |
|
| 37 | + $related_posts = array(); |
|
| 38 | 38 | |
| 39 | - // If the current post is an entity, related posts to the current entity are |
|
| 40 | - // returned. |
|
| 41 | - $entity_service = Wordlift_Entity_Service::get_instance(); |
|
| 39 | + // If the current post is an entity, related posts to the current entity are |
|
| 40 | + // returned. |
|
| 41 | + $entity_service = Wordlift_Entity_Service::get_instance(); |
|
| 42 | 42 | |
| 43 | - if ( $entity_service->is_entity( $post->ID ) ) { |
|
| 44 | - $filtering_entity_ids = array( $post_id ); |
|
| 45 | - } |
|
| 43 | + if ( $entity_service->is_entity( $post->ID ) ) { |
|
| 44 | + $filtering_entity_ids = array( $post_id ); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - if ( ! empty( $filtering_entity_ids ) ) { |
|
| 47 | + if ( ! empty( $filtering_entity_ids ) ) { |
|
| 48 | 48 | |
| 49 | - $related_posts = Wordlift_Relation_Service::get_instance() |
|
| 50 | - ->get_article_subjects( $filtering_entity_ids, '*', null, 'publish', array( $post_id ), 5 ); |
|
| 49 | + $related_posts = Wordlift_Relation_Service::get_instance() |
|
| 50 | + ->get_article_subjects( $filtering_entity_ids, '*', null, 'publish', array( $post_id ), 5 ); |
|
| 51 | 51 | |
| 52 | - foreach ( $related_posts as $post_obj ) { |
|
| 52 | + foreach ( $related_posts as $post_obj ) { |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Use the thumbnail. |
|
| 56 | - * |
|
| 57 | - * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue. |
|
| 58 | - * @see https://github.com/insideout10/wordlift-plugin/issues/837 |
|
| 59 | - * |
|
| 60 | - * @since 3.19.3 We're using the medium size image. |
|
| 61 | - */ |
|
| 62 | - $thumbnail = get_the_post_thumbnail_url( $post_obj, 'medium' ); |
|
| 63 | - $post_obj->thumbnail = ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 64 | - $post_obj->link = get_edit_post_link( $post_obj->ID, 'none' ); |
|
| 65 | - $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
| 66 | - } |
|
| 67 | - } |
|
| 54 | + /** |
|
| 55 | + * Use the thumbnail. |
|
| 56 | + * |
|
| 57 | + * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue. |
|
| 58 | + * @see https://github.com/insideout10/wordlift-plugin/issues/837 |
|
| 59 | + * |
|
| 60 | + * @since 3.19.3 We're using the medium size image. |
|
| 61 | + */ |
|
| 62 | + $thumbnail = get_the_post_thumbnail_url( $post_obj, 'medium' ); |
|
| 63 | + $post_obj->thumbnail = ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 64 | + $post_obj->link = get_edit_post_link( $post_obj->ID, 'none' ); |
|
| 65 | + $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - wl_core_send_json( $related_posts ); |
|
| 69 | + wl_core_send_json( $related_posts ); |
|
| 70 | 70 | |
| 71 | 71 | } |
| 72 | 72 | |
@@ -14,42 +14,42 @@ discard block |
||
| 14 | 14 | * |
| 15 | 15 | * @param null $http_raw_data |
| 16 | 16 | */ |
| 17 | -function wordlift_ajax_related_posts( $http_raw_data = null ) { |
|
| 17 | +function wordlift_ajax_related_posts($http_raw_data = null) { |
|
| 18 | 18 | |
| 19 | 19 | // Extract filtering conditions |
| 20 | - if ( ! isset( $_GET["post_id"] ) || ! is_numeric( $_GET["post_id"] ) ) { |
|
| 21 | - wp_die( 'Post id missing or invalid!' ); |
|
| 20 | + if ( ! isset($_GET["post_id"]) || ! is_numeric($_GET["post_id"])) { |
|
| 21 | + wp_die('Post id missing or invalid!'); |
|
| 22 | 22 | |
| 23 | 23 | return; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // Get the current post |
| 27 | 27 | $post_id = $_GET["post_id"]; |
| 28 | - $post = get_post( $post_id ); |
|
| 28 | + $post = get_post($post_id); |
|
| 29 | 29 | |
| 30 | - Wordlift_Log_Service::get_logger( 'wordlift_ajax_related_posts' )->trace( "Going to find posts related to current with post id: $post_id ..." ); |
|
| 30 | + Wordlift_Log_Service::get_logger('wordlift_ajax_related_posts')->trace("Going to find posts related to current with post id: $post_id ..."); |
|
| 31 | 31 | |
| 32 | 32 | // Extract filtering conditions |
| 33 | - $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data; |
|
| 34 | - $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
| 33 | + $filtering_entity_uris = (null == $http_raw_data) ? file_get_contents("php://input") : $http_raw_data; |
|
| 34 | + $filtering_entity_uris = json_decode($filtering_entity_uris); |
|
| 35 | 35 | |
| 36 | - $filtering_entity_ids = wl_get_entity_post_ids_by_uris( $filtering_entity_uris ); |
|
| 36 | + $filtering_entity_ids = wl_get_entity_post_ids_by_uris($filtering_entity_uris); |
|
| 37 | 37 | $related_posts = array(); |
| 38 | 38 | |
| 39 | 39 | // If the current post is an entity, related posts to the current entity are |
| 40 | 40 | // returned. |
| 41 | 41 | $entity_service = Wordlift_Entity_Service::get_instance(); |
| 42 | 42 | |
| 43 | - if ( $entity_service->is_entity( $post->ID ) ) { |
|
| 44 | - $filtering_entity_ids = array( $post_id ); |
|
| 43 | + if ($entity_service->is_entity($post->ID)) { |
|
| 44 | + $filtering_entity_ids = array($post_id); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - if ( ! empty( $filtering_entity_ids ) ) { |
|
| 47 | + if ( ! empty($filtering_entity_ids)) { |
|
| 48 | 48 | |
| 49 | 49 | $related_posts = Wordlift_Relation_Service::get_instance() |
| 50 | - ->get_article_subjects( $filtering_entity_ids, '*', null, 'publish', array( $post_id ), 5 ); |
|
| 50 | + ->get_article_subjects($filtering_entity_ids, '*', null, 'publish', array($post_id), 5); |
|
| 51 | 51 | |
| 52 | - foreach ( $related_posts as $post_obj ) { |
|
| 52 | + foreach ($related_posts as $post_obj) { |
|
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * Use the thumbnail. |
@@ -59,15 +59,15 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | * @since 3.19.3 We're using the medium size image. |
| 61 | 61 | */ |
| 62 | - $thumbnail = get_the_post_thumbnail_url( $post_obj, 'medium' ); |
|
| 63 | - $post_obj->thumbnail = ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 64 | - $post_obj->link = get_edit_post_link( $post_obj->ID, 'none' ); |
|
| 65 | - $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
| 62 | + $thumbnail = get_the_post_thumbnail_url($post_obj, 'medium'); |
|
| 63 | + $post_obj->thumbnail = ($thumbnail) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 64 | + $post_obj->link = get_edit_post_link($post_obj->ID, 'none'); |
|
| 65 | + $post_obj->permalink = get_post_permalink($post_obj->ID); |
|
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - wl_core_send_json( $related_posts ); |
|
| 69 | + wl_core_send_json($related_posts); |
|
| 70 | 70 | |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | -add_action( 'wp_ajax_wordlift_related_posts', 'wordlift_ajax_related_posts' ); |
|
| 73 | +add_action('wp_ajax_wordlift_related_posts', 'wordlift_ajax_related_posts'); |
|