Completed
Pull Request — develop (#1253)
by Naveen
03:59
created
src/public/class-wordlift-faceted-search-shortcode.php 2 patches
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -17,146 +17,146 @@  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
-				'attributes'      => array(
60
-					'title'       => array(
61
-						'type'    => 'string',
62
-						'default' => __( 'Related articles', 'wordlift' ),
63
-					),
64
-					'template_id' => array(
65
-						'type' => 'string',
66
-						'default' => '',
67
-					),
68
-					'post_id'     => array(
69
-						'type'    => 'number',
70
-						'default' => '',
71
-					),
72
-					'uniqid'      => array(
73
-						'type'    => 'string',
74
-						'default' => '',
75
-					),
76
-					'limit'       => array(
77
-						'type'    => 'number',
78
-						'default' => apply_filters( 'wl_faceted_search_default_limit', 10 ),
79
-					),
80
-					'preview'     => array(
81
-						'type'    => 'boolean',
82
-						'default' => false,
83
-					),
84
-					'preview_src' => array(
85
-						'type'    => 'string',
86
-						'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/faceted-search.png',
87
-					),
88
-				),
89
-			) );
90
-		} );
91
-	}
92
-
93
-	/**
94
-	 * Shared function used by web_shortcode and amp_shortcode
95
-	 * Bootstrap logic for attributes extraction and boolean filtering
96
-	 *
97
-	 * @since      3.20.0
98
-	 *
99
-	 * @param array $atts Shortcode attributes.
100
-	 *
101
-	 * @return array $shortcode_atts
102
-	 */
103
-	private function make_shortcode_atts( $atts ) {
104
-
105
-		// Extract attributes and set default values.
106
-		$shortcode_atts = shortcode_atts( array(
107
-			'title'       => __( 'Related articles', 'wordlift' ),
108
-			'limit'       => apply_filters( 'wl_faceted_search_default_limit', 10 ),
109
-			'post_id'     => '',
110
-			'template_id' => '',
111
-			'uniqid'      => uniqid( 'wl-faceted-widget-' ),
112
-		), $atts );
113
-
114
-		return $shortcode_atts;
115
-	}
116
-
117
-	/**
118
-	 * Function in charge of diplaying the [wl-faceted-search] in web mode.
119
-	 *
120
-	 * @since 3.20.0
121
-	 *
122
-	 * @param array $atts Shortcode attributes.
123
-	 *
124
-	 * @return string Shortcode HTML for web
125
-	 */
126
-	private function web_shortcode( $atts ) {
127
-
128
-		// attributes extraction and boolean filtering
129
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
130
-
131
-		// avoid building the widget when no post_id is specified and there is a list of posts.
132
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
133
-			return;
134
-		}
135
-
136
-		$post        = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
137
-		$title       = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
138
-		$template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
139
-		$limit       = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
140
-		$faceted_id  = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' );
141
-
142
-		$permalink_structure = get_option( 'permalink_structure' );
143
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
144
-		$rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( array(
145
-				'post_id' => $post->ID,
146
-				'limit'   => $limit
147
-			) ) ) : false;
148
-		$rest_url = esc_attr( $rest_url );
149
-
150
-		// avoid building the widget when no valid $rest_url
151
-		if ( ! $rest_url ) {
152
-			return;
153
-		}
154
-
155
-		wp_enqueue_script( 'wordlift-cloud' );
156
-		$json_faceted_id = wp_json_encode( $faceted_id );
157
-		$template_url = get_rest_url( null, '/wordlift/v1/faceted-search/template' );
158
-
159
-		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
+                'attributes'      => array(
60
+                    'title'       => array(
61
+                        'type'    => 'string',
62
+                        'default' => __( 'Related articles', 'wordlift' ),
63
+                    ),
64
+                    'template_id' => array(
65
+                        'type' => 'string',
66
+                        'default' => '',
67
+                    ),
68
+                    'post_id'     => array(
69
+                        'type'    => 'number',
70
+                        'default' => '',
71
+                    ),
72
+                    'uniqid'      => array(
73
+                        'type'    => 'string',
74
+                        'default' => '',
75
+                    ),
76
+                    'limit'       => array(
77
+                        'type'    => 'number',
78
+                        'default' => apply_filters( 'wl_faceted_search_default_limit', 10 ),
79
+                    ),
80
+                    'preview'     => array(
81
+                        'type'    => 'boolean',
82
+                        'default' => false,
83
+                    ),
84
+                    'preview_src' => array(
85
+                        'type'    => 'string',
86
+                        'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/faceted-search.png',
87
+                    ),
88
+                ),
89
+            ) );
90
+        } );
91
+    }
92
+
93
+    /**
94
+     * Shared function used by web_shortcode and amp_shortcode
95
+     * Bootstrap logic for attributes extraction and boolean filtering
96
+     *
97
+     * @since      3.20.0
98
+     *
99
+     * @param array $atts Shortcode attributes.
100
+     *
101
+     * @return array $shortcode_atts
102
+     */
103
+    private function make_shortcode_atts( $atts ) {
104
+
105
+        // Extract attributes and set default values.
106
+        $shortcode_atts = shortcode_atts( array(
107
+            'title'       => __( 'Related articles', 'wordlift' ),
108
+            'limit'       => apply_filters( 'wl_faceted_search_default_limit', 10 ),
109
+            'post_id'     => '',
110
+            'template_id' => '',
111
+            'uniqid'      => uniqid( 'wl-faceted-widget-' ),
112
+        ), $atts );
113
+
114
+        return $shortcode_atts;
115
+    }
116
+
117
+    /**
118
+     * Function in charge of diplaying the [wl-faceted-search] in web mode.
119
+     *
120
+     * @since 3.20.0
121
+     *
122
+     * @param array $atts Shortcode attributes.
123
+     *
124
+     * @return string Shortcode HTML for web
125
+     */
126
+    private function web_shortcode( $atts ) {
127
+
128
+        // attributes extraction and boolean filtering
129
+        $shortcode_atts = $this->make_shortcode_atts( $atts );
130
+
131
+        // avoid building the widget when no post_id is specified and there is a list of posts.
132
+        if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
133
+            return;
134
+        }
135
+
136
+        $post        = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
137
+        $title       = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
138
+        $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
139
+        $limit       = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
140
+        $faceted_id  = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' );
141
+
142
+        $permalink_structure = get_option( 'permalink_structure' );
143
+        $delimiter           = empty( $permalink_structure ) ? '&' : '?';
144
+        $rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( array(
145
+                'post_id' => $post->ID,
146
+                'limit'   => $limit
147
+            ) ) ) : false;
148
+        $rest_url = esc_attr( $rest_url );
149
+
150
+        // avoid building the widget when no valid $rest_url
151
+        if ( ! $rest_url ) {
152
+            return;
153
+        }
154
+
155
+        wp_enqueue_script( 'wordlift-cloud' );
156
+        $json_faceted_id = wp_json_encode( $faceted_id );
157
+        $template_url = get_rest_url( null, '/wordlift/v1/faceted-search/template' );
158
+
159
+        return <<<HTML
160 160
 			<!-- Faceted {$faceted_id} -->
161 161
 			<script type="application/javascript">
162 162
 				window.wlFaceteds = window.wlFaceteds || []; wlFaceteds.push({$json_faceted_id});
@@ -169,58 +169,58 @@  discard block
 block discarded – undo
169 169
 				 data-template-url="{$template_url}"></div>
170 170
 			<!-- /Faceted {$faceted_id} -->
171 171
 HTML;
172
-	}
173
-
174
-	/**
175
-	 * Function in charge of diplaying the [wl-faceted-search] in amp mode.
176
-	 *
177
-	 * @since 3.20.0
178
-	 *
179
-	 * @param array $atts Shortcode attributes.
180
-	 *
181
-	 * @return string Shortcode HTML for amp
182
-	 */
183
-	private function amp_shortcode( $atts ) {
184
-
185
-		// attributes extraction and boolean filtering
186
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
187
-
188
-		// avoid building the widget when no post_id is specified and there is a list of posts.
189
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
190
-			return;
191
-		}
192
-
193
-		$post        = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
194
-		$title       = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
195
-		$template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
196
-		$limit       = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
197
-		$faceted_id  = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' );
198
-
199
-		$permalink_structure = get_option( 'permalink_structure' );
200
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
201
-		$rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( array(
202
-				'amp',
203
-				'post_id' => $post->ID,
204
-				'limit'   => $limit
205
-			) ) ) : false;
206
-
207
-		$rest_url = $post ? rest_url( sprintf( "wordlift/v1/faceted-search?amp&post_id=%s&limit=%s", $post->ID, $limit ) ) : false;
208
-
209
-		// avoid building the widget when no valid $rest_url
210
-		if ( ! $rest_url ) {
211
-			return;
212
-		}
213
-
214
-		// Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
215
-		// This is a hackish way, but this works for http and https URLs
216
-		$rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
217
-
218
-		if ( empty( $template_id ) ) {
219
-			$template_id = "template-" . $faceted_id;
220
-			wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( dirname( __FILE__ ) ) . '/css/wordlift-amp-custom.min.css' );
221
-		}
222
-
223
-		return <<<HTML
172
+    }
173
+
174
+    /**
175
+     * Function in charge of diplaying the [wl-faceted-search] in amp mode.
176
+     *
177
+     * @since 3.20.0
178
+     *
179
+     * @param array $atts Shortcode attributes.
180
+     *
181
+     * @return string Shortcode HTML for amp
182
+     */
183
+    private function amp_shortcode( $atts ) {
184
+
185
+        // attributes extraction and boolean filtering
186
+        $shortcode_atts = $this->make_shortcode_atts( $atts );
187
+
188
+        // avoid building the widget when no post_id is specified and there is a list of posts.
189
+        if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
190
+            return;
191
+        }
192
+
193
+        $post        = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
194
+        $title       = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
195
+        $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
196
+        $limit       = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
197
+        $faceted_id  = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' );
198
+
199
+        $permalink_structure = get_option( 'permalink_structure' );
200
+        $delimiter           = empty( $permalink_structure ) ? '&' : '?';
201
+        $rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( array(
202
+                'amp',
203
+                'post_id' => $post->ID,
204
+                'limit'   => $limit
205
+            ) ) ) : false;
206
+
207
+        $rest_url = $post ? rest_url( sprintf( "wordlift/v1/faceted-search?amp&post_id=%s&limit=%s", $post->ID, $limit ) ) : false;
208
+
209
+        // avoid building the widget when no valid $rest_url
210
+        if ( ! $rest_url ) {
211
+            return;
212
+        }
213
+
214
+        // Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
215
+        // This is a hackish way, but this works for http and https URLs
216
+        $rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
217
+
218
+        if ( empty( $template_id ) ) {
219
+            $template_id = "template-" . $faceted_id;
220
+            wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( dirname( __FILE__ ) ) . '/css/wordlift-amp-custom.min.css' );
221
+        }
222
+
223
+        return <<<HTML
224 224
 		<div id="{$faceted_id}" class="wl-amp-faceted">
225 225
 			<h2 class="wl-headline">{$title}</h2>
226 226
 			<amp-state id="referencedPosts">
@@ -303,6 +303,6 @@  discard block
 block discarded – undo
303 303
 			</section>
304 304
 		</div>
305 305
 HTML;
306
-	}
306
+    }
307 307
 
308 308
 }
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 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/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
 				'attributes'      => array(
60 60
 					'title'       => array(
61 61
 						'type'    => 'string',
62
-						'default' => __( 'Related articles', 'wordlift' ),
62
+						'default' => __('Related articles', 'wordlift'),
63 63
 					),
64 64
 					'template_id' => array(
65 65
 						'type' => 'string',
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 					),
76 76
 					'limit'       => array(
77 77
 						'type'    => 'number',
78
-						'default' => apply_filters( 'wl_faceted_search_default_limit', 10 ),
78
+						'default' => apply_filters('wl_faceted_search_default_limit', 10),
79 79
 					),
80 80
 					'preview'     => array(
81 81
 						'type'    => 'boolean',
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
 					),
84 84
 					'preview_src' => array(
85 85
 						'type'    => 'string',
86
-						'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/faceted-search.png',
86
+						'default' => WP_CONTENT_URL.'/plugins/wordlift/images/block-previews/faceted-search.png',
87 87
 					),
88 88
 				),
89
-			) );
89
+			));
90 90
 		} );
91 91
 	}
92 92
 
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
 	 *
101 101
 	 * @return array $shortcode_atts
102 102
 	 */
103
-	private function make_shortcode_atts( $atts ) {
103
+	private function make_shortcode_atts($atts) {
104 104
 
105 105
 		// Extract attributes and set default values.
106
-		$shortcode_atts = shortcode_atts( array(
107
-			'title'       => __( 'Related articles', 'wordlift' ),
108
-			'limit'       => apply_filters( 'wl_faceted_search_default_limit', 10 ),
106
+		$shortcode_atts = shortcode_atts(array(
107
+			'title'       => __('Related articles', 'wordlift'),
108
+			'limit'       => apply_filters('wl_faceted_search_default_limit', 10),
109 109
 			'post_id'     => '',
110 110
 			'template_id' => '',
111
-			'uniqid'      => uniqid( 'wl-faceted-widget-' ),
112
-		), $atts );
111
+			'uniqid'      => uniqid('wl-faceted-widget-'),
112
+		), $atts);
113 113
 
114 114
 		return $shortcode_atts;
115 115
 	}
@@ -123,38 +123,38 @@  discard block
 block discarded – undo
123 123
 	 *
124 124
 	 * @return string Shortcode HTML for web
125 125
 	 */
126
-	private function web_shortcode( $atts ) {
126
+	private function web_shortcode($atts) {
127 127
 
128 128
 		// attributes extraction and boolean filtering
129
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
129
+		$shortcode_atts = $this->make_shortcode_atts($atts);
130 130
 
131 131
 		// avoid building the widget when no post_id is specified and there is a list of posts.
132
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
132
+		if (empty($shortcode_atts['post_id']) && ! is_singular()) {
133 133
 			return;
134 134
 		}
135 135
 
136
-		$post        = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
137
-		$title       = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
138
-		$template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
139
-		$limit       = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
140
-		$faceted_id  = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' );
136
+		$post        = ! empty($shortcode_atts['post_id']) ? get_post(intval(sanitize_text_field($shortcode_atts['post_id']))) : get_post();
137
+		$title       = esc_attr(sanitize_text_field($shortcode_atts['title']));
138
+		$template_id = esc_attr(sanitize_text_field($shortcode_atts['template_id']));
139
+		$limit       = esc_attr(sanitize_text_field($shortcode_atts['limit']));
140
+		$faceted_id  = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-faceted-widget-');
141 141
 
142
-		$permalink_structure = get_option( 'permalink_structure' );
143
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
144
-		$rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( array(
142
+		$permalink_structure = get_option('permalink_structure');
143
+		$delimiter           = empty($permalink_structure) ? '&' : '?';
144
+		$rest_url            = $post ? rest_url(WL_REST_ROUTE_DEFAULT_NAMESPACE.'/faceted-search'.$delimiter.build_query(array(
145 145
 				'post_id' => $post->ID,
146 146
 				'limit'   => $limit
147
-			) ) ) : false;
148
-		$rest_url = esc_attr( $rest_url );
147
+			))) : false;
148
+		$rest_url = esc_attr($rest_url);
149 149
 
150 150
 		// avoid building the widget when no valid $rest_url
151
-		if ( ! $rest_url ) {
151
+		if ( ! $rest_url) {
152 152
 			return;
153 153
 		}
154 154
 
155
-		wp_enqueue_script( 'wordlift-cloud' );
156
-		$json_faceted_id = wp_json_encode( $faceted_id );
157
-		$template_url = get_rest_url( null, '/wordlift/v1/faceted-search/template' );
155
+		wp_enqueue_script('wordlift-cloud');
156
+		$json_faceted_id = wp_json_encode($faceted_id);
157
+		$template_url = get_rest_url(null, '/wordlift/v1/faceted-search/template');
158 158
 
159 159
 		return <<<HTML
160 160
 			<!-- Faceted {$faceted_id} -->
@@ -180,44 +180,44 @@  discard block
 block discarded – undo
180 180
 	 *
181 181
 	 * @return string Shortcode HTML for amp
182 182
 	 */
183
-	private function amp_shortcode( $atts ) {
183
+	private function amp_shortcode($atts) {
184 184
 
185 185
 		// attributes extraction and boolean filtering
186
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
186
+		$shortcode_atts = $this->make_shortcode_atts($atts);
187 187
 
188 188
 		// avoid building the widget when no post_id is specified and there is a list of posts.
189
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
189
+		if (empty($shortcode_atts['post_id']) && ! is_singular()) {
190 190
 			return;
191 191
 		}
192 192
 
193
-		$post        = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
194
-		$title       = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
195
-		$template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
196
-		$limit       = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
197
-		$faceted_id  = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' );
193
+		$post        = ! empty($shortcode_atts['post_id']) ? get_post(intval(sanitize_text_field($shortcode_atts['post_id']))) : get_post();
194
+		$title       = esc_attr(sanitize_text_field($shortcode_atts['title']));
195
+		$template_id = esc_attr(sanitize_text_field($shortcode_atts['template_id']));
196
+		$limit       = esc_attr(sanitize_text_field($shortcode_atts['limit']));
197
+		$faceted_id  = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-faceted-widget-');
198 198
 
199
-		$permalink_structure = get_option( 'permalink_structure' );
200
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
201
-		$rest_url            = $post ? rest_url( WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( array(
199
+		$permalink_structure = get_option('permalink_structure');
200
+		$delimiter           = empty($permalink_structure) ? '&' : '?';
201
+		$rest_url            = $post ? rest_url(WL_REST_ROUTE_DEFAULT_NAMESPACE.'/faceted-search'.$delimiter.build_query(array(
202 202
 				'amp',
203 203
 				'post_id' => $post->ID,
204 204
 				'limit'   => $limit
205
-			) ) ) : false;
205
+			))) : false;
206 206
 
207
-		$rest_url = $post ? rest_url( sprintf( "wordlift/v1/faceted-search?amp&post_id=%s&limit=%s", $post->ID, $limit ) ) : false;
207
+		$rest_url = $post ? rest_url(sprintf("wordlift/v1/faceted-search?amp&post_id=%s&limit=%s", $post->ID, $limit)) : false;
208 208
 
209 209
 		// avoid building the widget when no valid $rest_url
210
-		if ( ! $rest_url ) {
210
+		if ( ! $rest_url) {
211 211
 			return;
212 212
 		}
213 213
 
214 214
 		// Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
215 215
 		// This is a hackish way, but this works for http and https URLs
216
-		$rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
216
+		$rest_url = str_replace(array('http:', 'https:'), '', $rest_url);
217 217
 
218
-		if ( empty( $template_id ) ) {
219
-			$template_id = "template-" . $faceted_id;
220
-			wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( dirname( __FILE__ ) ) . '/css/wordlift-amp-custom.min.css' );
218
+		if (empty($template_id)) {
219
+			$template_id = "template-".$faceted_id;
220
+			wp_enqueue_style('wordlift-amp-custom', plugin_dir_url(dirname(__FILE__)).'/css/wordlift-amp-custom.min.css');
221 221
 		}
222 222
 
223 223
 		return <<<HTML
Please login to merge, or discard this patch.