Completed
Pull Request — master (#1573)
by Naveen
01:14
created
src/admin/wordlift-admin.php 2 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -17,28 +17,28 @@  discard block
 block discarded – undo
17 17
  */
18 18
 function wl_serialize_entity( $entity ) {
19 19
 
20
-	$entity = ( is_numeric( $entity ) ) ? get_post( $entity ) : $entity;
20
+    $entity = ( is_numeric( $entity ) ) ? get_post( $entity ) : $entity;
21 21
 
22
-	// Bail if the entity doesn't exists.
23
-	// In some cases we have `wl_topic` meta
24
-	// pointing to an entity that has been deleted.
25
-	if ( empty( $entity ) ) {
26
-		return;
27
-	}
22
+    // Bail if the entity doesn't exists.
23
+    // In some cases we have `wl_topic` meta
24
+    // pointing to an entity that has been deleted.
25
+    if ( empty( $entity ) ) {
26
+        return;
27
+    }
28 28
 
29
-	$type   = Wordlift_Entity_Type_Service::get_instance()->get( $entity->ID );
30
-	$images = wl_get_image_urls( $entity->ID );
29
+    $type   = Wordlift_Entity_Type_Service::get_instance()->get( $entity->ID );
30
+    $images = wl_get_image_urls( $entity->ID );
31 31
 
32
-	return array(
33
-		'id'          => wl_get_entity_uri( $entity->ID ),
34
-		'label'       => $entity->post_title,
35
-		'description' => $entity->post_content,
36
-		'sameAs'      => wl_schema_get_value( $entity->ID, 'sameAs' ),
37
-		'mainType'    => str_replace( 'wl-', '', $type['css_class'] ),
38
-		'types'       => wl_get_entity_rdf_types( $entity->ID ),
39
-		'images'      => $images,
32
+    return array(
33
+        'id'          => wl_get_entity_uri( $entity->ID ),
34
+        'label'       => $entity->post_title,
35
+        'description' => $entity->post_content,
36
+        'sameAs'      => wl_schema_get_value( $entity->ID, 'sameAs' ),
37
+        'mainType'    => str_replace( 'wl-', '', $type['css_class'] ),
38
+        'types'       => wl_get_entity_rdf_types( $entity->ID ),
39
+        'images'      => $images,
40 40
 
41
-	);
41
+    );
42 42
 }
43 43
 
44 44
 /**
@@ -51,29 +51,29 @@  discard block
 block discarded – undo
51 51
  */
52 52
 function wl_remove_text_annotations( $data ) {
53 53
 
54
-	// Remove blank elements that can interfere with annotations removing
55
-	// See https://github.com/insideout10/wordlift-plugin/issues/234
56
-	// Just blank span tags without any attributes are cleaned up.
57
-	// Restrict removal to empty spans only as we may impact valid empty elements like: <th>
58
-	$pattern = '/<span><\/span>/im';
59
-	// Remove the pattern while it is found (match nested annotations).
60
-	while ( 1 === preg_match( $pattern, $data['post_content'] ) ) {
61
-		$data['post_content'] = preg_replace( $pattern, '$2', $data['post_content'], - 1, $count );
62
-	}
63
-	// Remove text annotations
64
-	// <span class="textannotation" id="urn:enhancement-777cbed4-b131-00fb-54a4-ed9b26ae57ea">.
54
+    // Remove blank elements that can interfere with annotations removing
55
+    // See https://github.com/insideout10/wordlift-plugin/issues/234
56
+    // Just blank span tags without any attributes are cleaned up.
57
+    // Restrict removal to empty spans only as we may impact valid empty elements like: <th>
58
+    $pattern = '/<span><\/span>/im';
59
+    // Remove the pattern while it is found (match nested annotations).
60
+    while ( 1 === preg_match( $pattern, $data['post_content'] ) ) {
61
+        $data['post_content'] = preg_replace( $pattern, '$2', $data['post_content'], - 1, $count );
62
+    }
63
+    // Remove text annotations
64
+    // <span class="textannotation" id="urn:enhancement-777cbed4-b131-00fb-54a4-ed9b26ae57ea">.
65 65
 
66
-	// @see https://github.com/insideout10/wordlift-plugin/issues/771
67
-	// Changing this:
68
-	// $pattern = '/<(\w+)[^>]*\sclass=\\\"textannotation(?![^\\"]*\sdisambiguated)[^\\"]*\\\"[^>]*>([^<]+)<\/\1>/im';
69
-	// to:
70
-	$pattern = '/<(\w+)[^>]*\sclass=\\\"textannotation(?![^\\"]*\sdisambiguated)[^\\"]*\\\"[^>]*>(.*?)<\/\1>/im';
71
-	// Remove the pattern while it is found (match nested annotations).
72
-	while ( 1 === preg_match( $pattern, $data['post_content'] ) ) {
73
-		$data['post_content'] = preg_replace( $pattern, '$2', $data['post_content'], - 1, $count );
74
-	}
66
+    // @see https://github.com/insideout10/wordlift-plugin/issues/771
67
+    // Changing this:
68
+    // $pattern = '/<(\w+)[^>]*\sclass=\\\"textannotation(?![^\\"]*\sdisambiguated)[^\\"]*\\\"[^>]*>([^<]+)<\/\1>/im';
69
+    // to:
70
+    $pattern = '/<(\w+)[^>]*\sclass=\\\"textannotation(?![^\\"]*\sdisambiguated)[^\\"]*\\\"[^>]*>(.*?)<\/\1>/im';
71
+    // Remove the pattern while it is found (match nested annotations).
72
+    while ( 1 === preg_match( $pattern, $data['post_content'] ) ) {
73
+        $data['post_content'] = preg_replace( $pattern, '$2', $data['post_content'], - 1, $count );
74
+    }
75 75
 
76
-	return $data;
76
+    return $data;
77 77
 }
78 78
 
79 79
 add_filter( 'wp_insert_post_data', 'wl_remove_text_annotations', '98', 1 );
@@ -88,5 +88,5 @@  discard block
 block discarded – undo
88 88
  */
89 89
 function wl_admin_metaboxes_add_css_class( $classes = array() ) {
90 90
 
91
-	return array_merge( $classes, array( 'wl-metabox' ) );
91
+    return array_merge( $classes, array( 'wl-metabox' ) );
92 92
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -15,27 +15,27 @@  discard block
 block discarded – undo
15 15
  *
16 16
  * @return array mixed The entity data array.
17 17
  */
18
-function wl_serialize_entity( $entity ) {
18
+function wl_serialize_entity($entity) {
19 19
 
20
-	$entity = ( is_numeric( $entity ) ) ? get_post( $entity ) : $entity;
20
+	$entity = (is_numeric($entity)) ? get_post($entity) : $entity;
21 21
 
22 22
 	// Bail if the entity doesn't exists.
23 23
 	// In some cases we have `wl_topic` meta
24 24
 	// pointing to an entity that has been deleted.
25
-	if ( empty( $entity ) ) {
25
+	if (empty($entity)) {
26 26
 		return;
27 27
 	}
28 28
 
29
-	$type   = Wordlift_Entity_Type_Service::get_instance()->get( $entity->ID );
30
-	$images = wl_get_image_urls( $entity->ID );
29
+	$type   = Wordlift_Entity_Type_Service::get_instance()->get($entity->ID);
30
+	$images = wl_get_image_urls($entity->ID);
31 31
 
32 32
 	return array(
33
-		'id'          => wl_get_entity_uri( $entity->ID ),
33
+		'id'          => wl_get_entity_uri($entity->ID),
34 34
 		'label'       => $entity->post_title,
35 35
 		'description' => $entity->post_content,
36
-		'sameAs'      => wl_schema_get_value( $entity->ID, 'sameAs' ),
37
-		'mainType'    => str_replace( 'wl-', '', $type['css_class'] ),
38
-		'types'       => wl_get_entity_rdf_types( $entity->ID ),
36
+		'sameAs'      => wl_schema_get_value($entity->ID, 'sameAs'),
37
+		'mainType'    => str_replace('wl-', '', $type['css_class']),
38
+		'types'       => wl_get_entity_rdf_types($entity->ID),
39 39
 		'images'      => $images,
40 40
 
41 41
 	);
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
  * @return array mixed The post data array.
50 50
  * @since 1.0.0
51 51
  */
52
-function wl_remove_text_annotations( $data ) {
52
+function wl_remove_text_annotations($data) {
53 53
 
54 54
 	// Remove blank elements that can interfere with annotations removing
55 55
 	// See https://github.com/insideout10/wordlift-plugin/issues/234
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
 	// Restrict removal to empty spans only as we may impact valid empty elements like: <th>
58 58
 	$pattern = '/<span><\/span>/im';
59 59
 	// Remove the pattern while it is found (match nested annotations).
60
-	while ( 1 === preg_match( $pattern, $data['post_content'] ) ) {
61
-		$data['post_content'] = preg_replace( $pattern, '$2', $data['post_content'], - 1, $count );
60
+	while (1 === preg_match($pattern, $data['post_content'])) {
61
+		$data['post_content'] = preg_replace($pattern, '$2', $data['post_content'], - 1, $count);
62 62
 	}
63 63
 	// Remove text annotations
64 64
 	// <span class="textannotation" id="urn:enhancement-777cbed4-b131-00fb-54a4-ed9b26ae57ea">.
@@ -69,14 +69,14 @@  discard block
 block discarded – undo
69 69
 	// to:
70 70
 	$pattern = '/<(\w+)[^>]*\sclass=\\\"textannotation(?![^\\"]*\sdisambiguated)[^\\"]*\\\"[^>]*>(.*?)<\/\1>/im';
71 71
 	// Remove the pattern while it is found (match nested annotations).
72
-	while ( 1 === preg_match( $pattern, $data['post_content'] ) ) {
73
-		$data['post_content'] = preg_replace( $pattern, '$2', $data['post_content'], - 1, $count );
72
+	while (1 === preg_match($pattern, $data['post_content'])) {
73
+		$data['post_content'] = preg_replace($pattern, '$2', $data['post_content'], - 1, $count);
74 74
 	}
75 75
 
76 76
 	return $data;
77 77
 }
78 78
 
79
-add_filter( 'wp_insert_post_data', 'wl_remove_text_annotations', '98', 1 );
79
+add_filter('wp_insert_post_data', 'wl_remove_text_annotations', '98', 1);
80 80
 
81 81
 /**
82 82
  * Adds wl-metabox CSS class to a metabox.
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
  * @return array The updated list of CSS classes.
87 87
  * @since 3.2.0
88 88
  */
89
-function wl_admin_metaboxes_add_css_class( $classes = array() ) {
89
+function wl_admin_metaboxes_add_css_class($classes = array()) {
90 90
 
91
-	return array_merge( $classes, array( 'wl-metabox' ) );
91
+	return array_merge($classes, array('wl-metabox'));
92 92
 }
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php 2 patches
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -17,43 +17,43 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Wordlift_Admin_Schemaorg_Taxonomy_Metabox {
19 19
 
20
-	/**
21
-	 * Render the metabox.
22
-	 *
23
-	 * @since 3.20.0
24
-	 */
25
-	public static function render() {
20
+    /**
21
+     * Render the metabox.
22
+     *
23
+     * @since 3.20.0
24
+     */
25
+    public static function render() {
26 26
 
27
-		self::post_categories_meta_box(
28
-			get_post(),
29
-			array(
30
-				'args' =>
31
-					array( 'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ),
32
-			)
33
-		);
27
+        self::post_categories_meta_box(
28
+            get_post(),
29
+            array(
30
+                'args' =>
31
+                    array( 'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ),
32
+            )
33
+        );
34 34
 
35
-	}
35
+    }
36 36
 
37
-	/**
38
-	 * A function which resembles WordPress' own to display a metabox, but which customizes the output
39
-	 * to display the Schema.org classes tree.
40
-	 *
41
-	 * @param WP_Post $post The {@link WP_Post} being edited.
42
-	 * @param array   $box An array of arguments.
43
-	 *
44
-	 * @since 3.20.0
45
-	 */
46
-	private static function post_categories_meta_box( $post, $box ) {
47
-		$defaults = array( 'taxonomy' => 'category' );
48
-		if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) {
49
-			$args = array();
50
-		} else {
51
-			$args = $box['args'];
52
-		}
53
-		$r        = wp_parse_args( $args, $defaults );
54
-		$tax_name = esc_attr( $r['taxonomy'] );
55
-		$taxonomy = get_taxonomy( $r['taxonomy'] );
56
-		?>
37
+    /**
38
+     * A function which resembles WordPress' own to display a metabox, but which customizes the output
39
+     * to display the Schema.org classes tree.
40
+     *
41
+     * @param WP_Post $post The {@link WP_Post} being edited.
42
+     * @param array   $box An array of arguments.
43
+     *
44
+     * @since 3.20.0
45
+     */
46
+    private static function post_categories_meta_box( $post, $box ) {
47
+        $defaults = array( 'taxonomy' => 'category' );
48
+        if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) {
49
+            $args = array();
50
+        } else {
51
+            $args = $box['args'];
52
+        }
53
+        $r        = wp_parse_args( $args, $defaults );
54
+        $tax_name = esc_attr( $r['taxonomy'] );
55
+        $taxonomy = get_taxonomy( $r['taxonomy'] );
56
+        ?>
57 57
 		<div id="taxonomy-<?php echo esc_attr( $tax_name ); ?>" class="categorydiv">
58 58
 			<ul id="<?php echo esc_attr( $tax_name ); ?>-tabs" class="category-tabs">
59 59
 				<li class="tabs"><a
@@ -79,34 +79,34 @@  discard block
 block discarded – undo
79 79
 
80 80
 			<div id="<?php echo esc_attr( $tax_name ); ?>-legacy" class="tabs-panel" style="display: none;">
81 81
 				<?php
82
-				$name = ( 'category' === $tax_name ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
83
-				echo wp_kses(
84
-					sprintf(
85
-						"<input type='hidden' name='%s[]' value='0' />",
86
-						esc_attr( $name )
87
-					),
88
-					array(
89
-						'input' =>
90
-							array(
91
-								'type'  => array(),
92
-								'name'  => array(),
93
-								'value' => array(),
94
-							),
95
-					)
96
-				); // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
97
-				?>
82
+                $name = ( 'category' === $tax_name ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
83
+                echo wp_kses(
84
+                    sprintf(
85
+                        "<input type='hidden' name='%s[]' value='0' />",
86
+                        esc_attr( $name )
87
+                    ),
88
+                    array(
89
+                        'input' =>
90
+                            array(
91
+                                'type'  => array(),
92
+                                'name'  => array(),
93
+                                'value' => array(),
94
+                            ),
95
+                    )
96
+                ); // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
97
+                ?>
98 98
 				<ul id="<?php echo esc_attr( $tax_name ); ?>checklist"
99 99
 					data-wp-lists="list:<?php echo esc_attr( $tax_name ); ?>"
100 100
 					class="categorychecklist form-no-clear">
101 101
 					<?php
102
-					wp_terms_checklist(
103
-						$post->ID,
104
-						array(
105
-							'taxonomy'     => $tax_name,
106
-							'popular_cats' => $popular_ids,
107
-						)
108
-					);
109
-					?>
102
+                    wp_terms_checklist(
103
+                        $post->ID,
104
+                        array(
105
+                            'taxonomy'     => $tax_name,
106
+                            'popular_cats' => $popular_ids,
107
+                        )
108
+                    );
109
+                    ?>
110 110
 				</ul>
111 111
 			</div>
112 112
 			<?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?>
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
 					   href="#<?php echo esc_attr( $tax_name ); ?>-add"
116 116
 					   class="taxonomy-add-new">
117 117
 						<?php
118
-						/* translators: %s: add new taxonomy label */
119
-						echo esc_html( sprintf( __( '+ %s', 'default' ), $taxonomy->labels->add_new_item ) );
120
-						?>
118
+                        /* translators: %s: add new taxonomy label */
119
+                        echo esc_html( sprintf( __( '+ %s', 'default' ), $taxonomy->labels->add_new_item ) );
120
+                        ?>
121 121
 					</a>
122 122
 					<p id="<?php echo esc_attr( $tax_name ); ?>-add" class="category-add wp-hidden-child">
123 123
 						<label class="screen-reader-text"
@@ -131,42 +131,42 @@  discard block
 block discarded – undo
131 131
 							<?php echo esc_html( $taxonomy->labels->parent_item_colon ); ?>
132 132
 						</label>
133 133
 						<?php
134
-						$parent_dropdown_args = array(
135
-							'taxonomy'         => $tax_name,
136
-							'hide_empty'       => 0,
137
-							'name'             => 'new' . $tax_name . '_parent',
138
-							'orderby'          => 'name',
139
-							'hierarchical'     => 1,
140
-							'show_option_none' => '&mdash; ' . $taxonomy->labels->parent_item . ' &mdash;',
141
-						);
134
+                        $parent_dropdown_args = array(
135
+                            'taxonomy'         => $tax_name,
136
+                            'hide_empty'       => 0,
137
+                            'name'             => 'new' . $tax_name . '_parent',
138
+                            'orderby'          => 'name',
139
+                            'hierarchical'     => 1,
140
+                            'show_option_none' => '&mdash; ' . $taxonomy->labels->parent_item . ' &mdash;',
141
+                        );
142 142
 
143
-						/**
144
-						 * Filters the arguments for the taxonomy parent dropdown on the Post Edit page.
145
-						 *
146
-						 * @param array $parent_dropdown_args {
147
-						 *     Optional. Array of arguments to generate parent dropdown.
148
-						 *
149
-						 * @type string $taxonomy Name of the taxonomy to retrieve.
150
-						 * @type bool $hide_if_empty True to skip generating markup if no
151
-						 *                                      categories are found. Default 0.
152
-						 * @type string $name Value for the 'name' attribute
153
-						 *                                      of the select element.
154
-						 *                                      Default "new{$tax_name}_parent".
155
-						 * @type string $orderby Which column to use for ordering
156
-						 *                                      terms. Default 'name'.
157
-						 * @type bool|int $hierarchical Whether to traverse the taxonomy
158
-						 *                                      hierarchy. Default 1.
159
-						 * @type string $show_option_none Text to display for the "none" option.
160
-						 *                                      Default "&mdash; {$parent} &mdash;",
161
-						 *                                      where `$parent` is 'parent_item'
162
-						 *                                      taxonomy label.
163
-						 * }
164
-						 * @since 4.4.0
165
-						 */
166
-						$parent_dropdown_args = apply_filters( 'post_edit_category_parent_dropdown_args', $parent_dropdown_args );
143
+                        /**
144
+                         * Filters the arguments for the taxonomy parent dropdown on the Post Edit page.
145
+                         *
146
+                         * @param array $parent_dropdown_args {
147
+                         *     Optional. Array of arguments to generate parent dropdown.
148
+                         *
149
+                         * @type string $taxonomy Name of the taxonomy to retrieve.
150
+                         * @type bool $hide_if_empty True to skip generating markup if no
151
+                         *                                      categories are found. Default 0.
152
+                         * @type string $name Value for the 'name' attribute
153
+                         *                                      of the select element.
154
+                         *                                      Default "new{$tax_name}_parent".
155
+                         * @type string $orderby Which column to use for ordering
156
+                         *                                      terms. Default 'name'.
157
+                         * @type bool|int $hierarchical Whether to traverse the taxonomy
158
+                         *                                      hierarchy. Default 1.
159
+                         * @type string $show_option_none Text to display for the "none" option.
160
+                         *                                      Default "&mdash; {$parent} &mdash;",
161
+                         *                                      where `$parent` is 'parent_item'
162
+                         *                                      taxonomy label.
163
+                         * }
164
+                         * @since 4.4.0
165
+                         */
166
+                        $parent_dropdown_args = apply_filters( 'post_edit_category_parent_dropdown_args', $parent_dropdown_args );
167 167
 
168
-						wp_dropdown_categories( $parent_dropdown_args );
169
-						?>
168
+                        wp_dropdown_categories( $parent_dropdown_args );
169
+                        ?>
170 170
 						<input type="button" id="<?php echo esc_attr( $tax_name ); ?>-add-submit"
171 171
 							   data-wp-lists="add:<?php echo esc_html( $tax_name ); ?>checklist:<?php echo esc_attr( $tax_name ); ?>-add"
172 172
 							   class="button category-add-submit"
@@ -178,6 +178,6 @@  discard block
 block discarded – undo
178 178
 			<?php endif; ?>
179 179
 		</div>
180 180
 		<?php
181
-	}
181
+    }
182 182
 
183 183
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 			get_post(),
29 29
 			array(
30 30
 				'args' =>
31
-					array( 'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ),
31
+					array('taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME),
32 32
 			)
33 33
 		);
34 34
 
@@ -43,47 +43,47 @@  discard block
 block discarded – undo
43 43
 	 *
44 44
 	 * @since 3.20.0
45 45
 	 */
46
-	private static function post_categories_meta_box( $post, $box ) {
47
-		$defaults = array( 'taxonomy' => 'category' );
48
-		if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) {
46
+	private static function post_categories_meta_box($post, $box) {
47
+		$defaults = array('taxonomy' => 'category');
48
+		if ( ! isset($box['args']) || ! is_array($box['args'])) {
49 49
 			$args = array();
50 50
 		} else {
51 51
 			$args = $box['args'];
52 52
 		}
53
-		$r        = wp_parse_args( $args, $defaults );
54
-		$tax_name = esc_attr( $r['taxonomy'] );
55
-		$taxonomy = get_taxonomy( $r['taxonomy'] );
53
+		$r        = wp_parse_args($args, $defaults);
54
+		$tax_name = esc_attr($r['taxonomy']);
55
+		$taxonomy = get_taxonomy($r['taxonomy']);
56 56
 		?>
57
-		<div id="taxonomy-<?php echo esc_attr( $tax_name ); ?>" class="categorydiv">
58
-			<ul id="<?php echo esc_attr( $tax_name ); ?>-tabs" class="category-tabs">
57
+		<div id="taxonomy-<?php echo esc_attr($tax_name); ?>" class="categorydiv">
58
+			<ul id="<?php echo esc_attr($tax_name); ?>-tabs" class="category-tabs">
59 59
 				<li class="tabs"><a
60
-							href="#<?php echo esc_attr( $tax_name ); ?>-all"><?php echo esc_html( $taxonomy->labels->all_items ); ?></a>
60
+							href="#<?php echo esc_attr($tax_name); ?>-all"><?php echo esc_html($taxonomy->labels->all_items); ?></a>
61 61
 				</li>
62 62
 				<li>
63
-					<a href="#<?php echo esc_attr( $tax_name ); ?>-pop"><?php echo esc_html__( 'Most Used', 'wordlift' ); ?></a>
63
+					<a href="#<?php echo esc_attr($tax_name); ?>-pop"><?php echo esc_html__('Most Used', 'wordlift'); ?></a>
64 64
 				</li>
65
-				<li><a href="#<?php echo esc_attr( $tax_name ); ?>-legacy">
66
-						<?php echo esc_html_x( 'A-Z', 'Entity Types metabox', 'wordlift' ); ?></a>
65
+				<li><a href="#<?php echo esc_attr($tax_name); ?>-legacy">
66
+						<?php echo esc_html_x('A-Z', 'Entity Types metabox', 'wordlift'); ?></a>
67 67
 				</li>
68 68
 			</ul>
69 69
 
70
-			<div id="<?php echo esc_attr( $tax_name ); ?>-all" class="tabs-panel">
70
+			<div id="<?php echo esc_attr($tax_name); ?>-all" class="tabs-panel">
71 71
 				<div id="wl-schema-class-tree"></div>
72 72
 			</div>
73 73
 
74
-			<div id="<?php echo esc_attr( $tax_name ); ?>-pop" class="tabs-panel" style="display: none;">
75
-				<ul id="<?php echo esc_attr( $tax_name ); ?>checklist-pop" class="categorychecklist form-no-clear">
76
-					<?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?>
74
+			<div id="<?php echo esc_attr($tax_name); ?>-pop" class="tabs-panel" style="display: none;">
75
+				<ul id="<?php echo esc_attr($tax_name); ?>checklist-pop" class="categorychecklist form-no-clear">
76
+					<?php $popular_ids = wp_popular_terms_checklist($tax_name); ?>
77 77
 				</ul>
78 78
 			</div>
79 79
 
80
-			<div id="<?php echo esc_attr( $tax_name ); ?>-legacy" class="tabs-panel" style="display: none;">
80
+			<div id="<?php echo esc_attr($tax_name); ?>-legacy" class="tabs-panel" style="display: none;">
81 81
 				<?php
82
-				$name = ( 'category' === $tax_name ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
82
+				$name = ('category' === $tax_name) ? 'post_category' : 'tax_input['.$tax_name.']';
83 83
 				echo wp_kses(
84 84
 					sprintf(
85 85
 						"<input type='hidden' name='%s[]' value='0' />",
86
-						esc_attr( $name )
86
+						esc_attr($name)
87 87
 					),
88 88
 					array(
89 89
 						'input' =>
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
 					)
96 96
 				); // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
97 97
 				?>
98
-				<ul id="<?php echo esc_attr( $tax_name ); ?>checklist"
99
-					data-wp-lists="list:<?php echo esc_attr( $tax_name ); ?>"
98
+				<ul id="<?php echo esc_attr($tax_name); ?>checklist"
99
+					data-wp-lists="list:<?php echo esc_attr($tax_name); ?>"
100 100
 					class="categorychecklist form-no-clear">
101 101
 					<?php
102 102
 					wp_terms_checklist(
@@ -109,35 +109,35 @@  discard block
 block discarded – undo
109 109
 					?>
110 110
 				</ul>
111 111
 			</div>
112
-			<?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?>
113
-				<div id="<?php echo esc_attr( $tax_name ); ?>-adder" class="wp-hidden-children">
114
-					<a id="<?php echo esc_attr( $tax_name ); ?>-add-toggle"
115
-					   href="#<?php echo esc_attr( $tax_name ); ?>-add"
112
+			<?php if (current_user_can($taxonomy->cap->edit_terms)) : ?>
113
+				<div id="<?php echo esc_attr($tax_name); ?>-adder" class="wp-hidden-children">
114
+					<a id="<?php echo esc_attr($tax_name); ?>-add-toggle"
115
+					   href="#<?php echo esc_attr($tax_name); ?>-add"
116 116
 					   class="taxonomy-add-new">
117 117
 						<?php
118 118
 						/* translators: %s: add new taxonomy label */
119
-						echo esc_html( sprintf( __( '+ %s', 'default' ), $taxonomy->labels->add_new_item ) );
119
+						echo esc_html(sprintf(__('+ %s', 'default'), $taxonomy->labels->add_new_item));
120 120
 						?>
121 121
 					</a>
122
-					<p id="<?php echo esc_attr( $tax_name ); ?>-add" class="category-add wp-hidden-child">
122
+					<p id="<?php echo esc_attr($tax_name); ?>-add" class="category-add wp-hidden-child">
123 123
 						<label class="screen-reader-text"
124
-							   for="new<?php echo esc_attr( $tax_name ); ?>"><?php echo esc_html( $taxonomy->labels->add_new_item ); ?></label>
125
-						<input type="text" name="new<?php echo esc_html( $tax_name ); ?>"
126
-							   id="new<?php echo esc_attr( $tax_name ); ?>"
124
+							   for="new<?php echo esc_attr($tax_name); ?>"><?php echo esc_html($taxonomy->labels->add_new_item); ?></label>
125
+						<input type="text" name="new<?php echo esc_html($tax_name); ?>"
126
+							   id="new<?php echo esc_attr($tax_name); ?>"
127 127
 							   class="form-required form-input-tip"
128
-							   value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>"
128
+							   value="<?php echo esc_attr($taxonomy->labels->new_item_name); ?>"
129 129
 							   aria-required="true"/>
130
-						<label class="screen-reader-text" for="new<?php echo esc_attr( $tax_name ); ?>_parent">
131
-							<?php echo esc_html( $taxonomy->labels->parent_item_colon ); ?>
130
+						<label class="screen-reader-text" for="new<?php echo esc_attr($tax_name); ?>_parent">
131
+							<?php echo esc_html($taxonomy->labels->parent_item_colon); ?>
132 132
 						</label>
133 133
 						<?php
134 134
 						$parent_dropdown_args = array(
135 135
 							'taxonomy'         => $tax_name,
136 136
 							'hide_empty'       => 0,
137
-							'name'             => 'new' . $tax_name . '_parent',
137
+							'name'             => 'new'.$tax_name.'_parent',
138 138
 							'orderby'          => 'name',
139 139
 							'hierarchical'     => 1,
140
-							'show_option_none' => '&mdash; ' . $taxonomy->labels->parent_item . ' &mdash;',
140
+							'show_option_none' => '&mdash; '.$taxonomy->labels->parent_item.' &mdash;',
141 141
 						);
142 142
 
143 143
 						/**
@@ -163,16 +163,16 @@  discard block
 block discarded – undo
163 163
 						 * }
164 164
 						 * @since 4.4.0
165 165
 						 */
166
-						$parent_dropdown_args = apply_filters( 'post_edit_category_parent_dropdown_args', $parent_dropdown_args );
166
+						$parent_dropdown_args = apply_filters('post_edit_category_parent_dropdown_args', $parent_dropdown_args);
167 167
 
168
-						wp_dropdown_categories( $parent_dropdown_args );
168
+						wp_dropdown_categories($parent_dropdown_args);
169 169
 						?>
170
-						<input type="button" id="<?php echo esc_attr( $tax_name ); ?>-add-submit"
171
-							   data-wp-lists="add:<?php echo esc_html( $tax_name ); ?>checklist:<?php echo esc_attr( $tax_name ); ?>-add"
170
+						<input type="button" id="<?php echo esc_attr($tax_name); ?>-add-submit"
171
+							   data-wp-lists="add:<?php echo esc_html($tax_name); ?>checklist:<?php echo esc_attr($tax_name); ?>-add"
172 172
 							   class="button category-add-submit"
173
-							   value="<?php echo esc_attr( $taxonomy->labels->add_new_item ); ?>"/>
174
-						<?php wp_nonce_field( 'add-' . $tax_name, '_ajax_nonce-add-' . $tax_name, false ); ?>
175
-						<span id="<?php echo esc_attr( $tax_name ); ?>-ajax-response"></span>
173
+							   value="<?php echo esc_attr($taxonomy->labels->add_new_item); ?>"/>
174
+						<?php wp_nonce_field('add-'.$tax_name, '_ajax_nonce-add-'.$tax_name, false); ?>
175
+						<span id="<?php echo esc_attr($tax_name); ?>-ajax-response"></span>
176 176
 					</p>
177 177
 				</div>
178 178
 			<?php endif; ?>
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-dashboard-v2.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -4,95 +4,95 @@  discard block
 block discarded – undo
4 4
 
5 5
 class Wordlift_Admin_Dashboard_V2 {
6 6
 
7
-	const TODAYS_TIP       = 'wl_todays_tip_data';
8
-	const AVERAGE_POSITION = 'wl_search_rankings_average_position';
9
-
10
-	/**
11
-	 * @var \Wordlift_Entity_Service $entity_service
12
-	 */
13
-	private $entity_service;
14
-
15
-	/**
16
-	 * Wordlift_Admin_Dashboard_V2 constructor.
17
-	 *
18
-	 * @since 3.20.0
19
-	 */
20
-	public function __construct( $entity_service ) {
21
-
22
-		add_action( 'wp_dashboard_setup', array( $this, 'dashboard_setup' ) );
23
-
24
-		// Define where to access the tip.
25
-		defined( 'WL_TODAYS_TIP_JSON_URL' ) || define( 'WL_TODAYS_TIP_JSON_URL', 'https://wordlift.io/blog' );
26
-		defined( 'WL_TODAYS_TIP_JSON_URL_IT' ) || define( 'WL_TODAYS_TIP_JSON_URL_IT', '/it/wp-json/wp/v2/posts?context=embed&per_page=1&categories=27' );
27
-		defined( 'WL_TODAYS_TIP_JSON_URL_EN' ) || define( 'WL_TODAYS_TIP_JSON_URL_EN', '/en/wp-json/wp/v2/posts?context=embed&per_page=1&categories=38' );
28
-		$this->entity_service = $entity_service;
29
-
30
-	}
31
-
32
-	/**
33
-	 * Set up the dashboard metabox.
34
-	 *
35
-	 * @since 3.20.0
36
-	 */
37
-	public function dashboard_setup() {
38
-		/**
39
-		 * Filter name: wl_feature__enable__wordlift-dashboard
40
-		 * Feature flag to enable / disable dashboard
41
-		 *
42
-		 * @since 3.30.0
43
-		 */
7
+    const TODAYS_TIP       = 'wl_todays_tip_data';
8
+    const AVERAGE_POSITION = 'wl_search_rankings_average_position';
9
+
10
+    /**
11
+     * @var \Wordlift_Entity_Service $entity_service
12
+     */
13
+    private $entity_service;
14
+
15
+    /**
16
+     * Wordlift_Admin_Dashboard_V2 constructor.
17
+     *
18
+     * @since 3.20.0
19
+     */
20
+    public function __construct( $entity_service ) {
21
+
22
+        add_action( 'wp_dashboard_setup', array( $this, 'dashboard_setup' ) );
23
+
24
+        // Define where to access the tip.
25
+        defined( 'WL_TODAYS_TIP_JSON_URL' ) || define( 'WL_TODAYS_TIP_JSON_URL', 'https://wordlift.io/blog' );
26
+        defined( 'WL_TODAYS_TIP_JSON_URL_IT' ) || define( 'WL_TODAYS_TIP_JSON_URL_IT', '/it/wp-json/wp/v2/posts?context=embed&per_page=1&categories=27' );
27
+        defined( 'WL_TODAYS_TIP_JSON_URL_EN' ) || define( 'WL_TODAYS_TIP_JSON_URL_EN', '/en/wp-json/wp/v2/posts?context=embed&per_page=1&categories=38' );
28
+        $this->entity_service = $entity_service;
29
+
30
+    }
31
+
32
+    /**
33
+     * Set up the dashboard metabox.
34
+     *
35
+     * @since 3.20.0
36
+     */
37
+    public function dashboard_setup() {
38
+        /**
39
+         * Filter name: wl_feature__enable__wordlift-dashboard
40
+         * Feature flag to enable / disable dashboard
41
+         *
42
+         * @since 3.30.0
43
+         */
44 44
         // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
45
-		if ( apply_filters( 'wl_feature__enable__wordlift-dashboard', true ) ) {
46
-			wp_add_dashboard_widget(
47
-				'wl-dashboard-v2',
48
-				__( 'WordLift Dashboard', 'wordlift' ),
49
-				array( $this, 'dashboard_setup_callback' )
50
-			);
51
-		}
52
-
53
-	}
54
-
55
-	/**
56
-	 * The dashboard setup callback.
57
-	 *
58
-	 * @since 3.20.0
59
-	 */
60
-	public function dashboard_setup_callback() {
61
-
62
-		require_once plugin_dir_path( __DIR__ ) . 'admin/partials/wordlift-admin-dashboard-v2.php';
63
-
64
-	}
65
-
66
-	/**
67
-	 * Get the top entities.
68
-	 *
69
-	 * @return array|object|null An array of top entities.
70
-	 * @since 3.20.0
71
-	 */
72
-	private function get_top_entities() {
73
-		/**
74
-		 * @since 3.27.7
75
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/1214
76
-		 * Top entities are generated by cron now.
77
-		 */
78
-		return get_option( Top_Entities::OPTION_KEY, array() );
79
-	}
80
-
81
-	/**
82
-	 * Get the today's tip block.
83
-	 *
84
-	 * @since 3.20.0
85
-	 */
86
-	public static function get_todays_tip_block() {
45
+        if ( apply_filters( 'wl_feature__enable__wordlift-dashboard', true ) ) {
46
+            wp_add_dashboard_widget(
47
+                'wl-dashboard-v2',
48
+                __( 'WordLift Dashboard', 'wordlift' ),
49
+                array( $this, 'dashboard_setup_callback' )
50
+            );
51
+        }
52
+
53
+    }
54
+
55
+    /**
56
+     * The dashboard setup callback.
57
+     *
58
+     * @since 3.20.0
59
+     */
60
+    public function dashboard_setup_callback() {
61
+
62
+        require_once plugin_dir_path( __DIR__ ) . 'admin/partials/wordlift-admin-dashboard-v2.php';
63
+
64
+    }
65
+
66
+    /**
67
+     * Get the top entities.
68
+     *
69
+     * @return array|object|null An array of top entities.
70
+     * @since 3.20.0
71
+     */
72
+    private function get_top_entities() {
73
+        /**
74
+         * @since 3.27.7
75
+         * @see https://github.com/insideout10/wordlift-plugin/issues/1214
76
+         * Top entities are generated by cron now.
77
+         */
78
+        return get_option( Top_Entities::OPTION_KEY, array() );
79
+    }
80
+
81
+    /**
82
+     * Get the today's tip block.
83
+     *
84
+     * @since 3.20.0
85
+     */
86
+    public static function get_todays_tip_block() {
87 87
 
88 88
         // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
89
-		$data = @self::get_todays_tip_data();
89
+        $data = @self::get_todays_tip_data();
90 90
 
91
-		// Unable to get data from the local cache, nor from the remote URL.
92
-		if ( false === $data ) {
93
-			return;
94
-		}
95
-		?>
91
+        // Unable to get data from the local cache, nor from the remote URL.
92
+        if ( false === $data ) {
93
+            return;
94
+        }
95
+        ?>
96 96
 
97 97
 		<div id="wl-todays-tip" class="wl-dashboard__block wl-dashboard__block--todays-tip">
98 98
 			<header>
@@ -107,52 +107,52 @@  discard block
 block discarded – undo
107 107
 		</div>
108 108
 		<?php
109 109
 
110
-	}
111
-
112
-	/**
113
-	 * Get the today's tip data.
114
-	 *
115
-	 * @return array|false The today's tip data or false in case of error.
116
-	 * @since 3.20.0
117
-	 */
118
-	private static function get_todays_tip_data() {
119
-
120
-		// Return the transient.
121
-		if ( false !== get_transient( self::TODAYS_TIP ) ) {
122
-			return get_transient( self::TODAYS_TIP );
123
-		}
124
-
125
-		// If the transient isn't available, query the remote web site.
126
-		$url = WL_TODAYS_TIP_JSON_URL
127
-			   . ( 'it' === get_bloginfo( 'language' ) ? WL_TODAYS_TIP_JSON_URL_IT : WL_TODAYS_TIP_JSON_URL_EN );
128
-
129
-		$response = wp_remote_get( $url );
130
-
131
-		if ( is_wp_error( $response )
132
-			 || ! isset( $response['response']['code'] )
133
-			 || 2 !== (int) $response['response']['code'] / 100 ) {
134
-			return false;
135
-		}
136
-
137
-		$json = json_decode( $response['body'], true );
138
-
139
-		if ( empty( $json )
140
-			 || ! isset( $json[0]['title']['rendered'] )
141
-			 || ! isset( $json[0]['excerpt']['rendered'] )
142
-			 || ! isset( $json[0]['link'] ) ) {
143
-			return false;
144
-		}
145
-
146
-		$value = array(
147
-			'title'   => $json[0]['title']['rendered'],
148
-			'excerpt' => '<!-- cached -->' . $json[0]['excerpt']['rendered'],
149
-			'link'    => $json[0]['link'],
150
-		);
151
-
152
-		// Store the results for one day.
153
-		set_transient( self::TODAYS_TIP, $value, 86400 );
154
-
155
-		return $value;
156
-	}
110
+    }
111
+
112
+    /**
113
+     * Get the today's tip data.
114
+     *
115
+     * @return array|false The today's tip data or false in case of error.
116
+     * @since 3.20.0
117
+     */
118
+    private static function get_todays_tip_data() {
119
+
120
+        // Return the transient.
121
+        if ( false !== get_transient( self::TODAYS_TIP ) ) {
122
+            return get_transient( self::TODAYS_TIP );
123
+        }
124
+
125
+        // If the transient isn't available, query the remote web site.
126
+        $url = WL_TODAYS_TIP_JSON_URL
127
+                . ( 'it' === get_bloginfo( 'language' ) ? WL_TODAYS_TIP_JSON_URL_IT : WL_TODAYS_TIP_JSON_URL_EN );
128
+
129
+        $response = wp_remote_get( $url );
130
+
131
+        if ( is_wp_error( $response )
132
+             || ! isset( $response['response']['code'] )
133
+             || 2 !== (int) $response['response']['code'] / 100 ) {
134
+            return false;
135
+        }
136
+
137
+        $json = json_decode( $response['body'], true );
138
+
139
+        if ( empty( $json )
140
+             || ! isset( $json[0]['title']['rendered'] )
141
+             || ! isset( $json[0]['excerpt']['rendered'] )
142
+             || ! isset( $json[0]['link'] ) ) {
143
+            return false;
144
+        }
145
+
146
+        $value = array(
147
+            'title'   => $json[0]['title']['rendered'],
148
+            'excerpt' => '<!-- cached -->' . $json[0]['excerpt']['rendered'],
149
+            'link'    => $json[0]['link'],
150
+        );
151
+
152
+        // Store the results for one day.
153
+        set_transient( self::TODAYS_TIP, $value, 86400 );
154
+
155
+        return $value;
156
+    }
157 157
 
158 158
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -17,14 +17,14 @@  discard block
 block discarded – undo
17 17
 	 *
18 18
 	 * @since 3.20.0
19 19
 	 */
20
-	public function __construct( $entity_service ) {
20
+	public function __construct($entity_service) {
21 21
 
22
-		add_action( 'wp_dashboard_setup', array( $this, 'dashboard_setup' ) );
22
+		add_action('wp_dashboard_setup', array($this, 'dashboard_setup'));
23 23
 
24 24
 		// Define where to access the tip.
25
-		defined( 'WL_TODAYS_TIP_JSON_URL' ) || define( 'WL_TODAYS_TIP_JSON_URL', 'https://wordlift.io/blog' );
26
-		defined( 'WL_TODAYS_TIP_JSON_URL_IT' ) || define( 'WL_TODAYS_TIP_JSON_URL_IT', '/it/wp-json/wp/v2/posts?context=embed&per_page=1&categories=27' );
27
-		defined( 'WL_TODAYS_TIP_JSON_URL_EN' ) || define( 'WL_TODAYS_TIP_JSON_URL_EN', '/en/wp-json/wp/v2/posts?context=embed&per_page=1&categories=38' );
25
+		defined('WL_TODAYS_TIP_JSON_URL') || define('WL_TODAYS_TIP_JSON_URL', 'https://wordlift.io/blog');
26
+		defined('WL_TODAYS_TIP_JSON_URL_IT') || define('WL_TODAYS_TIP_JSON_URL_IT', '/it/wp-json/wp/v2/posts?context=embed&per_page=1&categories=27');
27
+		defined('WL_TODAYS_TIP_JSON_URL_EN') || define('WL_TODAYS_TIP_JSON_URL_EN', '/en/wp-json/wp/v2/posts?context=embed&per_page=1&categories=38');
28 28
 		$this->entity_service = $entity_service;
29 29
 
30 30
 	}
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
 		 * @since 3.30.0
43 43
 		 */
44 44
         // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
45
-		if ( apply_filters( 'wl_feature__enable__wordlift-dashboard', true ) ) {
45
+		if (apply_filters('wl_feature__enable__wordlift-dashboard', true)) {
46 46
 			wp_add_dashboard_widget(
47 47
 				'wl-dashboard-v2',
48
-				__( 'WordLift Dashboard', 'wordlift' ),
49
-				array( $this, 'dashboard_setup_callback' )
48
+				__('WordLift Dashboard', 'wordlift'),
49
+				array($this, 'dashboard_setup_callback')
50 50
 			);
51 51
 		}
52 52
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 */
60 60
 	public function dashboard_setup_callback() {
61 61
 
62
-		require_once plugin_dir_path( __DIR__ ) . 'admin/partials/wordlift-admin-dashboard-v2.php';
62
+		require_once plugin_dir_path(__DIR__).'admin/partials/wordlift-admin-dashboard-v2.php';
63 63
 
64 64
 	}
65 65
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/1214
76 76
 		 * Top entities are generated by cron now.
77 77
 		 */
78
-		return get_option( Top_Entities::OPTION_KEY, array() );
78
+		return get_option(Top_Entities::OPTION_KEY, array());
79 79
 	}
80 80
 
81 81
 	/**
@@ -89,20 +89,20 @@  discard block
 block discarded – undo
89 89
 		$data = @self::get_todays_tip_data();
90 90
 
91 91
 		// Unable to get data from the local cache, nor from the remote URL.
92
-		if ( false === $data ) {
92
+		if (false === $data) {
93 93
 			return;
94 94
 		}
95 95
 		?>
96 96
 
97 97
 		<div id="wl-todays-tip" class="wl-dashboard__block wl-dashboard__block--todays-tip">
98 98
 			<header>
99
-				<h3><?php esc_html_e( "Today's Tip", 'wordlift' ); ?></h3>
99
+				<h3><?php esc_html_e("Today's Tip", 'wordlift'); ?></h3>
100 100
 			</header>
101 101
 			<article>
102
-				<p><strong><?php echo esc_html( wp_strip_all_tags( $data['title'] ) ); ?></strong>
103
-					<?php echo esc_html( wp_strip_all_tags( $data['excerpt'] ) ); ?>
102
+				<p><strong><?php echo esc_html(wp_strip_all_tags($data['title'])); ?></strong>
103
+					<?php echo esc_html(wp_strip_all_tags($data['excerpt'])); ?>
104 104
 					<a target="_blank"
105
-					   href="<?php echo esc_attr( $data['link'] ); ?>"><?php echo esc_html( __( 'Read more', 'wordlift' ) ); ?></a>
105
+					   href="<?php echo esc_attr($data['link']); ?>"><?php echo esc_html(__('Read more', 'wordlift')); ?></a>
106 106
 				</p>
107 107
 		</div>
108 108
 		<?php
@@ -118,39 +118,39 @@  discard block
 block discarded – undo
118 118
 	private static function get_todays_tip_data() {
119 119
 
120 120
 		// Return the transient.
121
-		if ( false !== get_transient( self::TODAYS_TIP ) ) {
122
-			return get_transient( self::TODAYS_TIP );
121
+		if (false !== get_transient(self::TODAYS_TIP)) {
122
+			return get_transient(self::TODAYS_TIP);
123 123
 		}
124 124
 
125 125
 		// If the transient isn't available, query the remote web site.
126 126
 		$url = WL_TODAYS_TIP_JSON_URL
127
-			   . ( 'it' === get_bloginfo( 'language' ) ? WL_TODAYS_TIP_JSON_URL_IT : WL_TODAYS_TIP_JSON_URL_EN );
127
+			   . ('it' === get_bloginfo('language') ? WL_TODAYS_TIP_JSON_URL_IT : WL_TODAYS_TIP_JSON_URL_EN);
128 128
 
129
-		$response = wp_remote_get( $url );
129
+		$response = wp_remote_get($url);
130 130
 
131
-		if ( is_wp_error( $response )
132
-			 || ! isset( $response['response']['code'] )
133
-			 || 2 !== (int) $response['response']['code'] / 100 ) {
131
+		if (is_wp_error($response)
132
+			 || ! isset($response['response']['code'])
133
+			 || 2 !== (int) $response['response']['code'] / 100) {
134 134
 			return false;
135 135
 		}
136 136
 
137
-		$json = json_decode( $response['body'], true );
137
+		$json = json_decode($response['body'], true);
138 138
 
139
-		if ( empty( $json )
140
-			 || ! isset( $json[0]['title']['rendered'] )
141
-			 || ! isset( $json[0]['excerpt']['rendered'] )
142
-			 || ! isset( $json[0]['link'] ) ) {
139
+		if (empty($json)
140
+			 || ! isset($json[0]['title']['rendered'])
141
+			 || ! isset($json[0]['excerpt']['rendered'])
142
+			 || ! isset($json[0]['link'])) {
143 143
 			return false;
144 144
 		}
145 145
 
146 146
 		$value = array(
147 147
 			'title'   => $json[0]['title']['rendered'],
148
-			'excerpt' => '<!-- cached -->' . $json[0]['excerpt']['rendered'],
148
+			'excerpt' => '<!-- cached -->'.$json[0]['excerpt']['rendered'],
149 149
 			'link'    => $json[0]['link'],
150 150
 		);
151 151
 
152 152
 		// Store the results for one day.
153
-		set_transient( self::TODAYS_TIP, $value, 86400 );
153
+		set_transient(self::TODAYS_TIP, $value, 86400);
154 154
 
155 155
 		return $value;
156 156
 	}
Please login to merge, or discard this patch.
src/wordlift.php 2 patches
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
 // If this file is called directly, abort.
35 35
 if ( ! defined( 'WPINC' ) ) {
36
-	die;
36
+    die;
37 37
 }
38 38
 
39 39
 define( 'WORDLIFT_VERSION', '3.37.2' );
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
  * @since 3.33.6
45 45
  */
46 46
 if ( ! apply_filters( 'wl_is_enabled', true ) ) {
47
-	return;
47
+    return;
48 48
 }
49 49
 
50 50
 require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
@@ -73,29 +73,29 @@  discard block
 block discarded – undo
73 73
  */
74 74
 function activate_wordlift() {
75 75
 
76
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
77
-
78
-	$log->info( 'Activating WordLift...' );
79
-
80
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
81
-	Wordlift_Activator::activate();
82
-
83
-	/**
84
-	 * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks.
85
-	 *
86
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue.
87
-	 * @since 3.19.2
88
-	 */
89
-	Wordlift_Http_Api::activate();
90
-
91
-	// Ensure the post type is registered before flushing the rewrite rules.
92
-	Wordlift_Entity_Post_Type_Service::get_instance()->register();
93
-	flush_rewrite_rules();
94
-	/**
95
-	 * @since 3.27.7
96
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/1214
97
-	 */
98
-	Top_Entities::activate();
76
+    $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
77
+
78
+    $log->info( 'Activating WordLift...' );
79
+
80
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
81
+    Wordlift_Activator::activate();
82
+
83
+    /**
84
+     * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks.
85
+     *
86
+     * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue.
87
+     * @since 3.19.2
88
+     */
89
+    Wordlift_Http_Api::activate();
90
+
91
+    // Ensure the post type is registered before flushing the rewrite rules.
92
+    Wordlift_Entity_Post_Type_Service::get_instance()->register();
93
+    flush_rewrite_rules();
94
+    /**
95
+     * @since 3.27.7
96
+     * @see https://github.com/insideout10/wordlift-plugin/issues/1214
97
+     */
98
+    Top_Entities::activate();
99 99
 }
100 100
 
101 101
 /**
@@ -104,21 +104,21 @@  discard block
 block discarded – undo
104 104
  */
105 105
 function deactivate_wordlift() {
106 106
 
107
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
108
-	Wordlift_Deactivator::deactivate();
109
-	Wordlift_Http_Api::deactivate();
110
-	Ttl_Cache_Cleaner::deactivate();
111
-	/**
112
-	 * @since 3.27.7
113
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/1214
114
-	 */
115
-	Top_Entities::deactivate();
116
-	/**
117
-	 * @since 3.27.8
118
-	 * Remove notification flag on deactivation.
119
-	 */
120
-	Key_Validation_Notice::remove_notification_flag();
121
-	flush_rewrite_rules();
107
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
108
+    Wordlift_Deactivator::deactivate();
109
+    Wordlift_Http_Api::deactivate();
110
+    Ttl_Cache_Cleaner::deactivate();
111
+    /**
112
+     * @since 3.27.7
113
+     * @see https://github.com/insideout10/wordlift-plugin/issues/1214
114
+     */
115
+    Top_Entities::deactivate();
116
+    /**
117
+     * @since 3.27.8
118
+     * Remove notification flag on deactivation.
119
+     */
120
+    Key_Validation_Notice::remove_notification_flag();
121
+    flush_rewrite_rules();
122 122
 
123 123
 }
124 124
 
@@ -141,84 +141,84 @@  discard block
 block discarded – undo
141 141
  * @since    1.0.0
142 142
  */
143 143
 function run_wordlift() {
144
-	/**
145
-	 * Filter: wl_feature__enable__widgets.
146
-	 *
147
-	 * @param bool whether the widgets needed to be registered, defaults to true.
148
-	 *
149
-	 * @return bool
150
-	 * @since 3.27.6
151
-	 */
152
-	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
153
-		add_action( 'widgets_init', 'wl_register_chord_widget' );
154
-		add_action( 'widgets_init', 'wl_register_geo_widget' );
155
-		add_action( 'widgets_init', 'wl_register_timeline_widget' );
156
-	}
157
-	add_filter( 'widget_text', 'do_shortcode' );
158
-
159
-	/**
160
-	 * Filter: wl_feature__enable__analysis
161
-	 *
162
-	 * @param bool Whether to send api request to analysis or not
163
-	 *
164
-	 * @return bool
165
-	 * @since 3.27.6
166
-	 */
167
-	if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
168
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
169
-	} else {
170
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
171
-	}
172
-
173
-	$plugin = new Wordlift();
174
-	$plugin->run();
175
-
176
-	// Initialize the TTL Cache Cleaner.
177
-	new Ttl_Cache_Cleaner();
178
-
179
-	// Load the new Post Adapter.
180
-	new Post_Adapter();
181
-
182
-	// Load the API Data Hooks.
183
-	new Api_Data_Hooks();
184
-
185
-	add_action(
186
-		'plugins_loaded',
187
-		function () {
188
-			// All features from registry should be initialized here.
189
-			$features_registry = Features_Registry::get_instance();
190
-			$features_registry->initialize_all_features();
191
-		},
192
-		5
193
-	);
194
-
195
-	add_action(
196
-		'plugins_loaded',
197
-		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
198
-		function () use ( $plugin ) {
199
-
200
-			new Wordlift_Products_Navigator_Shortcode_REST();
201
-
202
-			// Register the Dataset module, requires `$api_service`.
203
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
204
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php';
205
-
206
-			/*
144
+    /**
145
+     * Filter: wl_feature__enable__widgets.
146
+     *
147
+     * @param bool whether the widgets needed to be registered, defaults to true.
148
+     *
149
+     * @return bool
150
+     * @since 3.27.6
151
+     */
152
+    if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
153
+        add_action( 'widgets_init', 'wl_register_chord_widget' );
154
+        add_action( 'widgets_init', 'wl_register_geo_widget' );
155
+        add_action( 'widgets_init', 'wl_register_timeline_widget' );
156
+    }
157
+    add_filter( 'widget_text', 'do_shortcode' );
158
+
159
+    /**
160
+     * Filter: wl_feature__enable__analysis
161
+     *
162
+     * @param bool Whether to send api request to analysis or not
163
+     *
164
+     * @return bool
165
+     * @since 3.27.6
166
+     */
167
+    if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
168
+        add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
169
+    } else {
170
+        add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
171
+    }
172
+
173
+    $plugin = new Wordlift();
174
+    $plugin->run();
175
+
176
+    // Initialize the TTL Cache Cleaner.
177
+    new Ttl_Cache_Cleaner();
178
+
179
+    // Load the new Post Adapter.
180
+    new Post_Adapter();
181
+
182
+    // Load the API Data Hooks.
183
+    new Api_Data_Hooks();
184
+
185
+    add_action(
186
+        'plugins_loaded',
187
+        function () {
188
+            // All features from registry should be initialized here.
189
+            $features_registry = Features_Registry::get_instance();
190
+            $features_registry->initialize_all_features();
191
+        },
192
+        5
193
+    );
194
+
195
+    add_action(
196
+        'plugins_loaded',
197
+        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
198
+        function () use ( $plugin ) {
199
+
200
+            new Wordlift_Products_Navigator_Shortcode_REST();
201
+
202
+            // Register the Dataset module, requires `$api_service`.
203
+            require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
204
+            require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php';
205
+
206
+            /*
207 207
 			* Require the Entity annotation cleanup module.
208 208
 			*
209 209
 			* @since 3.34.6
210 210
 			*/
211
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php';
211
+            require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php';
212 212
 
213
-			/*
213
+            /*
214 214
 			* Import LOD entities.
215 215
 			*
216 216
 			* @since 3.35.0
217 217
 			*/
218
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php';
218
+            require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php';
219 219
 
220
-		}
221
-	);
220
+        }
221
+    );
222 222
 
223 223
 }
224 224
 
@@ -232,45 +232,45 @@  discard block
 block discarded – undo
232 232
  */
233 233
 function wordlift_plugin_autoload_register() {
234 234
 
235
-	spl_autoload_register(
236
-		function ( $class_name ) {
235
+    spl_autoload_register(
236
+        function ( $class_name ) {
237 237
 
238
-			// Bail out if these are not our classes.
239
-			if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
240
-				return false;
241
-			}
238
+            // Bail out if these are not our classes.
239
+            if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
240
+                return false;
241
+            }
242 242
 
243
-			$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
243
+            $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
244 244
 
245
-			preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
245
+            preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
246 246
 
247
-			$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
248
-			$file = 'class-' . $matches[2] . '.php';
247
+            $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
248
+            $file = 'class-' . $matches[2] . '.php';
249 249
 
250
-			$full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
250
+            $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
251 251
 
252
-			if ( ! file_exists( $full_path ) ) {
253
-				return false;
254
-			}
252
+            if ( ! file_exists( $full_path ) ) {
253
+                return false;
254
+            }
255 255
 
256
-			require_once $full_path;
256
+            require_once $full_path;
257 257
 
258
-			return true;
259
-		}
260
-	);
258
+            return true;
259
+        }
260
+    );
261 261
 
262 262
 }
263 263
 
264 264
 function wl_block_categories( $categories ) {
265
-	return array_merge(
266
-		$categories,
267
-		array(
268
-			array(
269
-				'slug'  => 'wordlift',
270
-				'title' => __( 'WordLift', 'wordlift' ),
271
-			),
272
-		)
273
-	);
265
+    return array_merge(
266
+        $categories,
267
+        array(
268
+            array(
269
+                'slug'  => 'wordlift',
270
+                'title' => __( 'WordLift', 'wordlift' ),
271
+            ),
272
+        )
273
+    );
274 274
 }
275 275
 
276 276
 /**
@@ -278,19 +278,19 @@  discard block
 block discarded – undo
278 278
  * this has to be removed when removing the legacy fields from the ui.
279 279
  */
280 280
 function wl_enqueue_leaflet( $in_footer = false ) {
281
-	// Leaflet.
282
-	wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' );
283
-	wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer );
281
+    // Leaflet.
282
+    wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' );
283
+    wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer );
284 284
 }
285 285
 
286 286
 add_filter( 'block_categories', 'wl_block_categories', 10 );
287 287
 
288 288
 // Temporary fix for a typo in WooCommerce Extension.
289 289
 add_filter(
290
-	'wl_feature__enable__dataset',
291
-	function ( $value ) {
292
-		return apply_filters( 'wl_features__enable__dataset', $value );
293
-	}
290
+    'wl_feature__enable__dataset',
291
+    function ( $value ) {
292
+        return apply_filters( 'wl_features__enable__dataset', $value );
293
+    }
294 294
 );
295 295
 
296 296
 require_once __DIR__ . '/modules/food-kg/load.php';
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -32,22 +32,22 @@  discard block
 block discarded – undo
32 32
 use Wordlift\Post\Post_Adapter;
33 33
 
34 34
 // If this file is called directly, abort.
35
-if ( ! defined( 'WPINC' ) ) {
35
+if ( ! defined('WPINC')) {
36 36
 	die;
37 37
 }
38 38
 
39
-define( 'WORDLIFT_VERSION', '3.37.2' );
39
+define('WORDLIFT_VERSION', '3.37.2');
40 40
 
41 41
 /**
42 42
  * Filter to disable WLP on any request, defaults to true.
43 43
  *
44 44
  * @since 3.33.6
45 45
  */
46
-if ( ! apply_filters( 'wl_is_enabled', true ) ) {
46
+if ( ! apply_filters('wl_is_enabled', true)) {
47 47
 	return;
48 48
 }
49 49
 
50
-require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
50
+require_once plugin_dir_path(__FILE__).'vendor/autoload.php';
51 51
 
52 52
 /*
53 53
 	 * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http.
@@ -57,15 +57,15 @@  discard block
 block discarded – undo
57 57
 wordlift_plugin_autoload_register();
58 58
 
59 59
 // Include WordLift constants.
60
-require_once plugin_dir_path( __FILE__ ) . 'wordlift-constants.php';
60
+require_once plugin_dir_path(__FILE__).'wordlift-constants.php';
61 61
 
62 62
 // Load modules.
63
-require_once plugin_dir_path( __FILE__ ) . 'modules/core/wordlift-core.php';
63
+require_once plugin_dir_path(__FILE__).'modules/core/wordlift-core.php';
64 64
 
65
-require_once plugin_dir_path( __FILE__ ) . 'deprecations.php';
65
+require_once plugin_dir_path(__FILE__).'deprecations.php';
66 66
 
67 67
 // Load early to enable/disable features.
68
-require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php';
68
+require_once plugin_dir_path(__FILE__).'wordlift/features/index.php';
69 69
 
70 70
 /**
71 71
  * The code that runs during plugin activation.
@@ -73,11 +73,11 @@  discard block
 block discarded – undo
73 73
  */
74 74
 function activate_wordlift() {
75 75
 
76
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
76
+	$log = Wordlift_Log_Service::get_logger('activate_wordlift');
77 77
 
78
-	$log->info( 'Activating WordLift...' );
78
+	$log->info('Activating WordLift...');
79 79
 
80
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
80
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php';
81 81
 	Wordlift_Activator::activate();
82 82
 
83 83
 	/**
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
  */
105 105
 function deactivate_wordlift() {
106 106
 
107
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
107
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php';
108 108
 	Wordlift_Deactivator::deactivate();
109 109
 	Wordlift_Http_Api::deactivate();
110 110
 	Ttl_Cache_Cleaner::deactivate();
@@ -122,14 +122,14 @@  discard block
 block discarded – undo
122 122
 
123 123
 }
124 124
 
125
-register_activation_hook( __FILE__, 'activate_wordlift' );
126
-register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
125
+register_activation_hook(__FILE__, 'activate_wordlift');
126
+register_deactivation_hook(__FILE__, 'deactivate_wordlift');
127 127
 
128 128
 /**
129 129
  * The core plugin class that is used to define internationalization,
130 130
  * admin-specific hooks, and public-facing site hooks.
131 131
  */
132
-require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
132
+require plugin_dir_path(__FILE__).'includes/class-wordlift.php';
133 133
 
134 134
 /**
135 135
  * Begins execution of the plugin.
@@ -149,12 +149,12 @@  discard block
 block discarded – undo
149 149
 	 * @return bool
150 150
 	 * @since 3.27.6
151 151
 	 */
152
-	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
153
-		add_action( 'widgets_init', 'wl_register_chord_widget' );
154
-		add_action( 'widgets_init', 'wl_register_geo_widget' );
155
-		add_action( 'widgets_init', 'wl_register_timeline_widget' );
152
+	if (apply_filters('wl_feature__enable__widgets', true)) {
153
+		add_action('widgets_init', 'wl_register_chord_widget');
154
+		add_action('widgets_init', 'wl_register_geo_widget');
155
+		add_action('widgets_init', 'wl_register_timeline_widget');
156 156
 	}
157
-	add_filter( 'widget_text', 'do_shortcode' );
157
+	add_filter('widget_text', 'do_shortcode');
158 158
 
159 159
 	/**
160 160
 	 * Filter: wl_feature__enable__analysis
@@ -164,10 +164,10 @@  discard block
 block discarded – undo
164 164
 	 * @return bool
165 165
 	 * @since 3.27.6
166 166
 	 */
167
-	if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
168
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
167
+	if (apply_filters('wl_feature__enable__analysis', true)) {
168
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action');
169 169
 	} else {
170
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
170
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action');
171 171
 	}
172 172
 
173 173
 	$plugin = new Wordlift();
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 
185 185
 	add_action(
186 186
 		'plugins_loaded',
187
-		function () {
187
+		function() {
188 188
 			// All features from registry should be initialized here.
189 189
 			$features_registry = Features_Registry::get_instance();
190 190
 			$features_registry->initialize_all_features();
@@ -195,27 +195,27 @@  discard block
 block discarded – undo
195 195
 	add_action(
196 196
 		'plugins_loaded',
197 197
 		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
198
-		function () use ( $plugin ) {
198
+		function() use ($plugin) {
199 199
 
200 200
 			new Wordlift_Products_Navigator_Shortcode_REST();
201 201
 
202 202
 			// Register the Dataset module, requires `$api_service`.
203
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
204
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php';
203
+			require_once plugin_dir_path(__FILE__).'wordlift/dataset/index.php';
204
+			require_once plugin_dir_path(__FILE__).'wordlift/shipping-data/index.php';
205 205
 
206 206
 			/*
207 207
 			* Require the Entity annotation cleanup module.
208 208
 			*
209 209
 			* @since 3.34.6
210 210
 			*/
211
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php';
211
+			require_once plugin_dir_path(__FILE__).'wordlift/cleanup/index.php';
212 212
 
213 213
 			/*
214 214
 			* Import LOD entities.
215 215
 			*
216 216
 			* @since 3.35.0
217 217
 			*/
218
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php';
218
+			require_once plugin_dir_path(__FILE__).'wordlift/lod-import/index.php';
219 219
 
220 220
 		}
221 221
 	);
@@ -233,23 +233,23 @@  discard block
 block discarded – undo
233 233
 function wordlift_plugin_autoload_register() {
234 234
 
235 235
 	spl_autoload_register(
236
-		function ( $class_name ) {
236
+		function($class_name) {
237 237
 
238 238
 			// Bail out if these are not our classes.
239
-			if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
239
+			if (0 !== strpos($class_name, 'Wordlift\\')) {
240 240
 				return false;
241 241
 			}
242 242
 
243
-			$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
243
+			$class_name_lc = strtolower(str_replace('_', '-', $class_name));
244 244
 
245
-			preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
245
+			preg_match('|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches);
246 246
 
247
-			$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
248
-			$file = 'class-' . $matches[2] . '.php';
247
+			$path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]);
248
+			$file = 'class-'.$matches[2].'.php';
249 249
 
250
-			$full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
250
+			$full_path = plugin_dir_path(__FILE__).$path.DIRECTORY_SEPARATOR.$file;
251 251
 
252
-			if ( ! file_exists( $full_path ) ) {
252
+			if ( ! file_exists($full_path)) {
253 253
 				return false;
254 254
 			}
255 255
 
@@ -261,13 +261,13 @@  discard block
 block discarded – undo
261 261
 
262 262
 }
263 263
 
264
-function wl_block_categories( $categories ) {
264
+function wl_block_categories($categories) {
265 265
 	return array_merge(
266 266
 		$categories,
267 267
 		array(
268 268
 			array(
269 269
 				'slug'  => 'wordlift',
270
-				'title' => __( 'WordLift', 'wordlift' ),
270
+				'title' => __('WordLift', 'wordlift'),
271 271
 			),
272 272
 		)
273 273
 	);
@@ -277,21 +277,21 @@  discard block
 block discarded – undo
277 277
  * This function is created temporarily to handle the legacy library,
278 278
  * this has to be removed when removing the legacy fields from the ui.
279 279
  */
280
-function wl_enqueue_leaflet( $in_footer = false ) {
280
+function wl_enqueue_leaflet($in_footer = false) {
281 281
 	// Leaflet.
282
-	wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' );
283
-	wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer );
282
+	wp_enqueue_style('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.css', array(), '1.6.0');
283
+	wp_enqueue_script('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer);
284 284
 }
285 285
 
286
-add_filter( 'block_categories', 'wl_block_categories', 10 );
286
+add_filter('block_categories', 'wl_block_categories', 10);
287 287
 
288 288
 // Temporary fix for a typo in WooCommerce Extension.
289 289
 add_filter(
290 290
 	'wl_feature__enable__dataset',
291
-	function ( $value ) {
292
-		return apply_filters( 'wl_features__enable__dataset', $value );
291
+	function($value) {
292
+		return apply_filters('wl_features__enable__dataset', $value);
293 293
 	}
294 294
 );
295 295
 
296
-require_once __DIR__ . '/modules/food-kg/load.php';
297
-require_once __DIR__ . '/modules/acf4so/load.php';
296
+require_once __DIR__.'/modules/food-kg/load.php';
297
+require_once __DIR__.'/modules/acf4so/load.php';
Please login to merge, or discard this patch.
src/shortcodes/wordlift-shortcode-field.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -11,36 +11,36 @@
 block discarded – undo
11 11
  */
12 12
 function wl_shortcode_field( $atts ) {
13 13
 
14
-	// Extract attributes and set default values.
15
-	$field_atts = shortcode_atts(
16
-		array(
17
-			'id'   => null,
18
-			'name' => null,
19
-		),
20
-		$atts
21
-	);
22
-
23
-	// Get id of the post
24
-	$entity_id = $field_atts['id'];
25
-	if ( $field_atts['id'] === null || ! is_numeric( $field_atts['id'] ) ) {
26
-		$entity_id = get_the_ID();
27
-	}
28
-
29
-	$property_name = $field_atts['name'];
30
-	if ( $property_name !== null ) {
31
-		$values = wl_schema_get_value( $entity_id, $property_name );
32
-	}
33
-
34
-	// Return
35
-	if ( is_array( $values ) ) {
36
-		return implode( ', ', $values );
37
-	} else {
38
-		return null;
39
-	}
14
+    // Extract attributes and set default values.
15
+    $field_atts = shortcode_atts(
16
+        array(
17
+            'id'   => null,
18
+            'name' => null,
19
+        ),
20
+        $atts
21
+    );
22
+
23
+    // Get id of the post
24
+    $entity_id = $field_atts['id'];
25
+    if ( $field_atts['id'] === null || ! is_numeric( $field_atts['id'] ) ) {
26
+        $entity_id = get_the_ID();
27
+    }
28
+
29
+    $property_name = $field_atts['name'];
30
+    if ( $property_name !== null ) {
31
+        $values = wl_schema_get_value( $entity_id, $property_name );
32
+    }
33
+
34
+    // Return
35
+    if ( is_array( $values ) ) {
36
+        return implode( ', ', $values );
37
+    } else {
38
+        return null;
39
+    }
40 40
 }
41 41
 
42 42
 function wl_register_shortcode_field() {
43
-	add_shortcode( 'wl_field', 'wl_shortcode_field' );
43
+    add_shortcode( 'wl_field', 'wl_shortcode_field' );
44 44
 }
45 45
 
46 46
 add_action( 'init', 'wl_register_shortcode_field' );
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * @param array $atts An array of shortcode attributes.
10 10
  * @return string A dom element with requested property value(s).
11 11
  */
12
-function wl_shortcode_field( $atts ) {
12
+function wl_shortcode_field($atts) {
13 13
 
14 14
 	// Extract attributes and set default values.
15 15
 	$field_atts = shortcode_atts(
@@ -22,26 +22,26 @@  discard block
 block discarded – undo
22 22
 
23 23
 	// Get id of the post
24 24
 	$entity_id = $field_atts['id'];
25
-	if ( $field_atts['id'] === null || ! is_numeric( $field_atts['id'] ) ) {
25
+	if ($field_atts['id'] === null || ! is_numeric($field_atts['id'])) {
26 26
 		$entity_id = get_the_ID();
27 27
 	}
28 28
 
29 29
 	$property_name = $field_atts['name'];
30
-	if ( $property_name !== null ) {
31
-		$values = wl_schema_get_value( $entity_id, $property_name );
30
+	if ($property_name !== null) {
31
+		$values = wl_schema_get_value($entity_id, $property_name);
32 32
 	}
33 33
 
34 34
 	// Return
35
-	if ( is_array( $values ) ) {
36
-		return implode( ', ', $values );
35
+	if (is_array($values)) {
36
+		return implode(', ', $values);
37 37
 	} else {
38 38
 		return null;
39 39
 	}
40 40
 }
41 41
 
42 42
 function wl_register_shortcode_field() {
43
-	add_shortcode( 'wl_field', 'wl_shortcode_field' );
43
+	add_shortcode('wl_field', 'wl_shortcode_field');
44 44
 }
45 45
 
46
-add_action( 'init', 'wl_register_shortcode_field' );
46
+add_action('init', 'wl_register_shortcode_field');
47 47
 
Please login to merge, or discard this patch.
src/shortcodes/class-wordlift-shortcode-rest.php 2 patches
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -10,131 +10,131 @@
 block discarded – undo
10 10
  */
11 11
 abstract class Wordlift_Shortcode_REST {
12 12
 
13
-	/**
14
-	 * The cache_ttl, set by extending classes.
15
-	 */
16
-	const CACHE_TTL = 86400; // 24 hours
17
-
18
-	public function __construct( $endpoint, $args ) {
19
-
20
-		$scope          = $this;
21
-		$this->endpoint = $endpoint;
22
-		$this->args     = $args;
23
-
24
-		// Register rest route with callback
25
-		add_action(
26
-			'rest_api_init',
27
-			function () use ( $scope ) {
28
-				register_rest_route(
29
-					WL_REST_ROUTE_DEFAULT_NAMESPACE,
30
-					$scope->endpoint,
31
-					array(
32
-						'methods'             => WP_REST_Server::READABLE,
33
-						'permission_callback' => '__return_true',
34
-						'callback'            => array( $scope, 'rest_callback' ),
35
-						'args'                => $scope->args,
36
-					)
37
-				);
38
-			}
39
-		);
40
-
41
-		// Optimizations: disable unneeded plugins on this specific REST call. WPSeo is slowing down the responses quite a bit.
42
-		add_action(
43
-			'plugins_loaded',
44
-			function () use ( $scope ) {
45
-
46
-				if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST || ! $scope->is_endpoint() ) {
47
-					return;
48
-				}
49
-
50
-				remove_action( 'plugins_loaded', 'rocket_init' );
51
-				remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
52
-				remove_action( 'plugins_loaded', 'wpseo_init', 14 );
53
-			},
54
-			0
55
-		);
56
-
57
-		add_action(
58
-			'init',
59
-			function () use ( $scope ) {
60
-
61
-				if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST || ! $scope->is_endpoint() ) {
62
-					return;
63
-				}
64
-
65
-				remove_action( 'init', 'wp_widgets_init', 1 );
66
-				remove_action( 'init', 'gglcptch_init' );
67
-			},
68
-			0
69
-		);
70
-
71
-	}
72
-
73
-	abstract public function get_data( $request );
74
-
75
-	public function rest_callback( WP_REST_Request $request ) {
76
-
77
-		// Respond from origin if TTL is 0
78
-		if ( static::CACHE_TTL === 0 ) {
79
-
80
-			$data     = $this->get_data( $request );
81
-			$response = rest_ensure_response( $data );
82
-			if ( is_wp_error( $data ) ) {
83
-				return $response;
84
-			}
85
-			$response->header( 'Access-Control-Allow-Origin', '*' );
86
-			$response->header( 'X-WordLift-Cache', 'MISS' );
87
-
88
-			return $response;
89
-		}
90
-
91
-		// Create the cache key.
92
-		$cache_key_params = $request->get_params();
93
-		unset( $cache_key_params['uniqid'] );
94
-		unset( $cache_key_params['rest_route'] );
95
-		$cache_key = array( 'request_params' => $cache_key_params );
96
-
97
-		// Create the TTL cache and try to get the results.
98
-		$cache         = new Ttl_Cache( $this->endpoint, static::CACHE_TTL );
99
-		$cache_results = $cache->get( $cache_key );
100
-
101
-		if ( isset( $cache_results ) ) {
102
-
103
-			$response = rest_ensure_response( $cache_results );
104
-			$response->header( 'Access-Control-Allow-Origin', '*' );
105
-			$response->header( 'X-WordLift-Cache', 'HIT' );
106
-
107
-			return $response;
108
-		}
109
-
110
-		$data     = $this->get_data( $request );
111
-		$response = rest_ensure_response( $data );
112
-		if ( is_wp_error( $data ) ) {
113
-			return $response;
114
-		}
115
-		$response->header( 'Access-Control-Allow-Origin', '*' );
116
-		$response->header( 'X-WordLift-Cache', 'MISS' );
117
-
118
-		// Put the result before sending the json to the client, since sending the json will terminate us.
119
-		$cache->put( $cache_key, $data );
120
-
121
-		return $response;
122
-
123
-	}
124
-
125
-	private function is_endpoint() {
126
-		$compare_route = WL_REST_ROUTE_DEFAULT_NAMESPACE . $this->endpoint;
127
-
128
-		// Directly accessing $_SERVER['REQUEST_URI'] or $_GET['rest_route'] here as it's too early to use global $wp reliably
129
-
130
-		if ( isset( $_SERVER['REQUEST_URI'] ) && strpos( esc_url_raw( wp_unslash( (string) $_SERVER['REQUEST_URI'] ) ), $compare_route ) ) {
131
-			return true;
132
-		}
133
-		if ( ! empty( $_GET['rest_route'] ) && strpos( esc_url_raw( wp_unslash( (string) $_GET['rest_route'] ) ), $compare_route ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
134
-			return true;
135
-		}
13
+    /**
14
+     * The cache_ttl, set by extending classes.
15
+     */
16
+    const CACHE_TTL = 86400; // 24 hours
17
+
18
+    public function __construct( $endpoint, $args ) {
19
+
20
+        $scope          = $this;
21
+        $this->endpoint = $endpoint;
22
+        $this->args     = $args;
23
+
24
+        // Register rest route with callback
25
+        add_action(
26
+            'rest_api_init',
27
+            function () use ( $scope ) {
28
+                register_rest_route(
29
+                    WL_REST_ROUTE_DEFAULT_NAMESPACE,
30
+                    $scope->endpoint,
31
+                    array(
32
+                        'methods'             => WP_REST_Server::READABLE,
33
+                        'permission_callback' => '__return_true',
34
+                        'callback'            => array( $scope, 'rest_callback' ),
35
+                        'args'                => $scope->args,
36
+                    )
37
+                );
38
+            }
39
+        );
40
+
41
+        // Optimizations: disable unneeded plugins on this specific REST call. WPSeo is slowing down the responses quite a bit.
42
+        add_action(
43
+            'plugins_loaded',
44
+            function () use ( $scope ) {
45
+
46
+                if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST || ! $scope->is_endpoint() ) {
47
+                    return;
48
+                }
49
+
50
+                remove_action( 'plugins_loaded', 'rocket_init' );
51
+                remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
52
+                remove_action( 'plugins_loaded', 'wpseo_init', 14 );
53
+            },
54
+            0
55
+        );
56
+
57
+        add_action(
58
+            'init',
59
+            function () use ( $scope ) {
60
+
61
+                if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST || ! $scope->is_endpoint() ) {
62
+                    return;
63
+                }
64
+
65
+                remove_action( 'init', 'wp_widgets_init', 1 );
66
+                remove_action( 'init', 'gglcptch_init' );
67
+            },
68
+            0
69
+        );
70
+
71
+    }
72
+
73
+    abstract public function get_data( $request );
74
+
75
+    public function rest_callback( WP_REST_Request $request ) {
76
+
77
+        // Respond from origin if TTL is 0
78
+        if ( static::CACHE_TTL === 0 ) {
79
+
80
+            $data     = $this->get_data( $request );
81
+            $response = rest_ensure_response( $data );
82
+            if ( is_wp_error( $data ) ) {
83
+                return $response;
84
+            }
85
+            $response->header( 'Access-Control-Allow-Origin', '*' );
86
+            $response->header( 'X-WordLift-Cache', 'MISS' );
87
+
88
+            return $response;
89
+        }
90
+
91
+        // Create the cache key.
92
+        $cache_key_params = $request->get_params();
93
+        unset( $cache_key_params['uniqid'] );
94
+        unset( $cache_key_params['rest_route'] );
95
+        $cache_key = array( 'request_params' => $cache_key_params );
96
+
97
+        // Create the TTL cache and try to get the results.
98
+        $cache         = new Ttl_Cache( $this->endpoint, static::CACHE_TTL );
99
+        $cache_results = $cache->get( $cache_key );
100
+
101
+        if ( isset( $cache_results ) ) {
102
+
103
+            $response = rest_ensure_response( $cache_results );
104
+            $response->header( 'Access-Control-Allow-Origin', '*' );
105
+            $response->header( 'X-WordLift-Cache', 'HIT' );
106
+
107
+            return $response;
108
+        }
109
+
110
+        $data     = $this->get_data( $request );
111
+        $response = rest_ensure_response( $data );
112
+        if ( is_wp_error( $data ) ) {
113
+            return $response;
114
+        }
115
+        $response->header( 'Access-Control-Allow-Origin', '*' );
116
+        $response->header( 'X-WordLift-Cache', 'MISS' );
117
+
118
+        // Put the result before sending the json to the client, since sending the json will terminate us.
119
+        $cache->put( $cache_key, $data );
120
+
121
+        return $response;
122
+
123
+    }
124
+
125
+    private function is_endpoint() {
126
+        $compare_route = WL_REST_ROUTE_DEFAULT_NAMESPACE . $this->endpoint;
127
+
128
+        // Directly accessing $_SERVER['REQUEST_URI'] or $_GET['rest_route'] here as it's too early to use global $wp reliably
129
+
130
+        if ( isset( $_SERVER['REQUEST_URI'] ) && strpos( esc_url_raw( wp_unslash( (string) $_SERVER['REQUEST_URI'] ) ), $compare_route ) ) {
131
+            return true;
132
+        }
133
+        if ( ! empty( $_GET['rest_route'] ) && strpos( esc_url_raw( wp_unslash( (string) $_GET['rest_route'] ) ), $compare_route ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
134
+            return true;
135
+        }
136 136
 
137
-		return false;
138
-	}
137
+        return false;
138
+    }
139 139
 
140 140
 }
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	 */
16 16
 	const CACHE_TTL = 86400; // 24 hours
17 17
 
18
-	public function __construct( $endpoint, $args ) {
18
+	public function __construct($endpoint, $args) {
19 19
 
20 20
 		$scope          = $this;
21 21
 		$this->endpoint = $endpoint;
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
 		// Register rest route with callback
25 25
 		add_action(
26 26
 			'rest_api_init',
27
-			function () use ( $scope ) {
27
+			function() use ($scope) {
28 28
 				register_rest_route(
29 29
 					WL_REST_ROUTE_DEFAULT_NAMESPACE,
30 30
 					$scope->endpoint,
31 31
 					array(
32 32
 						'methods'             => WP_REST_Server::READABLE,
33 33
 						'permission_callback' => '__return_true',
34
-						'callback'            => array( $scope, 'rest_callback' ),
34
+						'callback'            => array($scope, 'rest_callback'),
35 35
 						'args'                => $scope->args,
36 36
 					)
37 37
 				);
@@ -41,96 +41,96 @@  discard block
 block discarded – undo
41 41
 		// Optimizations: disable unneeded plugins on this specific REST call. WPSeo is slowing down the responses quite a bit.
42 42
 		add_action(
43 43
 			'plugins_loaded',
44
-			function () use ( $scope ) {
44
+			function() use ($scope) {
45 45
 
46
-				if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST || ! $scope->is_endpoint() ) {
46
+				if ( ! defined('REST_REQUEST') || ! REST_REQUEST || ! $scope->is_endpoint()) {
47 47
 					return;
48 48
 				}
49 49
 
50
-				remove_action( 'plugins_loaded', 'rocket_init' );
51
-				remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
52
-				remove_action( 'plugins_loaded', 'wpseo_init', 14 );
50
+				remove_action('plugins_loaded', 'rocket_init');
51
+				remove_action('plugins_loaded', 'wpseo_premium_init', 14);
52
+				remove_action('plugins_loaded', 'wpseo_init', 14);
53 53
 			},
54 54
 			0
55 55
 		);
56 56
 
57 57
 		add_action(
58 58
 			'init',
59
-			function () use ( $scope ) {
59
+			function() use ($scope) {
60 60
 
61
-				if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST || ! $scope->is_endpoint() ) {
61
+				if ( ! defined('REST_REQUEST') || ! REST_REQUEST || ! $scope->is_endpoint()) {
62 62
 					return;
63 63
 				}
64 64
 
65
-				remove_action( 'init', 'wp_widgets_init', 1 );
66
-				remove_action( 'init', 'gglcptch_init' );
65
+				remove_action('init', 'wp_widgets_init', 1);
66
+				remove_action('init', 'gglcptch_init');
67 67
 			},
68 68
 			0
69 69
 		);
70 70
 
71 71
 	}
72 72
 
73
-	abstract public function get_data( $request );
73
+	abstract public function get_data($request);
74 74
 
75
-	public function rest_callback( WP_REST_Request $request ) {
75
+	public function rest_callback(WP_REST_Request $request) {
76 76
 
77 77
 		// Respond from origin if TTL is 0
78
-		if ( static::CACHE_TTL === 0 ) {
78
+		if (static::CACHE_TTL === 0) {
79 79
 
80
-			$data     = $this->get_data( $request );
81
-			$response = rest_ensure_response( $data );
82
-			if ( is_wp_error( $data ) ) {
80
+			$data     = $this->get_data($request);
81
+			$response = rest_ensure_response($data);
82
+			if (is_wp_error($data)) {
83 83
 				return $response;
84 84
 			}
85
-			$response->header( 'Access-Control-Allow-Origin', '*' );
86
-			$response->header( 'X-WordLift-Cache', 'MISS' );
85
+			$response->header('Access-Control-Allow-Origin', '*');
86
+			$response->header('X-WordLift-Cache', 'MISS');
87 87
 
88 88
 			return $response;
89 89
 		}
90 90
 
91 91
 		// Create the cache key.
92 92
 		$cache_key_params = $request->get_params();
93
-		unset( $cache_key_params['uniqid'] );
94
-		unset( $cache_key_params['rest_route'] );
95
-		$cache_key = array( 'request_params' => $cache_key_params );
93
+		unset($cache_key_params['uniqid']);
94
+		unset($cache_key_params['rest_route']);
95
+		$cache_key = array('request_params' => $cache_key_params);
96 96
 
97 97
 		// Create the TTL cache and try to get the results.
98
-		$cache         = new Ttl_Cache( $this->endpoint, static::CACHE_TTL );
99
-		$cache_results = $cache->get( $cache_key );
98
+		$cache         = new Ttl_Cache($this->endpoint, static::CACHE_TTL);
99
+		$cache_results = $cache->get($cache_key);
100 100
 
101
-		if ( isset( $cache_results ) ) {
101
+		if (isset($cache_results)) {
102 102
 
103
-			$response = rest_ensure_response( $cache_results );
104
-			$response->header( 'Access-Control-Allow-Origin', '*' );
105
-			$response->header( 'X-WordLift-Cache', 'HIT' );
103
+			$response = rest_ensure_response($cache_results);
104
+			$response->header('Access-Control-Allow-Origin', '*');
105
+			$response->header('X-WordLift-Cache', 'HIT');
106 106
 
107 107
 			return $response;
108 108
 		}
109 109
 
110
-		$data     = $this->get_data( $request );
111
-		$response = rest_ensure_response( $data );
112
-		if ( is_wp_error( $data ) ) {
110
+		$data     = $this->get_data($request);
111
+		$response = rest_ensure_response($data);
112
+		if (is_wp_error($data)) {
113 113
 			return $response;
114 114
 		}
115
-		$response->header( 'Access-Control-Allow-Origin', '*' );
116
-		$response->header( 'X-WordLift-Cache', 'MISS' );
115
+		$response->header('Access-Control-Allow-Origin', '*');
116
+		$response->header('X-WordLift-Cache', 'MISS');
117 117
 
118 118
 		// Put the result before sending the json to the client, since sending the json will terminate us.
119
-		$cache->put( $cache_key, $data );
119
+		$cache->put($cache_key, $data);
120 120
 
121 121
 		return $response;
122 122
 
123 123
 	}
124 124
 
125 125
 	private function is_endpoint() {
126
-		$compare_route = WL_REST_ROUTE_DEFAULT_NAMESPACE . $this->endpoint;
126
+		$compare_route = WL_REST_ROUTE_DEFAULT_NAMESPACE.$this->endpoint;
127 127
 
128 128
 		// Directly accessing $_SERVER['REQUEST_URI'] or $_GET['rest_route'] here as it's too early to use global $wp reliably
129 129
 
130
-		if ( isset( $_SERVER['REQUEST_URI'] ) && strpos( esc_url_raw( wp_unslash( (string) $_SERVER['REQUEST_URI'] ) ), $compare_route ) ) {
130
+		if (isset($_SERVER['REQUEST_URI']) && strpos(esc_url_raw(wp_unslash((string) $_SERVER['REQUEST_URI'])), $compare_route)) {
131 131
 			return true;
132 132
 		}
133
-		if ( ! empty( $_GET['rest_route'] ) && strpos( esc_url_raw( wp_unslash( (string) $_GET['rest_route'] ) ), $compare_route ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
133
+		if ( ! empty($_GET['rest_route']) && strpos(esc_url_raw(wp_unslash((string) $_GET['rest_route'])), $compare_route)) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
134 134
 			return true;
135 135
 		}
136 136
 
Please login to merge, or discard this patch.
src/shortcodes/wordlift-shortcode-navigator.php 2 patches
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -19,168 +19,168 @@  discard block
 block discarded – undo
19 19
  */
20 20
 function wl_shortcode_navigator_data() {
21 21
 
22
-	// Create the cache key.
23
-	$cache_key_params = $_REQUEST; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
24
-	unset( $cache_key_params['uniqid'] );
25
-	$cache_key = array( 'request_params' => $cache_key_params );
22
+    // Create the cache key.
23
+    $cache_key_params = $_REQUEST; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
24
+    unset( $cache_key_params['uniqid'] );
25
+    $cache_key = array( 'request_params' => $cache_key_params );
26 26
 
27
-	// Create the TTL cache and try to get the results.
28
-	$cache         = new Ttl_Cache( 'navigator', 8 * 60 * 60 ); // 8 hours.
29
-	$cache_results = $cache->get( $cache_key );
27
+    // Create the TTL cache and try to get the results.
28
+    $cache         = new Ttl_Cache( 'navigator', 8 * 60 * 60 ); // 8 hours.
29
+    $cache_results = $cache->get( $cache_key );
30 30
 
31
-	// So that the endpoint can be used remotely
32
-	header( 'Access-Control-Allow-Origin: *' );
31
+    // So that the endpoint can be used remotely
32
+    header( 'Access-Control-Allow-Origin: *' );
33 33
 
34
-	if ( isset( $cache_results ) ) {
35
-		header( 'X-WordLift-Cache: HIT' );
34
+    if ( isset( $cache_results ) ) {
35
+        header( 'X-WordLift-Cache: HIT' );
36 36
 
37
-		return $cache_results;
38
-	}
37
+        return $cache_results;
38
+    }
39 39
 
40
-	header( 'X-WordLift-Cache: MISS' );
40
+    header( 'X-WordLift-Cache: MISS' );
41 41
 
42
-	$results = _wl_navigator_get_data();
42
+    $results = _wl_navigator_get_data();
43 43
 
44
-	// Put the result before sending the json to the client, since sending the json will terminate us.
45
-	$cache->put( $cache_key, $results );
44
+    // Put the result before sending the json to the client, since sending the json will terminate us.
45
+    $cache->put( $cache_key, $results );
46 46
 
47
-	return $results;
47
+    return $results;
48 48
 }
49 49
 
50 50
 
51 51
 function _wl_navigator_get_data() {
52 52
 
53
-	check_ajax_referer( 'wl_navigator' );
54
-
55
-	// Post ID must be defined
56
-	if ( ! isset( $_GET['post_id'] ) ) {
57
-		wp_send_json_error( 'No post_id given' );
58
-
59
-		return array();
60
-	}
61
-
62
-	// Post ID must be defined
63
-	if ( ! isset( $_GET['uniqid'] ) ) {
64
-		wp_send_json_error( 'No uniqid given' );
65
-
66
-		return array();
67
-	}
68
-
69
-	// Limit the results (defaults to 4)
70
-	$navigator_length    = isset( $_GET['limit'] ) ? intval( $_GET['limit'] ) : 4;
71
-	$navigator_offset    = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0;
72
-	$order_by            = isset( $_GET['sort'] ) ? sanitize_sql_orderby( wp_unslash( $_GET['sort'] ) ) : 'ID DESC';
73
-	$post_types          = isset( $_GET['post_types'] ) ? sanitize_text_field( wp_unslash( $_GET['post_types'] ) ) : '';
74
-	$post_types          = explode( ',', $post_types );
75
-	$existing_post_types = get_post_types();
76
-	$post_types          = array_values( array_intersect( $existing_post_types, $post_types ) );
77
-	$current_post_id     = (int) $_GET['post_id'];
78
-	$current_post        = get_post( $current_post_id );
79
-
80
-	$navigator_id = sanitize_text_field( wp_unslash( $_GET['uniqid'] ) );
81
-
82
-	// Post ID has to match an existing item
83
-	if ( null === $current_post ) {
84
-		wp_send_json_error( 'No valid post_id given' );
85
-
86
-		return array();
87
-	}
88
-
89
-	// Determine navigator type and call respective _get_results
90
-	if ( get_post_type( $current_post_id ) === Wordlift_Entity_Service::TYPE_NAME ) {
91
-
92
-		$referencing_posts = Navigator_Data::entity_navigator_get_results(
93
-			$current_post_id,
94
-			array(
95
-				'ID',
96
-				'post_title',
97
-			),
98
-			$order_by,
99
-			$navigator_length,
100
-			$navigator_offset,
101
-			$post_types
102
-		);
103
-	} else {
104
-		$referencing_posts = Navigator_Data::post_navigator_get_results(
105
-			$current_post_id,
106
-			array(
107
-				'ID',
108
-				'post_title',
109
-			),
110
-			$order_by,
111
-			$navigator_length,
112
-			$navigator_offset,
113
-			$post_types
114
-		);
115
-
116
-	}
117
-
118
-	// loop over them and take the first one which is not already in the $related_posts
119
-	$results = array();
120
-	foreach ( $referencing_posts as $referencing_post ) {
121
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
122
-
123
-		/**
124
-		 * Use the thumbnail.
125
-		 *
126
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
127
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/837
128
-		 *
129
-		 * @since 3.19.3 We're using the medium size image.
130
-		 */
131
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
132
-
133
-		$result = array(
134
-			'post'   => array(
135
-				'id'        => $referencing_post->ID,
136
-				'permalink' => get_permalink( $referencing_post->ID ),
137
-				'title'     => html_entity_decode( $referencing_post->post_title, ENT_QUOTES, 'UTF-8' ),
138
-				'thumbnail' => $thumbnail,
139
-				'srcset'    => Srcset_Util::get_srcset( $referencing_post->ID, Srcset_Util::NAVIGATOR_WIDGET ),
140
-			),
141
-			'entity' => array(
142
-				'id'        => $referencing_post->entity_id,
143
-				'label'     => $serialized_entity['label'],
144
-				'mainType'  => $serialized_entity['mainType'],
145
-				'permalink' => get_permalink( $referencing_post->entity_id ),
146
-			),
147
-		);
148
-
149
-		$results[] = $result;
150
-	}
151
-
152
-	if ( count( $results ) < $navigator_length ) {
153
-		$results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
154
-	}
155
-
156
-	// Add filler posts if needed
157
-	$filler_count = $navigator_length - count( $results );
158
-	if ( $filler_count > 0 ) {
159
-		$referencing_post_ids = array_map(
160
-			function ( $p ) {
161
-				return $p->ID;
162
-			},
163
-			$referencing_posts
164
-		);
165
-		/**
166
-		 * @since 3.27.8
167
-		 * Filler posts are fetched using this util.
168
-		 */
169
-		$filler_posts_util       = new Filler_Posts_Util( $current_post_id, $post_types );
170
-		$post_ids_to_be_excluded = array_merge( array( $current_post_id ), $referencing_post_ids );
171
-		$filler_posts            = $filler_posts_util->get_filler_response( $filler_count, $post_ids_to_be_excluded );
172
-		$results                 = array_merge( $results, $filler_posts );
173
-	}
174
-
175
-	// Apply filters after fillers are added
176
-	foreach ( $results as $result_index => $result ) {
177
-		$results[ $result_index ]['post']   = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $result['post']['id'] ), $navigator_id );
178
-		$results[ $result_index ]['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $result['entity']['id'] ), $navigator_id );
179
-	}
180
-
181
-	$results = apply_filters( 'wl_navigator_results', $results, $navigator_id, $current_post_id );
182
-
183
-	return $results;
53
+    check_ajax_referer( 'wl_navigator' );
54
+
55
+    // Post ID must be defined
56
+    if ( ! isset( $_GET['post_id'] ) ) {
57
+        wp_send_json_error( 'No post_id given' );
58
+
59
+        return array();
60
+    }
61
+
62
+    // Post ID must be defined
63
+    if ( ! isset( $_GET['uniqid'] ) ) {
64
+        wp_send_json_error( 'No uniqid given' );
65
+
66
+        return array();
67
+    }
68
+
69
+    // Limit the results (defaults to 4)
70
+    $navigator_length    = isset( $_GET['limit'] ) ? intval( $_GET['limit'] ) : 4;
71
+    $navigator_offset    = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0;
72
+    $order_by            = isset( $_GET['sort'] ) ? sanitize_sql_orderby( wp_unslash( $_GET['sort'] ) ) : 'ID DESC';
73
+    $post_types          = isset( $_GET['post_types'] ) ? sanitize_text_field( wp_unslash( $_GET['post_types'] ) ) : '';
74
+    $post_types          = explode( ',', $post_types );
75
+    $existing_post_types = get_post_types();
76
+    $post_types          = array_values( array_intersect( $existing_post_types, $post_types ) );
77
+    $current_post_id     = (int) $_GET['post_id'];
78
+    $current_post        = get_post( $current_post_id );
79
+
80
+    $navigator_id = sanitize_text_field( wp_unslash( $_GET['uniqid'] ) );
81
+
82
+    // Post ID has to match an existing item
83
+    if ( null === $current_post ) {
84
+        wp_send_json_error( 'No valid post_id given' );
85
+
86
+        return array();
87
+    }
88
+
89
+    // Determine navigator type and call respective _get_results
90
+    if ( get_post_type( $current_post_id ) === Wordlift_Entity_Service::TYPE_NAME ) {
91
+
92
+        $referencing_posts = Navigator_Data::entity_navigator_get_results(
93
+            $current_post_id,
94
+            array(
95
+                'ID',
96
+                'post_title',
97
+            ),
98
+            $order_by,
99
+            $navigator_length,
100
+            $navigator_offset,
101
+            $post_types
102
+        );
103
+    } else {
104
+        $referencing_posts = Navigator_Data::post_navigator_get_results(
105
+            $current_post_id,
106
+            array(
107
+                'ID',
108
+                'post_title',
109
+            ),
110
+            $order_by,
111
+            $navigator_length,
112
+            $navigator_offset,
113
+            $post_types
114
+        );
115
+
116
+    }
117
+
118
+    // loop over them and take the first one which is not already in the $related_posts
119
+    $results = array();
120
+    foreach ( $referencing_posts as $referencing_post ) {
121
+        $serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
122
+
123
+        /**
124
+         * Use the thumbnail.
125
+         *
126
+         * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
127
+         * @see https://github.com/insideout10/wordlift-plugin/issues/837
128
+         *
129
+         * @since 3.19.3 We're using the medium size image.
130
+         */
131
+        $thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
132
+
133
+        $result = array(
134
+            'post'   => array(
135
+                'id'        => $referencing_post->ID,
136
+                'permalink' => get_permalink( $referencing_post->ID ),
137
+                'title'     => html_entity_decode( $referencing_post->post_title, ENT_QUOTES, 'UTF-8' ),
138
+                'thumbnail' => $thumbnail,
139
+                'srcset'    => Srcset_Util::get_srcset( $referencing_post->ID, Srcset_Util::NAVIGATOR_WIDGET ),
140
+            ),
141
+            'entity' => array(
142
+                'id'        => $referencing_post->entity_id,
143
+                'label'     => $serialized_entity['label'],
144
+                'mainType'  => $serialized_entity['mainType'],
145
+                'permalink' => get_permalink( $referencing_post->entity_id ),
146
+            ),
147
+        );
148
+
149
+        $results[] = $result;
150
+    }
151
+
152
+    if ( count( $results ) < $navigator_length ) {
153
+        $results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
154
+    }
155
+
156
+    // Add filler posts if needed
157
+    $filler_count = $navigator_length - count( $results );
158
+    if ( $filler_count > 0 ) {
159
+        $referencing_post_ids = array_map(
160
+            function ( $p ) {
161
+                return $p->ID;
162
+            },
163
+            $referencing_posts
164
+        );
165
+        /**
166
+         * @since 3.27.8
167
+         * Filler posts are fetched using this util.
168
+         */
169
+        $filler_posts_util       = new Filler_Posts_Util( $current_post_id, $post_types );
170
+        $post_ids_to_be_excluded = array_merge( array( $current_post_id ), $referencing_post_ids );
171
+        $filler_posts            = $filler_posts_util->get_filler_response( $filler_count, $post_ids_to_be_excluded );
172
+        $results                 = array_merge( $results, $filler_posts );
173
+    }
174
+
175
+    // Apply filters after fillers are added
176
+    foreach ( $results as $result_index => $result ) {
177
+        $results[ $result_index ]['post']   = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $result['post']['id'] ), $navigator_id );
178
+        $results[ $result_index ]['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $result['entity']['id'] ), $navigator_id );
179
+    }
180
+
181
+    $results = apply_filters( 'wl_navigator_results', $results, $navigator_id, $current_post_id );
182
+
183
+    return $results;
184 184
 }
185 185
 
186 186
 
@@ -193,9 +193,9 @@  discard block
 block discarded – undo
193 193
  */
194 194
 function wl_shortcode_navigator_ajax() {
195 195
 
196
-	// Temporary blocking the Navigator.
197
-	$results = wl_shortcode_navigator_data();
198
-	wl_core_send_json( $results );
196
+    // Temporary blocking the Navigator.
197
+    $results = wl_shortcode_navigator_data();
198
+    wl_core_send_json( $results );
199 199
 
200 200
 }
201 201
 
@@ -207,16 +207,16 @@  discard block
 block discarded – undo
207 207
  */
208 208
 function wl_shortcode_navigator_wp_json() {
209 209
 
210
-	$results = wl_shortcode_navigator_data();
211
-	if ( ob_get_contents() ) {
212
-		ob_clean();
213
-	}
210
+    $results = wl_shortcode_navigator_data();
211
+    if ( ob_get_contents() ) {
212
+        ob_clean();
213
+    }
214 214
 
215
-	return array(
216
-		'items' => array(
217
-			array( 'values' => $results ),
218
-		),
219
-	);
215
+    return array(
216
+        'items' => array(
217
+            array( 'values' => $results ),
218
+        ),
219
+    );
220 220
 
221 221
 }
222 222
 
@@ -224,18 +224,18 @@  discard block
 block discarded – undo
224 224
  * Adding `rest_api_init` action for amp backend of navigator
225 225
  */
226 226
 add_action(
227
-	'rest_api_init',
228
-	function () {
229
-		register_rest_route(
230
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
231
-			'/navigator',
232
-			array(
233
-				'methods'             => 'GET',
234
-				'permission_callback' => '__return_true',
235
-				'callback'            => 'wl_shortcode_navigator_wp_json',
236
-			)
237
-		);
238
-	}
227
+    'rest_api_init',
228
+    function () {
229
+        register_rest_route(
230
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
231
+            '/navigator',
232
+            array(
233
+                'methods'             => 'GET',
234
+                'permission_callback' => '__return_true',
235
+                'callback'            => 'wl_shortcode_navigator_wp_json',
236
+            )
237
+        );
238
+    }
239 239
 );
240 240
 
241 241
 
@@ -245,31 +245,31 @@  discard block
 block discarded – undo
245 245
  * @since 2.2.0
246 246
  */
247 247
 add_action(
248
-	'plugins_loaded',
249
-	function () {
250
-		$action = array_key_exists( 'action', $_REQUEST ) ? sanitize_text_field( wp_unslash( (string) $_REQUEST['action'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
251
-		if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $action ) {
252
-			return;
253
-		}
254
-
255
-		remove_action( 'plugins_loaded', 'rocket_init' );
256
-		remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
257
-		remove_action( 'plugins_loaded', 'wpseo_init', 14 );
258
-	},
259
-	0
248
+    'plugins_loaded',
249
+    function () {
250
+        $action = array_key_exists( 'action', $_REQUEST ) ? sanitize_text_field( wp_unslash( (string) $_REQUEST['action'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
251
+        if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $action ) {
252
+            return;
253
+        }
254
+
255
+        remove_action( 'plugins_loaded', 'rocket_init' );
256
+        remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
257
+        remove_action( 'plugins_loaded', 'wpseo_init', 14 );
258
+    },
259
+    0
260 260
 );
261 261
 
262 262
 add_action(
263
-	'init',
264
-	function () {
265
-		$action = array_key_exists( 'action', $_REQUEST ) ? sanitize_text_field( wp_unslash( (string) $_REQUEST['action'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
266
-		if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $action ) {
267
-			return;
268
-		}
269
-
270
-		remove_action( 'init', 'wp_widgets_init', 1 );
271
-		remove_action( 'init', 'gglcptch_init' );
272
-	},
273
-	0
263
+    'init',
264
+    function () {
265
+        $action = array_key_exists( 'action', $_REQUEST ) ? sanitize_text_field( wp_unslash( (string) $_REQUEST['action'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
266
+        if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $action ) {
267
+            return;
268
+        }
269
+
270
+        remove_action( 'init', 'wp_widgets_init', 1 );
271
+        remove_action( 'init', 'gglcptch_init' );
272
+    },
273
+    0
274 274
 );
275 275
 
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -21,28 +21,28 @@  discard block
 block discarded – undo
21 21
 
22 22
 	// Create the cache key.
23 23
 	$cache_key_params = $_REQUEST; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
24
-	unset( $cache_key_params['uniqid'] );
25
-	$cache_key = array( 'request_params' => $cache_key_params );
24
+	unset($cache_key_params['uniqid']);
25
+	$cache_key = array('request_params' => $cache_key_params);
26 26
 
27 27
 	// Create the TTL cache and try to get the results.
28
-	$cache         = new Ttl_Cache( 'navigator', 8 * 60 * 60 ); // 8 hours.
29
-	$cache_results = $cache->get( $cache_key );
28
+	$cache         = new Ttl_Cache('navigator', 8 * 60 * 60); // 8 hours.
29
+	$cache_results = $cache->get($cache_key);
30 30
 
31 31
 	// So that the endpoint can be used remotely
32
-	header( 'Access-Control-Allow-Origin: *' );
32
+	header('Access-Control-Allow-Origin: *');
33 33
 
34
-	if ( isset( $cache_results ) ) {
35
-		header( 'X-WordLift-Cache: HIT' );
34
+	if (isset($cache_results)) {
35
+		header('X-WordLift-Cache: HIT');
36 36
 
37 37
 		return $cache_results;
38 38
 	}
39 39
 
40
-	header( 'X-WordLift-Cache: MISS' );
40
+	header('X-WordLift-Cache: MISS');
41 41
 
42 42
 	$results = _wl_navigator_get_data();
43 43
 
44 44
 	// Put the result before sending the json to the client, since sending the json will terminate us.
45
-	$cache->put( $cache_key, $results );
45
+	$cache->put($cache_key, $results);
46 46
 
47 47
 	return $results;
48 48
 }
@@ -50,44 +50,44 @@  discard block
 block discarded – undo
50 50
 
51 51
 function _wl_navigator_get_data() {
52 52
 
53
-	check_ajax_referer( 'wl_navigator' );
53
+	check_ajax_referer('wl_navigator');
54 54
 
55 55
 	// Post ID must be defined
56
-	if ( ! isset( $_GET['post_id'] ) ) {
57
-		wp_send_json_error( 'No post_id given' );
56
+	if ( ! isset($_GET['post_id'])) {
57
+		wp_send_json_error('No post_id given');
58 58
 
59 59
 		return array();
60 60
 	}
61 61
 
62 62
 	// Post ID must be defined
63
-	if ( ! isset( $_GET['uniqid'] ) ) {
64
-		wp_send_json_error( 'No uniqid given' );
63
+	if ( ! isset($_GET['uniqid'])) {
64
+		wp_send_json_error('No uniqid given');
65 65
 
66 66
 		return array();
67 67
 	}
68 68
 
69 69
 	// Limit the results (defaults to 4)
70
-	$navigator_length    = isset( $_GET['limit'] ) ? intval( $_GET['limit'] ) : 4;
71
-	$navigator_offset    = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0;
72
-	$order_by            = isset( $_GET['sort'] ) ? sanitize_sql_orderby( wp_unslash( $_GET['sort'] ) ) : 'ID DESC';
73
-	$post_types          = isset( $_GET['post_types'] ) ? sanitize_text_field( wp_unslash( $_GET['post_types'] ) ) : '';
74
-	$post_types          = explode( ',', $post_types );
70
+	$navigator_length    = isset($_GET['limit']) ? intval($_GET['limit']) : 4;
71
+	$navigator_offset    = isset($_GET['offset']) ? intval($_GET['offset']) : 0;
72
+	$order_by            = isset($_GET['sort']) ? sanitize_sql_orderby(wp_unslash($_GET['sort'])) : 'ID DESC';
73
+	$post_types          = isset($_GET['post_types']) ? sanitize_text_field(wp_unslash($_GET['post_types'])) : '';
74
+	$post_types          = explode(',', $post_types);
75 75
 	$existing_post_types = get_post_types();
76
-	$post_types          = array_values( array_intersect( $existing_post_types, $post_types ) );
76
+	$post_types          = array_values(array_intersect($existing_post_types, $post_types));
77 77
 	$current_post_id     = (int) $_GET['post_id'];
78
-	$current_post        = get_post( $current_post_id );
78
+	$current_post        = get_post($current_post_id);
79 79
 
80
-	$navigator_id = sanitize_text_field( wp_unslash( $_GET['uniqid'] ) );
80
+	$navigator_id = sanitize_text_field(wp_unslash($_GET['uniqid']));
81 81
 
82 82
 	// Post ID has to match an existing item
83
-	if ( null === $current_post ) {
84
-		wp_send_json_error( 'No valid post_id given' );
83
+	if (null === $current_post) {
84
+		wp_send_json_error('No valid post_id given');
85 85
 
86 86
 		return array();
87 87
 	}
88 88
 
89 89
 	// Determine navigator type and call respective _get_results
90
-	if ( get_post_type( $current_post_id ) === Wordlift_Entity_Service::TYPE_NAME ) {
90
+	if (get_post_type($current_post_id) === Wordlift_Entity_Service::TYPE_NAME) {
91 91
 
92 92
 		$referencing_posts = Navigator_Data::entity_navigator_get_results(
93 93
 			$current_post_id,
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 
118 118
 	// loop over them and take the first one which is not already in the $related_posts
119 119
 	$results = array();
120
-	foreach ( $referencing_posts as $referencing_post ) {
121
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
120
+	foreach ($referencing_posts as $referencing_post) {
121
+		$serialized_entity = wl_serialize_entity($referencing_post->entity_id);
122 122
 
123 123
 		/**
124 124
 		 * Use the thumbnail.
@@ -128,36 +128,36 @@  discard block
 block discarded – undo
128 128
 		 *
129 129
 		 * @since 3.19.3 We're using the medium size image.
130 130
 		 */
131
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
131
+		$thumbnail = get_the_post_thumbnail_url($referencing_post, 'medium');
132 132
 
133 133
 		$result = array(
134 134
 			'post'   => array(
135 135
 				'id'        => $referencing_post->ID,
136
-				'permalink' => get_permalink( $referencing_post->ID ),
137
-				'title'     => html_entity_decode( $referencing_post->post_title, ENT_QUOTES, 'UTF-8' ),
136
+				'permalink' => get_permalink($referencing_post->ID),
137
+				'title'     => html_entity_decode($referencing_post->post_title, ENT_QUOTES, 'UTF-8'),
138 138
 				'thumbnail' => $thumbnail,
139
-				'srcset'    => Srcset_Util::get_srcset( $referencing_post->ID, Srcset_Util::NAVIGATOR_WIDGET ),
139
+				'srcset'    => Srcset_Util::get_srcset($referencing_post->ID, Srcset_Util::NAVIGATOR_WIDGET),
140 140
 			),
141 141
 			'entity' => array(
142 142
 				'id'        => $referencing_post->entity_id,
143 143
 				'label'     => $serialized_entity['label'],
144 144
 				'mainType'  => $serialized_entity['mainType'],
145
-				'permalink' => get_permalink( $referencing_post->entity_id ),
145
+				'permalink' => get_permalink($referencing_post->entity_id),
146 146
 			),
147 147
 		);
148 148
 
149 149
 		$results[] = $result;
150 150
 	}
151 151
 
152
-	if ( count( $results ) < $navigator_length ) {
153
-		$results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
152
+	if (count($results) < $navigator_length) {
153
+		$results = apply_filters('wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length);
154 154
 	}
155 155
 
156 156
 	// Add filler posts if needed
157
-	$filler_count = $navigator_length - count( $results );
158
-	if ( $filler_count > 0 ) {
157
+	$filler_count = $navigator_length - count($results);
158
+	if ($filler_count > 0) {
159 159
 		$referencing_post_ids = array_map(
160
-			function ( $p ) {
160
+			function($p) {
161 161
 				return $p->ID;
162 162
 			},
163 163
 			$referencing_posts
@@ -166,19 +166,19 @@  discard block
 block discarded – undo
166 166
 		 * @since 3.27.8
167 167
 		 * Filler posts are fetched using this util.
168 168
 		 */
169
-		$filler_posts_util       = new Filler_Posts_Util( $current_post_id, $post_types );
170
-		$post_ids_to_be_excluded = array_merge( array( $current_post_id ), $referencing_post_ids );
171
-		$filler_posts            = $filler_posts_util->get_filler_response( $filler_count, $post_ids_to_be_excluded );
172
-		$results                 = array_merge( $results, $filler_posts );
169
+		$filler_posts_util       = new Filler_Posts_Util($current_post_id, $post_types);
170
+		$post_ids_to_be_excluded = array_merge(array($current_post_id), $referencing_post_ids);
171
+		$filler_posts            = $filler_posts_util->get_filler_response($filler_count, $post_ids_to_be_excluded);
172
+		$results                 = array_merge($results, $filler_posts);
173 173
 	}
174 174
 
175 175
 	// Apply filters after fillers are added
176
-	foreach ( $results as $result_index => $result ) {
177
-		$results[ $result_index ]['post']   = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $result['post']['id'] ), $navigator_id );
178
-		$results[ $result_index ]['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $result['entity']['id'] ), $navigator_id );
176
+	foreach ($results as $result_index => $result) {
177
+		$results[$result_index]['post']   = apply_filters('wl_navigator_data_post', $result['post'], intval($result['post']['id']), $navigator_id);
178
+		$results[$result_index]['entity'] = apply_filters('wl_navigator_data_entity', $result['entity'], intval($result['entity']['id']), $navigator_id);
179 179
 	}
180 180
 
181
-	$results = apply_filters( 'wl_navigator_results', $results, $navigator_id, $current_post_id );
181
+	$results = apply_filters('wl_navigator_results', $results, $navigator_id, $current_post_id);
182 182
 
183 183
 	return $results;
184 184
 }
@@ -195,12 +195,12 @@  discard block
 block discarded – undo
195 195
 
196 196
 	// Temporary blocking the Navigator.
197 197
 	$results = wl_shortcode_navigator_data();
198
-	wl_core_send_json( $results );
198
+	wl_core_send_json($results);
199 199
 
200 200
 }
201 201
 
202
-add_action( 'wp_ajax_wl_navigator', 'wl_shortcode_navigator_ajax' );
203
-add_action( 'wp_ajax_nopriv_wl_navigator', 'wl_shortcode_navigator_ajax' );
202
+add_action('wp_ajax_wl_navigator', 'wl_shortcode_navigator_ajax');
203
+add_action('wp_ajax_nopriv_wl_navigator', 'wl_shortcode_navigator_ajax');
204 204
 
205 205
 /**
206 206
  * wp-json call for the navigator widget
@@ -208,13 +208,13 @@  discard block
 block discarded – undo
208 208
 function wl_shortcode_navigator_wp_json() {
209 209
 
210 210
 	$results = wl_shortcode_navigator_data();
211
-	if ( ob_get_contents() ) {
211
+	if (ob_get_contents()) {
212 212
 		ob_clean();
213 213
 	}
214 214
 
215 215
 	return array(
216 216
 		'items' => array(
217
-			array( 'values' => $results ),
217
+			array('values' => $results),
218 218
 		),
219 219
 	);
220 220
 
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
  */
226 226
 add_action(
227 227
 	'rest_api_init',
228
-	function () {
228
+	function() {
229 229
 		register_rest_route(
230 230
 			WL_REST_ROUTE_DEFAULT_NAMESPACE,
231 231
 			'/navigator',
@@ -246,29 +246,29 @@  discard block
 block discarded – undo
246 246
  */
247 247
 add_action(
248 248
 	'plugins_loaded',
249
-	function () {
250
-		$action = array_key_exists( 'action', $_REQUEST ) ? sanitize_text_field( wp_unslash( (string) $_REQUEST['action'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
251
-		if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $action ) {
249
+	function() {
250
+		$action = array_key_exists('action', $_REQUEST) ? sanitize_text_field(wp_unslash((string) $_REQUEST['action'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
251
+		if ( ! defined('DOING_AJAX') || ! DOING_AJAX || 'wl_navigator' !== $action) {
252 252
 			return;
253 253
 		}
254 254
 
255
-		remove_action( 'plugins_loaded', 'rocket_init' );
256
-		remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
257
-		remove_action( 'plugins_loaded', 'wpseo_init', 14 );
255
+		remove_action('plugins_loaded', 'rocket_init');
256
+		remove_action('plugins_loaded', 'wpseo_premium_init', 14);
257
+		remove_action('plugins_loaded', 'wpseo_init', 14);
258 258
 	},
259 259
 	0
260 260
 );
261 261
 
262 262
 add_action(
263 263
 	'init',
264
-	function () {
265
-		$action = array_key_exists( 'action', $_REQUEST ) ? sanitize_text_field( wp_unslash( (string) $_REQUEST['action'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
266
-		if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $action ) {
264
+	function() {
265
+		$action = array_key_exists('action', $_REQUEST) ? sanitize_text_field(wp_unslash((string) $_REQUEST['action'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
266
+		if ( ! defined('DOING_AJAX') || ! DOING_AJAX || 'wl_navigator' !== $action) {
267 267
 			return;
268 268
 		}
269 269
 
270
-		remove_action( 'init', 'wp_widgets_init', 1 );
271
-		remove_action( 'init', 'gglcptch_init' );
270
+		remove_action('init', 'wp_widgets_init', 1);
271
+		remove_action('init', 'gglcptch_init');
272 272
 	},
273 273
 	0
274 274
 );
Please login to merge, or discard this patch.
src/shortcodes/wordlift-shortcode-geomap.php 2 patches
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -11,46 +11,46 @@  discard block
 block discarded – undo
11 11
  * Print both global or post related places in json. It's executed via Ajax
12 12
  */
13 13
 function wl_shortcode_geomap_ajax() {
14
-	check_ajax_referer( 'wl_geomap' );
15
-	// Get the post Id.
16
-	$post_id = isset( $_REQUEST['post_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post_id'] ) ) : null;
14
+    check_ajax_referer( 'wl_geomap' );
15
+    // Get the post Id.
16
+    $post_id = isset( $_REQUEST['post_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post_id'] ) ) : null;
17 17
 
18
-	$map_data = ( is_numeric( $post_id )
19
-		? wl_shortcode_geomap_ajax_single_post( (int) $post_id )
20
-		: wl_shortcode_geomap_ajax_all_posts() );
18
+    $map_data = ( is_numeric( $post_id )
19
+        ? wl_shortcode_geomap_ajax_single_post( (int) $post_id )
20
+        : wl_shortcode_geomap_ajax_all_posts() );
21 21
 
22
-	wl_core_send_json( wl_shortcode_geomap_format_results( $map_data, $post_id ) );
22
+    wl_core_send_json( wl_shortcode_geomap_format_results( $map_data, $post_id ) );
23 23
 
24 24
 }
25 25
 
26 26
 function wl_shortcode_geomap_ajax_all_posts() {
27
-	global $wpdb;
28
-
29
-	return $wpdb->get_results(
30
-		$wpdb->prepare(
31
-			'SELECT DISTINCT p1.ID, p1.post_title, pm1.meta_value AS longitude, pm2.meta_value AS latitude'
32
-			. " FROM {$wpdb->posts} p1 "
33
-			. " INNER JOIN {$wpdb->prefix}wl_relation_instances ri"
34
-			. '  ON ri.object_id = p1.ID AND ri.predicate = %s'
35
-			. " INNER JOIN {$wpdb->postmeta} pm1"
36
-			. "  ON pm1.post_id = p1.ID AND pm1.meta_key = %s AND '0' != pm1.meta_value"
37
-			. " INNER JOIN {$wpdb->postmeta} pm2"
38
-			. "  ON pm2.post_id = p1.ID AND pm2.meta_key = %s AND '0' != pm2.meta_value"
39
-			. ' WHERE p1.post_status = %s',
40
-			'where',
41
-			'wl_geo_latitude',
42
-			'wl_geo_longitude',
43
-			'publish'
44
-		)
45
-	);
27
+    global $wpdb;
28
+
29
+    return $wpdb->get_results(
30
+        $wpdb->prepare(
31
+            'SELECT DISTINCT p1.ID, p1.post_title, pm1.meta_value AS longitude, pm2.meta_value AS latitude'
32
+            . " FROM {$wpdb->posts} p1 "
33
+            . " INNER JOIN {$wpdb->prefix}wl_relation_instances ri"
34
+            . '  ON ri.object_id = p1.ID AND ri.predicate = %s'
35
+            . " INNER JOIN {$wpdb->postmeta} pm1"
36
+            . "  ON pm1.post_id = p1.ID AND pm1.meta_key = %s AND '0' != pm1.meta_value"
37
+            . " INNER JOIN {$wpdb->postmeta} pm2"
38
+            . "  ON pm2.post_id = p1.ID AND pm2.meta_key = %s AND '0' != pm2.meta_value"
39
+            . ' WHERE p1.post_status = %s',
40
+            'where',
41
+            'wl_geo_latitude',
42
+            'wl_geo_longitude',
43
+            'publish'
44
+        )
45
+    );
46 46
 }
47 47
 
48 48
 function wl_shortcode_geomap_ajax_single_post( $post_id ) {
49
-	global $wpdb;
49
+    global $wpdb;
50 50
 
51
-	return $wpdb->get_results(
52
-		$wpdb->prepare(
53
-			"
51
+    return $wpdb->get_results(
52
+        $wpdb->prepare(
53
+            "
54 54
 		SELECT p2.ID, p2.post_title, pm1.meta_value AS longitude, pm2.meta_value AS latitude
55 55
 		 FROM {$wpdb->prefix}wl_relation_instances ri
56 56
 		 INNER JOIN {$wpdb->posts} p2
@@ -69,87 +69,87 @@  discard block
 block discarded – undo
69 69
 		  ON pm2.post_id = p.ID AND pm2.meta_key = %s AND '0' != pm2.meta_value
70 70
 		 WHERE p.ID = %s
71 71
 		",
72
-			'publish',
73
-			'wl_geo_latitude',
74
-			'wl_geo_longitude',
75
-			$post_id,
76
-			'where',
77
-			// UNION
78
-			'wl_geo_latitude',
79
-			'wl_geo_longitude',
80
-			$post_id
81
-		)
82
-	);
72
+            'publish',
73
+            'wl_geo_latitude',
74
+            'wl_geo_longitude',
75
+            $post_id,
76
+            'where',
77
+            // UNION
78
+            'wl_geo_latitude',
79
+            'wl_geo_longitude',
80
+            $post_id
81
+        )
82
+    );
83 83
 }
84 84
 
85 85
 function wl_shortcode_geomap_get_subjects( $post_id, $exclude_post_id ) {
86 86
 
87
-	global $wpdb;
88
-
89
-	return $wpdb->get_results(
90
-		$wpdb->prepare(
91
-			'SELECT p.ID, p.post_title'
92
-			. " FROM {$wpdb->prefix}wl_relation_instances ri" .
93
-			" INNER JOIN {$wpdb->posts} p" .
94
-			'  ON p.ID = ri.subject_id AND p.post_status = %s AND p.ID != %d' .
95
-			' WHERE ri.object_id = %d AND ri.predicate = %s',
96
-			'publish',
97
-			$exclude_post_id,
98
-			$post_id,
99
-			'where'
100
-		)
101
-	);
87
+    global $wpdb;
88
+
89
+    return $wpdb->get_results(
90
+        $wpdb->prepare(
91
+            'SELECT p.ID, p.post_title'
92
+            . " FROM {$wpdb->prefix}wl_relation_instances ri" .
93
+            " INNER JOIN {$wpdb->posts} p" .
94
+            '  ON p.ID = ri.subject_id AND p.post_status = %s AND p.ID != %d' .
95
+            ' WHERE ri.object_id = %d AND ri.predicate = %s',
96
+            'publish',
97
+            $exclude_post_id,
98
+            $post_id,
99
+            'where'
100
+        )
101
+    );
102 102
 }
103 103
 
104 104
 function wl_shortcode_geomap_format_results( $results, $post_id = null ) {
105 105
 
106
-	$boundaries = array();
107
-	$features   = array_map(
108
-		function ( $item ) use ( &$boundaries, $post_id ) {
109
-
110
-			$thumbnail_url  = get_the_post_thumbnail_url( $item->ID );
111
-			$thumbnail_html = ( $thumbnail_url ? "<img src='$thumbnail_url' width='100%'>" : '' );
112
-
113
-			// Related posts.
114
-			// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
115
-			$subjects            = wl_shortcode_geomap_get_subjects( $item->ID, $post_id );
116
-			$subjects_inner_html = array_reduce(
117
-				$subjects,
118
-				function ( $carry, $subject ) {
119
-
120
-					$permalink = get_permalink( $subject->ID );
121
-
122
-					return $carry . sprintf( '<li><a href="%s">%s</a></li>', $permalink, esc_html( $subject->post_title ) );
123
-				},
124
-				''
125
-			);
126
-			$subjects_html       = ( ! empty( $subjects_inner_html ) ? '<ul>' . $subjects_inner_html . '</ul>' : '' );
127
-
128
-			$popup_content = sprintf( '<a href="%s"><h6>%s</h6>%s</a>%s', get_permalink( $item->ID ), $thumbnail_html, esc_html( $item->post_title ), $subjects_html );
129
-			$latitude      = floatval( $item->latitude );
130
-			$longitude     = floatval( $item->longitude );
131
-			$coordinates   = array( $latitude, $longitude );
132
-			$geometry      = array(
133
-				'type'        => 'Point',
134
-				'coordinates' => $coordinates,
135
-			);
136
-
137
-			// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
138
-			$boundaries[] = array( $longitude, $latitude );
139
-
140
-			return array(
141
-				'type'       => 'Feature',
142
-				'properties' => array( 'popupContent' => $popup_content ),
143
-				'geometry'   => $geometry,
144
-			);
145
-		},
146
-		$results
147
-	);
148
-
149
-	return array(
150
-		'features'   => $features,
151
-		'boundaries' => $boundaries,
152
-	);
106
+    $boundaries = array();
107
+    $features   = array_map(
108
+        function ( $item ) use ( &$boundaries, $post_id ) {
109
+
110
+            $thumbnail_url  = get_the_post_thumbnail_url( $item->ID );
111
+            $thumbnail_html = ( $thumbnail_url ? "<img src='$thumbnail_url' width='100%'>" : '' );
112
+
113
+            // Related posts.
114
+            // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
115
+            $subjects            = wl_shortcode_geomap_get_subjects( $item->ID, $post_id );
116
+            $subjects_inner_html = array_reduce(
117
+                $subjects,
118
+                function ( $carry, $subject ) {
119
+
120
+                    $permalink = get_permalink( $subject->ID );
121
+
122
+                    return $carry . sprintf( '<li><a href="%s">%s</a></li>', $permalink, esc_html( $subject->post_title ) );
123
+                },
124
+                ''
125
+            );
126
+            $subjects_html       = ( ! empty( $subjects_inner_html ) ? '<ul>' . $subjects_inner_html . '</ul>' : '' );
127
+
128
+            $popup_content = sprintf( '<a href="%s"><h6>%s</h6>%s</a>%s', get_permalink( $item->ID ), $thumbnail_html, esc_html( $item->post_title ), $subjects_html );
129
+            $latitude      = floatval( $item->latitude );
130
+            $longitude     = floatval( $item->longitude );
131
+            $coordinates   = array( $latitude, $longitude );
132
+            $geometry      = array(
133
+                'type'        => 'Point',
134
+                'coordinates' => $coordinates,
135
+            );
136
+
137
+            // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
138
+            $boundaries[] = array( $longitude, $latitude );
139
+
140
+            return array(
141
+                'type'       => 'Feature',
142
+                'properties' => array( 'popupContent' => $popup_content ),
143
+                'geometry'   => $geometry,
144
+            );
145
+        },
146
+        $results
147
+    );
148
+
149
+    return array(
150
+        'features'   => $features,
151
+        'boundaries' => $boundaries,
152
+    );
153 153
 }
154 154
 
155 155
 add_action( 'wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax' );
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -11,15 +11,15 @@  discard block
 block discarded – undo
11 11
  * Print both global or post related places in json. It's executed via Ajax
12 12
  */
13 13
 function wl_shortcode_geomap_ajax() {
14
-	check_ajax_referer( 'wl_geomap' );
14
+	check_ajax_referer('wl_geomap');
15 15
 	// Get the post Id.
16
-	$post_id = isset( $_REQUEST['post_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post_id'] ) ) : null;
16
+	$post_id = isset($_REQUEST['post_id']) ? sanitize_text_field(wp_unslash($_REQUEST['post_id'])) : null;
17 17
 
18
-	$map_data = ( is_numeric( $post_id )
19
-		? wl_shortcode_geomap_ajax_single_post( (int) $post_id )
20
-		: wl_shortcode_geomap_ajax_all_posts() );
18
+	$map_data = (is_numeric($post_id)
19
+		? wl_shortcode_geomap_ajax_single_post((int) $post_id)
20
+		: wl_shortcode_geomap_ajax_all_posts());
21 21
 
22
-	wl_core_send_json( wl_shortcode_geomap_format_results( $map_data, $post_id ) );
22
+	wl_core_send_json(wl_shortcode_geomap_format_results($map_data, $post_id));
23 23
 
24 24
 }
25 25
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	);
46 46
 }
47 47
 
48
-function wl_shortcode_geomap_ajax_single_post( $post_id ) {
48
+function wl_shortcode_geomap_ajax_single_post($post_id) {
49 49
 	global $wpdb;
50 50
 
51 51
 	return $wpdb->get_results(
@@ -82,16 +82,16 @@  discard block
 block discarded – undo
82 82
 	);
83 83
 }
84 84
 
85
-function wl_shortcode_geomap_get_subjects( $post_id, $exclude_post_id ) {
85
+function wl_shortcode_geomap_get_subjects($post_id, $exclude_post_id) {
86 86
 
87 87
 	global $wpdb;
88 88
 
89 89
 	return $wpdb->get_results(
90 90
 		$wpdb->prepare(
91 91
 			'SELECT p.ID, p.post_title'
92
-			. " FROM {$wpdb->prefix}wl_relation_instances ri" .
93
-			" INNER JOIN {$wpdb->posts} p" .
94
-			'  ON p.ID = ri.subject_id AND p.post_status = %s AND p.ID != %d' .
92
+			. " FROM {$wpdb->prefix}wl_relation_instances ri".
93
+			" INNER JOIN {$wpdb->posts} p".
94
+			'  ON p.ID = ri.subject_id AND p.post_status = %s AND p.ID != %d'.
95 95
 			' WHERE ri.object_id = %d AND ri.predicate = %s',
96 96
 			'publish',
97 97
 			$exclude_post_id,
@@ -101,45 +101,45 @@  discard block
 block discarded – undo
101 101
 	);
102 102
 }
103 103
 
104
-function wl_shortcode_geomap_format_results( $results, $post_id = null ) {
104
+function wl_shortcode_geomap_format_results($results, $post_id = null) {
105 105
 
106 106
 	$boundaries = array();
107 107
 	$features   = array_map(
108
-		function ( $item ) use ( &$boundaries, $post_id ) {
108
+		function($item) use (&$boundaries, $post_id) {
109 109
 
110
-			$thumbnail_url  = get_the_post_thumbnail_url( $item->ID );
111
-			$thumbnail_html = ( $thumbnail_url ? "<img src='$thumbnail_url' width='100%'>" : '' );
110
+			$thumbnail_url  = get_the_post_thumbnail_url($item->ID);
111
+			$thumbnail_html = ($thumbnail_url ? "<img src='$thumbnail_url' width='100%'>" : '');
112 112
 
113 113
 			// Related posts.
114 114
 			// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
115
-			$subjects            = wl_shortcode_geomap_get_subjects( $item->ID, $post_id );
115
+			$subjects            = wl_shortcode_geomap_get_subjects($item->ID, $post_id);
116 116
 			$subjects_inner_html = array_reduce(
117 117
 				$subjects,
118
-				function ( $carry, $subject ) {
118
+				function($carry, $subject) {
119 119
 
120
-					$permalink = get_permalink( $subject->ID );
120
+					$permalink = get_permalink($subject->ID);
121 121
 
122
-					return $carry . sprintf( '<li><a href="%s">%s</a></li>', $permalink, esc_html( $subject->post_title ) );
122
+					return $carry.sprintf('<li><a href="%s">%s</a></li>', $permalink, esc_html($subject->post_title));
123 123
 				},
124 124
 				''
125 125
 			);
126
-			$subjects_html       = ( ! empty( $subjects_inner_html ) ? '<ul>' . $subjects_inner_html . '</ul>' : '' );
126
+			$subjects_html = ( ! empty($subjects_inner_html) ? '<ul>'.$subjects_inner_html.'</ul>' : '');
127 127
 
128
-			$popup_content = sprintf( '<a href="%s"><h6>%s</h6>%s</a>%s', get_permalink( $item->ID ), $thumbnail_html, esc_html( $item->post_title ), $subjects_html );
129
-			$latitude      = floatval( $item->latitude );
130
-			$longitude     = floatval( $item->longitude );
131
-			$coordinates   = array( $latitude, $longitude );
128
+			$popup_content = sprintf('<a href="%s"><h6>%s</h6>%s</a>%s', get_permalink($item->ID), $thumbnail_html, esc_html($item->post_title), $subjects_html);
129
+			$latitude      = floatval($item->latitude);
130
+			$longitude     = floatval($item->longitude);
131
+			$coordinates   = array($latitude, $longitude);
132 132
 			$geometry      = array(
133 133
 				'type'        => 'Point',
134 134
 				'coordinates' => $coordinates,
135 135
 			);
136 136
 
137 137
 			// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
138
-			$boundaries[] = array( $longitude, $latitude );
138
+			$boundaries[] = array($longitude, $latitude);
139 139
 
140 140
 			return array(
141 141
 				'type'       => 'Feature',
142
-				'properties' => array( 'popupContent' => $popup_content ),
142
+				'properties' => array('popupContent' => $popup_content),
143 143
 				'geometry'   => $geometry,
144 144
 			);
145 145
 		},
@@ -152,5 +152,5 @@  discard block
 block discarded – undo
152 152
 	);
153 153
 }
154 154
 
155
-add_action( 'wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax' );
156
-add_action( 'wp_ajax_nopriv_wl_geomap', 'wl_shortcode_geomap_ajax' );
155
+add_action('wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax');
156
+add_action('wp_ajax_nopriv_wl_geomap', 'wl_shortcode_geomap_ajax');
Please login to merge, or discard this patch.
src/shortcodes/class-wordlift-products-navigator-shortcode-rest.php 2 patches
Indentation   +287 added lines, -287 removed lines patch added patch discarded remove patch
@@ -4,243 +4,243 @@  discard block
 block discarded – undo
4 4
 
5 5
 class Wordlift_Products_Navigator_Shortcode_REST extends Wordlift_Shortcode_REST {
6 6
 
7
-	const CACHE_TTL = 3600; // 1 hour
8
-
9
-	public function __construct() {
10
-		parent::__construct(
11
-			'/products-navigator',
12
-			array(
13
-				'post_id' => array(
14
-					'description' => __( 'Post ID for which Navigator has to be queried', 'wordlift' ),
15
-					'type'        => 'integer',
16
-					'required'    => true,
17
-				),
18
-				'uniqid'  => array(
19
-					'description' => __( 'Navigator uniqueid', 'wordlift' ),
20
-					'type'        => 'string',
21
-					'required'    => true,
22
-				),
23
-				'limit'   => array(
24
-					'default'           => 4,
25
-					'type'              => 'integer',
26
-					'sanitize_callback' => 'absint',
27
-				),
28
-				'offset'  => array(
29
-					'default'           => 0,
30
-					'type'              => 'integer',
31
-					'sanitize_callback' => 'absint',
32
-				),
33
-				'sort'    => array(
34
-					'default'           => 'ID DESC',
35
-					'sanitize_callback' => 'sanitize_sql_orderby',
36
-				),
37
-				'amp'     => array(
38
-					'sanitize_callback' => 'rest_sanitize_boolean',
39
-				),
40
-			)
41
-		);
42
-	}
43
-
44
-	public function get_data( $request ) {
45
-
46
-		// Sanitize and set defaults
47
-		$navigator_length = $request['limit'];
48
-		$navigator_offset = $request['offset'];
49
-		$order_by         = $request['sort'];
50
-		$post_id          = $request['post_id'];
51
-		$navigator_id     = $request['uniqid'];
52
-		$amp              = $request['amp'];
53
-
54
-		$post = get_post( $post_id );
55
-
56
-		// Post ID has to match an existing item
57
-		if ( null === $post ) {
58
-			return new WP_Error( 'rest_invalid_post_id', __( 'Invalid post_id', 'wordlift' ), array( 'status' => 404 ) );
59
-		}
60
-
61
-		// Determine navigator type and call respective get_*_results
62
-		if ( get_post_type( $post_id ) === Wordlift_Entity_Service::TYPE_NAME ) {
63
-			$referencing_posts = $this->get_entity_results(
64
-				$post_id,
65
-				array(
66
-					'ID',
67
-					'post_title',
68
-				),
69
-				$order_by,
70
-				$navigator_length,
71
-				$navigator_offset
72
-			);
73
-		} else {
74
-			$referencing_posts = $this->get_post_results(
75
-				$post_id,
76
-				array(
77
-					'ID',
78
-					'post_title',
79
-				),
80
-				$order_by,
81
-				$navigator_length,
82
-				$navigator_offset
83
-			);
84
-		}
85
-
86
-		// Fetch directly referencing posts excluding referencing posts via entities
87
-		$directly_referencing_posts = $this->get_directly_referencing_posts(
88
-			$post_id,
89
-			array_map(
90
-				function ( $referencing_post ) {
91
-					return $referencing_post->ID;
92
-				},
93
-				$referencing_posts
94
-			)
95
-		);
96
-
97
-		// Combine directly referencing posts and referencing posts via entities
98
-		$referencing_posts = array_merge( $directly_referencing_posts, $referencing_posts );
99
-
100
-		// loop over them and take the first one which is not already in the $related_posts
101
-		$results = array();
102
-		foreach ( $referencing_posts as $referencing_post ) {
103
-			$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
104
-			$product           = wc_get_product( $referencing_post->ID );
105
-
106
-			$result = array(
107
-				'product' => array(
108
-					'id'              => $referencing_post->ID,
109
-					'permalink'       => get_permalink( $referencing_post->ID ),
110
-					'title'           => $referencing_post->post_title,
111
-					'thumbnail'       => get_the_post_thumbnail_url( $referencing_post, 'medium' ),
112
-					'regular_price'   => $product->get_regular_price(),
113
-					'sale_price'      => $product->get_sale_price(),
114
-					'price'           => $product->get_price(),
115
-					'currency_symbol' => get_woocommerce_currency_symbol(),
116
-					'discount_pc'     => ( $product->get_sale_price() && ( $product->get_regular_price() > 0 ) ) ? round( 1 - ( $product->get_sale_price() / $product->get_regular_price() ), 2 ) * 100 : 0,
117
-					'average_rating'  => $product->get_average_rating(),
118
-					'rating_count'    => $product->get_rating_count(),
119
-					'rating_html'     => wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ),
120
-				),
121
-				'entity'  => array(
122
-					'id'        => $referencing_post->entity_id,
123
-					'label'     => $serialized_entity['label'],
124
-					'mainType'  => $serialized_entity['mainType'],
125
-					'permalink' => get_permalink( $referencing_post->entity_id ),
126
-				),
127
-			);
128
-
129
-			$results[] = $result;
130
-
131
-		}
132
-
133
-		if ( count( $results ) < $navigator_length ) {
134
-			$results = apply_filters( 'wl_products_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
135
-		}
136
-
137
-		// Add filler posts if needed
138
-		$filler_count = $navigator_length - count( $results );
139
-		if ( $filler_count > 0 ) {
140
-			$referencing_post_ids = array_map(
141
-				function ( $p ) {
142
-					return $p->ID;
143
-				},
144
-				$referencing_posts
145
-			);
146
-			/**
147
-			 * @since 3.28.0
148
-			 * Filler posts are fetched using this util.
149
-			 */
150
-			$filler_posts_util       = new Filler_Posts_Util( $post_id, 'product' );
151
-			$post_ids_to_be_excluded = array_merge( array( $post_id ), $referencing_post_ids );
152
-			$filler_posts            = $filler_posts_util->get_product_navigator_response( $filler_count, $post_ids_to_be_excluded );
153
-			$results                 = array_merge( $results, $filler_posts );
154
-		}
155
-
156
-		// Apply filters after fillers are added
157
-		foreach ( $results as $result_index => $result ) {
158
-			$results[ $result_index ]['product'] = apply_filters( 'wl_products_navigator_data_post', $result['product'], intval( $result['product']['id'] ), $navigator_id );
159
-			$results[ $result_index ]['entity']  = apply_filters( 'wl_products_navigator_data_entity', $result['entity'], intval( $result['entity']['id'] ), $navigator_id );
160
-		}
161
-
162
-		$results = apply_filters( 'wl_products_navigator_results', $results, $navigator_id );
163
-
164
-		return $amp ? array(
165
-			'items' => array(
166
-				array( 'values' => $results ),
167
-			),
168
-		) : $results;
169
-
170
-	}
171
-
172
-	private function get_directly_referencing_posts( $post_id, $referencing_post_ids ) {
173
-
174
-		$directly_referencing_post_ids = Wordlift_Entity_Service::get_instance()->get_related_entities( $post_id );
175
-
176
-		$post__in = array_diff( $directly_referencing_post_ids, $referencing_post_ids );
177
-
178
-		$directly_referencing_posts = get_posts(
179
-			array(
180
-				'meta_query'          => array(
181
-					array(
182
-						'key' => '_thumbnail_id',
183
-					),
184
-					array(
185
-						'key'   => '_stock_status',
186
-						'value' => 'instock',
187
-					),
188
-				),
189
-				'post__in'            => $post__in,
190
-				'post_type'           => 'product',
191
-				'ignore_sticky_posts' => 1,
192
-			)
193
-		);
194
-
195
-		$results = array();
196
-
197
-		foreach ( $directly_referencing_posts as $post ) {
198
-			$result             = new stdClass();
199
-			$result->ID         = $post->ID;
200
-			$result->post_title = $post->post_title;
201
-			$result->entity_id  = $post->ID;
202
-			$results[]          = $result;
203
-		}
204
-
205
-		return $results;
206
-	}
207
-
208
-	private function get_entity_results(
209
-		$post_id,
210
-		$fields = array(
211
-			'ID',
212
-			'post_title',
213
-		),
214
-		$order_by = 'ID DESC',
215
-		$limit = 10,
216
-		$offset = 0
217
-	) {
218
-		global $wpdb;
219
-
220
-		$select = implode(
221
-			', ',
222
-			array_map(
223
-				function ( $item ) {
224
-					return "p.$item AS $item";
225
-				},
226
-				(array) $fields
227
-			)
228
-		);
229
-
230
-		$order_by = implode(
231
-			', ',
232
-			array_map(
233
-				function ( $item ) {
234
-					return "p.$item";
235
-				},
236
-				(array) $order_by
237
-			)
238
-		);
7
+    const CACHE_TTL = 3600; // 1 hour
8
+
9
+    public function __construct() {
10
+        parent::__construct(
11
+            '/products-navigator',
12
+            array(
13
+                'post_id' => array(
14
+                    'description' => __( 'Post ID for which Navigator has to be queried', 'wordlift' ),
15
+                    'type'        => 'integer',
16
+                    'required'    => true,
17
+                ),
18
+                'uniqid'  => array(
19
+                    'description' => __( 'Navigator uniqueid', 'wordlift' ),
20
+                    'type'        => 'string',
21
+                    'required'    => true,
22
+                ),
23
+                'limit'   => array(
24
+                    'default'           => 4,
25
+                    'type'              => 'integer',
26
+                    'sanitize_callback' => 'absint',
27
+                ),
28
+                'offset'  => array(
29
+                    'default'           => 0,
30
+                    'type'              => 'integer',
31
+                    'sanitize_callback' => 'absint',
32
+                ),
33
+                'sort'    => array(
34
+                    'default'           => 'ID DESC',
35
+                    'sanitize_callback' => 'sanitize_sql_orderby',
36
+                ),
37
+                'amp'     => array(
38
+                    'sanitize_callback' => 'rest_sanitize_boolean',
39
+                ),
40
+            )
41
+        );
42
+    }
43
+
44
+    public function get_data( $request ) {
45
+
46
+        // Sanitize and set defaults
47
+        $navigator_length = $request['limit'];
48
+        $navigator_offset = $request['offset'];
49
+        $order_by         = $request['sort'];
50
+        $post_id          = $request['post_id'];
51
+        $navigator_id     = $request['uniqid'];
52
+        $amp              = $request['amp'];
53
+
54
+        $post = get_post( $post_id );
55
+
56
+        // Post ID has to match an existing item
57
+        if ( null === $post ) {
58
+            return new WP_Error( 'rest_invalid_post_id', __( 'Invalid post_id', 'wordlift' ), array( 'status' => 404 ) );
59
+        }
60
+
61
+        // Determine navigator type and call respective get_*_results
62
+        if ( get_post_type( $post_id ) === Wordlift_Entity_Service::TYPE_NAME ) {
63
+            $referencing_posts = $this->get_entity_results(
64
+                $post_id,
65
+                array(
66
+                    'ID',
67
+                    'post_title',
68
+                ),
69
+                $order_by,
70
+                $navigator_length,
71
+                $navigator_offset
72
+            );
73
+        } else {
74
+            $referencing_posts = $this->get_post_results(
75
+                $post_id,
76
+                array(
77
+                    'ID',
78
+                    'post_title',
79
+                ),
80
+                $order_by,
81
+                $navigator_length,
82
+                $navigator_offset
83
+            );
84
+        }
85
+
86
+        // Fetch directly referencing posts excluding referencing posts via entities
87
+        $directly_referencing_posts = $this->get_directly_referencing_posts(
88
+            $post_id,
89
+            array_map(
90
+                function ( $referencing_post ) {
91
+                    return $referencing_post->ID;
92
+                },
93
+                $referencing_posts
94
+            )
95
+        );
96
+
97
+        // Combine directly referencing posts and referencing posts via entities
98
+        $referencing_posts = array_merge( $directly_referencing_posts, $referencing_posts );
99
+
100
+        // loop over them and take the first one which is not already in the $related_posts
101
+        $results = array();
102
+        foreach ( $referencing_posts as $referencing_post ) {
103
+            $serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
104
+            $product           = wc_get_product( $referencing_post->ID );
105
+
106
+            $result = array(
107
+                'product' => array(
108
+                    'id'              => $referencing_post->ID,
109
+                    'permalink'       => get_permalink( $referencing_post->ID ),
110
+                    'title'           => $referencing_post->post_title,
111
+                    'thumbnail'       => get_the_post_thumbnail_url( $referencing_post, 'medium' ),
112
+                    'regular_price'   => $product->get_regular_price(),
113
+                    'sale_price'      => $product->get_sale_price(),
114
+                    'price'           => $product->get_price(),
115
+                    'currency_symbol' => get_woocommerce_currency_symbol(),
116
+                    'discount_pc'     => ( $product->get_sale_price() && ( $product->get_regular_price() > 0 ) ) ? round( 1 - ( $product->get_sale_price() / $product->get_regular_price() ), 2 ) * 100 : 0,
117
+                    'average_rating'  => $product->get_average_rating(),
118
+                    'rating_count'    => $product->get_rating_count(),
119
+                    'rating_html'     => wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ),
120
+                ),
121
+                'entity'  => array(
122
+                    'id'        => $referencing_post->entity_id,
123
+                    'label'     => $serialized_entity['label'],
124
+                    'mainType'  => $serialized_entity['mainType'],
125
+                    'permalink' => get_permalink( $referencing_post->entity_id ),
126
+                ),
127
+            );
128
+
129
+            $results[] = $result;
130
+
131
+        }
132
+
133
+        if ( count( $results ) < $navigator_length ) {
134
+            $results = apply_filters( 'wl_products_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
135
+        }
136
+
137
+        // Add filler posts if needed
138
+        $filler_count = $navigator_length - count( $results );
139
+        if ( $filler_count > 0 ) {
140
+            $referencing_post_ids = array_map(
141
+                function ( $p ) {
142
+                    return $p->ID;
143
+                },
144
+                $referencing_posts
145
+            );
146
+            /**
147
+             * @since 3.28.0
148
+             * Filler posts are fetched using this util.
149
+             */
150
+            $filler_posts_util       = new Filler_Posts_Util( $post_id, 'product' );
151
+            $post_ids_to_be_excluded = array_merge( array( $post_id ), $referencing_post_ids );
152
+            $filler_posts            = $filler_posts_util->get_product_navigator_response( $filler_count, $post_ids_to_be_excluded );
153
+            $results                 = array_merge( $results, $filler_posts );
154
+        }
155
+
156
+        // Apply filters after fillers are added
157
+        foreach ( $results as $result_index => $result ) {
158
+            $results[ $result_index ]['product'] = apply_filters( 'wl_products_navigator_data_post', $result['product'], intval( $result['product']['id'] ), $navigator_id );
159
+            $results[ $result_index ]['entity']  = apply_filters( 'wl_products_navigator_data_entity', $result['entity'], intval( $result['entity']['id'] ), $navigator_id );
160
+        }
161
+
162
+        $results = apply_filters( 'wl_products_navigator_results', $results, $navigator_id );
163
+
164
+        return $amp ? array(
165
+            'items' => array(
166
+                array( 'values' => $results ),
167
+            ),
168
+        ) : $results;
169
+
170
+    }
171
+
172
+    private function get_directly_referencing_posts( $post_id, $referencing_post_ids ) {
173
+
174
+        $directly_referencing_post_ids = Wordlift_Entity_Service::get_instance()->get_related_entities( $post_id );
175
+
176
+        $post__in = array_diff( $directly_referencing_post_ids, $referencing_post_ids );
177
+
178
+        $directly_referencing_posts = get_posts(
179
+            array(
180
+                'meta_query'          => array(
181
+                    array(
182
+                        'key' => '_thumbnail_id',
183
+                    ),
184
+                    array(
185
+                        'key'   => '_stock_status',
186
+                        'value' => 'instock',
187
+                    ),
188
+                ),
189
+                'post__in'            => $post__in,
190
+                'post_type'           => 'product',
191
+                'ignore_sticky_posts' => 1,
192
+            )
193
+        );
194
+
195
+        $results = array();
196
+
197
+        foreach ( $directly_referencing_posts as $post ) {
198
+            $result             = new stdClass();
199
+            $result->ID         = $post->ID;
200
+            $result->post_title = $post->post_title;
201
+            $result->entity_id  = $post->ID;
202
+            $results[]          = $result;
203
+        }
204
+
205
+        return $results;
206
+    }
207
+
208
+    private function get_entity_results(
209
+        $post_id,
210
+        $fields = array(
211
+            'ID',
212
+            'post_title',
213
+        ),
214
+        $order_by = 'ID DESC',
215
+        $limit = 10,
216
+        $offset = 0
217
+    ) {
218
+        global $wpdb;
219
+
220
+        $select = implode(
221
+            ', ',
222
+            array_map(
223
+                function ( $item ) {
224
+                    return "p.$item AS $item";
225
+                },
226
+                (array) $fields
227
+            )
228
+        );
229
+
230
+        $order_by = implode(
231
+            ', ',
232
+            array_map(
233
+                function ( $item ) {
234
+                    return "p.$item";
235
+                },
236
+                (array) $order_by
237
+            )
238
+        );
239 239
 // phpcs:disable WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder
240
-		/** @noinspection SqlNoDataSourceInspection */
241
-		return $wpdb->get_results(
242
-			$wpdb->prepare(
243
-				"
240
+        /** @noinspection SqlNoDataSourceInspection */
241
+        return $wpdb->get_results(
242
+            $wpdb->prepare(
243
+                "
244 244
 SELECT %4\$s, p2.ID as entity_id
245 245
  FROM {$wpdb->prefix}wl_relation_instances r1
246 246
 	-- get the ID of the post entity in common between the object and the subject 2. 
@@ -273,51 +273,51 @@  discard block
 block discarded – undo
273 273
  LIMIT %2\$d
274 274
  OFFSET %3\$d
275 275
 ",
276
-				$post_id,
277
-				$limit,
278
-				$offset,
279
-				$select,
280
-				$order_by
281
-			)
282
-		);
283
-	}
276
+                $post_id,
277
+                $limit,
278
+                $offset,
279
+                $select,
280
+                $order_by
281
+            )
282
+        );
283
+    }
284 284
 // phpcs:enable
285
-	private function get_post_results(
286
-		$post_id,
287
-		$fields = array(
288
-			'ID',
289
-			'post_title',
290
-		),
291
-		$order_by = 'ID DESC',
292
-		$limit = 10,
293
-		$offset = 0
294
-	) {
295
-		global $wpdb;
296
-
297
-		$select = implode(
298
-			', ',
299
-			array_map(
300
-				function ( $item ) {
301
-					return "p.$item AS $item";
302
-				},
303
-				(array) $fields
304
-			)
305
-		);
306
-
307
-		$order_by = implode(
308
-			', ',
309
-			array_map(
310
-				function ( $item ) {
311
-					return "p.$item";
312
-				},
313
-				(array) $order_by
314
-			)
315
-		);
285
+    private function get_post_results(
286
+        $post_id,
287
+        $fields = array(
288
+            'ID',
289
+            'post_title',
290
+        ),
291
+        $order_by = 'ID DESC',
292
+        $limit = 10,
293
+        $offset = 0
294
+    ) {
295
+        global $wpdb;
296
+
297
+        $select = implode(
298
+            ', ',
299
+            array_map(
300
+                function ( $item ) {
301
+                    return "p.$item AS $item";
302
+                },
303
+                (array) $fields
304
+            )
305
+        );
306
+
307
+        $order_by = implode(
308
+            ', ',
309
+            array_map(
310
+                function ( $item ) {
311
+                    return "p.$item";
312
+                },
313
+                (array) $order_by
314
+            )
315
+        );
316 316
 // phpcs:disable WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder,WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
317
-		/** @noinspection SqlNoDataSourceInspection */
318
-		return $wpdb->get_results(
319
-			$wpdb->prepare(
320
-				"
317
+        /** @noinspection SqlNoDataSourceInspection */
318
+        return $wpdb->get_results(
319
+            $wpdb->prepare(
320
+                "
321 321
 SELECT %4\$s, p2.ID as entity_id
322 322
  FROM {$wpdb->prefix}wl_relation_instances r1
323 323
     INNER JOIN {$wpdb->prefix}wl_relation_instances r2
@@ -353,13 +353,13 @@  discard block
 block discarded – undo
353 353
  LIMIT %2\$d
354 354
  OFFSET %3\$d
355 355
 ",
356
-				$post_id,
357
-				$limit,
358
-				$offset,
359
-				$select,
360
-				$order_by
361
-			)
362
-		);
363
-	}
356
+                $post_id,
357
+                $limit,
358
+                $offset,
359
+                $select,
360
+                $order_by
361
+            )
362
+        );
363
+    }
364 364
 // phpcs:enable
365 365
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -11,12 +11,12 @@  discard block
 block discarded – undo
11 11
 			'/products-navigator',
12 12
 			array(
13 13
 				'post_id' => array(
14
-					'description' => __( 'Post ID for which Navigator has to be queried', 'wordlift' ),
14
+					'description' => __('Post ID for which Navigator has to be queried', 'wordlift'),
15 15
 					'type'        => 'integer',
16 16
 					'required'    => true,
17 17
 				),
18 18
 				'uniqid'  => array(
19
-					'description' => __( 'Navigator uniqueid', 'wordlift' ),
19
+					'description' => __('Navigator uniqueid', 'wordlift'),
20 20
 					'type'        => 'string',
21 21
 					'required'    => true,
22 22
 				),
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 		);
42 42
 	}
43 43
 
44
-	public function get_data( $request ) {
44
+	public function get_data($request) {
45 45
 
46 46
 		// Sanitize and set defaults
47 47
 		$navigator_length = $request['limit'];
@@ -51,15 +51,15 @@  discard block
 block discarded – undo
51 51
 		$navigator_id     = $request['uniqid'];
52 52
 		$amp              = $request['amp'];
53 53
 
54
-		$post = get_post( $post_id );
54
+		$post = get_post($post_id);
55 55
 
56 56
 		// Post ID has to match an existing item
57
-		if ( null === $post ) {
58
-			return new WP_Error( 'rest_invalid_post_id', __( 'Invalid post_id', 'wordlift' ), array( 'status' => 404 ) );
57
+		if (null === $post) {
58
+			return new WP_Error('rest_invalid_post_id', __('Invalid post_id', 'wordlift'), array('status' => 404));
59 59
 		}
60 60
 
61 61
 		// Determine navigator type and call respective get_*_results
62
-		if ( get_post_type( $post_id ) === Wordlift_Entity_Service::TYPE_NAME ) {
62
+		if (get_post_type($post_id) === Wordlift_Entity_Service::TYPE_NAME) {
63 63
 			$referencing_posts = $this->get_entity_results(
64 64
 				$post_id,
65 65
 				array(
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 		$directly_referencing_posts = $this->get_directly_referencing_posts(
88 88
 			$post_id,
89 89
 			array_map(
90
-				function ( $referencing_post ) {
90
+				function($referencing_post) {
91 91
 					return $referencing_post->ID;
92 92
 				},
93 93
 				$referencing_posts
@@ -95,34 +95,34 @@  discard block
 block discarded – undo
95 95
 		);
96 96
 
97 97
 		// Combine directly referencing posts and referencing posts via entities
98
-		$referencing_posts = array_merge( $directly_referencing_posts, $referencing_posts );
98
+		$referencing_posts = array_merge($directly_referencing_posts, $referencing_posts);
99 99
 
100 100
 		// loop over them and take the first one which is not already in the $related_posts
101 101
 		$results = array();
102
-		foreach ( $referencing_posts as $referencing_post ) {
103
-			$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
104
-			$product           = wc_get_product( $referencing_post->ID );
102
+		foreach ($referencing_posts as $referencing_post) {
103
+			$serialized_entity = wl_serialize_entity($referencing_post->entity_id);
104
+			$product           = wc_get_product($referencing_post->ID);
105 105
 
106 106
 			$result = array(
107 107
 				'product' => array(
108 108
 					'id'              => $referencing_post->ID,
109
-					'permalink'       => get_permalink( $referencing_post->ID ),
109
+					'permalink'       => get_permalink($referencing_post->ID),
110 110
 					'title'           => $referencing_post->post_title,
111
-					'thumbnail'       => get_the_post_thumbnail_url( $referencing_post, 'medium' ),
111
+					'thumbnail'       => get_the_post_thumbnail_url($referencing_post, 'medium'),
112 112
 					'regular_price'   => $product->get_regular_price(),
113 113
 					'sale_price'      => $product->get_sale_price(),
114 114
 					'price'           => $product->get_price(),
115 115
 					'currency_symbol' => get_woocommerce_currency_symbol(),
116
-					'discount_pc'     => ( $product->get_sale_price() && ( $product->get_regular_price() > 0 ) ) ? round( 1 - ( $product->get_sale_price() / $product->get_regular_price() ), 2 ) * 100 : 0,
116
+					'discount_pc'     => ($product->get_sale_price() && ($product->get_regular_price() > 0)) ? round(1 - ($product->get_sale_price() / $product->get_regular_price()), 2) * 100 : 0,
117 117
 					'average_rating'  => $product->get_average_rating(),
118 118
 					'rating_count'    => $product->get_rating_count(),
119
-					'rating_html'     => wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ),
119
+					'rating_html'     => wc_get_rating_html($product->get_average_rating(), $product->get_rating_count()),
120 120
 				),
121 121
 				'entity'  => array(
122 122
 					'id'        => $referencing_post->entity_id,
123 123
 					'label'     => $serialized_entity['label'],
124 124
 					'mainType'  => $serialized_entity['mainType'],
125
-					'permalink' => get_permalink( $referencing_post->entity_id ),
125
+					'permalink' => get_permalink($referencing_post->entity_id),
126 126
 				),
127 127
 			);
128 128
 
@@ -130,15 +130,15 @@  discard block
 block discarded – undo
130 130
 
131 131
 		}
132 132
 
133
-		if ( count( $results ) < $navigator_length ) {
134
-			$results = apply_filters( 'wl_products_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
133
+		if (count($results) < $navigator_length) {
134
+			$results = apply_filters('wl_products_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length);
135 135
 		}
136 136
 
137 137
 		// Add filler posts if needed
138
-		$filler_count = $navigator_length - count( $results );
139
-		if ( $filler_count > 0 ) {
138
+		$filler_count = $navigator_length - count($results);
139
+		if ($filler_count > 0) {
140 140
 			$referencing_post_ids = array_map(
141
-				function ( $p ) {
141
+				function($p) {
142 142
 					return $p->ID;
143 143
 				},
144 144
 				$referencing_posts
@@ -147,33 +147,33 @@  discard block
 block discarded – undo
147 147
 			 * @since 3.28.0
148 148
 			 * Filler posts are fetched using this util.
149 149
 			 */
150
-			$filler_posts_util       = new Filler_Posts_Util( $post_id, 'product' );
151
-			$post_ids_to_be_excluded = array_merge( array( $post_id ), $referencing_post_ids );
152
-			$filler_posts            = $filler_posts_util->get_product_navigator_response( $filler_count, $post_ids_to_be_excluded );
153
-			$results                 = array_merge( $results, $filler_posts );
150
+			$filler_posts_util       = new Filler_Posts_Util($post_id, 'product');
151
+			$post_ids_to_be_excluded = array_merge(array($post_id), $referencing_post_ids);
152
+			$filler_posts            = $filler_posts_util->get_product_navigator_response($filler_count, $post_ids_to_be_excluded);
153
+			$results                 = array_merge($results, $filler_posts);
154 154
 		}
155 155
 
156 156
 		// Apply filters after fillers are added
157
-		foreach ( $results as $result_index => $result ) {
158
-			$results[ $result_index ]['product'] = apply_filters( 'wl_products_navigator_data_post', $result['product'], intval( $result['product']['id'] ), $navigator_id );
159
-			$results[ $result_index ]['entity']  = apply_filters( 'wl_products_navigator_data_entity', $result['entity'], intval( $result['entity']['id'] ), $navigator_id );
157
+		foreach ($results as $result_index => $result) {
158
+			$results[$result_index]['product'] = apply_filters('wl_products_navigator_data_post', $result['product'], intval($result['product']['id']), $navigator_id);
159
+			$results[$result_index]['entity']  = apply_filters('wl_products_navigator_data_entity', $result['entity'], intval($result['entity']['id']), $navigator_id);
160 160
 		}
161 161
 
162
-		$results = apply_filters( 'wl_products_navigator_results', $results, $navigator_id );
162
+		$results = apply_filters('wl_products_navigator_results', $results, $navigator_id);
163 163
 
164 164
 		return $amp ? array(
165 165
 			'items' => array(
166
-				array( 'values' => $results ),
166
+				array('values' => $results),
167 167
 			),
168 168
 		) : $results;
169 169
 
170 170
 	}
171 171
 
172
-	private function get_directly_referencing_posts( $post_id, $referencing_post_ids ) {
172
+	private function get_directly_referencing_posts($post_id, $referencing_post_ids) {
173 173
 
174
-		$directly_referencing_post_ids = Wordlift_Entity_Service::get_instance()->get_related_entities( $post_id );
174
+		$directly_referencing_post_ids = Wordlift_Entity_Service::get_instance()->get_related_entities($post_id);
175 175
 
176
-		$post__in = array_diff( $directly_referencing_post_ids, $referencing_post_ids );
176
+		$post__in = array_diff($directly_referencing_post_ids, $referencing_post_ids);
177 177
 
178 178
 		$directly_referencing_posts = get_posts(
179 179
 			array(
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 
195 195
 		$results = array();
196 196
 
197
-		foreach ( $directly_referencing_posts as $post ) {
197
+		foreach ($directly_referencing_posts as $post) {
198 198
 			$result             = new stdClass();
199 199
 			$result->ID         = $post->ID;
200 200
 			$result->post_title = $post->post_title;
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 		$select = implode(
221 221
 			', ',
222 222
 			array_map(
223
-				function ( $item ) {
223
+				function($item) {
224 224
 					return "p.$item AS $item";
225 225
 				},
226 226
 				(array) $fields
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 		$order_by = implode(
231 231
 			', ',
232 232
 			array_map(
233
-				function ( $item ) {
233
+				function($item) {
234 234
 					return "p.$item";
235 235
 				},
236 236
 				(array) $order_by
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 		$select = implode(
298 298
 			', ',
299 299
 			array_map(
300
-				function ( $item ) {
300
+				function($item) {
301 301
 					return "p.$item AS $item";
302 302
 				},
303 303
 				(array) $fields
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 		$order_by = implode(
308 308
 			', ',
309 309
 			array_map(
310
-				function ( $item ) {
310
+				function($item) {
311 311
 					return "p.$item";
312 312
 				},
313 313
 				(array) $order_by
Please login to merge, or discard this patch.