Completed
Push — develop ( 52a408...ad9e4d )
by
unknown
03:05
created
src/public/class-wordlift-products-navigator-shortcode.php 2 patches
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -17,158 +17,158 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Wordlift_Products_Navigator_Shortcode extends Wordlift_Shortcode {
19 19
 
20
-	/**
21
-	 * {@inheritdoc}
22
-	 */
23
-	const SHORTCODE = 'wl_products_navigator';
20
+    /**
21
+     * {@inheritdoc}
22
+     */
23
+    const SHORTCODE = 'wl_products_navigator';
24 24
 
25
-	public function __construct() {
26
-		parent::__construct();
27
-		$this->register_block_type();
28
-	}
25
+    public function __construct() {
26
+        parent::__construct();
27
+        $this->register_block_type();
28
+    }
29 29
 
30
-	/**
31
-	 * {@inheritdoc}
32
-	 */
33
-	public function render( $atts ) {
30
+    /**
31
+     * {@inheritdoc}
32
+     */
33
+    public function render( $atts ) {
34 34
 
35
-		return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts )
36
-			: $this->web_shortcode( $atts );
37
-	}
35
+        return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts )
36
+            : $this->web_shortcode( $atts );
37
+    }
38 38
 
39
-	private function register_block_type() {
39
+    private function register_block_type() {
40 40
 
41
-		$scope = $this;
41
+        $scope = $this;
42 42
 
43
-		add_action( 'init', function () use ( $scope ) {
44
-			if ( ! function_exists( 'register_block_type' ) ) {
45
-				// Gutenberg is not active.
46
-				return;
47
-			}
43
+        add_action( 'init', function () use ( $scope ) {
44
+            if ( ! function_exists( 'register_block_type' ) ) {
45
+                // Gutenberg is not active.
46
+                return;
47
+            }
48 48
 
49
-			register_block_type( 'wordlift/products-navigator', array(
50
-				'editor_script'   => 'wl-block-editor',
51
-				'render_callback' => function ( $attributes ) use ( $scope ) {
52
-					$attr_code = '';
53
-					foreach ( $attributes as $key => $value ) {
54
-						$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
55
-					}
49
+            register_block_type( 'wordlift/products-navigator', array(
50
+                'editor_script'   => 'wl-block-editor',
51
+                'render_callback' => function ( $attributes ) use ( $scope ) {
52
+                    $attr_code = '';
53
+                    foreach ( $attributes as $key => $value ) {
54
+                        $attr_code .= $key . '="' . htmlentities( $value ) . '" ';
55
+                    }
56 56
 
57
-					return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
58
-				},
59
-				'attributes'      => array(
60
-					'title'       => array(
61
-						'type'    => 'string',
62
-						'default' => __( 'Related products', 'wordlift' ),
63
-					),
64
-					'limit'       => array(
65
-						'type'    => 'number',
66
-						'default' => 4,
67
-					),
68
-					'template_id' => array(
69
-						'type' => 'string',
70
-						'default' => '',
71
-					),
72
-					'post_id'     => array(
73
-						'type' => 'number',
74
-						'default' => '',
75
-					),
76
-					'offset'      => array(
77
-						'type'    => 'number',
78
-						'default' => 0,
79
-					),
80
-					'uniqid'      => array(
81
-						'type'    => 'string',
82
-						'default' => '',
83
-					),
84
-					'order_by'    => array(
85
-						'type'    => 'string',
86
-						'default' => 'ID DESC',
87
-					),
88
-					'preview'     => array(
89
-						'type'    => 'boolean',
90
-						'default' => false,
91
-					),
92
-					'preview_src'     => array(
93
-						'type'    => 'string',
94
-						'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/products-navigator.png',
95
-					),
96
-				),
97
-			) );
98
-		} );
99
-	}
57
+                    return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
58
+                },
59
+                'attributes'      => array(
60
+                    'title'       => array(
61
+                        'type'    => 'string',
62
+                        'default' => __( 'Related products', 'wordlift' ),
63
+                    ),
64
+                    'limit'       => array(
65
+                        'type'    => 'number',
66
+                        'default' => 4,
67
+                    ),
68
+                    'template_id' => array(
69
+                        'type' => 'string',
70
+                        'default' => '',
71
+                    ),
72
+                    'post_id'     => array(
73
+                        'type' => 'number',
74
+                        'default' => '',
75
+                    ),
76
+                    'offset'      => array(
77
+                        'type'    => 'number',
78
+                        'default' => 0,
79
+                    ),
80
+                    'uniqid'      => array(
81
+                        'type'    => 'string',
82
+                        'default' => '',
83
+                    ),
84
+                    'order_by'    => array(
85
+                        'type'    => 'string',
86
+                        'default' => 'ID DESC',
87
+                    ),
88
+                    'preview'     => array(
89
+                        'type'    => 'boolean',
90
+                        'default' => false,
91
+                    ),
92
+                    'preview_src'     => array(
93
+                        'type'    => 'string',
94
+                        'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/products-navigator.png',
95
+                    ),
96
+                ),
97
+            ) );
98
+        } );
99
+    }
100 100
 
101
-	/**
102
-	 * Shared function used by web_shortcode and amp_shortcode
103
-	 * Bootstrap logic for attributes extraction and boolean filtering
104
-	 *
105
-	 * @param array $atts Shortcode attributes.
106
-	 *
107
-	 * @return array $shortcode_atts
108
-	 * @since      3.27.0
109
-	 *
110
-	 */
111
-	private function make_shortcode_atts( $atts ) {
101
+    /**
102
+     * Shared function used by web_shortcode and amp_shortcode
103
+     * Bootstrap logic for attributes extraction and boolean filtering
104
+     *
105
+     * @param array $atts Shortcode attributes.
106
+     *
107
+     * @return array $shortcode_atts
108
+     * @since      3.27.0
109
+     *
110
+     */
111
+    private function make_shortcode_atts( $atts ) {
112 112
 
113
-		// Extract attributes and set default values.
114
-		$shortcode_atts = shortcode_atts( array(
115
-			'title'       => __( 'Related products', 'wordlift' ),
116
-			'limit'       => 4,
117
-			'offset'      => 0,
118
-			'template_id' => '',
119
-			'post_id'     => '',
120
-			'uniqid'      => uniqid( 'wl-products-navigator-widget-' ),
121
-			'order_by'    => 'ID DESC'
122
-		), $atts );
113
+        // Extract attributes and set default values.
114
+        $shortcode_atts = shortcode_atts( array(
115
+            'title'       => __( 'Related products', 'wordlift' ),
116
+            'limit'       => 4,
117
+            'offset'      => 0,
118
+            'template_id' => '',
119
+            'post_id'     => '',
120
+            'uniqid'      => uniqid( 'wl-products-navigator-widget-' ),
121
+            'order_by'    => 'ID DESC'
122
+        ), $atts );
123 123
 
124
-		return $shortcode_atts;
125
-	}
124
+        return $shortcode_atts;
125
+    }
126 126
 
127
-	/**
128
-	 * Function in charge of diplaying the [wl_products_navigator] in web mode.
129
-	 *
130
-	 * @param array $atts Shortcode attributes.
131
-	 *
132
-	 * @return string Shortcode HTML for web
133
-	 * @since 3.20.0
134
-	 *
135
-	 */
136
-	private function web_shortcode( $atts ) {
127
+    /**
128
+     * Function in charge of diplaying the [wl_products_navigator] in web mode.
129
+     *
130
+     * @param array $atts Shortcode attributes.
131
+     *
132
+     * @return string Shortcode HTML for web
133
+     * @since 3.20.0
134
+     *
135
+     */
136
+    private function web_shortcode( $atts ) {
137 137
 
138
-		// attributes extraction and boolean filtering
139
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
138
+        // attributes extraction and boolean filtering
139
+        $shortcode_atts = $this->make_shortcode_atts( $atts );
140 140
 
141
-		// avoid building the widget when no post_id is specified and there is a list of posts.
142
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
143
-			return;
144
-		}
141
+        // avoid building the widget when no post_id is specified and there is a list of posts.
142
+        if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
143
+            return;
144
+        }
145 145
 
146
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
147
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
148
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
149
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
150
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
151
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
152
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-products-navigator-widget-' );
146
+        $post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
147
+        $title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
148
+        $template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
149
+        $limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
150
+        $offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
151
+        $sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
152
+        $navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-products-navigator-widget-' );
153 153
 
154
-		$permalink_structure = get_option( 'permalink_structure' );
155
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
156
-		$rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/products-navigator' . $delimiter . build_query( array(
157
-				'uniqid'  => $navigator_id,
158
-				'post_id' => $post->ID,
159
-				'limit'   => $limit,
160
-				'offset'  => $offset,
161
-				'sort'    => $sort
162
-			) ) ) : false;
154
+        $permalink_structure = get_option( 'permalink_structure' );
155
+        $delimiter           = empty( $permalink_structure ) ? '&' : '?';
156
+        $rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/products-navigator' . $delimiter . build_query( array(
157
+                'uniqid'  => $navigator_id,
158
+                'post_id' => $post->ID,
159
+                'limit'   => $limit,
160
+                'offset'  => $offset,
161
+                'sort'    => $sort
162
+            ) ) ) : false;
163 163
 
164
-		// avoid building the widget when no valid $rest_url
165
-		if ( ! $rest_url ) {
166
-			return;
167
-		}
164
+        // avoid building the widget when no valid $rest_url
165
+        if ( ! $rest_url ) {
166
+            return;
167
+        }
168 168
 
169
-		wp_enqueue_script( 'wordlift-cloud' );
169
+        wp_enqueue_script( 'wordlift-cloud' );
170 170
 
171
-		return <<<HTML
171
+        return <<<HTML
172 172
 			<!-- Products Navigator {$navigator_id} -->
173 173
 			<div id="{$navigator_id}" 
174 174
 				 class="wl-products-navigator" 
@@ -178,61 +178,61 @@  discard block
 block discarded – undo
178 178
 				 data-limit="{$limit}"></div>
179 179
 			<!-- /Products Navigator {$navigator_id} -->
180 180
 HTML;
181
-	}
181
+    }
182 182
 
183
-	/**
184
-	 * Function in charge of diplaying the [wl_products_navigator] in amp mode.
185
-	 *
186
-	 * @param array $atts Shortcode attributes.
187
-	 *
188
-	 * @return string Shortcode HTML for amp
189
-	 * @since 3.20.0
190
-	 *
191
-	 */
192
-	private function amp_shortcode( $atts ) {
183
+    /**
184
+     * Function in charge of diplaying the [wl_products_navigator] in amp mode.
185
+     *
186
+     * @param array $atts Shortcode attributes.
187
+     *
188
+     * @return string Shortcode HTML for amp
189
+     * @since 3.20.0
190
+     *
191
+     */
192
+    private function amp_shortcode( $atts ) {
193 193
 
194
-		// attributes extraction and boolean filtering
195
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
194
+        // attributes extraction and boolean filtering
195
+        $shortcode_atts = $this->make_shortcode_atts( $atts );
196 196
 
197
-		// avoid building the widget when no post_id is specified and there is a list of posts.
198
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
199
-			return;
200
-		}
197
+        // avoid building the widget when no post_id is specified and there is a list of posts.
198
+        if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
199
+            return;
200
+        }
201 201
 
202
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
203
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
204
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
205
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
206
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
207
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
208
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-products-navigator-widget-' );
202
+        $post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
203
+        $title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
204
+        $template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
205
+        $limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
206
+        $offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
207
+        $sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
208
+        $navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-products-navigator-widget-' );
209 209
 
210
-		$permalink_structure = get_option( 'permalink_structure' );
211
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
212
-		$rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/products-navigator' . $delimiter . build_query( array(
213
-				'amp'     => true,
214
-				'uniqid'  => $navigator_id,
215
-				'post_id' => $post->ID,
216
-				'limit'   => $limit,
217
-				'offset'  => $offset,
218
-				'sort'    => $sort
219
-			) ) ) : false;
210
+        $permalink_structure = get_option( 'permalink_structure' );
211
+        $delimiter           = empty( $permalink_structure ) ? '&' : '?';
212
+        $rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/products-navigator' . $delimiter . build_query( array(
213
+                'amp'     => true,
214
+                'uniqid'  => $navigator_id,
215
+                'post_id' => $post->ID,
216
+                'limit'   => $limit,
217
+                'offset'  => $offset,
218
+                'sort'    => $sort
219
+            ) ) ) : false;
220 220
 
221
-		// avoid building the widget when no valid $rest_url
222
-		if ( ! $rest_url ) {
223
-			return;
224
-		}
221
+        // avoid building the widget when no valid $rest_url
222
+        if ( ! $rest_url ) {
223
+            return;
224
+        }
225 225
 
226
-		// Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
227
-		// This is a hackish way, but this works for http and https URLs
228
-		$rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
226
+        // Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
227
+        // This is a hackish way, but this works for http and https URLs
228
+        $rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
229 229
 
230
-		if ( empty( $template_id ) ) {
231
-			$template_id = "template-" . $navigator_id;
232
-			wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( dirname( __FILE__ ) ) . '/css/wordlift-amp-custom.min.css' );
233
-		}
230
+        if ( empty( $template_id ) ) {
231
+            $template_id = "template-" . $navigator_id;
232
+            wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( dirname( __FILE__ ) ) . '/css/wordlift-amp-custom.min.css' );
233
+        }
234 234
 
235
-		return <<<HTML
235
+        return <<<HTML
236 236
 		<div id="{$navigator_id}" class="wl-amp-products-navigator">
237 237
 			<h3 class="wl-headline">{$title}</h3>
238 238
 			<section class="cards">
@@ -334,6 +334,6 @@  discard block
 block discarded – undo
334 334
 			</section>
335 335
 		</div>
336 336
 HTML;
337
-	}
337
+    }
338 338
 
339 339
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -30,36 +30,36 @@  discard block
 block discarded – undo
30 30
 	/**
31 31
 	 * {@inheritdoc}
32 32
 	 */
33
-	public function render( $atts ) {
33
+	public function render($atts) {
34 34
 
35
-		return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts )
36
-			: $this->web_shortcode( $atts );
35
+		return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode($atts)
36
+			: $this->web_shortcode($atts);
37 37
 	}
38 38
 
39 39
 	private function register_block_type() {
40 40
 
41 41
 		$scope = $this;
42 42
 
43
-		add_action( 'init', function () use ( $scope ) {
44
-			if ( ! function_exists( 'register_block_type' ) ) {
43
+		add_action('init', function() use ($scope) {
44
+			if ( ! function_exists('register_block_type')) {
45 45
 				// Gutenberg is not active.
46 46
 				return;
47 47
 			}
48 48
 
49
-			register_block_type( 'wordlift/products-navigator', array(
49
+			register_block_type('wordlift/products-navigator', array(
50 50
 				'editor_script'   => 'wl-block-editor',
51
-				'render_callback' => function ( $attributes ) use ( $scope ) {
51
+				'render_callback' => function($attributes) use ($scope) {
52 52
 					$attr_code = '';
53
-					foreach ( $attributes as $key => $value ) {
54
-						$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
53
+					foreach ($attributes as $key => $value) {
54
+						$attr_code .= $key.'="'.htmlentities($value).'" ';
55 55
 					}
56 56
 
57
-					return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
57
+					return '['.$scope::SHORTCODE.' '.$attr_code.']';
58 58
 				},
59 59
 				'attributes'      => array(
60 60
 					'title'       => array(
61 61
 						'type'    => 'string',
62
-						'default' => __( 'Related products', 'wordlift' ),
62
+						'default' => __('Related products', 'wordlift'),
63 63
 					),
64 64
 					'limit'       => array(
65 65
 						'type'    => 'number',
@@ -91,10 +91,10 @@  discard block
 block discarded – undo
91 91
 					),
92 92
 					'preview_src'     => array(
93 93
 						'type'    => 'string',
94
-						'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/products-navigator.png',
94
+						'default' => WP_CONTENT_URL.'/plugins/wordlift/images/block-previews/products-navigator.png',
95 95
 					),
96 96
 				),
97
-			) );
97
+			));
98 98
 		} );
99 99
 	}
100 100
 
@@ -108,18 +108,18 @@  discard block
 block discarded – undo
108 108
 	 * @since      3.27.0
109 109
 	 *
110 110
 	 */
111
-	private function make_shortcode_atts( $atts ) {
111
+	private function make_shortcode_atts($atts) {
112 112
 
113 113
 		// Extract attributes and set default values.
114
-		$shortcode_atts = shortcode_atts( array(
115
-			'title'       => __( 'Related products', 'wordlift' ),
114
+		$shortcode_atts = shortcode_atts(array(
115
+			'title'       => __('Related products', 'wordlift'),
116 116
 			'limit'       => 4,
117 117
 			'offset'      => 0,
118 118
 			'template_id' => '',
119 119
 			'post_id'     => '',
120
-			'uniqid'      => uniqid( 'wl-products-navigator-widget-' ),
120
+			'uniqid'      => uniqid('wl-products-navigator-widget-'),
121 121
 			'order_by'    => 'ID DESC'
122
-		), $atts );
122
+		), $atts);
123 123
 
124 124
 		return $shortcode_atts;
125 125
 	}
@@ -133,40 +133,40 @@  discard block
 block discarded – undo
133 133
 	 * @since 3.20.0
134 134
 	 *
135 135
 	 */
136
-	private function web_shortcode( $atts ) {
136
+	private function web_shortcode($atts) {
137 137
 
138 138
 		// attributes extraction and boolean filtering
139
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
139
+		$shortcode_atts = $this->make_shortcode_atts($atts);
140 140
 
141 141
 		// avoid building the widget when no post_id is specified and there is a list of posts.
142
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
142
+		if (empty($shortcode_atts['post_id']) && ! is_singular()) {
143 143
 			return;
144 144
 		}
145 145
 
146
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
147
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
148
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
149
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
150
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
151
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
152
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-products-navigator-widget-' );
146
+		$post         = ! empty($shortcode_atts['post_id']) ? get_post(intval(sanitize_text_field($shortcode_atts['post_id']))) : get_post();
147
+		$title        = esc_attr(sanitize_text_field($shortcode_atts['title']));
148
+		$template_id  = esc_attr(sanitize_text_field($shortcode_atts['template_id']));
149
+		$limit        = esc_attr(sanitize_text_field($shortcode_atts['limit']));
150
+		$offset       = esc_attr(sanitize_text_field($shortcode_atts['offset']));
151
+		$sort         = esc_attr(sanitize_sql_orderby(sanitize_text_field($shortcode_atts['order_by'])));
152
+		$navigator_id = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-products-navigator-widget-');
153 153
 
154
-		$permalink_structure = get_option( 'permalink_structure' );
155
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
156
-		$rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/products-navigator' . $delimiter . build_query( array(
154
+		$permalink_structure = get_option('permalink_structure');
155
+		$delimiter           = empty($permalink_structure) ? '&' : '?';
156
+		$rest_url            = $post ? rest_url(WL_REST_ROUTE_DEFAULT_NAMESPACE.'/products-navigator'.$delimiter.build_query(array(
157 157
 				'uniqid'  => $navigator_id,
158 158
 				'post_id' => $post->ID,
159 159
 				'limit'   => $limit,
160 160
 				'offset'  => $offset,
161 161
 				'sort'    => $sort
162
-			) ) ) : false;
162
+			))) : false;
163 163
 
164 164
 		// avoid building the widget when no valid $rest_url
165
-		if ( ! $rest_url ) {
165
+		if ( ! $rest_url) {
166 166
 			return;
167 167
 		}
168 168
 
169
-		wp_enqueue_script( 'wordlift-cloud' );
169
+		wp_enqueue_script('wordlift-cloud');
170 170
 
171 171
 		return <<<HTML
172 172
 			<!-- Products Navigator {$navigator_id} -->
@@ -189,47 +189,47 @@  discard block
 block discarded – undo
189 189
 	 * @since 3.20.0
190 190
 	 *
191 191
 	 */
192
-	private function amp_shortcode( $atts ) {
192
+	private function amp_shortcode($atts) {
193 193
 
194 194
 		// attributes extraction and boolean filtering
195
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
195
+		$shortcode_atts = $this->make_shortcode_atts($atts);
196 196
 
197 197
 		// avoid building the widget when no post_id is specified and there is a list of posts.
198
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
198
+		if (empty($shortcode_atts['post_id']) && ! is_singular()) {
199 199
 			return;
200 200
 		}
201 201
 
202
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
203
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
204
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
205
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
206
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
207
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
208
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-products-navigator-widget-' );
202
+		$post         = ! empty($shortcode_atts['post_id']) ? get_post(intval(sanitize_text_field($shortcode_atts['post_id']))) : get_post();
203
+		$title        = esc_attr(sanitize_text_field($shortcode_atts['title']));
204
+		$template_id  = esc_attr(sanitize_text_field($shortcode_atts['template_id']));
205
+		$limit        = esc_attr(sanitize_text_field($shortcode_atts['limit']));
206
+		$offset       = esc_attr(sanitize_text_field($shortcode_atts['offset']));
207
+		$sort         = esc_attr(sanitize_sql_orderby(sanitize_text_field($shortcode_atts['order_by'])));
208
+		$navigator_id = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-products-navigator-widget-');
209 209
 
210
-		$permalink_structure = get_option( 'permalink_structure' );
211
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
212
-		$rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/products-navigator' . $delimiter . build_query( array(
210
+		$permalink_structure = get_option('permalink_structure');
211
+		$delimiter           = empty($permalink_structure) ? '&' : '?';
212
+		$rest_url            = $post ? rest_url(WL_REST_ROUTE_DEFAULT_NAMESPACE.'/products-navigator'.$delimiter.build_query(array(
213 213
 				'amp'     => true,
214 214
 				'uniqid'  => $navigator_id,
215 215
 				'post_id' => $post->ID,
216 216
 				'limit'   => $limit,
217 217
 				'offset'  => $offset,
218 218
 				'sort'    => $sort
219
-			) ) ) : false;
219
+			))) : false;
220 220
 
221 221
 		// avoid building the widget when no valid $rest_url
222
-		if ( ! $rest_url ) {
222
+		if ( ! $rest_url) {
223 223
 			return;
224 224
 		}
225 225
 
226 226
 		// Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
227 227
 		// This is a hackish way, but this works for http and https URLs
228
-		$rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
228
+		$rest_url = str_replace(array('http:', 'https:'), '', $rest_url);
229 229
 
230
-		if ( empty( $template_id ) ) {
231
-			$template_id = "template-" . $navigator_id;
232
-			wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( dirname( __FILE__ ) ) . '/css/wordlift-amp-custom.min.css' );
230
+		if (empty($template_id)) {
231
+			$template_id = "template-".$navigator_id;
232
+			wp_enqueue_style('wordlift-amp-custom', plugin_dir_url(dirname(__FILE__)).'/css/wordlift-amp-custom.min.css');
233 233
 		}
234 234
 
235 235
 		return <<<HTML
Please login to merge, or discard this patch.
src/public/class-wordlift-navigator-shortcode.php 2 patches
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -17,123 +17,123 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Wordlift_Navigator_Shortcode extends Wordlift_Shortcode {
19 19
 
20
-	/**
21
-	 * {@inheritdoc}
22
-	 */
23
-	const SHORTCODE = 'wl_navigator';
24
-
25
-	public function __construct() {
26
-		parent::__construct();
27
-		$this->register_block_type();
28
-	}
29
-
30
-	/**
31
-	 * {@inheritdoc}
32
-	 */
33
-	public function render( $atts ) {
34
-
35
-		return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts )
36
-			: $this->web_shortcode( $atts );
37
-	}
38
-
39
-	private function register_block_type() {
40
-
41
-		$scope = $this;
42
-
43
-		add_action( 'init', function () use ( $scope ) {
44
-			if ( ! function_exists( 'register_block_type' ) ) {
45
-				// Gutenberg is not active.
46
-				return;
47
-			}
48
-
49
-			register_block_type( 'wordlift/navigator', array(
50
-				'editor_script'   => 'wl-block-editor',
51
-				'render_callback' => function ( $attributes ) use ( $scope ) {
52
-					$attr_code = '';
53
-					foreach ( $attributes as $key => $value ) {
54
-						$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
55
-					}
56
-
57
-					return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
58
-				},
59
-				'attributes'      => $scope->get_navigator_block_attributes(),
60
-			) );
61
-		} );
62
-	}
63
-
64
-	/**
65
-	 * Shared function used by web_shortcode and amp_shortcode
66
-	 * Bootstrap logic for attributes extraction and boolean filtering
67
-	 *
68
-	 * @param array $atts Shortcode attributes.
69
-	 *
70
-	 * @return array $shortcode_atts
71
-	 * @since      3.20.0
72
-	 *
73
-	 */
74
-	private function make_shortcode_atts( $atts ) {
75
-
76
-		// Extract attributes and set default values.
77
-		$shortcode_atts = shortcode_atts( array(
78
-			'title'       => __( 'Related articles', 'wordlift' ),
79
-			'limit'       => 4,
80
-			'offset'      => 0,
81
-			'template_id' => '',
82
-			'post_id'     => '',
83
-			'uniqid'      => uniqid( 'wl-navigator-widget-' ),
84
-			'order_by'    => 'ID DESC',
85
-			'post_types'  => '',
86
-		), $atts );
87
-
88
-		return $shortcode_atts;
89
-	}
90
-
91
-	/**
92
-	 * Function in charge of displaying the [wl-navigator] in web mode.
93
-	 *
94
-	 * @param array $atts Shortcode attributes.
95
-	 *
96
-	 * @return string Shortcode HTML for web
97
-	 * @since 3.20.0
98
-	 *
99
-	 */
100
-	private function web_shortcode( $atts ) {
101
-
102
-		// attributes extraction and boolean filtering
103
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
104
-
105
-		// avoid building the widget when no post_id is specified and there is a list of posts.
106
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
107
-			return;
108
-		}
109
-
110
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
111
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
112
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
113
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
114
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
115
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
116
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' );
117
-
118
-		$rest_url = $post ? admin_url( 'admin-ajax.php?' . build_query( array(
119
-				'action'  => 'wl_navigator',
120
-				'uniqid'  => $navigator_id,
121
-				'post_id' => $post->ID,
122
-				'limit'   => $limit,
123
-				'offset'  => $offset,
124
-				'sort'    => $sort,
125
-				'post_types' => $shortcode_atts['post_types']
126
-			) ) ) : false;
127
-
128
-		// avoid building the widget when no valid $rest_url
129
-		if ( ! $rest_url ) {
130
-			return;
131
-		}
132
-
133
-		wp_enqueue_script( 'wordlift-cloud' );
134
-		$template_url      = get_rest_url( null, '/wordlift/v1/navigator/template' );
135
-
136
-		return <<<HTML
20
+    /**
21
+     * {@inheritdoc}
22
+     */
23
+    const SHORTCODE = 'wl_navigator';
24
+
25
+    public function __construct() {
26
+        parent::__construct();
27
+        $this->register_block_type();
28
+    }
29
+
30
+    /**
31
+     * {@inheritdoc}
32
+     */
33
+    public function render( $atts ) {
34
+
35
+        return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts )
36
+            : $this->web_shortcode( $atts );
37
+    }
38
+
39
+    private function register_block_type() {
40
+
41
+        $scope = $this;
42
+
43
+        add_action( 'init', function () use ( $scope ) {
44
+            if ( ! function_exists( 'register_block_type' ) ) {
45
+                // Gutenberg is not active.
46
+                return;
47
+            }
48
+
49
+            register_block_type( 'wordlift/navigator', array(
50
+                'editor_script'   => 'wl-block-editor',
51
+                'render_callback' => function ( $attributes ) use ( $scope ) {
52
+                    $attr_code = '';
53
+                    foreach ( $attributes as $key => $value ) {
54
+                        $attr_code .= $key . '="' . htmlentities( $value ) . '" ';
55
+                    }
56
+
57
+                    return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
58
+                },
59
+                'attributes'      => $scope->get_navigator_block_attributes(),
60
+            ) );
61
+        } );
62
+    }
63
+
64
+    /**
65
+     * Shared function used by web_shortcode and amp_shortcode
66
+     * Bootstrap logic for attributes extraction and boolean filtering
67
+     *
68
+     * @param array $atts Shortcode attributes.
69
+     *
70
+     * @return array $shortcode_atts
71
+     * @since      3.20.0
72
+     *
73
+     */
74
+    private function make_shortcode_atts( $atts ) {
75
+
76
+        // Extract attributes and set default values.
77
+        $shortcode_atts = shortcode_atts( array(
78
+            'title'       => __( 'Related articles', 'wordlift' ),
79
+            'limit'       => 4,
80
+            'offset'      => 0,
81
+            'template_id' => '',
82
+            'post_id'     => '',
83
+            'uniqid'      => uniqid( 'wl-navigator-widget-' ),
84
+            'order_by'    => 'ID DESC',
85
+            'post_types'  => '',
86
+        ), $atts );
87
+
88
+        return $shortcode_atts;
89
+    }
90
+
91
+    /**
92
+     * Function in charge of displaying the [wl-navigator] in web mode.
93
+     *
94
+     * @param array $atts Shortcode attributes.
95
+     *
96
+     * @return string Shortcode HTML for web
97
+     * @since 3.20.0
98
+     *
99
+     */
100
+    private function web_shortcode( $atts ) {
101
+
102
+        // attributes extraction and boolean filtering
103
+        $shortcode_atts = $this->make_shortcode_atts( $atts );
104
+
105
+        // avoid building the widget when no post_id is specified and there is a list of posts.
106
+        if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
107
+            return;
108
+        }
109
+
110
+        $post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
111
+        $title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
112
+        $template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
113
+        $limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
114
+        $offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
115
+        $sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
116
+        $navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' );
117
+
118
+        $rest_url = $post ? admin_url( 'admin-ajax.php?' . build_query( array(
119
+                'action'  => 'wl_navigator',
120
+                'uniqid'  => $navigator_id,
121
+                'post_id' => $post->ID,
122
+                'limit'   => $limit,
123
+                'offset'  => $offset,
124
+                'sort'    => $sort,
125
+                'post_types' => $shortcode_atts['post_types']
126
+            ) ) ) : false;
127
+
128
+        // avoid building the widget when no valid $rest_url
129
+        if ( ! $rest_url ) {
130
+            return;
131
+        }
132
+
133
+        wp_enqueue_script( 'wordlift-cloud' );
134
+        $template_url      = get_rest_url( null, '/wordlift/v1/navigator/template' );
135
+
136
+        return <<<HTML
137 137
 			<!-- Navigator {$navigator_id} -->
138 138
 			<div id="{$navigator_id}" 
139 139
 				 class="wl-navigator" 
@@ -144,60 +144,60 @@  discard block
 block discarded – undo
144 144
 				 data-limit="{$limit}"></div>
145 145
 			<!-- /Navigator {$navigator_id} -->
146 146
 HTML;
147
-	}
148
-
149
-	/**
150
-	 * Function in charge of diplaying the [wl-faceted-search] in amp mode.
151
-	 *
152
-	 * @param array $atts Shortcode attributes.
153
-	 *
154
-	 * @return string Shortcode HTML for amp
155
-	 * @since 3.20.0
156
-	 *
157
-	 */
158
-	private function amp_shortcode( $atts ) {
159
-
160
-		// attributes extraction and boolean filtering
161
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
162
-
163
-		// avoid building the widget when no post_id is specified and there is a list of posts.
164
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
165
-			return;
166
-		}
167
-
168
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
169
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
170
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
171
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
172
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
173
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
174
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' );
175
-
176
-		$permalink_structure = get_option( 'permalink_structure' );
177
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
178
-		$rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/navigator' . $delimiter . build_query( array(
179
-				'uniqid'  => $navigator_id,
180
-				'post_id' => $post->ID,
181
-				'limit'   => $limit,
182
-				'offset'  => $offset,
183
-				'sort'    => $sort
184
-			) ) ) : false;
185
-
186
-		// avoid building the widget when no valid $rest_url
187
-		if ( ! $rest_url ) {
188
-			return;
189
-		}
190
-
191
-		// Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
192
-		// This is a hackish way, but this works for http and https URLs
193
-		$rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
194
-
195
-		if ( empty( $template_id ) ) {
196
-			$template_id = "template-" . $navigator_id;
197
-			wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( dirname( __FILE__ ) ) . '/css/wordlift-amp-custom.min.css' );
198
-		}
199
-
200
-		return <<<HTML
147
+    }
148
+
149
+    /**
150
+     * Function in charge of diplaying the [wl-faceted-search] in amp mode.
151
+     *
152
+     * @param array $atts Shortcode attributes.
153
+     *
154
+     * @return string Shortcode HTML for amp
155
+     * @since 3.20.0
156
+     *
157
+     */
158
+    private function amp_shortcode( $atts ) {
159
+
160
+        // attributes extraction and boolean filtering
161
+        $shortcode_atts = $this->make_shortcode_atts( $atts );
162
+
163
+        // avoid building the widget when no post_id is specified and there is a list of posts.
164
+        if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
165
+            return;
166
+        }
167
+
168
+        $post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
169
+        $title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
170
+        $template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
171
+        $limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
172
+        $offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
173
+        $sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
174
+        $navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' );
175
+
176
+        $permalink_structure = get_option( 'permalink_structure' );
177
+        $delimiter           = empty( $permalink_structure ) ? '&' : '?';
178
+        $rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/navigator' . $delimiter . build_query( array(
179
+                'uniqid'  => $navigator_id,
180
+                'post_id' => $post->ID,
181
+                'limit'   => $limit,
182
+                'offset'  => $offset,
183
+                'sort'    => $sort
184
+            ) ) ) : false;
185
+
186
+        // avoid building the widget when no valid $rest_url
187
+        if ( ! $rest_url ) {
188
+            return;
189
+        }
190
+
191
+        // Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
192
+        // This is a hackish way, but this works for http and https URLs
193
+        $rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
194
+
195
+        if ( empty( $template_id ) ) {
196
+            $template_id = "template-" . $navigator_id;
197
+            wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( dirname( __FILE__ ) ) . '/css/wordlift-amp-custom.min.css' );
198
+        }
199
+
200
+        return <<<HTML
201 201
 		<div id="{$navigator_id}" class="wl-amp-navigator" style="width: 100%">
202 202
 			<h3 class="wl-headline">{$title}</h3>
203 203
 			<amp-list 
@@ -229,54 +229,54 @@  discard block
 block discarded – undo
229 229
 			</div>
230 230
 		</template>
231 231
 HTML;
232
-	}
233
-
234
-	/**
235
-	 * @return array
236
-	 */
237
-	public function get_navigator_block_attributes() {
238
-		return array(
239
-			'title'       => array(
240
-				'type'    => 'string',
241
-				'default' => __( 'Related articles', 'wordlift' ),
242
-			),
243
-			'limit'       => array(
244
-				'type'    => 'number',
245
-				'default' => 4,
246
-			),
247
-			'template_id' => array(
248
-				'type'    => 'string',
249
-				'default' => '',
250
-			),
251
-			'post_id'     => array(
252
-				'type'    => 'number',
253
-				'default' => '',
254
-			),
255
-			'offset'      => array(
256
-				'type'    => 'number',
257
-				'default' => 0,
258
-			),
259
-			'uniqid'      => array(
260
-				'type'    => 'string',
261
-				'default' => '',
262
-			),
263
-			'order_by'    => array(
264
-				'type'    => 'string',
265
-				'default' => 'ID DESC',
266
-			),
267
-			'preview'     => array(
268
-				'type'    => 'boolean',
269
-				'default' => false,
270
-			),
271
-			'preview_src' => array(
272
-				'type'    => 'string',
273
-				'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/navigator.png',
274
-			),
275
-			'post_types'  => array(
276
-				'type'    => 'string',
277
-				'default' => '',
278
-			)
279
-		);
280
-	}
232
+    }
233
+
234
+    /**
235
+     * @return array
236
+     */
237
+    public function get_navigator_block_attributes() {
238
+        return array(
239
+            'title'       => array(
240
+                'type'    => 'string',
241
+                'default' => __( 'Related articles', 'wordlift' ),
242
+            ),
243
+            'limit'       => array(
244
+                'type'    => 'number',
245
+                'default' => 4,
246
+            ),
247
+            'template_id' => array(
248
+                'type'    => 'string',
249
+                'default' => '',
250
+            ),
251
+            'post_id'     => array(
252
+                'type'    => 'number',
253
+                'default' => '',
254
+            ),
255
+            'offset'      => array(
256
+                'type'    => 'number',
257
+                'default' => 0,
258
+            ),
259
+            'uniqid'      => array(
260
+                'type'    => 'string',
261
+                'default' => '',
262
+            ),
263
+            'order_by'    => array(
264
+                'type'    => 'string',
265
+                'default' => 'ID DESC',
266
+            ),
267
+            'preview'     => array(
268
+                'type'    => 'boolean',
269
+                'default' => false,
270
+            ),
271
+            'preview_src' => array(
272
+                'type'    => 'string',
273
+                'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/navigator.png',
274
+            ),
275
+            'post_types'  => array(
276
+                'type'    => 'string',
277
+                'default' => '',
278
+            )
279
+        );
280
+    }
281 281
 
282 282
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -30,34 +30,34 @@  discard block
 block discarded – undo
30 30
 	/**
31 31
 	 * {@inheritdoc}
32 32
 	 */
33
-	public function render( $atts ) {
33
+	public function render($atts) {
34 34
 
35
-		return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts )
36
-			: $this->web_shortcode( $atts );
35
+		return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode($atts)
36
+			: $this->web_shortcode($atts);
37 37
 	}
38 38
 
39 39
 	private function register_block_type() {
40 40
 
41 41
 		$scope = $this;
42 42
 
43
-		add_action( 'init', function () use ( $scope ) {
44
-			if ( ! function_exists( 'register_block_type' ) ) {
43
+		add_action('init', function() use ($scope) {
44
+			if ( ! function_exists('register_block_type')) {
45 45
 				// Gutenberg is not active.
46 46
 				return;
47 47
 			}
48 48
 
49
-			register_block_type( 'wordlift/navigator', array(
49
+			register_block_type('wordlift/navigator', array(
50 50
 				'editor_script'   => 'wl-block-editor',
51
-				'render_callback' => function ( $attributes ) use ( $scope ) {
51
+				'render_callback' => function($attributes) use ($scope) {
52 52
 					$attr_code = '';
53
-					foreach ( $attributes as $key => $value ) {
54
-						$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
53
+					foreach ($attributes as $key => $value) {
54
+						$attr_code .= $key.'="'.htmlentities($value).'" ';
55 55
 					}
56 56
 
57
-					return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
57
+					return '['.$scope::SHORTCODE.' '.$attr_code.']';
58 58
 				},
59 59
 				'attributes'      => $scope->get_navigator_block_attributes(),
60
-			) );
60
+			));
61 61
 		} );
62 62
 	}
63 63
 
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
 	 * @since      3.20.0
72 72
 	 *
73 73
 	 */
74
-	private function make_shortcode_atts( $atts ) {
74
+	private function make_shortcode_atts($atts) {
75 75
 
76 76
 		// Extract attributes and set default values.
77
-		$shortcode_atts = shortcode_atts( array(
78
-			'title'       => __( 'Related articles', 'wordlift' ),
77
+		$shortcode_atts = shortcode_atts(array(
78
+			'title'       => __('Related articles', 'wordlift'),
79 79
 			'limit'       => 4,
80 80
 			'offset'      => 0,
81 81
 			'template_id' => '',
82 82
 			'post_id'     => '',
83
-			'uniqid'      => uniqid( 'wl-navigator-widget-' ),
83
+			'uniqid'      => uniqid('wl-navigator-widget-'),
84 84
 			'order_by'    => 'ID DESC',
85 85
 			'post_types'  => '',
86
-		), $atts );
86
+		), $atts);
87 87
 
88 88
 		return $shortcode_atts;
89 89
 	}
@@ -97,25 +97,25 @@  discard block
 block discarded – undo
97 97
 	 * @since 3.20.0
98 98
 	 *
99 99
 	 */
100
-	private function web_shortcode( $atts ) {
100
+	private function web_shortcode($atts) {
101 101
 
102 102
 		// attributes extraction and boolean filtering
103
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
103
+		$shortcode_atts = $this->make_shortcode_atts($atts);
104 104
 
105 105
 		// avoid building the widget when no post_id is specified and there is a list of posts.
106
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
106
+		if (empty($shortcode_atts['post_id']) && ! is_singular()) {
107 107
 			return;
108 108
 		}
109 109
 
110
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
111
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
112
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
113
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
114
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
115
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
116
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' );
110
+		$post         = ! empty($shortcode_atts['post_id']) ? get_post(intval($shortcode_atts['post_id'])) : get_post();
111
+		$title        = esc_attr(sanitize_text_field($shortcode_atts['title']));
112
+		$template_id  = esc_attr(sanitize_text_field($shortcode_atts['template_id']));
113
+		$limit        = esc_attr(sanitize_text_field($shortcode_atts['limit']));
114
+		$offset       = esc_attr(sanitize_text_field($shortcode_atts['offset']));
115
+		$sort         = esc_attr(sanitize_sql_orderby(sanitize_text_field($shortcode_atts['order_by'])));
116
+		$navigator_id = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-navigator-widget-');
117 117
 
118
-		$rest_url = $post ? admin_url( 'admin-ajax.php?' . build_query( array(
118
+		$rest_url = $post ? admin_url('admin-ajax.php?'.build_query(array(
119 119
 				'action'  => 'wl_navigator',
120 120
 				'uniqid'  => $navigator_id,
121 121
 				'post_id' => $post->ID,
@@ -123,15 +123,15 @@  discard block
 block discarded – undo
123 123
 				'offset'  => $offset,
124 124
 				'sort'    => $sort,
125 125
 				'post_types' => $shortcode_atts['post_types']
126
-			) ) ) : false;
126
+			))) : false;
127 127
 
128 128
 		// avoid building the widget when no valid $rest_url
129
-		if ( ! $rest_url ) {
129
+		if ( ! $rest_url) {
130 130
 			return;
131 131
 		}
132 132
 
133
-		wp_enqueue_script( 'wordlift-cloud' );
134
-		$template_url      = get_rest_url( null, '/wordlift/v1/navigator/template' );
133
+		wp_enqueue_script('wordlift-cloud');
134
+		$template_url = get_rest_url(null, '/wordlift/v1/navigator/template');
135 135
 
136 136
 		return <<<HTML
137 137
 			<!-- Navigator {$navigator_id} -->
@@ -155,46 +155,46 @@  discard block
 block discarded – undo
155 155
 	 * @since 3.20.0
156 156
 	 *
157 157
 	 */
158
-	private function amp_shortcode( $atts ) {
158
+	private function amp_shortcode($atts) {
159 159
 
160 160
 		// attributes extraction and boolean filtering
161
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
161
+		$shortcode_atts = $this->make_shortcode_atts($atts);
162 162
 
163 163
 		// avoid building the widget when no post_id is specified and there is a list of posts.
164
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
164
+		if (empty($shortcode_atts['post_id']) && ! is_singular()) {
165 165
 			return;
166 166
 		}
167 167
 
168
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
169
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
170
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
171
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
172
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
173
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
174
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' );
175
-
176
-		$permalink_structure = get_option( 'permalink_structure' );
177
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
178
-		$rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/navigator' . $delimiter . build_query( array(
168
+		$post         = ! empty($shortcode_atts['post_id']) ? get_post(intval($shortcode_atts['post_id'])) : get_post();
169
+		$title        = esc_attr(sanitize_text_field($shortcode_atts['title']));
170
+		$template_id  = esc_attr(sanitize_text_field($shortcode_atts['template_id']));
171
+		$limit        = esc_attr(sanitize_text_field($shortcode_atts['limit']));
172
+		$offset       = esc_attr(sanitize_text_field($shortcode_atts['offset']));
173
+		$sort         = esc_attr(sanitize_sql_orderby(sanitize_text_field($shortcode_atts['order_by'])));
174
+		$navigator_id = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-navigator-widget-');
175
+
176
+		$permalink_structure = get_option('permalink_structure');
177
+		$delimiter           = empty($permalink_structure) ? '&' : '?';
178
+		$rest_url            = $post ? rest_url(WL_REST_ROUTE_DEFAULT_NAMESPACE.'/navigator'.$delimiter.build_query(array(
179 179
 				'uniqid'  => $navigator_id,
180 180
 				'post_id' => $post->ID,
181 181
 				'limit'   => $limit,
182 182
 				'offset'  => $offset,
183 183
 				'sort'    => $sort
184
-			) ) ) : false;
184
+			))) : false;
185 185
 
186 186
 		// avoid building the widget when no valid $rest_url
187
-		if ( ! $rest_url ) {
187
+		if ( ! $rest_url) {
188 188
 			return;
189 189
 		}
190 190
 
191 191
 		// Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
192 192
 		// This is a hackish way, but this works for http and https URLs
193
-		$rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
193
+		$rest_url = str_replace(array('http:', 'https:'), '', $rest_url);
194 194
 
195
-		if ( empty( $template_id ) ) {
196
-			$template_id = "template-" . $navigator_id;
197
-			wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( dirname( __FILE__ ) ) . '/css/wordlift-amp-custom.min.css' );
195
+		if (empty($template_id)) {
196
+			$template_id = "template-".$navigator_id;
197
+			wp_enqueue_style('wordlift-amp-custom', plugin_dir_url(dirname(__FILE__)).'/css/wordlift-amp-custom.min.css');
198 198
 		}
199 199
 
200 200
 		return <<<HTML
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 		return array(
239 239
 			'title'       => array(
240 240
 				'type'    => 'string',
241
-				'default' => __( 'Related articles', 'wordlift' ),
241
+				'default' => __('Related articles', 'wordlift'),
242 242
 			),
243 243
 			'limit'       => array(
244 244
 				'type'    => 'number',
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 			),
271 271
 			'preview_src' => array(
272 272
 				'type'    => 'string',
273
-				'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/navigator.png',
273
+				'default' => WP_CONTENT_URL.'/plugins/wordlift/images/block-previews/navigator.png',
274 274
 			),
275 275
 			'post_types'  => array(
276 276
 				'type'    => 'string',
Please login to merge, or discard this patch.
src/public/class-wordlift-faceted-search-shortcode.php 2 patches
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -17,116 +17,116 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Wordlift_Faceted_Search_Shortcode extends Wordlift_Shortcode {
19 19
 
20
-	/**
21
-	 * {@inheritdoc}
22
-	 */
23
-	const SHORTCODE = 'wl_faceted_search';
24
-
25
-	public function __construct() {
26
-		parent::__construct();
27
-		$this->register_block_type();
28
-	}
29
-
30
-	/**
31
-	 * {@inheritdoc}
32
-	 */
33
-	public function render( $atts ) {
34
-
35
-		return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts )
36
-			: $this->web_shortcode( $atts );
37
-	}
38
-
39
-	private function register_block_type() {
40
-
41
-		$scope = $this;
42
-
43
-		add_action( 'init', function () use ( $scope ) {
44
-			if ( ! function_exists( 'register_block_type' ) ) {
45
-				// Gutenberg is not active.
46
-				return;
47
-			}
48
-
49
-			register_block_type( 'wordlift/faceted-search', array(
50
-				'editor_script'   => 'wl-block-editor',
51
-				'render_callback' => function ( $attributes ) use ( $scope ) {
52
-					$attr_code = '';
53
-					foreach ( $attributes as $key => $value ) {
54
-						$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
55
-					}
56
-
57
-					return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
58
-				},
59
-
60
-				'attributes'      => $scope->get_block_attributes(),
61
-			) );
62
-		} );
63
-	}
64
-
65
-	/**
66
-	 * Shared function used by web_shortcode and amp_shortcode
67
-	 * Bootstrap logic for attributes extraction and boolean filtering
68
-	 *
69
-	 * @param array $atts Shortcode attributes.
70
-	 *
71
-	 * @return array $shortcode_atts
72
-	 * @since      3.20.0
73
-	 *
74
-	 */
75
-	private function make_shortcode_atts( $atts ) {
76
-
77
-		// Extract attributes and set default values.
78
-		$shortcode_atts = shortcode_atts( array(
79
-			'title'       => __( 'Related articles', 'wordlift' ),
80
-			'limit'       => apply_filters( 'wl_faceted_search_default_limit', 10 ),
81
-			'post_id'     => '',
82
-			'template_id' => '',
83
-			'uniqid'      => uniqid( 'wl-faceted-widget-' ),
84
-			'post_types'  => '',
85
-		), $atts );
86
-
87
-		return $shortcode_atts;
88
-	}
89
-
90
-	/**
91
-	 * Function in charge of diplaying the [wl-faceted-search] in web mode.
92
-	 *
93
-	 * @param array $atts Shortcode attributes.
94
-	 *
95
-	 * @return string Shortcode HTML for web
96
-	 * @since 3.20.0
97
-	 *
98
-	 */
99
-	private function web_shortcode( $atts ) {
100
-
101
-		// attributes extraction and boolean filtering
102
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
103
-
104
-		// avoid building the widget when no post_id is specified and there is a list of posts.
105
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
106
-			return;
107
-		}
108
-
109
-		$post        = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
110
-		$title       = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
111
-		$template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
112
-		$limit       = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
113
-		$faceted_id  = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' );
114
-
115
-		$permalink_structure = get_option( 'permalink_structure' );
116
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
117
-		$rest_url            = $this->get_rest_url( $post, $delimiter, $limit, $shortcode_atts['post_types'] );
118
-		$rest_url            = esc_attr( $rest_url );
119
-
120
-
121
-		// avoid building the widget when no valid $rest_url
122
-		if ( ! $rest_url ) {
123
-			return;
124
-		}
125
-
126
-		wp_enqueue_script( 'wordlift-cloud' );
127
-		$template_url    = get_rest_url( null, '/wordlift/v1/faceted-search/template' );
128
-
129
-		return <<<HTML
20
+    /**
21
+     * {@inheritdoc}
22
+     */
23
+    const SHORTCODE = 'wl_faceted_search';
24
+
25
+    public function __construct() {
26
+        parent::__construct();
27
+        $this->register_block_type();
28
+    }
29
+
30
+    /**
31
+     * {@inheritdoc}
32
+     */
33
+    public function render( $atts ) {
34
+
35
+        return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts )
36
+            : $this->web_shortcode( $atts );
37
+    }
38
+
39
+    private function register_block_type() {
40
+
41
+        $scope = $this;
42
+
43
+        add_action( 'init', function () use ( $scope ) {
44
+            if ( ! function_exists( 'register_block_type' ) ) {
45
+                // Gutenberg is not active.
46
+                return;
47
+            }
48
+
49
+            register_block_type( 'wordlift/faceted-search', array(
50
+                'editor_script'   => 'wl-block-editor',
51
+                'render_callback' => function ( $attributes ) use ( $scope ) {
52
+                    $attr_code = '';
53
+                    foreach ( $attributes as $key => $value ) {
54
+                        $attr_code .= $key . '="' . htmlentities( $value ) . '" ';
55
+                    }
56
+
57
+                    return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
58
+                },
59
+
60
+                'attributes'      => $scope->get_block_attributes(),
61
+            ) );
62
+        } );
63
+    }
64
+
65
+    /**
66
+     * Shared function used by web_shortcode and amp_shortcode
67
+     * Bootstrap logic for attributes extraction and boolean filtering
68
+     *
69
+     * @param array $atts Shortcode attributes.
70
+     *
71
+     * @return array $shortcode_atts
72
+     * @since      3.20.0
73
+     *
74
+     */
75
+    private function make_shortcode_atts( $atts ) {
76
+
77
+        // Extract attributes and set default values.
78
+        $shortcode_atts = shortcode_atts( array(
79
+            'title'       => __( 'Related articles', 'wordlift' ),
80
+            'limit'       => apply_filters( 'wl_faceted_search_default_limit', 10 ),
81
+            'post_id'     => '',
82
+            'template_id' => '',
83
+            'uniqid'      => uniqid( 'wl-faceted-widget-' ),
84
+            'post_types'  => '',
85
+        ), $atts );
86
+
87
+        return $shortcode_atts;
88
+    }
89
+
90
+    /**
91
+     * Function in charge of diplaying the [wl-faceted-search] in web mode.
92
+     *
93
+     * @param array $atts Shortcode attributes.
94
+     *
95
+     * @return string Shortcode HTML for web
96
+     * @since 3.20.0
97
+     *
98
+     */
99
+    private function web_shortcode( $atts ) {
100
+
101
+        // attributes extraction and boolean filtering
102
+        $shortcode_atts = $this->make_shortcode_atts( $atts );
103
+
104
+        // avoid building the widget when no post_id is specified and there is a list of posts.
105
+        if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
106
+            return;
107
+        }
108
+
109
+        $post        = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
110
+        $title       = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
111
+        $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
112
+        $limit       = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
113
+        $faceted_id  = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' );
114
+
115
+        $permalink_structure = get_option( 'permalink_structure' );
116
+        $delimiter           = empty( $permalink_structure ) ? '&' : '?';
117
+        $rest_url            = $this->get_rest_url( $post, $delimiter, $limit, $shortcode_atts['post_types'] );
118
+        $rest_url            = esc_attr( $rest_url );
119
+
120
+
121
+        // avoid building the widget when no valid $rest_url
122
+        if ( ! $rest_url ) {
123
+            return;
124
+        }
125
+
126
+        wp_enqueue_script( 'wordlift-cloud' );
127
+        $template_url    = get_rest_url( null, '/wordlift/v1/faceted-search/template' );
128
+
129
+        return <<<HTML
130 130
 			<!-- Faceted {$faceted_id} -->
131 131
 			<div id="{$faceted_id}" 
132 132
 				 class="wl-faceted" 
@@ -136,58 +136,58 @@  discard block
 block discarded – undo
136 136
 				 data-template-url="{$template_url}"></div>
137 137
 			<!-- /Faceted {$faceted_id} -->
138 138
 HTML;
139
-	}
140
-
141
-	/**
142
-	 * Function in charge of diplaying the [wl-faceted-search] in amp mode.
143
-	 *
144
-	 * @param array $atts Shortcode attributes.
145
-	 *
146
-	 * @return string Shortcode HTML for amp
147
-	 * @since 3.20.0
148
-	 *
149
-	 */
150
-	private function amp_shortcode( $atts ) {
151
-
152
-		// attributes extraction and boolean filtering
153
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
154
-
155
-		// avoid building the widget when no post_id is specified and there is a list of posts.
156
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
157
-			return;
158
-		}
159
-
160
-		$post        = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
161
-		$title       = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
162
-		$template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
163
-		$limit       = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
164
-		$faceted_id  = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' );
165
-
166
-		$permalink_structure = get_option( 'permalink_structure' );
167
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
168
-		$rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( array(
169
-				'amp',
170
-				'post_id' => $post->ID,
171
-				'limit'   => $limit
172
-			) ) ) : false;
173
-
174
-		$rest_url = $post ? rest_url( sprintf( "wordlift/v1/faceted-search?amp&post_id=%s&limit=%s", $post->ID, $limit ) ) : false;
175
-
176
-		// avoid building the widget when no valid $rest_url
177
-		if ( ! $rest_url ) {
178
-			return;
179
-		}
180
-
181
-		// Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
182
-		// This is a hackish way, but this works for http and https URLs
183
-		$rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
184
-
185
-		if ( empty( $template_id ) ) {
186
-			$template_id = "template-" . $faceted_id;
187
-			wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( dirname( __FILE__ ) ) . '/css/wordlift-amp-custom.min.css' );
188
-		}
189
-
190
-		return <<<HTML
139
+    }
140
+
141
+    /**
142
+     * Function in charge of diplaying the [wl-faceted-search] in amp mode.
143
+     *
144
+     * @param array $atts Shortcode attributes.
145
+     *
146
+     * @return string Shortcode HTML for amp
147
+     * @since 3.20.0
148
+     *
149
+     */
150
+    private function amp_shortcode( $atts ) {
151
+
152
+        // attributes extraction and boolean filtering
153
+        $shortcode_atts = $this->make_shortcode_atts( $atts );
154
+
155
+        // avoid building the widget when no post_id is specified and there is a list of posts.
156
+        if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
157
+            return;
158
+        }
159
+
160
+        $post        = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
161
+        $title       = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
162
+        $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
163
+        $limit       = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
164
+        $faceted_id  = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' );
165
+
166
+        $permalink_structure = get_option( 'permalink_structure' );
167
+        $delimiter           = empty( $permalink_structure ) ? '&' : '?';
168
+        $rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( array(
169
+                'amp',
170
+                'post_id' => $post->ID,
171
+                'limit'   => $limit
172
+            ) ) ) : false;
173
+
174
+        $rest_url = $post ? rest_url( sprintf( "wordlift/v1/faceted-search?amp&post_id=%s&limit=%s", $post->ID, $limit ) ) : false;
175
+
176
+        // avoid building the widget when no valid $rest_url
177
+        if ( ! $rest_url ) {
178
+            return;
179
+        }
180
+
181
+        // Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
182
+        // This is a hackish way, but this works for http and https URLs
183
+        $rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
184
+
185
+        if ( empty( $template_id ) ) {
186
+            $template_id = "template-" . $faceted_id;
187
+            wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( dirname( __FILE__ ) ) . '/css/wordlift-amp-custom.min.css' );
188
+        }
189
+
190
+        return <<<HTML
191 191
 		<div id="{$faceted_id}" class="wl-amp-faceted">
192 192
 			<h2 class="wl-headline">{$title}</h2>
193 193
 			<amp-state id="referencedPosts">
@@ -270,62 +270,62 @@  discard block
 block discarded – undo
270 270
 			</section>
271 271
 		</div>
272 272
 HTML;
273
-	}
274
-
275
-	public function get_block_attributes() {
276
-		return array(
277
-			'title'       => array(
278
-				'type'    => 'string',
279
-				'default' => __( 'Related articles', 'wordlift' ),
280
-			),
281
-			'template_id' => array(
282
-				'type'    => 'string',
283
-				'default' => '',
284
-			),
285
-			'post_id'     => array(
286
-				'type'    => 'number',
287
-				'default' => '',
288
-			),
289
-			'uniqid'      => array(
290
-				'type'    => 'string',
291
-				'default' => '',
292
-			),
293
-			'limit'       => array(
294
-				'type'    => 'number',
295
-				'default' => apply_filters( 'wl_faceted_search_default_limit', 10 ),
296
-			),
297
-			'preview'     => array(
298
-				'type'    => 'boolean',
299
-				'default' => false,
300
-			),
301
-			'preview_src' => array(
302
-				'type'    => 'string',
303
-				'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/faceted-search.png',
304
-			),
305
-			'post_types'  => array(
306
-				'type'    => 'string',
307
-				'default' => '',
308
-			)
309
-		);
310
-	}
311
-
312
-	/**
313
-	 * @param $post
314
-	 * @param $delimiter
315
-	 * @param $limit
316
-	 *
317
-	 * @param $post_types
318
-	 *
319
-	 * @return bool|string
320
-	 */
321
-	public function get_rest_url( $post, $delimiter, $limit, $post_types ) {
322
-		$rest_url = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( array(
323
-				'post_id'    => $post->ID,
324
-				'limit'      => $limit,
325
-				'post_types' => $post_types
326
-			) ) ) : false;
327
-
328
-		return $rest_url;
329
-	}
273
+    }
274
+
275
+    public function get_block_attributes() {
276
+        return array(
277
+            'title'       => array(
278
+                'type'    => 'string',
279
+                'default' => __( 'Related articles', 'wordlift' ),
280
+            ),
281
+            'template_id' => array(
282
+                'type'    => 'string',
283
+                'default' => '',
284
+            ),
285
+            'post_id'     => array(
286
+                'type'    => 'number',
287
+                'default' => '',
288
+            ),
289
+            'uniqid'      => array(
290
+                'type'    => 'string',
291
+                'default' => '',
292
+            ),
293
+            'limit'       => array(
294
+                'type'    => 'number',
295
+                'default' => apply_filters( 'wl_faceted_search_default_limit', 10 ),
296
+            ),
297
+            'preview'     => array(
298
+                'type'    => 'boolean',
299
+                'default' => false,
300
+            ),
301
+            'preview_src' => array(
302
+                'type'    => 'string',
303
+                'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/faceted-search.png',
304
+            ),
305
+            'post_types'  => array(
306
+                'type'    => 'string',
307
+                'default' => '',
308
+            )
309
+        );
310
+    }
311
+
312
+    /**
313
+     * @param $post
314
+     * @param $delimiter
315
+     * @param $limit
316
+     *
317
+     * @param $post_types
318
+     *
319
+     * @return bool|string
320
+     */
321
+    public function get_rest_url( $post, $delimiter, $limit, $post_types ) {
322
+        $rest_url = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( array(
323
+                'post_id'    => $post->ID,
324
+                'limit'      => $limit,
325
+                'post_types' => $post_types
326
+            ) ) ) : false;
327
+
328
+        return $rest_url;
329
+    }
330 330
 
331 331
 }
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -30,35 +30,35 @@  discard block
 block discarded – undo
30 30
 	/**
31 31
 	 * {@inheritdoc}
32 32
 	 */
33
-	public function render( $atts ) {
33
+	public function render($atts) {
34 34
 
35
-		return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts )
36
-			: $this->web_shortcode( $atts );
35
+		return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode($atts)
36
+			: $this->web_shortcode($atts);
37 37
 	}
38 38
 
39 39
 	private function register_block_type() {
40 40
 
41 41
 		$scope = $this;
42 42
 
43
-		add_action( 'init', function () use ( $scope ) {
44
-			if ( ! function_exists( 'register_block_type' ) ) {
43
+		add_action('init', function() use ($scope) {
44
+			if ( ! function_exists('register_block_type')) {
45 45
 				// Gutenberg is not active.
46 46
 				return;
47 47
 			}
48 48
 
49
-			register_block_type( 'wordlift/faceted-search', array(
49
+			register_block_type('wordlift/faceted-search', array(
50 50
 				'editor_script'   => 'wl-block-editor',
51
-				'render_callback' => function ( $attributes ) use ( $scope ) {
51
+				'render_callback' => function($attributes) use ($scope) {
52 52
 					$attr_code = '';
53
-					foreach ( $attributes as $key => $value ) {
54
-						$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
53
+					foreach ($attributes as $key => $value) {
54
+						$attr_code .= $key.'="'.htmlentities($value).'" ';
55 55
 					}
56 56
 
57
-					return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
57
+					return '['.$scope::SHORTCODE.' '.$attr_code.']';
58 58
 				},
59 59
 
60 60
 				'attributes'      => $scope->get_block_attributes(),
61
-			) );
61
+			));
62 62
 		} );
63 63
 	}
64 64
 
@@ -72,17 +72,17 @@  discard block
 block discarded – undo
72 72
 	 * @since      3.20.0
73 73
 	 *
74 74
 	 */
75
-	private function make_shortcode_atts( $atts ) {
75
+	private function make_shortcode_atts($atts) {
76 76
 
77 77
 		// Extract attributes and set default values.
78
-		$shortcode_atts = shortcode_atts( array(
79
-			'title'       => __( 'Related articles', 'wordlift' ),
80
-			'limit'       => apply_filters( 'wl_faceted_search_default_limit', 10 ),
78
+		$shortcode_atts = shortcode_atts(array(
79
+			'title'       => __('Related articles', 'wordlift'),
80
+			'limit'       => apply_filters('wl_faceted_search_default_limit', 10),
81 81
 			'post_id'     => '',
82 82
 			'template_id' => '',
83
-			'uniqid'      => uniqid( 'wl-faceted-widget-' ),
83
+			'uniqid'      => uniqid('wl-faceted-widget-'),
84 84
 			'post_types'  => '',
85
-		), $atts );
85
+		), $atts);
86 86
 
87 87
 		return $shortcode_atts;
88 88
 	}
@@ -96,35 +96,35 @@  discard block
 block discarded – undo
96 96
 	 * @since 3.20.0
97 97
 	 *
98 98
 	 */
99
-	private function web_shortcode( $atts ) {
99
+	private function web_shortcode($atts) {
100 100
 
101 101
 		// attributes extraction and boolean filtering
102
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
102
+		$shortcode_atts = $this->make_shortcode_atts($atts);
103 103
 
104 104
 		// avoid building the widget when no post_id is specified and there is a list of posts.
105
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
105
+		if (empty($shortcode_atts['post_id']) && ! is_singular()) {
106 106
 			return;
107 107
 		}
108 108
 
109
-		$post        = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
110
-		$title       = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
111
-		$template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
112
-		$limit       = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
113
-		$faceted_id  = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' );
109
+		$post        = ! empty($shortcode_atts['post_id']) ? get_post(intval(sanitize_text_field($shortcode_atts['post_id']))) : get_post();
110
+		$title       = esc_attr(sanitize_text_field($shortcode_atts['title']));
111
+		$template_id = esc_attr(sanitize_text_field($shortcode_atts['template_id']));
112
+		$limit       = esc_attr(sanitize_text_field($shortcode_atts['limit']));
113
+		$faceted_id  = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-faceted-widget-');
114 114
 
115
-		$permalink_structure = get_option( 'permalink_structure' );
116
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
117
-		$rest_url            = $this->get_rest_url( $post, $delimiter, $limit, $shortcode_atts['post_types'] );
118
-		$rest_url            = esc_attr( $rest_url );
115
+		$permalink_structure = get_option('permalink_structure');
116
+		$delimiter           = empty($permalink_structure) ? '&' : '?';
117
+		$rest_url            = $this->get_rest_url($post, $delimiter, $limit, $shortcode_atts['post_types']);
118
+		$rest_url            = esc_attr($rest_url);
119 119
 
120 120
 
121 121
 		// avoid building the widget when no valid $rest_url
122
-		if ( ! $rest_url ) {
122
+		if ( ! $rest_url) {
123 123
 			return;
124 124
 		}
125 125
 
126
-		wp_enqueue_script( 'wordlift-cloud' );
127
-		$template_url    = get_rest_url( null, '/wordlift/v1/faceted-search/template' );
126
+		wp_enqueue_script('wordlift-cloud');
127
+		$template_url = get_rest_url(null, '/wordlift/v1/faceted-search/template');
128 128
 
129 129
 		return <<<HTML
130 130
 			<!-- Faceted {$faceted_id} -->
@@ -147,44 +147,44 @@  discard block
 block discarded – undo
147 147
 	 * @since 3.20.0
148 148
 	 *
149 149
 	 */
150
-	private function amp_shortcode( $atts ) {
150
+	private function amp_shortcode($atts) {
151 151
 
152 152
 		// attributes extraction and boolean filtering
153
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
153
+		$shortcode_atts = $this->make_shortcode_atts($atts);
154 154
 
155 155
 		// avoid building the widget when no post_id is specified and there is a list of posts.
156
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
156
+		if (empty($shortcode_atts['post_id']) && ! is_singular()) {
157 157
 			return;
158 158
 		}
159 159
 
160
-		$post        = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
161
-		$title       = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
162
-		$template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
163
-		$limit       = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
164
-		$faceted_id  = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' );
160
+		$post        = ! empty($shortcode_atts['post_id']) ? get_post(intval(sanitize_text_field($shortcode_atts['post_id']))) : get_post();
161
+		$title       = esc_attr(sanitize_text_field($shortcode_atts['title']));
162
+		$template_id = esc_attr(sanitize_text_field($shortcode_atts['template_id']));
163
+		$limit       = esc_attr(sanitize_text_field($shortcode_atts['limit']));
164
+		$faceted_id  = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-faceted-widget-');
165 165
 
166
-		$permalink_structure = get_option( 'permalink_structure' );
167
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
168
-		$rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( array(
166
+		$permalink_structure = get_option('permalink_structure');
167
+		$delimiter           = empty($permalink_structure) ? '&' : '?';
168
+		$rest_url            = $post ? rest_url(WL_REST_ROUTE_DEFAULT_NAMESPACE.'/faceted-search'.$delimiter.build_query(array(
169 169
 				'amp',
170 170
 				'post_id' => $post->ID,
171 171
 				'limit'   => $limit
172
-			) ) ) : false;
172
+			))) : false;
173 173
 
174
-		$rest_url = $post ? rest_url( sprintf( "wordlift/v1/faceted-search?amp&post_id=%s&limit=%s", $post->ID, $limit ) ) : false;
174
+		$rest_url = $post ? rest_url(sprintf("wordlift/v1/faceted-search?amp&post_id=%s&limit=%s", $post->ID, $limit)) : false;
175 175
 
176 176
 		// avoid building the widget when no valid $rest_url
177
-		if ( ! $rest_url ) {
177
+		if ( ! $rest_url) {
178 178
 			return;
179 179
 		}
180 180
 
181 181
 		// Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
182 182
 		// This is a hackish way, but this works for http and https URLs
183
-		$rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
183
+		$rest_url = str_replace(array('http:', 'https:'), '', $rest_url);
184 184
 
185
-		if ( empty( $template_id ) ) {
186
-			$template_id = "template-" . $faceted_id;
187
-			wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( dirname( __FILE__ ) ) . '/css/wordlift-amp-custom.min.css' );
185
+		if (empty($template_id)) {
186
+			$template_id = "template-".$faceted_id;
187
+			wp_enqueue_style('wordlift-amp-custom', plugin_dir_url(dirname(__FILE__)).'/css/wordlift-amp-custom.min.css');
188 188
 		}
189 189
 
190 190
 		return <<<HTML
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 		return array(
277 277
 			'title'       => array(
278 278
 				'type'    => 'string',
279
-				'default' => __( 'Related articles', 'wordlift' ),
279
+				'default' => __('Related articles', 'wordlift'),
280 280
 			),
281 281
 			'template_id' => array(
282 282
 				'type'    => 'string',
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 			),
293 293
 			'limit'       => array(
294 294
 				'type'    => 'number',
295
-				'default' => apply_filters( 'wl_faceted_search_default_limit', 10 ),
295
+				'default' => apply_filters('wl_faceted_search_default_limit', 10),
296 296
 			),
297 297
 			'preview'     => array(
298 298
 				'type'    => 'boolean',
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 			),
301 301
 			'preview_src' => array(
302 302
 				'type'    => 'string',
303
-				'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/faceted-search.png',
303
+				'default' => WP_CONTENT_URL.'/plugins/wordlift/images/block-previews/faceted-search.png',
304 304
 			),
305 305
 			'post_types'  => array(
306 306
 				'type'    => 'string',
@@ -318,12 +318,12 @@  discard block
 block discarded – undo
318 318
 	 *
319 319
 	 * @return bool|string
320 320
 	 */
321
-	public function get_rest_url( $post, $delimiter, $limit, $post_types ) {
322
-		$rest_url = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( array(
321
+	public function get_rest_url($post, $delimiter, $limit, $post_types) {
322
+		$rest_url = $post ? rest_url(WL_REST_ROUTE_DEFAULT_NAMESPACE.'/faceted-search'.$delimiter.build_query(array(
323 323
 				'post_id'    => $post->ID,
324 324
 				'limit'      => $limit,
325 325
 				'post_types' => $post_types
326
-			) ) ) : false;
326
+			))) : false;
327 327
 
328 328
 		return $rest_url;
329 329
 	}
Please login to merge, or discard this patch.