Completed
Push — master ( 2a63eb...2c5109 )
by David
53s
created
src/admin/wordlift_admin_ajax_related_posts.php 2 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -19,66 +19,66 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -17,34 +17,34 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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');
Please login to merge, or discard this patch.