173 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			173 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace PluginNamespace;
 | |
| 
 | |
| use eftec\bladeone\BladeOne;
 | |
| use Exception;
 | |
| 
 | |
| if ( ! defined( 'ABSPATH' ) ) {
 | |
| 	exit;
 | |
| }
 | |
| 
 | |
| class App {
 | |
| 
 | |
| 	/** @var \PluginNamespace\App */
 | |
| 	public static $instance;
 | |
| 
 | |
| 	/** @var \eftec\bladeone\BladeOne */
 | |
| 	public $blade;
 | |
| 
 | |
| 	/**
 | |
| 	 * Any logic that needs executed when the plugin is activated.
 | |
| 	 *
 | |
| 	 * @package PluginNamespace\App
 | |
| 	 * @since 1.0.0
 | |
| 	 *
 | |
| 	 * @return void
 | |
| 	 */
 | |
| 	public static function plugin_activation(): void {
 | |
| 		self::ensure_template_cache_dir_exists();
 | |
| 
 | |
| 		$plugin_metadata = array(
 | |
| 			'plugin_version' => PLUGIN_NAME_VERSION,
 | |
| 			'db_version'     => PLUGIN_NAME_DB_VERSION,
 | |
| 		);
 | |
| 		add_option( 'nmsp_plugin_metadata', $plugin_metadata );
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Any logic that needs executed when the plugin is deactivated.
 | |
| 	 *
 | |
| 	 * @package PluginNamespace\App
 | |
| 	 * @since 1.0.0
 | |
| 	 *
 | |
| 	 * @return void
 | |
| 	 */
 | |
| 	public static function plugin_deactivation(): void {
 | |
| 		// phpcs:disable
 | |
| 		// phpcs:enable
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Check that the cache directory for Blade exists and
 | |
| 	 * if not then attempt to create it.
 | |
| 	 *
 | |
| 	 * @package PluginNamespace\App
 | |
| 	 * @since 1.0.0
 | |
| 	 *
 | |
| 	 * @throws \Exception
 | |
| 	 *
 | |
| 	 * @return void
 | |
| 	 */
 | |
| 	public static function ensure_template_cache_dir_exists(): void {
 | |
| 		if ( ! file_exists( NMSP_PLUGIN_BASE_DIR . '/cache/blade/.gitignore' ) ) {
 | |
| 			try {
 | |
| 				mkdir( NMSP_PLUGIN_BASE_DIR . '/cache/blade', 0755, true );
 | |
| 			} catch ( Exception $exp ) {
 | |
| 				$error_payload = array(
 | |
| 					'level'   => 'critical',
 | |
| 					'message' => $exp->getMessage(),
 | |
| 					'context' => array(
 | |
| 						'file' => $exp->getFile(),
 | |
| 						'line' => $exp->getLine(),
 | |
| 					),
 | |
| 				);
 | |
| 				error_log( json_encode( $error_payload, JSON_PRETTY_PRINT ) );
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Return an instance of this plugin class. If it has
 | |
| 	 * not been initialized, do so then return it.
 | |
| 	 *
 | |
| 	 * @package PluginNamespace\App
 | |
| 	 * @since 1.0.0
 | |
| 	 *
 | |
| 	 * @return \PluginNamespace\App
 | |
| 	 */
 | |
| 	public static function get_instance(): App {
 | |
| 		if ( ! ( self::$instance instanceof App ) ) {
 | |
| 			self::$instance = new App();
 | |
| 
 | |
| 			self::$instance->load_plugin_textdomain();
 | |
| 			self::$instance->scaffold_plugin();
 | |
| 			self::$instance->includes();
 | |
| 		}
 | |
| 
 | |
| 		return self::$instance;
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Load your translation files for this plugin.
 | |
| 	 *
 | |
| 	 * @package PluginNamespace\App
 | |
| 	 * @since 1.0.0
 | |
| 	 *
 | |
| 	 * @return void
 | |
| 	 */
 | |
| 	public function load_plugin_textdomain(): void {
 | |
| 		load_plugin_textdomain( 'nmsp-plugin-name-text-domain', false, 'languages' );
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Steps to take when initializing this plugin??
 | |
| 	 *
 | |
| 	 * @package PluginNamespace\App
 | |
| 	 * @since 1.0.0
 | |
| 	 *
 | |
| 	 * @return void
 | |
| 	 */
 | |
| 	public function scaffold_plugin(): void {
 | |
| 		// phpcs:disable
 | |
| 		if ( is_admin() ) {
 | |
| 			// admin only logic here, remove phpcs calls around this
 | |
| 		}
 | |
| 		// phpcs:enable
 | |
| 
 | |
| 		// other logic here
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Other files to include so that this plugin will
 | |
| 	 * have a single entrypoint but be able to break
 | |
| 	 * up code in a logical manor.
 | |
| 	 *
 | |
| 	 * @codeCoverageIgnore
 | |
| 	 *
 | |
| 	 * @package PluginNamespace\App
 | |
| 	 * @since 1.0.0
 | |
| 	 *
 | |
| 	 * @return void
 | |
| 	 */
 | |
| 	public function includes(): void {
 | |
| 		// Files to include on the admin.
 | |
| 		if ( is_admin() ) {
 | |
| 			require_once NMSP_PLUGIN_BASE_DIR . '/admin/nmsp-admin-functions.php';
 | |
| 			require_once NMSP_PLUGIN_BASE_DIR . '/admin/nmsp-update-functions.php';
 | |
| 			require_once NMSP_PLUGIN_BASE_DIR . '/admin/class-adminsettings.php';
 | |
| 		}
 | |
| 
 | |
| 		// Files to include on every request.
 | |
| 		//
 | |
| 
 | |
| 		// Files to include that may be sub-namespaced.
 | |
| 		require_once __DIR__ . '/front/class-custompage.php';
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Load BladeOne as the templating engine for the plugin.
 | |
| 	 *
 | |
| 	 * @package PluginNamespace\App
 | |
| 	 * @since 1.0.0
 | |
| 	 *
 | |
| 	 * @param \eftec\bladeone\BladeOne $blade
 | |
| 	 *
 | |
| 	 * @return void
 | |
| 	 */
 | |
| 	public function load_blade( BladeOne $blade ): void {
 | |
| 		$this->blade = $blade;
 | |
| 	}
 | |
| 
 | |
| }
 |