inc2734/wp-plugin-view-controller

1.1.1 2020-11-17 17:30 UTC

This package is auto-updated.

Last update: 2020-11-17 17:33:15 UTC


README

Build Status Latest Stable Version License

Install

$ composer require inc2734/wp-plugin-view-controller

How to use

use Inc2734\WP_Plugin_View_Controller\Bootstrap;

$bootstrap = new Bootstrap(
	[
		'prefix' => 'prefix_',
		'path'   => __DIR__ . '/templates/',
	]
);

$bootstrap->render( $slug, $name, $args );

Filter hooks

<prefix>view_args

/**
 * @param array $args
 *  @var string $slug
 *  @var string $name
 *  @var array $vars
 * @param array
 */
add_filter(
	'<prefix>view_args',
	function( $args ) {
		return $args;
	}
);

<prefix>view_render_definition

/**
 * @param null|string $html
 * @param string $slug
 * @param string $name
 * @param array $vars
 * @return string
 */
add_filter(
	'<prefix>view_render_definition',
	function( $html, $slug, $name, $vars ) {
		return 'YOUR HTML';
	},
	10,
	4
);

<prefix>view_render

/**
 * @param string $html
 * @param string $slug
 * @param string $name
 * @param array $vars
 * @return string
 */
add_filter(
	'<prefix>view_render',
	function( $html, $slug, $name, $vars ) {
		return $html;
	},
	10,
	4
);

Action hooks

<prefix>view_pre_render

/**
 * @param array $args
 *  @var string $slug
 *  @var string $name
 *  @var array $vars
 */
add_action(
	'<prefix>view_pre_render',
	function( $args ) {
	}
);

<prefix>view_post_render

/**
 * @param array $args
 *  @var string $slug
 *  @var string $name
 *  @var array $vars
 */
add_action(
	'<prefix>view_post_render',
	function( $args ) {
	}
);

<prefix>view_<slug>

/**
 * @param string $name
 * @param array $vars
 */
add_action(
	'<prefix>view_<slug>',
	function( $name, $vars ) {
		?>
		HTML
		<?php
	},
	10,
	2
);

<prefix>view_<slug>-<name>

/**
 * @param array $vars
 */
add_action(
	'<prefix>view_<slug>-<name>',
	function( $vars ) {
		?>
		HTML
		<?php
	}
);