Adding direct access prevention to files
This commit is contained in:
@ -2,6 +2,10 @@
|
||||
|
||||
namespace PluginNamespace\Admin;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Settings {
|
||||
|
||||
/**
|
||||
@ -26,11 +30,11 @@ class Settings {
|
||||
*/
|
||||
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' );
|
||||
$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 );
|
||||
}
|
||||
@ -45,7 +49,7 @@ class Settings {
|
||||
public function show_main_settings_page(): string {
|
||||
$data = array();
|
||||
|
||||
$this->localize_script();
|
||||
$this->localize_script( array() );
|
||||
|
||||
ob_start();
|
||||
echo nmsp_plugin_app()->blade->run( 'admin.settings', $data );
|
||||
@ -78,9 +82,12 @@ class Settings {
|
||||
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 ),
|
||||
$payload = array_merge(
|
||||
$additional_data,
|
||||
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 );
|
||||
}
|
||||
|
Reference in New Issue
Block a user