PluginProbe
Code Snippets / 3.10.0
Code Snippets v3.10.0
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 / Functions_Snippet_Handler.php

Functions_Snippet_Handler.php in Code Snippets 3.10.0, at php/Flat_Files/Handlers/Functions_Snippet_Handler.php

41 lines 909 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 functions snippets.
9 */
10 class Functions_Snippet_Handler implements Snippet_Type_Handler {
11
12 /**
13 * Set 'php' as the file extension for functions snippets, so they can be directly loaded.
14 *
15 * @return string
16 */
17 public function get_file_extension(): string {
18 return 'php';
19 }
20
21 /**
22 * Store content snippets in a 'php' directory.
23 *
24 * @return string
25 */
26 public function get_dir_name(): string {
27 return 'php';
28 }
29
30 /**
31 * Wrap functions snippets by adding a header that disallows direct access.
32 *
33 * @param string $code Snippet PHP 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" . $code;
39 }
40 }
41