Currently I'm working on a plugin that will display a grid based on post type with many settings to customize it. One of the settings will be to choose between different skins available to display inside the grid.
I would like to offer the possibility to developers to include their own skins with a custom HOOK/Filter.
What is the right way to add this functionality in a plugin?
I was thinking about something like this but I'm not sure if it's the right way and if it will work:
// register skin class in plugin
class skinclass {
//existing skins
function myclass() {
}
do_action('add_custom_skin');
}
// developers register action to include it's own skins (in function.php)
add_action('add_custom_skin','my_custom_skins')
function my_custom_skins($post) {
function skin1($post) {
$skin1 = '<article class="skin1-holder">';
$skin1 .= '<h2 class="skin1-title">'. get_the_title() .'</h2>';
$skin1 .= '<div class="skin1-excerpt">'. get_the_excerpt() .'</div>';
$skin1 .= '</article>';
return $skin1;
}
function skin2($post) {
$skin2 = '<article class="skin2-holder">';
$skin2 .= '<h2 class="skin2-title">'. get_the_title() .'</h2>';
$skin2 .= '<div class="skin2-excerpt">'. get_the_excerpt() .'</div>';
$skin2 .= '</article>';
return $skin2;
}
}
// get skin function in plugin
$skins = get_class_methods(new skinclass());
// to output skin in a drop down list
foreach ($skins as $skin_name) {
echo "$skin_name\n";
}
// output skin in front end
$func = 'skin1';
$func();
The skin to output will be in a query_posts loop.