Completed
Pull Request — develop (#1645)
by
unknown
01:10
created
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.', 'wordlift' );
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.', 'wordlift' );
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   +24 added lines, -24 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 ) {
71
-				return __( 'WordLift Chord: no entities found.', 'wordlift' );
70
+			if (null === $post_id) {
71
+				return __('WordLift Chord: no entities found.', 'wordlift');
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.