69 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace PluginNamespace\Front;
 | |
| 
 | |
| if ( ! defined( 'ABSPATH' ) ) {
 | |
| 	exit;
 | |
| }
 | |
| 
 | |
| class CustomPage {
 | |
| 
 | |
| 	/**
 | |
| 	 * Class constructor.
 | |
| 	 *
 | |
| 	 * @since 1.0.0
 | |
| 	 *
 | |
| 	 * @return void
 | |
| 	 */
 | |
| 	public function __construct() {
 | |
| 		add_shortcode( 'nmsp_plugin_shortcode', array( $this, 'display_custom_page' ) );
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Register and enqueue stylesheets and javascript files.
 | |
| 	 *
 | |
| 	 * @since 1.0.0
 | |
| 	 *
 | |
| 	 * @return void
 | |
| 	 */
 | |
| 	public function enqueue_scripts(): void {
 | |
| 		wp_enqueue_style( 'nmsp-plugin-name-css', plugins_url( '../../assets/css/nmsp-plugin-name.css', __FILE__ ), array(), '1.0.0', 'screen' );
 | |
| 
 | |
| 		wp_register_script( 'nmsp-plugin-name-js', plugins_url( '../../assets/js/nmsp-plugin-name.js', __FILE__ ), array( 'jquery' ), '1.0.0', false );
 | |
| 		wp_enqueue_script( 'nmsp-plugin-name-js' );
 | |
| 
 | |
| 		$payload = array(
 | |
| 			'wp_ajax_url' => admin_url( 'admin-ajax.php' ),
 | |
| 			'_nonce'      => wp_create_nonce( NMSP_PLUGIN_NONCE ),
 | |
| 		);
 | |
| 		wp_localize_script( 'nmsp-plugin-name-js', 'nmspPluginApi', $payload );
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * 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,
 | |
| 			),
 | |
| 		);
 | |
| 
 | |
| 		ob_start();
 | |
| 		echo nmsp_plugin_app()->blade->run( 'front.custom-page', $data );
 | |
| 		$output = ob_get_clean();
 | |
| 		return wp_kses_post( $output );
 | |
| 	}
 | |
| 
 | |
| }
 | |
| 
 | |
| new CustomPage();
 |