Files
roi-theme/wp-content/plugins/wp-database-tools/includes/class-wp-database-tools.php
root a22573bf0b Commit inicial - WordPress Análisis de Precios Unitarios
- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 21:04:30 -06:00

512 lines
14 KiB
PHP
Executable File

<?php
/**
* The file that defines the core plugin class
*
* A class definition that includes attributes and functions used across both the
* public-facing side of the site and the admin area.
*
* @link https://raiolanetworks.es
* @since 1.0.0
*
* @package Wp_Database_Tools
* @subpackage Wp_Database_Tools/includes
*/
/**
* 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 1.0.0
* @package Wp_Database_Tools
* @subpackage Wp_Database_Tools/includes
* @author Raiola Networks <info@raiolanetworks.es>
*/
class Wp_Database_Tools {
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @since 1.0.0
* @access protected
* @var Wp_Database_Tools_Loader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* The class responsible for logic database manage.
*
* @since 1.0.0
* @access protected
* @var Wp_Database_Tools_Database $loader Maintains and registers all hooks for the plugin.
*/
protected $database;
/**
* The class responsible for logic of manage license.
*
* @since 1.0.0
* @access protected
* @var Wp_Database_Tools_License $license Manage the license functionalities.
*/
protected $license;
/**
* The class responsible for logic of manage license.
*
* @since 1.0.0
* @access protected
* @var Wp_Database_Tools_Cronjobs $cronjobs Manage the license functionalities.
*/
protected $cronjobs;
/**
* The class responsible for logic of manage license.
*
* @since 1.0.0
* @access protected
* @var Wp_Database_Tools_Scanner $license Manage the license functionalities.
*/
protected $scanner;
/**
* The class responsible for logic of manage license.
*
* @since 1.0.0
* @access protected
* @var Wp_Database_Tools_Updater $updater Manage the license functionalities.
*/
protected $updater;
/**
* The class responsible for logic of manage user feedback.
*
* @since 1.0.0
* @access protected
* @var Wp_Database_Tools_Feedback $feedback Manage the license functionalities.
*/
protected $feedback;
/**
* The unique identifier of this plugin.
*
* @since 1.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 1.0.0
* @access protected
* @var string $version The current version of the plugin.
*/
protected $version;
/**
* The current version of the plugin.
*
* @since 1.0.0
* @access protected
* @var string $version The current version of the plugin.
*/
protected $plugins;
/**
* The current version of the plugin.
*
* @since 1.0.0
* @access protected
* @var string $version The current version of the plugin.
*/
protected $themes;
/**
* The current version of the plugin.
*
* @since 1.0.0
* @access protected
* @var string $version The current version of the plugin.
*/
protected $matching;
/**
* 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 1.0.0
*/
public function __construct() {
if ( defined( 'WPDBT_VERSION' ) ) {
$this->version = WPDBT_VERSION;
} else {
$this->version = '1.0.0';
}
$this->plugin_name = 'wp-database-tools';
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
}
/**
* Load the required dependencies for this plugin.
*
* Include the following files that make up the plugin:
*
* - Wp_Database_Tools_Loader. Orchestrates the hooks of the plugin.
* - Wp_Database_Tools_i18n. Defines internationalization functionality.
* - Wp_Database_Tools_Admin. Defines all hooks for the admin area.
*
* Create an instance of the loader which will be used to register the hooks
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function load_dependencies() {
/**
* The class responsible for orchestrating the actions and filters of the
* core plugin.
*/
include_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-database-tools-loader.php';
/**
* The class responsible for logic of database functions
*/
include_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-database-tools-database.php';
/**
* The class responsible for features of current license
*/
include_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-database-tools-license.php';
/**
* The class responsible for features of scanner database
*/
include_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-database-tools-scanner.php';
/**
* The class responsible for defining internationalization functionality
* of the plugin.
*/
include_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-database-tools-i18n.php';
/**
* The class responsible for updated
*/
include_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-database-tools-updater.php';
/**
* The class responsible for defining all actions that occur in the admin area.
*/
include_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wp-database-tools-admin.php';
/**
* The class responsible for plugins
*/
include_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-database-tools-plugins.php';
/**
* The class responsible for themes
*/
include_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-database-tools-themes.php';
/**
* The class responsible for themes
*/
include_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-database-tools-matching.php';
/**
* The class responsible for themes
*/
include_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-database-tools-feedback.php';
$this->loader = new Wp_Database_Tools_Loader();
$this->plugins = new Wp_Database_Tools_Plugins();
$this->themes = new Wp_Database_Tools_Themes();
$this->matching = new Wp_Database_Tools_Matching( $this->plugins, $this->themes );
$this->license = new Wp_Database_Tools_License( $this->plugin_name );
$this->database = new Wp_Database_Tools_Database( $this->plugins, $this->themes, $this->matching, $this->license->get_is_active() );
$this->scanner = new Wp_Database_Tools_Scanner( $this->license, $this->plugins, $this->themes );
$this->feedback = new Wp_Database_Tools_Feedback();
if ( $this->license->get_is_active() ) {
$this->updater = new Wp_Database_Tools_Updater(
WPDBT_EDD_STORE_URL,
'wp-database-tools/wp-database-tools.php',
array(
'version' => $this->version,
'license' => $this->license->get_license_key(),
'item_id' => WPDBT_EDD_ITEM_ID,
'author' => 'Raiola Networks',
'beta' => false,
)
);
}
}
/**
* Define the locale for this plugin for internationalization.
*
* Uses the Wp_Database_Tools_i18n class in order to set the domain and to register the hook
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function set_locale() {
$plugin_i18n = new Wp_Database_Tools_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 1.0.0
* @access private
*/
private function define_admin_hooks() {
$plugin_admin = new Wp_Database_Tools_Admin(
$this->get_plugin_name(),
$this->get_version(),
$this->get_database(),
$this->get_license(),
$this->get_scanner(),
$this->get_cronjobs(),
$this->get_feedback(),
);
// Load styles.
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
// Load scripts.
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
// Load menu.
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_admin_menu' );
// License.
$this->loader->add_action( 'admin_post_active_plugin', $plugin_admin, 'active_plugin' );
// Action forms.
$this->loader->add_action( 'admin_post_process_general', $plugin_admin, 'process_general' );
$this->loader->add_action( 'admin_post_process_tables', $plugin_admin, 'process_tables' );
$this->loader->add_action( 'admin_post_process_options', $plugin_admin, 'process_options' );
$this->loader->add_action( 'admin_post_process_transients', $plugin_admin, 'process_transients' );
$this->loader->add_action( 'admin_post_process_cronjobs', $plugin_admin, 'process_cronjobs' );
// Notices return.
$this->loader->add_action( 'admin_notices', $plugin_admin, 'custom_notices' );
// Scanner cronjob.
$this->loader->add_filter( 'wp_database_tools_scanner_database_daily', $plugin_admin, 'cron_scanner' );
$this->loader->add_filter( 'wp_database_tools_scanner_database_single', $plugin_admin, 'cron_scanner' );
// Scanner ajax call.
$this->loader->add_action( 'wp_ajax_nopriv_init_scanner', $plugin_admin, 'init_scanner' );
$this->loader->add_action( 'wp_ajax_init_scanner', $plugin_admin, 'init_scanner' );
// Scanner ajax feedbck.
$this->loader->add_action( 'wp_ajax_nopriv_save_feedback_user', $this->get_feedback(), 'save_feedback_user' );
$this->loader->add_action( 'wp_ajax_save_feedback_user', $this->get_feedback(), 'save_feedback_user' );
$this->loader->add_action( 'wp_ajax_load_data', $plugin_admin, 'load_data' );
$this->loader->add_action( 'wp_ajax_load_data_status', $plugin_admin, 'load_data_status' );
$this->loader->add_action( 'wp_ajax_check_force_scanner', $plugin_admin, 'check_force_scanner' );
// Remove all transients.
$this->loader->add_action( 'wp_ajax_nopriv_remove_all_transients', $this->database->get_transients_obj(), 'remove_all_transients' );
$this->loader->add_action( 'wp_ajax_remove_all_transients', $this->database->get_transients_obj(), 'remove_all_transients' );
// Scanner class.
$this->loader->add_action( 'init', $this->get_scanner(), 'wpdt_test_cron_spawn' );
// Admin load.
$this->loader->add_action( 'admin_init', $this->get_database(), 'remove_data_loop' );
}
/**
* Run the loader to execute all of the hooks with WordPress.
*
* @since 1.0.0
*/
public function run() {
$this->loader->run();
}
/**
* Run the scanner if the option did not exist or the data
* returned by the API is empty.
*
* @since 1.1.0
*/
public function run_force_execute_scanner() {
$this->check_exist_execute_scanner();
$this->check_data_execute_scanner();
$force_execute_scanner = get_option( WPDBT_PREFIX . 'force_execute_scanner' );
if ( 'YES' === $force_execute_scanner ) {
// schedule cron job.
if ( ! wp_next_scheduled( 'wp_database_tools_scanner_database_single' ) ) {
wp_schedule_single_event( time() - 3600, 'wp_database_tools_scanner_database_single' );
}
}
}
/**
* If the json returned by the api is empty set the option to "YES".
*
* @since 1.1.2
* @access private
*/
private function check_data_execute_scanner() {
$api_data_source = json_decode( file_get_contents( plugin_dir_path( __DIR__ ) . 'data/api/tables.json' ) );
if ( ( is_null( $api_data_source ) || empty( $api_data_source ) ) && $this->license->get_is_active() === true ) {
update_option( WPDBT_PREFIX . 'force_execute_scanner', 'YES' );
} else {
update_option( WPDBT_PREFIX . 'force_execute_scanner', 'NO' );
}
}
/**
* If the option does not exist, set the scanner execution to "YES".
*
* @since 1.1.2
* @access private
*/
private function check_exist_execute_scanner() {
$force_execute_scanner = get_option( WPDBT_PREFIX . 'force_execute_scanner' );
if ( false === $force_execute_scanner ) {
update_option( WPDBT_PREFIX . 'force_execute_scanner', 'YES' );
}
}
/**
* The name of the plugin used to uniquely identify it within the context of
* WordPress and to define internationalization functionality.
*
* @since 1.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 1.0.0
* @return Wp_Database_Tools_Loader Orchestrates the hooks of the plugin.
*/
public function get_loader() {
return $this->loader;
}
/**
* The class responsible for logic of database functions.
*
* @since 1.0.0
* @return Wp_Database_Tools_Database Manage database functionalities.
*/
public function get_database() {
return $this->database;
}
/**
* The class responsible for all features of the current license.
*
* @since 1.0.0
* @return Wp_Database_Tools_License Defines all features of the current license.
*/
public function get_license() {
return $this->license;
}
/**
* The class responsible for all features of the current license.
*
* @since 1.0.0
* @return Wp_Database_Tools_Cronjobs Defines all features of the current cronjobs.
*/
public function get_cronjobs() {
return $this->cronjobs;
}
/**
* The class responsible for all features of the current scanner.
*
* @since 1.0.0
* @return Wp_Database_Tools_Scanner Defines all features of the current scanner.
*/
public function get_scanner() {
return $this->scanner;
}
/**
* The class responsible for all features of the current plugins.
*
* @since 1.0.0
* @return Wp_Database_Tools_Plugins Defines all features of the current plugins.
*/
public function get_plugins() {
return $this->plugins;
}
/**
* The class responsible for all features of the user feedback.
*
* @since 1.0.0
* @return Wp_Database_Tools_Feedback Defines features of feedback.
*/
public function get_feedback() {
return $this->feedback;
}
/**
* Retrieve the version number of the plugin.
*
* @since 1.0.0
* @return string The version number of the plugin.
*/
public function get_version() {
return $this->version;
}
}