Passed
Push — main ( aaef5c...e4c121 )
by TARIQ
71:39
created
vendor/automattic/jetpack-autoloader/src/class-hook-manager.php 2 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -6,63 +6,63 @@
 block discarded – undo
6 6
  */
7 7
 class Hook_Manager {
8 8
 
9
-	/**
10
-	 * An array containing all of the hooks that we've registered.
11
-	 *
12
-	 * @var array
13
-	 */
14
-	private $registered_hooks;
9
+    /**
10
+     * An array containing all of the hooks that we've registered.
11
+     *
12
+     * @var array
13
+     */
14
+    private $registered_hooks;
15 15
 
16
-	/**
17
-	 * The constructor.
18
-	 */
19
-	public function __construct() {
20
-		$this->registered_hooks = array();
21
-	}
16
+    /**
17
+     * The constructor.
18
+     */
19
+    public function __construct() {
20
+        $this->registered_hooks = array();
21
+    }
22 22
 
23
-	/**
24
-	 * Adds an action to WordPress and registers it internally.
25
-	 *
26
-	 * @param string   $tag           The name of the action which is hooked.
27
-	 * @param callable $callable      The function to call.
28
-	 * @param int      $priority      Used to specify the priority of the action.
29
-	 * @param int      $accepted_args Used to specify the number of arguments the callable accepts.
30
-	 */
31
-	public function add_action( $tag, $callable, $priority = 10, $accepted_args = 1 ) {
32
-		$this->registered_hooks[ $tag ][] = array(
33
-			'priority' => $priority,
34
-			'callable' => $callable,
35
-		);
23
+    /**
24
+     * Adds an action to WordPress and registers it internally.
25
+     *
26
+     * @param string   $tag           The name of the action which is hooked.
27
+     * @param callable $callable      The function to call.
28
+     * @param int      $priority      Used to specify the priority of the action.
29
+     * @param int      $accepted_args Used to specify the number of arguments the callable accepts.
30
+     */
31
+    public function add_action( $tag, $callable, $priority = 10, $accepted_args = 1 ) {
32
+        $this->registered_hooks[ $tag ][] = array(
33
+            'priority' => $priority,
34
+            'callable' => $callable,
35
+        );
36 36
 
37
-		add_action( $tag, $callable, $priority, $accepted_args );
38
-	}
37
+        add_action( $tag, $callable, $priority, $accepted_args );
38
+    }
39 39
 
40
-	/**
41
-	 * Adds a filter to WordPress and registers it internally.
42
-	 *
43
-	 * @param string   $tag           The name of the filter which is hooked.
44
-	 * @param callable $callable      The function to call.
45
-	 * @param int      $priority      Used to specify the priority of the filter.
46
-	 * @param int      $accepted_args Used to specify the number of arguments the callable accepts.
47
-	 */
48
-	public function add_filter( $tag, $callable, $priority = 10, $accepted_args = 1 ) {
49
-		$this->registered_hooks[ $tag ][] = array(
50
-			'priority' => $priority,
51
-			'callable' => $callable,
52
-		);
40
+    /**
41
+     * Adds a filter to WordPress and registers it internally.
42
+     *
43
+     * @param string   $tag           The name of the filter which is hooked.
44
+     * @param callable $callable      The function to call.
45
+     * @param int      $priority      Used to specify the priority of the filter.
46
+     * @param int      $accepted_args Used to specify the number of arguments the callable accepts.
47
+     */
48
+    public function add_filter( $tag, $callable, $priority = 10, $accepted_args = 1 ) {
49
+        $this->registered_hooks[ $tag ][] = array(
50
+            'priority' => $priority,
51
+            'callable' => $callable,
52
+        );
53 53
 
54
-		add_filter( $tag, $callable, $priority, $accepted_args );
55
-	}
54
+        add_filter( $tag, $callable, $priority, $accepted_args );
55
+    }
56 56
 
57
-	/**
58
-	 * Removes all of the registered hooks.
59
-	 */
60
-	public function reset() {
61
-		foreach ( $this->registered_hooks as $tag => $hooks ) {
62
-			foreach ( $hooks as $hook ) {
63
-				remove_filter( $tag, $hook['callable'], $hook['priority'] );
64
-			}
65
-		}
66
-		$this->registered_hooks = array();
67
-	}
57
+    /**
58
+     * Removes all of the registered hooks.
59
+     */
60
+    public function reset() {
61
+        foreach ( $this->registered_hooks as $tag => $hooks ) {
62
+            foreach ( $hooks as $hook ) {
63
+                remove_filter( $tag, $hook['callable'], $hook['priority'] );
64
+            }
65
+        }
66
+        $this->registered_hooks = array();
67
+    }
68 68
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -28,13 +28,13 @@  discard block
 block discarded – undo
28 28
 	 * @param int      $priority      Used to specify the priority of the action.
29 29
 	 * @param int      $accepted_args Used to specify the number of arguments the callable accepts.
30 30
 	 */
31
-	public function add_action( $tag, $callable, $priority = 10, $accepted_args = 1 ) {
32
-		$this->registered_hooks[ $tag ][] = array(
31
+	public function add_action($tag, $callable, $priority = 10, $accepted_args = 1) {
32
+		$this->registered_hooks[$tag][] = array(
33 33
 			'priority' => $priority,
34 34
 			'callable' => $callable,
35 35
 		);
36 36
 
37
-		add_action( $tag, $callable, $priority, $accepted_args );
37
+		add_action($tag, $callable, $priority, $accepted_args);
38 38
 	}
39 39
 
40 40
 	/**
@@ -45,22 +45,22 @@  discard block
 block discarded – undo
45 45
 	 * @param int      $priority      Used to specify the priority of the filter.
46 46
 	 * @param int      $accepted_args Used to specify the number of arguments the callable accepts.
47 47
 	 */
48
-	public function add_filter( $tag, $callable, $priority = 10, $accepted_args = 1 ) {
49
-		$this->registered_hooks[ $tag ][] = array(
48
+	public function add_filter($tag, $callable, $priority = 10, $accepted_args = 1) {
49
+		$this->registered_hooks[$tag][] = array(
50 50
 			'priority' => $priority,
51 51
 			'callable' => $callable,
52 52
 		);
53 53
 
54
-		add_filter( $tag, $callable, $priority, $accepted_args );
54
+		add_filter($tag, $callable, $priority, $accepted_args);
55 55
 	}
56 56
 
57 57
 	/**
58 58
 	 * Removes all of the registered hooks.
59 59
 	 */
60 60
 	public function reset() {
61
-		foreach ( $this->registered_hooks as $tag => $hooks ) {
62
-			foreach ( $hooks as $hook ) {
63
-				remove_filter( $tag, $hook['callable'], $hook['priority'] );
61
+		foreach ($this->registered_hooks as $tag => $hooks) {
62
+			foreach ($hooks as $hook) {
63
+				remove_filter($tag, $hook['callable'], $hook['priority']);
64 64
 			}
65 65
 		}
66 66
 		$this->registered_hooks = array();
Please login to merge, or discard this patch.
vendor/automattic/jetpack-autoloader/src/class-path-processor.php 2 patches
Indentation   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -5,182 +5,182 @@
 block discarded – undo
5 5
  * This class handles dealing with paths for the autoloader.
6 6
  */
7 7
 class Path_Processor {
8
-	/**
9
-	 * Given a path this will replace any of the path constants with a token to represent it.
10
-	 *
11
-	 * @param string $path The path we want to process.
12
-	 *
13
-	 * @return string The tokenized path.
14
-	 */
15
-	public function tokenize_path_constants( $path ) {
16
-		$path = wp_normalize_path( $path );
17
-
18
-		$constants = $this->get_normalized_constants();
19
-		foreach ( $constants as $constant => $constant_path ) {
20
-			$len = strlen( $constant_path );
21
-			if ( substr( $path, 0, $len ) !== $constant_path ) {
22
-				continue;
23
-			}
24
-
25
-			return substr_replace( $path, '{{' . $constant . '}}', 0, $len );
26
-		}
27
-
28
-		return $path;
29
-	}
30
-
31
-	/**
32
-	 * Given a path this will replace any of the path constant tokens with the expanded path.
33
-	 *
34
-	 * @param string $tokenized_path The path we want to process.
35
-	 *
36
-	 * @return string The expanded path.
37
-	 */
38
-	public function untokenize_path_constants( $tokenized_path ) {
39
-		$tokenized_path = wp_normalize_path( $tokenized_path );
40
-
41
-		$constants = $this->get_normalized_constants();
42
-		foreach ( $constants as $constant => $constant_path ) {
43
-			$constant = '{{' . $constant . '}}';
44
-
45
-			$len = strlen( $constant );
46
-			if ( substr( $tokenized_path, 0, $len ) !== $constant ) {
47
-				continue;
48
-			}
49
-
50
-			return $this->get_real_path( substr_replace( $tokenized_path, $constant_path, 0, $len ) );
51
-		}
52
-
53
-		return $tokenized_path;
54
-	}
55
-
56
-	/**
57
-	 * Given a file and an array of places it might be, this will find the absolute path and return it.
58
-	 *
59
-	 * @param string $file The plugin or theme file to resolve.
60
-	 * @param array  $directories_to_check The directories we should check for the file if it isn't an absolute path.
61
-	 *
62
-	 * @return string|false Returns the absolute path to the directory, otherwise false.
63
-	 */
64
-	public function find_directory_with_autoloader( $file, $directories_to_check ) {
65
-		$file = wp_normalize_path( $file );
66
-
67
-		if ( ! $this->is_absolute_path( $file ) ) {
68
-			$file = $this->find_absolute_plugin_path( $file, $directories_to_check );
69
-			if ( ! isset( $file ) ) {
70
-				return false;
71
-			}
72
-		}
73
-
74
-		// We need the real path for consistency with __DIR__ paths.
75
-		$file = $this->get_real_path( $file );
76
-
77
-		// phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
78
-		$directory = @is_file( $file ) ? dirname( $file ) : $file;
79
-		if ( ! @is_file( $directory . '/vendor/composer/jetpack_autoload_classmap.php' ) ) {
80
-			return false;
81
-		}
82
-		// phpcs:enable WordPress.PHP.NoSilencedErrors.Discouraged
83
-
84
-		return $directory;
85
-	}
86
-
87
-	/**
88
-	 * Fetches an array of normalized paths keyed by the constant they came from.
89
-	 *
90
-	 * @return string[] The normalized paths keyed by the constant.
91
-	 */
92
-	private function get_normalized_constants() {
93
-		$raw_constants = array(
94
-			// Order the constants from most-specific to least-specific.
95
-			'WP_PLUGIN_DIR',
96
-			'WPMU_PLUGIN_DIR',
97
-			'WP_CONTENT_DIR',
98
-			'ABSPATH',
99
-		);
100
-
101
-		$constants = array();
102
-		foreach ( $raw_constants as $raw ) {
103
-			if ( ! defined( $raw ) ) {
104
-				continue;
105
-			}
106
-
107
-			$path = wp_normalize_path( constant( $raw ) );
108
-			if ( isset( $path ) ) {
109
-				$constants[ $raw ] = $path;
110
-			}
111
-		}
112
-
113
-		return $constants;
114
-	}
115
-
116
-	/**
117
-	 * Indicates whether or not a path is absolute.
118
-	 *
119
-	 * @param string $path The path to check.
120
-	 *
121
-	 * @return bool True if the path is absolute, otherwise false.
122
-	 */
123
-	private function is_absolute_path( $path ) {
124
-		if ( 0 === strlen( $path ) || '.' === $path[0] ) {
125
-			return false;
126
-		}
127
-
128
-		// Absolute paths on Windows may begin with a drive letter.
129
-		if ( preg_match( '/^[a-zA-Z]:[\/\\\\]/', $path ) ) {
130
-			return true;
131
-		}
132
-
133
-		// A path starting with / or \ is absolute; anything else is relative.
134
-		return ( '/' === $path[0] || '\\' === $path[0] );
135
-	}
136
-
137
-	/**
138
-	 * Given a file and a list of directories to check, this method will try to figure out
139
-	 * the absolute path to the file in question.
140
-	 *
141
-	 * @param string $normalized_path The normalized path to the plugin or theme file to resolve.
142
-	 * @param array  $directories_to_check The directories we should check for the file if it isn't an absolute path.
143
-	 *
144
-	 * @return string|null The absolute path to the plugin file, otherwise null.
145
-	 */
146
-	private function find_absolute_plugin_path( $normalized_path, $directories_to_check ) {
147
-		// We're only able to find the absolute path for plugin/theme PHP files.
148
-		if ( ! is_string( $normalized_path ) || '.php' !== substr( $normalized_path, -4 ) ) {
149
-			return null;
150
-		}
151
-
152
-		foreach ( $directories_to_check as $directory ) {
153
-			$normalized_check = wp_normalize_path( trailingslashit( $directory ) ) . $normalized_path;
154
-			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
155
-			if ( @is_file( $normalized_check ) ) {
156
-				return $normalized_check;
157
-			}
158
-		}
159
-
160
-		return null;
161
-	}
162
-
163
-	/**
164
-	 * Given a path this will figure out the real path that we should be using.
165
-	 *
166
-	 * @param string $path The path to resolve.
167
-	 *
168
-	 * @return string The resolved path.
169
-	 */
170
-	private function get_real_path( $path ) {
171
-		// We want to resolve symbolic links for consistency with __DIR__ paths.
172
-		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
173
-		$real_path = @realpath( $path );
174
-		if ( false === $real_path ) {
175
-			// Let the autoloader deal with paths that don't exist.
176
-			$real_path = $path;
177
-		}
178
-
179
-		// Using realpath will make it platform-specific so we must normalize it after.
180
-		if ( $path !== $real_path ) {
181
-			$real_path = wp_normalize_path( $real_path );
182
-		}
183
-
184
-		return $real_path;
185
-	}
8
+    /**
9
+     * Given a path this will replace any of the path constants with a token to represent it.
10
+     *
11
+     * @param string $path The path we want to process.
12
+     *
13
+     * @return string The tokenized path.
14
+     */
15
+    public function tokenize_path_constants( $path ) {
16
+        $path = wp_normalize_path( $path );
17
+
18
+        $constants = $this->get_normalized_constants();
19
+        foreach ( $constants as $constant => $constant_path ) {
20
+            $len = strlen( $constant_path );
21
+            if ( substr( $path, 0, $len ) !== $constant_path ) {
22
+                continue;
23
+            }
24
+
25
+            return substr_replace( $path, '{{' . $constant . '}}', 0, $len );
26
+        }
27
+
28
+        return $path;
29
+    }
30
+
31
+    /**
32
+     * Given a path this will replace any of the path constant tokens with the expanded path.
33
+     *
34
+     * @param string $tokenized_path The path we want to process.
35
+     *
36
+     * @return string The expanded path.
37
+     */
38
+    public function untokenize_path_constants( $tokenized_path ) {
39
+        $tokenized_path = wp_normalize_path( $tokenized_path );
40
+
41
+        $constants = $this->get_normalized_constants();
42
+        foreach ( $constants as $constant => $constant_path ) {
43
+            $constant = '{{' . $constant . '}}';
44
+
45
+            $len = strlen( $constant );
46
+            if ( substr( $tokenized_path, 0, $len ) !== $constant ) {
47
+                continue;
48
+            }
49
+
50
+            return $this->get_real_path( substr_replace( $tokenized_path, $constant_path, 0, $len ) );
51
+        }
52
+
53
+        return $tokenized_path;
54
+    }
55
+
56
+    /**
57
+     * Given a file and an array of places it might be, this will find the absolute path and return it.
58
+     *
59
+     * @param string $file The plugin or theme file to resolve.
60
+     * @param array  $directories_to_check The directories we should check for the file if it isn't an absolute path.
61
+     *
62
+     * @return string|false Returns the absolute path to the directory, otherwise false.
63
+     */
64
+    public function find_directory_with_autoloader( $file, $directories_to_check ) {
65
+        $file = wp_normalize_path( $file );
66
+
67
+        if ( ! $this->is_absolute_path( $file ) ) {
68
+            $file = $this->find_absolute_plugin_path( $file, $directories_to_check );
69
+            if ( ! isset( $file ) ) {
70
+                return false;
71
+            }
72
+        }
73
+
74
+        // We need the real path for consistency with __DIR__ paths.
75
+        $file = $this->get_real_path( $file );
76
+
77
+        // phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
78
+        $directory = @is_file( $file ) ? dirname( $file ) : $file;
79
+        if ( ! @is_file( $directory . '/vendor/composer/jetpack_autoload_classmap.php' ) ) {
80
+            return false;
81
+        }
82
+        // phpcs:enable WordPress.PHP.NoSilencedErrors.Discouraged
83
+
84
+        return $directory;
85
+    }
86
+
87
+    /**
88
+     * Fetches an array of normalized paths keyed by the constant they came from.
89
+     *
90
+     * @return string[] The normalized paths keyed by the constant.
91
+     */
92
+    private function get_normalized_constants() {
93
+        $raw_constants = array(
94
+            // Order the constants from most-specific to least-specific.
95
+            'WP_PLUGIN_DIR',
96
+            'WPMU_PLUGIN_DIR',
97
+            'WP_CONTENT_DIR',
98
+            'ABSPATH',
99
+        );
100
+
101
+        $constants = array();
102
+        foreach ( $raw_constants as $raw ) {
103
+            if ( ! defined( $raw ) ) {
104
+                continue;
105
+            }
106
+
107
+            $path = wp_normalize_path( constant( $raw ) );
108
+            if ( isset( $path ) ) {
109
+                $constants[ $raw ] = $path;
110
+            }
111
+        }
112
+
113
+        return $constants;
114
+    }
115
+
116
+    /**
117
+     * Indicates whether or not a path is absolute.
118
+     *
119
+     * @param string $path The path to check.
120
+     *
121
+     * @return bool True if the path is absolute, otherwise false.
122
+     */
123
+    private function is_absolute_path( $path ) {
124
+        if ( 0 === strlen( $path ) || '.' === $path[0] ) {
125
+            return false;
126
+        }
127
+
128
+        // Absolute paths on Windows may begin with a drive letter.
129
+        if ( preg_match( '/^[a-zA-Z]:[\/\\\\]/', $path ) ) {
130
+            return true;
131
+        }
132
+
133
+        // A path starting with / or \ is absolute; anything else is relative.
134
+        return ( '/' === $path[0] || '\\' === $path[0] );
135
+    }
136
+
137
+    /**
138
+     * Given a file and a list of directories to check, this method will try to figure out
139
+     * the absolute path to the file in question.
140
+     *
141
+     * @param string $normalized_path The normalized path to the plugin or theme file to resolve.
142
+     * @param array  $directories_to_check The directories we should check for the file if it isn't an absolute path.
143
+     *
144
+     * @return string|null The absolute path to the plugin file, otherwise null.
145
+     */
146
+    private function find_absolute_plugin_path( $normalized_path, $directories_to_check ) {
147
+        // We're only able to find the absolute path for plugin/theme PHP files.
148
+        if ( ! is_string( $normalized_path ) || '.php' !== substr( $normalized_path, -4 ) ) {
149
+            return null;
150
+        }
151
+
152
+        foreach ( $directories_to_check as $directory ) {
153
+            $normalized_check = wp_normalize_path( trailingslashit( $directory ) ) . $normalized_path;
154
+            // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
155
+            if ( @is_file( $normalized_check ) ) {
156
+                return $normalized_check;
157
+            }
158
+        }
159
+
160
+        return null;
161
+    }
162
+
163
+    /**
164
+     * Given a path this will figure out the real path that we should be using.
165
+     *
166
+     * @param string $path The path to resolve.
167
+     *
168
+     * @return string The resolved path.
169
+     */
170
+    private function get_real_path( $path ) {
171
+        // We want to resolve symbolic links for consistency with __DIR__ paths.
172
+        // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
173
+        $real_path = @realpath( $path );
174
+        if ( false === $real_path ) {
175
+            // Let the autoloader deal with paths that don't exist.
176
+            $real_path = $path;
177
+        }
178
+
179
+        // Using realpath will make it platform-specific so we must normalize it after.
180
+        if ( $path !== $real_path ) {
181
+            $real_path = wp_normalize_path( $real_path );
182
+        }
183
+
184
+        return $real_path;
185
+    }
186 186
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -12,17 +12,17 @@  discard block
 block discarded – undo
12 12
 	 *
13 13
 	 * @return string The tokenized path.
14 14
 	 */
15
-	public function tokenize_path_constants( $path ) {
16
-		$path = wp_normalize_path( $path );
15
+	public function tokenize_path_constants($path) {
16
+		$path = wp_normalize_path($path);
17 17
 
18 18
 		$constants = $this->get_normalized_constants();
19
-		foreach ( $constants as $constant => $constant_path ) {
20
-			$len = strlen( $constant_path );
21
-			if ( substr( $path, 0, $len ) !== $constant_path ) {
19
+		foreach ($constants as $constant => $constant_path) {
20
+			$len = strlen($constant_path);
21
+			if (substr($path, 0, $len) !== $constant_path) {
22 22
 				continue;
23 23
 			}
24 24
 
25
-			return substr_replace( $path, '{{' . $constant . '}}', 0, $len );
25
+			return substr_replace($path, '{{' . $constant . '}}', 0, $len);
26 26
 		}
27 27
 
28 28
 		return $path;
@@ -35,19 +35,19 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @return string The expanded path.
37 37
 	 */
38
-	public function untokenize_path_constants( $tokenized_path ) {
39
-		$tokenized_path = wp_normalize_path( $tokenized_path );
38
+	public function untokenize_path_constants($tokenized_path) {
39
+		$tokenized_path = wp_normalize_path($tokenized_path);
40 40
 
41 41
 		$constants = $this->get_normalized_constants();
42
-		foreach ( $constants as $constant => $constant_path ) {
42
+		foreach ($constants as $constant => $constant_path) {
43 43
 			$constant = '{{' . $constant . '}}';
44 44
 
45
-			$len = strlen( $constant );
46
-			if ( substr( $tokenized_path, 0, $len ) !== $constant ) {
45
+			$len = strlen($constant);
46
+			if (substr($tokenized_path, 0, $len) !== $constant) {
47 47
 				continue;
48 48
 			}
49 49
 
50
-			return $this->get_real_path( substr_replace( $tokenized_path, $constant_path, 0, $len ) );
50
+			return $this->get_real_path(substr_replace($tokenized_path, $constant_path, 0, $len));
51 51
 		}
52 52
 
53 53
 		return $tokenized_path;
@@ -61,22 +61,22 @@  discard block
 block discarded – undo
61 61
 	 *
62 62
 	 * @return string|false Returns the absolute path to the directory, otherwise false.
63 63
 	 */
64
-	public function find_directory_with_autoloader( $file, $directories_to_check ) {
65
-		$file = wp_normalize_path( $file );
64
+	public function find_directory_with_autoloader($file, $directories_to_check) {
65
+		$file = wp_normalize_path($file);
66 66
 
67
-		if ( ! $this->is_absolute_path( $file ) ) {
68
-			$file = $this->find_absolute_plugin_path( $file, $directories_to_check );
69
-			if ( ! isset( $file ) ) {
67
+		if (!$this->is_absolute_path($file)) {
68
+			$file = $this->find_absolute_plugin_path($file, $directories_to_check);
69
+			if (!isset($file)) {
70 70
 				return false;
71 71
 			}
72 72
 		}
73 73
 
74 74
 		// We need the real path for consistency with __DIR__ paths.
75
-		$file = $this->get_real_path( $file );
75
+		$file = $this->get_real_path($file);
76 76
 
77 77
 		// phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
78
-		$directory = @is_file( $file ) ? dirname( $file ) : $file;
79
-		if ( ! @is_file( $directory . '/vendor/composer/jetpack_autoload_classmap.php' ) ) {
78
+		$directory = @is_file($file) ? dirname($file) : $file;
79
+		if (!@is_file($directory . '/vendor/composer/jetpack_autoload_classmap.php')) {
80 80
 			return false;
81 81
 		}
82 82
 		// phpcs:enable WordPress.PHP.NoSilencedErrors.Discouraged
@@ -99,14 +99,14 @@  discard block
 block discarded – undo
99 99
 		);
100 100
 
101 101
 		$constants = array();
102
-		foreach ( $raw_constants as $raw ) {
103
-			if ( ! defined( $raw ) ) {
102
+		foreach ($raw_constants as $raw) {
103
+			if (!defined($raw)) {
104 104
 				continue;
105 105
 			}
106 106
 
107
-			$path = wp_normalize_path( constant( $raw ) );
108
-			if ( isset( $path ) ) {
109
-				$constants[ $raw ] = $path;
107
+			$path = wp_normalize_path(constant($raw));
108
+			if (isset($path)) {
109
+				$constants[$raw] = $path;
110 110
 			}
111 111
 		}
112 112
 
@@ -120,18 +120,18 @@  discard block
 block discarded – undo
120 120
 	 *
121 121
 	 * @return bool True if the path is absolute, otherwise false.
122 122
 	 */
123
-	private function is_absolute_path( $path ) {
124
-		if ( 0 === strlen( $path ) || '.' === $path[0] ) {
123
+	private function is_absolute_path($path) {
124
+		if (0 === strlen($path) || '.' === $path[0]) {
125 125
 			return false;
126 126
 		}
127 127
 
128 128
 		// Absolute paths on Windows may begin with a drive letter.
129
-		if ( preg_match( '/^[a-zA-Z]:[\/\\\\]/', $path ) ) {
129
+		if (preg_match('/^[a-zA-Z]:[\/\\\\]/', $path)) {
130 130
 			return true;
131 131
 		}
132 132
 
133 133
 		// A path starting with / or \ is absolute; anything else is relative.
134
-		return ( '/' === $path[0] || '\\' === $path[0] );
134
+		return ('/' === $path[0] || '\\' === $path[0]);
135 135
 	}
136 136
 
137 137
 	/**
@@ -143,16 +143,16 @@  discard block
 block discarded – undo
143 143
 	 *
144 144
 	 * @return string|null The absolute path to the plugin file, otherwise null.
145 145
 	 */
146
-	private function find_absolute_plugin_path( $normalized_path, $directories_to_check ) {
146
+	private function find_absolute_plugin_path($normalized_path, $directories_to_check) {
147 147
 		// We're only able to find the absolute path for plugin/theme PHP files.
148
-		if ( ! is_string( $normalized_path ) || '.php' !== substr( $normalized_path, -4 ) ) {
148
+		if (!is_string($normalized_path) || '.php' !== substr($normalized_path, -4)) {
149 149
 			return null;
150 150
 		}
151 151
 
152
-		foreach ( $directories_to_check as $directory ) {
153
-			$normalized_check = wp_normalize_path( trailingslashit( $directory ) ) . $normalized_path;
152
+		foreach ($directories_to_check as $directory) {
153
+			$normalized_check = wp_normalize_path(trailingslashit($directory)) . $normalized_path;
154 154
 			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
155
-			if ( @is_file( $normalized_check ) ) {
155
+			if (@is_file($normalized_check)) {
156 156
 				return $normalized_check;
157 157
 			}
158 158
 		}
@@ -167,18 +167,18 @@  discard block
 block discarded – undo
167 167
 	 *
168 168
 	 * @return string The resolved path.
169 169
 	 */
170
-	private function get_real_path( $path ) {
170
+	private function get_real_path($path) {
171 171
 		// We want to resolve symbolic links for consistency with __DIR__ paths.
172 172
 		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
173
-		$real_path = @realpath( $path );
174
-		if ( false === $real_path ) {
173
+		$real_path = @realpath($path);
174
+		if (false === $real_path) {
175 175
 			// Let the autoloader deal with paths that don't exist.
176 176
 			$real_path = $path;
177 177
 		}
178 178
 
179 179
 		// Using realpath will make it platform-specific so we must normalize it after.
180
-		if ( $path !== $real_path ) {
181
-			$real_path = wp_normalize_path( $real_path );
180
+		if ($path !== $real_path) {
181
+			$real_path = wp_normalize_path($real_path);
182 182
 		}
183 183
 
184 184
 		return $real_path;
Please login to merge, or discard this patch.
vendor/automattic/jetpack-autoloader/src/class-version-selector.php 2 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -6,56 +6,56 @@
 block discarded – undo
6 6
  */
7 7
 class Version_Selector {
8 8
 
9
-	/**
10
-	 * Checks whether the selected package version should be updated. Composer development
11
-	 * package versions ('9999999-dev' or versions that start with 'dev-') are favored
12
-	 * when the JETPACK_AUTOLOAD_DEV constant is set to true.
13
-	 *
14
-	 * @param String $selected_version The currently selected package version.
15
-	 * @param String $compare_version The package version that is being evaluated to
16
-	 *                                determine if the version needs to be updated.
17
-	 *
18
-	 * @return bool Returns true if the selected package version should be updated,
19
-	 *                 else false.
20
-	 */
21
-	public function is_version_update_required( $selected_version, $compare_version ) {
22
-		$use_dev_versions = defined( 'JETPACK_AUTOLOAD_DEV' ) && JETPACK_AUTOLOAD_DEV;
23
-
24
-		if ( is_null( $selected_version ) ) {
25
-			return true;
26
-		}
27
-
28
-		if ( $use_dev_versions && $this->is_dev_version( $selected_version ) ) {
29
-			return false;
30
-		}
31
-
32
-		if ( $this->is_dev_version( $compare_version ) ) {
33
-			if ( $use_dev_versions ) {
34
-				return true;
35
-			} else {
36
-				return false;
37
-			}
38
-		}
39
-
40
-		if ( version_compare( $selected_version, $compare_version, '<' ) ) {
41
-			return true;
42
-		}
43
-
44
-		return false;
45
-	}
46
-
47
-	/**
48
-	 * Checks whether the given package version is a development version.
49
-	 *
50
-	 * @param String $version The package version.
51
-	 *
52
-	 * @return bool True if the version is a dev version, else false.
53
-	 */
54
-	public function is_dev_version( $version ) {
55
-		if ( 'dev-' === substr( $version, 0, 4 ) || '9999999-dev' === $version ) {
56
-			return true;
57
-		}
58
-
59
-		return false;
60
-	}
9
+    /**
10
+     * Checks whether the selected package version should be updated. Composer development
11
+     * package versions ('9999999-dev' or versions that start with 'dev-') are favored
12
+     * when the JETPACK_AUTOLOAD_DEV constant is set to true.
13
+     *
14
+     * @param String $selected_version The currently selected package version.
15
+     * @param String $compare_version The package version that is being evaluated to
16
+     *                                determine if the version needs to be updated.
17
+     *
18
+     * @return bool Returns true if the selected package version should be updated,
19
+     *                 else false.
20
+     */
21
+    public function is_version_update_required( $selected_version, $compare_version ) {
22
+        $use_dev_versions = defined( 'JETPACK_AUTOLOAD_DEV' ) && JETPACK_AUTOLOAD_DEV;
23
+
24
+        if ( is_null( $selected_version ) ) {
25
+            return true;
26
+        }
27
+
28
+        if ( $use_dev_versions && $this->is_dev_version( $selected_version ) ) {
29
+            return false;
30
+        }
31
+
32
+        if ( $this->is_dev_version( $compare_version ) ) {
33
+            if ( $use_dev_versions ) {
34
+                return true;
35
+            } else {
36
+                return false;
37
+            }
38
+        }
39
+
40
+        if ( version_compare( $selected_version, $compare_version, '<' ) ) {
41
+            return true;
42
+        }
43
+
44
+        return false;
45
+    }
46
+
47
+    /**
48
+     * Checks whether the given package version is a development version.
49
+     *
50
+     * @param String $version The package version.
51
+     *
52
+     * @return bool True if the version is a dev version, else false.
53
+     */
54
+    public function is_dev_version( $version ) {
55
+        if ( 'dev-' === substr( $version, 0, 4 ) || '9999999-dev' === $version ) {
56
+            return true;
57
+        }
58
+
59
+        return false;
60
+    }
61 61
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -18,26 +18,26 @@  discard block
 block discarded – undo
18 18
 	 * @return bool Returns true if the selected package version should be updated,
19 19
 	 *                 else false.
20 20
 	 */
21
-	public function is_version_update_required( $selected_version, $compare_version ) {
22
-		$use_dev_versions = defined( 'JETPACK_AUTOLOAD_DEV' ) && JETPACK_AUTOLOAD_DEV;
21
+	public function is_version_update_required($selected_version, $compare_version) {
22
+		$use_dev_versions = defined('JETPACK_AUTOLOAD_DEV') && JETPACK_AUTOLOAD_DEV;
23 23
 
24
-		if ( is_null( $selected_version ) ) {
24
+		if (is_null($selected_version)) {
25 25
 			return true;
26 26
 		}
27 27
 
28
-		if ( $use_dev_versions && $this->is_dev_version( $selected_version ) ) {
28
+		if ($use_dev_versions && $this->is_dev_version($selected_version)) {
29 29
 			return false;
30 30
 		}
31 31
 
32
-		if ( $this->is_dev_version( $compare_version ) ) {
33
-			if ( $use_dev_versions ) {
32
+		if ($this->is_dev_version($compare_version)) {
33
+			if ($use_dev_versions) {
34 34
 				return true;
35 35
 			} else {
36 36
 				return false;
37 37
 			}
38 38
 		}
39 39
 
40
-		if ( version_compare( $selected_version, $compare_version, '<' ) ) {
40
+		if (version_compare($selected_version, $compare_version, '<')) {
41 41
 			return true;
42 42
 		}
43 43
 
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @return bool True if the version is a dev version, else false.
53 53
 	 */
54
-	public function is_dev_version( $version ) {
55
-		if ( 'dev-' === substr( $version, 0, 4 ) || '9999999-dev' === $version ) {
54
+	public function is_dev_version($version) {
55
+		if ('dev-' === substr($version, 0, 4) || '9999999-dev' === $version) {
56 56
 			return true;
57 57
 		}
58 58
 
Please login to merge, or discard this patch.
vendor/automattic/jetpack-autoloader/src/class-autoloader-locator.php 2 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -8,75 +8,75 @@
 block discarded – undo
8 8
  */
9 9
 class Autoloader_Locator {
10 10
 
11
-	/**
12
-	 * The object for comparing autoloader versions.
13
-	 *
14
-	 * @var Version_Selector
15
-	 */
16
-	private $version_selector;
11
+    /**
12
+     * The object for comparing autoloader versions.
13
+     *
14
+     * @var Version_Selector
15
+     */
16
+    private $version_selector;
17 17
 
18
-	/**
19
-	 * The constructor.
20
-	 *
21
-	 * @param Version_Selector $version_selector The version selector object.
22
-	 */
23
-	public function __construct( $version_selector ) {
24
-		$this->version_selector = $version_selector;
25
-	}
18
+    /**
19
+     * The constructor.
20
+     *
21
+     * @param Version_Selector $version_selector The version selector object.
22
+     */
23
+    public function __construct( $version_selector ) {
24
+        $this->version_selector = $version_selector;
25
+    }
26 26
 
27
-	/**
28
-	 * Finds the path to the plugin with the latest autoloader.
29
-	 *
30
-	 * @param array  $plugin_paths An array of plugin paths.
31
-	 * @param string $latest_version The latest version reference.
32
-	 *
33
-	 * @return string|null
34
-	 */
35
-	public function find_latest_autoloader( $plugin_paths, &$latest_version ) {
36
-		$latest_plugin = null;
27
+    /**
28
+     * Finds the path to the plugin with the latest autoloader.
29
+     *
30
+     * @param array  $plugin_paths An array of plugin paths.
31
+     * @param string $latest_version The latest version reference.
32
+     *
33
+     * @return string|null
34
+     */
35
+    public function find_latest_autoloader( $plugin_paths, &$latest_version ) {
36
+        $latest_plugin = null;
37 37
 
38
-		foreach ( $plugin_paths as $plugin_path ) {
39
-			$version = $this->get_autoloader_version( $plugin_path );
40
-			if ( ! $this->version_selector->is_version_update_required( $latest_version, $version ) ) {
41
-				continue;
42
-			}
38
+        foreach ( $plugin_paths as $plugin_path ) {
39
+            $version = $this->get_autoloader_version( $plugin_path );
40
+            if ( ! $this->version_selector->is_version_update_required( $latest_version, $version ) ) {
41
+                continue;
42
+            }
43 43
 
44
-			$latest_version = $version;
45
-			$latest_plugin  = $plugin_path;
46
-		}
44
+            $latest_version = $version;
45
+            $latest_plugin  = $plugin_path;
46
+        }
47 47
 
48
-		return $latest_plugin;
49
-	}
48
+        return $latest_plugin;
49
+    }
50 50
 
51
-	/**
52
-	 * Gets the path to the autoloader.
53
-	 *
54
-	 * @param string $plugin_path The path to the plugin.
55
-	 *
56
-	 * @return string
57
-	 */
58
-	public function get_autoloader_path( $plugin_path ) {
59
-		return trailingslashit( $plugin_path ) . 'vendor/autoload_packages.php';
60
-	}
51
+    /**
52
+     * Gets the path to the autoloader.
53
+     *
54
+     * @param string $plugin_path The path to the plugin.
55
+     *
56
+     * @return string
57
+     */
58
+    public function get_autoloader_path( $plugin_path ) {
59
+        return trailingslashit( $plugin_path ) . 'vendor/autoload_packages.php';
60
+    }
61 61
 
62
-	/**
63
-	 * Gets the version for the autoloader.
64
-	 *
65
-	 * @param string $plugin_path The path to the plugin.
66
-	 *
67
-	 * @return string|null
68
-	 */
69
-	public function get_autoloader_version( $plugin_path ) {
70
-		$classmap = trailingslashit( $plugin_path ) . 'vendor/composer/jetpack_autoload_classmap.php';
71
-		if ( ! file_exists( $classmap ) ) {
72
-			return null;
73
-		}
62
+    /**
63
+     * Gets the version for the autoloader.
64
+     *
65
+     * @param string $plugin_path The path to the plugin.
66
+     *
67
+     * @return string|null
68
+     */
69
+    public function get_autoloader_version( $plugin_path ) {
70
+        $classmap = trailingslashit( $plugin_path ) . 'vendor/composer/jetpack_autoload_classmap.php';
71
+        if ( ! file_exists( $classmap ) ) {
72
+            return null;
73
+        }
74 74
 
75
-		$classmap = require $classmap;
76
-		if ( isset( $classmap[ AutoloadGenerator::class ] ) ) {
77
-			return $classmap[ AutoloadGenerator::class ]['version'];
78
-		}
75
+        $classmap = require $classmap;
76
+        if ( isset( $classmap[ AutoloadGenerator::class ] ) ) {
77
+            return $classmap[ AutoloadGenerator::class ]['version'];
78
+        }
79 79
 
80
-		return null;
81
-	}
80
+        return null;
81
+    }
82 82
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 *
21 21
 	 * @param Version_Selector $version_selector The version selector object.
22 22
 	 */
23
-	public function __construct( $version_selector ) {
23
+	public function __construct($version_selector) {
24 24
 		$this->version_selector = $version_selector;
25 25
 	}
26 26
 
@@ -32,12 +32,12 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @return string|null
34 34
 	 */
35
-	public function find_latest_autoloader( $plugin_paths, &$latest_version ) {
35
+	public function find_latest_autoloader($plugin_paths, &$latest_version) {
36 36
 		$latest_plugin = null;
37 37
 
38
-		foreach ( $plugin_paths as $plugin_path ) {
39
-			$version = $this->get_autoloader_version( $plugin_path );
40
-			if ( ! $this->version_selector->is_version_update_required( $latest_version, $version ) ) {
38
+		foreach ($plugin_paths as $plugin_path) {
39
+			$version = $this->get_autoloader_version($plugin_path);
40
+			if (!$this->version_selector->is_version_update_required($latest_version, $version)) {
41 41
 				continue;
42 42
 			}
43 43
 
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
 	 *
56 56
 	 * @return string
57 57
 	 */
58
-	public function get_autoloader_path( $plugin_path ) {
59
-		return trailingslashit( $plugin_path ) . 'vendor/autoload_packages.php';
58
+	public function get_autoloader_path($plugin_path) {
59
+		return trailingslashit($plugin_path) . 'vendor/autoload_packages.php';
60 60
 	}
61 61
 
62 62
 	/**
@@ -66,15 +66,15 @@  discard block
 block discarded – undo
66 66
 	 *
67 67
 	 * @return string|null
68 68
 	 */
69
-	public function get_autoloader_version( $plugin_path ) {
70
-		$classmap = trailingslashit( $plugin_path ) . 'vendor/composer/jetpack_autoload_classmap.php';
71
-		if ( ! file_exists( $classmap ) ) {
69
+	public function get_autoloader_version($plugin_path) {
70
+		$classmap = trailingslashit($plugin_path) . 'vendor/composer/jetpack_autoload_classmap.php';
71
+		if (!file_exists($classmap)) {
72 72
 			return null;
73 73
 		}
74 74
 
75 75
 		$classmap = require $classmap;
76
-		if ( isset( $classmap[ AutoloadGenerator::class ] ) ) {
77
-			return $classmap[ AutoloadGenerator::class ]['version'];
76
+		if (isset($classmap[AutoloadGenerator::class])) {
77
+			return $classmap[AutoloadGenerator::class]['version'];
78 78
 		}
79 79
 
80 80
 		return null;
Please login to merge, or discard this patch.
woocommerce-blocks/templates/emails/plain/customer-new-account-blocks.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 echo sprintf( esc_html__( 'Thanks for creating an account on %1$s. Your username is %2$s. You can access your account area to view orders, change your password, and more at: %3$s', 'woocommerce' ), esc_html( $blogname ), esc_html( $user_login ), esc_html( wc_get_page_permalink( 'myaccount' ) ) ) . "\n\n";
22 22
 
23 23
 if ( $set_password_url ) {
24
-	echo esc_html__( 'To set your password, visit the following address: ', 'woocommerce' ) . "\n\n";
25
-	echo esc_html( $set_password_url ) . "\n\n";
24
+    echo esc_html__( 'To set your password, visit the following address: ', 'woocommerce' ) . "\n\n";
25
+    echo esc_html( $set_password_url ) . "\n\n";
26 26
 }
27 27
 
28 28
 echo "\n\n----------------------------------------\n\n";
@@ -31,8 +31,8 @@  discard block
 block discarded – undo
31 31
  * Show user-defined additional content - this is set in each email's settings.
32 32
  */
33 33
 if ( $additional_content ) {
34
-	echo esc_html( wp_strip_all_tags( wptexturize( $additional_content ) ) );
35
-	echo "\n\n----------------------------------------\n\n";
34
+    echo esc_html( wp_strip_all_tags( wptexturize( $additional_content ) ) );
35
+    echo "\n\n----------------------------------------\n\n";
36 36
 }
37 37
 
38 38
 echo wp_kses_post( apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' ) ) );
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -9,20 +9,20 @@  discard block
 block discarded – undo
9 9
  * @package  WooCommerce/Blocks
10 10
  */
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
15
-echo esc_html( wp_strip_all_tags( $email_heading ) );
15
+echo esc_html(wp_strip_all_tags($email_heading));
16 16
 echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
17 17
 
18 18
 /* translators: %s: Customer username */
19
-echo sprintf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $user_login ) ) . "\n\n";
19
+echo sprintf(esc_html__('Hi %s,', 'woocommerce'), esc_html($user_login)) . "\n\n";
20 20
 /* translators: %1$s: Site title, %2$s: Username, %3$s: My account link */
21
-echo sprintf( esc_html__( 'Thanks for creating an account on %1$s. Your username is %2$s. You can access your account area to view orders, change your password, and more at: %3$s', 'woocommerce' ), esc_html( $blogname ), esc_html( $user_login ), esc_html( wc_get_page_permalink( 'myaccount' ) ) ) . "\n\n";
21
+echo sprintf(esc_html__('Thanks for creating an account on %1$s. Your username is %2$s. You can access your account area to view orders, change your password, and more at: %3$s', 'woocommerce'), esc_html($blogname), esc_html($user_login), esc_html(wc_get_page_permalink('myaccount'))) . "\n\n";
22 22
 
23
-if ( $set_password_url ) {
24
-	echo esc_html__( 'To set your password, visit the following address: ', 'woocommerce' ) . "\n\n";
25
-	echo esc_html( $set_password_url ) . "\n\n";
23
+if ($set_password_url) {
24
+	echo esc_html__('To set your password, visit the following address: ', 'woocommerce') . "\n\n";
25
+	echo esc_html($set_password_url) . "\n\n";
26 26
 }
27 27
 
28 28
 echo "\n\n----------------------------------------\n\n";
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
 /**
31 31
  * Show user-defined additional content - this is set in each email's settings.
32 32
  */
33
-if ( $additional_content ) {
34
-	echo esc_html( wp_strip_all_tags( wptexturize( $additional_content ) ) );
33
+if ($additional_content) {
34
+	echo esc_html(wp_strip_all_tags(wptexturize($additional_content)));
35 35
 	echo "\n\n----------------------------------------\n\n";
36 36
 }
37 37
 
38
-echo wp_kses_post( apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' ) ) );
38
+echo wp_kses_post(apply_filters('woocommerce_email_footer_text', get_option('woocommerce_email_footer_text')));
Please login to merge, or discard this patch.
woocommerce-blocks/templates/emails/customer-new-account-blocks.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
  * Show user-defined additional content - this is set in each email's settings.
34 34
  */
35 35
 if ( $additional_content ) {
36
-	echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
36
+    echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
37 37
 }
38 38
 
39 39
 do_action( 'woocommerce_email_footer', $email );
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -9,24 +9,24 @@
 block discarded – undo
9 9
  * @package  WooCommerce/Blocks
10 10
  */
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14
-do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
14
+do_action('woocommerce_email_header', $email_heading, $email); ?>
15 15
 
16 16
 <?php /* translators: %s: Customer username */ ?>
17
-<p><?php printf( esc_html__( 'Hello %s,', 'woocommerce' ), esc_html( $user_login ) ); ?></p>
17
+<p><?php printf(esc_html__('Hello %s,', 'woocommerce'), esc_html($user_login)); ?></p>
18 18
 <?php /* translators: %1$s: Site title, %2$s: Username, %3$s: My account link */ ?>
19
-<p><?php printf( esc_html__( 'Thanks for creating an account on %1$s. Your username is %2$s. You can access your account area to view orders, change your password, and more at: %3$s', 'woocommerce' ), esc_html( $blogname ), '<strong>' . esc_html( $user_login ) . '</strong>', make_clickable( esc_url( wc_get_page_permalink( 'myaccount' ) ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
20
-<?php if ( $set_password_url ) : ?>
21
-	<p><a href="<?php echo esc_attr( $set_password_url ); ?>"><?php printf( esc_html__( 'Click here to set your new password.', 'woocommerce' ) ); ?></a></p>
19
+<p><?php printf(esc_html__('Thanks for creating an account on %1$s. Your username is %2$s. You can access your account area to view orders, change your password, and more at: %3$s', 'woocommerce'), esc_html($blogname), '<strong>' . esc_html($user_login) . '</strong>', make_clickable(esc_url(wc_get_page_permalink('myaccount')))); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
20
+<?php if ($set_password_url) : ?>
21
+	<p><a href="<?php echo esc_attr($set_password_url); ?>"><?php printf(esc_html__('Click here to set your new password.', 'woocommerce')); ?></a></p>
22 22
 <?php endif; ?>
23 23
 
24 24
 <?php
25 25
 /**
26 26
  * Show user-defined additional content - this is set in each email's settings.
27 27
  */
28
-if ( $additional_content ) {
29
-	echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
28
+if ($additional_content) {
29
+	echo wp_kses_post(wpautop(wptexturize($additional_content)));
30 30
 }
31 31
 
32
-do_action( 'woocommerce_email_footer', $email );
32
+do_action('woocommerce_email_footer', $email);
Please login to merge, or discard this patch.
plugins/woocommerce/packages/woocommerce-blocks/src/Assets.php 2 patches
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -12,84 +12,84 @@
 block discarded – undo
12 12
  */
13 13
 class Assets {
14 14
 
15
-	/**
16
-	 * Initialize class features on init.
17
-	 *
18
-	 * @since 2.5.0
19
-	 * @deprecated 5.0.0
20
-	 */
21
-	public static function init() {
22
-		_deprecated_function( 'Assets::init', '5.0.0' );
23
-	}
15
+    /**
16
+     * Initialize class features on init.
17
+     *
18
+     * @since 2.5.0
19
+     * @deprecated 5.0.0
20
+     */
21
+    public static function init() {
22
+        _deprecated_function( 'Assets::init', '5.0.0' );
23
+    }
24 24
 
25
-	/**
26
-	 * Register block scripts & styles.
27
-	 *
28
-	 * @since 2.5.0
29
-	 * @deprecated 5.0.0
30
-	 */
31
-	public static function register_assets() {
32
-		_deprecated_function( 'Assets::register_assets', '5.0.0' );
33
-	}
25
+    /**
26
+     * Register block scripts & styles.
27
+     *
28
+     * @since 2.5.0
29
+     * @deprecated 5.0.0
30
+     */
31
+    public static function register_assets() {
32
+        _deprecated_function( 'Assets::register_assets', '5.0.0' );
33
+    }
34 34
 
35
-	/**
36
-	 * Register the vendors style file. We need to do it after the other files
37
-	 * because we need to check if `wp-edit-post` has been enqueued.
38
-	 *
39
-	 * @deprecated 5.0.0
40
-	 */
41
-	public static function enqueue_scripts() {
42
-		_deprecated_function( 'Assets::enqueue_scripts', '5.0.0' );
43
-	}
35
+    /**
36
+     * Register the vendors style file. We need to do it after the other files
37
+     * because we need to check if `wp-edit-post` has been enqueued.
38
+     *
39
+     * @deprecated 5.0.0
40
+     */
41
+    public static function enqueue_scripts() {
42
+        _deprecated_function( 'Assets::enqueue_scripts', '5.0.0' );
43
+    }
44 44
 
45
-	/**
46
-	 * Add body classes.
47
-	 *
48
-	 * @deprecated 5.0.0
49
-	 * @param array $classes Array of CSS classnames.
50
-	 * @return array Modified array of CSS classnames.
51
-	 */
52
-	public static function add_theme_body_class( $classes = [] ) {
53
-		_deprecated_function( 'Assets::add_theme_body_class', '5.0.0' );
54
-		return $classes;
55
-	}
45
+    /**
46
+     * Add body classes.
47
+     *
48
+     * @deprecated 5.0.0
49
+     * @param array $classes Array of CSS classnames.
50
+     * @return array Modified array of CSS classnames.
51
+     */
52
+    public static function add_theme_body_class( $classes = [] ) {
53
+        _deprecated_function( 'Assets::add_theme_body_class', '5.0.0' );
54
+        return $classes;
55
+    }
56 56
 
57
-	/**
58
-	 * Add theme class to admin body.
59
-	 *
60
-	 * @deprecated 5.0.0
61
-	 * @param array $classes String with the CSS classnames.
62
-	 * @return array Modified string of CSS classnames.
63
-	 */
64
-	public static function add_theme_admin_body_class( $classes = '' ) {
65
-		_deprecated_function( 'Assets::add_theme_admin_body_class', '5.0.0' );
66
-		return $classes;
67
-	}
57
+    /**
58
+     * Add theme class to admin body.
59
+     *
60
+     * @deprecated 5.0.0
61
+     * @param array $classes String with the CSS classnames.
62
+     * @return array Modified string of CSS classnames.
63
+     */
64
+    public static function add_theme_admin_body_class( $classes = '' ) {
65
+        _deprecated_function( 'Assets::add_theme_admin_body_class', '5.0.0' );
66
+        return $classes;
67
+    }
68 68
 
69
-	/**
70
-	 * Adds a redirect field to the login form so blocks can redirect users after login.
71
-	 *
72
-	 * @deprecated 5.0.0
73
-	 */
74
-	public static function redirect_to_field() {
75
-		_deprecated_function( 'Assets::redirect_to_field', '5.0.0' );
76
-	}
69
+    /**
70
+     * Adds a redirect field to the login form so blocks can redirect users after login.
71
+     *
72
+     * @deprecated 5.0.0
73
+     */
74
+    public static function redirect_to_field() {
75
+        _deprecated_function( 'Assets::redirect_to_field', '5.0.0' );
76
+    }
77 77
 
78
-	/**
79
-	 * Queues a block script in the frontend.
80
-	 *
81
-	 * @since 2.3.0
82
-	 * @since 2.6.0 Changed $name to $script_name and added $handle argument.
83
-	 * @since 2.9.0 Made it so scripts are not loaded in admin pages.
84
-	 * @deprecated 4.5.0 Block types register the scripts themselves.
85
-	 *
86
-	 * @param string $script_name  Name of the script used to identify the file inside build folder.
87
-	 * @param string $handle       Optional. Provided if the handle should be different than the script name. `wc-` prefix automatically added.
88
-	 * @param array  $dependencies Optional. An array of registered script handles this script depends on. Default empty array.
89
-	 */
90
-	public static function register_block_script( $script_name, $handle = '', $dependencies = [] ) {
91
-		_deprecated_function( 'register_block_script', '4.5.0' );
92
-		$asset_api = Package::container()->get( AssetApi::class );
93
-		$asset_api->register_block_script( $script_name, $handle, $dependencies );
94
-	}
78
+    /**
79
+     * Queues a block script in the frontend.
80
+     *
81
+     * @since 2.3.0
82
+     * @since 2.6.0 Changed $name to $script_name and added $handle argument.
83
+     * @since 2.9.0 Made it so scripts are not loaded in admin pages.
84
+     * @deprecated 4.5.0 Block types register the scripts themselves.
85
+     *
86
+     * @param string $script_name  Name of the script used to identify the file inside build folder.
87
+     * @param string $handle       Optional. Provided if the handle should be different than the script name. `wc-` prefix automatically added.
88
+     * @param array  $dependencies Optional. An array of registered script handles this script depends on. Default empty array.
89
+     */
90
+    public static function register_block_script( $script_name, $handle = '', $dependencies = [] ) {
91
+        _deprecated_function( 'register_block_script', '4.5.0' );
92
+        $asset_api = Package::container()->get( AssetApi::class );
93
+        $asset_api->register_block_script( $script_name, $handle, $dependencies );
94
+    }
95 95
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	 * @deprecated 5.0.0
20 20
 	 */
21 21
 	public static function init() {
22
-		_deprecated_function( 'Assets::init', '5.0.0' );
22
+		_deprecated_function('Assets::init', '5.0.0');
23 23
 	}
24 24
 
25 25
 	/**
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * @deprecated 5.0.0
30 30
 	 */
31 31
 	public static function register_assets() {
32
-		_deprecated_function( 'Assets::register_assets', '5.0.0' );
32
+		_deprecated_function('Assets::register_assets', '5.0.0');
33 33
 	}
34 34
 
35 35
 	/**
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	 * @deprecated 5.0.0
40 40
 	 */
41 41
 	public static function enqueue_scripts() {
42
-		_deprecated_function( 'Assets::enqueue_scripts', '5.0.0' );
42
+		_deprecated_function('Assets::enqueue_scripts', '5.0.0');
43 43
 	}
44 44
 
45 45
 	/**
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 	 * @param array $classes Array of CSS classnames.
50 50
 	 * @return array Modified array of CSS classnames.
51 51
 	 */
52
-	public static function add_theme_body_class( $classes = [] ) {
53
-		_deprecated_function( 'Assets::add_theme_body_class', '5.0.0' );
52
+	public static function add_theme_body_class($classes = []) {
53
+		_deprecated_function('Assets::add_theme_body_class', '5.0.0');
54 54
 		return $classes;
55 55
 	}
56 56
 
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 	 * @param array $classes String with the CSS classnames.
62 62
 	 * @return array Modified string of CSS classnames.
63 63
 	 */
64
-	public static function add_theme_admin_body_class( $classes = '' ) {
65
-		_deprecated_function( 'Assets::add_theme_admin_body_class', '5.0.0' );
64
+	public static function add_theme_admin_body_class($classes = '') {
65
+		_deprecated_function('Assets::add_theme_admin_body_class', '5.0.0');
66 66
 		return $classes;
67 67
 	}
68 68
 
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 * @deprecated 5.0.0
73 73
 	 */
74 74
 	public static function redirect_to_field() {
75
-		_deprecated_function( 'Assets::redirect_to_field', '5.0.0' );
75
+		_deprecated_function('Assets::redirect_to_field', '5.0.0');
76 76
 	}
77 77
 
78 78
 	/**
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 	 * @param string $handle       Optional. Provided if the handle should be different than the script name. `wc-` prefix automatically added.
88 88
 	 * @param array  $dependencies Optional. An array of registered script handles this script depends on. Default empty array.
89 89
 	 */
90
-	public static function register_block_script( $script_name, $handle = '', $dependencies = [] ) {
91
-		_deprecated_function( 'register_block_script', '4.5.0' );
92
-		$asset_api = Package::container()->get( AssetApi::class );
93
-		$asset_api->register_block_script( $script_name, $handle, $dependencies );
90
+	public static function register_block_script($script_name, $handle = '', $dependencies = []) {
91
+		_deprecated_function('register_block_script', '4.5.0');
92
+		$asset_api = Package::container()->get(AssetApi::class);
93
+		$asset_api->register_block_script($script_name, $handle, $dependencies);
94 94
 	}
95 95
 }
Please login to merge, or discard this patch.
woocommerce/packages/woocommerce-blocks/src/BlockTemplatesController.php 2 patches
Indentation   +399 added lines, -399 removed lines patch added patch discarded remove patch
@@ -10,403 +10,403 @@
 block discarded – undo
10 10
  */
11 11
 class BlockTemplatesController {
12 12
 
13
-	/**
14
-	 * Holds the path for the directory where the block templates will be kept.
15
-	 *
16
-	 * @var string
17
-	 */
18
-	private $templates_directory;
19
-
20
-	/**
21
-	 * Holds the path for the directory where the block template parts will be kept.
22
-	 *
23
-	 * @var string
24
-	 */
25
-	private $template_parts_directory;
26
-
27
-	/**
28
-	 * Directory which contains all templates
29
-	 *
30
-	 * @var string
31
-	 */
32
-	const TEMPLATES_ROOT_DIR = 'templates';
33
-
34
-	/**
35
-	 * Constructor.
36
-	 */
37
-	public function __construct() {
38
-		// This feature is gated for WooCommerce versions 6.0.0 and above.
39
-		if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '6.0.0', '>=' ) ) {
40
-			$root_path                      = plugin_dir_path( __DIR__ ) . self::TEMPLATES_ROOT_DIR . DIRECTORY_SEPARATOR;
41
-			$this->templates_directory      = $root_path . BlockTemplateUtils::DIRECTORY_NAMES['TEMPLATES'];
42
-			$this->template_parts_directory = $root_path . BlockTemplateUtils::DIRECTORY_NAMES['TEMPLATE_PARTS'];
43
-			$this->init();
44
-		}
45
-	}
46
-
47
-	/**
48
-	 * Initialization method.
49
-	 */
50
-	protected function init() {
51
-		add_action( 'template_redirect', array( $this, 'render_block_template' ) );
52
-		add_filter( 'pre_get_block_file_template', array( $this, 'get_block_file_template' ), 10, 3 );
53
-		add_filter( 'get_block_templates', array( $this, 'add_block_templates' ), 10, 3 );
54
-		add_filter( 'current_theme_supports-block-templates', array( $this, 'remove_block_template_support_for_shop_page' ) );
55
-	}
56
-
57
-	/**
58
-	 * This function checks if there's a block template file in `woo-gutenberg-products-block/templates/templates/`
59
-	 * to return to pre_get_posts short-circuiting the query in Gutenberg.
60
-	 *
61
-	 * @param \WP_Block_Template|null $template Return a block template object to short-circuit the default query,
62
-	 *                                               or null to allow WP to run its normal queries.
63
-	 * @param string                  $id Template unique identifier (example: theme_slug//template_slug).
64
-	 * @param string                  $template_type wp_template or wp_template_part.
65
-	 *
66
-	 * @return mixed|\WP_Block_Template|\WP_Error
67
-	 */
68
-	public function get_block_file_template( $template, $id, $template_type ) {
69
-		$template_name_parts = explode( '//', $id );
70
-
71
-		if ( count( $template_name_parts ) < 2 ) {
72
-			return $template;
73
-		}
74
-
75
-		list( $template_id, $template_slug ) = $template_name_parts;
76
-
77
-		// If the theme has an archive-product.html template, but not a taxonomy-product_cat/tag.html template let's use the themes archive-product.html template.
78
-		if ( BlockTemplateUtils::template_is_eligible_for_product_archive_fallback( $template_slug ) ) {
79
-			$template_path   = BlockTemplateUtils::get_theme_template_path( 'archive-product' );
80
-			$template_object = BlockTemplateUtils::create_new_block_template_object( $template_path, $template_type, $template_slug, true );
81
-			return BlockTemplateUtils::build_template_result_from_file( $template_object, $template_type );
82
-		}
83
-
84
-		// This is a real edge-case, we are supporting users who have saved templates under the deprecated slug. See its definition for more information.
85
-		// You can likely ignore this code unless you're supporting/debugging early customised templates.
86
-		if ( BlockTemplateUtils::DEPRECATED_PLUGIN_SLUG === strtolower( $template_id ) ) {
87
-			// Because we are using get_block_templates we have to unhook this method to prevent a recursive loop where this filter is applied.
88
-			remove_filter( 'pre_get_block_file_template', array( $this, 'get_block_file_template' ), 10, 3 );
89
-			$template_with_deprecated_id = BlockTemplateUtils::get_block_template( $id, $template_type );
90
-			// Let's hook this method back now that we have used the function.
91
-			add_filter( 'pre_get_block_file_template', array( $this, 'get_block_file_template' ), 10, 3 );
92
-
93
-			if ( null !== $template_with_deprecated_id ) {
94
-				return $template_with_deprecated_id;
95
-			}
96
-		}
97
-
98
-		// If we are not dealing with a WooCommerce template let's return early and let it continue through the process.
99
-		if ( BlockTemplateUtils::PLUGIN_SLUG !== $template_id ) {
100
-			return $template;
101
-		}
102
-
103
-		// If we don't have a template let Gutenberg do its thing.
104
-		if ( ! $this->block_template_is_available( $template_slug, $template_type ) ) {
105
-			return $template;
106
-		}
107
-
108
-		$directory          = $this->get_templates_directory( $template_type );
109
-		$template_file_path = $directory . '/' . $template_slug . '.html';
110
-		$template_object    = BlockTemplateUtils::create_new_block_template_object( $template_file_path, $template_type, $template_slug );
111
-		$template_built     = BlockTemplateUtils::build_template_result_from_file( $template_object, $template_type );
112
-
113
-		if ( null !== $template_built ) {
114
-			return $template_built;
115
-		}
116
-
117
-		// Hand back over to Gutenberg if we can't find a template.
118
-		return $template;
119
-	}
120
-
121
-	/**
122
-	 * Add the block template objects to be used.
123
-	 *
124
-	 * @param array $query_result Array of template objects.
125
-	 * @param array $query Optional. Arguments to retrieve templates.
126
-	 * @param array $template_type wp_template or wp_template_part.
127
-	 * @return array
128
-	 */
129
-	public function add_block_templates( $query_result, $query, $template_type ) {
130
-		if ( ! BlockTemplateUtils::supports_block_templates() ) {
131
-			return $query_result;
132
-		}
133
-
134
-		$post_type      = isset( $query['post_type'] ) ? $query['post_type'] : '';
135
-		$slugs          = isset( $query['slug__in'] ) ? $query['slug__in'] : array();
136
-		$template_files = $this->get_block_templates( $slugs, $template_type );
137
-
138
-		// @todo: Add apply_filters to _gutenberg_get_template_files() in Gutenberg to prevent duplication of logic.
139
-		foreach ( $template_files as $template_file ) {
140
-
141
-			// If we have a template which is eligible for a fallback, we need to explicitly tell Gutenberg that
142
-			// it has a theme file (because it is using the fallback template file). And then `continue` to avoid
143
-			// adding duplicates.
144
-			if ( BlockTemplateUtils::set_has_theme_file_if_fallback_is_available( $query_result, $template_file ) ) {
145
-				continue;
146
-			}
147
-
148
-			// If the current $post_type is set (e.g. on an Edit Post screen), and isn't included in the available post_types
149
-			// on the template file, then lets skip it so that it doesn't get added. This is typically used to hide templates
150
-			// in the template dropdown on the Edit Post page.
151
-			if ( $post_type &&
152
-				isset( $template_file->post_types ) &&
153
-				! in_array( $post_type, $template_file->post_types, true )
154
-			) {
155
-				continue;
156
-			}
157
-
158
-			// It would be custom if the template was modified in the editor, so if it's not custom we can load it from
159
-			// the filesystem.
160
-			if ( 'custom' !== $template_file->source ) {
161
-				$template = BlockTemplateUtils::build_template_result_from_file( $template_file, $template_type );
162
-			} else {
163
-				$template_file->title       = BlockTemplateUtils::get_block_template_title( $template_file->slug );
164
-				$template_file->description = BlockTemplateUtils::get_block_template_description( $template_file->slug );
165
-				$query_result[]             = $template_file;
166
-				continue;
167
-			}
168
-
169
-			$is_not_custom   = false === array_search(
170
-				wp_get_theme()->get_stylesheet() . '//' . $template_file->slug,
171
-				array_column( $query_result, 'id' ),
172
-				true
173
-			);
174
-			$fits_slug_query =
175
-				! isset( $query['slug__in'] ) || in_array( $template_file->slug, $query['slug__in'], true );
176
-			$fits_area_query =
177
-				! isset( $query['area'] ) || $template_file->area === $query['area'];
178
-			$should_include  = $is_not_custom && $fits_slug_query && $fits_area_query;
179
-			if ( $should_include ) {
180
-				$query_result[] = $template;
181
-			}
182
-		}
183
-
184
-		// We need to remove theme (i.e. filesystem) templates that have the same slug as a customised one.
185
-		// This only affects saved templates that were saved BEFORE a theme template with the same slug was added.
186
-		$query_result = BlockTemplateUtils::remove_theme_templates_with_custom_alternative( $query_result );
187
-
188
-		/**
189
-		 * WC templates from theme aren't included in `$this->get_block_templates()` but are handled by Gutenberg.
190
-		 * We need to do additional search through all templates file to update title and description for WC
191
-		 * templates that aren't listed in theme.json.
192
-		 */
193
-		$query_result = array_map(
194
-			function( $template ) {
195
-				if ( 'theme' === $template->origin ) {
196
-					return $template;
197
-				}
198
-				if ( $template->title === $template->slug ) {
199
-					$template->title = BlockTemplateUtils::get_block_template_title( $template->slug );
200
-				}
201
-				if ( ! $template->description ) {
202
-					$template->description = BlockTemplateUtils::get_block_template_description( $template->slug );
203
-				}
204
-				return $template;
205
-			},
206
-			$query_result
207
-		);
208
-
209
-		return $query_result;
210
-	}
211
-
212
-	/**
213
-	 * Gets the templates saved in the database.
214
-	 *
215
-	 * @param array $slugs An array of slugs to retrieve templates for.
216
-	 * @param array $template_type wp_template or wp_template_part.
217
-	 *
218
-	 * @return int[]|\WP_Post[] An array of found templates.
219
-	 */
220
-	public function get_block_templates_from_db( $slugs = array(), $template_type = 'wp_template' ) {
221
-		$check_query_args = array(
222
-			'post_type'      => $template_type,
223
-			'posts_per_page' => -1,
224
-			'no_found_rows'  => true,
225
-			'tax_query'      => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
226
-				array(
227
-					'taxonomy' => 'wp_theme',
228
-					'field'    => 'name',
229
-					'terms'    => array( BlockTemplateUtils::DEPRECATED_PLUGIN_SLUG, BlockTemplateUtils::PLUGIN_SLUG, get_stylesheet() ),
230
-				),
231
-			),
232
-		);
233
-
234
-		if ( is_array( $slugs ) && count( $slugs ) > 0 ) {
235
-			$check_query_args['post_name__in'] = $slugs;
236
-		}
237
-
238
-		$check_query         = new \WP_Query( $check_query_args );
239
-		$saved_woo_templates = $check_query->posts;
240
-
241
-		return array_map(
242
-			function( $saved_woo_template ) {
243
-				return BlockTemplateUtils::build_template_result_from_post( $saved_woo_template );
244
-			},
245
-			$saved_woo_templates
246
-		);
247
-	}
248
-
249
-	/**
250
-	 * Gets the templates from the WooCommerce blocks directory, skipping those for which a template already exists
251
-	 * in the theme directory.
252
-	 *
253
-	 * @param string[] $slugs An array of slugs to filter templates by. Templates whose slug does not match will not be returned.
254
-	 * @param array    $already_found_templates Templates that have already been found, these are customised templates that are loaded from the database.
255
-	 * @param string   $template_type wp_template or wp_template_part.
256
-	 *
257
-	 * @return array Templates from the WooCommerce blocks plugin directory.
258
-	 */
259
-	public function get_block_templates_from_woocommerce( $slugs, $already_found_templates, $template_type = 'wp_template' ) {
260
-		$directory      = $this->get_templates_directory( $template_type );
261
-		$template_files = BlockTemplateUtils::get_template_paths( $directory );
262
-		$templates      = array();
263
-
264
-		foreach ( $template_files as $template_file ) {
265
-			$template_slug = BlockTemplateUtils::generate_template_slug_from_path( $template_file );
266
-
267
-			// This template does not have a slug we're looking for. Skip it.
268
-			if ( is_array( $slugs ) && count( $slugs ) > 0 && ! in_array( $template_slug, $slugs, true ) ) {
269
-				continue;
270
-			}
271
-
272
-			// If the theme already has a template, or the template is already in the list (i.e. it came from the
273
-			// database) then we should not overwrite it with the one from the filesystem.
274
-			if (
275
-				BlockTemplateUtils::theme_has_template( $template_slug ) ||
276
-				count(
277
-					array_filter(
278
-						$already_found_templates,
279
-						function ( $template ) use ( $template_slug ) {
280
-							$template_obj = (object) $template; //phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
281
-							return $template_obj->slug === $template_slug;
282
-						}
283
-					)
284
-				) > 0 ) {
285
-				continue;
286
-			}
287
-
288
-			// If the theme has an archive-product.html template, but not a taxonomy-product_cat.html template let's use the themes archive-product.html template.
289
-			if ( BlockTemplateUtils::template_is_eligible_for_product_archive_fallback( $template_slug ) ) {
290
-				$template_file = BlockTemplateUtils::get_theme_template_path( 'archive-product' );
291
-				$templates[]   = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug, true );
292
-				continue;
293
-			}
294
-
295
-			// At this point the template only exists in the Blocks filesystem and has not been saved in the DB,
296
-			// or superseded by the theme.
297
-			$templates[] = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug );
298
-		}
299
-
300
-		return $templates;
301
-	}
302
-
303
-	/**
304
-	 * Get and build the block template objects from the block template files.
305
-	 *
306
-	 * @param array $slugs An array of slugs to retrieve templates for.
307
-	 * @param array $template_type wp_template or wp_template_part.
308
-	 *
309
-	 * @return array WP_Block_Template[] An array of block template objects.
310
-	 */
311
-	public function get_block_templates( $slugs = array(), $template_type = 'wp_template' ) {
312
-		$templates_from_db  = $this->get_block_templates_from_db( $slugs, $template_type );
313
-		$templates_from_woo = $this->get_block_templates_from_woocommerce( $slugs, $templates_from_db, $template_type );
314
-		$templates          = array_merge( $templates_from_db, $templates_from_woo );
315
-		return BlockTemplateUtils::filter_block_templates_by_feature_flag( $templates );
316
-
317
-	}
318
-
319
-	/**
320
-	 * Gets the directory where templates of a specific template type can be found.
321
-	 *
322
-	 * @param array $template_type wp_template or wp_template_part.
323
-	 *
324
-	 * @return string
325
-	 */
326
-	protected function get_templates_directory( $template_type = 'wp_template' ) {
327
-		if ( 'wp_template_part' === $template_type ) {
328
-			return $this->template_parts_directory;
329
-		}
330
-		return $this->templates_directory;
331
-	}
332
-
333
-	/**
334
-	 * Checks whether a block template with that name exists in Woo Blocks
335
-	 *
336
-	 * @param string $template_name Template to check.
337
-	 * @param array  $template_type wp_template or wp_template_part.
338
-	 *
339
-	 * @return boolean
340
-	 */
341
-	public function block_template_is_available( $template_name, $template_type = 'wp_template' ) {
342
-		if ( ! $template_name ) {
343
-			return false;
344
-		}
345
-		$directory = $this->get_templates_directory( $template_type ) . '/' . $template_name . '.html';
346
-
347
-		return is_readable(
348
-			$directory
349
-		) || $this->get_block_templates( array( $template_name ), $template_type );
350
-	}
351
-
352
-	/**
353
-	 * Renders the default block template from Woo Blocks if no theme templates exist.
354
-	 */
355
-	public function render_block_template() {
356
-		if ( is_embed() || ! BlockTemplateUtils::supports_block_templates() ) {
357
-			return;
358
-		}
359
-
360
-		if (
361
-			is_singular( 'product' ) &&
362
-			! BlockTemplateUtils::theme_has_template( 'single-product' ) &&
363
-			$this->block_template_is_available( 'single-product' )
364
-		) {
365
-			add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
366
-		} elseif (
367
-			( is_product_taxonomy() && is_tax( 'product_cat' ) ) &&
368
-			! BlockTemplateUtils::theme_has_template( 'taxonomy-product_cat' ) &&
369
-			$this->block_template_is_available( 'taxonomy-product_cat' )
370
-		) {
371
-			add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
372
-		} elseif (
373
-			( is_product_taxonomy() && is_tax( 'product_tag' ) ) &&
374
-			! BlockTemplateUtils::theme_has_template( 'taxonomy-product_tag' ) &&
375
-			$this->block_template_is_available( 'taxonomy-product_tag' )
376
-		) {
377
-			add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
378
-		} elseif (
379
-			( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) &&
380
-			! BlockTemplateUtils::theme_has_template( 'archive-product' ) &&
381
-			$this->block_template_is_available( 'archive-product' )
382
-		) {
383
-			add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
384
-		}
385
-	}
386
-
387
-	/**
388
-	 * Remove the template panel from the Sidebar of the Shop page because
389
-	 * the Site Editor handles it.
390
-	 *
391
-	 * @see https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/6278
392
-	 *
393
-	 * @param bool $is_support Whether the active theme supports block templates.
394
-	 *
395
-	 * @return bool
396
-	 */
397
-	public function remove_block_template_support_for_shop_page( $is_support ) {
398
-		global $pagenow, $post;
399
-
400
-		if (
401
-			is_admin() &&
402
-			'post.php' === $pagenow &&
403
-			function_exists( 'wc_get_page_id' ) &&
404
-			is_a( $post, 'WP_Post' ) &&
405
-			wc_get_page_id( 'shop' ) === $post->ID
406
-		) {
407
-			return false;
408
-		}
409
-
410
-		return $is_support;
411
-	}
13
+    /**
14
+     * Holds the path for the directory where the block templates will be kept.
15
+     *
16
+     * @var string
17
+     */
18
+    private $templates_directory;
19
+
20
+    /**
21
+     * Holds the path for the directory where the block template parts will be kept.
22
+     *
23
+     * @var string
24
+     */
25
+    private $template_parts_directory;
26
+
27
+    /**
28
+     * Directory which contains all templates
29
+     *
30
+     * @var string
31
+     */
32
+    const TEMPLATES_ROOT_DIR = 'templates';
33
+
34
+    /**
35
+     * Constructor.
36
+     */
37
+    public function __construct() {
38
+        // This feature is gated for WooCommerce versions 6.0.0 and above.
39
+        if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '6.0.0', '>=' ) ) {
40
+            $root_path                      = plugin_dir_path( __DIR__ ) . self::TEMPLATES_ROOT_DIR . DIRECTORY_SEPARATOR;
41
+            $this->templates_directory      = $root_path . BlockTemplateUtils::DIRECTORY_NAMES['TEMPLATES'];
42
+            $this->template_parts_directory = $root_path . BlockTemplateUtils::DIRECTORY_NAMES['TEMPLATE_PARTS'];
43
+            $this->init();
44
+        }
45
+    }
46
+
47
+    /**
48
+     * Initialization method.
49
+     */
50
+    protected function init() {
51
+        add_action( 'template_redirect', array( $this, 'render_block_template' ) );
52
+        add_filter( 'pre_get_block_file_template', array( $this, 'get_block_file_template' ), 10, 3 );
53
+        add_filter( 'get_block_templates', array( $this, 'add_block_templates' ), 10, 3 );
54
+        add_filter( 'current_theme_supports-block-templates', array( $this, 'remove_block_template_support_for_shop_page' ) );
55
+    }
56
+
57
+    /**
58
+     * This function checks if there's a block template file in `woo-gutenberg-products-block/templates/templates/`
59
+     * to return to pre_get_posts short-circuiting the query in Gutenberg.
60
+     *
61
+     * @param \WP_Block_Template|null $template Return a block template object to short-circuit the default query,
62
+     *                                               or null to allow WP to run its normal queries.
63
+     * @param string                  $id Template unique identifier (example: theme_slug//template_slug).
64
+     * @param string                  $template_type wp_template or wp_template_part.
65
+     *
66
+     * @return mixed|\WP_Block_Template|\WP_Error
67
+     */
68
+    public function get_block_file_template( $template, $id, $template_type ) {
69
+        $template_name_parts = explode( '//', $id );
70
+
71
+        if ( count( $template_name_parts ) < 2 ) {
72
+            return $template;
73
+        }
74
+
75
+        list( $template_id, $template_slug ) = $template_name_parts;
76
+
77
+        // If the theme has an archive-product.html template, but not a taxonomy-product_cat/tag.html template let's use the themes archive-product.html template.
78
+        if ( BlockTemplateUtils::template_is_eligible_for_product_archive_fallback( $template_slug ) ) {
79
+            $template_path   = BlockTemplateUtils::get_theme_template_path( 'archive-product' );
80
+            $template_object = BlockTemplateUtils::create_new_block_template_object( $template_path, $template_type, $template_slug, true );
81
+            return BlockTemplateUtils::build_template_result_from_file( $template_object, $template_type );
82
+        }
83
+
84
+        // This is a real edge-case, we are supporting users who have saved templates under the deprecated slug. See its definition for more information.
85
+        // You can likely ignore this code unless you're supporting/debugging early customised templates.
86
+        if ( BlockTemplateUtils::DEPRECATED_PLUGIN_SLUG === strtolower( $template_id ) ) {
87
+            // Because we are using get_block_templates we have to unhook this method to prevent a recursive loop where this filter is applied.
88
+            remove_filter( 'pre_get_block_file_template', array( $this, 'get_block_file_template' ), 10, 3 );
89
+            $template_with_deprecated_id = BlockTemplateUtils::get_block_template( $id, $template_type );
90
+            // Let's hook this method back now that we have used the function.
91
+            add_filter( 'pre_get_block_file_template', array( $this, 'get_block_file_template' ), 10, 3 );
92
+
93
+            if ( null !== $template_with_deprecated_id ) {
94
+                return $template_with_deprecated_id;
95
+            }
96
+        }
97
+
98
+        // If we are not dealing with a WooCommerce template let's return early and let it continue through the process.
99
+        if ( BlockTemplateUtils::PLUGIN_SLUG !== $template_id ) {
100
+            return $template;
101
+        }
102
+
103
+        // If we don't have a template let Gutenberg do its thing.
104
+        if ( ! $this->block_template_is_available( $template_slug, $template_type ) ) {
105
+            return $template;
106
+        }
107
+
108
+        $directory          = $this->get_templates_directory( $template_type );
109
+        $template_file_path = $directory . '/' . $template_slug . '.html';
110
+        $template_object    = BlockTemplateUtils::create_new_block_template_object( $template_file_path, $template_type, $template_slug );
111
+        $template_built     = BlockTemplateUtils::build_template_result_from_file( $template_object, $template_type );
112
+
113
+        if ( null !== $template_built ) {
114
+            return $template_built;
115
+        }
116
+
117
+        // Hand back over to Gutenberg if we can't find a template.
118
+        return $template;
119
+    }
120
+
121
+    /**
122
+     * Add the block template objects to be used.
123
+     *
124
+     * @param array $query_result Array of template objects.
125
+     * @param array $query Optional. Arguments to retrieve templates.
126
+     * @param array $template_type wp_template or wp_template_part.
127
+     * @return array
128
+     */
129
+    public function add_block_templates( $query_result, $query, $template_type ) {
130
+        if ( ! BlockTemplateUtils::supports_block_templates() ) {
131
+            return $query_result;
132
+        }
133
+
134
+        $post_type      = isset( $query['post_type'] ) ? $query['post_type'] : '';
135
+        $slugs          = isset( $query['slug__in'] ) ? $query['slug__in'] : array();
136
+        $template_files = $this->get_block_templates( $slugs, $template_type );
137
+
138
+        // @todo: Add apply_filters to _gutenberg_get_template_files() in Gutenberg to prevent duplication of logic.
139
+        foreach ( $template_files as $template_file ) {
140
+
141
+            // If we have a template which is eligible for a fallback, we need to explicitly tell Gutenberg that
142
+            // it has a theme file (because it is using the fallback template file). And then `continue` to avoid
143
+            // adding duplicates.
144
+            if ( BlockTemplateUtils::set_has_theme_file_if_fallback_is_available( $query_result, $template_file ) ) {
145
+                continue;
146
+            }
147
+
148
+            // If the current $post_type is set (e.g. on an Edit Post screen), and isn't included in the available post_types
149
+            // on the template file, then lets skip it so that it doesn't get added. This is typically used to hide templates
150
+            // in the template dropdown on the Edit Post page.
151
+            if ( $post_type &&
152
+                isset( $template_file->post_types ) &&
153
+                ! in_array( $post_type, $template_file->post_types, true )
154
+            ) {
155
+                continue;
156
+            }
157
+
158
+            // It would be custom if the template was modified in the editor, so if it's not custom we can load it from
159
+            // the filesystem.
160
+            if ( 'custom' !== $template_file->source ) {
161
+                $template = BlockTemplateUtils::build_template_result_from_file( $template_file, $template_type );
162
+            } else {
163
+                $template_file->title       = BlockTemplateUtils::get_block_template_title( $template_file->slug );
164
+                $template_file->description = BlockTemplateUtils::get_block_template_description( $template_file->slug );
165
+                $query_result[]             = $template_file;
166
+                continue;
167
+            }
168
+
169
+            $is_not_custom   = false === array_search(
170
+                wp_get_theme()->get_stylesheet() . '//' . $template_file->slug,
171
+                array_column( $query_result, 'id' ),
172
+                true
173
+            );
174
+            $fits_slug_query =
175
+                ! isset( $query['slug__in'] ) || in_array( $template_file->slug, $query['slug__in'], true );
176
+            $fits_area_query =
177
+                ! isset( $query['area'] ) || $template_file->area === $query['area'];
178
+            $should_include  = $is_not_custom && $fits_slug_query && $fits_area_query;
179
+            if ( $should_include ) {
180
+                $query_result[] = $template;
181
+            }
182
+        }
183
+
184
+        // We need to remove theme (i.e. filesystem) templates that have the same slug as a customised one.
185
+        // This only affects saved templates that were saved BEFORE a theme template with the same slug was added.
186
+        $query_result = BlockTemplateUtils::remove_theme_templates_with_custom_alternative( $query_result );
187
+
188
+        /**
189
+         * WC templates from theme aren't included in `$this->get_block_templates()` but are handled by Gutenberg.
190
+         * We need to do additional search through all templates file to update title and description for WC
191
+         * templates that aren't listed in theme.json.
192
+         */
193
+        $query_result = array_map(
194
+            function( $template ) {
195
+                if ( 'theme' === $template->origin ) {
196
+                    return $template;
197
+                }
198
+                if ( $template->title === $template->slug ) {
199
+                    $template->title = BlockTemplateUtils::get_block_template_title( $template->slug );
200
+                }
201
+                if ( ! $template->description ) {
202
+                    $template->description = BlockTemplateUtils::get_block_template_description( $template->slug );
203
+                }
204
+                return $template;
205
+            },
206
+            $query_result
207
+        );
208
+
209
+        return $query_result;
210
+    }
211
+
212
+    /**
213
+     * Gets the templates saved in the database.
214
+     *
215
+     * @param array $slugs An array of slugs to retrieve templates for.
216
+     * @param array $template_type wp_template or wp_template_part.
217
+     *
218
+     * @return int[]|\WP_Post[] An array of found templates.
219
+     */
220
+    public function get_block_templates_from_db( $slugs = array(), $template_type = 'wp_template' ) {
221
+        $check_query_args = array(
222
+            'post_type'      => $template_type,
223
+            'posts_per_page' => -1,
224
+            'no_found_rows'  => true,
225
+            'tax_query'      => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
226
+                array(
227
+                    'taxonomy' => 'wp_theme',
228
+                    'field'    => 'name',
229
+                    'terms'    => array( BlockTemplateUtils::DEPRECATED_PLUGIN_SLUG, BlockTemplateUtils::PLUGIN_SLUG, get_stylesheet() ),
230
+                ),
231
+            ),
232
+        );
233
+
234
+        if ( is_array( $slugs ) && count( $slugs ) > 0 ) {
235
+            $check_query_args['post_name__in'] = $slugs;
236
+        }
237
+
238
+        $check_query         = new \WP_Query( $check_query_args );
239
+        $saved_woo_templates = $check_query->posts;
240
+
241
+        return array_map(
242
+            function( $saved_woo_template ) {
243
+                return BlockTemplateUtils::build_template_result_from_post( $saved_woo_template );
244
+            },
245
+            $saved_woo_templates
246
+        );
247
+    }
248
+
249
+    /**
250
+     * Gets the templates from the WooCommerce blocks directory, skipping those for which a template already exists
251
+     * in the theme directory.
252
+     *
253
+     * @param string[] $slugs An array of slugs to filter templates by. Templates whose slug does not match will not be returned.
254
+     * @param array    $already_found_templates Templates that have already been found, these are customised templates that are loaded from the database.
255
+     * @param string   $template_type wp_template or wp_template_part.
256
+     *
257
+     * @return array Templates from the WooCommerce blocks plugin directory.
258
+     */
259
+    public function get_block_templates_from_woocommerce( $slugs, $already_found_templates, $template_type = 'wp_template' ) {
260
+        $directory      = $this->get_templates_directory( $template_type );
261
+        $template_files = BlockTemplateUtils::get_template_paths( $directory );
262
+        $templates      = array();
263
+
264
+        foreach ( $template_files as $template_file ) {
265
+            $template_slug = BlockTemplateUtils::generate_template_slug_from_path( $template_file );
266
+
267
+            // This template does not have a slug we're looking for. Skip it.
268
+            if ( is_array( $slugs ) && count( $slugs ) > 0 && ! in_array( $template_slug, $slugs, true ) ) {
269
+                continue;
270
+            }
271
+
272
+            // If the theme already has a template, or the template is already in the list (i.e. it came from the
273
+            // database) then we should not overwrite it with the one from the filesystem.
274
+            if (
275
+                BlockTemplateUtils::theme_has_template( $template_slug ) ||
276
+                count(
277
+                    array_filter(
278
+                        $already_found_templates,
279
+                        function ( $template ) use ( $template_slug ) {
280
+                            $template_obj = (object) $template; //phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
281
+                            return $template_obj->slug === $template_slug;
282
+                        }
283
+                    )
284
+                ) > 0 ) {
285
+                continue;
286
+            }
287
+
288
+            // If the theme has an archive-product.html template, but not a taxonomy-product_cat.html template let's use the themes archive-product.html template.
289
+            if ( BlockTemplateUtils::template_is_eligible_for_product_archive_fallback( $template_slug ) ) {
290
+                $template_file = BlockTemplateUtils::get_theme_template_path( 'archive-product' );
291
+                $templates[]   = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug, true );
292
+                continue;
293
+            }
294
+
295
+            // At this point the template only exists in the Blocks filesystem and has not been saved in the DB,
296
+            // or superseded by the theme.
297
+            $templates[] = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug );
298
+        }
299
+
300
+        return $templates;
301
+    }
302
+
303
+    /**
304
+     * Get and build the block template objects from the block template files.
305
+     *
306
+     * @param array $slugs An array of slugs to retrieve templates for.
307
+     * @param array $template_type wp_template or wp_template_part.
308
+     *
309
+     * @return array WP_Block_Template[] An array of block template objects.
310
+     */
311
+    public function get_block_templates( $slugs = array(), $template_type = 'wp_template' ) {
312
+        $templates_from_db  = $this->get_block_templates_from_db( $slugs, $template_type );
313
+        $templates_from_woo = $this->get_block_templates_from_woocommerce( $slugs, $templates_from_db, $template_type );
314
+        $templates          = array_merge( $templates_from_db, $templates_from_woo );
315
+        return BlockTemplateUtils::filter_block_templates_by_feature_flag( $templates );
316
+
317
+    }
318
+
319
+    /**
320
+     * Gets the directory where templates of a specific template type can be found.
321
+     *
322
+     * @param array $template_type wp_template or wp_template_part.
323
+     *
324
+     * @return string
325
+     */
326
+    protected function get_templates_directory( $template_type = 'wp_template' ) {
327
+        if ( 'wp_template_part' === $template_type ) {
328
+            return $this->template_parts_directory;
329
+        }
330
+        return $this->templates_directory;
331
+    }
332
+
333
+    /**
334
+     * Checks whether a block template with that name exists in Woo Blocks
335
+     *
336
+     * @param string $template_name Template to check.
337
+     * @param array  $template_type wp_template or wp_template_part.
338
+     *
339
+     * @return boolean
340
+     */
341
+    public function block_template_is_available( $template_name, $template_type = 'wp_template' ) {
342
+        if ( ! $template_name ) {
343
+            return false;
344
+        }
345
+        $directory = $this->get_templates_directory( $template_type ) . '/' . $template_name . '.html';
346
+
347
+        return is_readable(
348
+            $directory
349
+        ) || $this->get_block_templates( array( $template_name ), $template_type );
350
+    }
351
+
352
+    /**
353
+     * Renders the default block template from Woo Blocks if no theme templates exist.
354
+     */
355
+    public function render_block_template() {
356
+        if ( is_embed() || ! BlockTemplateUtils::supports_block_templates() ) {
357
+            return;
358
+        }
359
+
360
+        if (
361
+            is_singular( 'product' ) &&
362
+            ! BlockTemplateUtils::theme_has_template( 'single-product' ) &&
363
+            $this->block_template_is_available( 'single-product' )
364
+        ) {
365
+            add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
366
+        } elseif (
367
+            ( is_product_taxonomy() && is_tax( 'product_cat' ) ) &&
368
+            ! BlockTemplateUtils::theme_has_template( 'taxonomy-product_cat' ) &&
369
+            $this->block_template_is_available( 'taxonomy-product_cat' )
370
+        ) {
371
+            add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
372
+        } elseif (
373
+            ( is_product_taxonomy() && is_tax( 'product_tag' ) ) &&
374
+            ! BlockTemplateUtils::theme_has_template( 'taxonomy-product_tag' ) &&
375
+            $this->block_template_is_available( 'taxonomy-product_tag' )
376
+        ) {
377
+            add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
378
+        } elseif (
379
+            ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) &&
380
+            ! BlockTemplateUtils::theme_has_template( 'archive-product' ) &&
381
+            $this->block_template_is_available( 'archive-product' )
382
+        ) {
383
+            add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
384
+        }
385
+    }
386
+
387
+    /**
388
+     * Remove the template panel from the Sidebar of the Shop page because
389
+     * the Site Editor handles it.
390
+     *
391
+     * @see https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/6278
392
+     *
393
+     * @param bool $is_support Whether the active theme supports block templates.
394
+     *
395
+     * @return bool
396
+     */
397
+    public function remove_block_template_support_for_shop_page( $is_support ) {
398
+        global $pagenow, $post;
399
+
400
+        if (
401
+            is_admin() &&
402
+            'post.php' === $pagenow &&
403
+            function_exists( 'wc_get_page_id' ) &&
404
+            is_a( $post, 'WP_Post' ) &&
405
+            wc_get_page_id( 'shop' ) === $post->ID
406
+        ) {
407
+            return false;
408
+        }
409
+
410
+        return $is_support;
411
+    }
412 412
 }
Please login to merge, or discard this patch.
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
 	 */
37 37
 	public function __construct() {
38 38
 		// This feature is gated for WooCommerce versions 6.0.0 and above.
39
-		if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '6.0.0', '>=' ) ) {
40
-			$root_path                      = plugin_dir_path( __DIR__ ) . self::TEMPLATES_ROOT_DIR . DIRECTORY_SEPARATOR;
39
+		if (defined('WC_VERSION') && version_compare(WC_VERSION, '6.0.0', '>=')) {
40
+			$root_path                      = plugin_dir_path(__DIR__) . self::TEMPLATES_ROOT_DIR . DIRECTORY_SEPARATOR;
41 41
 			$this->templates_directory      = $root_path . BlockTemplateUtils::DIRECTORY_NAMES['TEMPLATES'];
42 42
 			$this->template_parts_directory = $root_path . BlockTemplateUtils::DIRECTORY_NAMES['TEMPLATE_PARTS'];
43 43
 			$this->init();
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
 	 * Initialization method.
49 49
 	 */
50 50
 	protected function init() {
51
-		add_action( 'template_redirect', array( $this, 'render_block_template' ) );
52
-		add_filter( 'pre_get_block_file_template', array( $this, 'get_block_file_template' ), 10, 3 );
53
-		add_filter( 'get_block_templates', array( $this, 'add_block_templates' ), 10, 3 );
54
-		add_filter( 'current_theme_supports-block-templates', array( $this, 'remove_block_template_support_for_shop_page' ) );
51
+		add_action('template_redirect', array($this, 'render_block_template'));
52
+		add_filter('pre_get_block_file_template', array($this, 'get_block_file_template'), 10, 3);
53
+		add_filter('get_block_templates', array($this, 'add_block_templates'), 10, 3);
54
+		add_filter('current_theme_supports-block-templates', array($this, 'remove_block_template_support_for_shop_page'));
55 55
 	}
56 56
 
57 57
 	/**
@@ -65,52 +65,52 @@  discard block
 block discarded – undo
65 65
 	 *
66 66
 	 * @return mixed|\WP_Block_Template|\WP_Error
67 67
 	 */
68
-	public function get_block_file_template( $template, $id, $template_type ) {
69
-		$template_name_parts = explode( '//', $id );
68
+	public function get_block_file_template($template, $id, $template_type) {
69
+		$template_name_parts = explode('//', $id);
70 70
 
71
-		if ( count( $template_name_parts ) < 2 ) {
71
+		if (count($template_name_parts) < 2) {
72 72
 			return $template;
73 73
 		}
74 74
 
75
-		list( $template_id, $template_slug ) = $template_name_parts;
75
+		list($template_id, $template_slug) = $template_name_parts;
76 76
 
77 77
 		// If the theme has an archive-product.html template, but not a taxonomy-product_cat/tag.html template let's use the themes archive-product.html template.
78
-		if ( BlockTemplateUtils::template_is_eligible_for_product_archive_fallback( $template_slug ) ) {
79
-			$template_path   = BlockTemplateUtils::get_theme_template_path( 'archive-product' );
80
-			$template_object = BlockTemplateUtils::create_new_block_template_object( $template_path, $template_type, $template_slug, true );
81
-			return BlockTemplateUtils::build_template_result_from_file( $template_object, $template_type );
78
+		if (BlockTemplateUtils::template_is_eligible_for_product_archive_fallback($template_slug)) {
79
+			$template_path   = BlockTemplateUtils::get_theme_template_path('archive-product');
80
+			$template_object = BlockTemplateUtils::create_new_block_template_object($template_path, $template_type, $template_slug, true);
81
+			return BlockTemplateUtils::build_template_result_from_file($template_object, $template_type);
82 82
 		}
83 83
 
84 84
 		// This is a real edge-case, we are supporting users who have saved templates under the deprecated slug. See its definition for more information.
85 85
 		// You can likely ignore this code unless you're supporting/debugging early customised templates.
86
-		if ( BlockTemplateUtils::DEPRECATED_PLUGIN_SLUG === strtolower( $template_id ) ) {
86
+		if (BlockTemplateUtils::DEPRECATED_PLUGIN_SLUG === strtolower($template_id)) {
87 87
 			// Because we are using get_block_templates we have to unhook this method to prevent a recursive loop where this filter is applied.
88
-			remove_filter( 'pre_get_block_file_template', array( $this, 'get_block_file_template' ), 10, 3 );
89
-			$template_with_deprecated_id = BlockTemplateUtils::get_block_template( $id, $template_type );
88
+			remove_filter('pre_get_block_file_template', array($this, 'get_block_file_template'), 10, 3);
89
+			$template_with_deprecated_id = BlockTemplateUtils::get_block_template($id, $template_type);
90 90
 			// Let's hook this method back now that we have used the function.
91
-			add_filter( 'pre_get_block_file_template', array( $this, 'get_block_file_template' ), 10, 3 );
91
+			add_filter('pre_get_block_file_template', array($this, 'get_block_file_template'), 10, 3);
92 92
 
93
-			if ( null !== $template_with_deprecated_id ) {
93
+			if (null !== $template_with_deprecated_id) {
94 94
 				return $template_with_deprecated_id;
95 95
 			}
96 96
 		}
97 97
 
98 98
 		// If we are not dealing with a WooCommerce template let's return early and let it continue through the process.
99
-		if ( BlockTemplateUtils::PLUGIN_SLUG !== $template_id ) {
99
+		if (BlockTemplateUtils::PLUGIN_SLUG !== $template_id) {
100 100
 			return $template;
101 101
 		}
102 102
 
103 103
 		// If we don't have a template let Gutenberg do its thing.
104
-		if ( ! $this->block_template_is_available( $template_slug, $template_type ) ) {
104
+		if (!$this->block_template_is_available($template_slug, $template_type)) {
105 105
 			return $template;
106 106
 		}
107 107
 
108
-		$directory          = $this->get_templates_directory( $template_type );
108
+		$directory          = $this->get_templates_directory($template_type);
109 109
 		$template_file_path = $directory . '/' . $template_slug . '.html';
110
-		$template_object    = BlockTemplateUtils::create_new_block_template_object( $template_file_path, $template_type, $template_slug );
111
-		$template_built     = BlockTemplateUtils::build_template_result_from_file( $template_object, $template_type );
110
+		$template_object    = BlockTemplateUtils::create_new_block_template_object($template_file_path, $template_type, $template_slug);
111
+		$template_built     = BlockTemplateUtils::build_template_result_from_file($template_object, $template_type);
112 112
 
113
-		if ( null !== $template_built ) {
113
+		if (null !== $template_built) {
114 114
 			return $template_built;
115 115
 		}
116 116
 
@@ -126,64 +126,64 @@  discard block
 block discarded – undo
126 126
 	 * @param array $template_type wp_template or wp_template_part.
127 127
 	 * @return array
128 128
 	 */
129
-	public function add_block_templates( $query_result, $query, $template_type ) {
130
-		if ( ! BlockTemplateUtils::supports_block_templates() ) {
129
+	public function add_block_templates($query_result, $query, $template_type) {
130
+		if (!BlockTemplateUtils::supports_block_templates()) {
131 131
 			return $query_result;
132 132
 		}
133 133
 
134
-		$post_type      = isset( $query['post_type'] ) ? $query['post_type'] : '';
135
-		$slugs          = isset( $query['slug__in'] ) ? $query['slug__in'] : array();
136
-		$template_files = $this->get_block_templates( $slugs, $template_type );
134
+		$post_type      = isset($query['post_type']) ? $query['post_type'] : '';
135
+		$slugs          = isset($query['slug__in']) ? $query['slug__in'] : array();
136
+		$template_files = $this->get_block_templates($slugs, $template_type);
137 137
 
138 138
 		// @todo: Add apply_filters to _gutenberg_get_template_files() in Gutenberg to prevent duplication of logic.
139
-		foreach ( $template_files as $template_file ) {
139
+		foreach ($template_files as $template_file) {
140 140
 
141 141
 			// If we have a template which is eligible for a fallback, we need to explicitly tell Gutenberg that
142 142
 			// it has a theme file (because it is using the fallback template file). And then `continue` to avoid
143 143
 			// adding duplicates.
144
-			if ( BlockTemplateUtils::set_has_theme_file_if_fallback_is_available( $query_result, $template_file ) ) {
144
+			if (BlockTemplateUtils::set_has_theme_file_if_fallback_is_available($query_result, $template_file)) {
145 145
 				continue;
146 146
 			}
147 147
 
148 148
 			// If the current $post_type is set (e.g. on an Edit Post screen), and isn't included in the available post_types
149 149
 			// on the template file, then lets skip it so that it doesn't get added. This is typically used to hide templates
150 150
 			// in the template dropdown on the Edit Post page.
151
-			if ( $post_type &&
152
-				isset( $template_file->post_types ) &&
153
-				! in_array( $post_type, $template_file->post_types, true )
151
+			if ($post_type &&
152
+				isset($template_file->post_types) &&
153
+				!in_array($post_type, $template_file->post_types, true)
154 154
 			) {
155 155
 				continue;
156 156
 			}
157 157
 
158 158
 			// It would be custom if the template was modified in the editor, so if it's not custom we can load it from
159 159
 			// the filesystem.
160
-			if ( 'custom' !== $template_file->source ) {
161
-				$template = BlockTemplateUtils::build_template_result_from_file( $template_file, $template_type );
160
+			if ('custom' !== $template_file->source) {
161
+				$template = BlockTemplateUtils::build_template_result_from_file($template_file, $template_type);
162 162
 			} else {
163
-				$template_file->title       = BlockTemplateUtils::get_block_template_title( $template_file->slug );
164
-				$template_file->description = BlockTemplateUtils::get_block_template_description( $template_file->slug );
163
+				$template_file->title       = BlockTemplateUtils::get_block_template_title($template_file->slug);
164
+				$template_file->description = BlockTemplateUtils::get_block_template_description($template_file->slug);
165 165
 				$query_result[]             = $template_file;
166 166
 				continue;
167 167
 			}
168 168
 
169
-			$is_not_custom   = false === array_search(
169
+			$is_not_custom = false === array_search(
170 170
 				wp_get_theme()->get_stylesheet() . '//' . $template_file->slug,
171
-				array_column( $query_result, 'id' ),
171
+				array_column($query_result, 'id'),
172 172
 				true
173 173
 			);
174 174
 			$fits_slug_query =
175
-				! isset( $query['slug__in'] ) || in_array( $template_file->slug, $query['slug__in'], true );
175
+				!isset($query['slug__in']) || in_array($template_file->slug, $query['slug__in'], true);
176 176
 			$fits_area_query =
177
-				! isset( $query['area'] ) || $template_file->area === $query['area'];
177
+				!isset($query['area']) || $template_file->area === $query['area'];
178 178
 			$should_include  = $is_not_custom && $fits_slug_query && $fits_area_query;
179
-			if ( $should_include ) {
179
+			if ($should_include) {
180 180
 				$query_result[] = $template;
181 181
 			}
182 182
 		}
183 183
 
184 184
 		// We need to remove theme (i.e. filesystem) templates that have the same slug as a customised one.
185 185
 		// This only affects saved templates that were saved BEFORE a theme template with the same slug was added.
186
-		$query_result = BlockTemplateUtils::remove_theme_templates_with_custom_alternative( $query_result );
186
+		$query_result = BlockTemplateUtils::remove_theme_templates_with_custom_alternative($query_result);
187 187
 
188 188
 		/**
189 189
 		 * WC templates from theme aren't included in `$this->get_block_templates()` but are handled by Gutenberg.
@@ -191,15 +191,15 @@  discard block
 block discarded – undo
191 191
 		 * templates that aren't listed in theme.json.
192 192
 		 */
193 193
 		$query_result = array_map(
194
-			function( $template ) {
195
-				if ( 'theme' === $template->origin ) {
194
+			function($template) {
195
+				if ('theme' === $template->origin) {
196 196
 					return $template;
197 197
 				}
198
-				if ( $template->title === $template->slug ) {
199
-					$template->title = BlockTemplateUtils::get_block_template_title( $template->slug );
198
+				if ($template->title === $template->slug) {
199
+					$template->title = BlockTemplateUtils::get_block_template_title($template->slug);
200 200
 				}
201
-				if ( ! $template->description ) {
202
-					$template->description = BlockTemplateUtils::get_block_template_description( $template->slug );
201
+				if (!$template->description) {
202
+					$template->description = BlockTemplateUtils::get_block_template_description($template->slug);
203 203
 				}
204 204
 				return $template;
205 205
 			},
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	 *
218 218
 	 * @return int[]|\WP_Post[] An array of found templates.
219 219
 	 */
220
-	public function get_block_templates_from_db( $slugs = array(), $template_type = 'wp_template' ) {
220
+	public function get_block_templates_from_db($slugs = array(), $template_type = 'wp_template') {
221 221
 		$check_query_args = array(
222 222
 			'post_type'      => $template_type,
223 223
 			'posts_per_page' => -1,
@@ -226,21 +226,21 @@  discard block
 block discarded – undo
226 226
 				array(
227 227
 					'taxonomy' => 'wp_theme',
228 228
 					'field'    => 'name',
229
-					'terms'    => array( BlockTemplateUtils::DEPRECATED_PLUGIN_SLUG, BlockTemplateUtils::PLUGIN_SLUG, get_stylesheet() ),
229
+					'terms'    => array(BlockTemplateUtils::DEPRECATED_PLUGIN_SLUG, BlockTemplateUtils::PLUGIN_SLUG, get_stylesheet()),
230 230
 				),
231 231
 			),
232 232
 		);
233 233
 
234
-		if ( is_array( $slugs ) && count( $slugs ) > 0 ) {
234
+		if (is_array($slugs) && count($slugs) > 0) {
235 235
 			$check_query_args['post_name__in'] = $slugs;
236 236
 		}
237 237
 
238
-		$check_query         = new \WP_Query( $check_query_args );
238
+		$check_query         = new \WP_Query($check_query_args);
239 239
 		$saved_woo_templates = $check_query->posts;
240 240
 
241 241
 		return array_map(
242
-			function( $saved_woo_template ) {
243
-				return BlockTemplateUtils::build_template_result_from_post( $saved_woo_template );
242
+			function($saved_woo_template) {
243
+				return BlockTemplateUtils::build_template_result_from_post($saved_woo_template);
244 244
 			},
245 245
 			$saved_woo_templates
246 246
 		);
@@ -256,27 +256,27 @@  discard block
 block discarded – undo
256 256
 	 *
257 257
 	 * @return array Templates from the WooCommerce blocks plugin directory.
258 258
 	 */
259
-	public function get_block_templates_from_woocommerce( $slugs, $already_found_templates, $template_type = 'wp_template' ) {
260
-		$directory      = $this->get_templates_directory( $template_type );
261
-		$template_files = BlockTemplateUtils::get_template_paths( $directory );
259
+	public function get_block_templates_from_woocommerce($slugs, $already_found_templates, $template_type = 'wp_template') {
260
+		$directory      = $this->get_templates_directory($template_type);
261
+		$template_files = BlockTemplateUtils::get_template_paths($directory);
262 262
 		$templates      = array();
263 263
 
264
-		foreach ( $template_files as $template_file ) {
265
-			$template_slug = BlockTemplateUtils::generate_template_slug_from_path( $template_file );
264
+		foreach ($template_files as $template_file) {
265
+			$template_slug = BlockTemplateUtils::generate_template_slug_from_path($template_file);
266 266
 
267 267
 			// This template does not have a slug we're looking for. Skip it.
268
-			if ( is_array( $slugs ) && count( $slugs ) > 0 && ! in_array( $template_slug, $slugs, true ) ) {
268
+			if (is_array($slugs) && count($slugs) > 0 && !in_array($template_slug, $slugs, true)) {
269 269
 				continue;
270 270
 			}
271 271
 
272 272
 			// If the theme already has a template, or the template is already in the list (i.e. it came from the
273 273
 			// database) then we should not overwrite it with the one from the filesystem.
274 274
 			if (
275
-				BlockTemplateUtils::theme_has_template( $template_slug ) ||
275
+				BlockTemplateUtils::theme_has_template($template_slug) ||
276 276
 				count(
277 277
 					array_filter(
278 278
 						$already_found_templates,
279
-						function ( $template ) use ( $template_slug ) {
279
+						function($template) use ($template_slug) {
280 280
 							$template_obj = (object) $template; //phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
281 281
 							return $template_obj->slug === $template_slug;
282 282
 						}
@@ -286,15 +286,15 @@  discard block
 block discarded – undo
286 286
 			}
287 287
 
288 288
 			// If the theme has an archive-product.html template, but not a taxonomy-product_cat.html template let's use the themes archive-product.html template.
289
-			if ( BlockTemplateUtils::template_is_eligible_for_product_archive_fallback( $template_slug ) ) {
290
-				$template_file = BlockTemplateUtils::get_theme_template_path( 'archive-product' );
291
-				$templates[]   = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug, true );
289
+			if (BlockTemplateUtils::template_is_eligible_for_product_archive_fallback($template_slug)) {
290
+				$template_file = BlockTemplateUtils::get_theme_template_path('archive-product');
291
+				$templates[]   = BlockTemplateUtils::create_new_block_template_object($template_file, $template_type, $template_slug, true);
292 292
 				continue;
293 293
 			}
294 294
 
295 295
 			// At this point the template only exists in the Blocks filesystem and has not been saved in the DB,
296 296
 			// or superseded by the theme.
297
-			$templates[] = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug );
297
+			$templates[] = BlockTemplateUtils::create_new_block_template_object($template_file, $template_type, $template_slug);
298 298
 		}
299 299
 
300 300
 		return $templates;
@@ -308,11 +308,11 @@  discard block
 block discarded – undo
308 308
 	 *
309 309
 	 * @return array WP_Block_Template[] An array of block template objects.
310 310
 	 */
311
-	public function get_block_templates( $slugs = array(), $template_type = 'wp_template' ) {
312
-		$templates_from_db  = $this->get_block_templates_from_db( $slugs, $template_type );
313
-		$templates_from_woo = $this->get_block_templates_from_woocommerce( $slugs, $templates_from_db, $template_type );
314
-		$templates          = array_merge( $templates_from_db, $templates_from_woo );
315
-		return BlockTemplateUtils::filter_block_templates_by_feature_flag( $templates );
311
+	public function get_block_templates($slugs = array(), $template_type = 'wp_template') {
312
+		$templates_from_db  = $this->get_block_templates_from_db($slugs, $template_type);
313
+		$templates_from_woo = $this->get_block_templates_from_woocommerce($slugs, $templates_from_db, $template_type);
314
+		$templates          = array_merge($templates_from_db, $templates_from_woo);
315
+		return BlockTemplateUtils::filter_block_templates_by_feature_flag($templates);
316 316
 
317 317
 	}
318 318
 
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
 	 *
324 324
 	 * @return string
325 325
 	 */
326
-	protected function get_templates_directory( $template_type = 'wp_template' ) {
327
-		if ( 'wp_template_part' === $template_type ) {
326
+	protected function get_templates_directory($template_type = 'wp_template') {
327
+		if ('wp_template_part' === $template_type) {
328 328
 			return $this->template_parts_directory;
329 329
 		}
330 330
 		return $this->templates_directory;
@@ -338,49 +338,49 @@  discard block
 block discarded – undo
338 338
 	 *
339 339
 	 * @return boolean
340 340
 	 */
341
-	public function block_template_is_available( $template_name, $template_type = 'wp_template' ) {
342
-		if ( ! $template_name ) {
341
+	public function block_template_is_available($template_name, $template_type = 'wp_template') {
342
+		if (!$template_name) {
343 343
 			return false;
344 344
 		}
345
-		$directory = $this->get_templates_directory( $template_type ) . '/' . $template_name . '.html';
345
+		$directory = $this->get_templates_directory($template_type) . '/' . $template_name . '.html';
346 346
 
347 347
 		return is_readable(
348 348
 			$directory
349
-		) || $this->get_block_templates( array( $template_name ), $template_type );
349
+		) || $this->get_block_templates(array($template_name), $template_type);
350 350
 	}
351 351
 
352 352
 	/**
353 353
 	 * Renders the default block template from Woo Blocks if no theme templates exist.
354 354
 	 */
355 355
 	public function render_block_template() {
356
-		if ( is_embed() || ! BlockTemplateUtils::supports_block_templates() ) {
356
+		if (is_embed() || !BlockTemplateUtils::supports_block_templates()) {
357 357
 			return;
358 358
 		}
359 359
 
360 360
 		if (
361
-			is_singular( 'product' ) &&
362
-			! BlockTemplateUtils::theme_has_template( 'single-product' ) &&
363
-			$this->block_template_is_available( 'single-product' )
361
+			is_singular('product') &&
362
+			!BlockTemplateUtils::theme_has_template('single-product') &&
363
+			$this->block_template_is_available('single-product')
364 364
 		) {
365
-			add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
365
+			add_filter('woocommerce_has_block_template', '__return_true', 10, 0);
366 366
 		} elseif (
367
-			( is_product_taxonomy() && is_tax( 'product_cat' ) ) &&
368
-			! BlockTemplateUtils::theme_has_template( 'taxonomy-product_cat' ) &&
369
-			$this->block_template_is_available( 'taxonomy-product_cat' )
367
+			(is_product_taxonomy() && is_tax('product_cat')) &&
368
+			!BlockTemplateUtils::theme_has_template('taxonomy-product_cat') &&
369
+			$this->block_template_is_available('taxonomy-product_cat')
370 370
 		) {
371
-			add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
371
+			add_filter('woocommerce_has_block_template', '__return_true', 10, 0);
372 372
 		} elseif (
373
-			( is_product_taxonomy() && is_tax( 'product_tag' ) ) &&
374
-			! BlockTemplateUtils::theme_has_template( 'taxonomy-product_tag' ) &&
375
-			$this->block_template_is_available( 'taxonomy-product_tag' )
373
+			(is_product_taxonomy() && is_tax('product_tag')) &&
374
+			!BlockTemplateUtils::theme_has_template('taxonomy-product_tag') &&
375
+			$this->block_template_is_available('taxonomy-product_tag')
376 376
 		) {
377
-			add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
377
+			add_filter('woocommerce_has_block_template', '__return_true', 10, 0);
378 378
 		} elseif (
379
-			( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) &&
380
-			! BlockTemplateUtils::theme_has_template( 'archive-product' ) &&
381
-			$this->block_template_is_available( 'archive-product' )
379
+			(is_post_type_archive('product') || is_page(wc_get_page_id('shop'))) &&
380
+			!BlockTemplateUtils::theme_has_template('archive-product') &&
381
+			$this->block_template_is_available('archive-product')
382 382
 		) {
383
-			add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
383
+			add_filter('woocommerce_has_block_template', '__return_true', 10, 0);
384 384
 		}
385 385
 	}
386 386
 
@@ -394,15 +394,15 @@  discard block
 block discarded – undo
394 394
 	 *
395 395
 	 * @return bool
396 396
 	 */
397
-	public function remove_block_template_support_for_shop_page( $is_support ) {
397
+	public function remove_block_template_support_for_shop_page($is_support) {
398 398
 		global $pagenow, $post;
399 399
 
400 400
 		if (
401 401
 			is_admin() &&
402 402
 			'post.php' === $pagenow &&
403
-			function_exists( 'wc_get_page_id' ) &&
404
-			is_a( $post, 'WP_Post' ) &&
405
-			wc_get_page_id( 'shop' ) === $post->ID
403
+			function_exists('wc_get_page_id') &&
404
+			is_a($post, 'WP_Post') &&
405
+			wc_get_page_id('shop') === $post->ID
406 406
 		) {
407 407
 			return false;
408 408
 		}
Please login to merge, or discard this patch.
packages/woocommerce-blocks/src/Integrations/IntegrationRegistry.php 2 patches
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -5,175 +5,175 @@
 block discarded – undo
5 5
  * Class used for tracking registered integrations with various Block types.
6 6
  */
7 7
 class IntegrationRegistry {
8
-	/**
9
-	 * Integration identifier is used to construct hook names and is given when the integration registry is initialized.
10
-	 *
11
-	 * @var string
12
-	 */
13
-	protected $registry_identifier = '';
14
-
15
-	/**
16
-	 * Registered integrations, as `$name => $instance` pairs.
17
-	 *
18
-	 * @var IntegrationInterface[]
19
-	 */
20
-	protected $registered_integrations = [];
21
-
22
-	/**
23
-	 * Initializes all registered integrations.
24
-	 *
25
-	 * Integration identifier is used to construct hook names and is given when the integration registry is initialized.
26
-	 *
27
-	 * @param string $registry_identifier Identifier for this registry.
28
-	 */
29
-	public function initialize( $registry_identifier = '' ) {
30
-		if ( $registry_identifier ) {
31
-			$this->registry_identifier = $registry_identifier;
32
-		}
33
-
34
-		if ( empty( $this->registry_identifier ) ) {
35
-			_doing_it_wrong( __METHOD__, esc_html__( 'Integration registry requires an identifier.', 'woocommerce' ), '4.6.0' );
36
-			return false;
37
-		}
38
-
39
-		/**
40
-		 * Fires when the IntegrationRegistry is initialized.
41
-		 *
42
-		 * Runs before integrations are initialized allowing new integration to be registered for use. This should be
43
-		 * used as the primary hook for integrations to include their scripts, styles, and other code extending the
44
-		 * blocks.
45
-		 *
46
-		 * @param IntegrationRegistry $this Instance of the IntegrationRegistry class which exposes the IntegrationRegistry::register() method.
47
-		 */
48
-		do_action( 'woocommerce_blocks_' . $this->registry_identifier . '_registration', $this );
49
-
50
-		foreach ( $this->get_all_registered() as $registered_integration ) {
51
-			$registered_integration->initialize();
52
-		}
53
-	}
54
-
55
-	/**
56
-	 * Registers an integration.
57
-	 *
58
-	 * @param IntegrationInterface $integration An instance of IntegrationInterface.
59
-	 *
60
-	 * @return boolean True means registered successfully.
61
-	 */
62
-	public function register( IntegrationInterface $integration ) {
63
-		$name = $integration->get_name();
64
-
65
-		if ( $this->is_registered( $name ) ) {
66
-			/* translators: %s: Integration name. */
67
-			_doing_it_wrong( __METHOD__, esc_html( sprintf( __( '"%s" is already registered.', 'woocommerce' ), $name ) ), '4.6.0' );
68
-			return false;
69
-		}
70
-
71
-		$this->registered_integrations[ $name ] = $integration;
72
-		return true;
73
-	}
74
-
75
-	/**
76
-	 * Checks if an integration is already registered.
77
-	 *
78
-	 * @param string $name Integration name.
79
-	 * @return bool True if the integration is registered, false otherwise.
80
-	 */
81
-	public function is_registered( $name ) {
82
-		return isset( $this->registered_integrations[ $name ] );
83
-	}
84
-
85
-	/**
86
-	 * Un-register an integration.
87
-	 *
88
-	 * @param string|IntegrationInterface $name Integration name, or alternatively a IntegrationInterface instance.
89
-	 * @return boolean|IntegrationInterface Returns the unregistered integration instance if unregistered successfully.
90
-	 */
91
-	public function unregister( $name ) {
92
-		if ( $name instanceof IntegrationInterface ) {
93
-			$name = $name->get_name();
94
-		}
95
-
96
-		if ( ! $this->is_registered( $name ) ) {
97
-			/* translators: %s: Integration name. */
98
-			_doing_it_wrong( __METHOD__, esc_html( sprintf( __( 'Integration "%s" is not registered.', 'woocommerce' ), $name ) ), '4.6.0' );
99
-			return false;
100
-		}
101
-
102
-		$unregistered = $this->registered_integrations[ $name ];
103
-		unset( $this->registered_integrations[ $name ] );
104
-		return $unregistered;
105
-	}
106
-
107
-	/**
108
-	 * Retrieves a registered Integration by name.
109
-	 *
110
-	 * @param string $name Integration name.
111
-	 * @return IntegrationInterface|null The registered integration, or null if it is not registered.
112
-	 */
113
-	public function get_registered( $name ) {
114
-		return $this->is_registered( $name ) ? $this->registered_integrations[ $name ] : null;
115
-	}
116
-
117
-	/**
118
-	 * Retrieves all registered integrations.
119
-	 *
120
-	 * @return IntegrationInterface[]
121
-	 */
122
-	public function get_all_registered() {
123
-		return $this->registered_integrations;
124
-	}
125
-
126
-	/**
127
-	 * Gets an array of all registered integration's script handles for the editor.
128
-	 *
129
-	 * @return string[]
130
-	 */
131
-	public function get_all_registered_editor_script_handles() {
132
-		$script_handles          = [];
133
-		$registered_integrations = $this->get_all_registered();
134
-
135
-		foreach ( $registered_integrations as $registered_integration ) {
136
-			$script_handles = array_merge(
137
-				$script_handles,
138
-				$registered_integration->get_editor_script_handles()
139
-			);
140
-		}
141
-
142
-		return array_unique( array_filter( $script_handles ) );
143
-	}
144
-
145
-	/**
146
-	 * Gets an array of all registered integration's script handles.
147
-	 *
148
-	 * @return string[]
149
-	 */
150
-	public function get_all_registered_script_handles() {
151
-		$script_handles          = [];
152
-		$registered_integrations = $this->get_all_registered();
153
-
154
-		foreach ( $registered_integrations as $registered_integration ) {
155
-			$script_handles = array_merge(
156
-				$script_handles,
157
-				$registered_integration->get_script_handles()
158
-			);
159
-		}
160
-
161
-		return array_unique( array_filter( $script_handles ) );
162
-	}
163
-
164
-	/**
165
-	 * Gets an array of all registered integration's script data.
166
-	 *
167
-	 * @return array
168
-	 */
169
-	public function get_all_registered_script_data() {
170
-		$script_data             = [];
171
-		$registered_integrations = $this->get_all_registered();
172
-
173
-		foreach ( $registered_integrations as $registered_integration ) {
174
-			$script_data[ $registered_integration->get_name() . '_data' ] = $registered_integration->get_script_data();
175
-		}
176
-
177
-		return array_filter( $script_data );
178
-	}
8
+    /**
9
+     * Integration identifier is used to construct hook names and is given when the integration registry is initialized.
10
+     *
11
+     * @var string
12
+     */
13
+    protected $registry_identifier = '';
14
+
15
+    /**
16
+     * Registered integrations, as `$name => $instance` pairs.
17
+     *
18
+     * @var IntegrationInterface[]
19
+     */
20
+    protected $registered_integrations = [];
21
+
22
+    /**
23
+     * Initializes all registered integrations.
24
+     *
25
+     * Integration identifier is used to construct hook names and is given when the integration registry is initialized.
26
+     *
27
+     * @param string $registry_identifier Identifier for this registry.
28
+     */
29
+    public function initialize( $registry_identifier = '' ) {
30
+        if ( $registry_identifier ) {
31
+            $this->registry_identifier = $registry_identifier;
32
+        }
33
+
34
+        if ( empty( $this->registry_identifier ) ) {
35
+            _doing_it_wrong( __METHOD__, esc_html__( 'Integration registry requires an identifier.', 'woocommerce' ), '4.6.0' );
36
+            return false;
37
+        }
38
+
39
+        /**
40
+         * Fires when the IntegrationRegistry is initialized.
41
+         *
42
+         * Runs before integrations are initialized allowing new integration to be registered for use. This should be
43
+         * used as the primary hook for integrations to include their scripts, styles, and other code extending the
44
+         * blocks.
45
+         *
46
+         * @param IntegrationRegistry $this Instance of the IntegrationRegistry class which exposes the IntegrationRegistry::register() method.
47
+         */
48
+        do_action( 'woocommerce_blocks_' . $this->registry_identifier . '_registration', $this );
49
+
50
+        foreach ( $this->get_all_registered() as $registered_integration ) {
51
+            $registered_integration->initialize();
52
+        }
53
+    }
54
+
55
+    /**
56
+     * Registers an integration.
57
+     *
58
+     * @param IntegrationInterface $integration An instance of IntegrationInterface.
59
+     *
60
+     * @return boolean True means registered successfully.
61
+     */
62
+    public function register( IntegrationInterface $integration ) {
63
+        $name = $integration->get_name();
64
+
65
+        if ( $this->is_registered( $name ) ) {
66
+            /* translators: %s: Integration name. */
67
+            _doing_it_wrong( __METHOD__, esc_html( sprintf( __( '"%s" is already registered.', 'woocommerce' ), $name ) ), '4.6.0' );
68
+            return false;
69
+        }
70
+
71
+        $this->registered_integrations[ $name ] = $integration;
72
+        return true;
73
+    }
74
+
75
+    /**
76
+     * Checks if an integration is already registered.
77
+     *
78
+     * @param string $name Integration name.
79
+     * @return bool True if the integration is registered, false otherwise.
80
+     */
81
+    public function is_registered( $name ) {
82
+        return isset( $this->registered_integrations[ $name ] );
83
+    }
84
+
85
+    /**
86
+     * Un-register an integration.
87
+     *
88
+     * @param string|IntegrationInterface $name Integration name, or alternatively a IntegrationInterface instance.
89
+     * @return boolean|IntegrationInterface Returns the unregistered integration instance if unregistered successfully.
90
+     */
91
+    public function unregister( $name ) {
92
+        if ( $name instanceof IntegrationInterface ) {
93
+            $name = $name->get_name();
94
+        }
95
+
96
+        if ( ! $this->is_registered( $name ) ) {
97
+            /* translators: %s: Integration name. */
98
+            _doing_it_wrong( __METHOD__, esc_html( sprintf( __( 'Integration "%s" is not registered.', 'woocommerce' ), $name ) ), '4.6.0' );
99
+            return false;
100
+        }
101
+
102
+        $unregistered = $this->registered_integrations[ $name ];
103
+        unset( $this->registered_integrations[ $name ] );
104
+        return $unregistered;
105
+    }
106
+
107
+    /**
108
+     * Retrieves a registered Integration by name.
109
+     *
110
+     * @param string $name Integration name.
111
+     * @return IntegrationInterface|null The registered integration, or null if it is not registered.
112
+     */
113
+    public function get_registered( $name ) {
114
+        return $this->is_registered( $name ) ? $this->registered_integrations[ $name ] : null;
115
+    }
116
+
117
+    /**
118
+     * Retrieves all registered integrations.
119
+     *
120
+     * @return IntegrationInterface[]
121
+     */
122
+    public function get_all_registered() {
123
+        return $this->registered_integrations;
124
+    }
125
+
126
+    /**
127
+     * Gets an array of all registered integration's script handles for the editor.
128
+     *
129
+     * @return string[]
130
+     */
131
+    public function get_all_registered_editor_script_handles() {
132
+        $script_handles          = [];
133
+        $registered_integrations = $this->get_all_registered();
134
+
135
+        foreach ( $registered_integrations as $registered_integration ) {
136
+            $script_handles = array_merge(
137
+                $script_handles,
138
+                $registered_integration->get_editor_script_handles()
139
+            );
140
+        }
141
+
142
+        return array_unique( array_filter( $script_handles ) );
143
+    }
144
+
145
+    /**
146
+     * Gets an array of all registered integration's script handles.
147
+     *
148
+     * @return string[]
149
+     */
150
+    public function get_all_registered_script_handles() {
151
+        $script_handles          = [];
152
+        $registered_integrations = $this->get_all_registered();
153
+
154
+        foreach ( $registered_integrations as $registered_integration ) {
155
+            $script_handles = array_merge(
156
+                $script_handles,
157
+                $registered_integration->get_script_handles()
158
+            );
159
+        }
160
+
161
+        return array_unique( array_filter( $script_handles ) );
162
+    }
163
+
164
+    /**
165
+     * Gets an array of all registered integration's script data.
166
+     *
167
+     * @return array
168
+     */
169
+    public function get_all_registered_script_data() {
170
+        $script_data             = [];
171
+        $registered_integrations = $this->get_all_registered();
172
+
173
+        foreach ( $registered_integrations as $registered_integration ) {
174
+            $script_data[ $registered_integration->get_name() . '_data' ] = $registered_integration->get_script_data();
175
+        }
176
+
177
+        return array_filter( $script_data );
178
+    }
179 179
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -26,13 +26,13 @@  discard block
 block discarded – undo
26 26
 	 *
27 27
 	 * @param string $registry_identifier Identifier for this registry.
28 28
 	 */
29
-	public function initialize( $registry_identifier = '' ) {
30
-		if ( $registry_identifier ) {
29
+	public function initialize($registry_identifier = '') {
30
+		if ($registry_identifier) {
31 31
 			$this->registry_identifier = $registry_identifier;
32 32
 		}
33 33
 
34
-		if ( empty( $this->registry_identifier ) ) {
35
-			_doing_it_wrong( __METHOD__, esc_html__( 'Integration registry requires an identifier.', 'woocommerce' ), '4.6.0' );
34
+		if (empty($this->registry_identifier)) {
35
+			_doing_it_wrong(__METHOD__, esc_html__('Integration registry requires an identifier.', 'woocommerce'), '4.6.0');
36 36
 			return false;
37 37
 		}
38 38
 
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
 		 *
46 46
 		 * @param IntegrationRegistry $this Instance of the IntegrationRegistry class which exposes the IntegrationRegistry::register() method.
47 47
 		 */
48
-		do_action( 'woocommerce_blocks_' . $this->registry_identifier . '_registration', $this );
48
+		do_action('woocommerce_blocks_' . $this->registry_identifier . '_registration', $this);
49 49
 
50
-		foreach ( $this->get_all_registered() as $registered_integration ) {
50
+		foreach ($this->get_all_registered() as $registered_integration) {
51 51
 			$registered_integration->initialize();
52 52
 		}
53 53
 	}
@@ -59,16 +59,16 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @return boolean True means registered successfully.
61 61
 	 */
62
-	public function register( IntegrationInterface $integration ) {
62
+	public function register(IntegrationInterface $integration) {
63 63
 		$name = $integration->get_name();
64 64
 
65
-		if ( $this->is_registered( $name ) ) {
65
+		if ($this->is_registered($name)) {
66 66
 			/* translators: %s: Integration name. */
67
-			_doing_it_wrong( __METHOD__, esc_html( sprintf( __( '"%s" is already registered.', 'woocommerce' ), $name ) ), '4.6.0' );
67
+			_doing_it_wrong(__METHOD__, esc_html(sprintf(__('"%s" is already registered.', 'woocommerce'), $name)), '4.6.0');
68 68
 			return false;
69 69
 		}
70 70
 
71
-		$this->registered_integrations[ $name ] = $integration;
71
+		$this->registered_integrations[$name] = $integration;
72 72
 		return true;
73 73
 	}
74 74
 
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 	 * @param string $name Integration name.
79 79
 	 * @return bool True if the integration is registered, false otherwise.
80 80
 	 */
81
-	public function is_registered( $name ) {
82
-		return isset( $this->registered_integrations[ $name ] );
81
+	public function is_registered($name) {
82
+		return isset($this->registered_integrations[$name]);
83 83
 	}
84 84
 
85 85
 	/**
@@ -88,19 +88,19 @@  discard block
 block discarded – undo
88 88
 	 * @param string|IntegrationInterface $name Integration name, or alternatively a IntegrationInterface instance.
89 89
 	 * @return boolean|IntegrationInterface Returns the unregistered integration instance if unregistered successfully.
90 90
 	 */
91
-	public function unregister( $name ) {
92
-		if ( $name instanceof IntegrationInterface ) {
91
+	public function unregister($name) {
92
+		if ($name instanceof IntegrationInterface) {
93 93
 			$name = $name->get_name();
94 94
 		}
95 95
 
96
-		if ( ! $this->is_registered( $name ) ) {
96
+		if (!$this->is_registered($name)) {
97 97
 			/* translators: %s: Integration name. */
98
-			_doing_it_wrong( __METHOD__, esc_html( sprintf( __( 'Integration "%s" is not registered.', 'woocommerce' ), $name ) ), '4.6.0' );
98
+			_doing_it_wrong(__METHOD__, esc_html(sprintf(__('Integration "%s" is not registered.', 'woocommerce'), $name)), '4.6.0');
99 99
 			return false;
100 100
 		}
101 101
 
102
-		$unregistered = $this->registered_integrations[ $name ];
103
-		unset( $this->registered_integrations[ $name ] );
102
+		$unregistered = $this->registered_integrations[$name];
103
+		unset($this->registered_integrations[$name]);
104 104
 		return $unregistered;
105 105
 	}
106 106
 
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
 	 * @param string $name Integration name.
111 111
 	 * @return IntegrationInterface|null The registered integration, or null if it is not registered.
112 112
 	 */
113
-	public function get_registered( $name ) {
114
-		return $this->is_registered( $name ) ? $this->registered_integrations[ $name ] : null;
113
+	public function get_registered($name) {
114
+		return $this->is_registered($name) ? $this->registered_integrations[$name] : null;
115 115
 	}
116 116
 
117 117
 	/**
@@ -132,14 +132,14 @@  discard block
 block discarded – undo
132 132
 		$script_handles          = [];
133 133
 		$registered_integrations = $this->get_all_registered();
134 134
 
135
-		foreach ( $registered_integrations as $registered_integration ) {
135
+		foreach ($registered_integrations as $registered_integration) {
136 136
 			$script_handles = array_merge(
137 137
 				$script_handles,
138 138
 				$registered_integration->get_editor_script_handles()
139 139
 			);
140 140
 		}
141 141
 
142
-		return array_unique( array_filter( $script_handles ) );
142
+		return array_unique(array_filter($script_handles));
143 143
 	}
144 144
 
145 145
 	/**
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
 		$script_handles          = [];
152 152
 		$registered_integrations = $this->get_all_registered();
153 153
 
154
-		foreach ( $registered_integrations as $registered_integration ) {
154
+		foreach ($registered_integrations as $registered_integration) {
155 155
 			$script_handles = array_merge(
156 156
 				$script_handles,
157 157
 				$registered_integration->get_script_handles()
158 158
 			);
159 159
 		}
160 160
 
161
-		return array_unique( array_filter( $script_handles ) );
161
+		return array_unique(array_filter($script_handles));
162 162
 	}
163 163
 
164 164
 	/**
@@ -170,10 +170,10 @@  discard block
 block discarded – undo
170 170
 		$script_data             = [];
171 171
 		$registered_integrations = $this->get_all_registered();
172 172
 
173
-		foreach ( $registered_integrations as $registered_integration ) {
174
-			$script_data[ $registered_integration->get_name() . '_data' ] = $registered_integration->get_script_data();
173
+		foreach ($registered_integrations as $registered_integration) {
174
+			$script_data[$registered_integration->get_name() . '_data'] = $registered_integration->get_script_data();
175 175
 		}
176 176
 
177
-		return array_filter( $script_data );
177
+		return array_filter($script_data);
178 178
 	}
179 179
 }
Please login to merge, or discard this patch.