View.php in Post Snippets – Custom WordPress Code Snippets Customizer trunk, at src/PostSnippets/View.php
| 1 | <?php |
| 2 | namespace PostSnippets; |
| 3 | |
| 4 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 5 | |
| 6 | /** |
| 7 | * View Handling. |
| 8 | * |
| 9 | */ |
| 10 | class View |
| 11 | { |
| 12 | /** |
| 13 | * Render a View. |
| 14 | * |
| 15 | * @param string $view |
| 16 | * @param array $data |
| 17 | * @return string |
| 18 | */ |
| 19 | public static function render($view, $data = null) |
| 20 | { |
| 21 | // Handle data |
| 22 | ($data) ? extract($data) : null; |
| 23 | |
| 24 | ob_start(); |
| 25 | include(plugin_dir_path(__FILE__).'../../views/'.$view.'.php'); |
| 26 | $view = ob_get_contents(); |
| 27 | ob_end_clean(); |
| 28 | |
| 29 | return $view; |
| 30 | } |
| 31 | } |
| 32 |