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