Completed
Push — develop ( 4f9670...66f708 )
by David
02:29 queued 15s
created
src/public/class-wordlift-sharethis-service.php 2 patches
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -17,116 +17,116 @@
 block discarded – undo
17 17
  */
18 18
 class Wordlift_ShareThis_Service {
19 19
 
20
-	/**
21
-	 * The ShareThis function which prints the buttons.
22
-	 *
23
-	 * @since 3.2.0
24
-	 */
25
-	const ADD_WIDGET_FUNCTION_NAME = 'st_add_widget';
26
-
27
-	/**
28
-	 * The Log service.
29
-	 *
30
-	 * @since  3.2.0
31
-	 * @access private
32
-	 * @var \Wordlift_Log_Service $log_service The Log service.
33
-	 */
34
-	private $log_service;
35
-
36
-	/**
37
-	 * Create an instance of the ShareThis service.
38
-	 *
39
-	 * @since 3.2.0
40
-	 */
41
-	public function __construct() {
42
-
43
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_ShareThis_Service' );
44
-
45
-	}
46
-
47
-	/**
48
-	 * Receive <em>the_content</em> filter calls from WordPress.
49
-	 *
50
-	 * @since 3.2.0
51
-	 *
52
-	 * @param string $content The post content.
53
-	 *
54
-	 * @return string The updated post content.
55
-	 */
56
-	public function the_content( $content ) {
57
-
58
-		return $this->call_sharethis( 'the_content', $content );
59
-	}
60
-
61
-	/**
62
-	 * Receive <em>the_excerpt</em> filter calls from WordPress.
63
-	 *
64
-	 * @since 3.2.0
65
-	 *
66
-	 * @param string $content The post excerpt.
67
-	 *
68
-	 * @return string The updated post excerpt.
69
-	 */
70
-	public function the_excerpt( $content ) {
71
-
72
-		return $this->call_sharethis( 'the_excerpt', $content );
73
-	}
74
-
75
-	/**
76
-	 * Call the ShareThis function.
77
-	 *
78
-	 * @since 3.2.0
79
-	 *
80
-	 * @param string $tag The filter tag.
81
-	 * @param string $content The post content.
82
-	 *
83
-	 * @return string The updated post content.
84
-	 */
85
-	private function call_sharethis( $tag, $content ) {
86
-
87
-		// Get the current post.
88
-		global $post;
89
-
90
-		// Bail out if the global $post instance isn't set.
91
-		if ( ! isset( $post ) ) {
92
-			return $content;
93
-		}
94
-
95
-		// Bail out if the current entity is a post/page since this is already handled by ShareThis.
96
-		//
97
-		// See https://github.com/insideout10/wordlift-plugin/issues/819
98
-		if ( 'post' === $post->post_type || 'page' === $post->post_type ) {
99
-			return $content;
100
-		}
101
-
102
-		// If it's not the entity type, return.
103
-		$entity_service = Wordlift_Entity_Service::get_instance();
104
-		if ( null === $post || ! $entity_service->is_entity( get_the_ID() ) ) {
105
-			return $content;
106
-		}
107
-
108
-		// If the ShareThis function doesn't exist, return.
109
-		if ( ! function_exists( self::ADD_WIDGET_FUNCTION_NAME ) ) {
110
-			return $content;
111
-		}
112
-
113
-		// If ShareThis hasn't been added as a filter, return.
114
-		if ( ! has_filter( $tag, self::ADD_WIDGET_FUNCTION_NAME ) ) {
115
-			return $content;
116
-		}
117
-
118
-		// Temporary pop the post type and replace it with post.
119
-		$post_type       = $post->post_type;
120
-		$post->post_type = 'post';
121
-
122
-		// Call ShareThis (disguised as a post).
123
-		$content = call_user_func_array( self::ADD_WIDGET_FUNCTION_NAME, array( $content ) );
124
-
125
-		// Restore our post type.
126
-		$post->post_type = $post_type;
127
-
128
-		// Finally return the content.
129
-		return $content;
130
-	}
20
+    /**
21
+     * The ShareThis function which prints the buttons.
22
+     *
23
+     * @since 3.2.0
24
+     */
25
+    const ADD_WIDGET_FUNCTION_NAME = 'st_add_widget';
26
+
27
+    /**
28
+     * The Log service.
29
+     *
30
+     * @since  3.2.0
31
+     * @access private
32
+     * @var \Wordlift_Log_Service $log_service The Log service.
33
+     */
34
+    private $log_service;
35
+
36
+    /**
37
+     * Create an instance of the ShareThis service.
38
+     *
39
+     * @since 3.2.0
40
+     */
41
+    public function __construct() {
42
+
43
+        $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_ShareThis_Service' );
44
+
45
+    }
46
+
47
+    /**
48
+     * Receive <em>the_content</em> filter calls from WordPress.
49
+     *
50
+     * @since 3.2.0
51
+     *
52
+     * @param string $content The post content.
53
+     *
54
+     * @return string The updated post content.
55
+     */
56
+    public function the_content( $content ) {
57
+
58
+        return $this->call_sharethis( 'the_content', $content );
59
+    }
60
+
61
+    /**
62
+     * Receive <em>the_excerpt</em> filter calls from WordPress.
63
+     *
64
+     * @since 3.2.0
65
+     *
66
+     * @param string $content The post excerpt.
67
+     *
68
+     * @return string The updated post excerpt.
69
+     */
70
+    public function the_excerpt( $content ) {
71
+
72
+        return $this->call_sharethis( 'the_excerpt', $content );
73
+    }
74
+
75
+    /**
76
+     * Call the ShareThis function.
77
+     *
78
+     * @since 3.2.0
79
+     *
80
+     * @param string $tag The filter tag.
81
+     * @param string $content The post content.
82
+     *
83
+     * @return string The updated post content.
84
+     */
85
+    private function call_sharethis( $tag, $content ) {
86
+
87
+        // Get the current post.
88
+        global $post;
89
+
90
+        // Bail out if the global $post instance isn't set.
91
+        if ( ! isset( $post ) ) {
92
+            return $content;
93
+        }
94
+
95
+        // Bail out if the current entity is a post/page since this is already handled by ShareThis.
96
+        //
97
+        // See https://github.com/insideout10/wordlift-plugin/issues/819
98
+        if ( 'post' === $post->post_type || 'page' === $post->post_type ) {
99
+            return $content;
100
+        }
101
+
102
+        // If it's not the entity type, return.
103
+        $entity_service = Wordlift_Entity_Service::get_instance();
104
+        if ( null === $post || ! $entity_service->is_entity( get_the_ID() ) ) {
105
+            return $content;
106
+        }
107
+
108
+        // If the ShareThis function doesn't exist, return.
109
+        if ( ! function_exists( self::ADD_WIDGET_FUNCTION_NAME ) ) {
110
+            return $content;
111
+        }
112
+
113
+        // If ShareThis hasn't been added as a filter, return.
114
+        if ( ! has_filter( $tag, self::ADD_WIDGET_FUNCTION_NAME ) ) {
115
+            return $content;
116
+        }
117
+
118
+        // Temporary pop the post type and replace it with post.
119
+        $post_type       = $post->post_type;
120
+        $post->post_type = 'post';
121
+
122
+        // Call ShareThis (disguised as a post).
123
+        $content = call_user_func_array( self::ADD_WIDGET_FUNCTION_NAME, array( $content ) );
124
+
125
+        // Restore our post type.
126
+        $post->post_type = $post_type;
127
+
128
+        // Finally return the content.
129
+        return $content;
130
+    }
131 131
 
132 132
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 */
41 41
 	public function __construct() {
42 42
 
43
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_ShareThis_Service' );
43
+		$this->log_service = Wordlift_Log_Service::get_logger('Wordlift_ShareThis_Service');
44 44
 
45 45
 	}
46 46
 
@@ -53,9 +53,9 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @return string The updated post content.
55 55
 	 */
56
-	public function the_content( $content ) {
56
+	public function the_content($content) {
57 57
 
58
-		return $this->call_sharethis( 'the_content', $content );
58
+		return $this->call_sharethis('the_content', $content);
59 59
 	}
60 60
 
61 61
 	/**
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
 	 *
68 68
 	 * @return string The updated post excerpt.
69 69
 	 */
70
-	public function the_excerpt( $content ) {
70
+	public function the_excerpt($content) {
71 71
 
72
-		return $this->call_sharethis( 'the_excerpt', $content );
72
+		return $this->call_sharethis('the_excerpt', $content);
73 73
 	}
74 74
 
75 75
 	/**
@@ -82,36 +82,36 @@  discard block
 block discarded – undo
82 82
 	 *
83 83
 	 * @return string The updated post content.
84 84
 	 */
85
-	private function call_sharethis( $tag, $content ) {
85
+	private function call_sharethis($tag, $content) {
86 86
 
87 87
 		// Get the current post.
88 88
 		global $post;
89 89
 
90 90
 		// Bail out if the global $post instance isn't set.
91
-		if ( ! isset( $post ) ) {
91
+		if ( ! isset($post)) {
92 92
 			return $content;
93 93
 		}
94 94
 
95 95
 		// Bail out if the current entity is a post/page since this is already handled by ShareThis.
96 96
 		//
97 97
 		// See https://github.com/insideout10/wordlift-plugin/issues/819
98
-		if ( 'post' === $post->post_type || 'page' === $post->post_type ) {
98
+		if ('post' === $post->post_type || 'page' === $post->post_type) {
99 99
 			return $content;
100 100
 		}
101 101
 
102 102
 		// If it's not the entity type, return.
103 103
 		$entity_service = Wordlift_Entity_Service::get_instance();
104
-		if ( null === $post || ! $entity_service->is_entity( get_the_ID() ) ) {
104
+		if (null === $post || ! $entity_service->is_entity(get_the_ID())) {
105 105
 			return $content;
106 106
 		}
107 107
 
108 108
 		// If the ShareThis function doesn't exist, return.
109
-		if ( ! function_exists( self::ADD_WIDGET_FUNCTION_NAME ) ) {
109
+		if ( ! function_exists(self::ADD_WIDGET_FUNCTION_NAME)) {
110 110
 			return $content;
111 111
 		}
112 112
 
113 113
 		// If ShareThis hasn't been added as a filter, return.
114
-		if ( ! has_filter( $tag, self::ADD_WIDGET_FUNCTION_NAME ) ) {
114
+		if ( ! has_filter($tag, self::ADD_WIDGET_FUNCTION_NAME)) {
115 115
 			return $content;
116 116
 		}
117 117
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 		$post->post_type = 'post';
121 121
 
122 122
 		// Call ShareThis (disguised as a post).
123
-		$content = call_user_func_array( self::ADD_WIDGET_FUNCTION_NAME, array( $content ) );
123
+		$content = call_user_func_array(self::ADD_WIDGET_FUNCTION_NAME, array($content));
124 124
 
125 125
 		// Restore our post type.
126 126
 		$post->post_type = $post_type;
Please login to merge, or discard this patch.
src/public/class-wordlift-public.php 2 patches
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -22,106 +22,106 @@  discard block
 block discarded – undo
22 22
  */
23 23
 class Wordlift_Public {
24 24
 
25
-	/**
26
-	 * The ID of this plugin.
27
-	 *
28
-	 * @since    1.0.0
29
-	 * @access   private
30
-	 * @var      string $plugin_name The ID of this plugin.
31
-	 */
32
-	private $plugin_name;
33
-
34
-	/**
35
-	 * The version of this plugin.
36
-	 *
37
-	 * @since    1.0.0
38
-	 * @access   private
39
-	 * @var      string $version The current version of this plugin.
40
-	 */
41
-	private $version;
42
-
43
-	/**
44
-	 * Initialize the class and set its properties.
45
-	 *
46
-	 * @param string $plugin_name The name of the plugin.
47
-	 * @param string $version The version of this plugin.
48
-	 *
49
-	 * @since    1.0.0
50
-	 */
51
-	public function __construct( $plugin_name, $version ) {
52
-
53
-		$this->plugin_name = $plugin_name;
54
-		$this->version     = $version;
55
-
56
-	}
57
-
58
-	/**
59
-	 * Register the stylesheets for the public-facing side of the site.
60
-	 *
61
-	 * @since 3.19.3 Register the `wordlift-ui` css.
62
-	 * @since 3.19.2 The call to this function is commented out in `class-wordlift.php` because `wordlift-public.css`
63
-	 *               is empty.
64
-	 * @since 1.0.0
65
-	 */
66
-	public function enqueue_styles() {
67
-
68
-		/**
69
-		 * An instance of this class should be passed to the run() function
70
-		 * defined in Wordlift_Loader as all of the hooks are defined
71
-		 * in that particular class.
72
-		 *
73
-		 * The Wordlift_Loader will then create the relationship
74
-		 * between the defined hooks and the functions defined in this
75
-		 * class.
76
-		 */
77
-
78
-		/**
79
-		 * Add the `wordlift-font-awesome` unless some 3rd party sets the flag to false.
80
-		 *
81
-		 * @param bool $include Whether to include or not font-awesome (default true).
82
-		 *
83
-		 * @since 3.19.3
84
-		 */
85
-		$deps = apply_filters( 'wl_include_font_awesome', true )
86
-			? array( 'wordlift-font-awesome' )
87
-			: array();
88
-		wp_register_style( 'wordlift-font-awesome', plugin_dir_url( __DIR__ ) . 'css/wordlift-font-awesome' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), $this->version, 'all' );
89
-		wp_register_style( 'wordlift-ui', plugin_dir_url( __DIR__ ) . 'css/wordlift-ui' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', $deps, $this->version, 'all' );
90
-
91
-		// You need to re-enable the enqueue_styles in `class-wordlift.php` to make this effective.
92
-		//
93
-		// @see https://github.com/insideout10/wordlift-plugin/issues/821
94
-		//
95
-		// wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-public.css', array(), $this->version, 'all' );
96
-	}
97
-
98
-	/**
99
-	 * Register the stylesheets for the public-facing side of the site.
100
-	 *
101
-	 * @since    1.0.0
102
-	 */
103
-	public function enqueue_scripts() {
104
-
105
-		/**
106
-		 * This function is provided for demonstration purposes only.
107
-		 *
108
-		 * An instance of this class should be passed to the run() function
109
-		 * defined in Wordlift_Loader as all of the hooks are defined
110
-		 * in that particular class.
111
-		 *
112
-		 * The Wordlift_Loader will then create the relationship
113
-		 * between the defined hooks and the functions defined in this
114
-		 * class.
115
-		 */
116
-
117
-		$settings = self::get_settings();
118
-
119
-		// Note that we switched the js to be loaded in footer, since it is loading
120
-		// the json-ld representation.
121
-		wp_enqueue_script( $this->plugin_name, self::get_public_js_url(), array(), $this->version, true );
122
-		wp_localize_script( $this->plugin_name, 'wlSettings', $settings );
123
-
124
-		/*
25
+    /**
26
+     * The ID of this plugin.
27
+     *
28
+     * @since    1.0.0
29
+     * @access   private
30
+     * @var      string $plugin_name The ID of this plugin.
31
+     */
32
+    private $plugin_name;
33
+
34
+    /**
35
+     * The version of this plugin.
36
+     *
37
+     * @since    1.0.0
38
+     * @access   private
39
+     * @var      string $version The current version of this plugin.
40
+     */
41
+    private $version;
42
+
43
+    /**
44
+     * Initialize the class and set its properties.
45
+     *
46
+     * @param string $plugin_name The name of the plugin.
47
+     * @param string $version The version of this plugin.
48
+     *
49
+     * @since    1.0.0
50
+     */
51
+    public function __construct( $plugin_name, $version ) {
52
+
53
+        $this->plugin_name = $plugin_name;
54
+        $this->version     = $version;
55
+
56
+    }
57
+
58
+    /**
59
+     * Register the stylesheets for the public-facing side of the site.
60
+     *
61
+     * @since 3.19.3 Register the `wordlift-ui` css.
62
+     * @since 3.19.2 The call to this function is commented out in `class-wordlift.php` because `wordlift-public.css`
63
+     *               is empty.
64
+     * @since 1.0.0
65
+     */
66
+    public function enqueue_styles() {
67
+
68
+        /**
69
+         * An instance of this class should be passed to the run() function
70
+         * defined in Wordlift_Loader as all of the hooks are defined
71
+         * in that particular class.
72
+         *
73
+         * The Wordlift_Loader will then create the relationship
74
+         * between the defined hooks and the functions defined in this
75
+         * class.
76
+         */
77
+
78
+        /**
79
+         * Add the `wordlift-font-awesome` unless some 3rd party sets the flag to false.
80
+         *
81
+         * @param bool $include Whether to include or not font-awesome (default true).
82
+         *
83
+         * @since 3.19.3
84
+         */
85
+        $deps = apply_filters( 'wl_include_font_awesome', true )
86
+            ? array( 'wordlift-font-awesome' )
87
+            : array();
88
+        wp_register_style( 'wordlift-font-awesome', plugin_dir_url( __DIR__ ) . 'css/wordlift-font-awesome' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), $this->version, 'all' );
89
+        wp_register_style( 'wordlift-ui', plugin_dir_url( __DIR__ ) . 'css/wordlift-ui' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', $deps, $this->version, 'all' );
90
+
91
+        // You need to re-enable the enqueue_styles in `class-wordlift.php` to make this effective.
92
+        //
93
+        // @see https://github.com/insideout10/wordlift-plugin/issues/821
94
+        //
95
+        // wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-public.css', array(), $this->version, 'all' );
96
+    }
97
+
98
+    /**
99
+     * Register the stylesheets for the public-facing side of the site.
100
+     *
101
+     * @since    1.0.0
102
+     */
103
+    public function enqueue_scripts() {
104
+
105
+        /**
106
+         * This function is provided for demonstration purposes only.
107
+         *
108
+         * An instance of this class should be passed to the run() function
109
+         * defined in Wordlift_Loader as all of the hooks are defined
110
+         * in that particular class.
111
+         *
112
+         * The Wordlift_Loader will then create the relationship
113
+         * between the defined hooks and the functions defined in this
114
+         * class.
115
+         */
116
+
117
+        $settings = self::get_settings();
118
+
119
+        // Note that we switched the js to be loaded in footer, since it is loading
120
+        // the json-ld representation.
121
+        wp_enqueue_script( $this->plugin_name, self::get_public_js_url(), array(), $this->version, true );
122
+        wp_localize_script( $this->plugin_name, 'wlSettings', $settings );
123
+
124
+        /*
125 125
 		 * Add WordLift's version.
126 126
 		 * Can be disabled via filter 'wl_disable_version_js' since 3.21.1
127 127
 		 *
@@ -130,133 +130,133 @@  discard block
 block discarded – undo
130 130
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/843.
131 131
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/926.
132 132
 		 */
133
-		$show_version_default = false;
134
-		$show_version         = apply_filters( 'wl_disable_version_js', $show_version_default );
135
-
136
-		if ( $show_version ) {
137
-			wp_localize_script(
138
-				$this->plugin_name,
139
-				'wordlift',
140
-				array(
141
-					'version' => $this->version,
142
-				)
143
-			);
144
-		}
145
-
146
-		/*
133
+        $show_version_default = false;
134
+        $show_version         = apply_filters( 'wl_disable_version_js', $show_version_default );
135
+
136
+        if ( $show_version ) {
137
+            wp_localize_script(
138
+                $this->plugin_name,
139
+                'wordlift',
140
+                array(
141
+                    'version' => $this->version,
142
+                )
143
+            );
144
+        }
145
+
146
+        /*
147 147
 		 * Register wordlift-cloud script which is shared by
148 148
 		 * Navigator, Products Navigator, Faceted Search, Context Cards
149 149
 		 *
150 150
 		 * @since 3.22.0
151 151
 		 *
152 152
 		 */
153
-		$deps = $this->wp_version_compare( '>=', '5.0' ) ? array( 'wp-hooks' ) : array();
153
+        $deps = $this->wp_version_compare( '>=', '5.0' ) ? array( 'wp-hooks' ) : array();
154 154
 
155
-		/*
155
+        /*
156 156
 		 * Added defer to wordlift-cloud
157 157
 		 *
158 158
 		 * @since 3.27.4
159 159
 		 */
160
-		add_filter(
161
-			'script_loader_tag',
162
-			function ( $tag, $handle ) {
163
-				if ( 'wordlift-cloud' !== $handle ) {
164
-					return $tag;
165
-				}
166
-
167
-				return str_replace( ' src', ' defer="defer" src', $tag );
168
-			},
169
-			10,
170
-			2
171
-		);
172
-		wp_register_script( 'wordlift-cloud', self::get_cloud_js_url(), $deps, Wordlift::get_instance()->get_version(), true );
173
-
174
-	}
175
-
176
-	/**
177
-	 * Get the settings array.
178
-	 *
179
-	 * @return array An array with the settings.
180
-	 * @since 3.19.1
181
-	 */
182
-	public static function get_settings() {
183
-
184
-		// Prepare a settings array for client-side functions.
185
-		$settings = array(
186
-			'ajaxUrl'    => admin_url( 'admin-ajax.php' ),
187
-			'apiUrl'     => get_home_url( null, 'wl-api/' ),
188
-			'jsonld_url' => rest_url( '/wordlift/v1/jsonld/' ),
189
-		);
190
-
191
-		// If we're in a single page, then print out the post id.
192
-		if ( is_singular() ) {
193
-			$settings['postId'] = get_the_ID();
194
-		}
195
-
196
-		// Add flag that we are on home/blog page.
197
-		if ( is_home() || is_front_page() ) {
198
-			$settings['isHome'] = true;
199
-		}
200
-
201
-		// As of 2020-02-15, we publish the JSON-LD in the head, see Jsonld_Adaper.
202
-		$settings['jsonld_enabled'] = false;
203
-
204
-		// By default only enable JSON-LD on supported entity pages (includes
205
-		// `page`, `post` and `entity` by default) and on the home page.
206
-		//
207
-		// @see https://github.com/insideout10/wordlift-plugin/issues/733
208
-		// $jsonld_enabled = is_home() || is_front_page() || Wordlift_Entity_Type_Service::is_valid_entity_post_type( get_post_type() );
209
-
210
-		// Add the JSON-LD enabled flag, when set to false, the JSON-LD won't
211
-		// be loaded.
212
-		//
213
-		// @see https://github.com/insideout10/wordlift-plugin/issues/642.
214
-		// $settings['jsonld_enabled'] = apply_filters( 'wl_jsonld_enabled', $jsonld_enabled );
215
-
216
-		return $settings;
217
-	}
218
-
219
-	/**
220
-	 * Get the public JavaScript URL.
221
-	 *
222
-	 * Using this function is encouraged, since the public JavaScript is also used by the {@link Wordlift_WpRocket_Adapter}
223
-	 * in order to avoid breaking optimizations.
224
-	 *
225
-	 * @return string The URL to the public JavaScript.
226
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/842.
227
-	 *
228
-	 * @since 3.19.4
229
-	 */
230
-	public static function get_public_js_url() {
231
-
232
-		return plugin_dir_url( __DIR__ ) . 'js/dist/bundle.js';
233
-	}
234
-
235
-	/**
236
-	 * Get the Cloud JavaScript URL.
237
-	 *
238
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/971
239
-	 * @since 3.23.0
240
-	 * @return string The URL to the Cloud JavaScript.
241
-	 */
242
-	public static function get_cloud_js_url() {
243
-
244
-		return plugin_dir_url( __DIR__ ) . 'js/dist/wordlift-cloud.js';
245
-	}
246
-
247
-	/**
248
-	 * Helper function to check WP version
249
-	 *
250
-	 * @since 3.26.0
251
-	 *
252
-	 * @param string $operator
253
-	 * @param string $version
254
-	 *
255
-	 * @return mixed
256
-	 */
257
-	private function wp_version_compare( $operator = '>', $version = '5.0' ) {
258
-		global $wp_version;
259
-
260
-		return version_compare( $wp_version, $version, $operator );
261
-	}
160
+        add_filter(
161
+            'script_loader_tag',
162
+            function ( $tag, $handle ) {
163
+                if ( 'wordlift-cloud' !== $handle ) {
164
+                    return $tag;
165
+                }
166
+
167
+                return str_replace( ' src', ' defer="defer" src', $tag );
168
+            },
169
+            10,
170
+            2
171
+        );
172
+        wp_register_script( 'wordlift-cloud', self::get_cloud_js_url(), $deps, Wordlift::get_instance()->get_version(), true );
173
+
174
+    }
175
+
176
+    /**
177
+     * Get the settings array.
178
+     *
179
+     * @return array An array with the settings.
180
+     * @since 3.19.1
181
+     */
182
+    public static function get_settings() {
183
+
184
+        // Prepare a settings array for client-side functions.
185
+        $settings = array(
186
+            'ajaxUrl'    => admin_url( 'admin-ajax.php' ),
187
+            'apiUrl'     => get_home_url( null, 'wl-api/' ),
188
+            'jsonld_url' => rest_url( '/wordlift/v1/jsonld/' ),
189
+        );
190
+
191
+        // If we're in a single page, then print out the post id.
192
+        if ( is_singular() ) {
193
+            $settings['postId'] = get_the_ID();
194
+        }
195
+
196
+        // Add flag that we are on home/blog page.
197
+        if ( is_home() || is_front_page() ) {
198
+            $settings['isHome'] = true;
199
+        }
200
+
201
+        // As of 2020-02-15, we publish the JSON-LD in the head, see Jsonld_Adaper.
202
+        $settings['jsonld_enabled'] = false;
203
+
204
+        // By default only enable JSON-LD on supported entity pages (includes
205
+        // `page`, `post` and `entity` by default) and on the home page.
206
+        //
207
+        // @see https://github.com/insideout10/wordlift-plugin/issues/733
208
+        // $jsonld_enabled = is_home() || is_front_page() || Wordlift_Entity_Type_Service::is_valid_entity_post_type( get_post_type() );
209
+
210
+        // Add the JSON-LD enabled flag, when set to false, the JSON-LD won't
211
+        // be loaded.
212
+        //
213
+        // @see https://github.com/insideout10/wordlift-plugin/issues/642.
214
+        // $settings['jsonld_enabled'] = apply_filters( 'wl_jsonld_enabled', $jsonld_enabled );
215
+
216
+        return $settings;
217
+    }
218
+
219
+    /**
220
+     * Get the public JavaScript URL.
221
+     *
222
+     * Using this function is encouraged, since the public JavaScript is also used by the {@link Wordlift_WpRocket_Adapter}
223
+     * in order to avoid breaking optimizations.
224
+     *
225
+     * @return string The URL to the public JavaScript.
226
+     * @see https://github.com/insideout10/wordlift-plugin/issues/842.
227
+     *
228
+     * @since 3.19.4
229
+     */
230
+    public static function get_public_js_url() {
231
+
232
+        return plugin_dir_url( __DIR__ ) . 'js/dist/bundle.js';
233
+    }
234
+
235
+    /**
236
+     * Get the Cloud JavaScript URL.
237
+     *
238
+     * @see https://github.com/insideout10/wordlift-plugin/issues/971
239
+     * @since 3.23.0
240
+     * @return string The URL to the Cloud JavaScript.
241
+     */
242
+    public static function get_cloud_js_url() {
243
+
244
+        return plugin_dir_url( __DIR__ ) . 'js/dist/wordlift-cloud.js';
245
+    }
246
+
247
+    /**
248
+     * Helper function to check WP version
249
+     *
250
+     * @since 3.26.0
251
+     *
252
+     * @param string $operator
253
+     * @param string $version
254
+     *
255
+     * @return mixed
256
+     */
257
+    private function wp_version_compare( $operator = '>', $version = '5.0' ) {
258
+        global $wp_version;
259
+
260
+        return version_compare( $wp_version, $version, $operator );
261
+    }
262 262
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	 *
49 49
 	 * @since    1.0.0
50 50
 	 */
51
-	public function __construct( $plugin_name, $version ) {
51
+	public function __construct($plugin_name, $version) {
52 52
 
53 53
 		$this->plugin_name = $plugin_name;
54 54
 		$this->version     = $version;
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
 		 *
83 83
 		 * @since 3.19.3
84 84
 		 */
85
-		$deps = apply_filters( 'wl_include_font_awesome', true )
86
-			? array( 'wordlift-font-awesome' )
85
+		$deps = apply_filters('wl_include_font_awesome', true)
86
+			? array('wordlift-font-awesome')
87 87
 			: array();
88
-		wp_register_style( 'wordlift-font-awesome', plugin_dir_url( __DIR__ ) . 'css/wordlift-font-awesome' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), $this->version, 'all' );
89
-		wp_register_style( 'wordlift-ui', plugin_dir_url( __DIR__ ) . 'css/wordlift-ui' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', $deps, $this->version, 'all' );
88
+		wp_register_style('wordlift-font-awesome', plugin_dir_url(__DIR__).'css/wordlift-font-awesome'.( ! defined('SCRIPT_DEBUG') || ! SCRIPT_DEBUG ? '.min' : '').'.css', array(), $this->version, 'all');
89
+		wp_register_style('wordlift-ui', plugin_dir_url(__DIR__).'css/wordlift-ui'.( ! defined('SCRIPT_DEBUG') || ! SCRIPT_DEBUG ? '.min' : '').'.css', $deps, $this->version, 'all');
90 90
 
91 91
 		// You need to re-enable the enqueue_styles in `class-wordlift.php` to make this effective.
92 92
 		//
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
 
119 119
 		// Note that we switched the js to be loaded in footer, since it is loading
120 120
 		// the json-ld representation.
121
-		wp_enqueue_script( $this->plugin_name, self::get_public_js_url(), array(), $this->version, true );
122
-		wp_localize_script( $this->plugin_name, 'wlSettings', $settings );
121
+		wp_enqueue_script($this->plugin_name, self::get_public_js_url(), array(), $this->version, true);
122
+		wp_localize_script($this->plugin_name, 'wlSettings', $settings);
123 123
 
124 124
 		/*
125 125
 		 * Add WordLift's version.
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/926.
132 132
 		 */
133 133
 		$show_version_default = false;
134
-		$show_version         = apply_filters( 'wl_disable_version_js', $show_version_default );
134
+		$show_version         = apply_filters('wl_disable_version_js', $show_version_default);
135 135
 
136
-		if ( $show_version ) {
136
+		if ($show_version) {
137 137
 			wp_localize_script(
138 138
 				$this->plugin_name,
139 139
 				'wordlift',
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 		 * @since 3.22.0
151 151
 		 *
152 152
 		 */
153
-		$deps = $this->wp_version_compare( '>=', '5.0' ) ? array( 'wp-hooks' ) : array();
153
+		$deps = $this->wp_version_compare('>=', '5.0') ? array('wp-hooks') : array();
154 154
 
155 155
 		/*
156 156
 		 * Added defer to wordlift-cloud
@@ -159,17 +159,17 @@  discard block
 block discarded – undo
159 159
 		 */
160 160
 		add_filter(
161 161
 			'script_loader_tag',
162
-			function ( $tag, $handle ) {
163
-				if ( 'wordlift-cloud' !== $handle ) {
162
+			function($tag, $handle) {
163
+				if ('wordlift-cloud' !== $handle) {
164 164
 					return $tag;
165 165
 				}
166 166
 
167
-				return str_replace( ' src', ' defer="defer" src', $tag );
167
+				return str_replace(' src', ' defer="defer" src', $tag);
168 168
 			},
169 169
 			10,
170 170
 			2
171 171
 		);
172
-		wp_register_script( 'wordlift-cloud', self::get_cloud_js_url(), $deps, Wordlift::get_instance()->get_version(), true );
172
+		wp_register_script('wordlift-cloud', self::get_cloud_js_url(), $deps, Wordlift::get_instance()->get_version(), true);
173 173
 
174 174
 	}
175 175
 
@@ -183,18 +183,18 @@  discard block
 block discarded – undo
183 183
 
184 184
 		// Prepare a settings array for client-side functions.
185 185
 		$settings = array(
186
-			'ajaxUrl'    => admin_url( 'admin-ajax.php' ),
187
-			'apiUrl'     => get_home_url( null, 'wl-api/' ),
188
-			'jsonld_url' => rest_url( '/wordlift/v1/jsonld/' ),
186
+			'ajaxUrl'    => admin_url('admin-ajax.php'),
187
+			'apiUrl'     => get_home_url(null, 'wl-api/'),
188
+			'jsonld_url' => rest_url('/wordlift/v1/jsonld/'),
189 189
 		);
190 190
 
191 191
 		// If we're in a single page, then print out the post id.
192
-		if ( is_singular() ) {
192
+		if (is_singular()) {
193 193
 			$settings['postId'] = get_the_ID();
194 194
 		}
195 195
 
196 196
 		// Add flag that we are on home/blog page.
197
-		if ( is_home() || is_front_page() ) {
197
+		if (is_home() || is_front_page()) {
198 198
 			$settings['isHome'] = true;
199 199
 		}
200 200
 
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 	 */
230 230
 	public static function get_public_js_url() {
231 231
 
232
-		return plugin_dir_url( __DIR__ ) . 'js/dist/bundle.js';
232
+		return plugin_dir_url(__DIR__).'js/dist/bundle.js';
233 233
 	}
234 234
 
235 235
 	/**
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	 */
242 242
 	public static function get_cloud_js_url() {
243 243
 
244
-		return plugin_dir_url( __DIR__ ) . 'js/dist/wordlift-cloud.js';
244
+		return plugin_dir_url(__DIR__).'js/dist/wordlift-cloud.js';
245 245
 	}
246 246
 
247 247
 	/**
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
 	 *
255 255
 	 * @return mixed
256 256
 	 */
257
-	private function wp_version_compare( $operator = '>', $version = '5.0' ) {
257
+	private function wp_version_compare($operator = '>', $version = '5.0') {
258 258
 		global $wp_version;
259 259
 
260
-		return version_compare( $wp_version, $version, $operator );
260
+		return version_compare($wp_version, $version, $operator);
261 261
 	}
262 262
 }
Please login to merge, or discard this patch.
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.