PHP code example of inc2734 / wp-view-controller

1. Go to this page and download the library: Download inc2734/wp-view-controller 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/ */

    

inc2734 / wp-view-controller example snippets



// in functions.php
new Inc2734\WP_View_Controller\Bootstrap();


// in page template
use Inc2734\WP_View_Controller\Bootstrap;

Bootstrap::layout( 'right-sidebar' );
Bootstrap::render( 'front-page' );

/**
 * Change config path
 *
 * @param string $path
 * @return string $path
 */
add_filter(
	'inc2734_wp_view_controller_config_path',
	function( $path ) {
		return $path;
	}
);

/**
 * Define and return the content before loading the template.
 * If a string is returned, the template will not load.
 *
 * @param null $html
 * @param string $slug
 * @param string $name
 * @param array $vars
 * @return string
 */
add_filter(
	'inc2734_wp_view_controller_pre_template_part_render',
	function( $html, $slug, $name, $vars ) {
		return $html;
	},
	10,
	4
);

/**
 * Customize the rendered HTML
 *
 * @param string $html
 * @param string $slug
 * @param string $name
 * @param array $vars
 * @return string
 */
add_filter(
	'inc2734_wp_view_controller_template_part_render',
	function( $html, $slug, $name, $vars ) {
		return $html;
	},
	10,
	4
);

/**
 * Change layout file
 *
 * @param string $layout The layout file template slug
 * @return string
 */
add_filter(
	'inc2734_wp_view_controller_layout',
	function( $layout ) {
		return $layout;
	}
);

/**
* Change view file
*
* @param string $view The view file template slug
* @return string
*/
add_filter(
	'inc2734_wp_view_controller_view',
	function( $view ) {
		return $view;
	}
);

/**
 * Customize config values
 *
 * @param array $values
 * @return array
*/
add_filter(
	'inc2734_wp_view_controller_config',
	function( $values ) {
		return $values;
	}
);

/**
 * Change controller
 *
 * @param string $template
 * @return string
 */
add_filter(
	'inc2734_wp_view_controller_controller',
	function( $template ) {
		return $template;
	}
);

/**
 * Customize template part args
 *
 * @param array $args
 *   @var string $slug
 *   @var string $name
 *   @var array $vars
 * @return array
 */
add_filter(
	'inc2734_wp_view_controller_get_template_part_args',
	function( $args ) {
		return $args;
	}
);

/**
 * Customize root hierarchy
 *
 * @param array $hierarchy
 * @param string $slug
 * @param string $name
 * @param array $vars
 * @return array
 */
add_filter(
	'inc2734_wp_view_controller_template_part_root_hierarchy',
	function( $hierarchy, $slug, $name, $vars ) {
		return $hierarchy;
	},
	10,
	4
);

/**
 * You can specify a template for fallback
 *
 * @param string|null $fallback_slug
 * @param array $relative_dir_paths
 * @param string $slug
 * @param string $name
 * @return string|null
 */
add_filter(
	'inc2734_wp_view_controller_located_template_slug_fallback',
	function( $fallback_slug, $relative_dir_paths, $slug, $name ) {
		return $fallback_slug;
	},
	10,
	4
);

/**
 * Change rendered type.
 *
 * loop ... Loading in the WordPress loop
 * direct ... Simply loading
 *
 * @param string $render_type loop or direct
 * @return string
 */
add_filter(
	'inc2734_wp_view_controller_render_type',
	function( $render_type ) {
		return $render_type;
	}
);

/**
 * Define template
 *
 * @deprecated
 *
 * @param array $vars
 * @return void
 */
add_action(
	'inc2734_wp_view_controller_get_template_part_<slug>-<name>',
	function( $vars ) {
		

/**
 * Define template
 *
 * @deprecated
 *
 * @param string $name
 * @param array $vars
 * @return void
 */
add_action(
	'inc2734_wp_view_controller_get_template_part_<slug>',
	function( $name, $vars ) {
		

/**
 * Fire before template rendering
 *
 * @param array $args
 */
add_action(
	'inc2734_wp_view_controller_get_template_part_pre_render',
	function( $args ) {
		// Do something
	}
);

/**
 * Fire after template rendering
 *
 * @param array $args
 */
add_action(
	'inc2734_wp_view_controller_get_template_part_post_render',
	function( $args ) {
		// Do something
	}
);
 $_view_controller->view();