Adding a public-facing page with a shortcode
This commit is contained in:
@ -147,7 +147,9 @@ class App {
|
||||
//
|
||||
|
||||
// Files to include that may be sub-namespaced.
|
||||
//
|
||||
if ( is_single() ) {
|
||||
require_once __DIR__ . '/front/class-custompage.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
36
includes/front/class-custompage.php
Normal file
36
includes/front/class-custompage.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace PluginNamespace\Front;
|
||||
|
||||
class CustomPage {
|
||||
|
||||
public function __construct() {
|
||||
add_shortcode( 'nmsp_plugin_shortcode', array( $this, 'display_custom_page' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a page in place of a shortcode.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $attributes Array of attributes on the shortcode string in the post body.
|
||||
* @param string $content (optional) Text content that is between opening and closing shortcodes.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display_custom_page( array $attributes = array(), $content = null ) {
|
||||
$data = array(
|
||||
'shortcode' => array(
|
||||
'attributes' => $attributes,
|
||||
'content' => $content,
|
||||
),
|
||||
);
|
||||
|
||||
// phpcs:disable WordPress.Security.EscapeOutput
|
||||
return nmsp_plugin_app()->blade->run( 'front.custom-page', $data );
|
||||
// phpcs:enable WordPress.Security.EscapeOutput
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new CustomPage();
|
Reference in New Issue
Block a user