PHP code example of undefinedfr / undefined-wp-framework
1. Go to this page and download the library: Download undefinedfr/undefined-wp-framework 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/ */
undefinedfr / undefined-wp-framework example snippets
namespace App\PostType;
use Undefined\Core\PostType\PostType;
class Project extends PostType
{
public static function getPostType(): string
{
return 'project';
}
protected static function getPostTypeConfig(): array
{
return [
'singulier' => 'Projet',
'pluriel' => 'Projets',
'feminin' => false,
'menu_icon' => 'dashicons-portfolio',
'supports' => ['title', 'editor', 'thumbnail'],
'taxonomies' => ['project_category'],
];
}
// Hook appelé à la sauvegarde
public static function onSavePost($post_id): void
{
// Logique personnalisée
}
}
namespace App\Taxonomy;
use Undefined\Core\Taxonomy\Taxonomy;
class ProjectCategory extends Taxonomy
{
public static function getTaxonomy(): string
{
return 'project_category';
}
protected static function getTaxonomyConfig(): array
{
return [
'name' => 'Catégorie',
'pluriel' => 'Catégories',
'feminin' => true,
'post_types' => ['project'],
'hierarchical' => true,
];
}
// Hook appelé à la sauvegarde d'un terme
public static function onSaveTerm($term_id, $tt_id, $update, $args): void
{
// Logique personnalisée
}
}
namespace App\blocks\hero;
use Undefined\Core\Block\Block;
use Extended\ACF\Fields\Text;
use Extended\ACF\Fields\Image;
class Hero extends Block
{
public $name = 'hero';
public $title = 'Hero Banner';
public $description = 'Bannière principale';
public $category = 'custom';
public $icon = 'cover-image';
public $mode = 'preview';
public $keywords = ['banner', 'header'];
protected function _setGroupField(): void
{
parent::_setGroupField();
$this->groupField['fields'] = [
Text::make('Titre', 'title')
->
// app/Controllers/AccountController.php
use Undefined\Core\Controllers\AbstractController;
class AccountController extends AbstractController
{
// Action par défaut: /account/
public function indexAction()
{
if (!is_user_logged_in()) {
$this->_redirect('/login');
}
$this->_setTitle('Mon compte');
$this->_setData([
'user' => wp_get_current_user(),
]);
$this->render();
}
// Action: /account/orders
public function ordersAction()
{
$this->_setData([
'orders' => $this->getOrders(),
]);
$this->render();
}
// POST sur /account/orders
public function ordersPostAction()
{
// Traitement du formulaire
$this->_addNotice('success', 'Commande mise à jour');
$this->_redirect('/account/orders');
}
}
// app/Router.php
use Undefined\Core\Router;
class AppRouter extends Router
{
public function __construct()
{
parent::__construct();
// Route simple
$this->addRule('account');
// Route avec section
$this->addRule('account', 'orders');
// Route avec paramètres dynamiques
$this->addRule('account', 'order', [
'order_id' => '([0-9]+)'
]);
}
}