1. Go to this page and download the library: Download tombroucke/wp-sidewheels library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tombroucke / wp-sidewheels example snippets
use Otomaties\Sidewheels\Sidewheels;
add_action('init', function(){
Sidewheels::init(dirname(__FILE__));
});
use Otomaties\Sidewheels\Sidewheels;
register_activation_hook(__FILE__, function(){
Sidewheels::install(dirname(__FILE__));
});
use Otomaties\Sidewheels\Sidewheels;
register_deactivation_hook(__FILE__, function(){
Sidewheels::uninstall();
});
namespace Namespace\Controllers;
use Otomaties\Sidewheels\Abstracts\Controller;
class Admin extends Controller
{
public function index()
{
$this->route()->setTitle('Dashboard'); // Optional, only for rendering complete pages
$this->render('admin/dash.html', [ // render() : complete page, renderContent() : render during the_content(), renderShortcode() : returns html instead of rendering
'website' => 'https://tombroucke.be'
]);
}
public function create()
{
// Create a post or perform other action on POST
}
public function shout(string $string)
{
return strtoupper($string);
}
}
use Namespace\Models\Order;
add_filter('sidewheels_user_has_access', function ($access, $route) {
if (current_user_can('manage_options')) {
$access = true;
}
// Only give access if current user is author of {order_id}
if ($route->path() == 'private-page/orders/{order_id}') {
$order = new Order($route->parameter('order_id'));
return $order->author() == get_current_user_id();
}
return $access;
}, 10, 2);
add_filter('sidewheels_route_title', function ($title, $route) {
if ($route->path() == 'public-page') {
$title = 'Custom public page title';
}
return $title;
}, 10, 2);
use \Twig\TwigFunction;
add_filter('sidewheels_twig_functions', function ($functions) {
$functions = new TwigFunction(
'customFunction',
function ($argument) {
// Modify $argument
return $argument;
}
);
return $functions;
});