Completed
Pull Request — master (#1641)
by Naveen
01:35
created
src/wordlift/widgets/navigator/class-navigator-data.php 2 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -8,54 +8,54 @@  discard block
 block discarded – undo
8 8
  */
9 9
 class Navigator_Data {
10 10
 
11
-	public static function get_post_types_as_string( $post_types ) {
12
-		if ( array() === $post_types ) {
13
-			$post_types = get_post_types();
14
-		}
15
-		$post_types = array_map(
16
-			function ( $post_type ) {
17
-				return "'" . esc_sql( $post_type ) . "'";
18
-			},
19
-			$post_types
20
-		);
11
+    public static function get_post_types_as_string( $post_types ) {
12
+        if ( array() === $post_types ) {
13
+            $post_types = get_post_types();
14
+        }
15
+        $post_types = array_map(
16
+            function ( $post_type ) {
17
+                return "'" . esc_sql( $post_type ) . "'";
18
+            },
19
+            $post_types
20
+        );
21 21
 
22
-		return implode( ',', $post_types );
23
-	}
22
+        return implode( ',', $post_types );
23
+    }
24 24
 
25
-	public static function post_navigator_get_results(
26
-		$post_id, $fields = array(
27
-			'ID',
28
-			'post_title',
29
-		), $order_by = 'ID DESC', $limit = 10, $offset = 0, $post_types = array()
30
-	) {
25
+    public static function post_navigator_get_results(
26
+        $post_id, $fields = array(
27
+            'ID',
28
+            'post_title',
29
+        ), $order_by = 'ID DESC', $limit = 10, $offset = 0, $post_types = array()
30
+    ) {
31 31
 
32
-		$post_types = self::get_post_types_as_string( $post_types );
33
-		global $wpdb;
32
+        $post_types = self::get_post_types_as_string( $post_types );
33
+        global $wpdb;
34 34
 
35
-		$select = implode(
36
-			', ',
37
-			array_map(
38
-				function ( $item ) {
39
-					return "p.$item AS $item";
40
-				},
41
-				(array) $fields
42
-			)
43
-		);
35
+        $select = implode(
36
+            ', ',
37
+            array_map(
38
+                function ( $item ) {
39
+                    return "p.$item AS $item";
40
+                },
41
+                (array) $fields
42
+            )
43
+        );
44 44
 
45
-		$order_by = implode(
46
-			', ',
47
-			array_map(
48
-				function ( $item ) {
49
-					return "p.$item";
50
-				},
51
-				(array) $order_by
52
-			)
53
-		);
45
+        $order_by = implode(
46
+            ', ',
47
+            array_map(
48
+                function ( $item ) {
49
+                    return "p.$item";
50
+                },
51
+                (array) $order_by
52
+            )
53
+        );
54 54
 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder
55
-		/** @noinspection SqlNoDataSourceInspection */
56
-		return $wpdb->get_results(
57
-			$wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
58
-				"
55
+        /** @noinspection SqlNoDataSourceInspection */
56
+        return $wpdb->get_results(
57
+            $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
58
+                "
59 59
 SELECT %4\$s, p2.ID as entity_id
60 60
  FROM {$wpdb->prefix}wl_relation_instances r1
61 61
     INNER JOIN {$wpdb->prefix}wl_relation_instances r2
@@ -89,50 +89,50 @@  discard block
 block discarded – undo
89 89
  LIMIT %2\$d
90 90
  OFFSET %3\$d
91 91
 ",
92
-				$post_id,
93
-				$limit,
94
-				$offset,
95
-				$select,
96
-				$order_by
97
-			)
98
-		);
92
+                $post_id,
93
+                $limit,
94
+                $offset,
95
+                $select,
96
+                $order_by
97
+            )
98
+        );
99 99
 // phpcs:enable
100
-	}
100
+    }
101 101
 
102
-	public static function entity_navigator_get_results(
103
-		$post_id, $fields = array(
104
-			'ID',
105
-			'post_title',
106
-		), $order_by = 'ID DESC', $limit = 10, $offset = 0, $post_types = array()
107
-	) {
108
-		global $wpdb;
102
+    public static function entity_navigator_get_results(
103
+        $post_id, $fields = array(
104
+            'ID',
105
+            'post_title',
106
+        ), $order_by = 'ID DESC', $limit = 10, $offset = 0, $post_types = array()
107
+    ) {
108
+        global $wpdb;
109 109
 
110
-		$select = implode(
111
-			', ',
112
-			array_map(
113
-				function ( $item ) {
114
-					return "p.$item AS $item";
115
-				},
116
-				(array) $fields
117
-			)
118
-		);
110
+        $select = implode(
111
+            ', ',
112
+            array_map(
113
+                function ( $item ) {
114
+                    return "p.$item AS $item";
115
+                },
116
+                (array) $fields
117
+            )
118
+        );
119 119
 
120
-		$order_by = implode(
121
-			', ',
122
-			array_map(
123
-				function ( $item ) {
124
-					return "p.$item";
125
-				},
126
-				(array) $order_by
127
-			)
128
-		);
120
+        $order_by = implode(
121
+            ', ',
122
+            array_map(
123
+                function ( $item ) {
124
+                    return "p.$item";
125
+                },
126
+                (array) $order_by
127
+            )
128
+        );
129 129
 
130
-		$post_types = self::get_post_types_as_string( $post_types );
130
+        $post_types = self::get_post_types_as_string( $post_types );
131 131
 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder
132
-		/** @noinspection SqlNoDataSourceInspection */
133
-		return $wpdb->get_results(
134
-			$wpdb->prepare(
135
-				"
132
+        /** @noinspection SqlNoDataSourceInspection */
133
+        return $wpdb->get_results(
134
+            $wpdb->prepare(
135
+                "
136 136
 SELECT %4\$s, p2.ID as entity_id
137 137
  FROM {$wpdb->prefix}wl_relation_instances r1
138 138
 	-- get the ID of the post entity in common between the object and the subject 2. 
@@ -163,14 +163,14 @@  discard block
 block discarded – undo
163 163
  LIMIT %2\$d
164 164
  OFFSET %3\$d
165 165
 ",
166
-				$post_id,
167
-				$limit,
168
-				$offset,
169
-				$select,
170
-				$order_by
171
-			)
172
-		);
173
-	}
166
+                $post_id,
167
+                $limit,
168
+                $offset,
169
+                $select,
170
+                $order_by
171
+            )
172
+        );
173
+    }
174 174
 // phpcs:enable
175 175
 }
176 176
 
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -8,18 +8,18 @@  discard block
 block discarded – undo
8 8
  */
9 9
 class Navigator_Data {
10 10
 
11
-	public static function get_post_types_as_string( $post_types ) {
12
-		if ( array() === $post_types ) {
11
+	public static function get_post_types_as_string($post_types) {
12
+		if (array() === $post_types) {
13 13
 			$post_types = get_post_types();
14 14
 		}
15 15
 		$post_types = array_map(
16
-			function ( $post_type ) {
17
-				return "'" . esc_sql( $post_type ) . "'";
16
+			function($post_type) {
17
+				return "'".esc_sql($post_type)."'";
18 18
 			},
19 19
 			$post_types
20 20
 		);
21 21
 
22
-		return implode( ',', $post_types );
22
+		return implode(',', $post_types);
23 23
 	}
24 24
 
25 25
 	public static function post_navigator_get_results(
@@ -29,13 +29,13 @@  discard block
 block discarded – undo
29 29
 		), $order_by = 'ID DESC', $limit = 10, $offset = 0, $post_types = array()
30 30
 	) {
31 31
 
32
-		$post_types = self::get_post_types_as_string( $post_types );
32
+		$post_types = self::get_post_types_as_string($post_types);
33 33
 		global $wpdb;
34 34
 
35 35
 		$select = implode(
36 36
 			', ',
37 37
 			array_map(
38
-				function ( $item ) {
38
+				function($item) {
39 39
 					return "p.$item AS $item";
40 40
 				},
41 41
 				(array) $fields
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 		$order_by = implode(
46 46
 			', ',
47 47
 			array_map(
48
-				function ( $item ) {
48
+				function($item) {
49 49
 					return "p.$item";
50 50
 				},
51 51
 				(array) $order_by
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 		$select = implode(
111 111
 			', ',
112 112
 			array_map(
113
-				function ( $item ) {
113
+				function($item) {
114 114
 					return "p.$item AS $item";
115 115
 				},
116 116
 				(array) $fields
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
 		$order_by = implode(
121 121
 			', ',
122 122
 			array_map(
123
-				function ( $item ) {
123
+				function($item) {
124 124
 					return "p.$item";
125 125
 				},
126 126
 				(array) $order_by
127 127
 			)
128 128
 		);
129 129
 
130
-		$post_types = self::get_post_types_as_string( $post_types );
130
+		$post_types = self::get_post_types_as_string($post_types);
131 131
 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder
132 132
 		/** @noinspection SqlNoDataSourceInspection */
133 133
 		return $wpdb->get_results(
Please login to merge, or discard this patch.
widgets/navigator/filler-posts/class-same-category-filler-posts.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -16,17 +16,17 @@
 block discarded – undo
16 16
  */
17 17
 class Same_Category_Filler_Posts extends Filler_Posts {
18 18
 
19
-	public function get_posts( $filler_count, $post_ids_to_be_excluded ) {
19
+    public function get_posts( $filler_count, $post_ids_to_be_excluded ) {
20 20
 
21
-		$current_post_categories = wp_get_post_categories( $this->post_id );
22
-		$post_type               = $this->alternate_post_type ? $this->alternate_post_type : get_post_types();
21
+        $current_post_categories = wp_get_post_categories( $this->post_id );
22
+        $post_type               = $this->alternate_post_type ? $this->alternate_post_type : get_post_types();
23 23
 
24
-		return get_posts(
25
-			array(
26
-				'category__in' => $current_post_categories,
27
-				'post_type'    => $post_type,
28
-			)
29
-						  + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded )
30
-		);
31
-	}
24
+        return get_posts(
25
+            array(
26
+                'category__in' => $current_post_categories,
27
+                'post_type'    => $post_type,
28
+            )
29
+                          + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded )
30
+        );
31
+    }
32 32
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class Same_Category_Filler_Posts extends Filler_Posts {
18 18
 
19
-	public function get_posts( $filler_count, $post_ids_to_be_excluded ) {
19
+	public function get_posts($filler_count, $post_ids_to_be_excluded) {
20 20
 
21
-		$current_post_categories = wp_get_post_categories( $this->post_id );
21
+		$current_post_categories = wp_get_post_categories($this->post_id);
22 22
 		$post_type               = $this->alternate_post_type ? $this->alternate_post_type : get_post_types();
23 23
 
24 24
 		return get_posts(
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 				'category__in' => $current_post_categories,
27 27
 				'post_type'    => $post_type,
28 28
 			)
29
-						  + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded )
29
+						  + $this->get_posts_config($filler_count, $post_ids_to_be_excluded)
30 30
 		);
31 31
 	}
32 32
 }
Please login to merge, or discard this patch.
widgets/navigator/filler-posts/class-same-post-type-same-category-posts.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@
 block discarded – undo
8 8
  */
9 9
 class Same_Post_Type_Same_Category_Posts extends Filler_Posts {
10 10
 
11
-	public function get_posts( $filler_count, $post_ids_to_be_excluded ) {
12
-		$current_post_categories = wp_get_post_categories( $this->post_id );
13
-		$post_type               = $this->alternate_post_type ? $this->alternate_post_type : get_post_type( $this->post_id );
11
+    public function get_posts( $filler_count, $post_ids_to_be_excluded ) {
12
+        $current_post_categories = wp_get_post_categories( $this->post_id );
13
+        $post_type               = $this->alternate_post_type ? $this->alternate_post_type : get_post_type( $this->post_id );
14 14
 
15
-		return get_posts(
16
-			array(
17
-				'category__in' => $current_post_categories,
18
-				'post_type'    => $post_type,
19
-			)
20
-						  + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded )
21
-		);
22
-	}
15
+        return get_posts(
16
+            array(
17
+                'category__in' => $current_post_categories,
18
+                'post_type'    => $post_type,
19
+            )
20
+                          + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded )
21
+        );
22
+    }
23 23
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@
 block discarded – undo
8 8
  */
9 9
 class Same_Post_Type_Same_Category_Posts extends Filler_Posts {
10 10
 
11
-	public function get_posts( $filler_count, $post_ids_to_be_excluded ) {
12
-		$current_post_categories = wp_get_post_categories( $this->post_id );
13
-		$post_type               = $this->alternate_post_type ? $this->alternate_post_type : get_post_type( $this->post_id );
11
+	public function get_posts($filler_count, $post_ids_to_be_excluded) {
12
+		$current_post_categories = wp_get_post_categories($this->post_id);
13
+		$post_type               = $this->alternate_post_type ? $this->alternate_post_type : get_post_type($this->post_id);
14 14
 
15 15
 		return get_posts(
16 16
 			array(
17 17
 				'category__in' => $current_post_categories,
18 18
 				'post_type'    => $post_type,
19 19
 			)
20
-						  + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded )
20
+						  + $this->get_posts_config($filler_count, $post_ids_to_be_excluded)
21 21
 		);
22 22
 	}
23 23
 }
Please login to merge, or discard this patch.
src/wordlift/widgets/navigator/filler-posts/class-filler-posts.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -8,54 +8,54 @@
 block discarded – undo
8 8
  */
9 9
 abstract class Filler_Posts {
10 10
 
11
-	/**
12
-	 * @var int
13
-	 */
14
-	public $filler_count;
15
-
16
-	/**
17
-	 * @var array<int>
18
-	 */
19
-	public $post_ids_to_be_excluded;
20
-
21
-	/**
22
-	 * @var $post_id int
23
-	 */
24
-	protected $post_id;
25
-
26
-	/**
27
-	 * Filler_Posts constructor.
28
-	 *
29
-	 * @param $post_id
30
-	 */
31
-	public function __construct( $post_id, $alternate_post_type = null ) {
32
-
33
-		$this->post_id             = $post_id;
34
-		$this->alternate_post_type = $alternate_post_type;
35
-
36
-	}
37
-
38
-	protected function get_posts_config( $filler_count, $post_ids_to_be_excluded ) {
39
-
40
-		return array(
41
-			'meta_query'          => array(
42
-				array(
43
-					'key' => '_thumbnail_id',
44
-				),
45
-			),
46
-			'numberposts'         => $filler_count,
47
-			'post__not_in'        => $post_ids_to_be_excluded,
48
-			'ignore_sticky_posts' => 1,
49
-		);
50
-
51
-	}
52
-
53
-	/**
54
-	 * @param $filler_count
55
-	 * @param $post_ids_to_be_excluded
56
-	 *
57
-	 * @return array<\WP_Post>
58
-	 */
59
-	abstract public function get_posts( $filler_count, $post_ids_to_be_excluded );
11
+    /**
12
+     * @var int
13
+     */
14
+    public $filler_count;
15
+
16
+    /**
17
+     * @var array<int>
18
+     */
19
+    public $post_ids_to_be_excluded;
20
+
21
+    /**
22
+     * @var $post_id int
23
+     */
24
+    protected $post_id;
25
+
26
+    /**
27
+     * Filler_Posts constructor.
28
+     *
29
+     * @param $post_id
30
+     */
31
+    public function __construct( $post_id, $alternate_post_type = null ) {
32
+
33
+        $this->post_id             = $post_id;
34
+        $this->alternate_post_type = $alternate_post_type;
35
+
36
+    }
37
+
38
+    protected function get_posts_config( $filler_count, $post_ids_to_be_excluded ) {
39
+
40
+        return array(
41
+            'meta_query'          => array(
42
+                array(
43
+                    'key' => '_thumbnail_id',
44
+                ),
45
+            ),
46
+            'numberposts'         => $filler_count,
47
+            'post__not_in'        => $post_ids_to_be_excluded,
48
+            'ignore_sticky_posts' => 1,
49
+        );
50
+
51
+    }
52
+
53
+    /**
54
+     * @param $filler_count
55
+     * @param $post_ids_to_be_excluded
56
+     *
57
+     * @return array<\WP_Post>
58
+     */
59
+    abstract public function get_posts( $filler_count, $post_ids_to_be_excluded );
60 60
 
61 61
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,14 +28,14 @@  discard block
 block discarded – undo
28 28
 	 *
29 29
 	 * @param $post_id
30 30
 	 */
31
-	public function __construct( $post_id, $alternate_post_type = null ) {
31
+	public function __construct($post_id, $alternate_post_type = null) {
32 32
 
33 33
 		$this->post_id             = $post_id;
34 34
 		$this->alternate_post_type = $alternate_post_type;
35 35
 
36 36
 	}
37 37
 
38
-	protected function get_posts_config( $filler_count, $post_ids_to_be_excluded ) {
38
+	protected function get_posts_config($filler_count, $post_ids_to_be_excluded) {
39 39
 
40 40
 		return array(
41 41
 			'meta_query'          => array(
@@ -56,6 +56,6 @@  discard block
 block discarded – undo
56 56
 	 *
57 57
 	 * @return array<\WP_Post>
58 58
 	 */
59
-	abstract public function get_posts( $filler_count, $post_ids_to_be_excluded );
59
+	abstract public function get_posts($filler_count, $post_ids_to_be_excluded);
60 60
 
61 61
 }
Please login to merge, or discard this patch.
src/wordlift/widgets/navigator/filler-posts/class-filler-posts-util.php 2 patches
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -10,161 +10,161 @@
 block discarded – undo
10 10
  */
11 11
 class Filler_Posts_Util {
12 12
 
13
-	/**
14
-	 * @var array<Filler_Posts>
15
-	 */
16
-	private $sources = array();
17
-
18
-	public function __construct( $post_id, $alternate_post_type = null ) {
19
-
20
-		$post_type = $alternate_post_type ? $alternate_post_type : get_post_type( $post_id );
21
-
22
-		if ( 'post' === $post_type || ( is_array( $post_type ) && in_array( 'post', $post_type, true ) ) ) {
23
-			$this->sources = array(
24
-				new Same_Category_Filler_Posts( $post_id ),
25
-				new Same_Post_Type_Filler_Posts( $post_id ),
26
-			);
27
-		} elseif ( 'product' === $post_type || ( is_array( $post_type ) && in_array( 'product', $post_type, true ) ) ) {
28
-			$this->sources = array(
29
-				new Same_Post_Type_Same_Category_Posts( $post_id, 'product' ),
30
-				new Same_Post_Type_Filler_Posts( $post_id, 'product' ),
31
-			);
32
-		} else {
33
-			$this->sources = array(
34
-				new Same_Post_Type_Filler_Posts( $post_id ),
35
-			);
36
-		}
37
-	}
38
-
39
-	/**
40
-	 * @param $posts array<\WP_Post>
41
-	 *
42
-	 * @return array<int>
43
-	 */
44
-	private function extract_post_ids( $posts ) {
45
-		return array_map(
46
-			function ( $post ) {
47
-				/**
48
-				 * @var $post \WP_Post
49
-				 */
50
-				return $post->ID;
51
-			},
52
-			$posts
53
-		);
54
-	}
55
-
56
-	public function get_filler_posts( $filler_count, $post_ids_to_be_excluded ) {
57
-
58
-		$filler_posts = array();
59
-
60
-		foreach ( $this->sources as $source ) {
61
-
62
-			if ( $filler_count <= 0 ) {
63
-				break;
64
-			}
65
-			/**
66
-			 * @var Filler_Posts $source
67
-			 */
68
-			$source->post_ids_to_be_excluded = $post_ids_to_be_excluded;
69
-			$source->filler_count            = $filler_count;
70
-
71
-			$posts    = $source->get_posts( $filler_count, $post_ids_to_be_excluded );
72
-			$post_ids = $this->extract_post_ids( $posts );
73
-
74
-			// Update the post ids, filler posts and filler count
75
-			$post_ids_to_be_excluded = array_merge( $post_ids_to_be_excluded, $post_ids );
76
-			$filler_count            = $filler_count - count( $posts );
77
-			$filler_posts            = array_merge( $filler_posts, $posts );
78
-		}
79
-		$filler_posts = $this->add_additional_properties_to_filler_posts( $filler_posts );
80
-
81
-		return $filler_posts;
82
-
83
-	}
84
-
85
-	/**
86
-	 * @param $posts array<\WP_Post>
87
-	 *
88
-	 * @return array $posts array<\WP_Post>
89
-	 */
90
-	private function add_additional_properties_to_filler_posts( $posts ) {
91
-		return array_map(
92
-			function ( $post ) {
93
-				$post->thumbnail  = get_the_post_thumbnail_url( $post->ID, 'medium' );
94
-				$post->permalink  = get_permalink( $post->ID );
95
-				$post->post_title = html_entity_decode( $post->post_title, ENT_QUOTES, 'UTF-8' );
96
-
97
-				return $post;
98
-			},
99
-			$posts
100
-		);
101
-	}
102
-
103
-	/**
104
-	 * Called by wordlift navigator, converts all the posts to response format.
105
-	 *
106
-	 * @param $filler_count
107
-	 * @param $post_ids_to_be_excluded
108
-	 *
109
-	 * @return array
110
-	 */
111
-	public function get_filler_response( $filler_count, $post_ids_to_be_excluded ) {
112
-		$filler_posts = $this->get_filler_posts( $filler_count, $post_ids_to_be_excluded );
113
-		// Add thumbnail and permalink to filler posts
114
-		$filler_response = array();
115
-		foreach ( $filler_posts as $post_obj ) {
116
-			$thumbnail         = get_the_post_thumbnail_url( $post_obj, 'medium' );
117
-			$filler_response[] = array(
118
-				'post'   => array(
119
-					'id'        => $post_obj->ID,
120
-					'permalink' => get_permalink( $post_obj->ID ),
121
-					'thumbnail' => ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH,
122
-					'title'     => $post_obj->post_title,
123
-					'srcset'    => Srcset_Util::get_srcset( $post_obj->ID, Srcset_Util::NAVIGATOR_WIDGET ),
124
-				),
125
-				'entity' => array(
126
-					'id' => 0,
127
-				),
128
-			);
129
-		}
130
-
131
-		return $filler_response;
132
-	}
133
-
134
-	/**
135
-	 * Called by wordlift navigator, converts all the posts to response format.
136
-	 *
137
-	 * @param $filler_count
138
-	 * @param $post_ids_to_be_excluded
139
-	 *
140
-	 * @return array
141
-	 */
142
-	public function get_product_navigator_response( $filler_count, $post_ids_to_be_excluded ) {
143
-		$filler_posts = $this->get_filler_posts( $filler_count, $post_ids_to_be_excluded );
144
-		// Add thumbnail and permalink to filler posts
145
-		$filler_response = array();
146
-		foreach ( $filler_posts as $post_obj ) {
147
-			$product           = wc_get_product( $post_obj->ID );
148
-			$filler_response[] = array(
149
-				'product' => array(
150
-					'id'              => $post_obj->ID,
151
-					'permalink'       => get_permalink( $post_obj->ID ),
152
-					'title'           => $post_obj->post_title,
153
-					'thumbnail'       => get_the_post_thumbnail_url( $post_obj->ID, 'medium' ),
154
-					'regular_price'   => $product->get_regular_price(),
155
-					'sale_price'      => $product->get_sale_price(),
156
-					'price'           => $product->get_price(),
157
-					'currency_symbol' => get_woocommerce_currency_symbol(),
158
-					'discount_pc'     => ( $product->get_sale_price() && ( $product->get_regular_price() > 0 ) ) ? round( 1 - ( $product->get_sale_price() / $product->get_regular_price() ), 2 ) * 100 : 0,
159
-					'average_rating'  => $product->get_average_rating(),
160
-					'rating_count'    => $product->get_rating_count(),
161
-					'rating_html'     => wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ),
162
-				),
163
-				'entity'  => array(),
164
-			);
165
-		}
166
-
167
-		return $filler_response;
168
-	}
13
+    /**
14
+     * @var array<Filler_Posts>
15
+     */
16
+    private $sources = array();
17
+
18
+    public function __construct( $post_id, $alternate_post_type = null ) {
19
+
20
+        $post_type = $alternate_post_type ? $alternate_post_type : get_post_type( $post_id );
21
+
22
+        if ( 'post' === $post_type || ( is_array( $post_type ) && in_array( 'post', $post_type, true ) ) ) {
23
+            $this->sources = array(
24
+                new Same_Category_Filler_Posts( $post_id ),
25
+                new Same_Post_Type_Filler_Posts( $post_id ),
26
+            );
27
+        } elseif ( 'product' === $post_type || ( is_array( $post_type ) && in_array( 'product', $post_type, true ) ) ) {
28
+            $this->sources = array(
29
+                new Same_Post_Type_Same_Category_Posts( $post_id, 'product' ),
30
+                new Same_Post_Type_Filler_Posts( $post_id, 'product' ),
31
+            );
32
+        } else {
33
+            $this->sources = array(
34
+                new Same_Post_Type_Filler_Posts( $post_id ),
35
+            );
36
+        }
37
+    }
38
+
39
+    /**
40
+     * @param $posts array<\WP_Post>
41
+     *
42
+     * @return array<int>
43
+     */
44
+    private function extract_post_ids( $posts ) {
45
+        return array_map(
46
+            function ( $post ) {
47
+                /**
48
+                 * @var $post \WP_Post
49
+                 */
50
+                return $post->ID;
51
+            },
52
+            $posts
53
+        );
54
+    }
55
+
56
+    public function get_filler_posts( $filler_count, $post_ids_to_be_excluded ) {
57
+
58
+        $filler_posts = array();
59
+
60
+        foreach ( $this->sources as $source ) {
61
+
62
+            if ( $filler_count <= 0 ) {
63
+                break;
64
+            }
65
+            /**
66
+             * @var Filler_Posts $source
67
+             */
68
+            $source->post_ids_to_be_excluded = $post_ids_to_be_excluded;
69
+            $source->filler_count            = $filler_count;
70
+
71
+            $posts    = $source->get_posts( $filler_count, $post_ids_to_be_excluded );
72
+            $post_ids = $this->extract_post_ids( $posts );
73
+
74
+            // Update the post ids, filler posts and filler count
75
+            $post_ids_to_be_excluded = array_merge( $post_ids_to_be_excluded, $post_ids );
76
+            $filler_count            = $filler_count - count( $posts );
77
+            $filler_posts            = array_merge( $filler_posts, $posts );
78
+        }
79
+        $filler_posts = $this->add_additional_properties_to_filler_posts( $filler_posts );
80
+
81
+        return $filler_posts;
82
+
83
+    }
84
+
85
+    /**
86
+     * @param $posts array<\WP_Post>
87
+     *
88
+     * @return array $posts array<\WP_Post>
89
+     */
90
+    private function add_additional_properties_to_filler_posts( $posts ) {
91
+        return array_map(
92
+            function ( $post ) {
93
+                $post->thumbnail  = get_the_post_thumbnail_url( $post->ID, 'medium' );
94
+                $post->permalink  = get_permalink( $post->ID );
95
+                $post->post_title = html_entity_decode( $post->post_title, ENT_QUOTES, 'UTF-8' );
96
+
97
+                return $post;
98
+            },
99
+            $posts
100
+        );
101
+    }
102
+
103
+    /**
104
+     * Called by wordlift navigator, converts all the posts to response format.
105
+     *
106
+     * @param $filler_count
107
+     * @param $post_ids_to_be_excluded
108
+     *
109
+     * @return array
110
+     */
111
+    public function get_filler_response( $filler_count, $post_ids_to_be_excluded ) {
112
+        $filler_posts = $this->get_filler_posts( $filler_count, $post_ids_to_be_excluded );
113
+        // Add thumbnail and permalink to filler posts
114
+        $filler_response = array();
115
+        foreach ( $filler_posts as $post_obj ) {
116
+            $thumbnail         = get_the_post_thumbnail_url( $post_obj, 'medium' );
117
+            $filler_response[] = array(
118
+                'post'   => array(
119
+                    'id'        => $post_obj->ID,
120
+                    'permalink' => get_permalink( $post_obj->ID ),
121
+                    'thumbnail' => ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH,
122
+                    'title'     => $post_obj->post_title,
123
+                    'srcset'    => Srcset_Util::get_srcset( $post_obj->ID, Srcset_Util::NAVIGATOR_WIDGET ),
124
+                ),
125
+                'entity' => array(
126
+                    'id' => 0,
127
+                ),
128
+            );
129
+        }
130
+
131
+        return $filler_response;
132
+    }
133
+
134
+    /**
135
+     * Called by wordlift navigator, converts all the posts to response format.
136
+     *
137
+     * @param $filler_count
138
+     * @param $post_ids_to_be_excluded
139
+     *
140
+     * @return array
141
+     */
142
+    public function get_product_navigator_response( $filler_count, $post_ids_to_be_excluded ) {
143
+        $filler_posts = $this->get_filler_posts( $filler_count, $post_ids_to_be_excluded );
144
+        // Add thumbnail and permalink to filler posts
145
+        $filler_response = array();
146
+        foreach ( $filler_posts as $post_obj ) {
147
+            $product           = wc_get_product( $post_obj->ID );
148
+            $filler_response[] = array(
149
+                'product' => array(
150
+                    'id'              => $post_obj->ID,
151
+                    'permalink'       => get_permalink( $post_obj->ID ),
152
+                    'title'           => $post_obj->post_title,
153
+                    'thumbnail'       => get_the_post_thumbnail_url( $post_obj->ID, 'medium' ),
154
+                    'regular_price'   => $product->get_regular_price(),
155
+                    'sale_price'      => $product->get_sale_price(),
156
+                    'price'           => $product->get_price(),
157
+                    'currency_symbol' => get_woocommerce_currency_symbol(),
158
+                    'discount_pc'     => ( $product->get_sale_price() && ( $product->get_regular_price() > 0 ) ) ? round( 1 - ( $product->get_sale_price() / $product->get_regular_price() ), 2 ) * 100 : 0,
159
+                    'average_rating'  => $product->get_average_rating(),
160
+                    'rating_count'    => $product->get_rating_count(),
161
+                    'rating_html'     => wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ),
162
+                ),
163
+                'entity'  => array(),
164
+            );
165
+        }
166
+
167
+        return $filler_response;
168
+    }
169 169
 
170 170
 }
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -15,23 +15,23 @@  discard block
 block discarded – undo
15 15
 	 */
16 16
 	private $sources = array();
17 17
 
18
-	public function __construct( $post_id, $alternate_post_type = null ) {
18
+	public function __construct($post_id, $alternate_post_type = null) {
19 19
 
20
-		$post_type = $alternate_post_type ? $alternate_post_type : get_post_type( $post_id );
20
+		$post_type = $alternate_post_type ? $alternate_post_type : get_post_type($post_id);
21 21
 
22
-		if ( 'post' === $post_type || ( is_array( $post_type ) && in_array( 'post', $post_type, true ) ) ) {
22
+		if ('post' === $post_type || (is_array($post_type) && in_array('post', $post_type, true))) {
23 23
 			$this->sources = array(
24
-				new Same_Category_Filler_Posts( $post_id ),
25
-				new Same_Post_Type_Filler_Posts( $post_id ),
24
+				new Same_Category_Filler_Posts($post_id),
25
+				new Same_Post_Type_Filler_Posts($post_id),
26 26
 			);
27
-		} elseif ( 'product' === $post_type || ( is_array( $post_type ) && in_array( 'product', $post_type, true ) ) ) {
27
+		} elseif ('product' === $post_type || (is_array($post_type) && in_array('product', $post_type, true))) {
28 28
 			$this->sources = array(
29
-				new Same_Post_Type_Same_Category_Posts( $post_id, 'product' ),
30
-				new Same_Post_Type_Filler_Posts( $post_id, 'product' ),
29
+				new Same_Post_Type_Same_Category_Posts($post_id, 'product'),
30
+				new Same_Post_Type_Filler_Posts($post_id, 'product'),
31 31
 			);
32 32
 		} else {
33 33
 			$this->sources = array(
34
-				new Same_Post_Type_Filler_Posts( $post_id ),
34
+				new Same_Post_Type_Filler_Posts($post_id),
35 35
 			);
36 36
 		}
37 37
 	}
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 	 *
42 42
 	 * @return array<int>
43 43
 	 */
44
-	private function extract_post_ids( $posts ) {
44
+	private function extract_post_ids($posts) {
45 45
 		return array_map(
46
-			function ( $post ) {
46
+			function($post) {
47 47
 				/**
48 48
 				 * @var $post \WP_Post
49 49
 				 */
@@ -53,13 +53,13 @@  discard block
 block discarded – undo
53 53
 		);
54 54
 	}
55 55
 
56
-	public function get_filler_posts( $filler_count, $post_ids_to_be_excluded ) {
56
+	public function get_filler_posts($filler_count, $post_ids_to_be_excluded) {
57 57
 
58 58
 		$filler_posts = array();
59 59
 
60
-		foreach ( $this->sources as $source ) {
60
+		foreach ($this->sources as $source) {
61 61
 
62
-			if ( $filler_count <= 0 ) {
62
+			if ($filler_count <= 0) {
63 63
 				break;
64 64
 			}
65 65
 			/**
@@ -68,15 +68,15 @@  discard block
 block discarded – undo
68 68
 			$source->post_ids_to_be_excluded = $post_ids_to_be_excluded;
69 69
 			$source->filler_count            = $filler_count;
70 70
 
71
-			$posts    = $source->get_posts( $filler_count, $post_ids_to_be_excluded );
72
-			$post_ids = $this->extract_post_ids( $posts );
71
+			$posts    = $source->get_posts($filler_count, $post_ids_to_be_excluded);
72
+			$post_ids = $this->extract_post_ids($posts);
73 73
 
74 74
 			// Update the post ids, filler posts and filler count
75
-			$post_ids_to_be_excluded = array_merge( $post_ids_to_be_excluded, $post_ids );
76
-			$filler_count            = $filler_count - count( $posts );
77
-			$filler_posts            = array_merge( $filler_posts, $posts );
75
+			$post_ids_to_be_excluded = array_merge($post_ids_to_be_excluded, $post_ids);
76
+			$filler_count            = $filler_count - count($posts);
77
+			$filler_posts            = array_merge($filler_posts, $posts);
78 78
 		}
79
-		$filler_posts = $this->add_additional_properties_to_filler_posts( $filler_posts );
79
+		$filler_posts = $this->add_additional_properties_to_filler_posts($filler_posts);
80 80
 
81 81
 		return $filler_posts;
82 82
 
@@ -87,12 +87,12 @@  discard block
 block discarded – undo
87 87
 	 *
88 88
 	 * @return array $posts array<\WP_Post>
89 89
 	 */
90
-	private function add_additional_properties_to_filler_posts( $posts ) {
90
+	private function add_additional_properties_to_filler_posts($posts) {
91 91
 		return array_map(
92
-			function ( $post ) {
93
-				$post->thumbnail  = get_the_post_thumbnail_url( $post->ID, 'medium' );
94
-				$post->permalink  = get_permalink( $post->ID );
95
-				$post->post_title = html_entity_decode( $post->post_title, ENT_QUOTES, 'UTF-8' );
92
+			function($post) {
93
+				$post->thumbnail  = get_the_post_thumbnail_url($post->ID, 'medium');
94
+				$post->permalink  = get_permalink($post->ID);
95
+				$post->post_title = html_entity_decode($post->post_title, ENT_QUOTES, 'UTF-8');
96 96
 
97 97
 				return $post;
98 98
 			},
@@ -108,19 +108,19 @@  discard block
 block discarded – undo
108 108
 	 *
109 109
 	 * @return array
110 110
 	 */
111
-	public function get_filler_response( $filler_count, $post_ids_to_be_excluded ) {
112
-		$filler_posts = $this->get_filler_posts( $filler_count, $post_ids_to_be_excluded );
111
+	public function get_filler_response($filler_count, $post_ids_to_be_excluded) {
112
+		$filler_posts = $this->get_filler_posts($filler_count, $post_ids_to_be_excluded);
113 113
 		// Add thumbnail and permalink to filler posts
114 114
 		$filler_response = array();
115
-		foreach ( $filler_posts as $post_obj ) {
116
-			$thumbnail         = get_the_post_thumbnail_url( $post_obj, 'medium' );
115
+		foreach ($filler_posts as $post_obj) {
116
+			$thumbnail         = get_the_post_thumbnail_url($post_obj, 'medium');
117 117
 			$filler_response[] = array(
118 118
 				'post'   => array(
119 119
 					'id'        => $post_obj->ID,
120
-					'permalink' => get_permalink( $post_obj->ID ),
121
-					'thumbnail' => ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH,
120
+					'permalink' => get_permalink($post_obj->ID),
121
+					'thumbnail' => ($thumbnail) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH,
122 122
 					'title'     => $post_obj->post_title,
123
-					'srcset'    => Srcset_Util::get_srcset( $post_obj->ID, Srcset_Util::NAVIGATOR_WIDGET ),
123
+					'srcset'    => Srcset_Util::get_srcset($post_obj->ID, Srcset_Util::NAVIGATOR_WIDGET),
124 124
 				),
125 125
 				'entity' => array(
126 126
 					'id' => 0,
@@ -139,26 +139,26 @@  discard block
 block discarded – undo
139 139
 	 *
140 140
 	 * @return array
141 141
 	 */
142
-	public function get_product_navigator_response( $filler_count, $post_ids_to_be_excluded ) {
143
-		$filler_posts = $this->get_filler_posts( $filler_count, $post_ids_to_be_excluded );
142
+	public function get_product_navigator_response($filler_count, $post_ids_to_be_excluded) {
143
+		$filler_posts = $this->get_filler_posts($filler_count, $post_ids_to_be_excluded);
144 144
 		// Add thumbnail and permalink to filler posts
145 145
 		$filler_response = array();
146
-		foreach ( $filler_posts as $post_obj ) {
147
-			$product           = wc_get_product( $post_obj->ID );
146
+		foreach ($filler_posts as $post_obj) {
147
+			$product           = wc_get_product($post_obj->ID);
148 148
 			$filler_response[] = array(
149 149
 				'product' => array(
150 150
 					'id'              => $post_obj->ID,
151
-					'permalink'       => get_permalink( $post_obj->ID ),
151
+					'permalink'       => get_permalink($post_obj->ID),
152 152
 					'title'           => $post_obj->post_title,
153
-					'thumbnail'       => get_the_post_thumbnail_url( $post_obj->ID, 'medium' ),
153
+					'thumbnail'       => get_the_post_thumbnail_url($post_obj->ID, 'medium'),
154 154
 					'regular_price'   => $product->get_regular_price(),
155 155
 					'sale_price'      => $product->get_sale_price(),
156 156
 					'price'           => $product->get_price(),
157 157
 					'currency_symbol' => get_woocommerce_currency_symbol(),
158
-					'discount_pc'     => ( $product->get_sale_price() && ( $product->get_regular_price() > 0 ) ) ? round( 1 - ( $product->get_sale_price() / $product->get_regular_price() ), 2 ) * 100 : 0,
158
+					'discount_pc'     => ($product->get_sale_price() && ($product->get_regular_price() > 0)) ? round(1 - ($product->get_sale_price() / $product->get_regular_price()), 2) * 100 : 0,
159 159
 					'average_rating'  => $product->get_average_rating(),
160 160
 					'rating_count'    => $product->get_rating_count(),
161
-					'rating_html'     => wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ),
161
+					'rating_html'     => wc_get_rating_html($product->get_average_rating(), $product->get_rating_count()),
162 162
 				),
163 163
 				'entity'  => array(),
164 164
 			);
Please login to merge, or discard this patch.
widgets/navigator/filler-posts/class-same-post-type-filler-posts.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -8,17 +8,17 @@
 block discarded – undo
8 8
  */
9 9
 class Same_Post_Type_Filler_Posts extends Filler_Posts {
10 10
 
11
-	public function get_posts( $filler_count, $post_ids_to_be_excluded ) {
11
+    public function get_posts( $filler_count, $post_ids_to_be_excluded ) {
12 12
 
13
-		$post_type = $this->alternate_post_type ? $this->alternate_post_type : get_post_type( $this->post_id );
13
+        $post_type = $this->alternate_post_type ? $this->alternate_post_type : get_post_type( $this->post_id );
14 14
 
15
-		if ( 'entity' === $post_type ) {
16
-			$post_type = 'post';
17
-		}
15
+        if ( 'entity' === $post_type ) {
16
+            $post_type = 'post';
17
+        }
18 18
 
19
-		return get_posts(
20
-			array( 'post_type' => $post_type )
21
-						  + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded )
22
-		);
23
-	}
19
+        return get_posts(
20
+            array( 'post_type' => $post_type )
21
+                          + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded )
22
+        );
23
+    }
24 24
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -8,17 +8,17 @@
 block discarded – undo
8 8
  */
9 9
 class Same_Post_Type_Filler_Posts extends Filler_Posts {
10 10
 
11
-	public function get_posts( $filler_count, $post_ids_to_be_excluded ) {
11
+	public function get_posts($filler_count, $post_ids_to_be_excluded) {
12 12
 
13
-		$post_type = $this->alternate_post_type ? $this->alternate_post_type : get_post_type( $this->post_id );
13
+		$post_type = $this->alternate_post_type ? $this->alternate_post_type : get_post_type($this->post_id);
14 14
 
15
-		if ( 'entity' === $post_type ) {
15
+		if ('entity' === $post_type) {
16 16
 			$post_type = 'post';
17 17
 		}
18 18
 
19 19
 		return get_posts(
20
-			array( 'post_type' => $post_type )
21
-						  + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded )
20
+			array('post_type' => $post_type)
21
+						  + $this->get_posts_config($filler_count, $post_ids_to_be_excluded)
22 22
 		);
23 23
 	}
24 24
 }
Please login to merge, or discard this patch.
external-plugin-hooks/recipe-maker/class-recipe-maker-jsonld-hook.php 2 patches
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -15,92 +15,92 @@
 block discarded – undo
15 15
  */
16 16
 class Recipe_Maker_Jsonld_Hook {
17 17
 
18
-	/**
19
-	 * @var \Wordlift_Attachment_Service
20
-	 */
21
-	private $attachment_service;
22
-	/**
23
-	 * @var Recipe_Maker_Validation_Service
24
-	 */
25
-	private $recipe_maker_validation_service;
26
-
27
-	/**
28
-	 * Recipe_Maker_Jsonld_Hook constructor.
29
-	 *
30
-	 * @param $attachment_service \Wordlift_Attachment_Service
31
-	 * @param $recipe_maker_validation_service Recipe_Maker_Validation_Service
32
-	 */
33
-	public function __construct( $attachment_service, $recipe_maker_validation_service ) {
34
-
35
-		$this->attachment_service              = $attachment_service;
36
-		$this->recipe_maker_validation_service = $recipe_maker_validation_service;
37
-		$this->merge_recipe_jsonld();
38
-	}
39
-
40
-	private function merge_recipe_jsonld() {
41
-		// First we push all the linked recipes to references.
42
-		add_filter( 'wl_entity_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 );
43
-		add_filter( 'wl_post_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 );
44
-
45
-		// Then we merge the jsonld for every recipe.
46
-		add_filter( 'wl_entity_jsonld', array( $this, 'wl_entity_jsonld' ), 10, 2 );
47
-	}
48
-
49
-	public function wl_entity_jsonld_array( $arr, $post_id ) {
50
-
51
-		$jsonld     = $arr['jsonld'];
52
-		$references = $arr['references'];
53
-
54
-		// check if wp recipe maker installed, if not return early.
55
-		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
56
-			return $arr;
57
-		}
58
-
59
-		// 1. Get the jsonld from recipe maker for the post id.
60
-		$recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
61
-
62
-		// If there are no associated recipes for a post id then return early
63
-		if ( ! $recipe_ids ) {
64
-			return $arr;
65
-		}
66
-
67
-		return array(
68
-			'jsonld'     => $jsonld,
69
-			'references' => array_merge( $recipe_ids, $references ),
70
-		);
71
-
72
-	}
73
-
74
-	public function wl_entity_jsonld( $jsonld, $post_id ) {
75
-		$recipe_data = $this->process_single_recipe_item( $post_id );
76
-		if ( ! $recipe_data ) {
77
-			return $jsonld;
78
-		}
79
-
80
-		if ( ! $jsonld ) {
81
-			return $recipe_data;
82
-		}
83
-
84
-		return $recipe_data + $jsonld;
85
-	}
86
-
87
-	/**
88
-	 * @param $linked_recipe_id int post id of that recipe.
89
-	 *
90
-	 * @return array Recipe valid jsonld data.
91
-	 */
92
-	private function process_single_recipe_item( $linked_recipe_id ) {
93
-		// check if recipe maker present.
94
-		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
95
-			return array();
96
-		}
97
-		$linked_recipe = \WPRM_Recipe_Manager::get_recipe( $linked_recipe_id );
98
-		if ( $linked_recipe ) {
99
-			$metadata = \WPRM_Metadata::get_metadata_details( $linked_recipe );
100
-			return $metadata ? $metadata : array();
101
-		}
102
-
103
-		return array();
104
-	}
18
+    /**
19
+     * @var \Wordlift_Attachment_Service
20
+     */
21
+    private $attachment_service;
22
+    /**
23
+     * @var Recipe_Maker_Validation_Service
24
+     */
25
+    private $recipe_maker_validation_service;
26
+
27
+    /**
28
+     * Recipe_Maker_Jsonld_Hook constructor.
29
+     *
30
+     * @param $attachment_service \Wordlift_Attachment_Service
31
+     * @param $recipe_maker_validation_service Recipe_Maker_Validation_Service
32
+     */
33
+    public function __construct( $attachment_service, $recipe_maker_validation_service ) {
34
+
35
+        $this->attachment_service              = $attachment_service;
36
+        $this->recipe_maker_validation_service = $recipe_maker_validation_service;
37
+        $this->merge_recipe_jsonld();
38
+    }
39
+
40
+    private function merge_recipe_jsonld() {
41
+        // First we push all the linked recipes to references.
42
+        add_filter( 'wl_entity_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 );
43
+        add_filter( 'wl_post_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 );
44
+
45
+        // Then we merge the jsonld for every recipe.
46
+        add_filter( 'wl_entity_jsonld', array( $this, 'wl_entity_jsonld' ), 10, 2 );
47
+    }
48
+
49
+    public function wl_entity_jsonld_array( $arr, $post_id ) {
50
+
51
+        $jsonld     = $arr['jsonld'];
52
+        $references = $arr['references'];
53
+
54
+        // check if wp recipe maker installed, if not return early.
55
+        if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
56
+            return $arr;
57
+        }
58
+
59
+        // 1. Get the jsonld from recipe maker for the post id.
60
+        $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
61
+
62
+        // If there are no associated recipes for a post id then return early
63
+        if ( ! $recipe_ids ) {
64
+            return $arr;
65
+        }
66
+
67
+        return array(
68
+            'jsonld'     => $jsonld,
69
+            'references' => array_merge( $recipe_ids, $references ),
70
+        );
71
+
72
+    }
73
+
74
+    public function wl_entity_jsonld( $jsonld, $post_id ) {
75
+        $recipe_data = $this->process_single_recipe_item( $post_id );
76
+        if ( ! $recipe_data ) {
77
+            return $jsonld;
78
+        }
79
+
80
+        if ( ! $jsonld ) {
81
+            return $recipe_data;
82
+        }
83
+
84
+        return $recipe_data + $jsonld;
85
+    }
86
+
87
+    /**
88
+     * @param $linked_recipe_id int post id of that recipe.
89
+     *
90
+     * @return array Recipe valid jsonld data.
91
+     */
92
+    private function process_single_recipe_item( $linked_recipe_id ) {
93
+        // check if recipe maker present.
94
+        if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
95
+            return array();
96
+        }
97
+        $linked_recipe = \WPRM_Recipe_Manager::get_recipe( $linked_recipe_id );
98
+        if ( $linked_recipe ) {
99
+            $metadata = \WPRM_Metadata::get_metadata_details( $linked_recipe );
100
+            return $metadata ? $metadata : array();
101
+        }
102
+
103
+        return array();
104
+    }
105 105
 
106 106
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	 * @param $attachment_service \Wordlift_Attachment_Service
31 31
 	 * @param $recipe_maker_validation_service Recipe_Maker_Validation_Service
32 32
 	 */
33
-	public function __construct( $attachment_service, $recipe_maker_validation_service ) {
33
+	public function __construct($attachment_service, $recipe_maker_validation_service) {
34 34
 
35 35
 		$this->attachment_service              = $attachment_service;
36 36
 		$this->recipe_maker_validation_service = $recipe_maker_validation_service;
@@ -39,45 +39,45 @@  discard block
 block discarded – undo
39 39
 
40 40
 	private function merge_recipe_jsonld() {
41 41
 		// First we push all the linked recipes to references.
42
-		add_filter( 'wl_entity_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 );
43
-		add_filter( 'wl_post_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 );
42
+		add_filter('wl_entity_jsonld_array', array($this, 'wl_entity_jsonld_array'), 10, 2);
43
+		add_filter('wl_post_jsonld_array', array($this, 'wl_entity_jsonld_array'), 10, 2);
44 44
 
45 45
 		// Then we merge the jsonld for every recipe.
46
-		add_filter( 'wl_entity_jsonld', array( $this, 'wl_entity_jsonld' ), 10, 2 );
46
+		add_filter('wl_entity_jsonld', array($this, 'wl_entity_jsonld'), 10, 2);
47 47
 	}
48 48
 
49
-	public function wl_entity_jsonld_array( $arr, $post_id ) {
49
+	public function wl_entity_jsonld_array($arr, $post_id) {
50 50
 
51 51
 		$jsonld     = $arr['jsonld'];
52 52
 		$references = $arr['references'];
53 53
 
54 54
 		// check if wp recipe maker installed, if not return early.
55
-		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
55
+		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available()) {
56 56
 			return $arr;
57 57
 		}
58 58
 
59 59
 		// 1. Get the jsonld from recipe maker for the post id.
60
-		$recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
60
+		$recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post($post_id);
61 61
 
62 62
 		// If there are no associated recipes for a post id then return early
63
-		if ( ! $recipe_ids ) {
63
+		if ( ! $recipe_ids) {
64 64
 			return $arr;
65 65
 		}
66 66
 
67 67
 		return array(
68 68
 			'jsonld'     => $jsonld,
69
-			'references' => array_merge( $recipe_ids, $references ),
69
+			'references' => array_merge($recipe_ids, $references),
70 70
 		);
71 71
 
72 72
 	}
73 73
 
74
-	public function wl_entity_jsonld( $jsonld, $post_id ) {
75
-		$recipe_data = $this->process_single_recipe_item( $post_id );
76
-		if ( ! $recipe_data ) {
74
+	public function wl_entity_jsonld($jsonld, $post_id) {
75
+		$recipe_data = $this->process_single_recipe_item($post_id);
76
+		if ( ! $recipe_data) {
77 77
 			return $jsonld;
78 78
 		}
79 79
 
80
-		if ( ! $jsonld ) {
80
+		if ( ! $jsonld) {
81 81
 			return $recipe_data;
82 82
 		}
83 83
 
@@ -89,14 +89,14 @@  discard block
 block discarded – undo
89 89
 	 *
90 90
 	 * @return array Recipe valid jsonld data.
91 91
 	 */
92
-	private function process_single_recipe_item( $linked_recipe_id ) {
92
+	private function process_single_recipe_item($linked_recipe_id) {
93 93
 		// check if recipe maker present.
94
-		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
94
+		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available()) {
95 95
 			return array();
96 96
 		}
97
-		$linked_recipe = \WPRM_Recipe_Manager::get_recipe( $linked_recipe_id );
98
-		if ( $linked_recipe ) {
99
-			$metadata = \WPRM_Metadata::get_metadata_details( $linked_recipe );
97
+		$linked_recipe = \WPRM_Recipe_Manager::get_recipe($linked_recipe_id);
98
+		if ($linked_recipe) {
99
+			$metadata = \WPRM_Metadata::get_metadata_details($linked_recipe);
100 100
 			return $metadata ? $metadata : array();
101 101
 		}
102 102
 
Please login to merge, or discard this patch.
external-plugin-hooks/recipe-maker/class-recipe-maker-post-type-hook.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -13,34 +13,34 @@
 block discarded – undo
13 13
  */
14 14
 class Recipe_Maker_Post_Type_Hook {
15 15
 
16
-	const RECIPE_MAKER_POST_TYPE = 'wprm_recipe';
16
+    const RECIPE_MAKER_POST_TYPE = 'wprm_recipe';
17 17
 
18
-	public function __construct() {
18
+    public function __construct() {
19 19
 
20
-		add_filter(
21
-			'wl_default_entity_type_for_post_type',
22
-			array( $this, 'wl_default_entity_type_for_post_type' ),
23
-			10,
24
-			2
25
-		);
20
+        add_filter(
21
+            'wl_default_entity_type_for_post_type',
22
+            array( $this, 'wl_default_entity_type_for_post_type' ),
23
+            10,
24
+            2
25
+        );
26 26
 
27
-		add_filter( 'wl_valid_entity_post_types', array( $this, 'add_post_type' ) );
27
+        add_filter( 'wl_valid_entity_post_types', array( $this, 'add_post_type' ) );
28 28
 
29
-	}
29
+    }
30 30
 
31
-	public function add_post_type( $post_types ) {
31
+    public function add_post_type( $post_types ) {
32 32
 
33
-		$post_types[] = self::RECIPE_MAKER_POST_TYPE;
33
+        $post_types[] = self::RECIPE_MAKER_POST_TYPE;
34 34
 
35
-		return $post_types;
36
-	}
35
+        return $post_types;
36
+    }
37 37
 
38
-	public function wl_default_entity_type_for_post_type( $entity_type, $post_type ) {
38
+    public function wl_default_entity_type_for_post_type( $entity_type, $post_type ) {
39 39
 
40
-		if ( self::RECIPE_MAKER_POST_TYPE === $post_type ) {
41
-			return 'http://schema.org/Recipe';
42
-		}
40
+        if ( self::RECIPE_MAKER_POST_TYPE === $post_type ) {
41
+            return 'http://schema.org/Recipe';
42
+        }
43 43
 
44
-		return $entity_type;
45
-	}
44
+        return $entity_type;
45
+    }
46 46
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -19,25 +19,25 @@
 block discarded – undo
19 19
 
20 20
 		add_filter(
21 21
 			'wl_default_entity_type_for_post_type',
22
-			array( $this, 'wl_default_entity_type_for_post_type' ),
22
+			array($this, 'wl_default_entity_type_for_post_type'),
23 23
 			10,
24 24
 			2
25 25
 		);
26 26
 
27
-		add_filter( 'wl_valid_entity_post_types', array( $this, 'add_post_type' ) );
27
+		add_filter('wl_valid_entity_post_types', array($this, 'add_post_type'));
28 28
 
29 29
 	}
30 30
 
31
-	public function add_post_type( $post_types ) {
31
+	public function add_post_type($post_types) {
32 32
 
33 33
 		$post_types[] = self::RECIPE_MAKER_POST_TYPE;
34 34
 
35 35
 		return $post_types;
36 36
 	}
37 37
 
38
-	public function wl_default_entity_type_for_post_type( $entity_type, $post_type ) {
38
+	public function wl_default_entity_type_for_post_type($entity_type, $post_type) {
39 39
 
40
-		if ( self::RECIPE_MAKER_POST_TYPE === $post_type ) {
40
+		if (self::RECIPE_MAKER_POST_TYPE === $post_type) {
41 41
 			return 'http://schema.org/Recipe';
42 42
 		}
43 43
 
Please login to merge, or discard this patch.
external-plugin-hooks/recipe-maker/class-recipe-maker-jsonld-swap.php 2 patches
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -10,60 +10,60 @@
 block discarded – undo
10 10
 
11 11
 class Recipe_Maker_Jsonld_Swap {
12 12
 
13
-	/**
14
-	 * @var Recipe_Maker_Validation_Service
15
-	 */
16
-	private $validation_service;
17
-	/**
18
-	 * @var \Wordlift_Jsonld_Service
19
-	 */
20
-	private $jsonld_service;
21
-
22
-	/**
23
-	 * @param $validation_service Recipe_Maker_Validation_Service
24
-	 */
25
-	public function __construct( $validation_service, $jsonld_service ) {
26
-
27
-		$this->validation_service = $validation_service;
28
-		$this->jsonld_service     = $jsonld_service;
29
-
30
-		add_filter( 'wprm_recipe_metadata', array( $this, 'alter_jsonld' ), 10 );
31
-	}
32
-
33
-	/**
34
-	 * Remove recipe maker jsonld or add mentions based on the integration.
35
-	 *
36
-	 * @param $metadata
37
-	 * @param $recipe
38
-	 *
39
-	 * @return array
40
-	 */
41
-	public function alter_jsonld( $metadata ) {
42
-
43
-		// If this filter is invoked on any other page except post, then we should not modify the jsonld.
44
-		if ( ! get_post() instanceof \WP_Post ) {
45
-			return $metadata;
46
-		}
47
-
48
-		$post_id = get_the_ID();
49
-
50
-		/**
51
-		 * We dont print our jsonld when the page has recipe maker, we enhance the recipe maker jsonld
52
-		 * by adding only the `mentions` property.
53
-		 */
54
-		add_filter( 'wl_jsonld_enabled', '__return_false' );
55
-
56
-		$post_jsonld = $this->jsonld_service->get_jsonld( false, $post_id, Jsonld_Context_Enum::PAGE );
57
-
58
-		if ( 0 === count( $post_jsonld ) || ! array_key_exists( 'mentions', $post_jsonld[0] )
59
-			 || 0 === count( $post_jsonld[0]['mentions'] ) ) {
60
-			// Even if we don't have mentions return the metadata.
61
-			return $metadata;
62
-		}
63
-
64
-		$metadata['mentions'] = $post_jsonld[0]['mentions'];
65
-
66
-		return $metadata;
67
-	}
13
+    /**
14
+     * @var Recipe_Maker_Validation_Service
15
+     */
16
+    private $validation_service;
17
+    /**
18
+     * @var \Wordlift_Jsonld_Service
19
+     */
20
+    private $jsonld_service;
21
+
22
+    /**
23
+     * @param $validation_service Recipe_Maker_Validation_Service
24
+     */
25
+    public function __construct( $validation_service, $jsonld_service ) {
26
+
27
+        $this->validation_service = $validation_service;
28
+        $this->jsonld_service     = $jsonld_service;
29
+
30
+        add_filter( 'wprm_recipe_metadata', array( $this, 'alter_jsonld' ), 10 );
31
+    }
32
+
33
+    /**
34
+     * Remove recipe maker jsonld or add mentions based on the integration.
35
+     *
36
+     * @param $metadata
37
+     * @param $recipe
38
+     *
39
+     * @return array
40
+     */
41
+    public function alter_jsonld( $metadata ) {
42
+
43
+        // If this filter is invoked on any other page except post, then we should not modify the jsonld.
44
+        if ( ! get_post() instanceof \WP_Post ) {
45
+            return $metadata;
46
+        }
47
+
48
+        $post_id = get_the_ID();
49
+
50
+        /**
51
+         * We dont print our jsonld when the page has recipe maker, we enhance the recipe maker jsonld
52
+         * by adding only the `mentions` property.
53
+         */
54
+        add_filter( 'wl_jsonld_enabled', '__return_false' );
55
+
56
+        $post_jsonld = $this->jsonld_service->get_jsonld( false, $post_id, Jsonld_Context_Enum::PAGE );
57
+
58
+        if ( 0 === count( $post_jsonld ) || ! array_key_exists( 'mentions', $post_jsonld[0] )
59
+             || 0 === count( $post_jsonld[0]['mentions'] ) ) {
60
+            // Even if we don't have mentions return the metadata.
61
+            return $metadata;
62
+        }
63
+
64
+        $metadata['mentions'] = $post_jsonld[0]['mentions'];
65
+
66
+        return $metadata;
67
+    }
68 68
 
69 69
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -22,12 +22,12 @@  discard block
 block discarded – undo
22 22
 	/**
23 23
 	 * @param $validation_service Recipe_Maker_Validation_Service
24 24
 	 */
25
-	public function __construct( $validation_service, $jsonld_service ) {
25
+	public function __construct($validation_service, $jsonld_service) {
26 26
 
27 27
 		$this->validation_service = $validation_service;
28 28
 		$this->jsonld_service     = $jsonld_service;
29 29
 
30
-		add_filter( 'wprm_recipe_metadata', array( $this, 'alter_jsonld' ), 10 );
30
+		add_filter('wprm_recipe_metadata', array($this, 'alter_jsonld'), 10);
31 31
 	}
32 32
 
33 33
 	/**
@@ -38,10 +38,10 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @return array
40 40
 	 */
41
-	public function alter_jsonld( $metadata ) {
41
+	public function alter_jsonld($metadata) {
42 42
 
43 43
 		// If this filter is invoked on any other page except post, then we should not modify the jsonld.
44
-		if ( ! get_post() instanceof \WP_Post ) {
44
+		if ( ! get_post() instanceof \WP_Post) {
45 45
 			return $metadata;
46 46
 		}
47 47
 
@@ -51,12 +51,12 @@  discard block
 block discarded – undo
51 51
 		 * We dont print our jsonld when the page has recipe maker, we enhance the recipe maker jsonld
52 52
 		 * by adding only the `mentions` property.
53 53
 		 */
54
-		add_filter( 'wl_jsonld_enabled', '__return_false' );
54
+		add_filter('wl_jsonld_enabled', '__return_false');
55 55
 
56
-		$post_jsonld = $this->jsonld_service->get_jsonld( false, $post_id, Jsonld_Context_Enum::PAGE );
56
+		$post_jsonld = $this->jsonld_service->get_jsonld(false, $post_id, Jsonld_Context_Enum::PAGE);
57 57
 
58
-		if ( 0 === count( $post_jsonld ) || ! array_key_exists( 'mentions', $post_jsonld[0] )
59
-			 || 0 === count( $post_jsonld[0]['mentions'] ) ) {
58
+		if (0 === count($post_jsonld) || ! array_key_exists('mentions', $post_jsonld[0])
59
+			 || 0 === count($post_jsonld[0]['mentions'])) {
60 60
 			// Even if we don't have mentions return the metadata.
61 61
 			return $metadata;
62 62
 		}
Please login to merge, or discard this patch.