%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /dom405686/wp-content/plugins/pws-core/includes/
Upload File :
Create Path :
Current File : /dom405686/wp-content/plugins/pws-core/includes/class-GD-cORe.php

<?php
if ( ! defined( 'ABSPATH' ) ) {

	exit;

}
/**
 * The core plugin class.
 *
 * This is used to define internationalization, admin-specific hooks, and
 * public-facing site hooks.
 *
 * Also maintains the unique identifier of this plugin as well as the current
 * version of the plugin.
 *
 * @since      3.0.0
 * @package    GD_cORe
 * @subpackage GD_cORe/includes
 */
class GD_cORe {

	/**
	 * The loader that's responsible for maintaining and registering all hooks that power
	 * the plugin.
	 *
	 * @since    3.0.0
	 * @access   protected
	 * @var      GD_cORe_Loader    $loader    Maintains and registers all hooks for the plugin.
	 */
	protected $loader;

	/**
	 * The unique identifier of this plugin.
	 *
	 * @since    3.0.0
	 * @access   protected
	 * @var      string    $plugin_name    The string used to uniquely identify this plugin.
	 */
	protected $plugin_name;

	/**
	 * The current version of the plugin.
	 *
	 * @since    3.0.0
	 * @access   protected
	 * @var      string    $version    The current version of the plugin.
	 */
	protected $version;

	/**
	 * 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    3.0.0
	 */
	public function __construct() {
		if ( defined( 'GD_cORe_VERSION' ) ) {
			$this->version = GD_cORe_VERSION;
		} else {
			$this->version = '4.1.16';
		}
		$this->plugin_name = 'gd-core';

		$this->load_dependencies();
		$this->set_locale();
		$this->define_admin_hooks();
		$this->define_public_hooks();
		$this->run_version_migrations();
	}

	/**
	 * Load the required dependencies for this plugins public functions.
	 *
	 * Include the following files that make up the plugin:
	 *
	 * - GD_cORe_Loader. Orchestrates the hooks of the plugin.
	 * - GD_cORe_i18n. Defines internationalization functionality.
	 * - GD_cORe_Public. Defines all hooks for the public side of the site.
	 *
	 * Create an instance of the loader which will be used to register the hooks
	 * with WordPress.
	 *
	 * @since    3.0.0
	 * @access   private
	 */
	private function load_dependencies() {

		/**
		 * The class responsible for defining all classes responsible for api and plugin functionality
		 */
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/handlers/register.php';

		/**
		 * The class responsible for orchestrating the actions and filters of the
		 * core plugin.
		 */
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-GD-cORe-loader.php';

		/**
		 * The class responsible for coordinating updates with Github and make sure the plugin is always updated.
		 */
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-GD-cORe-updater.php';
		new GD_cORe_Updater( GD_cORe_ROOT_PATH_FILE);

		/**
		 * The class responsible for defining internationalization functionality
		 * of the plugin.
		 */
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-GD-cORe-i18n.php';

		/**
		 * The class responsible for defining all actions that occur in the public-facing
		 * side of the site.
		 */
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-GD-cORe-public.php';


		/**
		 *
		 * Loads all functions/files related to admin funcitionality.
		 */

		if(is_admin() && is_user_logged_in() && current_user_can('manage_options')){
			/* *
			* The class responsible for defining all actions that occur in the admin area.
			*/
			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-GD-cORe-admin.php';

			/**
			* The class responsible for defining all plugin configurations
			*/
			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/handlers/plugin_configs/register.php';

			/**
			* The class responsible for defining all defualt theme configurations
			*/
			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/handlers/default_configs/register.php';
		}

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

	/**
	 * Define the locale for this plugin for internationalization.
	 *
	 * Uses the GD_cORe_i18n class in order to set the domain and to register the hook
	 * with WordPress.
	 *
	 * @since    3.0.0
	 * @access   private
	 */
	private function set_locale() {

		$plugin_i18n = new GD_cORe_i18n();

		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );

	}

	/**
	 * Register all of the hooks related to the admin area functionality
	 * of the plugin.
	 *
	 * @since    3.0.0
	 * @access   private
	 */
	private function define_admin_hooks() {
		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can('manage_options') ) {
			return;
		}

		$plugin_admin = new GD_cORe_Admin( $this->get_plugin_name(), $this->get_version() );
		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
		$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_admin_page' );

		$this->loader->add_action('admin_footer', $plugin_admin, 'core_cache_scripts');
		$this->loader->add_action( 'wp_ajax_core_flush_cache', $plugin_admin, 'core_flush');
	}

	/**
	 * Register all of the hooks related to the public-facing functionality
	 * of the plugin.
	 *
	 * @since    3.0.0
	 * @access   private
	 */
	private function define_public_hooks() {
		$plugin_public = new GD_cORe_Public( $this->get_plugin_name(), $this->get_version() );

		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
		$this->loader->add_action( 'admin_bar_menu', $plugin_public, 'gd_core_Dropdown' , 100);
		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'core_cache_scripts');
	}

	/**
	 * Run the loader to execute all of the hooks with WordPress.
	 *
	 * @since    3.0.0
	 */
	public function run() {
		$this->loader->run();
	}

	/**
	 * The name of the plugin used to uniquely identify it within the context of
	 * WordPress and to define internationalization functionality.
	 *
	 * @since     3.0.0
	 * @return    string    The name of the plugin.
	 */
	public function get_plugin_name() {
		return $this->plugin_name;
	}

	/**
	 * The reference to the class that orchestrates the hooks with the plugin.
	 *
	 * @since     3.0.0
	 * @return    GD_cORe_Loader    Orchestrates the hooks of the plugin.
	 */
	public function get_loader() {
		return $this->loader;
	}

	/**
	 * Retrieve the version number of the plugin.
	 *
	 * @since     3.0.0
	 * @return    string    The version number of the plugin.
	 */
	public function get_version() {
		return $this->version;
	}

	/**
	 * Run version-based migrations
	 *
	 * @since     3.20.0
	 * @access    private
	 */
	private function run_version_migrations() {
		// Get stored version and current version
		$stored_version = get_option('gd_core_version', '0.0.0');
		$current_version = $this->version;

		// Only run migrations if version has changed
		if (version_compare($stored_version, $current_version, '<')) {
			$this->execute_migrations($stored_version, $current_version);

			// Update stored version
			update_option('gd_core_version', $current_version);

			// Log migration execution
			if (defined('WP_DEBUG') && WP_DEBUG) {
				error_log("GD cORe: Version migration from $stored_version to $current_version completed");
			}
		}
	}

	/**
	 * Execute specific migrations based on version changes
	 *
	 * @since     3.20.0
	 * @access    private
	 * @param     string    $old_version    The previous version
	 * @param     string    $new_version    The current version
	 */
	private function execute_migrations($old_version, $new_version) {
		// Migration for WP Rocket consumer email update (version 3.20.0+)
		if (version_compare($old_version, '3.20.0', '<') && version_compare($new_version, '3.20.0', '>=')) {
			$this->migrate_wp_rocket_consumer_email();
		}

		if (version_compare($old_version, '4.0.0', '<') && version_compare($new_version, '4.0.0', '>=')) {
		    $this->ensure_database_tables_exist();
		}
	}

	/**
	 * Migrate WP Rocket consumer email to correct value
	 *
	 * @since     3.20.0
	 * @access    private
	 */
	private function migrate_wp_rocket_consumer_email() {
		// Check if WP Rocket is installed and active
		if (!function_exists('is_plugin_active') || !is_plugin_active('wp-rocket/wp-rocket.php')) {
			if (defined('WP_DEBUG') && WP_DEBUG) {
				error_log('GD cORe: WP Rocket migration skipped - plugin not active');
			}
			return;
		}

		// Get current WP Rocket settings
		$current_settings = get_option('wp_rocket_settings', array());

		// Check if consumer_email exists and needs updating
		if (isset($current_settings['consumer_email'])) {
			$current_email = $current_settings['consumer_email'];
			$correct_email = 'pwstech@godaddy.com';

			// Only update if the email is different from the correct one
			if ($current_email !== $correct_email) {
				// Update to correct email
				$current_settings['consumer_email'] = $correct_email;

				// Update the settings
				update_option('wp_rocket_settings', $current_settings, false);

				// Log the migration
				if (defined('WP_DEBUG') && WP_DEBUG) {
					error_log("GD cORe: Migrated WP Rocket consumer_email from '$current_email' to '$correct_email'");
				}
			} else {
				if (defined('WP_DEBUG') && WP_DEBUG) {
					error_log('GD cORe: WP Rocket consumer_email already correct, no migration needed');
				}
			}
		} else {
			if (defined('WP_DEBUG') && WP_DEBUG) {
				error_log('GD cORe: WP Rocket settings not found, cannot migrate consumer_email');
			}
		}
	}

	/**
	 * Ensure database tables exist (for plugin updates/replacements)
	 * This method checks if required tables exist and creates them if they don't
	 *
	 * @since    4.0.0
	 * @access   private
	 */
	private function ensure_database_tables_exist() {
		global $wpdb;

		// Check if the lighthouse reports table exists
		$table_name = $wpdb->prefix . 'gdcore_lighthouse_reports';
		$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name;

		// Load the activator class to use its table creation method
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-GD-cORe-activator.php';
		$result = GD_cORe_Activator::create_database_tables();

		// Log the table creation attempt
		if (defined('WP_DEBUG') && WP_DEBUG) {
			error_log('GD cORe: Database tables checked/created. Table exists: ' . ($table_exists ? 'yes' : 'no') . ', Version: ' . $current_version);
		}
	}
}

Zerion Mini Shell 1.0