class-wp-otp.php 3.4 KB
Newer Older
noplanman's avatar
noplanman committed
1 2 3 4 5
<?php
/**
 * The core functionality of the plugin
 *
 * @package Wp_Otp
noplanman's avatar
noplanman committed
6
 * @since   0.1.0
noplanman's avatar
noplanman committed
7 8 9 10 11 12 13
 */

namespace Wp_Otp;

/**
 * The core plugin class.
 *
14
 * @since 0.1.0
noplanman's avatar
noplanman committed
15 16 17 18 19 20 21 22 23
 */
class Wp_Otp {
	/**
	 * The loader that's responsible for maintaining and registering all hooks that power the plugin.
	 *
	 * @since  0.1.0
	 * @access private
	 * @var    Wp_Otp_Loader $loader
	 */
noplanman's avatar
noplanman committed
24
	private Wp_Otp_Loader $loader;
noplanman's avatar
noplanman committed
25 26 27 28 29 30 31 32 33 34 35 36

	/**
	 * Define the core functionality of the plugin.
	 *
	 * Set the plugin name and the plugin version that can be used throughout the plugin.
	 * Load the dependencies, define the locale, and set the hooks for the admin area and
	 * the public-facing side of the site.
	 *
	 * @since 0.1.0
	 */
	public function __construct() {
		$this->load_dependencies();
noplanman's avatar
noplanman committed
37
		$this->define_constants();
noplanman's avatar
noplanman committed
38 39 40 41 42 43 44 45 46 47
		$this->define_admin_hooks();
		$this->define_public_hooks();
	}

	/**
	 * Load the required dependencies for this plugin.
	 *
	 * @since  0.1.0
	 * @access private
	 */
48
	private function load_dependencies(): void {
noplanman's avatar
noplanman committed
49
		/**
50
		 * The class responsible for activation, deactivation and deletion of the plugin.
noplanman's avatar
noplanman committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
		 */
		require_once __DIR__ . '/class-wp-otp-setup.php';

		/**
		 * The class responsible for orchestrating the actions and filters of the core plugin.
		 */
		require_once __DIR__ . '/class-wp-otp-loader.php';

		/**
		 * The class responsible for managing all user meta data.
		 */
		require_once __DIR__ . '/class-wp-otp-user-meta.php';

		/**
		 * The class responsible for defining all actions that occur in the admin area.
		 */
		require_once dirname( __DIR__ ) . '/admin/class-wp-otp-admin.php';

		/**
		 * The class responsible for defining all actions that occur in the public-facing side of the site.
		 */
		require_once dirname( __DIR__ ) . '/public/class-wp-otp-public.php';

		$this->loader = new Wp_Otp_Loader();
	}

noplanman's avatar
noplanman committed
77 78 79
	/**
	 * Define the required constants for this plugin.
	 *
noplanman's avatar
noplanman committed
80
	 * @since  0.3.0
noplanman's avatar
noplanman committed
81 82
	 * @access private
	 */
83
	private function define_constants(): void {
noplanman's avatar
noplanman committed
84 85 86
		defined( 'WP_OTP_STEALTH' ) || define( 'WP_OTP_STEALTH', false );
	}

noplanman's avatar
noplanman committed
87 88 89 90 91 92
	/**
	 * Register all of the hooks related to the admin area functionality of the plugin.
	 *
	 * @since  0.1.0
	 * @access private
	 */
93
	private function define_admin_hooks(): void {
noplanman's avatar
noplanman committed
94 95
		$plugin_admin = new Wp_Otp_Admin();

96 97 98
		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );

noplanman's avatar
noplanman committed
99 100 101 102 103 104 105 106 107 108 109 110 111
		$this->loader->add_action( 'admin_init', $plugin_admin );
		$this->loader->add_action( 'admin_notices', $plugin_admin );

		$this->loader->add_action( 'profile_personal_options', $plugin_admin, 'user_profile_render' );
		$this->loader->add_action( 'personal_options_update', $plugin_admin, 'user_profile_updated' );
	}

	/**
	 * Register all of the hooks related to the public-facing functionality of the plugin.
	 *
	 * @since  0.1.0
	 * @access private
	 */
112
	private function define_public_hooks(): void {
noplanman's avatar
noplanman committed
113 114
		$plugin_public = new Wp_Otp_Public();

noplanman's avatar
noplanman committed
115 116 117 118 119
		if ( WP_OTP_STEALTH ) {
			$this->loader->add_action( 'wp_authenticate', $plugin_public, 'login_form_stealth_validate', 33, 2 );
			return;
		}

noplanman's avatar
noplanman committed
120 121 122 123 124 125 126 127 128
		$this->loader->add_action( 'login_form', $plugin_public, 'login_form_render' );
		$this->loader->add_action( 'authenticate', $plugin_public, 'login_form_validate', 33 );
	}

	/**
	 * Run the loader to execute all of the hooks with WordPress.
	 *
	 * @since 0.1.0
	 */
129
	public function run(): void {
noplanman's avatar
noplanman committed
130 131 132
		$this->loader->run();
	}
}