Adding a public-facing page with a shortcode

This commit is contained in:
Brian 2021-06-01 09:33:09 -06:00
parent 5aaf4bf1d0
commit 8f048c4088
Signed by: brian
GPG Key ID: DE1A5390A3B84CD8
4 changed files with 55 additions and 1 deletions

View File

@ -147,7 +147,9 @@ class App {
//
// Files to include that may be sub-namespaced.
//
if ( is_single() ) {
require_once __DIR__ . '/front/class-custompage.php';
}
}
/**

View 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();

View File

@ -0,0 +1,11 @@
@extends('layouts.front')
@section('content')
<p>Here is the content of the blade file, it will show in place of your shortcode.</p>
<p>Here are the attributes you passed in:</p>
<ul>
@foreach($shortcode['attributes'] as $key => $val)
<li>{{ $key }}: {{ $val }}</li>
@endforeach
</ul>
@endsection

View File

@ -0,0 +1,5 @@
<div id="nmsp-plugin-font-app" class="">
@yield('content')
</div>