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
code-snippets / php / Flat_Files / Handlers / Content_Snippet_Handler.php

Content_Snippet_Handler.php in Code Snippets 4.0.0-beta.2, at php/Flat_Files/Handlers/Content_Snippet_Handler.php

41 lines 921 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Code_Snippets\Flat_Files\Handlers;
4
5 use Code_Snippets\Flat_Files\Interfaces\Snippet_Type_Handler;
6
7 /**
8 * Snippet type handler for content snippets.
9 */
10 class Content_Snippet_Handler implements Snippet_Type_Handler {
11
12 /**
13 * Set 'php' as the file extension for content snippets, as they can contain embedded PHP code.
14 *
15 * @return string
16 */
17 public function get_file_extension(): string {
18 return 'php';
19 }
20
21 /**
22 * Store content snippets in an 'html' directory.
23 *
24 * @return string
25 */
26 public function get_dir_name(): string {
27 return 'html';
28 }
29
30 /**
31 * Wrap content snippets by adding a header that disallows direct access.
32 *
33 * @param string $code Content snippet code.
34 *
35 * @return string Content snippet code with header prepended.
36 */
37 public function wrap_code( string $code ): string {
38 return "<?php\n\nif ( ! defined( 'ABSPATH' ) ) { return; }\n\n?>\n\n" . $code;
39 }
40 }
41