Last active
September 15, 2020 16:22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace q\theme\context; | |
// willow ## | |
use q\willow; // to extend ## | |
// register class to render ## | |
\q\theme\context\ui::run(); | |
class ui { | |
public static function run( $args = null ) { | |
// check for willow ## | |
if( ! class_exists( 'q_willow' ) ){ return false; } | |
$class = new \ReflectionClass( __CLASS__ ); | |
$methods = $class->getMethods( \ReflectionMethod::IS_PUBLIC ); | |
foreach( $methods as $key ){ $public_methods[] = $key->name; } // match format returned by get_class_methods() ## | |
// register new class methods ## | |
\add_action( 'after_setup_theme', function() use ( $public_methods ) { | |
willow\context\extend::register([ | |
'context' => str_replace( __NAMESPACE__.'\\', '', __CLASS__ ), | |
'class' => __CLASS__, | |
'methods' => $public_methods // public only | |
]); | |
}, 2 ); | |
} | |
/** | |
* Example extension method | |
* | |
* @param Array $args | |
* @since 4.1.0 | |
* @return Array | |
*/ | |
public static function hello( $args = null ) { | |
// define key + values ## | |
return | |
[ | |
'data' => [ // | |
'0' => [ | |
'who' => 'You', | |
'time' => rand(), | |
], | |
'1' => [ | |
'who' => 'Me', | |
'time' => rand(), | |
] | |
] | |
] | |
; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment