'5.3', 'WordPress' => '4.2.0', ]; /** * status of checking environment * * @var null|string * * @since 1.0.0 * */ protected static $environment_status = null; private function __construct() { self::handler_loading_base_part(); $locale = AS_CM_Services_Locale::_instance(); add_action( 'init', [ $locale, 'load_textdomain' ], 30 ); add_action( 'plugins_loaded', [ __CLASS__, 'load_plugin_parts' ], 60 ); } /** * load plugin parts * * @since 1.0.0 * */ public static function load_plugin_parts() { /* INIT CONTROLLERS */ AS_CM_Helpers_General::load_controller( 'options', 'AS_CM_Controllers_Options' ); AS_CM_Helpers_General::load_controller( 'popup', 'AS_CM_Controllers_Popup' ); AS_CM_Helpers_General::load_controller( 'after_activate', 'AS_CM_Controllers_After_Activate' ); AS_CM_Helpers_General::load_controller( 'design', 'AS_CM_Controllers_Design' ); AS_CM_Helpers_General::load_controller( 'shortcodes', 'AS_CM_Controllers_Shortcodes' ); AS_CM_Helpers_General::load_controller( 'extensions/rocket', 'AS_CM_Controllers_Extensions_Rocket' ); AS_CM_Helpers_General::load_controller( 'extensions/consent_api', 'AS_CM_Controllers_Extensions_Consent_API' ); AS_CM_Helpers_General::load_controller( 'scan', 'AS_CM_Controllers_Scan' ); /* END INIT CONTROLLERS */ // Filters are not persistent, so the WP Consent API registration // must run on every request - not only during activation. self::register_wp_consent_api(); /* INIT SERVICES */ AS_CM_Helpers_General::load_controller( '../services/notice', 'AS_CM_Services_Notice', [ 'function' => 'hooks' ] ); AS_CM_Helpers_General::load_controller( '../services/cache/manager', 'AS_CM_Services_Cache_Manager', [ 'function' => 'hooks' ] ); // Inline detector is a static utility class - just load it without init action AS_CM_Helpers_General::load( self::$path . 'includes/services/scan/inline-detector', [ 'class' => 'AS_CM_Services_Inline_Detector', 'full_path' => true ] ); AS_CM_Helpers_General::load_controller( '../services/scan/storage', 'AS_CM_Services_Scan_Storage', [ 'function' => 'hooks' ] ); /* END INIT SERVICES */ } /** * load base logic of plugin * * @since 1.0.0 * */ protected static function load_base_logic() { /* LOAD HELPERS */ require_once( self::$path . 'includes/helpers/general.php' ); AS_CM_Helpers_General::load( 'helpers/transfer' ); AS_CM_Helpers_General::load( 'helpers/view' ); AS_CM_Helpers_General::load( 'helpers/file' ); /* END LOAD HELPERS */ /* LOAD CLASSES */ AS_CM_Helpers_General::load( 'classes/collection' ); AS_CM_Helpers_General::load( 'classes/controller' ); AS_CM_Helpers_General::load( 'classes/item' ); /* END LOAD CLASSES */ /* LOAD MODELS */ /* END LOAD MODELS */ /* LOAD SERVICES */ AS_CM_Helpers_General::load( 'services/locale' ); AS_CM_Helpers_General::load( 'services/rest' ); AS_CM_Helpers_General::load( 'services/notice' ); AS_CM_Helpers_General::load( 'services/cache/loader' ); AS_CM_Helpers_General::load( 'services/cache/manager' ); AS_CM_Helpers_General::load( 'services/scan/storage' ); AS_CM_Helpers_General::load( 'services/scan/inline-detector' ); /* END LOAD SERVICES */ /* LOAD CONTROLLERS */ AS_CM_Helpers_General::load( 'controllers/options' ); AS_CM_Helpers_General::load( 'controllers/popup' ); AS_CM_Helpers_General::load( 'controllers/after_activate' ); AS_CM_Helpers_General::load( 'controllers/design' ); AS_CM_Helpers_General::load( 'controllers/scan' ); /* END LOAD CONTROLLERS */ } /** * set general data * * @since 1.0.0 * */ private static function set_general_data() { self::$path = dirname( __FILE__ ) . '/'; self::$url = plugins_url( '', __FILE__ ); self::$version = self::get_plugin_info( 'Version', __FILE__ ); self::$action = self::get_plugin_info( 'TextDomain', __FILE__ ); } /** * get information about plugin by type * * @param string $name Type of data field. * Types https://codex.wordpress.org/File_Header * @param string|null $path * * @return string * * @since 1.0.0 * */ public static function get_plugin_info( $name, $path = null ) { /** WordPress Plugin Administration API */ require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); $data = get_plugin_data( is_null( $path ) ? __FILE__ : $path ); if ( $name == 'Release' ) { $d = explode( '.', $data['Version'] ); return $d[ sizeof( $d ) - 1 ]; } return $data[ $name ]; } /** * deactivate plugin * * @since 1.0.0 * */ public static function deactivate_plugin() { self::handler_loading_base_part(); self::deactivate(); } /** * handler loading base part of plugin * * @since 1.0.0 * */ public static function handler_loading_base_part() { self::set_general_data(); self::check_environment(); if ( self::get_environment_status() !== null ) { self::init_environment_error(); } self::load_base_logic(); } /** * deactivate plugin logic * * @since 1.0.0 * */ public static function deactivate() { AS_CM_Controllers_Options::deactivate(); AS_CM_Controllers_After_Activate::deactivate(); } /** * activate plugin * * @since 1.0.0 * */ public static function activate_plugin() { self::handler_loading_base_part(); self::activate(); } /** * activate plugin on site * * @since 1.0.0 * */ public static function activate() { AS_CM_Controllers_After_Activate::set_activation_key(); if ( class_exists( 'AS_CM_Services_Scan_Storage' ) ) { AS_CM_Services_Scan_Storage::maybe_upgrade(); } } /** * get info about environment * * @since 1.0.0 * */ public static function check_environment() { global $wp_version; $flag = null; foreach ( [ 'PHP' => [ 'version' => PHP_VERSION ], 'WordPress' => [ 'version' => $wp_version ], ] as $key => $data ) { $environment = self::get_environment( $key ); if ( ! is_null( $environment ) ) { if ( isset( $data['class'] ) && ! class_exists( $data['class'] ) ) { self::$environment_status = $key; return; } if ( version_compare( $data['version'], $environment, '<' ) ) { self::$environment_status = $key; return; } } } } /** * get environment status * * @return null|string * * @since 1.0.0 * */ public static function get_environment_status() { return self::$environment_status; } /** * return environment by key * * @param string $key * * @return string|null * * @since 1.0.0 * */ public static function get_environment( $key ) { return isset( self::$environment[ $key ] ) ? self::$environment[ $key ] : null; } /** * Tell the consent API we're following the api. */ protected static function register_wp_consent_api() { $plugin = plugin_basename(__FILE__); add_filter("wp_consent_api_registered_$plugin", function(){ return true; }); } /** * init environment error * * @since 1.0.0 * */ protected static function init_environment_error() { $as_cm_plugin_name = '
' . esc_html( self::get_plugin_info( 'Name' ) ) . ' '; /* translators: 1: environment name (PHP or WordPress), 2: required version number */ $message = $as_cm_plugin_name . sprintf( esc_html__( 'plugin requires %1$s version %2$s or greater.', 'adsimple-cookie-manager-for-wp' ), esc_html( self::get_environment_status() ), esc_html( self::get_environment( self::get_environment_status() ) ) ) . '
'; deactivate_plugins( plugin_basename( __FILE__ ) ); wp_die( wp_kses_post( $message ), esc_html__( 'Plugin Activation Error', 'adsimple-cookie-manager-for-wp' ), [ 'back_link' => true ] ); } private function __clone() {} /** * Force anonymous mode for scan requests. * * This runs very early (muplugins_loaded) to prevent WordPress from * authenticating the user, so the scan sees the page as a visitor would. * * @since 2.2.1 */ public static function maybe_force_anonymous_scan() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( empty( $_GET['as_cm_scan_job'] ) ) { return; } // Verify this is a legitimate scan request (referer from admin) $http_referer = isset( $_SERVER['HTTP_REFERER'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : ''; if ( empty( $http_referer ) ) { return; } // Check if referer contains wp-admin $admin_path = wp_parse_url( admin_url(), PHP_URL_PATH ); $referer_path = wp_parse_url( $http_referer, PHP_URL_PATH ); if ( $admin_path && $referer_path && strpos( $referer_path, $admin_path ) === false ) { return; } // Clear authentication cookies from the request to force anonymous mode // This prevents WordPress from authenticating the user $auth_cookie_names = [ 'wordpress_logged_in_', 'wordpress_sec_', 'wordpress_', 'wp-settings-', 'wp-settings-time-', ]; foreach ( array_keys( $_COOKIE ) as $cookie_name ) { foreach ( $auth_cookie_names as $prefix ) { if ( strpos( $cookie_name, $prefix ) === 0 ) { unset( $_COOKIE[ $cookie_name ] ); } } } // Also prevent admin bar from showing add_filter( 'show_admin_bar', '__return_false', 9999 ); // Disable any caching for scan requests. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- WordPress standard constant if ( ! defined( 'DONOTCACHEPAGE' ) ) { define( 'DONOTCACHEPAGE', true ); } } public static function _instance() { if ( null === self::$_instance ) { self::$_instance = new self(); } return self::$_instance; } }