PHP code example of clubdeuce / wpmvc-redux
1. Go to this page and download the library: Download clubdeuce/wpmvc-redux 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/ */
clubdeuce / wpmvc-redux example snippets
use Clubdeuce\Wpmvc_Redux\Application;
use Clubdeuce\Wpmvc_Redux\Contracts\HasActions;
class My_Plugin extends Application implements HasActions
{
public function add_actions(): void
{
add_action( 'init', [ $this, 'register_stuff' ] );
}
}
$plugin = new My_Plugin();
echo $plugin->getVersion(); // '1.0.0'
use Clubdeuce\Wpmvc_Redux\Base\Post;
class Book extends Post
{
// override any accessor or add custom methods
public function isbn(): string
{
return get_post_meta( $this->ID(), '_isbn', true ) ?: '';
}
}
$book = new Book( get_post( 42 ) );
echo $book->title(); // post_title
echo $book->slug(); // post_name
echo $book->status(); // post_status (e.g. 'publish')
echo $book->type(); // post_type
echo $book->date(); // post_date (MySQL datetime string)
echo $book->modified(); // post_modified
echo $book->excerpt(); // post_excerpt
$book->author_id(); // (int) post_author
$book->parent_id(); // (int) post_parent
$book->menu_order(); // (int) menu_order
$book->get_content_html(); // apply_filters('the_content', post_content)
$book->the_title(); // echoes esc_html( get_the_title() )
// Renders templates/book-card.php from the active theme
$book->the_template( 'book-card', [ 'show_date' => true ] );
// templates/book-card.php
echo $item->title();
if ( $show_date ) {
echo $item->date();
}
use Clubdeuce\Wpmvc_Redux\Base\Term;
class Genre extends Term {}
$genre = new Genre( get_term( 7, 'genre' ) );
echo $genre->ID(); // term_id
echo $genre->name(); // name
echo $genre->slug(); // slug
echo $genre->taxonomy(); // taxonomy
echo $genre->description(); // description
$genre->parent_id(); // (int) parent
$genre->count(); // (int) count
use Clubdeuce\Wpmvc_Redux\Controllers\Post_Type;
class Book_Post_Type extends Post_Type
{
const ?string POST_TYPE = 'book';
protected array $arguments = [
'public' => true,
'label' => 'Books',
'supports' => [ 'title', 'editor', 'thumbnail' ],
];
}
new Book_Post_Type(); // registers on wp 'init' hook automatically
use Clubdeuce\Wpmvc_Redux\Controllers\Taxonomy;
class Genre_Taxonomy extends Taxonomy
{
const ?string TAXONOMY = 'genre';
protected array $object_type = [ 'book' ];
protected array $arguments = [
'hierarchical' => true,
'label' => 'Genres',
];
}
new Genre_Taxonomy(); // registers on wp 'init' hook automatically
use Clubdeuce\Wpmvc_Redux\Contracts\HasActions;
interface HasActions
{
public function add_actions(): void;
}