dev-master
9999999-devBag of tools to aid in WordPress development.
MIT
The Requires
- php ^5.6 || ^7.0
The Development Requires
by Christian Nikkanen
Wallogit.com
2017 © Pedro Peláez
Bag of tools to aid in WordPress development.
Bag of tools to lessen the pain of WordPress development. Documentation exists, and might improve over time., (*1)
It's modular, so you can disable the parts you don't need., (*2)
PHP 7., (*3)
composer.json says 5.6, but that's just temporary so Composer stops complaining about it when installing with the standard macOS PHP, which is 5.6 and unreasonably hard to upgrade., (*4)
There's a lot going on, and some things aren't as useful as the other. It brings a new vibe to templating., (*5)
First, we "register" a template directory, add this to your theme's functions.php, (*6)
\rnb\template\load_glob(dirname(__FILE__) . '/templates/*');
Then every PHP file from templates/ is loaded and usable by \rnb\template\output() and \rnb\template\to_string(). You could have multiple template directories if you wanted to., (*7)
Templates differ a bit from "traditional" templates: all templates are functions that are given data as parameters, while the traditional template usually just calls a function directly. Example template, located in templates/single-item.php:, (*8)
function single_item($props = []) {
// We can also let the template populate itself with data if required.
$content = $props['content'] ?? get_the_content();
$image = $props['image'] ?? \rnb\media\image(get_post_thumbnail_id());
$injectorfn = !is_null($data['injectorfn']) ? $data['injectorfn'] : function() {
return '';
}; ?>
<article>
<?=$image?>
<p><?=$content?></p>
<?=$injectorfn()?> <!-- You could make the function echo data instead, choice is yours. -->
</article>
}
You could then use that template in The Loop, or supply the data in any other way., (*9)
while (have_posts()) { the_post();
\rnb\template\output('single_item');
}
// or
\rnb\template\output('single_item', [ // notice array inside array
[
'content' => 'Hello world!',
'image' => '<img src="/path/to/image.jpg">',
'injectorfn' => function() {
$link = get_permalink();
return \rnb\core\tag([
"<a href='$link'>",
"Read the whole thing",
"</a>"
]);
}
]
]);
This was all written inside the GitHub editor without actually testing the code, so if it works, great! If it doesn't, fix it and PR it please :), (*10)
Bag of tools to aid in WordPress development.
MIT