Completed
Pull Request — develop (#1701)
by
unknown
01:18
created
src/public/class-wordlift-navigator-shortcode.php 2 patches
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -17,134 +17,134 @@  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';
20
+    /**
21
+     * {@inheritdoc}
22
+     */
23
+    const SHORTCODE = 'wl_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 ) {
34
-		return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts )
35
-			: $this->web_shortcode( $atts );
36
-	}
30
+    /**
31
+     * {@inheritdoc}
32
+     */
33
+    public function render( $atts ) {
34
+        return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts )
35
+            : $this->web_shortcode( $atts );
36
+    }
37 37
 
38
-	private function register_block_type() {
38
+    private function register_block_type() {
39 39
 
40
-		$scope = $this;
40
+        $scope = $this;
41 41
 
42
-		add_action(
43
-			'init',
44
-			function () use ( $scope ) {
45
-				if ( ! function_exists( 'register_block_type' ) ) {
46
-					// Gutenberg is not active.
47
-					return;
48
-				}
42
+        add_action(
43
+            'init',
44
+            function () use ( $scope ) {
45
+                if ( ! function_exists( 'register_block_type' ) ) {
46
+                    // Gutenberg is not active.
47
+                    return;
48
+                }
49 49
 
50
-				register_block_type(
51
-					'wordlift/navigator',
52
-					array(
53
-						'editor_script'   => 'wl-block-editor',
54
-						'render_callback' => function ( $attributes ) use ( $scope ) {
55
-							$attr_code = '';
56
-							foreach ( $attributes as $key => $value ) {
57
-								$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
58
-							}
50
+                register_block_type(
51
+                    'wordlift/navigator',
52
+                    array(
53
+                        'editor_script'   => 'wl-block-editor',
54
+                        'render_callback' => function ( $attributes ) use ( $scope ) {
55
+                            $attr_code = '';
56
+                            foreach ( $attributes as $key => $value ) {
57
+                                $attr_code .= $key . '="' . htmlentities( $value ) . '" ';
58
+                            }
59 59
 
60
-							return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
61
-						},
62
-						'attributes'      => $scope->get_navigator_block_attributes(),
63
-					)
64
-				);
65
-			}
66
-		);
67
-	}
60
+                            return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
61
+                        },
62
+                        'attributes'      => $scope->get_navigator_block_attributes(),
63
+                    )
64
+                );
65
+            }
66
+        );
67
+    }
68 68
 
69
-	/**
70
-	 * Shared function used by web_shortcode and amp_shortcode
71
-	 * Bootstrap logic for attributes extraction and boolean filtering
72
-	 *
73
-	 * @param array $atts Shortcode attributes.
74
-	 *
75
-	 * @return array $shortcode_atts
76
-	 * @since      3.20.0
77
-	 */
78
-	private function make_shortcode_atts( $atts ) {
69
+    /**
70
+     * Shared function used by web_shortcode and amp_shortcode
71
+     * Bootstrap logic for attributes extraction and boolean filtering
72
+     *
73
+     * @param array $atts Shortcode attributes.
74
+     *
75
+     * @return array $shortcode_atts
76
+     * @since      3.20.0
77
+     */
78
+    private function make_shortcode_atts( $atts ) {
79 79
 
80
-		// Extract attributes and set default values.
81
-		$shortcode_atts = shortcode_atts(
82
-			array(
83
-				'title'       => __( 'Related articles', 'wordlift' ),
84
-				'limit'       => 4,
85
-				'offset'      => 0,
86
-				'template_id' => '',
87
-				'post_id'     => '',
88
-				'uniqid'      => uniqid( 'wl-navigator-widget-' ),
89
-				'order_by'    => 'ID DESC',
90
-				'post_types'  => '',
91
-			),
92
-			$atts
93
-		);
80
+        // Extract attributes and set default values.
81
+        $shortcode_atts = shortcode_atts(
82
+            array(
83
+                'title'       => __( 'Related articles', 'wordlift' ),
84
+                'limit'       => 4,
85
+                'offset'      => 0,
86
+                'template_id' => '',
87
+                'post_id'     => '',
88
+                'uniqid'      => uniqid( 'wl-navigator-widget-' ),
89
+                'order_by'    => 'ID DESC',
90
+                'post_types'  => '',
91
+            ),
92
+            $atts
93
+        );
94 94
 
95
-		return $shortcode_atts;
96
-	}
95
+        return $shortcode_atts;
96
+    }
97 97
 
98
-	/**
99
-	 * Function in charge of displaying the [wl-navigator] in web mode.
100
-	 *
101
-	 * @param array $atts Shortcode attributes.
102
-	 *
103
-	 * @return string Shortcode HTML for web
104
-	 * @since 3.20.0
105
-	 */
106
-	private function web_shortcode( $atts ) {
98
+    /**
99
+     * Function in charge of displaying the [wl-navigator] in web mode.
100
+     *
101
+     * @param array $atts Shortcode attributes.
102
+     *
103
+     * @return string Shortcode HTML for web
104
+     * @since 3.20.0
105
+     */
106
+    private function web_shortcode( $atts ) {
107 107
 
108
-		// attributes extraction and boolean filtering
109
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
108
+        // attributes extraction and boolean filtering
109
+        $shortcode_atts = $this->make_shortcode_atts( $atts );
110 110
 
111
-		// avoid building the widget when no post_id is specified and there is a list of posts.
112
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
113
-			return;
114
-		}
111
+        // avoid building the widget when no post_id is specified and there is a list of posts.
112
+        if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
113
+            return;
114
+        }
115 115
 
116
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
117
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
118
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
119
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
120
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
121
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
122
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' );
116
+        $post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
117
+        $title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
118
+        $template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
119
+        $limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
120
+        $offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
121
+        $sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
122
+        $navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' );
123 123
 
124
-		$rest_url = $post ? admin_url(
125
-			'admin-ajax.php?' . build_query(
126
-				array(
127
-					'action'     => 'wl_navigator',
128
-					'uniqid'     => $navigator_id,
129
-					'post_id'    => $post->ID,
130
-					'limit'      => $limit,
131
-					'offset'     => $offset,
132
-					'sort'       => $sort,
133
-					'post_types' => $shortcode_atts['post_types'],
134
-					'_wpnonce'   => wp_create_nonce( 'wl_navigator' ),
135
-				)
136
-			)
137
-		) : false;
124
+        $rest_url = $post ? admin_url(
125
+            'admin-ajax.php?' . build_query(
126
+                array(
127
+                    'action'     => 'wl_navigator',
128
+                    'uniqid'     => $navigator_id,
129
+                    'post_id'    => $post->ID,
130
+                    'limit'      => $limit,
131
+                    'offset'     => $offset,
132
+                    'sort'       => $sort,
133
+                    'post_types' => $shortcode_atts['post_types'],
134
+                    '_wpnonce'   => wp_create_nonce( 'wl_navigator' ),
135
+                )
136
+            )
137
+        ) : false;
138 138
 
139
-		// avoid building the widget when no valid $rest_url
140
-		if ( ! $rest_url ) {
141
-			return;
142
-		}
139
+        // avoid building the widget when no valid $rest_url
140
+        if ( ! $rest_url ) {
141
+            return;
142
+        }
143 143
 
144
-		wp_enqueue_script( 'wordlift-cloud' );
145
-		$template_url = get_rest_url( null, '/wordlift/v1/navigator/template' );
144
+        wp_enqueue_script( 'wordlift-cloud' );
145
+        $template_url = get_rest_url( null, '/wordlift/v1/navigator/template' );
146 146
 
147
-		return <<<HTML
147
+        return <<<HTML
148 148
 			<!-- Navigator {$navigator_id} -->
149 149
 			<div id="{$navigator_id}" 
150 150
 				 class="wl-navigator" 
@@ -155,63 +155,63 @@  discard block
 block discarded – undo
155 155
 				 data-limit="{$limit}"></div>
156 156
 			<!-- /Navigator {$navigator_id} -->
157 157
 HTML;
158
-	}
158
+    }
159 159
 
160
-	/**
161
-	 * Function in charge of diplaying the [wl-faceted-search] in amp mode.
162
-	 *
163
-	 * @param array $atts Shortcode attributes.
164
-	 *
165
-	 * @return string Shortcode HTML for amp
166
-	 * @since 3.20.0
167
-	 */
168
-	private function amp_shortcode( $atts ) {
169
-		// attributes extraction and boolean filtering
170
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
160
+    /**
161
+     * Function in charge of diplaying the [wl-faceted-search] in amp mode.
162
+     *
163
+     * @param array $atts Shortcode attributes.
164
+     *
165
+     * @return string Shortcode HTML for amp
166
+     * @since 3.20.0
167
+     */
168
+    private function amp_shortcode( $atts ) {
169
+        // attributes extraction and boolean filtering
170
+        $shortcode_atts = $this->make_shortcode_atts( $atts );
171 171
 
172
-		// avoid building the widget when no post_id is specified and there is a list of posts.
173
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
174
-			return;
175
-		}
172
+        // avoid building the widget when no post_id is specified and there is a list of posts.
173
+        if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
174
+            return;
175
+        }
176 176
 
177
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
178
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
179
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
180
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
181
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
182
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
183
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' );
177
+        $post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
178
+        $title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
179
+        $template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
180
+        $limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
181
+        $offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
182
+        $sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
183
+        $navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' );
184 184
 
185
-		$permalink_structure = get_option( 'permalink_structure' );
186
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
187
-		$rest_url            = $post ? rest_url(
188
-			WL_REST_ROUTE_DEFAULT_NAMESPACE . '/navigator' . $delimiter . build_query(
189
-				array(
190
-					'uniqid'   => $navigator_id,
191
-					'post_id'  => $post->ID,
192
-					'limit'    => $limit,
193
-					'offset'   => $offset,
194
-					'sort'     => $sort,
195
-					'_wpnonce' => wp_create_nonce( 'wl_navigator' ),
196
-				)
197
-			)
198
-		) : false;
185
+        $permalink_structure = get_option( 'permalink_structure' );
186
+        $delimiter           = empty( $permalink_structure ) ? '&' : '?';
187
+        $rest_url            = $post ? rest_url(
188
+            WL_REST_ROUTE_DEFAULT_NAMESPACE . '/navigator' . $delimiter . build_query(
189
+                array(
190
+                    'uniqid'   => $navigator_id,
191
+                    'post_id'  => $post->ID,
192
+                    'limit'    => $limit,
193
+                    'offset'   => $offset,
194
+                    'sort'     => $sort,
195
+                    '_wpnonce' => wp_create_nonce( 'wl_navigator' ),
196
+                )
197
+            )
198
+        ) : false;
199 199
 
200
-		// avoid building the widget when no valid $rest_url
201
-		if ( ! $rest_url ) {
202
-			return;
203
-		}
200
+        // avoid building the widget when no valid $rest_url
201
+        if ( ! $rest_url ) {
202
+            return;
203
+        }
204 204
 
205
-		// Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
206
-		// This is a hackish way, but this works for http and https URLs
207
-		$rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
205
+        // Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
206
+        // This is a hackish way, but this works for http and https URLs
207
+        $rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
208 208
 
209
-		if ( empty( $template_id ) ) {
210
-			$template_id = 'template-' . $navigator_id;
211
-			wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( __DIR__ ) . '/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION );
212
-		}
209
+        if ( empty( $template_id ) ) {
210
+            $template_id = 'template-' . $navigator_id;
211
+            wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( __DIR__ ) . '/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION );
212
+        }
213 213
 
214
-		return <<<HTML
214
+        return <<<HTML
215 215
 		<div id="{$navigator_id}" class="wl-amp-navigator" style="width: 100%">
216 216
 			<h3 class="wl-headline">{$title}</h3>
217 217
 			<amp-list 
@@ -244,54 +244,54 @@  discard block
 block discarded – undo
244 244
 			</div>
245 245
 		</template>
246 246
 HTML;
247
-	}
247
+    }
248 248
 
249
-	/**
250
-	 * @return array
251
-	 */
252
-	public function get_navigator_block_attributes() {
253
-		return array(
254
-			'title'       => array(
255
-				'type'    => 'string',
256
-				'default' => __( 'Related articles', 'wordlift' ),
257
-			),
258
-			'limit'       => array(
259
-				'type'    => 'number',
260
-				'default' => 4,
261
-			),
262
-			'template_id' => array(
263
-				'type'    => 'string',
264
-				'default' => '',
265
-			),
266
-			'post_id'     => array(
267
-				'type'    => 'number',
268
-				'default' => '',
269
-			),
270
-			'offset'      => array(
271
-				'type'    => 'number',
272
-				'default' => 0,
273
-			),
274
-			'uniqid'      => array(
275
-				'type'    => 'string',
276
-				'default' => '',
277
-			),
278
-			'order_by'    => array(
279
-				'type'    => 'string',
280
-				'default' => 'ID DESC',
281
-			),
282
-			'preview'     => array(
283
-				'type'    => 'boolean',
284
-				'default' => false,
285
-			),
286
-			'preview_src' => array(
287
-				'type'    => 'string',
288
-				'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/navigator.png',
289
-			),
290
-			'post_types'  => array(
291
-				'type'    => 'string',
292
-				'default' => '',
293
-			),
294
-		);
295
-	}
249
+    /**
250
+     * @return array
251
+     */
252
+    public function get_navigator_block_attributes() {
253
+        return array(
254
+            'title'       => array(
255
+                'type'    => 'string',
256
+                'default' => __( 'Related articles', 'wordlift' ),
257
+            ),
258
+            'limit'       => array(
259
+                'type'    => 'number',
260
+                'default' => 4,
261
+            ),
262
+            'template_id' => array(
263
+                'type'    => 'string',
264
+                'default' => '',
265
+            ),
266
+            'post_id'     => array(
267
+                'type'    => 'number',
268
+                'default' => '',
269
+            ),
270
+            'offset'      => array(
271
+                'type'    => 'number',
272
+                'default' => 0,
273
+            ),
274
+            'uniqid'      => array(
275
+                'type'    => 'string',
276
+                'default' => '',
277
+            ),
278
+            'order_by'    => array(
279
+                'type'    => 'string',
280
+                'default' => 'ID DESC',
281
+            ),
282
+            'preview'     => array(
283
+                'type'    => 'boolean',
284
+                'default' => false,
285
+            ),
286
+            'preview_src' => array(
287
+                'type'    => 'string',
288
+                'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/navigator.png',
289
+            ),
290
+            'post_types'  => array(
291
+                'type'    => 'string',
292
+                'default' => '',
293
+            ),
294
+        );
295
+    }
296 296
 
297 297
 }
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
 	/**
31 31
 	 * {@inheritdoc}
32 32
 	 */
33
-	public function render( $atts ) {
34
-		return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts )
35
-			: $this->web_shortcode( $atts );
33
+	public function render($atts) {
34
+		return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode($atts)
35
+			: $this->web_shortcode($atts);
36 36
 	}
37 37
 
38 38
 	private function register_block_type() {
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
 
42 42
 		add_action(
43 43
 			'init',
44
-			function () use ( $scope ) {
45
-				if ( ! function_exists( 'register_block_type' ) ) {
44
+			function() use ($scope) {
45
+				if ( ! function_exists('register_block_type')) {
46 46
 					// Gutenberg is not active.
47 47
 					return;
48 48
 				}
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
 					'wordlift/navigator',
52 52
 					array(
53 53
 						'editor_script'   => 'wl-block-editor',
54
-						'render_callback' => function ( $attributes ) use ( $scope ) {
54
+						'render_callback' => function($attributes) use ($scope) {
55 55
 							$attr_code = '';
56
-							foreach ( $attributes as $key => $value ) {
57
-								$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
56
+							foreach ($attributes as $key => $value) {
57
+								$attr_code .= $key.'="'.htmlentities($value).'" ';
58 58
 							}
59 59
 
60
-							return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
60
+							return '['.$scope::SHORTCODE.' '.$attr_code.']';
61 61
 						},
62 62
 						'attributes'      => $scope->get_navigator_block_attributes(),
63 63
 					)
@@ -75,17 +75,17 @@  discard block
 block discarded – undo
75 75
 	 * @return array $shortcode_atts
76 76
 	 * @since      3.20.0
77 77
 	 */
78
-	private function make_shortcode_atts( $atts ) {
78
+	private function make_shortcode_atts($atts) {
79 79
 
80 80
 		// Extract attributes and set default values.
81 81
 		$shortcode_atts = shortcode_atts(
82 82
 			array(
83
-				'title'       => __( 'Related articles', 'wordlift' ),
83
+				'title'       => __('Related articles', 'wordlift'),
84 84
 				'limit'       => 4,
85 85
 				'offset'      => 0,
86 86
 				'template_id' => '',
87 87
 				'post_id'     => '',
88
-				'uniqid'      => uniqid( 'wl-navigator-widget-' ),
88
+				'uniqid'      => uniqid('wl-navigator-widget-'),
89 89
 				'order_by'    => 'ID DESC',
90 90
 				'post_types'  => '',
91 91
 			),
@@ -103,26 +103,26 @@  discard block
 block discarded – undo
103 103
 	 * @return string Shortcode HTML for web
104 104
 	 * @since 3.20.0
105 105
 	 */
106
-	private function web_shortcode( $atts ) {
106
+	private function web_shortcode($atts) {
107 107
 
108 108
 		// attributes extraction and boolean filtering
109
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
109
+		$shortcode_atts = $this->make_shortcode_atts($atts);
110 110
 
111 111
 		// avoid building the widget when no post_id is specified and there is a list of posts.
112
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
112
+		if (empty($shortcode_atts['post_id']) && ! is_singular()) {
113 113
 			return;
114 114
 		}
115 115
 
116
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
117
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
118
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
119
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
120
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
121
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
122
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' );
116
+		$post         = ! empty($shortcode_atts['post_id']) ? get_post(intval($shortcode_atts['post_id'])) : get_post();
117
+		$title        = esc_attr(sanitize_text_field($shortcode_atts['title']));
118
+		$template_id  = esc_attr(sanitize_text_field($shortcode_atts['template_id']));
119
+		$limit        = esc_attr(sanitize_text_field($shortcode_atts['limit']));
120
+		$offset       = esc_attr(sanitize_text_field($shortcode_atts['offset']));
121
+		$sort         = esc_attr(sanitize_sql_orderby(sanitize_text_field($shortcode_atts['order_by'])));
122
+		$navigator_id = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-navigator-widget-');
123 123
 
124 124
 		$rest_url = $post ? admin_url(
125
-			'admin-ajax.php?' . build_query(
125
+			'admin-ajax.php?'.build_query(
126 126
 				array(
127 127
 					'action'     => 'wl_navigator',
128 128
 					'uniqid'     => $navigator_id,
@@ -131,18 +131,18 @@  discard block
 block discarded – undo
131 131
 					'offset'     => $offset,
132 132
 					'sort'       => $sort,
133 133
 					'post_types' => $shortcode_atts['post_types'],
134
-					'_wpnonce'   => wp_create_nonce( 'wl_navigator' ),
134
+					'_wpnonce'   => wp_create_nonce('wl_navigator'),
135 135
 				)
136 136
 			)
137 137
 		) : false;
138 138
 
139 139
 		// avoid building the widget when no valid $rest_url
140
-		if ( ! $rest_url ) {
140
+		if ( ! $rest_url) {
141 141
 			return;
142 142
 		}
143 143
 
144
-		wp_enqueue_script( 'wordlift-cloud' );
145
-		$template_url = get_rest_url( null, '/wordlift/v1/navigator/template' );
144
+		wp_enqueue_script('wordlift-cloud');
145
+		$template_url = get_rest_url(null, '/wordlift/v1/navigator/template');
146 146
 
147 147
 		return <<<HTML
148 148
 			<!-- Navigator {$navigator_id} -->
@@ -165,50 +165,50 @@  discard block
 block discarded – undo
165 165
 	 * @return string Shortcode HTML for amp
166 166
 	 * @since 3.20.0
167 167
 	 */
168
-	private function amp_shortcode( $atts ) {
168
+	private function amp_shortcode($atts) {
169 169
 		// attributes extraction and boolean filtering
170
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
170
+		$shortcode_atts = $this->make_shortcode_atts($atts);
171 171
 
172 172
 		// avoid building the widget when no post_id is specified and there is a list of posts.
173
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
173
+		if (empty($shortcode_atts['post_id']) && ! is_singular()) {
174 174
 			return;
175 175
 		}
176 176
 
177
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
178
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
179
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
180
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
181
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
182
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
183
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' );
177
+		$post         = ! empty($shortcode_atts['post_id']) ? get_post(intval($shortcode_atts['post_id'])) : get_post();
178
+		$title        = esc_attr(sanitize_text_field($shortcode_atts['title']));
179
+		$template_id  = esc_attr(sanitize_text_field($shortcode_atts['template_id']));
180
+		$limit        = esc_attr(sanitize_text_field($shortcode_atts['limit']));
181
+		$offset       = esc_attr(sanitize_text_field($shortcode_atts['offset']));
182
+		$sort         = esc_attr(sanitize_sql_orderby(sanitize_text_field($shortcode_atts['order_by'])));
183
+		$navigator_id = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-navigator-widget-');
184 184
 
185
-		$permalink_structure = get_option( 'permalink_structure' );
186
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
185
+		$permalink_structure = get_option('permalink_structure');
186
+		$delimiter           = empty($permalink_structure) ? '&' : '?';
187 187
 		$rest_url            = $post ? rest_url(
188
-			WL_REST_ROUTE_DEFAULT_NAMESPACE . '/navigator' . $delimiter . build_query(
188
+			WL_REST_ROUTE_DEFAULT_NAMESPACE.'/navigator'.$delimiter.build_query(
189 189
 				array(
190 190
 					'uniqid'   => $navigator_id,
191 191
 					'post_id'  => $post->ID,
192 192
 					'limit'    => $limit,
193 193
 					'offset'   => $offset,
194 194
 					'sort'     => $sort,
195
-					'_wpnonce' => wp_create_nonce( 'wl_navigator' ),
195
+					'_wpnonce' => wp_create_nonce('wl_navigator'),
196 196
 				)
197 197
 			)
198 198
 		) : false;
199 199
 
200 200
 		// avoid building the widget when no valid $rest_url
201
-		if ( ! $rest_url ) {
201
+		if ( ! $rest_url) {
202 202
 			return;
203 203
 		}
204 204
 
205 205
 		// Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
206 206
 		// This is a hackish way, but this works for http and https URLs
207
-		$rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
207
+		$rest_url = str_replace(array('http:', 'https:'), '', $rest_url);
208 208
 
209
-		if ( empty( $template_id ) ) {
210
-			$template_id = 'template-' . $navigator_id;
211
-			wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( __DIR__ ) . '/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION );
209
+		if (empty($template_id)) {
210
+			$template_id = 'template-'.$navigator_id;
211
+			wp_enqueue_style('wordlift-amp-custom', plugin_dir_url(__DIR__).'/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION);
212 212
 		}
213 213
 
214 214
 		return <<<HTML
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 		return array(
254 254
 			'title'       => array(
255 255
 				'type'    => 'string',
256
-				'default' => __( 'Related articles', 'wordlift' ),
256
+				'default' => __('Related articles', 'wordlift'),
257 257
 			),
258 258
 			'limit'       => array(
259 259
 				'type'    => 'number',
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 			),
286 286
 			'preview_src' => array(
287 287
 				'type'    => 'string',
288
-				'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/navigator.png',
288
+				'default' => WP_CONTENT_URL.'/plugins/wordlift/images/block-previews/navigator.png',
289 289
 			),
290 290
 			'post_types'  => array(
291 291
 				'type'    => 'string',
Please login to merge, or discard this patch.
src/public/class-wordlift-related-entities-cloud-shortcode.php 2 patches
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -16,168 +16,168 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Related_Entities_Cloud_Shortcode extends Wordlift_Shortcode {
18 18
 
19
-	/**
20
-	 * {@inheritdoc}
21
-	 */
22
-	const SHORTCODE = 'wl_cloud';
23
-
24
-	/**
25
-	 * The {@link Wordlift_Relation_Service} instance.
26
-	 *
27
-	 * @since  3.15.0
28
-	 * @access private
29
-	 * @var \Wordlift_Relation_Service $relation_service The {@link Wordlift_Relation_Service} instance.
30
-	 */
31
-	private $relation_service;
32
-	/**
33
-	 * @var Wordlift_Entity_Service
34
-	 */
35
-	private $entity_service;
36
-
37
-	/**
38
-	 * Create a {@link Wordlift_Related_Entities_Cloud_Shortcode} instance.
39
-	 *
40
-	 * @param \Wordlift_Relation_Service $relation_service The {@link Wordlift_Relation_Service} instance.
41
-	 * @param \Wordlift_Entity_Service   $entity_service
42
-	 *
43
-	 * @since 3.15.0
44
-	 */
45
-	public function __construct( $relation_service, $entity_service ) {
46
-		parent::__construct();
47
-
48
-		$this->relation_service = $relation_service;
49
-
50
-		$this->entity_service = $entity_service;
51
-
52
-		$this->register_block_type();
53
-
54
-	}
55
-
56
-	/**
57
-	 * {@inheritdoc}
58
-	 */
59
-	public function render( $atts ) {
60
-
61
-		$tags = $this->get_related_entities_tags();
62
-
63
-		// Bail out if there are no associated entities.
64
-		if ( empty( $tags ) ) {
65
-			return '';
66
-		}
67
-
68
-		/*
19
+    /**
20
+     * {@inheritdoc}
21
+     */
22
+    const SHORTCODE = 'wl_cloud';
23
+
24
+    /**
25
+     * The {@link Wordlift_Relation_Service} instance.
26
+     *
27
+     * @since  3.15.0
28
+     * @access private
29
+     * @var \Wordlift_Relation_Service $relation_service The {@link Wordlift_Relation_Service} instance.
30
+     */
31
+    private $relation_service;
32
+    /**
33
+     * @var Wordlift_Entity_Service
34
+     */
35
+    private $entity_service;
36
+
37
+    /**
38
+     * Create a {@link Wordlift_Related_Entities_Cloud_Shortcode} instance.
39
+     *
40
+     * @param \Wordlift_Relation_Service $relation_service The {@link Wordlift_Relation_Service} instance.
41
+     * @param \Wordlift_Entity_Service   $entity_service
42
+     *
43
+     * @since 3.15.0
44
+     */
45
+    public function __construct( $relation_service, $entity_service ) {
46
+        parent::__construct();
47
+
48
+        $this->relation_service = $relation_service;
49
+
50
+        $this->entity_service = $entity_service;
51
+
52
+        $this->register_block_type();
53
+
54
+    }
55
+
56
+    /**
57
+     * {@inheritdoc}
58
+     */
59
+    public function render( $atts ) {
60
+
61
+        $tags = $this->get_related_entities_tags();
62
+
63
+        // Bail out if there are no associated entities.
64
+        if ( empty( $tags ) ) {
65
+            return '';
66
+        }
67
+
68
+        /*
69 69
 		 * Since the output is use in the widget as well, we need to have the
70 70
 		 * same class as the core tagcloud widget, to easily inherit its styling.
71 71
 		 */
72 72
 
73
-		return '<div class="tagcloud wl-related-entities-cloud">' .
74
-			   wp_generate_tag_cloud( $tags, $atts ) .
75
-			   '</div>';
76
-	}
77
-
78
-	private function register_block_type() {
79
-
80
-		$scope = $this;
81
-
82
-		add_action(
83
-			'init',
84
-			function () use ( $scope ) {
85
-				if ( ! function_exists( 'register_block_type' ) ) {
86
-					// Gutenberg is not active.
87
-					return;
88
-				}
89
-
90
-				register_block_type(
91
-					'wordlift/cloud',
92
-					array(
93
-						'editor_script'   => 'wl-block-editor',
94
-						'render_callback' => function ( $attributes ) use ( $scope ) {
95
-							$attr_code = '';
96
-							foreach ( $attributes as $key => $value ) {
97
-								$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
98
-							}
99
-
100
-							return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
101
-						},
102
-						'attributes'      => array(
103
-							'preview'     => array(
104
-								'type'    => 'boolean',
105
-								'default' => false,
106
-							),
107
-							'preview_src' => array(
108
-								'type'    => 'string',
109
-								'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/cloud.png',
110
-							),
111
-						),
112
-					)
113
-				);
114
-			}
115
-		);
116
-	}
117
-
118
-	/**
119
-	 * Find the related entities to the currently displayed post and
120
-	 * calculate the "tags" for them as wp_generate_tag_cloud expects to get.
121
-	 *
122
-	 * @return array    Array of tags. Empty array in case we re not in a context
123
-	 *                  of a post, or it has no related entities.
124
-	 * @since 3.11.0
125
-	 */
126
-	public function get_related_entities_tags() {
127
-
128
-		// Define the supported types list.
129
-		$supported_types = Wordlift_Entity_Service::valid_entity_post_types();
130
-
131
-		// Show nothing if not on a post or entity page.
132
-		if ( ! is_singular( $supported_types ) ) {
133
-			return array();
134
-		}
135
-
136
-		// Get the IDs of entities related to current post.
137
-		$related_entities = wl_core_get_related_entity_ids( get_the_ID(), array( 'status' => 'publish' ) );
138
-
139
-		// Bail out if there are no associated entities.
140
-		if ( empty( $related_entities ) ) {
141
-			return array();
142
-		}
143
-
144
-		/*
73
+        return '<div class="tagcloud wl-related-entities-cloud">' .
74
+                wp_generate_tag_cloud( $tags, $atts ) .
75
+                '</div>';
76
+    }
77
+
78
+    private function register_block_type() {
79
+
80
+        $scope = $this;
81
+
82
+        add_action(
83
+            'init',
84
+            function () use ( $scope ) {
85
+                if ( ! function_exists( 'register_block_type' ) ) {
86
+                    // Gutenberg is not active.
87
+                    return;
88
+                }
89
+
90
+                register_block_type(
91
+                    'wordlift/cloud',
92
+                    array(
93
+                        'editor_script'   => 'wl-block-editor',
94
+                        'render_callback' => function ( $attributes ) use ( $scope ) {
95
+                            $attr_code = '';
96
+                            foreach ( $attributes as $key => $value ) {
97
+                                $attr_code .= $key . '="' . htmlentities( $value ) . '" ';
98
+                            }
99
+
100
+                            return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
101
+                        },
102
+                        'attributes'      => array(
103
+                            'preview'     => array(
104
+                                'type'    => 'boolean',
105
+                                'default' => false,
106
+                            ),
107
+                            'preview_src' => array(
108
+                                'type'    => 'string',
109
+                                'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/cloud.png',
110
+                            ),
111
+                        ),
112
+                    )
113
+                );
114
+            }
115
+        );
116
+    }
117
+
118
+    /**
119
+     * Find the related entities to the currently displayed post and
120
+     * calculate the "tags" for them as wp_generate_tag_cloud expects to get.
121
+     *
122
+     * @return array    Array of tags. Empty array in case we re not in a context
123
+     *                  of a post, or it has no related entities.
124
+     * @since 3.11.0
125
+     */
126
+    public function get_related_entities_tags() {
127
+
128
+        // Define the supported types list.
129
+        $supported_types = Wordlift_Entity_Service::valid_entity_post_types();
130
+
131
+        // Show nothing if not on a post or entity page.
132
+        if ( ! is_singular( $supported_types ) ) {
133
+            return array();
134
+        }
135
+
136
+        // Get the IDs of entities related to current post.
137
+        $related_entities = wl_core_get_related_entity_ids( get_the_ID(), array( 'status' => 'publish' ) );
138
+
139
+        // Bail out if there are no associated entities.
140
+        if ( empty( $related_entities ) ) {
141
+            return array();
142
+        }
143
+
144
+        /*
145 145
 		 * Create an array of "tags" to feed to wp_generate_tag_cloud.
146 146
 		 * Use the number of posts and entities connected to the entity as a weight.
147 147
 		 */
148
-		$tags = array();
149
-
150
-		foreach ( array_unique( $related_entities ) as $entity_id ) {
151
-
152
-			$connected_entities = count( wl_core_get_related_entity_ids( $entity_id, array( 'status' => 'publish' ) ) );
153
-			$connected_posts    = count( $this->relation_service->get_article_subjects( $entity_id, '*', null, 'publish' ) );
154
-			/**
155
-			 * @since 3.31.5
156
-			 * if synonym exists, use it instead of entity name.
157
-			 */
158
-			$synonyms    = $this->get_synonyms( $entity_id );
159
-			$entity_name = count( $synonyms ) > 0 ? $synonyms[0] : get_the_title( $entity_id );
160
-
161
-			$tags[] = (object) array(
162
-				'id'    => $entity_id,
163
-				// Used to give a unique class on the tag.
164
-				'name'  => $entity_name,
165
-				// The text of the tag.
166
-				'slug'  => get_the_title( $entity_id ),
167
-				// Required but not seem to be relevant
168
-				'link'  => get_permalink( $entity_id ),
169
-				// the url the tag links to.
170
-				'count' => $connected_entities + $connected_posts,
171
-				// The weight.
172
-			);
173
-
174
-		}
175
-
176
-		return $tags;
177
-	}
178
-
179
-	private function get_synonyms( $entity_id ) {
180
-		return $this->entity_service->get_alternative_labels( $entity_id );
181
-	}
148
+        $tags = array();
149
+
150
+        foreach ( array_unique( $related_entities ) as $entity_id ) {
151
+
152
+            $connected_entities = count( wl_core_get_related_entity_ids( $entity_id, array( 'status' => 'publish' ) ) );
153
+            $connected_posts    = count( $this->relation_service->get_article_subjects( $entity_id, '*', null, 'publish' ) );
154
+            /**
155
+             * @since 3.31.5
156
+             * if synonym exists, use it instead of entity name.
157
+             */
158
+            $synonyms    = $this->get_synonyms( $entity_id );
159
+            $entity_name = count( $synonyms ) > 0 ? $synonyms[0] : get_the_title( $entity_id );
160
+
161
+            $tags[] = (object) array(
162
+                'id'    => $entity_id,
163
+                // Used to give a unique class on the tag.
164
+                'name'  => $entity_name,
165
+                // The text of the tag.
166
+                'slug'  => get_the_title( $entity_id ),
167
+                // Required but not seem to be relevant
168
+                'link'  => get_permalink( $entity_id ),
169
+                // the url the tag links to.
170
+                'count' => $connected_entities + $connected_posts,
171
+                // The weight.
172
+            );
173
+
174
+        }
175
+
176
+        return $tags;
177
+    }
178
+
179
+    private function get_synonyms( $entity_id ) {
180
+        return $this->entity_service->get_alternative_labels( $entity_id );
181
+    }
182 182
 
183 183
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @since 3.15.0
44 44
 	 */
45
-	public function __construct( $relation_service, $entity_service ) {
45
+	public function __construct($relation_service, $entity_service) {
46 46
 		parent::__construct();
47 47
 
48 48
 		$this->relation_service = $relation_service;
@@ -56,12 +56,12 @@  discard block
 block discarded – undo
56 56
 	/**
57 57
 	 * {@inheritdoc}
58 58
 	 */
59
-	public function render( $atts ) {
59
+	public function render($atts) {
60 60
 
61 61
 		$tags = $this->get_related_entities_tags();
62 62
 
63 63
 		// Bail out if there are no associated entities.
64
-		if ( empty( $tags ) ) {
64
+		if (empty($tags)) {
65 65
 			return '';
66 66
 		}
67 67
 
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
 		 * same class as the core tagcloud widget, to easily inherit its styling.
71 71
 		 */
72 72
 
73
-		return '<div class="tagcloud wl-related-entities-cloud">' .
74
-			   wp_generate_tag_cloud( $tags, $atts ) .
73
+		return '<div class="tagcloud wl-related-entities-cloud">'.
74
+			   wp_generate_tag_cloud($tags, $atts).
75 75
 			   '</div>';
76 76
 	}
77 77
 
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 
82 82
 		add_action(
83 83
 			'init',
84
-			function () use ( $scope ) {
85
-				if ( ! function_exists( 'register_block_type' ) ) {
84
+			function() use ($scope) {
85
+				if ( ! function_exists('register_block_type')) {
86 86
 					// Gutenberg is not active.
87 87
 					return;
88 88
 				}
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
 					'wordlift/cloud',
92 92
 					array(
93 93
 						'editor_script'   => 'wl-block-editor',
94
-						'render_callback' => function ( $attributes ) use ( $scope ) {
94
+						'render_callback' => function($attributes) use ($scope) {
95 95
 							$attr_code = '';
96
-							foreach ( $attributes as $key => $value ) {
97
-								$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
96
+							foreach ($attributes as $key => $value) {
97
+								$attr_code .= $key.'="'.htmlentities($value).'" ';
98 98
 							}
99 99
 
100
-							return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
100
+							return '['.$scope::SHORTCODE.' '.$attr_code.']';
101 101
 						},
102 102
 						'attributes'      => array(
103 103
 							'preview'     => array(
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 							),
107 107
 							'preview_src' => array(
108 108
 								'type'    => 'string',
109
-								'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/cloud.png',
109
+								'default' => WP_CONTENT_URL.'/plugins/wordlift/images/block-previews/cloud.png',
110 110
 							),
111 111
 						),
112 112
 					)
@@ -129,15 +129,15 @@  discard block
 block discarded – undo
129 129
 		$supported_types = Wordlift_Entity_Service::valid_entity_post_types();
130 130
 
131 131
 		// Show nothing if not on a post or entity page.
132
-		if ( ! is_singular( $supported_types ) ) {
132
+		if ( ! is_singular($supported_types)) {
133 133
 			return array();
134 134
 		}
135 135
 
136 136
 		// Get the IDs of entities related to current post.
137
-		$related_entities = wl_core_get_related_entity_ids( get_the_ID(), array( 'status' => 'publish' ) );
137
+		$related_entities = wl_core_get_related_entity_ids(get_the_ID(), array('status' => 'publish'));
138 138
 
139 139
 		// Bail out if there are no associated entities.
140
-		if ( empty( $related_entities ) ) {
140
+		if (empty($related_entities)) {
141 141
 			return array();
142 142
 		}
143 143
 
@@ -147,25 +147,25 @@  discard block
 block discarded – undo
147 147
 		 */
148 148
 		$tags = array();
149 149
 
150
-		foreach ( array_unique( $related_entities ) as $entity_id ) {
150
+		foreach (array_unique($related_entities) as $entity_id) {
151 151
 
152
-			$connected_entities = count( wl_core_get_related_entity_ids( $entity_id, array( 'status' => 'publish' ) ) );
153
-			$connected_posts    = count( $this->relation_service->get_article_subjects( $entity_id, '*', null, 'publish' ) );
152
+			$connected_entities = count(wl_core_get_related_entity_ids($entity_id, array('status' => 'publish')));
153
+			$connected_posts    = count($this->relation_service->get_article_subjects($entity_id, '*', null, 'publish'));
154 154
 			/**
155 155
 			 * @since 3.31.5
156 156
 			 * if synonym exists, use it instead of entity name.
157 157
 			 */
158
-			$synonyms    = $this->get_synonyms( $entity_id );
159
-			$entity_name = count( $synonyms ) > 0 ? $synonyms[0] : get_the_title( $entity_id );
158
+			$synonyms    = $this->get_synonyms($entity_id);
159
+			$entity_name = count($synonyms) > 0 ? $synonyms[0] : get_the_title($entity_id);
160 160
 
161 161
 			$tags[] = (object) array(
162 162
 				'id'    => $entity_id,
163 163
 				// Used to give a unique class on the tag.
164 164
 				'name'  => $entity_name,
165 165
 				// The text of the tag.
166
-				'slug'  => get_the_title( $entity_id ),
166
+				'slug'  => get_the_title($entity_id),
167 167
 				// Required but not seem to be relevant
168
-				'link'  => get_permalink( $entity_id ),
168
+				'link'  => get_permalink($entity_id),
169 169
 				// the url the tag links to.
170 170
 				'count' => $connected_entities + $connected_posts,
171 171
 				// The weight.
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
 		return $tags;
177 177
 	}
178 178
 
179
-	private function get_synonyms( $entity_id ) {
180
-		return $this->entity_service->get_alternative_labels( $entity_id );
179
+	private function get_synonyms($entity_id) {
180
+		return $this->entity_service->get_alternative_labels($entity_id);
181 181
 	}
182 182
 
183 183
 }
Please login to merge, or discard this patch.
src/public/class-wordlift-products-navigator-shortcode.php 2 patches
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -17,169 +17,169 @@  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(
44
-			'init',
45
-			function () use ( $scope ) {
46
-				if ( ! function_exists( 'register_block_type' ) ) {
47
-					// Gutenberg is not active.
48
-					return;
49
-				}
43
+        add_action(
44
+            'init',
45
+            function () use ( $scope ) {
46
+                if ( ! function_exists( 'register_block_type' ) ) {
47
+                    // Gutenberg is not active.
48
+                    return;
49
+                }
50 50
 
51
-				register_block_type(
52
-					'wordlift/products-navigator',
53
-					array(
54
-						'editor_script'   => 'wl-block-editor',
55
-						'render_callback' => function ( $attributes ) use ( $scope ) {
56
-							$attr_code = '';
57
-							foreach ( $attributes as $key => $value ) {
58
-								$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
59
-							}
51
+                register_block_type(
52
+                    'wordlift/products-navigator',
53
+                    array(
54
+                        'editor_script'   => 'wl-block-editor',
55
+                        'render_callback' => function ( $attributes ) use ( $scope ) {
56
+                            $attr_code = '';
57
+                            foreach ( $attributes as $key => $value ) {
58
+                                $attr_code .= $key . '="' . htmlentities( $value ) . '" ';
59
+                            }
60 60
 
61
-							return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
62
-						},
63
-						'attributes'      => array(
64
-							'title'       => array(
65
-								'type'    => 'string',
66
-								'default' => __( 'Related products', 'wordlift' ),
67
-							),
68
-							'limit'       => array(
69
-								'type'    => 'number',
70
-								'default' => 4,
71
-							),
72
-							'template_id' => array(
73
-								'type'    => 'string',
74
-								'default' => '',
75
-							),
76
-							'post_id'     => array(
77
-								'type'    => 'number',
78
-								'default' => '',
79
-							),
80
-							'offset'      => array(
81
-								'type'    => 'number',
82
-								'default' => 0,
83
-							),
84
-							'uniqid'      => array(
85
-								'type'    => 'string',
86
-								'default' => '',
87
-							),
88
-							'order_by'    => array(
89
-								'type'    => 'string',
90
-								'default' => 'ID DESC',
91
-							),
92
-							'preview'     => array(
93
-								'type'    => 'boolean',
94
-								'default' => false,
95
-							),
96
-							'preview_src' => array(
97
-								'type'    => 'string',
98
-								'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/products-navigator.png',
99
-							),
100
-						),
101
-					)
102
-				);
103
-			}
104
-		);
105
-	}
61
+                            return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
62
+                        },
63
+                        'attributes'      => array(
64
+                            'title'       => array(
65
+                                'type'    => 'string',
66
+                                'default' => __( 'Related products', 'wordlift' ),
67
+                            ),
68
+                            'limit'       => array(
69
+                                'type'    => 'number',
70
+                                'default' => 4,
71
+                            ),
72
+                            'template_id' => array(
73
+                                'type'    => 'string',
74
+                                'default' => '',
75
+                            ),
76
+                            'post_id'     => array(
77
+                                'type'    => 'number',
78
+                                'default' => '',
79
+                            ),
80
+                            'offset'      => array(
81
+                                'type'    => 'number',
82
+                                'default' => 0,
83
+                            ),
84
+                            'uniqid'      => array(
85
+                                'type'    => 'string',
86
+                                'default' => '',
87
+                            ),
88
+                            'order_by'    => array(
89
+                                'type'    => 'string',
90
+                                'default' => 'ID DESC',
91
+                            ),
92
+                            'preview'     => array(
93
+                                'type'    => 'boolean',
94
+                                'default' => false,
95
+                            ),
96
+                            'preview_src' => array(
97
+                                'type'    => 'string',
98
+                                'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/products-navigator.png',
99
+                            ),
100
+                        ),
101
+                    )
102
+                );
103
+            }
104
+        );
105
+    }
106 106
 
107
-	/**
108
-	 * Shared function used by web_shortcode and amp_shortcode
109
-	 * Bootstrap logic for attributes extraction and boolean filtering
110
-	 *
111
-	 * @param array $atts Shortcode attributes.
112
-	 *
113
-	 * @return array $shortcode_atts
114
-	 * @since      3.27.0
115
-	 */
116
-	private function make_shortcode_atts( $atts ) {
107
+    /**
108
+     * Shared function used by web_shortcode and amp_shortcode
109
+     * Bootstrap logic for attributes extraction and boolean filtering
110
+     *
111
+     * @param array $atts Shortcode attributes.
112
+     *
113
+     * @return array $shortcode_atts
114
+     * @since      3.27.0
115
+     */
116
+    private function make_shortcode_atts( $atts ) {
117 117
 
118
-		// Extract attributes and set default values.
119
-		$shortcode_atts = shortcode_atts(
120
-			array(
121
-				'title'       => __( 'Related products', 'wordlift' ),
122
-				'limit'       => 4,
123
-				'offset'      => 0,
124
-				'template_id' => '',
125
-				'post_id'     => '',
126
-				'uniqid'      => uniqid( 'wl-products-navigator-widget-' ),
127
-				'order_by'    => 'ID DESC',
128
-			),
129
-			$atts
130
-		);
118
+        // Extract attributes and set default values.
119
+        $shortcode_atts = shortcode_atts(
120
+            array(
121
+                'title'       => __( 'Related products', 'wordlift' ),
122
+                'limit'       => 4,
123
+                'offset'      => 0,
124
+                'template_id' => '',
125
+                'post_id'     => '',
126
+                'uniqid'      => uniqid( 'wl-products-navigator-widget-' ),
127
+                'order_by'    => 'ID DESC',
128
+            ),
129
+            $atts
130
+        );
131 131
 
132
-		return $shortcode_atts;
133
-	}
132
+        return $shortcode_atts;
133
+    }
134 134
 
135
-	/**
136
-	 * Function in charge of diplaying the [wl_products_navigator] in web mode.
137
-	 *
138
-	 * @param array $atts Shortcode attributes.
139
-	 *
140
-	 * @return string Shortcode HTML for web
141
-	 * @since 3.20.0
142
-	 */
143
-	private function web_shortcode( $atts ) {
135
+    /**
136
+     * Function in charge of diplaying the [wl_products_navigator] in web mode.
137
+     *
138
+     * @param array $atts Shortcode attributes.
139
+     *
140
+     * @return string Shortcode HTML for web
141
+     * @since 3.20.0
142
+     */
143
+    private function web_shortcode( $atts ) {
144 144
 
145
-		// attributes extraction and boolean filtering
146
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
145
+        // attributes extraction and boolean filtering
146
+        $shortcode_atts = $this->make_shortcode_atts( $atts );
147 147
 
148
-		// avoid building the widget when no post_id is specified and there is a list of posts.
149
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
150
-			return;
151
-		}
148
+        // avoid building the widget when no post_id is specified and there is a list of posts.
149
+        if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
150
+            return;
151
+        }
152 152
 
153
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
154
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
155
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
156
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
157
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
158
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
159
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-products-navigator-widget-' );
153
+        $post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
154
+        $title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
155
+        $template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
156
+        $limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
157
+        $offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
158
+        $sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
159
+        $navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-products-navigator-widget-' );
160 160
 
161
-		$permalink_structure = get_option( 'permalink_structure' );
162
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
163
-		$rest_url            = $post ? rest_url(
164
-			WL_REST_ROUTE_DEFAULT_NAMESPACE . '/products-navigator' . $delimiter . build_query(
165
-				array(
166
-					'uniqid'  => $navigator_id,
167
-					'post_id' => $post->ID,
168
-					'limit'   => $limit,
169
-					'offset'  => $offset,
170
-					'sort'    => $sort,
171
-				)
172
-			)
173
-		) : false;
161
+        $permalink_structure = get_option( 'permalink_structure' );
162
+        $delimiter           = empty( $permalink_structure ) ? '&' : '?';
163
+        $rest_url            = $post ? rest_url(
164
+            WL_REST_ROUTE_DEFAULT_NAMESPACE . '/products-navigator' . $delimiter . build_query(
165
+                array(
166
+                    'uniqid'  => $navigator_id,
167
+                    'post_id' => $post->ID,
168
+                    'limit'   => $limit,
169
+                    'offset'  => $offset,
170
+                    'sort'    => $sort,
171
+                )
172
+            )
173
+        ) : false;
174 174
 
175
-		// avoid building the widget when no valid $rest_url
176
-		if ( ! $rest_url ) {
177
-			return;
178
-		}
175
+        // avoid building the widget when no valid $rest_url
176
+        if ( ! $rest_url ) {
177
+            return;
178
+        }
179 179
 
180
-		wp_enqueue_script( 'wordlift-cloud' );
180
+        wp_enqueue_script( 'wordlift-cloud' );
181 181
 
182
-		return <<<HTML
182
+        return <<<HTML
183 183
 			<!-- Products Navigator {$navigator_id} -->
184 184
 			<div id="{$navigator_id}" 
185 185
 				 class="wl-products-navigator" 
@@ -189,64 +189,64 @@  discard block
 block discarded – undo
189 189
 				 data-limit="{$limit}"></div>
190 190
 			<!-- /Products Navigator {$navigator_id} -->
191 191
 HTML;
192
-	}
192
+    }
193 193
 
194
-	/**
195
-	 * Function in charge of diplaying the [wl_products_navigator] in amp mode.
196
-	 *
197
-	 * @param array $atts Shortcode attributes.
198
-	 *
199
-	 * @return string Shortcode HTML for amp
200
-	 * @since 3.20.0
201
-	 */
202
-	private function amp_shortcode( $atts ) {
194
+    /**
195
+     * Function in charge of diplaying the [wl_products_navigator] in amp mode.
196
+     *
197
+     * @param array $atts Shortcode attributes.
198
+     *
199
+     * @return string Shortcode HTML for amp
200
+     * @since 3.20.0
201
+     */
202
+    private function amp_shortcode( $atts ) {
203 203
 
204
-		// attributes extraction and boolean filtering
205
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
204
+        // attributes extraction and boolean filtering
205
+        $shortcode_atts = $this->make_shortcode_atts( $atts );
206 206
 
207
-		// avoid building the widget when no post_id is specified and there is a list of posts.
208
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
209
-			return;
210
-		}
207
+        // avoid building the widget when no post_id is specified and there is a list of posts.
208
+        if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
209
+            return;
210
+        }
211 211
 
212
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
213
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
214
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
215
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
216
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
217
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
218
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-products-navigator-widget-' );
212
+        $post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
213
+        $title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
214
+        $template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
215
+        $limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
216
+        $offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
217
+        $sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
218
+        $navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-products-navigator-widget-' );
219 219
 
220
-		$permalink_structure = get_option( 'permalink_structure' );
221
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
222
-		$rest_url            = $post ? rest_url(
223
-			WL_REST_ROUTE_DEFAULT_NAMESPACE . '/products-navigator' . $delimiter . build_query(
224
-				array(
225
-					'amp'     => true,
226
-					'uniqid'  => $navigator_id,
227
-					'post_id' => $post->ID,
228
-					'limit'   => $limit,
229
-					'offset'  => $offset,
230
-					'sort'    => $sort,
231
-				)
232
-			)
233
-		) : false;
220
+        $permalink_structure = get_option( 'permalink_structure' );
221
+        $delimiter           = empty( $permalink_structure ) ? '&' : '?';
222
+        $rest_url            = $post ? rest_url(
223
+            WL_REST_ROUTE_DEFAULT_NAMESPACE . '/products-navigator' . $delimiter . build_query(
224
+                array(
225
+                    'amp'     => true,
226
+                    'uniqid'  => $navigator_id,
227
+                    'post_id' => $post->ID,
228
+                    'limit'   => $limit,
229
+                    'offset'  => $offset,
230
+                    'sort'    => $sort,
231
+                )
232
+            )
233
+        ) : false;
234 234
 
235
-		// avoid building the widget when no valid $rest_url
236
-		if ( ! $rest_url ) {
237
-			return;
238
-		}
235
+        // avoid building the widget when no valid $rest_url
236
+        if ( ! $rest_url ) {
237
+            return;
238
+        }
239 239
 
240
-		// Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
241
-		// This is a hackish way, but this works for http and https URLs
242
-		$rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
240
+        // Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
241
+        // This is a hackish way, but this works for http and https URLs
242
+        $rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
243 243
 
244
-		if ( empty( $template_id ) ) {
245
-			$template_id = 'template-' . $navigator_id;
246
-			wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( __DIR__ ) . '/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION );
247
-		}
244
+        if ( empty( $template_id ) ) {
245
+            $template_id = 'template-' . $navigator_id;
246
+            wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( __DIR__ ) . '/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION );
247
+        }
248 248
 
249
-		return <<<HTML
249
+        return <<<HTML
250 250
 		<div id="{$navigator_id}" class="wl-amp-products-navigator">
251 251
 			<h3 class="wl-headline">{$title}</h3>
252 252
 			<section class="cards">
@@ -348,6 +348,6 @@  discard block
 block discarded – undo
348 348
 			</section>
349 349
 		</div>
350 350
 HTML;
351
-	}
351
+    }
352 352
 
353 353
 }
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -30,10 +30,10 @@  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() {
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 
43 43
 		add_action(
44 44
 			'init',
45
-			function () use ( $scope ) {
46
-				if ( ! function_exists( 'register_block_type' ) ) {
45
+			function() use ($scope) {
46
+				if ( ! function_exists('register_block_type')) {
47 47
 					// Gutenberg is not active.
48 48
 					return;
49 49
 				}
@@ -52,18 +52,18 @@  discard block
 block discarded – undo
52 52
 					'wordlift/products-navigator',
53 53
 					array(
54 54
 						'editor_script'   => 'wl-block-editor',
55
-						'render_callback' => function ( $attributes ) use ( $scope ) {
55
+						'render_callback' => function($attributes) use ($scope) {
56 56
 							$attr_code = '';
57
-							foreach ( $attributes as $key => $value ) {
58
-								$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
57
+							foreach ($attributes as $key => $value) {
58
+								$attr_code .= $key.'="'.htmlentities($value).'" ';
59 59
 							}
60 60
 
61
-							return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
61
+							return '['.$scope::SHORTCODE.' '.$attr_code.']';
62 62
 						},
63 63
 						'attributes'      => array(
64 64
 							'title'       => array(
65 65
 								'type'    => 'string',
66
-								'default' => __( 'Related products', 'wordlift' ),
66
+								'default' => __('Related products', 'wordlift'),
67 67
 							),
68 68
 							'limit'       => array(
69 69
 								'type'    => 'number',
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 							),
96 96
 							'preview_src' => array(
97 97
 								'type'    => 'string',
98
-								'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/products-navigator.png',
98
+								'default' => WP_CONTENT_URL.'/plugins/wordlift/images/block-previews/products-navigator.png',
99 99
 							),
100 100
 						),
101 101
 					)
@@ -113,17 +113,17 @@  discard block
 block discarded – undo
113 113
 	 * @return array $shortcode_atts
114 114
 	 * @since      3.27.0
115 115
 	 */
116
-	private function make_shortcode_atts( $atts ) {
116
+	private function make_shortcode_atts($atts) {
117 117
 
118 118
 		// Extract attributes and set default values.
119 119
 		$shortcode_atts = shortcode_atts(
120 120
 			array(
121
-				'title'       => __( 'Related products', 'wordlift' ),
121
+				'title'       => __('Related products', 'wordlift'),
122 122
 				'limit'       => 4,
123 123
 				'offset'      => 0,
124 124
 				'template_id' => '',
125 125
 				'post_id'     => '',
126
-				'uniqid'      => uniqid( 'wl-products-navigator-widget-' ),
126
+				'uniqid'      => uniqid('wl-products-navigator-widget-'),
127 127
 				'order_by'    => 'ID DESC',
128 128
 			),
129 129
 			$atts
@@ -140,28 +140,28 @@  discard block
 block discarded – undo
140 140
 	 * @return string Shortcode HTML for web
141 141
 	 * @since 3.20.0
142 142
 	 */
143
-	private function web_shortcode( $atts ) {
143
+	private function web_shortcode($atts) {
144 144
 
145 145
 		// attributes extraction and boolean filtering
146
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
146
+		$shortcode_atts = $this->make_shortcode_atts($atts);
147 147
 
148 148
 		// avoid building the widget when no post_id is specified and there is a list of posts.
149
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
149
+		if (empty($shortcode_atts['post_id']) && ! is_singular()) {
150 150
 			return;
151 151
 		}
152 152
 
153
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
154
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
155
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
156
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
157
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
158
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
159
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-products-navigator-widget-' );
153
+		$post         = ! empty($shortcode_atts['post_id']) ? get_post(intval(sanitize_text_field($shortcode_atts['post_id']))) : get_post();
154
+		$title        = esc_attr(sanitize_text_field($shortcode_atts['title']));
155
+		$template_id  = esc_attr(sanitize_text_field($shortcode_atts['template_id']));
156
+		$limit        = esc_attr(sanitize_text_field($shortcode_atts['limit']));
157
+		$offset       = esc_attr(sanitize_text_field($shortcode_atts['offset']));
158
+		$sort         = esc_attr(sanitize_sql_orderby(sanitize_text_field($shortcode_atts['order_by'])));
159
+		$navigator_id = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-products-navigator-widget-');
160 160
 
161
-		$permalink_structure = get_option( 'permalink_structure' );
162
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
161
+		$permalink_structure = get_option('permalink_structure');
162
+		$delimiter           = empty($permalink_structure) ? '&' : '?';
163 163
 		$rest_url            = $post ? rest_url(
164
-			WL_REST_ROUTE_DEFAULT_NAMESPACE . '/products-navigator' . $delimiter . build_query(
164
+			WL_REST_ROUTE_DEFAULT_NAMESPACE.'/products-navigator'.$delimiter.build_query(
165 165
 				array(
166 166
 					'uniqid'  => $navigator_id,
167 167
 					'post_id' => $post->ID,
@@ -173,11 +173,11 @@  discard block
 block discarded – undo
173 173
 		) : false;
174 174
 
175 175
 		// avoid building the widget when no valid $rest_url
176
-		if ( ! $rest_url ) {
176
+		if ( ! $rest_url) {
177 177
 			return;
178 178
 		}
179 179
 
180
-		wp_enqueue_script( 'wordlift-cloud' );
180
+		wp_enqueue_script('wordlift-cloud');
181 181
 
182 182
 		return <<<HTML
183 183
 			<!-- Products Navigator {$navigator_id} -->
@@ -199,28 +199,28 @@  discard block
 block discarded – undo
199 199
 	 * @return string Shortcode HTML for amp
200 200
 	 * @since 3.20.0
201 201
 	 */
202
-	private function amp_shortcode( $atts ) {
202
+	private function amp_shortcode($atts) {
203 203
 
204 204
 		// attributes extraction and boolean filtering
205
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
205
+		$shortcode_atts = $this->make_shortcode_atts($atts);
206 206
 
207 207
 		// avoid building the widget when no post_id is specified and there is a list of posts.
208
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
208
+		if (empty($shortcode_atts['post_id']) && ! is_singular()) {
209 209
 			return;
210 210
 		}
211 211
 
212
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post();
213
-		$title        = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) );
214
-		$template_id  = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) );
215
-		$limit        = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) );
216
-		$offset       = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) );
217
-		$sort         = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) );
218
-		$navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-products-navigator-widget-' );
212
+		$post         = ! empty($shortcode_atts['post_id']) ? get_post(intval(sanitize_text_field($shortcode_atts['post_id']))) : get_post();
213
+		$title        = esc_attr(sanitize_text_field($shortcode_atts['title']));
214
+		$template_id  = esc_attr(sanitize_text_field($shortcode_atts['template_id']));
215
+		$limit        = esc_attr(sanitize_text_field($shortcode_atts['limit']));
216
+		$offset       = esc_attr(sanitize_text_field($shortcode_atts['offset']));
217
+		$sort         = esc_attr(sanitize_sql_orderby(sanitize_text_field($shortcode_atts['order_by'])));
218
+		$navigator_id = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-products-navigator-widget-');
219 219
 
220
-		$permalink_structure = get_option( 'permalink_structure' );
221
-		$delimiter           = empty( $permalink_structure ) ? '&' : '?';
220
+		$permalink_structure = get_option('permalink_structure');
221
+		$delimiter           = empty($permalink_structure) ? '&' : '?';
222 222
 		$rest_url            = $post ? rest_url(
223
-			WL_REST_ROUTE_DEFAULT_NAMESPACE . '/products-navigator' . $delimiter . build_query(
223
+			WL_REST_ROUTE_DEFAULT_NAMESPACE.'/products-navigator'.$delimiter.build_query(
224 224
 				array(
225 225
 					'amp'     => true,
226 226
 					'uniqid'  => $navigator_id,
@@ -233,17 +233,17 @@  discard block
 block discarded – undo
233 233
 		) : false;
234 234
 
235 235
 		// avoid building the widget when no valid $rest_url
236
-		if ( ! $rest_url ) {
236
+		if ( ! $rest_url) {
237 237
 			return;
238 238
 		}
239 239
 
240 240
 		// Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
241 241
 		// This is a hackish way, but this works for http and https URLs
242
-		$rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url );
242
+		$rest_url = str_replace(array('http:', 'https:'), '', $rest_url);
243 243
 
244
-		if ( empty( $template_id ) ) {
245
-			$template_id = 'template-' . $navigator_id;
246
-			wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( __DIR__ ) . '/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION );
244
+		if (empty($template_id)) {
245
+			$template_id = 'template-'.$navigator_id;
246
+			wp_enqueue_style('wordlift-amp-custom', plugin_dir_url(__DIR__).'/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION);
247 247
 		}
248 248
 
249 249
 		return <<<HTML
Please login to merge, or discard this patch.
src/public/class-wordlift-context-cards-service.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -9,68 +9,68 @@
 block discarded – undo
9 9
 
10 10
 class Wordlift_Context_Cards_Service {
11 11
 
12
-	public function enqueue_scripts() {
12
+    public function enqueue_scripts() {
13 13
 
14
-		$show_context_cards     = apply_filters( 'wl_context_cards_show', true );
15
-		$context_cards_base_url = apply_filters( 'wl_context_cards_base_url', get_rest_url( null, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/jsonld' ) );
14
+        $show_context_cards     = apply_filters( 'wl_context_cards_show', true );
15
+        $context_cards_base_url = apply_filters( 'wl_context_cards_base_url', get_rest_url( null, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/jsonld' ) );
16 16
 
17
-		/*
17
+        /*
18 18
 		 * Do not load wordlift-cloud on a non-static home page
19 19
 		 *
20 20
 		 * @since 3.27.4
21 21
 		 */
22
-		if ( is_front_page() && is_home() ) {
23
-			// Default homepage - force hide
24
-			$show_context_cards = false;
25
-		} elseif ( is_home() ) {
26
-			// Blog page - force hide
27
-			$show_context_cards = false;
28
-		}
22
+        if ( is_front_page() && is_home() ) {
23
+            // Default homepage - force hide
24
+            $show_context_cards = false;
25
+        } elseif ( is_home() ) {
26
+            // Blog page - force hide
27
+            $show_context_cards = false;
28
+        }
29 29
 
30
-		if ( $show_context_cards ) {
31
-			wp_enqueue_script( 'wordlift-cloud' );
32
-			wp_localize_script(
33
-				'wordlift-cloud',
34
-				'_wlCloudSettings',
35
-				array(
36
-					'selector' => 'a.wl-entity-page-link',
37
-					'url'      => $context_cards_base_url,
38
-				)
39
-			);
40
-		}
30
+        if ( $show_context_cards ) {
31
+            wp_enqueue_script( 'wordlift-cloud' );
32
+            wp_localize_script(
33
+                'wordlift-cloud',
34
+                '_wlCloudSettings',
35
+                array(
36
+                    'selector' => 'a.wl-entity-page-link',
37
+                    'url'      => $context_cards_base_url,
38
+                )
39
+            );
40
+        }
41 41
 
42
-		add_filter( 'wl_anchor_data_attributes', array( $this, 'anchor_data_attributes' ), 10, 2 );
43
-	}
42
+        add_filter( 'wl_anchor_data_attributes', array( $this, 'anchor_data_attributes' ), 10, 2 );
43
+    }
44 44
 
45
-	public function anchor_data_attributes( $attributes, $post_id ) {
45
+    public function anchor_data_attributes( $attributes, $post_id ) {
46 46
 
47
-		$supported_types   = Wordlift_Entity_Service::valid_entity_post_types();
48
-		$post_type         = get_post_type( $post_id );
49
-		$enabled_templates = apply_filters( 'wl_context_cards_enabled_templates', array( 'product' ) );
47
+        $supported_types   = Wordlift_Entity_Service::valid_entity_post_types();
48
+        $post_type         = get_post_type( $post_id );
49
+        $enabled_templates = apply_filters( 'wl_context_cards_enabled_templates', array( 'product' ) );
50 50
 
51
-		if ( in_array( $post_type, $supported_types, true ) && in_array( $post_type, $enabled_templates, true ) ) {
51
+        if ( in_array( $post_type, $supported_types, true ) && in_array( $post_type, $enabled_templates, true ) ) {
52 52
 
53
-			$additional_attributes = array( 'post-type-template' => $post_type );
53
+            $additional_attributes = array( 'post-type-template' => $post_type );
54 54
 
55
-			switch ( $post_type ) {
56
-				case 'product':
57
-					$product                                   = wc_get_product( $post_id );
58
-					$additional_attributes['template-payload'] = wp_json_encode(
59
-						array(
60
-							'regular_price'   => $product->get_regular_price(),
61
-							'currency_symbol' => get_woocommerce_currency_symbol(),
62
-							'discount_pc'     => ( $product->get_sale_price() && ( $product->get_regular_price() > 0 ) ) ? round( 1 - ( $product->get_sale_price() / $product->get_regular_price() ), 2 ) * 100 : 0,
63
-							'average_rating'  => $product->get_average_rating(),
64
-							'rating_count'    => $product->get_rating_count(),
65
-							'rating_html'     => wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ),
66
-						)
67
-					);
68
-			}
55
+            switch ( $post_type ) {
56
+                case 'product':
57
+                    $product                                   = wc_get_product( $post_id );
58
+                    $additional_attributes['template-payload'] = wp_json_encode(
59
+                        array(
60
+                            'regular_price'   => $product->get_regular_price(),
61
+                            'currency_symbol' => get_woocommerce_currency_symbol(),
62
+                            'discount_pc'     => ( $product->get_sale_price() && ( $product->get_regular_price() > 0 ) ) ? round( 1 - ( $product->get_sale_price() / $product->get_regular_price() ), 2 ) * 100 : 0,
63
+                            'average_rating'  => $product->get_average_rating(),
64
+                            'rating_count'    => $product->get_rating_count(),
65
+                            'rating_html'     => wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ),
66
+                        )
67
+                    );
68
+            }
69 69
 
70
-			return $attributes + $additional_attributes;
71
-		}
70
+            return $attributes + $additional_attributes;
71
+        }
72 72
 
73
-		return $attributes;
74
-	}
73
+        return $attributes;
74
+    }
75 75
 
76 76
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -11,24 +11,24 @@  discard block
 block discarded – undo
11 11
 
12 12
 	public function enqueue_scripts() {
13 13
 
14
-		$show_context_cards     = apply_filters( 'wl_context_cards_show', true );
15
-		$context_cards_base_url = apply_filters( 'wl_context_cards_base_url', get_rest_url( null, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/jsonld' ) );
14
+		$show_context_cards     = apply_filters('wl_context_cards_show', true);
15
+		$context_cards_base_url = apply_filters('wl_context_cards_base_url', get_rest_url(null, WL_REST_ROUTE_DEFAULT_NAMESPACE.'/jsonld'));
16 16
 
17 17
 		/*
18 18
 		 * Do not load wordlift-cloud on a non-static home page
19 19
 		 *
20 20
 		 * @since 3.27.4
21 21
 		 */
22
-		if ( is_front_page() && is_home() ) {
22
+		if (is_front_page() && is_home()) {
23 23
 			// Default homepage - force hide
24 24
 			$show_context_cards = false;
25
-		} elseif ( is_home() ) {
25
+		} elseif (is_home()) {
26 26
 			// Blog page - force hide
27 27
 			$show_context_cards = false;
28 28
 		}
29 29
 
30
-		if ( $show_context_cards ) {
31
-			wp_enqueue_script( 'wordlift-cloud' );
30
+		if ($show_context_cards) {
31
+			wp_enqueue_script('wordlift-cloud');
32 32
 			wp_localize_script(
33 33
 				'wordlift-cloud',
34 34
 				'_wlCloudSettings',
@@ -39,30 +39,30 @@  discard block
 block discarded – undo
39 39
 			);
40 40
 		}
41 41
 
42
-		add_filter( 'wl_anchor_data_attributes', array( $this, 'anchor_data_attributes' ), 10, 2 );
42
+		add_filter('wl_anchor_data_attributes', array($this, 'anchor_data_attributes'), 10, 2);
43 43
 	}
44 44
 
45
-	public function anchor_data_attributes( $attributes, $post_id ) {
45
+	public function anchor_data_attributes($attributes, $post_id) {
46 46
 
47 47
 		$supported_types   = Wordlift_Entity_Service::valid_entity_post_types();
48
-		$post_type         = get_post_type( $post_id );
49
-		$enabled_templates = apply_filters( 'wl_context_cards_enabled_templates', array( 'product' ) );
48
+		$post_type         = get_post_type($post_id);
49
+		$enabled_templates = apply_filters('wl_context_cards_enabled_templates', array('product'));
50 50
 
51
-		if ( in_array( $post_type, $supported_types, true ) && in_array( $post_type, $enabled_templates, true ) ) {
51
+		if (in_array($post_type, $supported_types, true) && in_array($post_type, $enabled_templates, true)) {
52 52
 
53
-			$additional_attributes = array( 'post-type-template' => $post_type );
53
+			$additional_attributes = array('post-type-template' => $post_type);
54 54
 
55
-			switch ( $post_type ) {
55
+			switch ($post_type) {
56 56
 				case 'product':
57
-					$product                                   = wc_get_product( $post_id );
57
+					$product                                   = wc_get_product($post_id);
58 58
 					$additional_attributes['template-payload'] = wp_json_encode(
59 59
 						array(
60 60
 							'regular_price'   => $product->get_regular_price(),
61 61
 							'currency_symbol' => get_woocommerce_currency_symbol(),
62
-							'discount_pc'     => ( $product->get_sale_price() && ( $product->get_regular_price() > 0 ) ) ? round( 1 - ( $product->get_sale_price() / $product->get_regular_price() ), 2 ) * 100 : 0,
62
+							'discount_pc'     => ($product->get_sale_price() && ($product->get_regular_price() > 0)) ? round(1 - ($product->get_sale_price() / $product->get_regular_price()), 2) * 100 : 0,
63 63
 							'average_rating'  => $product->get_average_rating(),
64 64
 							'rating_count'    => $product->get_rating_count(),
65
-							'rating_html'     => wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ),
65
+							'rating_html'     => wc_get_rating_html($product->get_average_rating(), $product->get_rating_count()),
66 66
 						)
67 67
 					);
68 68
 			}
Please login to merge, or discard this patch.
src/public/class-wordlift-chord-shortcode.php 2 patches
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -16,104 +16,104 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Chord_Shortcode extends Wordlift_Shortcode {
18 18
 
19
-	/**
20
-	 * {@inheritdoc}
21
-	 */
22
-	const SHORTCODE = 'wl_chord';
23
-
24
-	/**
25
-	 * Create a {@link Wordlift_Chord_Shortcode} instance.
26
-	 *
27
-	 * @since      3.5.4
28
-	 */
29
-	public function __construct() {
30
-		parent::__construct();
31
-
32
-		// Hook to the `amp_post_template_css` to hide ourselves when in AMP
33
-		// rendering.
34
-		add_action(
35
-			'amp_post_template_css',
36
-			array(
37
-				$this,
38
-				'amp_post_template_css',
39
-			)
40
-		);
41
-		$this->register_block_type();
42
-
43
-	}
44
-
45
-	/**
46
-	 * Render shordcode.
47
-	 *
48
-	 * @param array $atts shortcode attributes.
49
-	 *
50
-	 * @return string The HTML output.
51
-	 */
52
-	public function render( $atts ) {
53
-
54
-		// extract attributes and set default values.
55
-		$chord_atts = shortcode_atts(
56
-			array(
57
-				'width'      => '100%',
58
-				'height'     => '500px',
59
-				'main_color' => '000',
60
-				'depth'      => 2,
61
-				'global'     => false,
62
-			),
63
-			$atts
64
-		);
65
-
66
-		if ( $chord_atts['global'] ) {
67
-
68
-			$post_id = wl_shortcode_chord_most_referenced_entity_id();
69
-
70
-			if ( null === $post_id ) {
71
-				return 'WordLift Chord: no entities found.';
72
-			}
73
-
74
-			// Use the provided height if any, otherwise use a default of 200px.
75
-			//
76
-			// See https://github.com/insideout10/wordlift-plugin/issues/443.
77
-			$chord_atts['height'] = isset( $chord_atts['height'] ) ? $chord_atts['height'] : '200px';
78
-
79
-		} else {
80
-			$post_id = get_the_ID();
81
-		}
82
-
83
-		// Use the registered style which define an optional dependency to font-awesome.
84
-		//
85
-		// @see https://github.com/insideout10/wordlift-plugin/issues/699
86
-		// wp_enqueue_style( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' );
87
-		wp_enqueue_style( 'wordlift-ui' );
88
-
89
-		// Adding javascript code.
90
-		wp_enqueue_script( 'd3', dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/d3/d3.min.js', array(), WORDLIFT_VERSION, false );
91
-
92
-		$this->enqueue_scripts();
93
-
94
-		wp_localize_script(
95
-			'wordlift-ui',
96
-			'wl_chord_params',
97
-			array(
98
-				'ajax_url'       => admin_url( 'admin-ajax.php' ),
99
-				'action'         => 'wl_chord',
100
-				'wl_chord_nonce' => wp_create_nonce( 'wl_chord' ),
101
-			)
102
-		);
103
-
104
-		// Escaping atts.
105
-		$esc_class  = esc_attr( 'wl-chord' );
106
-		$esc_id     = esc_attr( uniqid( 'wl-chord-' ) );
107
-		$esc_width  = esc_attr( $chord_atts['width'] );
108
-		$esc_height = esc_attr( $chord_atts['height'] );
109
-
110
-		$esc_post_id    = esc_attr( $post_id );
111
-		$esc_depth      = esc_attr( $chord_atts['depth'] );
112
-		$esc_main_color = esc_attr( $chord_atts['main_color'] );
113
-
114
-		// Building template.
115
-		// TODO: in the HTML code there are static CSS rules. Move them to the CSS file.
116
-		return "
19
+    /**
20
+     * {@inheritdoc}
21
+     */
22
+    const SHORTCODE = 'wl_chord';
23
+
24
+    /**
25
+     * Create a {@link Wordlift_Chord_Shortcode} instance.
26
+     *
27
+     * @since      3.5.4
28
+     */
29
+    public function __construct() {
30
+        parent::__construct();
31
+
32
+        // Hook to the `amp_post_template_css` to hide ourselves when in AMP
33
+        // rendering.
34
+        add_action(
35
+            'amp_post_template_css',
36
+            array(
37
+                $this,
38
+                'amp_post_template_css',
39
+            )
40
+        );
41
+        $this->register_block_type();
42
+
43
+    }
44
+
45
+    /**
46
+     * Render shordcode.
47
+     *
48
+     * @param array $atts shortcode attributes.
49
+     *
50
+     * @return string The HTML output.
51
+     */
52
+    public function render( $atts ) {
53
+
54
+        // extract attributes and set default values.
55
+        $chord_atts = shortcode_atts(
56
+            array(
57
+                'width'      => '100%',
58
+                'height'     => '500px',
59
+                'main_color' => '000',
60
+                'depth'      => 2,
61
+                'global'     => false,
62
+            ),
63
+            $atts
64
+        );
65
+
66
+        if ( $chord_atts['global'] ) {
67
+
68
+            $post_id = wl_shortcode_chord_most_referenced_entity_id();
69
+
70
+            if ( null === $post_id ) {
71
+                return 'WordLift Chord: no entities found.';
72
+            }
73
+
74
+            // Use the provided height if any, otherwise use a default of 200px.
75
+            //
76
+            // See https://github.com/insideout10/wordlift-plugin/issues/443.
77
+            $chord_atts['height'] = isset( $chord_atts['height'] ) ? $chord_atts['height'] : '200px';
78
+
79
+        } else {
80
+            $post_id = get_the_ID();
81
+        }
82
+
83
+        // Use the registered style which define an optional dependency to font-awesome.
84
+        //
85
+        // @see https://github.com/insideout10/wordlift-plugin/issues/699
86
+        // wp_enqueue_style( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' );
87
+        wp_enqueue_style( 'wordlift-ui' );
88
+
89
+        // Adding javascript code.
90
+        wp_enqueue_script( 'd3', dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/d3/d3.min.js', array(), WORDLIFT_VERSION, false );
91
+
92
+        $this->enqueue_scripts();
93
+
94
+        wp_localize_script(
95
+            'wordlift-ui',
96
+            'wl_chord_params',
97
+            array(
98
+                'ajax_url'       => admin_url( 'admin-ajax.php' ),
99
+                'action'         => 'wl_chord',
100
+                'wl_chord_nonce' => wp_create_nonce( 'wl_chord' ),
101
+            )
102
+        );
103
+
104
+        // Escaping atts.
105
+        $esc_class  = esc_attr( 'wl-chord' );
106
+        $esc_id     = esc_attr( uniqid( 'wl-chord-' ) );
107
+        $esc_width  = esc_attr( $chord_atts['width'] );
108
+        $esc_height = esc_attr( $chord_atts['height'] );
109
+
110
+        $esc_post_id    = esc_attr( $post_id );
111
+        $esc_depth      = esc_attr( $chord_atts['depth'] );
112
+        $esc_main_color = esc_attr( $chord_atts['main_color'] );
113
+
114
+        // Building template.
115
+        // TODO: in the HTML code there are static CSS rules. Move them to the CSS file.
116
+        return "
117 117
 <div class='$esc_class' 
118 118
 	id='$esc_id'
119 119
 	data-post-id='$esc_post_id'
@@ -126,82 +126,82 @@  discard block
 block discarded – undo
126 126
         margin-bottom:10px'>
127 127
 </div>
128 128
 ";
129
-	}
130
-
131
-	private function register_block_type() {
132
-
133
-		$scope = $this;
134
-
135
-		add_action(
136
-			'init',
137
-			function () use ( $scope ) {
138
-				if ( ! function_exists( 'register_block_type' ) ) {
139
-					// Gutenberg is not active.
140
-					return;
141
-				}
142
-
143
-				register_block_type(
144
-					'wordlift/chord',
145
-					array(
146
-						'editor_script'   => 'wl-block-editor',
147
-						'render_callback' => function ( $attributes ) use ( $scope ) {
148
-							$attr_code = '';
149
-							foreach ( $attributes as $key => $value ) {
150
-								$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
151
-							}
152
-
153
-							return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
154
-						},
155
-						'attributes'      => array(
156
-							'width'       => array(
157
-								'type'    => 'string',
158
-								'default' => '100%',
159
-							),
160
-							'height'      => array(
161
-								'type'    => 'string',
162
-								'default' => '500px',
163
-							),
164
-							'main_color'  => array(
165
-								'type'    => 'string',
166
-								'default' => '000',
167
-							),
168
-							'depth'       => array(
169
-								'type'    => 'number',
170
-								'default' => 2,
171
-							),
172
-							'global'      => array(
173
-								'type'    => 'boolean',
174
-								'default' => false,
175
-							),
176
-							'preview'     => array(
177
-								'type'    => 'boolean',
178
-								'default' => false,
179
-							),
180
-							'preview_src' => array(
181
-								'type'    => 'string',
182
-								'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/chord.png',
183
-							),
184
-						),
185
-					)
186
-				);
187
-			}
188
-		);
189
-	}
190
-
191
-	/**
192
-	 * Customize the CSS when in AMP.
193
-	 *
194
-	 * See https://github.com/Automattic/amp-wp/blob/master/readme.md#custom-css
195
-	 *
196
-	 * @since 3.14.0
197
-	 */
129
+    }
130
+
131
+    private function register_block_type() {
132
+
133
+        $scope = $this;
134
+
135
+        add_action(
136
+            'init',
137
+            function () use ( $scope ) {
138
+                if ( ! function_exists( 'register_block_type' ) ) {
139
+                    // Gutenberg is not active.
140
+                    return;
141
+                }
142
+
143
+                register_block_type(
144
+                    'wordlift/chord',
145
+                    array(
146
+                        'editor_script'   => 'wl-block-editor',
147
+                        'render_callback' => function ( $attributes ) use ( $scope ) {
148
+                            $attr_code = '';
149
+                            foreach ( $attributes as $key => $value ) {
150
+                                $attr_code .= $key . '="' . htmlentities( $value ) . '" ';
151
+                            }
152
+
153
+                            return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
154
+                        },
155
+                        'attributes'      => array(
156
+                            'width'       => array(
157
+                                'type'    => 'string',
158
+                                'default' => '100%',
159
+                            ),
160
+                            'height'      => array(
161
+                                'type'    => 'string',
162
+                                'default' => '500px',
163
+                            ),
164
+                            'main_color'  => array(
165
+                                'type'    => 'string',
166
+                                'default' => '000',
167
+                            ),
168
+                            'depth'       => array(
169
+                                'type'    => 'number',
170
+                                'default' => 2,
171
+                            ),
172
+                            'global'      => array(
173
+                                'type'    => 'boolean',
174
+                                'default' => false,
175
+                            ),
176
+                            'preview'     => array(
177
+                                'type'    => 'boolean',
178
+                                'default' => false,
179
+                            ),
180
+                            'preview_src' => array(
181
+                                'type'    => 'string',
182
+                                'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/chord.png',
183
+                            ),
184
+                        ),
185
+                    )
186
+                );
187
+            }
188
+        );
189
+    }
190
+
191
+    /**
192
+     * Customize the CSS when in AMP.
193
+     *
194
+     * See https://github.com/Automattic/amp-wp/blob/master/readme.md#custom-css
195
+     *
196
+     * @since 3.14.0
197
+     */
198 198
     // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
199
-	public function amp_post_template_css( $amp_template ) {
199
+    public function amp_post_template_css( $amp_template ) {
200 200
 
201
-		// Hide the `wl-chord` when in AMP.
202
-		?>
201
+        // Hide the `wl-chord` when in AMP.
202
+        ?>
203 203
 		.wl-chord { display: none; }
204 204
 		<?php
205
-	}
205
+    }
206 206
 
207 207
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	 *
50 50
 	 * @return string The HTML output.
51 51
 	 */
52
-	public function render( $atts ) {
52
+	public function render($atts) {
53 53
 
54 54
 		// extract attributes and set default values.
55 55
 		$chord_atts = shortcode_atts(
@@ -63,18 +63,18 @@  discard block
 block discarded – undo
63 63
 			$atts
64 64
 		);
65 65
 
66
-		if ( $chord_atts['global'] ) {
66
+		if ($chord_atts['global']) {
67 67
 
68 68
 			$post_id = wl_shortcode_chord_most_referenced_entity_id();
69 69
 
70
-			if ( null === $post_id ) {
70
+			if (null === $post_id) {
71 71
 				return 'WordLift Chord: no entities found.';
72 72
 			}
73 73
 
74 74
 			// Use the provided height if any, otherwise use a default of 200px.
75 75
 			//
76 76
 			// See https://github.com/insideout10/wordlift-plugin/issues/443.
77
-			$chord_atts['height'] = isset( $chord_atts['height'] ) ? $chord_atts['height'] : '200px';
77
+			$chord_atts['height'] = isset($chord_atts['height']) ? $chord_atts['height'] : '200px';
78 78
 
79 79
 		} else {
80 80
 			$post_id = get_the_ID();
@@ -84,10 +84,10 @@  discard block
 block discarded – undo
84 84
 		//
85 85
 		// @see https://github.com/insideout10/wordlift-plugin/issues/699
86 86
 		// wp_enqueue_style( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' );
87
-		wp_enqueue_style( 'wordlift-ui' );
87
+		wp_enqueue_style('wordlift-ui');
88 88
 
89 89
 		// Adding javascript code.
90
-		wp_enqueue_script( 'd3', dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/d3/d3.min.js', array(), WORDLIFT_VERSION, false );
90
+		wp_enqueue_script('d3', dirname(plugin_dir_url(__FILE__)).'/bower_components/d3/d3.min.js', array(), WORDLIFT_VERSION, false);
91 91
 
92 92
 		$this->enqueue_scripts();
93 93
 
@@ -95,21 +95,21 @@  discard block
 block discarded – undo
95 95
 			'wordlift-ui',
96 96
 			'wl_chord_params',
97 97
 			array(
98
-				'ajax_url'       => admin_url( 'admin-ajax.php' ),
98
+				'ajax_url'       => admin_url('admin-ajax.php'),
99 99
 				'action'         => 'wl_chord',
100
-				'wl_chord_nonce' => wp_create_nonce( 'wl_chord' ),
100
+				'wl_chord_nonce' => wp_create_nonce('wl_chord'),
101 101
 			)
102 102
 		);
103 103
 
104 104
 		// Escaping atts.
105
-		$esc_class  = esc_attr( 'wl-chord' );
106
-		$esc_id     = esc_attr( uniqid( 'wl-chord-' ) );
107
-		$esc_width  = esc_attr( $chord_atts['width'] );
108
-		$esc_height = esc_attr( $chord_atts['height'] );
105
+		$esc_class  = esc_attr('wl-chord');
106
+		$esc_id     = esc_attr(uniqid('wl-chord-'));
107
+		$esc_width  = esc_attr($chord_atts['width']);
108
+		$esc_height = esc_attr($chord_atts['height']);
109 109
 
110
-		$esc_post_id    = esc_attr( $post_id );
111
-		$esc_depth      = esc_attr( $chord_atts['depth'] );
112
-		$esc_main_color = esc_attr( $chord_atts['main_color'] );
110
+		$esc_post_id    = esc_attr($post_id);
111
+		$esc_depth      = esc_attr($chord_atts['depth']);
112
+		$esc_main_color = esc_attr($chord_atts['main_color']);
113 113
 
114 114
 		// Building template.
115 115
 		// TODO: in the HTML code there are static CSS rules. Move them to the CSS file.
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
 
135 135
 		add_action(
136 136
 			'init',
137
-			function () use ( $scope ) {
138
-				if ( ! function_exists( 'register_block_type' ) ) {
137
+			function() use ($scope) {
138
+				if ( ! function_exists('register_block_type')) {
139 139
 					// Gutenberg is not active.
140 140
 					return;
141 141
 				}
@@ -144,13 +144,13 @@  discard block
 block discarded – undo
144 144
 					'wordlift/chord',
145 145
 					array(
146 146
 						'editor_script'   => 'wl-block-editor',
147
-						'render_callback' => function ( $attributes ) use ( $scope ) {
147
+						'render_callback' => function($attributes) use ($scope) {
148 148
 							$attr_code = '';
149
-							foreach ( $attributes as $key => $value ) {
150
-								$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
149
+							foreach ($attributes as $key => $value) {
150
+								$attr_code .= $key.'="'.htmlentities($value).'" ';
151 151
 							}
152 152
 
153
-							return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
153
+							return '['.$scope::SHORTCODE.' '.$attr_code.']';
154 154
 						},
155 155
 						'attributes'      => array(
156 156
 							'width'       => array(
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 							),
180 180
 							'preview_src' => array(
181 181
 								'type'    => 'string',
182
-								'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/chord.png',
182
+								'default' => WP_CONTENT_URL.'/plugins/wordlift/images/block-previews/chord.png',
183 183
 							),
184 184
 						),
185 185
 					)
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	 * @since 3.14.0
197 197
 	 */
198 198
     // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
199
-	public function amp_post_template_css( $amp_template ) {
199
+	public function amp_post_template_css($amp_template) {
200 200
 
201 201
 		// Hide the `wl-chord` when in AMP.
202 202
 		?>
Please login to merge, or discard this patch.
src/public/class-wordlift-geomap-shortcode.php 2 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -18,157 +18,157 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Geomap_Shortcode extends Wordlift_Shortcode {
20 20
 
21
-	const SHORTCODE = 'wl_geomap';
22
-
23
-	/**
24
-	 * Create a {@link Wordlift_Geomap_Shortcode} instance.
25
-	 *
26
-	 * @since 3.5.4
27
-	 */
28
-	public function __construct() {
29
-		parent::__construct();
30
-
31
-		// Hook to the `amp_post_template_css` to hide ourselves when in AMP
32
-		// rendering.
33
-		add_action( 'amp_post_template_css', array( $this, 'amp_post_template_css' ) );
34
-		$this->register_block_type();
35
-
36
-	}
37
-
38
-	/**
39
-	 * Render the shortcode.
40
-	 *
41
-	 * @param array $atts An array of shortcode attributes as set by the editor.
42
-	 *
43
-	 * @return string The output html code.
44
-	 * @since 3.5.4
45
-	 */
46
-	public function render( $atts ) {
47
-
48
-		// Extract attributes and set default values.
49
-		$geomap_atts = shortcode_atts(
50
-			array(
51
-				'width'  => '100%',
52
-				'height' => '300px',
53
-				'global' => false,
54
-			),
55
-			$atts
56
-		);
57
-
58
-		// Get id of the post
59
-		$post_id = get_the_ID();
60
-
61
-		if ( $geomap_atts['global'] || $post_id === null ) {
62
-			// Global geomap
63
-			$geomap_id = 'wl_geomap_global';
64
-			$post_id   = null;
65
-		} else {
66
-			// Post-specific geomap
67
-			$geomap_id = 'wl_geomap_' . $post_id;
68
-		}
69
-
70
-		wl_enqueue_leaflet( true );
71
-
72
-		// Use the registered style which define an optional dependency to font-awesome.
73
-		//
74
-		// @see https://github.com/insideout10/wordlift-plugin/issues/699
75
-		// wp_enqueue_style( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' );
76
-		wp_enqueue_style( 'wordlift-ui' );
77
-
78
-		$this->enqueue_scripts();
79
-
80
-		wp_localize_script(
81
-			'wordlift-ui',
82
-			'wl_geomap_params',
83
-			array(
84
-				'ajax_url'        => admin_url( 'admin-ajax.php' ),    // Global param
85
-				'action'          => 'wl_geomap',            // Global param
86
-				'wl_geomap_nonce' => wp_create_nonce( 'wl_geomap' ),
87
-			)
88
-		);
89
-
90
-		// Escaping atts.
91
-		$esc_id      = esc_attr( $geomap_id );
92
-		$esc_width   = esc_attr( $geomap_atts['width'] );
93
-		$esc_height  = esc_attr( $geomap_atts['height'] );
94
-		$esc_post_id = esc_attr( $post_id );
95
-
96
-		// Return HTML template.
97
-		return "
21
+    const SHORTCODE = 'wl_geomap';
22
+
23
+    /**
24
+     * Create a {@link Wordlift_Geomap_Shortcode} instance.
25
+     *
26
+     * @since 3.5.4
27
+     */
28
+    public function __construct() {
29
+        parent::__construct();
30
+
31
+        // Hook to the `amp_post_template_css` to hide ourselves when in AMP
32
+        // rendering.
33
+        add_action( 'amp_post_template_css', array( $this, 'amp_post_template_css' ) );
34
+        $this->register_block_type();
35
+
36
+    }
37
+
38
+    /**
39
+     * Render the shortcode.
40
+     *
41
+     * @param array $atts An array of shortcode attributes as set by the editor.
42
+     *
43
+     * @return string The output html code.
44
+     * @since 3.5.4
45
+     */
46
+    public function render( $atts ) {
47
+
48
+        // Extract attributes and set default values.
49
+        $geomap_atts = shortcode_atts(
50
+            array(
51
+                'width'  => '100%',
52
+                'height' => '300px',
53
+                'global' => false,
54
+            ),
55
+            $atts
56
+        );
57
+
58
+        // Get id of the post
59
+        $post_id = get_the_ID();
60
+
61
+        if ( $geomap_atts['global'] || $post_id === null ) {
62
+            // Global geomap
63
+            $geomap_id = 'wl_geomap_global';
64
+            $post_id   = null;
65
+        } else {
66
+            // Post-specific geomap
67
+            $geomap_id = 'wl_geomap_' . $post_id;
68
+        }
69
+
70
+        wl_enqueue_leaflet( true );
71
+
72
+        // Use the registered style which define an optional dependency to font-awesome.
73
+        //
74
+        // @see https://github.com/insideout10/wordlift-plugin/issues/699
75
+        // wp_enqueue_style( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' );
76
+        wp_enqueue_style( 'wordlift-ui' );
77
+
78
+        $this->enqueue_scripts();
79
+
80
+        wp_localize_script(
81
+            'wordlift-ui',
82
+            'wl_geomap_params',
83
+            array(
84
+                'ajax_url'        => admin_url( 'admin-ajax.php' ),    // Global param
85
+                'action'          => 'wl_geomap',            // Global param
86
+                'wl_geomap_nonce' => wp_create_nonce( 'wl_geomap' ),
87
+            )
88
+        );
89
+
90
+        // Escaping atts.
91
+        $esc_id      = esc_attr( $geomap_id );
92
+        $esc_width   = esc_attr( $geomap_atts['width'] );
93
+        $esc_height  = esc_attr( $geomap_atts['height'] );
94
+        $esc_post_id = esc_attr( $post_id );
95
+
96
+        // Return HTML template.
97
+        return "
98 98
 <div class='wl-geomap'  id='$esc_id' data-post-id='$esc_post_id'
99 99
 	style='width:$esc_width; height:$esc_height; background-color: gray;'>
100 100
 </div>
101 101
 ";
102
-	}
103
-
104
-	private function register_block_type() {
105
-
106
-		$scope = $this;
107
-
108
-		add_action(
109
-			'init',
110
-			function () use ( $scope ) {
111
-				if ( ! function_exists( 'register_block_type' ) ) {
112
-					// Gutenberg is not active.
113
-					return;
114
-				}
115
-
116
-				register_block_type(
117
-					'wordlift/geomap',
118
-					array(
119
-						'editor_script'   => 'wl-block-editor',
120
-						'render_callback' => function ( $attributes ) use ( $scope ) {
121
-							$attr_code = '';
122
-							foreach ( $attributes as $key => $value ) {
123
-								$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
124
-							}
125
-
126
-							return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
127
-						},
128
-						'attributes'      => array(
129
-							'width'       => array(
130
-								'type'    => 'string',
131
-								'default' => '100%',
132
-							),
133
-							'height'      => array(
134
-								'type'    => 'string',
135
-								'default' => '300px',
136
-							),
137
-							'global'      => array(
138
-								'type'    => 'boolean',
139
-								'default' => false,
140
-							),
141
-							'preview'     => array(
142
-								'type'    => 'boolean',
143
-								'default' => false,
144
-							),
145
-							'preview_src' => array(
146
-								'type'    => 'string',
147
-								'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/geomap.png',
148
-							),
149
-						),
150
-					)
151
-				);
152
-			}
153
-		);
154
-	}
155
-
156
-	/**
157
-	 * Customize the CSS when in AMP.
158
-	 *
159
-	 * See https://github.com/Automattic/amp-wp/blob/master/readme.md#custom-css
160
-	 *
161
-	 * @param object $amp_template The template.
162
-	 *
163
-	 * @since 3.13.0
164
-	 */
102
+    }
103
+
104
+    private function register_block_type() {
105
+
106
+        $scope = $this;
107
+
108
+        add_action(
109
+            'init',
110
+            function () use ( $scope ) {
111
+                if ( ! function_exists( 'register_block_type' ) ) {
112
+                    // Gutenberg is not active.
113
+                    return;
114
+                }
115
+
116
+                register_block_type(
117
+                    'wordlift/geomap',
118
+                    array(
119
+                        'editor_script'   => 'wl-block-editor',
120
+                        'render_callback' => function ( $attributes ) use ( $scope ) {
121
+                            $attr_code = '';
122
+                            foreach ( $attributes as $key => $value ) {
123
+                                $attr_code .= $key . '="' . htmlentities( $value ) . '" ';
124
+                            }
125
+
126
+                            return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
127
+                        },
128
+                        'attributes'      => array(
129
+                            'width'       => array(
130
+                                'type'    => 'string',
131
+                                'default' => '100%',
132
+                            ),
133
+                            'height'      => array(
134
+                                'type'    => 'string',
135
+                                'default' => '300px',
136
+                            ),
137
+                            'global'      => array(
138
+                                'type'    => 'boolean',
139
+                                'default' => false,
140
+                            ),
141
+                            'preview'     => array(
142
+                                'type'    => 'boolean',
143
+                                'default' => false,
144
+                            ),
145
+                            'preview_src' => array(
146
+                                'type'    => 'string',
147
+                                'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/geomap.png',
148
+                            ),
149
+                        ),
150
+                    )
151
+                );
152
+            }
153
+        );
154
+    }
155
+
156
+    /**
157
+     * Customize the CSS when in AMP.
158
+     *
159
+     * See https://github.com/Automattic/amp-wp/blob/master/readme.md#custom-css
160
+     *
161
+     * @param object $amp_template The template.
162
+     *
163
+     * @since 3.13.0
164
+     */
165 165
     // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
166
-	public function amp_post_template_css( $amp_template ) {
166
+    public function amp_post_template_css( $amp_template ) {
167 167
 
168
-		// Hide the `wl-geomap` when in AMP.
169
-		?>
168
+        // Hide the `wl-geomap` when in AMP.
169
+        ?>
170 170
 		.wl-geomap { display: none; }
171 171
 		<?php
172
-	}
172
+    }
173 173
 
174 174
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
 		// Hook to the `amp_post_template_css` to hide ourselves when in AMP
32 32
 		// rendering.
33
-		add_action( 'amp_post_template_css', array( $this, 'amp_post_template_css' ) );
33
+		add_action('amp_post_template_css', array($this, 'amp_post_template_css'));
34 34
 		$this->register_block_type();
35 35
 
36 36
 	}
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 * @return string The output html code.
44 44
 	 * @since 3.5.4
45 45
 	 */
46
-	public function render( $atts ) {
46
+	public function render($atts) {
47 47
 
48 48
 		// Extract attributes and set default values.
49 49
 		$geomap_atts = shortcode_atts(
@@ -58,22 +58,22 @@  discard block
 block discarded – undo
58 58
 		// Get id of the post
59 59
 		$post_id = get_the_ID();
60 60
 
61
-		if ( $geomap_atts['global'] || $post_id === null ) {
61
+		if ($geomap_atts['global'] || $post_id === null) {
62 62
 			// Global geomap
63 63
 			$geomap_id = 'wl_geomap_global';
64 64
 			$post_id   = null;
65 65
 		} else {
66 66
 			// Post-specific geomap
67
-			$geomap_id = 'wl_geomap_' . $post_id;
67
+			$geomap_id = 'wl_geomap_'.$post_id;
68 68
 		}
69 69
 
70
-		wl_enqueue_leaflet( true );
70
+		wl_enqueue_leaflet(true);
71 71
 
72 72
 		// Use the registered style which define an optional dependency to font-awesome.
73 73
 		//
74 74
 		// @see https://github.com/insideout10/wordlift-plugin/issues/699
75 75
 		// wp_enqueue_style( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' );
76
-		wp_enqueue_style( 'wordlift-ui' );
76
+		wp_enqueue_style('wordlift-ui');
77 77
 
78 78
 		$this->enqueue_scripts();
79 79
 
@@ -81,17 +81,17 @@  discard block
 block discarded – undo
81 81
 			'wordlift-ui',
82 82
 			'wl_geomap_params',
83 83
 			array(
84
-				'ajax_url'        => admin_url( 'admin-ajax.php' ),    // Global param
85
-				'action'          => 'wl_geomap',            // Global param
86
-				'wl_geomap_nonce' => wp_create_nonce( 'wl_geomap' ),
84
+				'ajax_url'        => admin_url('admin-ajax.php'), // Global param
85
+				'action'          => 'wl_geomap', // Global param
86
+				'wl_geomap_nonce' => wp_create_nonce('wl_geomap'),
87 87
 			)
88 88
 		);
89 89
 
90 90
 		// Escaping atts.
91
-		$esc_id      = esc_attr( $geomap_id );
92
-		$esc_width   = esc_attr( $geomap_atts['width'] );
93
-		$esc_height  = esc_attr( $geomap_atts['height'] );
94
-		$esc_post_id = esc_attr( $post_id );
91
+		$esc_id      = esc_attr($geomap_id);
92
+		$esc_width   = esc_attr($geomap_atts['width']);
93
+		$esc_height  = esc_attr($geomap_atts['height']);
94
+		$esc_post_id = esc_attr($post_id);
95 95
 
96 96
 		// Return HTML template.
97 97
 		return "
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 
108 108
 		add_action(
109 109
 			'init',
110
-			function () use ( $scope ) {
111
-				if ( ! function_exists( 'register_block_type' ) ) {
110
+			function() use ($scope) {
111
+				if ( ! function_exists('register_block_type')) {
112 112
 					// Gutenberg is not active.
113 113
 					return;
114 114
 				}
@@ -117,13 +117,13 @@  discard block
 block discarded – undo
117 117
 					'wordlift/geomap',
118 118
 					array(
119 119
 						'editor_script'   => 'wl-block-editor',
120
-						'render_callback' => function ( $attributes ) use ( $scope ) {
120
+						'render_callback' => function($attributes) use ($scope) {
121 121
 							$attr_code = '';
122
-							foreach ( $attributes as $key => $value ) {
123
-								$attr_code .= $key . '="' . htmlentities( $value ) . '" ';
122
+							foreach ($attributes as $key => $value) {
123
+								$attr_code .= $key.'="'.htmlentities($value).'" ';
124 124
 							}
125 125
 
126
-							return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
126
+							return '['.$scope::SHORTCODE.' '.$attr_code.']';
127 127
 						},
128 128
 						'attributes'      => array(
129 129
 							'width'       => array(
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 							),
145 145
 							'preview_src' => array(
146 146
 								'type'    => 'string',
147
-								'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/geomap.png',
147
+								'default' => WP_CONTENT_URL.'/plugins/wordlift/images/block-previews/geomap.png',
148 148
 							),
149 149
 						),
150 150
 					)
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 	 * @since 3.13.0
164 164
 	 */
165 165
     // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
166
-	public function amp_post_template_css( $amp_template ) {
166
+	public function amp_post_template_css($amp_template) {
167 167
 
168 168
 		// Hide the `wl-geomap` when in AMP.
169 169
 		?>
Please login to merge, or discard this patch.
src/public/class-wordlift-seo-service.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -21,68 +21,68 @@
 block discarded – undo
21 21
  */
22 22
 class Wordlift_Seo_Service {
23 23
 
24
-	/**
25
-	 * @inheritdoc
26
-	 */
27
-	public function __construct() {
24
+    /**
25
+     * @inheritdoc
26
+     */
27
+    public function __construct() {
28 28
 
29
-		// If we are not on the admin, run the get_term filter for entity type terms.
30
-		add_filter(
31
-			'get_wl_entity_type',
32
-			array(
33
-				$this,
34
-				'get_wl_entity_type',
35
-			),
36
-			10
37
-		);
29
+        // If we are not on the admin, run the get_term filter for entity type terms.
30
+        add_filter(
31
+            'get_wl_entity_type',
32
+            array(
33
+                $this,
34
+                'get_wl_entity_type',
35
+            ),
36
+            10
37
+        );
38 38
 
39
-	}
39
+    }
40 40
 
41
-	/**
42
-	 * Filter the entity term object, and when not in admin context replace title
43
-	 * and description with whatever was set in the entity settings page.
44
-	 *
45
-	 * @param WP_Term $term The term to filters.
46
-	 *
47
-	 * @return WP_Term The {@link WP_Term} with fields changed.
48
-	 * @since    3.11
49
-	 */
50
-	public function get_wl_entity_type( $term ) {
41
+    /**
42
+     * Filter the entity term object, and when not in admin context replace title
43
+     * and description with whatever was set in the entity settings page.
44
+     *
45
+     * @param WP_Term $term The term to filters.
46
+     *
47
+     * @return WP_Term The {@link WP_Term} with fields changed.
48
+     * @since    3.11
49
+     */
50
+    public function get_wl_entity_type( $term ) {
51 51
 
52
-		// Do nothing when in admin.
53
-		if ( is_admin() ) {
54
-			return $term;
55
-		}
52
+        // Do nothing when in admin.
53
+        if ( is_admin() ) {
54
+            return $term;
55
+        }
56 56
 
57
-		// Get the terms' settings.
58
-		$entity_settings = get_option( 'wl_entity_type_settings', array() );
57
+        // Get the terms' settings.
58
+        $entity_settings = get_option( 'wl_entity_type_settings', array() );
59 59
 
60
-		// If we have no settings for the specified term, then return the original
61
-		// term.
62
-		if ( ! isset( $entity_settings[ $term->term_id ] ) ) {
60
+        // If we have no settings for the specified term, then return the original
61
+        // term.
62
+        if ( ! isset( $entity_settings[ $term->term_id ] ) ) {
63 63
 
64
-			return $term;
65
-		}
64
+            return $term;
65
+        }
66 66
 
67
-		// Get the settings for the specified term.
68
-		$settings = $entity_settings[ $term->term_id ];
67
+        // Get the settings for the specified term.
68
+        $settings = $entity_settings[ $term->term_id ];
69 69
 
70
-		// Update the name.
71
-		if ( ! empty( $settings['title'] ) ) {
70
+        // Update the name.
71
+        if ( ! empty( $settings['title'] ) ) {
72 72
 
73
-			$term->name = $settings['title'];
73
+            $term->name = $settings['title'];
74 74
 
75
-		}
75
+        }
76 76
 
77
-		// Update the description.
78
-		if ( ! empty( $settings['description'] ) ) {
77
+        // Update the description.
78
+        if ( ! empty( $settings['description'] ) ) {
79 79
 
80
-			$term->description = $settings['description'];
80
+            $term->description = $settings['description'];
81 81
 
82
-		}
82
+        }
83 83
 
84
-		// Return the updated term.
85
-		return $term;
86
-	}
84
+        // Return the updated term.
85
+        return $term;
86
+    }
87 87
 
88 88
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -47,35 +47,35 @@
 block discarded – undo
47 47
 	 * @return WP_Term The {@link WP_Term} with fields changed.
48 48
 	 * @since    3.11
49 49
 	 */
50
-	public function get_wl_entity_type( $term ) {
50
+	public function get_wl_entity_type($term) {
51 51
 
52 52
 		// Do nothing when in admin.
53
-		if ( is_admin() ) {
53
+		if (is_admin()) {
54 54
 			return $term;
55 55
 		}
56 56
 
57 57
 		// Get the terms' settings.
58
-		$entity_settings = get_option( 'wl_entity_type_settings', array() );
58
+		$entity_settings = get_option('wl_entity_type_settings', array());
59 59
 
60 60
 		// If we have no settings for the specified term, then return the original
61 61
 		// term.
62
-		if ( ! isset( $entity_settings[ $term->term_id ] ) ) {
62
+		if ( ! isset($entity_settings[$term->term_id])) {
63 63
 
64 64
 			return $term;
65 65
 		}
66 66
 
67 67
 		// Get the settings for the specified term.
68
-		$settings = $entity_settings[ $term->term_id ];
68
+		$settings = $entity_settings[$term->term_id];
69 69
 
70 70
 		// Update the name.
71
-		if ( ! empty( $settings['title'] ) ) {
71
+		if ( ! empty($settings['title'])) {
72 72
 
73 73
 			$term->name = $settings['title'];
74 74
 
75 75
 		}
76 76
 
77 77
 		// Update the description.
78
-		if ( ! empty( $settings['description'] ) ) {
78
+		if ( ! empty($settings['description'])) {
79 79
 
80 80
 			$term->description = $settings['description'];
81 81
 
Please login to merge, or discard this patch.
src/public/class-wordlift-timeline-shortcode.php 2 patches
Indentation   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -7,277 +7,277 @@
 block discarded – undo
7 7
  */
8 8
 class Wordlift_Timeline_Shortcode extends Wordlift_Shortcode {
9 9
 
10
-	const SHORTCODE = 'wl_timeline';
10
+    const SHORTCODE = 'wl_timeline';
11 11
 
12
-	/**
13
-	 * The list of locales supported by TimelineJS (correspond to the list of
14
-	 * files in the locale subfolder).
15
-	 *
16
-	 * @since 3.7.0
17
-	 * @var array An array of two-letters language codes.
18
-	 */
19
-	private static $supported_locales = array(
20
-		'ur',
21
-		'uk',
22
-		'tr',
23
-		'tl',
24
-		'th',
25
-		'te',
26
-		'ta',
27
-		'sv',
28
-		'sr',
29
-		'sl',
30
-		'sk',
31
-		'si',
32
-		'ru',
33
-		'ro',
34
-		'rm',
35
-		'pt',
36
-		'pl',
37
-		'no',
38
-		'nl',
39
-		'ne',
40
-		'ms',
41
-		'lv',
42
-		'lt',
43
-		'lb',
44
-		'ko',
45
-		'ka',
46
-		'ja',
47
-		'iw',
48
-		'it',
49
-		'is',
50
-		'id',
51
-		'hy',
52
-		'hu',
53
-		'hr',
54
-		'hi',
55
-		'he',
56
-		'gl',
57
-		'ga',
58
-		'fy',
59
-		'fr',
60
-		'fo',
61
-		'fi',
62
-		'fa',
63
-		'eu',
64
-		'et',
65
-		'es',
66
-		'eo',
67
-		'en',
68
-		'el',
69
-		'de',
70
-		'da',
71
-		'cz',
72
-		'ca',
73
-		'bg',
74
-		'be',
75
-		'ar',
76
-		'af',
77
-	);
12
+    /**
13
+     * The list of locales supported by TimelineJS (correspond to the list of
14
+     * files in the locale subfolder).
15
+     *
16
+     * @since 3.7.0
17
+     * @var array An array of two-letters language codes.
18
+     */
19
+    private static $supported_locales = array(
20
+        'ur',
21
+        'uk',
22
+        'tr',
23
+        'tl',
24
+        'th',
25
+        'te',
26
+        'ta',
27
+        'sv',
28
+        'sr',
29
+        'sl',
30
+        'sk',
31
+        'si',
32
+        'ru',
33
+        'ro',
34
+        'rm',
35
+        'pt',
36
+        'pl',
37
+        'no',
38
+        'nl',
39
+        'ne',
40
+        'ms',
41
+        'lv',
42
+        'lt',
43
+        'lb',
44
+        'ko',
45
+        'ka',
46
+        'ja',
47
+        'iw',
48
+        'it',
49
+        'is',
50
+        'id',
51
+        'hy',
52
+        'hu',
53
+        'hr',
54
+        'hi',
55
+        'he',
56
+        'gl',
57
+        'ga',
58
+        'fy',
59
+        'fr',
60
+        'fo',
61
+        'fi',
62
+        'fa',
63
+        'eu',
64
+        'et',
65
+        'es',
66
+        'eo',
67
+        'en',
68
+        'el',
69
+        'de',
70
+        'da',
71
+        'cz',
72
+        'ca',
73
+        'bg',
74
+        'be',
75
+        'ar',
76
+        'af',
77
+    );
78 78
 
79
-	/**
80
-	 * The Log service.
81
-	 *
82
-	 * @since 3.1.0
83
-	 * @access private
84
-	 * @var \Wordlift_Log_Service $log_service The Log service.
85
-	 */
86
-	private $log_service;
79
+    /**
80
+     * The Log service.
81
+     *
82
+     * @since 3.1.0
83
+     * @access private
84
+     * @var \Wordlift_Log_Service $log_service The Log service.
85
+     */
86
+    private $log_service;
87 87
 
88
-	/**
89
-	 * Create a Wordlift_Timeline_Shortcode instance.
90
-	 *
91
-	 * @since 3.1.0
92
-	 */
93
-	public function __construct() {
94
-		parent::__construct();
88
+    /**
89
+     * Create a Wordlift_Timeline_Shortcode instance.
90
+     *
91
+     * @since 3.1.0
92
+     */
93
+    public function __construct() {
94
+        parent::__construct();
95 95
 
96
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Timeline_Shortcode' );
96
+        $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Timeline_Shortcode' );
97 97
 
98
-		$this->register_block_type();
98
+        $this->register_block_type();
99 99
 
100
-	}
100
+    }
101 101
 
102
-	public function get_timelinejs_default_options() {
103
-		return array(
104
-			'debug'                            => defined( 'WP_DEBUG' ) && WP_DEBUG,
105
-			'height'                           => null,
106
-			'width'                            => null,
107
-			'is_embed'                         => false,
108
-			'hash_bookmark'                    => false,
109
-			'default_bg_color'                 => 'white',
110
-			'scale_factor'                     => 2,
111
-			'initial_zoom'                     => null,
112
-			'zoom_sequence'                    => '[0.5, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]',
113
-			'timenav_position'                 => 'bottom',
114
-			'optimal_tick_width'               => 100,
115
-			'base_class'                       => 'tl-timeline',
116
-			'timenav_height'                   => 150,
117
-			'timenav_height_percentage'        => null,
118
-			'timenav_mobile_height_percentage' => 40,
119
-			'timenav_height_min'               => 150,
120
-			'marker_height_min'                => 30,
121
-			'marker_width_min'                 => 100,
122
-			'start_at_slide'                   => 0,
123
-			'start_at_end'                     => false,
124
-			'menubar_height'                   => 0,
125
-			'use_bc'                           => false,
126
-			'duration'                         => 1000,
127
-			'ease'                             => 'TL.Ease.easeInOutQuint',
128
-			'slide_default_fade'               => '0%',
129
-			'language'                         => $this->get_locale(),
130
-			'ga_property_id'                   => null,
131
-			'track_events'                     => "['back_to_start','nav_next','nav_previous','zoom_in','zoom_out']",
132
-		);
133
-	}
102
+    public function get_timelinejs_default_options() {
103
+        return array(
104
+            'debug'                            => defined( 'WP_DEBUG' ) && WP_DEBUG,
105
+            'height'                           => null,
106
+            'width'                            => null,
107
+            'is_embed'                         => false,
108
+            'hash_bookmark'                    => false,
109
+            'default_bg_color'                 => 'white',
110
+            'scale_factor'                     => 2,
111
+            'initial_zoom'                     => null,
112
+            'zoom_sequence'                    => '[0.5, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]',
113
+            'timenav_position'                 => 'bottom',
114
+            'optimal_tick_width'               => 100,
115
+            'base_class'                       => 'tl-timeline',
116
+            'timenav_height'                   => 150,
117
+            'timenav_height_percentage'        => null,
118
+            'timenav_mobile_height_percentage' => 40,
119
+            'timenav_height_min'               => 150,
120
+            'marker_height_min'                => 30,
121
+            'marker_width_min'                 => 100,
122
+            'start_at_slide'                   => 0,
123
+            'start_at_end'                     => false,
124
+            'menubar_height'                   => 0,
125
+            'use_bc'                           => false,
126
+            'duration'                         => 1000,
127
+            'ease'                             => 'TL.Ease.easeInOutQuint',
128
+            'slide_default_fade'               => '0%',
129
+            'language'                         => $this->get_locale(),
130
+            'ga_property_id'                   => null,
131
+            'track_events'                     => "['back_to_start','nav_next','nav_previous','zoom_in','zoom_out']",
132
+        );
133
+    }
134 134
 
135
-	/**
136
-	 * Renders the Timeline.
137
-	 *
138
-	 * @param array $atts An array of shortcode attributes.
139
-	 *
140
-	 * @return string The rendered HTML.
141
-	 * @since 3.1.0
142
-	 */
143
-	public function render( $atts ) {
135
+    /**
136
+     * Renders the Timeline.
137
+     *
138
+     * @param array $atts An array of shortcode attributes.
139
+     *
140
+     * @return string The rendered HTML.
141
+     * @since 3.1.0
142
+     */
143
+    public function render( $atts ) {
144 144
 
145
-		// extract attributes and set default values
146
-		$settings = shortcode_atts(
147
-			array_merge(
148
-				$this->get_timelinejs_default_options(),
149
-				array(
150
-					'global'            => false,
151
-					'display_images_as' => 'media',
152
-					'excerpt_length'    => 55,
153
-				)
154
-			),
155
-			$atts
156
-		);
145
+        // extract attributes and set default values
146
+        $settings = shortcode_atts(
147
+            array_merge(
148
+                $this->get_timelinejs_default_options(),
149
+                array(
150
+                    'global'            => false,
151
+                    'display_images_as' => 'media',
152
+                    'excerpt_length'    => 55,
153
+                )
154
+            ),
155
+            $atts
156
+        );
157 157
 
158
-		// Load the TimelineJS stylesheets and scripts.
159
-		wp_enqueue_style( 'timelinejs', dirname( plugin_dir_url( __FILE__ ) ) . '/timelinejs/css/timeline.css', array(), WORDLIFT_VERSION );
160
-		wp_enqueue_script( 'timelinejs', dirname( plugin_dir_url( __FILE__ ) ) . '/timelinejs/js/timeline' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '-min' : '' ) . '.js', array(), WORDLIFT_VERSION, false );
158
+        // Load the TimelineJS stylesheets and scripts.
159
+        wp_enqueue_style( 'timelinejs', dirname( plugin_dir_url( __FILE__ ) ) . '/timelinejs/css/timeline.css', array(), WORDLIFT_VERSION );
160
+        wp_enqueue_script( 'timelinejs', dirname( plugin_dir_url( __FILE__ ) ) . '/timelinejs/js/timeline' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '-min' : '' ) . '.js', array(), WORDLIFT_VERSION, false );
161 161
 
162
-		// Enqueue the scripts for the timeline.
163
-		$this->enqueue_scripts();
162
+        // Enqueue the scripts for the timeline.
163
+        $this->enqueue_scripts();
164 164
 
165
-		// Provide the script with options.
166
-		wp_localize_script(
167
-			'timelinejs',
168
-			'wl_timeline_params',
169
-			array(
170
-				'ajax_url'          => admin_url( 'admin-ajax.php' ),
171
-				// TODO: this parameter is already provided by WP
172
-				'action'            => 'wl_timeline',
173
-				'wl_timeline_nonce' => wp_create_nonce( 'wl_timeline' ),
174
-				// These settings apply to our wl_timeline AJAX endpoint.
175
-				'display_images_as' => $settings['display_images_as'],
176
-				'excerpt_length'    => $settings['excerpt_length'],
177
-				// These settings apply to the timeline javascript client.
178
-				'settings'          => array_filter(
179
-					$settings,
180
-					function ( $value ) {
181
-						// Do not set NULL values.
182
-						return ( null !== $value );
183
-					}
184
-				),
185
-			)
186
-		);
165
+        // Provide the script with options.
166
+        wp_localize_script(
167
+            'timelinejs',
168
+            'wl_timeline_params',
169
+            array(
170
+                'ajax_url'          => admin_url( 'admin-ajax.php' ),
171
+                // TODO: this parameter is already provided by WP
172
+                'action'            => 'wl_timeline',
173
+                'wl_timeline_nonce' => wp_create_nonce( 'wl_timeline' ),
174
+                // These settings apply to our wl_timeline AJAX endpoint.
175
+                'display_images_as' => $settings['display_images_as'],
176
+                'excerpt_length'    => $settings['excerpt_length'],
177
+                // These settings apply to the timeline javascript client.
178
+                'settings'          => array_filter(
179
+                    $settings,
180
+                    function ( $value ) {
181
+                        // Do not set NULL values.
182
+                        return ( null !== $value );
183
+                    }
184
+                ),
185
+            )
186
+        );
187 187
 
188
-		// Get the current post id or set null if global is set to true.
189
-		$post_id = ( $settings['global'] ? null : get_the_ID() );
188
+        // Get the current post id or set null if global is set to true.
189
+        $post_id = ( $settings['global'] ? null : get_the_ID() );
190 190
 
191
-		// Escaping atts.
192
-		$style        = sprintf( 'style="%s%s"', isset( $settings['width'] ) ? "width:{$settings['width']};" : '', isset( $settings['height'] ) ? "height:{$settings['height']};" : '' );
193
-		$data_post_id = ( isset( $post_id ) ? "data-post-id='$post_id'" : '' );
191
+        // Escaping atts.
192
+        $style        = sprintf( 'style="%s%s"', isset( $settings['width'] ) ? "width:{$settings['width']};" : '', isset( $settings['height'] ) ? "height:{$settings['height']};" : '' );
193
+        $data_post_id = ( isset( $post_id ) ? "data-post-id='$post_id'" : '' );
194 194
 
195
-		// Generate a unique ID for this timeline.
196
-		$element_id = uniqid( 'wl-timeline-' );
195
+        // Generate a unique ID for this timeline.
196
+        $element_id = uniqid( 'wl-timeline-' );
197 197
 
198
-		if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
199
-			$this->log_service->trace( "Creating a timeline widget [ element id :: $element_id ][ post id :: $post_id ]" );
200
-		}
198
+        if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
199
+            $this->log_service->trace( "Creating a timeline widget [ element id :: $element_id ][ post id :: $post_id ]" );
200
+        }
201 201
 
202
-		// Building template.
203
-		return sprintf( '<div class="wl-timeline-container" %s><div class="wl-timeline" id="%s" %s></div></div>', $style, $element_id, $data_post_id );
204
-	}
202
+        // Building template.
203
+        return sprintf( '<div class="wl-timeline-container" %s><div class="wl-timeline" id="%s" %s></div></div>', $style, $element_id, $data_post_id );
204
+    }
205 205
 
206
-	private function register_block_type() {
206
+    private function register_block_type() {
207 207
 
208
-		$scope = $this;
208
+        $scope = $this;
209 209
 
210
-		add_action(
211
-			'init',
212
-			function () use ( $scope ) {
213
-				if ( ! function_exists( 'register_block_type' ) ) {
214
-					// Gutenberg is not active.
215
-					return;
216
-				}
210
+        add_action(
211
+            'init',
212
+            function () use ( $scope ) {
213
+                if ( ! function_exists( 'register_block_type' ) ) {
214
+                    // Gutenberg is not active.
215
+                    return;
216
+                }
217 217
 
218
-				register_block_type(
219
-					'wordlift/timeline',
220
-					array(
221
-						'editor_script'   => 'wl-block-editor',
222
-						'render_callback' => function ( $attributes ) use ( $scope ) {
223
-							$attr_code          = '';
224
-							$timelinejs_options = json_decode( $attributes['timelinejs_options'], true );
225
-							unset( $attributes['timelinejs_options'] );
226
-							$attributes_all = array_merge( $attributes, $timelinejs_options );
227
-							foreach ( $attributes_all as $key => $value ) {
228
-								if ( $value && strpos( $value, '[' ) === false && strpos( $value, ']' ) === false ) {
229
-									$attr_code .= $key . '="' . $value . '" ';
230
-								}
231
-							}
218
+                register_block_type(
219
+                    'wordlift/timeline',
220
+                    array(
221
+                        'editor_script'   => 'wl-block-editor',
222
+                        'render_callback' => function ( $attributes ) use ( $scope ) {
223
+                            $attr_code          = '';
224
+                            $timelinejs_options = json_decode( $attributes['timelinejs_options'], true );
225
+                            unset( $attributes['timelinejs_options'] );
226
+                            $attributes_all = array_merge( $attributes, $timelinejs_options );
227
+                            foreach ( $attributes_all as $key => $value ) {
228
+                                if ( $value && strpos( $value, '[' ) === false && strpos( $value, ']' ) === false ) {
229
+                                    $attr_code .= $key . '="' . $value . '" ';
230
+                                }
231
+                            }
232 232
 
233
-							return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
234
-						},
235
-						'attributes'      => array(
236
-							'display_images_as'  => array(
237
-								'type'    => 'string',
238
-								'default' => 'media',
239
-							),
240
-							'excerpt_length'     => array(
241
-								'type'    => 'number',
242
-								'default' => 55,
243
-							),
244
-							'global'             => array(
245
-								'type'    => 'bool',
246
-								'default' => false,
247
-							),
248
-							'timelinejs_options' => array(
249
-								'type'    => 'string', // https://timeline.knightlab.com/docs/options.html
250
-								'default' => wp_json_encode( $scope->get_timelinejs_default_options(), JSON_PRETTY_PRINT ),
251
-							),
252
-							'preview'            => array(
253
-								'type'    => 'boolean',
254
-								'default' => false,
255
-							),
256
-							'preview_src'        => array(
257
-								'type'    => 'string',
258
-								'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/timeline.png',
259
-							),
260
-						),
261
-					)
262
-				);
263
-			}
264
-		);
265
-	}
233
+                            return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
234
+                        },
235
+                        'attributes'      => array(
236
+                            'display_images_as'  => array(
237
+                                'type'    => 'string',
238
+                                'default' => 'media',
239
+                            ),
240
+                            'excerpt_length'     => array(
241
+                                'type'    => 'number',
242
+                                'default' => 55,
243
+                            ),
244
+                            'global'             => array(
245
+                                'type'    => 'bool',
246
+                                'default' => false,
247
+                            ),
248
+                            'timelinejs_options' => array(
249
+                                'type'    => 'string', // https://timeline.knightlab.com/docs/options.html
250
+                                'default' => wp_json_encode( $scope->get_timelinejs_default_options(), JSON_PRETTY_PRINT ),
251
+                            ),
252
+                            'preview'            => array(
253
+                                'type'    => 'boolean',
254
+                                'default' => false,
255
+                            ),
256
+                            'preview_src'        => array(
257
+                                'type'    => 'string',
258
+                                'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/timeline.png',
259
+                            ),
260
+                        ),
261
+                    )
262
+                );
263
+            }
264
+        );
265
+    }
266 266
 
267
-	/**
268
-	 * Return the locale for the TimelineJS according to WP's configured locale and
269
-	 * support TimelineJS locales. If WP's locale is not supported, english is used.
270
-	 *
271
-	 * @return string The locale (2 letters code).
272
-	 * @since 3.7.0
273
-	 */
274
-	private function get_locale() {
267
+    /**
268
+     * Return the locale for the TimelineJS according to WP's configured locale and
269
+     * support TimelineJS locales. If WP's locale is not supported, english is used.
270
+     *
271
+     * @return string The locale (2 letters code).
272
+     * @since 3.7.0
273
+     */
274
+    private function get_locale() {
275 275
 
276
-		// Get the first 2 letters.
277
-		$locale = substr( get_locale(), 0, 2 );
276
+        // Get the first 2 letters.
277
+        $locale = substr( get_locale(), 0, 2 );
278 278
 
279
-		// Check that the specified locale is supported otherwise use English.
280
-		return in_array( $locale, self::$supported_locales, true ) ? $locale : 'en';
281
-	}
279
+        // Check that the specified locale is supported otherwise use English.
280
+        return in_array( $locale, self::$supported_locales, true ) ? $locale : 'en';
281
+    }
282 282
 
283 283
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	public function __construct() {
94 94
 		parent::__construct();
95 95
 
96
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Timeline_Shortcode' );
96
+		$this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Timeline_Shortcode');
97 97
 
98 98
 		$this->register_block_type();
99 99
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 
102 102
 	public function get_timelinejs_default_options() {
103 103
 		return array(
104
-			'debug'                            => defined( 'WP_DEBUG' ) && WP_DEBUG,
104
+			'debug'                            => defined('WP_DEBUG') && WP_DEBUG,
105 105
 			'height'                           => null,
106 106
 			'width'                            => null,
107 107
 			'is_embed'                         => false,
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	 * @return string The rendered HTML.
141 141
 	 * @since 3.1.0
142 142
 	 */
143
-	public function render( $atts ) {
143
+	public function render($atts) {
144 144
 
145 145
 		// extract attributes and set default values
146 146
 		$settings = shortcode_atts(
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
 		);
157 157
 
158 158
 		// Load the TimelineJS stylesheets and scripts.
159
-		wp_enqueue_style( 'timelinejs', dirname( plugin_dir_url( __FILE__ ) ) . '/timelinejs/css/timeline.css', array(), WORDLIFT_VERSION );
160
-		wp_enqueue_script( 'timelinejs', dirname( plugin_dir_url( __FILE__ ) ) . '/timelinejs/js/timeline' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '-min' : '' ) . '.js', array(), WORDLIFT_VERSION, false );
159
+		wp_enqueue_style('timelinejs', dirname(plugin_dir_url(__FILE__)).'/timelinejs/css/timeline.css', array(), WORDLIFT_VERSION);
160
+		wp_enqueue_script('timelinejs', dirname(plugin_dir_url(__FILE__)).'/timelinejs/js/timeline'.( ! defined('SCRIPT_DEBUG') || ! SCRIPT_DEBUG ? '-min' : '').'.js', array(), WORDLIFT_VERSION, false);
161 161
 
162 162
 		// Enqueue the scripts for the timeline.
163 163
 		$this->enqueue_scripts();
@@ -167,40 +167,40 @@  discard block
 block discarded – undo
167 167
 			'timelinejs',
168 168
 			'wl_timeline_params',
169 169
 			array(
170
-				'ajax_url'          => admin_url( 'admin-ajax.php' ),
170
+				'ajax_url'          => admin_url('admin-ajax.php'),
171 171
 				// TODO: this parameter is already provided by WP
172 172
 				'action'            => 'wl_timeline',
173
-				'wl_timeline_nonce' => wp_create_nonce( 'wl_timeline' ),
173
+				'wl_timeline_nonce' => wp_create_nonce('wl_timeline'),
174 174
 				// These settings apply to our wl_timeline AJAX endpoint.
175 175
 				'display_images_as' => $settings['display_images_as'],
176 176
 				'excerpt_length'    => $settings['excerpt_length'],
177 177
 				// These settings apply to the timeline javascript client.
178 178
 				'settings'          => array_filter(
179 179
 					$settings,
180
-					function ( $value ) {
180
+					function($value) {
181 181
 						// Do not set NULL values.
182
-						return ( null !== $value );
182
+						return (null !== $value);
183 183
 					}
184 184
 				),
185 185
 			)
186 186
 		);
187 187
 
188 188
 		// Get the current post id or set null if global is set to true.
189
-		$post_id = ( $settings['global'] ? null : get_the_ID() );
189
+		$post_id = ($settings['global'] ? null : get_the_ID());
190 190
 
191 191
 		// Escaping atts.
192
-		$style        = sprintf( 'style="%s%s"', isset( $settings['width'] ) ? "width:{$settings['width']};" : '', isset( $settings['height'] ) ? "height:{$settings['height']};" : '' );
193
-		$data_post_id = ( isset( $post_id ) ? "data-post-id='$post_id'" : '' );
192
+		$style        = sprintf('style="%s%s"', isset($settings['width']) ? "width:{$settings['width']};" : '', isset($settings['height']) ? "height:{$settings['height']};" : '');
193
+		$data_post_id = (isset($post_id) ? "data-post-id='$post_id'" : '');
194 194
 
195 195
 		// Generate a unique ID for this timeline.
196
-		$element_id = uniqid( 'wl-timeline-' );
196
+		$element_id = uniqid('wl-timeline-');
197 197
 
198
-		if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
199
-			$this->log_service->trace( "Creating a timeline widget [ element id :: $element_id ][ post id :: $post_id ]" );
198
+		if (defined('WP_DEBUG') && WP_DEBUG) {
199
+			$this->log_service->trace("Creating a timeline widget [ element id :: $element_id ][ post id :: $post_id ]");
200 200
 		}
201 201
 
202 202
 		// Building template.
203
-		return sprintf( '<div class="wl-timeline-container" %s><div class="wl-timeline" id="%s" %s></div></div>', $style, $element_id, $data_post_id );
203
+		return sprintf('<div class="wl-timeline-container" %s><div class="wl-timeline" id="%s" %s></div></div>', $style, $element_id, $data_post_id);
204 204
 	}
205 205
 
206 206
 	private function register_block_type() {
@@ -209,8 +209,8 @@  discard block
 block discarded – undo
209 209
 
210 210
 		add_action(
211 211
 			'init',
212
-			function () use ( $scope ) {
213
-				if ( ! function_exists( 'register_block_type' ) ) {
212
+			function() use ($scope) {
213
+				if ( ! function_exists('register_block_type')) {
214 214
 					// Gutenberg is not active.
215 215
 					return;
216 216
 				}
@@ -219,18 +219,18 @@  discard block
 block discarded – undo
219 219
 					'wordlift/timeline',
220 220
 					array(
221 221
 						'editor_script'   => 'wl-block-editor',
222
-						'render_callback' => function ( $attributes ) use ( $scope ) {
222
+						'render_callback' => function($attributes) use ($scope) {
223 223
 							$attr_code          = '';
224
-							$timelinejs_options = json_decode( $attributes['timelinejs_options'], true );
225
-							unset( $attributes['timelinejs_options'] );
226
-							$attributes_all = array_merge( $attributes, $timelinejs_options );
227
-							foreach ( $attributes_all as $key => $value ) {
228
-								if ( $value && strpos( $value, '[' ) === false && strpos( $value, ']' ) === false ) {
229
-									$attr_code .= $key . '="' . $value . '" ';
224
+							$timelinejs_options = json_decode($attributes['timelinejs_options'], true);
225
+							unset($attributes['timelinejs_options']);
226
+							$attributes_all = array_merge($attributes, $timelinejs_options);
227
+							foreach ($attributes_all as $key => $value) {
228
+								if ($value && strpos($value, '[') === false && strpos($value, ']') === false) {
229
+									$attr_code .= $key.'="'.$value.'" ';
230 230
 								}
231 231
 							}
232 232
 
233
-							return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']';
233
+							return '['.$scope::SHORTCODE.' '.$attr_code.']';
234 234
 						},
235 235
 						'attributes'      => array(
236 236
 							'display_images_as'  => array(
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 							),
248 248
 							'timelinejs_options' => array(
249 249
 								'type'    => 'string', // https://timeline.knightlab.com/docs/options.html
250
-								'default' => wp_json_encode( $scope->get_timelinejs_default_options(), JSON_PRETTY_PRINT ),
250
+								'default' => wp_json_encode($scope->get_timelinejs_default_options(), JSON_PRETTY_PRINT),
251 251
 							),
252 252
 							'preview'            => array(
253 253
 								'type'    => 'boolean',
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 							),
256 256
 							'preview_src'        => array(
257 257
 								'type'    => 'string',
258
-								'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/timeline.png',
258
+								'default' => WP_CONTENT_URL.'/plugins/wordlift/images/block-previews/timeline.png',
259 259
 							),
260 260
 						),
261 261
 					)
@@ -274,10 +274,10 @@  discard block
 block discarded – undo
274 274
 	private function get_locale() {
275 275
 
276 276
 		// Get the first 2 letters.
277
-		$locale = substr( get_locale(), 0, 2 );
277
+		$locale = substr(get_locale(), 0, 2);
278 278
 
279 279
 		// Check that the specified locale is supported otherwise use English.
280
-		return in_array( $locale, self::$supported_locales, true ) ? $locale : 'en';
280
+		return in_array($locale, self::$supported_locales, true) ? $locale : 'en';
281 281
 	}
282 282
 
283 283
 }
Please login to merge, or discard this patch.
src/uninstall.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 // If uninstall not called from WordPress, then exit.
29 29
 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
30
-	exit;
30
+    exit;
31 31
 }
32 32
 
33 33
 // Get a reference to WP and the Wordlift plugin
@@ -40,10 +40,10 @@  discard block
 block discarded – undo
40 40
 
41 41
 // Do a db search for posts of type entity
42 42
 $args           = array(
43
-	'posts_per_page' => - 1,
44
-	'post_type'      => Wordlift_Entity_Service::TYPE_NAME,
45
-	'post_status'    => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ),
46
-	'fields'         => 'ids',
43
+    'posts_per_page' => - 1,
44
+    'post_type'      => Wordlift_Entity_Service::TYPE_NAME,
45
+    'post_status'    => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ),
46
+    'fields'         => 'ids',
47 47
 );
48 48
 $entities_array = get_posts( $args );
49 49
 
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 wl_write_log( 'Deleting entities and their meta... ' );
53 53
 wl_write_log( $entities_array );
54 54
 foreach ( $entities_array as $entity_id ) {
55
-	// Delete the whole entity and its metas.
56
-	wp_delete_post( $entity_id, true );
55
+    // Delete the whole entity and its metas.
56
+    wp_delete_post( $entity_id, true );
57 57
 }
58 58
 wl_write_log( 'Done.' );
59 59
 
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 // We loop over terms in this rude way because in the uninstall script
74 74
 // is not possible to call WP custom taxonomy functions.
75 75
 foreach ( range( 0, 100 ) as $index ) {
76
-	delete_option( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME . '_' . $index );
77
-	wp_delete_term( $index, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
76
+    delete_option( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME . '_' . $index );
77
+    wp_delete_term( $index, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
78 78
 }
79 79
 delete_option( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME . '_children' );  // it's a hierarchical taxonomy
80 80
 wl_write_log( 'Done.' );
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  */
27 27
 
28 28
 // If uninstall not called from WordPress, then exit.
29
-if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
29
+if ( ! defined('WP_UNINSTALL_PLUGIN')) {
30 30
 	exit;
31 31
 }
32 32
 
@@ -39,52 +39,52 @@  discard block
 block discarded – undo
39 39
  */
40 40
 
41 41
 // Do a db search for posts of type entity
42
-$args           = array(
43
-	'posts_per_page' => - 1,
42
+$args = array(
43
+	'posts_per_page' => -1,
44 44
 	'post_type'      => Wordlift_Entity_Service::TYPE_NAME,
45
-	'post_status'    => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ),
45
+	'post_status'    => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash'),
46 46
 	'fields'         => 'ids',
47 47
 );
48
-$entities_array = get_posts( $args );
48
+$entities_array = get_posts($args);
49 49
 
50 50
 // Loop over entities and delete them.
51 51
 // TODO: thumbnails?
52
-wl_write_log( 'Deleting entities and their meta... ' );
53
-wl_write_log( $entities_array );
54
-foreach ( $entities_array as $entity_id ) {
52
+wl_write_log('Deleting entities and their meta... ');
53
+wl_write_log($entities_array);
54
+foreach ($entities_array as $entity_id) {
55 55
 	// Delete the whole entity and its metas.
56
-	wp_delete_post( $entity_id, true );
56
+	wp_delete_post($entity_id, true);
57 57
 }
58
-wl_write_log( 'Done.' );
58
+wl_write_log('Done.');
59 59
 
60 60
 /*
61 61
  * Delete post-entity relationships
62 62
  */
63
-wl_write_log( 'Deleting post-entity relationships... ' );
64
-$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wl_relation_instances" );
65
-delete_option( 'wl_db_version' );
66
-wl_write_log( 'Done.' );
63
+wl_write_log('Deleting post-entity relationships... ');
64
+$wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}wl_relation_instances");
65
+delete_option('wl_db_version');
66
+wl_write_log('Done.');
67 67
 
68 68
 /*
69 69
  * Delete taxonomy
70 70
  */
71
-wl_write_log( 'Cleaning entities taxonomy... ' );
71
+wl_write_log('Cleaning entities taxonomy... ');
72 72
 // Delte custom taxonomy terms.
73 73
 // We loop over terms in this rude way because in the uninstall script
74 74
 // is not possible to call WP custom taxonomy functions.
75
-foreach ( range( 0, 100 ) as $index ) {
76
-	delete_option( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME . '_' . $index );
77
-	wp_delete_term( $index, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
75
+foreach (range(0, 100) as $index) {
76
+	delete_option(Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME.'_'.$index);
77
+	wp_delete_term($index, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
78 78
 }
79
-delete_option( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME . '_children' );  // it's a hierarchical taxonomy
80
-wl_write_log( 'Done.' );
79
+delete_option(Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME.'_children'); // it's a hierarchical taxonomy
80
+wl_write_log('Done.');
81 81
 
82 82
 /**
83 83
  * Delete options
84 84
  */
85
-wl_write_log( 'Cleaning WordLift options... ' );
85
+wl_write_log('Cleaning WordLift options... ');
86 86
 // delete_option( WL_OPTIONS_NAME );
87
-delete_option( 'wl_option_prefixes' );
88
-delete_option( 'wl_general_settings' );
89
-delete_option( 'wl_advanced_settings' );
90
-wl_write_log( 'Done. WordLift successfully uninstalled.' );
87
+delete_option('wl_option_prefixes');
88
+delete_option('wl_general_settings');
89
+delete_option('wl_advanced_settings');
90
+wl_write_log('Done. WordLift successfully uninstalled.');
Please login to merge, or discard this patch.