Moving admin to it's own directory, trying to fix up docblocks and stuff
This commit is contained in:
@ -3,60 +3,61 @@
|
||||
namespace PluginNamespace\Front;
|
||||
|
||||
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' );
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
add_shortcode( 'nmsp_plugin_shortcode', array( $this, 'display_custom_page' ) );
|
||||
}
|
||||
|
||||
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' );
|
||||
/**
|
||||
* 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' );
|
||||
|
||||
$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 );
|
||||
}
|
||||
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' );
|
||||
|
||||
/**
|
||||
* 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,
|
||||
),
|
||||
);
|
||||
$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 );
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.Security.EscapeOutput
|
||||
return nmsp_plugin_app()->blade->run( 'front.custom-page', $data );
|
||||
// phpcs:enable WordPress.Security.EscapeOutput
|
||||
}
|
||||
/**
|
||||
* 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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -4,90 +4,90 @@ namespace PluginNamespace\Front;
|
||||
|
||||
class Rewrites {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'init', array( $this, 'add_rewrite_rules' ), 5 );
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'init', array( $this, 'add_rewrite_rules' ), 5 );
|
||||
|
||||
add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
|
||||
add_filter( 'nmsp_plugin_name_rewrite_urls', array( $this, 'build_rewrite_urls' ) );
|
||||
}
|
||||
add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
|
||||
add_filter( 'nmsp_plugin_name_rewrite_urls', array( $this, 'build_rewrite_urls' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate new rewrite rules and flush the cached values.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_rewrite_rules(): void {
|
||||
$filters = apply_filters( 'nmsp_plugin_name_rewrite_urls', array() );
|
||||
/**
|
||||
* Generate new rewrite rules and flush the cached values.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_rewrite_rules(): void {
|
||||
$filters = apply_filters( 'nmsp_plugin_name_rewrite_urls', array() );
|
||||
|
||||
add_rewrite_tag( 'foo', '([0-9]+)' );
|
||||
add_rewrite_tag( 'foo', '([0-9]+)' );
|
||||
|
||||
if ( is_iterable( $filters ) && count( $filters ) > 0 ) {
|
||||
foreach ( $filters as $item ) {
|
||||
if ( $item['slug'] ) {
|
||||
$slug = str_replace( home_url() . '/', '', get_permalink( $item['id'] ) );
|
||||
add_rewrite_rule( '^' . $slug . '([^/]*' . $item['var'] . ')/([^/]*)/?', 'index.php?page_id=' . $item['id'] . '&$matches[1]=$matches[2]', 'top' );
|
||||
}
|
||||
}
|
||||
if ( is_iterable( $filters ) && count( $filters ) > 0 ) {
|
||||
foreach ( $filters as $item ) {
|
||||
if ( $item['slug'] ) {
|
||||
$slug = str_replace( home_url() . '/', '', get_permalink( $item['id'] ) );
|
||||
add_rewrite_rule( '^' . $slug . '([^/]*' . $item['var'] . ')/([^/]*)/?', 'index.php?page_id=' . $item['id'] . '&$matches[1]=$matches[2]', 'top' );
|
||||
}
|
||||
}
|
||||
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
}
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the array of post IDs that have a slug for the URL
|
||||
* along with what custom query variable to use.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function build_rewrite_urls(): array {
|
||||
$pages = array();
|
||||
/**
|
||||
* Build the array of post IDs that have a slug for the URL
|
||||
* along with what custom query variable to use.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function build_rewrite_urls(): array {
|
||||
$pages = array();
|
||||
|
||||
$page_list = array(
|
||||
'NMSP_PLUGIN_SLUG_PAGE_NAME' => array( 'foo' ),
|
||||
);
|
||||
$page_list = array(
|
||||
'NMSP_PLUGIN_SLUG_PAGE_NAME' => array( 'foo' ),
|
||||
);
|
||||
|
||||
foreach ( $page_list as $key => $params ) {
|
||||
$page_id = get_option( constant( $key ) );
|
||||
$page = ( $page_id ) ? get_post( $page_id ) : false;
|
||||
if ( ! empty( $page ) ) {
|
||||
foreach ( $params as $param ) {
|
||||
$pages[] = array(
|
||||
'id' => $page_id,
|
||||
'slug' => $page->post_name,
|
||||
'var' => $param,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ( $page_list as $key => $params ) {
|
||||
$page_id = get_option( constant( $key ) );
|
||||
$page = ( $page_id ) ? get_post( $page_id ) : false;
|
||||
if ( ! empty( $page ) ) {
|
||||
foreach ( $params as $param ) {
|
||||
$pages[] = array(
|
||||
'id' => $page_id,
|
||||
'slug' => $page->post_name,
|
||||
'var' => $param,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $pages;
|
||||
}
|
||||
return $pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append custom query variables to the list WordPress maintinas
|
||||
* with each request.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $variable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function custom_query_vars( array $vars ): array {
|
||||
$vars[] = 'foo';
|
||||
return $vars;
|
||||
}
|
||||
/**
|
||||
* Append custom query variables to the list WordPress maintinas
|
||||
* with each request.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $variable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function custom_query_vars( array $vars ): array {
|
||||
$vars[] = 'foo';
|
||||
return $vars;
|
||||
}
|
||||
}
|
||||
|
||||
new Rewrites();
|
||||
|
1
includes/front/index.php
Normal file
1
includes/front/index.php
Normal file
@ -0,0 +1 @@
|
||||
<?php // silence is golden
|
Reference in New Issue
Block a user