Facades - nikonorovsv/wpf GitHub Wiki
The facade implements the wpf\wp\facades\IFacade
interface to obtain a single interface for objects such as WP_Post, WP_Term, WP_Site, WP_User and provides the classes Post, Term, User, Blog. All fields, presented by Wordpress, as well as meta-fields, with the help of magic methods become properties of the corresponding classes.
It looks like this
use \wpf\wp\facades\Post;
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
$p = new Post();
echo render('card', [
'title' => $p->title(),
'description' => $p->excerpt(20),
'url' => $p->url(),
'image' => $p->thumbUrl('medium')
]);
}
}
You can extend the functionality for a custom post types by inheriting one of these classes.
namespace app\facades;
use \wpf\wp\facades\Post;
use \wpf\helpers\Date;
final class Document extends Post {
private $type_info;
private $file_type;
public $date = null;
public $title;
public $url;
public $path;
public $size;
public $ext;
public $mime_type;
public function __construct( $post = null ) {
parent::__construct( $post );
$this->path = get_attached_file( $this->ID );
$this->size = file_exists( $this->path ) ? size_format( filesize( $this->path ) ) : null;
$this->type_info = wp_check_filetype( $this->path );
$this->ext = $this->type_info['ext'];
$this->mime_type = $this->type_info['type'];
$this->file_type = wp_ext2type( $this->ext );
if ( $this->placement_date ) {
$this->date = new Date( $this->placement_date );
}
}
public function title() {
return $this->post_excerpt ?: $this->post_title;
}
public function url() {
return wp_get_attachment_url( $this->ID );
}
public function __toString() {
return render( 'layouts/document', [
'name' => $this->title(),
'url' => $this->url(),
'icon' => $this->getIcon(),
'ext' => $this->ext,
'size' => $this->size,
'file_exists' => file_exists( $this->path ),
'options' => [],
'annexes' => $this->getAnnexes(),
'date' => is_null( $this->date ) ? '' : $this->date->format('d F Y г.')
] );
}
public function getIcon() {
// Return icon class
}
}