Adding direct access prevention to files

This commit is contained in:
Brian 2021-09-14 12:39:25 -06:00
parent 023c0f53e6
commit 3e03887bda
Signed by: brian
GPG Key ID: DE1A5390A3B84CD8
11 changed files with 61 additions and 18 deletions

View File

@ -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 );
}

View File

@ -1,5 +1,9 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
| ----------------------------------------------------------------
| Bootstrap

View File

@ -1,5 +1,9 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
| ----------------------------------------------------------------
| Base Definitions

View File

@ -1,5 +1,9 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
| ----------------------------------------------------------------
| HTTP Status Code Definitions

View File

@ -1,5 +1,9 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
| ----------------------------------------------------------------
| URL Rewrite Definitions

View File

@ -5,6 +5,10 @@ namespace PluginNamespace;
use eftec\bladeone\BladeOne;
use Exception;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class App {
/** @var \PluginNamespace\App */

View File

@ -5,7 +5,7 @@ namespace PluginNamespace;
use WP_CLI;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
exit;
}
class NmspCli {

View File

@ -2,6 +2,10 @@
namespace PluginNamespace\Front;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class CustomPage {
/**

View File

@ -2,6 +2,10 @@
namespace PluginNamespace\Front;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Rewrites {
/**

View File

@ -3,16 +3,16 @@
/**
* Boilerplate Plugin
*
* @package BoilerplatePlugin
* @author
* @copyright
* @license
* @package BoilerplatePlugin
* @author Plugin Author
* @copyright GPL v2
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
*
* @wordpress-plugin
* Plugin Name: Boilerplate Plugin
* Description: Your plugin description.
* License: GPL v2
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
* Plugin URI: https://domain.com
* Update URI: https://example.com/my-plugin/
* Version: 1.0.0
@ -21,12 +21,21 @@
* Author: Plugin Author
* Author URI: https://plugin-author.com
* Text Domain: nmsp-plugin-name-text-domain
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
exit;
}
/**
* Currently plugin version.
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'PLUGIN_NAME_VERSION', '1.0.0' );
define( 'NMSP_PLUGIN_BASE_DIR', __DIR__ );
require_once __DIR__ . '/vendor/autoload.php';

View File

@ -1,12 +1,11 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
// Exit if accessed directly
exit;
}
// This constant gets set when WordPress' uninstall.php file is invoked.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
// This constant gets set when WordPress' uninstall.php file is invoked.
exit;
}