Adding a public-facing page with a shortcode
This commit is contained in:
parent
5aaf4bf1d0
commit
8f048c4088
@ -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();
|
11
templates/front/custom-page.blade.php
Normal file
11
templates/front/custom-page.blade.php
Normal 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
|
5
templates/layouts/front.blade.php
Normal file
5
templates/layouts/front.blade.php
Normal file
@ -0,0 +1,5 @@
|
||||
<div id="nmsp-plugin-font-app" class="">
|
||||
|
||||
@yield('content')
|
||||
|
||||
</div>
|
Loading…
x
Reference in New Issue
Block a user