-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp-php-components-example.php
More file actions
48 lines (36 loc) · 1.07 KB
/
wp-php-components-example.php
File metadata and controls
48 lines (36 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* Plugin Name: WP Component Example
* Description: PHP Component Tutorial
* Version: 0.0.1
*/
spl_autoload_register( function($class_name) {
if( strpos($class_name, 'MyPHPComponents') !== 0 ) {
return;
}
$called_class = str_replace( ['\\', 'MyPHPComponents'], ['/', ''], $class_name );
$class_file = dirname(__FILE__) . '/src/classes' . $called_class . '.php';
if( file_exists($class_file) ) {
require_once( $class_file );
}
} );
/**
* Load our plugin
*/
add_action( 'plugins_loaded', function() {
defined('PLUGIN_PATH') or define( 'PLUGIN_PATH', plugin_dir_path( __FILE__ ));
defined('PLUGIN_URI') or define( 'PLUGIN_URI', plugin_dir_url( __FILE__ ));
$plugin = MyPHPComponents\Plugin::instance();
} );
/**
* Output our example component
*/
add_filter('the_content', function($content) {
$component = new MyPHPComponents\Components\ExampleComponent([
'link' => 'https://example.com',
'text' => __('Text'),
'size' => 'large'
]);
$component_string = $component->render(false);
return $content . $component_string;
});