True if snippets were evaluated, false if safe mode is active. */ public function evaluate_early(): bool { if ( $this->is_safe_mode_active() ) { return false; } if ( Snippet_Files::is_active() ) { return $this->evaluate_file_snippets(); } return $this->evaluate_db_snippets(); } public function evaluate_db_snippets(): bool { $scopes = [ 'global', 'single-use', is_admin() ? 'admin' : 'front-end' ]; $active_snippets = $this->db->fetch_active_snippets( $scopes ); $edit_snippet = $this->get_currently_editing_snippet(); foreach ( $active_snippets as $snippet ) { $snippet_id = $snippet['id']; $code = $snippet['code']; $table_name = $snippet['table']; // If the snippet is a single-use snippet, deactivate it before execution to ensure that the process always happens. if ( 'single-use' === $snippet['scope'] ) { $this->quick_deactivate_snippet( $snippet_id, $table_name ); } if ( apply_filters( 'code_snippets/allow_execute_snippet', true, $snippet_id, $table_name ) && ( is_null( $edit_snippet ) || $edit_snippet['id'] !== $snippet_id || $edit_snippet['table'] !== $table_name ) ) { execute_snippet( $code, $snippet_id ); } } return true; } private function evaluate_file_snippets(): bool { $type = 'php'; $scopes = [ 'global', 'single-use', is_admin() ? 'admin' : 'front-end' ]; $snippets = Snippet_Files::get_active_snippets_from_flat_files( $scopes, $type ); $edit_snippet = $this->get_currently_editing_snippet(); foreach ( $snippets as $snippet ) { $table_name = Snippet_Files::get_hashed_table_name( $snippet['table'] ); $base_path = Snippet_Files::get_base_dir( $table_name, $type ); $file = $base_path . '/' . $snippet['id'] . '.' . $type; $this->evaluate_snippet_flat_file( $snippet, $file, $edit_snippet ); } return true; } }