initialization(); } /** * Initialize main variables. * * @since 1.0.0 * @access private * * @return void **/ private function initialization() { /** Full path to main plugin file. */ self::$plugin_file = dirname( dirname( dirname( __DIR__ ) ) ) . '/adunlocker.php'; /** Set Plugin version. */ self::$version = self::get_plugin_data( 'Version' ); /** Set Plugin name. */ self::$name = self::get_plugin_data( 'Name' ); /** Plugin slug. */ self::$slug = self::get_plugin_data( 'TextDomain' ); /** Plugin type. */ self::$type = self::extract_plugin_type(); /** Gets the plugin URL (with trailing slash). */ self::$url = plugin_dir_url( self::$plugin_file ); /** Gets the plugin PATH. */ self::$path = plugin_dir_path( self::$plugin_file ); /** Using minified css and js files if SCRIPT_DEBUG is turned off. */ self::$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; /** Set plugin basename. */ self::$basename = plugin_basename( self::$plugin_file ); /** Plugin settings page menu base. There may be several. */ /** For Elementor plugins. */ if ( 'elementor' === self::$type ) { self::$menu_bases[] = 'elementor_page_pp_AdUnlocker_settings'; self::$menu_bases[] = 'settings_page_pp_AdUnlocker_settings'; /** For general WordPress plugins. */ } else { self::$menu_bases[] = 'toplevel_page_pp_AdUnlocker_settings'; self::$menu_bases[] = 'AdUnlocker_page_pp_AdUnlocker_settings'; } /** Fill $tabs field with default settings. */ $this->default_settings(); } /** * Fill $tabs field with default settings. * * @since 1.0.0 * @access private * * @return void **/ private function default_settings() { /** Add General Tab. */ $this->add_general_tab(); /** Add Custom CSS Tab. */ $this->add_custom_css_tab(); /** Add Assignments Tab. */ $this->add_assignments_tab(); /** Add Status Tab. */ $this->add_status_tab(); /** Add Uninstall Tab. */ $this->add_uninstall_tab(); } /** * Add General Tab to settings page. * * @since 1.0.0 * @access private * * @return void **/ private function add_general_tab() { /** Create empty General Tab. */ self::$tabs['general'] = [ 'enabled' => true, 'class' => TabGeneral::class, 'label' => esc_html__( 'General', 'AdUnlocker' ), 'title' => esc_html__( 'General Settings', 'AdUnlocker' ), 'show_title' => true, 'icon' => 'settings', 'fields' => [] ]; /** Special config for Elementor plugins. */ if ( 'elementor' === self::extract_plugin_type() ) { unset( self::$tabs['general'] ); } } /** * Add Custom Css Tab to settings page. * * @since 1.0.0 * @access private * * @return void **/ private function add_custom_css_tab() { self::$tabs['custom_css'] = [ 'enabled' => true, 'class' => TabCustomCSS::class, 'label' => esc_html__( 'Custom CSS', 'AdUnlocker' ), 'title' => esc_html__( 'Custom CSS', 'AdUnlocker' ), 'show_title' => true, 'icon' => 'code', 'fields' => [ 'custom_css' => [ 'type' => 'css_editor', 'description' => esc_html__( 'Add custom CSS here.', 'AdUnlocker' ), 'show_description' => true, 'default' => '', ] ] ]; /** Special config for Elementor plugins. */ if ( 'elementor' === self::extract_plugin_type() ) { unset( self::$tabs['custom_css'] ); } } /** * Add Assignments Tab to settings page. * * @since 1.0.0 * @access private * * @return void **/ private function add_assignments_tab() { self::$tabs['assignments'] = [ 'enabled' => true, 'class' => TabAssignments::class, 'label' => esc_html__( 'Assignments', 'AdUnlocker' ), 'title' => esc_html__( 'Assignments Settings', 'AdUnlocker' ), 'show_title' => true, 'icon' => 'beenhere', 'assignments' => [ 'matching_method' => true, 'wordpress_content' => true, 'home_page' => true, 'menu_items' => true, 'date_time' => true, 'languages' => true, 'user_roles' => true, 'url' => true, 'devices' => true, 'operating_systems' => true, 'browsers' => true, 'ip_addresses' => true, 'custom_php' => true, ], 'fields' => [ 'assignments' => [ 'type' => 'hidden', 'default' => '{|matchingMethod|:1,|WPContent|:0,|WPContentVal|:||,|homePage|:0,|menuItems|:0,|menuItemsVal|:||,|dateTime|:0,|dateTimeStart|:||,|dateTimeEnd|:||,|languages|:0,|languagesVal|:||,|userRoles|:0,|userRolesVal|:||,|URL|:0,|URLVal|:||,|devices|:0,|devicesVal|:||,|os|:0,|osVal|:||,|browsers|:0,|browsersVal|:||,|mobileBrowsersVal|:||,|IPs|:0,|IPsVal|:||,|PHP|:0,|PHPVal|:||}', ] ] ]; /** Special config for Elementor plugins. */ if ( 'elementor' === self::extract_plugin_type() ) { unset( self::$tabs['assignments'] ); } } /** * Add Status Tab to settings page. * * @since 1.0.0 * @access private * * @return void **/ private function add_status_tab() { self::$tabs['status'] = [ 'enabled' => true, 'class' => TabStatus::class, 'label' => esc_html__( 'Status', 'AdUnlocker' ), 'title' => esc_html__( 'System Status', 'AdUnlocker' ), 'show_title' => true, 'icon' => 'info', 'reports' => [ 'server' => [ 'enabled' => true, 'os' => true, 'software' => true, 'mysql_version' => true, 'php_version' => true, 'write_permissions' => true, 'zip_installed' => true, 'elementor_installed' => false, 'allow_url_fopen' => true, 'dom_installed' => true, 'xml_installed' => true, 'bcmath_installed' => true, ], 'wordpress' => [ 'enabled' => true ], 'plugins' => [ 'enabled' => true ], 'theme' => [ 'enabled' => true ], ] ]; /** Special config for Elementor plugins. */ if ( 'elementor' === self::extract_plugin_type() ) { self::$tabs['status']['reports']['server']['elementor_installed'] = true; self::$tabs['status']['reports']['server']['allow_url_fopen'] = false; self::$tabs['status']['reports']['server']['dom_installed'] = false; self::$tabs['status']['reports']['server']['xml_installed'] = false; self::$tabs['status']['reports']['server']['bcmath_installed'] = false; } } /** * Add Uninstall Tab to settings page. * * @since 1.0.0 * @access private * * @return void **/ private function add_uninstall_tab() { self::$tabs['uninstall'] = [ 'enabled' => true, 'class' => TabUninstall::class, 'label' => esc_html__( 'Uninstall', 'AdUnlocker' ), 'title' => esc_html__( 'Uninstall Settings', 'AdUnlocker' ), 'show_title' => true, 'icon' => 'delete', 'fields' => [ 'delete_plugin' => [ 'type' => 'select', 'options' => [ 'plugin' => esc_html__( 'Delete plugin only', 'AdUnlocker' ), 'plugin+settings' => esc_html__( 'Delete plugin and settings', 'AdUnlocker' ), 'plugin+settings+data' => esc_html__( 'Delete plugin, settings and data', 'AdUnlocker' ), ], 'default' => 'plugin', ] ] ]; /** Special config for Elementor plugins. */ if ( 'elementor' === self::extract_plugin_type() ) { unset( self::$tabs['uninstall']['fields']['delete_plugin']['options']['plugin+settings+data'] ); } } /** * Return current plugin metadata. * * @param string $field - Field name from plugin data. * * @since 1.0.0 * @access private * * @return string|array { * Plugin data. Values will be empty if not supplied by the plugin. * * @type string $Name Name of the plugin. Should be unique. * @type string $Title Title of the plugin and link to the plugin's site (if set). * @type string $Description Plugin description. * @type string $Author Author's name. * @type string $AuthorURI Author's website address (if set). * @type string $Version Plugin version. * @type string $TextDomain Plugin textdomain. * @type string $DomainPath Plugins relative directory path to .mo files. * @type bool $Network Whether the plugin can only be activated network-wide. * @type string $RequiresWP Minimum required version of WordPress. * @type string $RequiresPHP Minimum required version of PHP. * } **/ private static function get_plugin_data( $field ) { static $plugin_data; /** We already have $plugin_data. */ if ( $plugin_data !== null ) { return $plugin_data[$field]; } /** This is first time call of method, so prepare $plugin_data. */ if ( ! function_exists('get_plugin_data') ) { require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); } $plugin_data = get_plugin_data( self::get_plugin_file() ); return $plugin_data[$field]; } /** * Get Plugin version. * * @since 1.0.0 * @access public * * @return string **/ public static function get_version() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } return self::$version; } /** * Get Plugin Name. * * @since 1.0.0 * @access public * * @return string **/ public static function get_name() { return self::get_plugin_data( 'Name' ); } /** * Get .min suffix. * * @since 1.0.0 * @access public * * @return string **/ public static function get_suffix() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } return self::$suffix; } /** * Get URL to plugin folder with trailing slash. * * @since 1.0.0 * @access public * * @return string **/ public static function get_url() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } return self::$url; } /** * Get full Path to plugin folder with trailing slash. * * @since 1.0.0 * @access public * * @return string **/ public static function get_path() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } return self::$path; } /** * Get Plugin Basename. * * @since 1.0.0 * @access public * * @return string **/ public static function get_basename() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } return self::$basename; } /** * Get plugin menu bases. * * @since 1.0.0 * @access public * * @return array **/ public static function get_menu_bases() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } return self::$menu_bases; } /** * Get path to plugin file. * * @since 1.0.0 * @access public * * @return string **/ public static function get_plugin_file() { return dirname( dirname( dirname( __DIR__ ) ) ) . '/adunlocker.php'; } /** * Get Plugin slug. * * @since 1.0.0 * @access public * * @return string **/ public static function get_slug() { return self::get_plugin_data( 'TextDomain' ); } /** * Get Plugin type. * * @since 1.0.0 * @access public * * @return string **/ public static function get_type() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } return self::$type; } /** * Set Plugin type. * * @param string $type - Allow change plugin type. * * @since 1.0.0 * @access public * * @return void **/ public static function set_type( $type ) { if ( empty( $type ) ) { return; } self::$type = $type; } /** * Extract plugin type from slug. * * @since 1.0.0 * @access public * * @return string **/ private static function extract_plugin_type() { $slug = self::get_plugin_data( 'TextDomain' ); $type = 'wordpress'; if ( strpos( $slug, 'elementor' ) !== false ) { $type = 'elementor'; } if ( strpos( $slug, 'wpbakery' ) !== false ) { $type = 'wpbakery'; } return $type; } /** * Get Plugin tabs. * * @since 1.0.0 * @access public * * @return array **/ public static function get_tabs() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } return self::$tabs; } /** * Set Plugin tabs. * * @param array $tabs - Tabs and fields with settings. * * @since 1.0.0 * @access public * * @return void **/ public static function set_tabs( $tabs ) { self::$tabs = $tabs; } /** * Get instance of Plugin. * * Insures that only one instance of Plugin exists in memory at any one time. * * @static * @since 1.0.0 * * @return Plugin **/ public static function get_instance() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::$instance = new self; } return self::$instance; } }