Moved some files around to separate front and admin stuff
This commit is contained in:
@ -12,40 +12,40 @@ class Settings {
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'admin_menu', array( $this, 'append_to_main_dashboard_menu' ), 12 );
|
||||
add_action( 'admin_menu', array( $this, 'append_to_admin_menu' ), 12 );
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Append to the dashboard menu (prevents doubling).
|
||||
* Append to the admin menu (prevents doubling).
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function append_to_main_dashboard_menu(): 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_settings_page' );
|
||||
$callback = array( $this, 'show_main_settings_page' );
|
||||
|
||||
add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $callback );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the settings page on the dashboard.
|
||||
* Show the settings page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function show_settings_page(): void {
|
||||
public function show_main_settings_page(): void {
|
||||
$data = array();
|
||||
|
||||
echo nmsp_plugin_app()->blade->run( 'dashboard.settings', $data );
|
||||
echo nmsp_plugin_app()->blade->run( 'admin.settings', $data );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,16 +56,16 @@ class Settings {
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_scripts(): void {
|
||||
wp_enqueue_style( 'nmsp-plugin-dashboard-css', plugins_url( '../../assets/css/nmsp-plugin-name.css', __FILE__ ), array(), '1.0.0', 'screen' );
|
||||
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-dashboard-js', plugins_url( '../../assets/js/nmsp-plugin-name.js', __FILE__ ), array(), '1.0.0', false );
|
||||
wp_enqueue_script( 'nmsp-plugin-dashboard-js' );
|
||||
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-dashboard-js', 'nmspPluginDashboardApi', $payload );
|
||||
wp_localize_script( 'nmsp-plugin-name-admin-js', 'nmspPluginAdminApi', $payload );
|
||||
}
|
||||
|
||||
}
|
@ -137,9 +137,9 @@ class App {
|
||||
* @return void
|
||||
*/
|
||||
public function includes(): void {
|
||||
// Files to include on the dashboard.
|
||||
// Files to include on the admin.
|
||||
if ( is_admin() ) {
|
||||
require_once __DIR__ . '/dashboard/class-settings.php';
|
||||
require_once __DIR__ . '/admin/class-settings.php';
|
||||
}
|
||||
//
|
||||
|
||||
|
@ -4,10 +4,37 @@ 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' );
|
||||
|
||||
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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user