Moving admin to it's own directory, trying to fix up docblocks and stuff
This commit is contained in:
@ -1,73 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace PluginNamespace;
|
||||
|
||||
class Settings {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'admin_menu', array( $this, 'append_to_admin_menu' ), 12 );
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Append to the admin menu (prevents doubling).
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function append_to_admin_menu(): void {
|
||||
$parent_slug = 'nmsp-plugin-name-menu-slug';
|
||||
$page_title = __( 'Namespace Plugin Name - Settings', 'nmsp_plugin_name_settings_title' );
|
||||
$menu_title = __( 'Settings', 'nmsp_plugin_name_settings_title' );
|
||||
$capability = 'manage_options';
|
||||
$menu_slug = $parent_slug;
|
||||
$callback = array( $this, 'show_main_settings_page' );
|
||||
|
||||
add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $callback );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the settings page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function show_main_settings_page(): void {
|
||||
$data = array();
|
||||
|
||||
echo nmsp_plugin_app()->blade->run( 'admin.settings', $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register and enqueue stylesheets and javascript files.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_scripts(): void {
|
||||
wp_enqueue_style( 'nmsp-plugin-name-admin-css', plugins_url( '../../assets/css/nmsp-plugin-name-admin.css', __FILE__ ), array(), '1.0.0', 'screen' );
|
||||
|
||||
wp_register_script( 'nmsp-plugin-name-admin-js', plugins_url( '../../assets/js/nmsp-plugin-name-admin.js', __FILE__ ), array( 'jquery' ), '1.0.0', false );
|
||||
wp_enqueue_script( 'nmsp-plugin-name-admin-js' );
|
||||
|
||||
$payload = array(
|
||||
'wp_ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'_nonce' => wp_create_nonce( NMSP_PLUGIN_NONCE ),
|
||||
);
|
||||
wp_localize_script( 'nmsp-plugin-name-admin-js', 'nmspPluginAdminApi', $payload );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new Settings();
|
@ -7,162 +7,160 @@ use Exception;
|
||||
|
||||
class App {
|
||||
|
||||
/** @var \PluginNamespace\App */
|
||||
public static $instance;
|
||||
/** @var \PluginNamespace\App */
|
||||
public static $instance;
|
||||
|
||||
/** @var \eftec\bladeone\BladeOne */
|
||||
public $blade;
|
||||
/** @var \eftec\bladeone\BladeOne */
|
||||
public $blade;
|
||||
|
||||
/**
|
||||
* Any logic that needs executed when the plugin is activated.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function plugin_activation(): void {
|
||||
self::ensure_template_cache_dir_exists();
|
||||
}
|
||||
/**
|
||||
* Any logic that needs executed when the plugin is activated.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function plugin_activation(): void {
|
||||
self::ensure_template_cache_dir_exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Any logic that needs executed when the plugin is deactivated.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function plugin_deactivation(): void {
|
||||
//
|
||||
}
|
||||
/**
|
||||
* Any logic that needs executed when the plugin is deactivated.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function plugin_deactivation(): void {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the cache directory for Blade exists and
|
||||
* if not then attempt to create it.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function ensure_template_cache_dir_exists(): void {
|
||||
if ( ! file_exists( NMSP_PLUGIN_BASE_DIR . '/cache/blade/.gitignore' ) ) {
|
||||
try {
|
||||
mkdir( NMSP_PLUGIN_BASE_DIR . '/cache/blade', 0755, true );
|
||||
} catch ( Exception $e ) {
|
||||
$error_payload = array(
|
||||
'level' => 'critical',
|
||||
'message' => $e->getMessage(),
|
||||
'context' => array(
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
),
|
||||
);
|
||||
error_log( json_encode( $error_payload, JSON_PRETTY_PRINT ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check that the cache directory for Blade exists and
|
||||
* if not then attempt to create it.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function ensure_template_cache_dir_exists(): void {
|
||||
if ( ! file_exists( NMSP_PLUGIN_BASE_DIR . '/cache/blade/.gitignore' ) ) {
|
||||
try {
|
||||
mkdir( NMSP_PLUGIN_BASE_DIR . '/cache/blade', 0755, true );
|
||||
} catch ( Exception $e ) {
|
||||
$error_payload = array(
|
||||
'level' => 'critical',
|
||||
'message' => $e->getMessage(),
|
||||
'context' => array(
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
),
|
||||
);
|
||||
error_log( json_encode( $error_payload, JSON_PRETTY_PRINT ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of this plugin class. If it has
|
||||
* not been initialized, do so then return it.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return \PluginNamespace\App
|
||||
*/
|
||||
public static function get_instance(): App {
|
||||
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof App ) ) {
|
||||
self::$instance = new App();
|
||||
/**
|
||||
* Return an instance of this plugin class. If it has
|
||||
* not been initialized, do so then return it.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return \PluginNamespace\App
|
||||
*/
|
||||
public static function get_instance(): App {
|
||||
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof App ) ) {
|
||||
self::$instance = new App();
|
||||
|
||||
self::$instance->load_plugin_textdomain();
|
||||
self::$instance->scaffold_plugin();
|
||||
self::$instance->includes();
|
||||
}
|
||||
self::$instance->load_plugin_textdomain();
|
||||
self::$instance->scaffold_plugin();
|
||||
self::$instance->includes();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load your translation files for this plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load_plugin_textdomain(): void {
|
||||
load_plugin_textdomain( 'nmsp-plugin-name-text-domain', false, 'languages' );
|
||||
}
|
||||
/**
|
||||
* Load your translation files for this plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load_plugin_textdomain(): void {
|
||||
load_plugin_textdomain( 'nmsp-plugin-name-text-domain', false, 'languages' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Steps to take when initializing this plugin??
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function scaffold_plugin(): void {
|
||||
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
|
||||
}
|
||||
/**
|
||||
* Steps to take when initializing this plugin??
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function scaffold_plugin(): void {
|
||||
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setting up the WordPress dashboard menu for this plugin.
|
||||
* Setting this here to be overriden later so that a base is always available.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_admin_menu(): void {
|
||||
$page_title = __( 'Namespace Plugin Name', 'nmsp_plugin_name_menu' );
|
||||
$menu_title = __( 'Namespace Plugin Name', 'nmsp_plugin_name_menu' );
|
||||
$capability = 'manage_options';
|
||||
$menu_slug = 'nmsp-plugin-name-menu-slug';
|
||||
$callback = '';
|
||||
$icon = plugins_url( '../assets/images/menu-icon.svg', __FILE__ );
|
||||
$position = 100;
|
||||
/**
|
||||
* Setting up the WordPress dashboard menu for this plugin.
|
||||
* Setting this here to be overriden later so that a base is always available.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_admin_menu(): void {
|
||||
$page_title = __( 'Namespace Plugin Name', 'nmsp_plugin_name_menu' );
|
||||
$menu_title = __( 'Namespace Plugin Name', 'nmsp_plugin_name_menu' );
|
||||
$capability = 'manage_options';
|
||||
$menu_slug = 'nmsp-plugin-name-menu-slug';
|
||||
$callback = '';
|
||||
$icon = plugins_url( '../assets/images/menu-icon.svg', __FILE__ );
|
||||
$position = 100;
|
||||
|
||||
add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $callback, $icon, $position );
|
||||
}
|
||||
add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $callback, $icon, $position );
|
||||
}
|
||||
|
||||
/**
|
||||
* Other files to include so that this plugin will
|
||||
* have a single entrypoint but be able to break
|
||||
* up code in a logical manor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function includes(): void {
|
||||
// Files to include on the admin.
|
||||
if ( is_admin() ) {
|
||||
require_once __DIR__ . '/admin/class-settings.php';
|
||||
}
|
||||
//
|
||||
/**
|
||||
* Other files to include so that this plugin will
|
||||
* have a single entrypoint but be able to break
|
||||
* up code in a logical manor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function includes(): void {
|
||||
// Files to include on the admin.
|
||||
if ( is_admin() ) {
|
||||
require_once NMSP_PLUGIN_BASE_DIR . '/admin/class-settings.php';
|
||||
}
|
||||
//
|
||||
|
||||
// Files to include on every request.
|
||||
//
|
||||
// Files to include on every request.
|
||||
//
|
||||
|
||||
// Files to include that may be sub-namespaced.
|
||||
if ( is_single() ) {
|
||||
require_once __DIR__ . '/front/class-custompage.php';
|
||||
}
|
||||
}
|
||||
// Files to include that may be sub-namespaced.
|
||||
require_once __DIR__ . '/front/class-custompage.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* .
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param \eftec\bladeone\BladeOne $blade
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load_blade( BladeOne $blade ): void {
|
||||
$this->blade = $blade;
|
||||
}
|
||||
/**
|
||||
* Load Blade as the templating engine for the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param \eftec\bladeone\BladeOne $blade
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load_blade( BladeOne $blade ): void {
|
||||
$this->blade = $blade;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,39 +5,39 @@ namespace PluginNamespace;
|
||||
use WP_CLI;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class NmspCli {
|
||||
|
||||
/**
|
||||
* Class constructor. Can add commands here.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
WP_CLI::add_command(
|
||||
'nmsp-plugin do',
|
||||
array( $this, 'do_the_thing' ),
|
||||
array(
|
||||
'shortdesc' => __( 'The short description.', 'nmsp-plugin-name-text-domain' ),
|
||||
'longdesc' => __( "This is the super long description that will go on and on my friend. Some people started writing it not knowing what it was, and we'll continue writing it forever just because this is the description that never ends...", 'nmsp-plugin-name-text-domain' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Class constructor. Can add commands here.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
WP_CLI::add_command(
|
||||
'nmsp-plugin do',
|
||||
array( $this, 'do_the_thing' ),
|
||||
array(
|
||||
'shortdesc' => __( 'The short description.', 'nmsp-plugin-name-text-domain' ),
|
||||
'longdesc' => __( "This is the super long description that will go on and on my friend. Some people started writing it not knowing what it was, and we'll continue writing it forever just because this is the description that never ends...", 'nmsp-plugin-name-text-domain' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A sample method where something is done.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function do_the_thing(): void {
|
||||
WP_CLI::success( __( 'Congradulations, it is working.', 'nmsp-plugin-name-text-domain' ) );
|
||||
}
|
||||
/**
|
||||
* A sample method where something is done by being invoked from WP CLI.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function do_the_thing(): void {
|
||||
WP_CLI::success( __( 'Congradulations, it is working.', 'nmsp-plugin-name-text-domain' ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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
|
1
includes/index.php
Normal file
1
includes/index.php
Normal file
@ -0,0 +1 @@
|
||||
<?php // silence is golden
|
Reference in New Issue
Block a user