芝麻web文件管理V1.00
编辑当前文件:/home/conskgoa/doughi.co.uk/wp-content/plugins/contact-forms-anti-spam/contact-forms-anti-spam.php
. * */ // If this file is called directly, abort. if (!defined('ABSPATH')) exit; /** * Currently plugin version. */ define( 'MASPIK_VERSION', '2.9.1' ); define('MASPIK_PLUGIN_FILE', __FILE__); /** * Load plugin text domain and initialize plugin */ require_once plugin_dir_path(__FILE__) . 'includes/consts.php'; function maspik_plugins_loaded() { // Load text domain load_plugin_textdomain( 'contact-forms-anti-spam', false, dirname(plugin_basename(__FILE__)) . '/languages/' ); // Initialize plugin require plugin_dir_path(__FILE__) . 'includes/class-maspik.php'; require_once plugin_dir_path(__FILE__) . 'admin/maspik-statistics.php'; require_once plugin_dir_path(__FILE__) . 'includes/dashboard-statistics.php'; if (apply_filters('maspik_active_license_library', true)) { require plugin_dir_path(__FILE__) . 'license/license.php'; } $plugin = new Maspik(); $plugin->run(); } // Hook into plugins_loaded which runs before init add_action('init', 'maspik_plugins_loaded'); // Add plugin row meta add_filter( 'plugin_row_meta', 'maspik_plugin_row_meta', 10, 2 ); function maspik_plugin_row_meta( $links, $file ) { if( strpos( $file, basename(__FILE__) ) ) { $maspik_links = array( 'donat_link' => '
'.__( 'Love it? Rate us 5⭐', 'contact-forms-anti-spam' ).'
', 'settings' => '
'.__( 'Setting page', 'contact-forms-anti-spam' ).'
', ); $links = array_merge( $links, $maspik_links ); } return $links; } //make new log table function create_maspik_log_table() { global $wpdb; $table_name = $wpdb->prefix . 'maspik_spam_logs'; // define the structure of the table $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, spam_type varchar(191) NOT NULL, spam_value varchar(191) NOT NULL, spam_detail longtext NOT NULL, spam_ip varchar(191) NOT NULL, spam_country varchar(191) NOT NULL, spam_agent varchar(191) NOT NULL, spam_date varchar(191) NOT NULL, spam_source varchar(191) NOT NULL, spamsrc_label varchar(191) NOT NULL DEFAULT '', spamsrc_val varchar(191) NOT NULL DEFAULT '', spam_tag varchar(191) NOT NULL DEFAULT '', PRIMARY KEY (id) ) " . $wpdb->get_charset_collate(); // if the table doesn't exist or if we need to update the structure require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); // mark the function as run successfully update_option('maspik_columns_last_check', '2'); } function maspik_check_and_update_log_table($upgrader_object = null, $options = array()) { // Check if this is our plugin being updated if ($upgrader_object && !empty($options)) { if (!isset($options['plugin']) || strpos($options['plugin'], 'contact-forms-anti-spam') === false) { return; } } // Check user capabilities if not during activation/update if (!$upgrader_object && !current_user_can('manage_options')) { return; } // Check if required function exists if (!function_exists('create_maspik_log_table')) { error_log('Maspik DB Update Error: Required function create_maspik_log_table() not found'); return; } global $wpdb; $table_name = $wpdb->prefix . 'maspik_spam_logs'; $current_db_version = get_option('maspik_db_version', '1.0'); $required_db_version = '2.0'; // start at version 2.5.2 // Start transaction $transaction_started = $wpdb->query('START TRANSACTION'); if ($transaction_started === false) { error_log('Maspik DB Update Error: Failed to start transaction - ' . $wpdb->last_error); if (!$upgrader_object) { wp_die('Failed to start database transaction: ' . $wpdb->last_error); } return; } try { // Only run if we need to update if (version_compare($current_db_version, $required_db_version, '<')) { // Check if table exists $table_exists = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table_name)); if (!$table_exists) { $result = create_maspik_log_table(); if ($result === false) { throw new Exception('Failed to create log table: ' . $wpdb->last_error); } } else { // Check if columns exist $columns = $wpdb->get_col("SHOW COLUMNS FROM $table_name"); if ($columns === false) { throw new Exception('Failed to get columns: ' . $wpdb->last_error); } // Add missing columns $new_columns = array( 'spam_tag' => "ALTER TABLE $table_name ADD COLUMN spam_tag varchar(191) NOT NULL DEFAULT ''", 'spamsrc_label' => "ALTER TABLE $table_name ADD COLUMN spamsrc_label varchar(191) NOT NULL DEFAULT ''", 'spamsrc_val' => "ALTER TABLE $table_name ADD COLUMN spamsrc_val varchar(191) NOT NULL DEFAULT ''" ); foreach ($new_columns as $column => $sql) { if (!in_array($column, $columns)) { $result = $wpdb->query($sql); if ($result === false) { throw new Exception("Failed to add column $column: " . $wpdb->last_error); } } } } // Update the stored version $update_result = update_option('maspik_db_version', $required_db_version); if ($update_result === false) { throw new Exception('Failed to update version number'); } // Commit transaction $commit_result = $wpdb->query('COMMIT'); if ($commit_result === false) { throw new Exception('Failed to commit transaction: ' . $wpdb->last_error); } } else { // Commit transaction even if no update was needed $wpdb->query('COMMIT'); } } catch (Exception $e) { // Rollback on error $wpdb->query('ROLLBACK'); // If this is an activation, we should show error but not deactivate if (!$upgrader_object) { wp_die('Failed to create or update database tables: ' . $e->getMessage()); } } } // Run during plugin update add_action('upgrader_process_complete', 'maspik_check_and_update_log_table', 10, 2); // Run during plugin activation register_activation_hook(__FILE__, function() { try { maspik_check_and_update_log_table(null, array()); } catch (Exception $e) { // Deactivate the plugin if database setup fails error_log('Maspik DB Activation Error: ' . $e->getMessage()); deactivate_plugins(plugin_basename(__FILE__)); wp_die('Plugin activation failed: ' . $e->getMessage()); } }); add_action('admin_footer-plugins.php', 'maspik_deactivation_survey'); function maspik_deactivation_survey() { $nonce = wp_create_nonce('maspik_deactivation_survey'); ?>
×
</textarea>
</textarea>