admin-site-enhancements.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Plugin Name: Admin and Site Enhancements (ASE) |
| 5 | * Plugin URI: https://www.wpase.com/plugin-uri |
| 6 | * Description: Easily enable enhancements and features that usually require multiple plugins. |
| 7 | * Version: 8.4.2 |
| 8 | * Author: wpase.com |
| 9 | * Author URI: https://www.wpase.com/author-uri |
| 10 | * License: GPL-2.0+ |
| 11 | * License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 12 | */ |
| 13 | // If this file is called directly, abort. |
| 14 | if ( !defined( 'ABSPATH' ) ) { |
| 15 | exit; |
| 16 | } |
| 17 | |
| 18 | define( 'ASENHA_VERSION', '8.4.2' ); |
| 19 | define( 'ASENHA_ID', 'asenha' ); |
| 20 | define( 'ASENHA_SLUG', 'admin-site-enhancements' ); |
| 21 | define( 'ASENHA_SLUG_U', 'admin_site_enhancements' ); |
| 22 | define( 'ASENHA_URL', plugins_url( '/', __FILE__ ) ); // e.g. https://www.example.com/wp-content/plugins/this-plugin/ |
| 23 | define( 'ASENHA_PATH', plugin_dir_path( __FILE__ ) ); // e.g. /home/user/apps/wp-root/wp-content/plugins/this-plugin/ |
| 24 | // define( 'ASENHA_BASE', plugin_basename( __FILE__ ) ); // e.g. plugin-slug/this-file.php |
| 25 | // define( 'ASENHA_FILE', __FILE__ ); // /home/user/apps/wp-root/wp-content/plugins/this-plugin/this-file.php |
| 26 | |
| 27 | /** |
| 28 | * Autoload classes defined by this plugin |
| 29 | * |
| 30 | * @param string $class_name e.g. \ASENHA\Classes\The_Name |
| 31 | * @since 1.0.0 |
| 32 | */ |
| 33 | function asenha_autoloader( $class_name ) { |
| 34 | |
| 35 | $namespace = 'ASENHA'; |
| 36 | |
| 37 | // Only process classes within this plugin's namespace |
| 38 | |
| 39 | if ( false !== strpos( $class_name, $namespace ) ) { |
| 40 | |
| 41 | // Assemble file path where class is defined |
| 42 | |
| 43 | // \ASENHA\Classes\The_Name => \Classes\The_Name |
| 44 | $path = str_replace( $namespace, "", $class_name ); |
| 45 | |
| 46 | // \Classes\The_Name => /classes/the_name |
| 47 | $path = str_replace( "\\", DIRECTORY_SEPARATOR, strtolower( $path ) ); |
| 48 | |
| 49 | // /classes/the_name => /classes/the-name.php |
| 50 | $path = str_replace( "_", "-", $path ) . '.php'; |
| 51 | |
| 52 | // /classes/the-name.php => /classes/class-the-name.php |
| 53 | $path = str_replace( "classes" . DIRECTORY_SEPARATOR, "classes" . DIRECTORY_SEPARATOR . "class-", $path ); |
| 54 | |
| 55 | // Remove first '/' |
| 56 | $path = substr( $path, 1 ); |
| 57 | |
| 58 | // Get /plugin-path/classes/class-the-name.php |
| 59 | $path = ASENHA_PATH . $path; |
| 60 | |
| 61 | if ( file_exists( $path ) ) { |
| 62 | require_once( $path ); |
| 63 | } |
| 64 | |
| 65 | } |
| 66 | |
| 67 | } |
| 68 | |
| 69 | // Register autoloading classes |
| 70 | spl_autoload_register( 'asenha_autoloader' ); |
| 71 | |
| 72 | /** |
| 73 | * Code that runs on plugin activation |
| 74 | * |
| 75 | * @since 1.0.0 |
| 76 | */ |
| 77 | function asenha_on_activation() { |
| 78 | $activation = new ASENHA\Classes\Activation; |
| 79 | $activation->create_failed_logins_log_table(); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Code that runs on plugin deactivation |
| 84 | * |
| 85 | * @since 1.0.0 |
| 86 | */ |
| 87 | function asenha_on_deactivation() { |
| 88 | $deactivation = new ASENHA\Classes\Deactivation; |
| 89 | $deactivation->delete_failed_logins_log_table(); |
| 90 | } |
| 91 | |
| 92 | // Register code that runs on plugin activation |
| 93 | register_activation_hook( __FILE__, 'asenha_on_activation'); |
| 94 | |
| 95 | // Register code that runs on plugin deactivation |
| 96 | register_deactivation_hook( __FILE__, 'asenha_on_deactivation' ); |
| 97 | |
| 98 | // Load translations |
| 99 | function asenha_free_load_textdomain() { |
| 100 | load_plugin_textdomain( 'admin-site-enhancements', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); |
| 101 | } |
| 102 | add_action( 'init', 'asenha_free_load_textdomain' ); |
| 103 | |
| 104 | // https://make.wordpress.org/core/2024/10/21/i18n-improvements-6-7/ |
| 105 | // Use when tracing which code is triggering the "_load_textdomain_just_in_time Called Incorrectly" notice |
| 106 | // add_action( |
| 107 | // 'doing_it_wrong_run', |
| 108 | // static function ( $function_name ) { |
| 109 | // if ( '_load_textdomain_just_in_time' === $function_name ) { |
| 110 | // debug_print_backtrace(); |
| 111 | // } |
| 112 | // } |
| 113 | // ); |
| 114 | |
| 115 | // Functions for setting up admin menu, admin page, the settings sections and fields and other fondational stuff |
| 116 | require_once ASENHA_PATH . 'settings.php'; |
| 117 | |
| 118 | // Other required functions |
| 119 | require_once ASENHA_PATH . 'functions.php'; |
| 120 | |
| 121 | // Load vendor libraries |
| 122 | // require_once ASENHA_PATH . 'vendor/autoload.php'; |
| 123 | |
| 124 | // Bootstrap all the functionalities of this plugin |
| 125 | require_once ASENHA_PATH . 'bootstrap.php'; |