Moving admin to it's own directory, trying to fix up docblocks and stuff
This commit is contained in:
90
admin/class-settings.php
Normal file
90
admin/class-settings.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace PluginNamespace\Admin;
|
||||
|
||||
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, 'register_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 string
|
||||
*/
|
||||
public function show_main_settings_page(): string {
|
||||
$data = array();
|
||||
|
||||
$this->localize_script();
|
||||
|
||||
ob_start();
|
||||
echo nmsp_plugin_app()->blade->run( 'admin.settings', $data );
|
||||
$output = ob_get_clean();
|
||||
return wp_kses_post( $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register and enqueue stylesheets and javascript files.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $additional_data (optional) Additional key-value paired data to pass to JavaScript.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function localize_script( array $additional_data = array() ): void {
|
||||
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();
|
1
admin/index.php
Normal file
1
admin/index.php
Normal file
@ -0,0 +1 @@
|
||||
<?php // silence is golden
|
Reference in New Issue
Block a user