132 lines
5.6 KiB
PHP
132 lines
5.6 KiB
PHP
<?php
|
|
/**
|
|
* The Advanced Settings AJAX handler.
|
|
*
|
|
* @package SEO_Pro_Stack
|
|
* @subpackage SEO_Pro_Stack/Admin/Settings/AJAX
|
|
*/
|
|
|
|
// If this file is called directly, abort.
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* The Advanced Settings AJAX handler.
|
|
*/
|
|
class SEOProStack_AJAX_Advanced {
|
|
|
|
/**
|
|
* Initialize the AJAX handlers.
|
|
*/
|
|
public function init() {
|
|
add_action('wp_ajax_seoprostack_save_advanced_settings', array($this, 'save_advanced_settings'));
|
|
add_action('wp_ajax_seoprostack_optimize_database', array($this, 'optimize_database'));
|
|
}
|
|
|
|
/**
|
|
* Save advanced settings.
|
|
*/
|
|
public function save_advanced_settings() {
|
|
// Verify nonce
|
|
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'seoprostack_ajax_nonce')) {
|
|
wp_send_json_error(array('message' => 'Security check failed'));
|
|
}
|
|
|
|
// Check capabilities
|
|
if (!current_user_can('manage_options')) {
|
|
wp_send_json_error(array('message' => 'You do not have permission to change settings'));
|
|
}
|
|
|
|
// Get settings
|
|
$settings = array(
|
|
'disable_emojis' => isset($_POST['disable_emojis']) ? sanitize_text_field($_POST['disable_emojis']) : 'no',
|
|
'disable_embeds' => isset($_POST['disable_embeds']) ? sanitize_text_field($_POST['disable_embeds']) : 'no',
|
|
'remove_query_strings' => isset($_POST['remove_query_strings']) ? sanitize_text_field($_POST['remove_query_strings']) : 'no',
|
|
'disable_xmlrpc' => isset($_POST['disable_xmlrpc']) ? sanitize_text_field($_POST['disable_xmlrpc']) : 'no',
|
|
'remove_shortlink' => isset($_POST['remove_shortlink']) ? sanitize_text_field($_POST['remove_shortlink']) : 'no',
|
|
'remove_rsd_link' => isset($_POST['remove_rsd_link']) ? sanitize_text_field($_POST['remove_rsd_link']) : 'no',
|
|
'remove_wlwmanifest_link' => isset($_POST['remove_wlwmanifest_link']) ? sanitize_text_field($_POST['remove_wlwmanifest_link']) : 'no',
|
|
'disable_self_pingbacks' => isset($_POST['disable_self_pingbacks']) ? sanitize_text_field($_POST['disable_self_pingbacks']) : 'no',
|
|
'disable_feed_links' => isset($_POST['disable_feed_links']) ? sanitize_text_field($_POST['disable_feed_links']) : 'no',
|
|
'remove_rest_api_links' => isset($_POST['remove_rest_api_links']) ? sanitize_text_field($_POST['remove_rest_api_links']) : 'no',
|
|
'minify_html' => isset($_POST['minify_html']) ? sanitize_text_field($_POST['minify_html']) : 'no',
|
|
'minify_css' => isset($_POST['minify_css']) ? sanitize_text_field($_POST['minify_css']) : 'no',
|
|
'minify_js' => isset($_POST['minify_js']) ? sanitize_text_field($_POST['minify_js']) : 'no'
|
|
);
|
|
|
|
// Save settings
|
|
update_option('seoprostack_advanced_settings', $settings);
|
|
|
|
// Flush rewrite rules if necessary
|
|
if (isset($settings['disable_feed_links']) && $settings['disable_feed_links'] === 'yes') {
|
|
flush_rewrite_rules();
|
|
}
|
|
|
|
// Send response
|
|
wp_send_json_success(array('message' => 'Settings saved successfully'));
|
|
}
|
|
|
|
/**
|
|
* Optimize database.
|
|
*/
|
|
public function optimize_database() {
|
|
global $wpdb;
|
|
|
|
// Verify nonce
|
|
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'seoprostack_ajax_nonce')) {
|
|
wp_send_json_error(array('message' => 'Security check failed'));
|
|
}
|
|
|
|
// Check capabilities
|
|
if (!current_user_can('manage_options')) {
|
|
wp_send_json_error(array('message' => 'You do not have permission to optimize database'));
|
|
}
|
|
|
|
// Tables to optimize
|
|
$tables = $wpdb->get_col("SHOW TABLES LIKE '{$wpdb->prefix}%'");
|
|
$optimized = 0;
|
|
$failed = 0;
|
|
|
|
foreach ($tables as $table) {
|
|
$result = $wpdb->query("OPTIMIZE TABLE $table");
|
|
if ($result === false) {
|
|
$failed++;
|
|
} else {
|
|
$optimized++;
|
|
}
|
|
}
|
|
|
|
// Delete post revisions
|
|
$deleted_revisions = $wpdb->query("DELETE FROM $wpdb->posts WHERE post_type = 'revision'");
|
|
|
|
// Delete auto drafts
|
|
$deleted_drafts = $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'");
|
|
|
|
// Delete trashed posts
|
|
$deleted_trash = $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'trash'");
|
|
|
|
// Delete spam comments
|
|
$deleted_spam = $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'");
|
|
|
|
// Delete trashed comments
|
|
$deleted_trash_comments = $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'");
|
|
|
|
// Delete expired transients
|
|
$deleted_transients = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_%' AND option_name NOT LIKE '_transient_timeout_%'");
|
|
|
|
// Send response
|
|
wp_send_json_success(array(
|
|
'message' => sprintf(
|
|
'Database optimization complete. %d tables optimized, %d revisions deleted, %d auto-drafts deleted, %d trash posts deleted, %d spam comments deleted, %d trash comments deleted, %d expired transients deleted.',
|
|
$optimized,
|
|
$deleted_revisions ? $deleted_revisions : 0,
|
|
$deleted_drafts ? $deleted_drafts : 0,
|
|
$deleted_trash ? $deleted_trash : 0,
|
|
$deleted_spam ? $deleted_spam : 0,
|
|
$deleted_trash_comments ? $deleted_trash_comments : 0,
|
|
$deleted_transients ? $deleted_transients : 0
|
|
)
|
|
));
|
|
}
|
|
} |