PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
← All changes | php/Integration/Evaluate_Functions.php +19 -23 3.10.24.0.0-beta.2 View file →
@@ -136,9 +136,9 @@
136 136 *
137 137 * @return bool New filter value.
138 138 */
139 139 public function disable_snippet_execution( $execute_snippets ): bool {
140 - return (bool) $execute_snippets && ! $this->is_safe_mode_requested();
140 + return $execute_snippets && ! $this->is_safe_mode_requested();
141 141 }
142 142
143 143 /**
144 144 * Quickly deactivate a snippet with minimal overhead.
@@ -176,17 +176,17 @@
176 176 }
177 177 }
178 178
179 179 /**
180 - * Evaluate a snippet stored in a flat file.
180 + * Evaluate a snippet.
181 181 *
182 - * @param array $snippet Snippet data.
183 - * @param string $file_path Path to the snippet file.
184 - * @param array|null $edit_snippet Data of snippet currently being edited, if applicable.
182 + * @param array $snippet Snippet data.
183 + * @param string|null $file_path Path to the snippet file, or null if executing from the database.
184 + * @param array|null $edit_snippet Data of snippet currently being edited, if applicable.
185 185 *
186 186 * @return void
187 187 */
188 - private function evaluate_snippet_flat_file( array $snippet, string $file_path, ?array $edit_snippet = null ) {
188 + private function evaluate_snippet( array $snippet, ?string $file_path, ?array $edit_snippet ) {
189 189 $snippet_id = $snippet['id'];
190 190 $code = $snippet['code'];
191 191 $table_name = $snippet['table'];
192 192
@@ -199,9 +199,13 @@
199 199 return;
200 200 }
201 201
202 202 if ( apply_filters( 'code_snippets/allow_execute_snippet', true, $snippet_id, $table_name ) ) {
203 - execute_snippet_from_flat_file( $code, $file_path, $snippet_id );
203 + if ( is_null( $file_path ) ) {
204 + execute_snippet( $code, $snippet_id );
205 + } else {
206 + execute_snippet_from_flat_file( $code, $file_path, $snippet_id );
207 + }
204 208 }
205 209 }
206 210
207 211 /**
@@ -231,21 +235,11 @@
231 235 $active_snippets = $this->db->fetch_active_snippets( $scopes );
232 236 $edit_snippet = $this->get_currently_editing_snippet();
233 237
234 238 foreach ( $active_snippets as $snippet ) {
235 - $snippet_id = $snippet['id'];
236 - $code = $snippet['code'];
237 - $table_name = $snippet['table'];
238 -
239 - // If the snippet is a single-use snippet, deactivate it before execution to ensure that the process always happens.
240 - if ( 'single-use' === $snippet['scope'] ) {
241 - $this->quick_deactivate_snippet( $snippet_id, $table_name );
239 + if ( 'condition' !== $snippet['scope'] ) {
240 + $this->evaluate_snippet( $snippet, null, $edit_snippet );
242 241 }
243 -
244 - if ( apply_filters( 'code_snippets/allow_execute_snippet', true, $snippet_id, $table_name ) &&
245 - ( is_null( $edit_snippet ) || $edit_snippet['id'] !== $snippet_id || $edit_snippet['table'] !== $table_name ) ) {
246 - execute_snippet( $code, $snippet_id );
247 - }
248 242 }
249 243
250 244 return true;
251 245 }
@@ -261,13 +255,15 @@
261 255 $snippets = Snippet_Files::get_active_snippets_from_flat_files( $scopes, $type );
262 256 $edit_snippet = $this->get_currently_editing_snippet();
263 257
264 258 foreach ( $snippets as $snippet ) {
265 - $table_name = Snippet_Files::get_hashed_table_name( $snippet['table'] );
266 - $base_path = Snippet_Files::get_base_dir( $table_name, $type );
267 - $file = $base_path . '/' . $snippet['id'] . '.' . $type;
259 + if ( 'condition' !== $snippet['scope'] ) {
260 + $table_name = Snippet_Files::get_hashed_table_name( $snippet['table'] );
261 + $base_path = Snippet_Files::get_base_dir( $table_name, $type );
262 + $file = $base_path . '/' . $snippet['id'] . '.' . $type;
268 263
269 - $this->evaluate_snippet_flat_file( $snippet, $file, $edit_snippet );
264 + $this->evaluate_snippet( $snippet, $file, $edit_snippet );
265 + }
270 266 }
271 267
272 268 return true;
273 269 }