Moved some files around to separate front and admin stuff
This commit is contained in:
		
							
								
								
									
										73
									
								
								includes/admin/class-settings.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								includes/admin/class-settings.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,73 @@ | ||||
| <?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(); | ||||
		Reference in New Issue
	
	Block a user