verify_license_key($key, 'slm_activate'); if (!empty($key_response) && $key_response->result == 'success') { update_option('berqwp_license_key', $key); if (is_admin()) { ?>
result == 'error') { $error = $key_response->message; if (is_admin()) { ?>
activate_license_from_multi_site(); } if (is_admin()) { $this->berq_post_types(); } if (get_option('berqwp_disable_emojis') == 1) { $this->disable_emoji(); } if (is_admin() && !empty(get_option('berqwp_license_key'))) { $license_key = get_option('berqwp_license_key'); $key_response = $this->verify_license_key($license_key); if (!empty($key_response) && $key_response->result == 'success' && $key_response->status == 'active') { $this->is_key_verified = true; $this->key_response = $key_response; } else { $this->is_key_verified = false; } } // redirect to berqwp admin page if (get_transient('berqwp_redirect')) { delete_transient('berqwp_redirect'); // Set the URL to redirect to after activation $redirect_url = admin_url('admin.php?page=berqwp'); // Redirect after activation wp_redirect($redirect_url); // Make sure to exit after the redirect exit; } // Deactivate conflicting plugins if (is_admin() && isset($_POST['berqwp_plugins_deactivate']) && wp_verify_nonce($_POST['berqwp_plugins_deactivate'], 'berqwp_plugins_deactivate')) { foreach ($this->conflicting_plugins as $plugin) { // Deactivate each conflicting plugin if (is_plugin_active($plugin)) { deactivate_plugins($plugin); } } header('location: ' . esc_url(get_site_url() . add_query_arg($_GET))); exit; } } function save_settings() { require_once optifer_PATH . '/admin/save-settings.php'; } function berqwp_cleanup_completed_and_failed_tasks() { if (!get_transient('berqwp_action_cleanup')) { set_transient('berqwp_action_cleanup', true, 60 * 60 * 10); global $berq_log; $berq_log->info("* * * * * * * * *"); $berq_log->info("* Task Cleanup"); $berq_log->info("* * * * * * * * *"); global $wpdb; // Define the hook name $hook_name = 'warmup_cache_by_slug'; // Count the number of completed and failed actions for the given hook $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}actionscheduler_actions WHERE hook = %s AND (status = 'complete' OR status = 'failed')", $hook_name ) ); $berq_log->info("Completed + failed task count: $count"); // Check if the count exceeds 50 if ($count > 50) { $delete_count = $count - 50; // Calculate how many rows to delete $berq_log->info("Deleting last $delete_count"); $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}actionscheduler_actions WHERE hook = %s AND (status = 'complete' OR status = 'failed') ORDER BY scheduled_date_gmt ASC LIMIT %d", $hook_name, $delete_count ) ); } // clear logs, keep the last 1000 if ( class_exists( 'ActionScheduler_QueueRunner' ) ) { global $wpdb; $table_name = $wpdb->prefix . 'actionscheduler_logs'; // Count the total number of logs $total_logs = $wpdb->get_var( "SELECT COUNT(*) FROM $table_name" ); // Set the limit to keep the latest 1000 logs $limit = max( 0, $total_logs - 1000 ); // Delete logs beyond the limit $wpdb->query( "DELETE FROM $table_name WHERE log_date_gmt < (SELECT log_date_gmt FROM $table_name ORDER BY log_date_gmt DESC LIMIT 1 OFFSET $limit)" ); } $berq_log->info("* * * * * * * * * *"); $berq_log->info("* Task Cleanup End"); $berq_log->info("* * * * * * * * * *"); } } function notices() { if (isset($_GET['dismiss_feedback'])) { set_transient( 'bqwp_hide_feedback_notice', true, DAY_IN_SECONDS * 2 ); } // Check rest api $check_rest = bwp_check_rest_api(); if ( $check_rest['status'] == 'error' ) { ?>

Error: The WordPress REST API is disabled. BerqWP plugin will not function correctly without the REST API. Please enable the REST API for full functionality.

is_key_verified) { $notice = '
'; $notice .= '

'; $notice .= __('🎉 Loving BerqWP\'s performance? 🚀 Show some love and help us grow 👉 - Rate BerqWP Plugin. Your insights shape our journey.', 'searchpro'); $notice .= 'Dismiss'; $notice .= '

'; $notice .= '
'; echo wp_kses_post($notice); } if (berq_is_localhost()) { ?>
Localhost Detected: BerqWP doesn't operate in a localhost environment.

", 'searchpro')); ?>
conflicting_plugins as $plugin) { if (is_plugin_active($plugin)) { $plugins_to_deactivate .= '
  • ' . basename(dirname($plugin)) . '
  • '; } } if (!empty($plugins_to_deactivate)) { echo ""; echo '
    '; echo wp_kses_post(__('

    BerqWP Plugin Conflict: The following plugins have a same nature as BerqWP plugin. Having multiple plugins of the same type can cause unexpected results.

    ', 'searchpro')); ?>
    '; ?>
    $plugins_to_deactivate"); echo '
    '; } } function berq_post_types() { // Get post type names $post_type_names = get_post_types(array( 'public' => true, 'exclude_from_search' => false, ), 'names'); unset($post_type_names['attachment']); // var_dump($post_type_names); // Modify which post types to optimize $post_type_names = apply_filters( 'berqwp_post_types', $post_type_names ); // Save the names in a WordPress option update_option('berqwp_post_type_names', $post_type_names); // Cleanup actions $this->berqwp_cleanup_completed_and_failed_tasks(); } function plugin_settings_links($links) { $mylinks = array( '' . __('Help Center', 'searchpro') . '', '' . __('Settings', 'searchpro') . '', ); return array_merge($links, $mylinks); } function verify_license_key($license_key, $action = 'slm_check') { // Action // slm_activate // slm_deactivate // slm_check if (empty($license_key)) { return; } global $berq_log; $transient_key = 'berq_lic_response_cache'; // Set a unique key for the transient if ($action !== 'slm_check') { delete_transient( $transient_key ); } // Check if the response is already cached $cached_response = get_transient($transient_key); if (false === $cached_response) { // If not cached, perform the API request $berq_log->info('Checking the license key.'); $api_params = array( 'registered_domain' => $_SERVER['SERVER_NAME'], 'slm_action' => $action, 'secret_key' => BERQ_SECRET, 'license_key' => $license_key, ); $endpoint_url = esc_url(add_query_arg($api_params, BERQ_SERVER)); $args = array( 'method' => 'POST', // Only POST works for unknown reason 'timeout' => 10, 'redirection' => 5, 'blocking' => true, 'headers' => array( 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'Accept-Encoding' => 'gzip, deflate, br', 'Accept-Language' => 'en-US,en;q=0.9', 'Connection' => 'keep-alive', 'Referer' => 'https://berqwp.com/', // Adjust based on actual referer ), 'cookies' => array(), 'sslverify' => false, // Disable SSL verification (for debugging purposes) ); $response = wp_remote_request(add_query_arg($api_params, BERQ_SERVER), $args); // Send query to the license manager server // $response = (array) wp_remote_post($endpoint_url, array('timeout' => 20, 'sslverify' => false)); // if wp_remote_get didn't work if (is_array($response) && empty($response['body'])) { // Create context options with headers $context_options = [ "ssl" => array( "verify_peer" => false, "verify_peer_name" => false, ), 'http' => [ 'method' => 'GET', 'header' => [ 'Content-Type: application/json', ], ], ]; // Create a stream context $context = stream_context_create($context_options); // Make the GET request $response = json_decode(file_get_contents($endpoint_url, false, $context)); } if (is_array($response)) { $cached_response = json_decode($response['body']); if ($action == 'slm_check' && !empty($cached_response)) { // Cache the response for 24 hours set_transient($transient_key, $cached_response, 24 * HOUR_IN_SECONDS); } } else { $cached_response = $response; if ($action == 'slm_check' && !empty($cached_response) && $cached_response->result == 'success' && $cached_response->status == 'active') { // Cache the response for 24 hours set_transient($transient_key, $cached_response, 24 * HOUR_IN_SECONDS); } } } else { $berq_log->info('Delivering license key object from the transient cache.'); } // Return the cached response return $cached_response; } // Disable emoji functionality function disable_emoji() { // Remove emoji-related actions and filters remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('admin_print_scripts', 'print_emoji_detection_script'); remove_action('wp_print_styles', 'print_emoji_styles'); remove_action('admin_print_styles', 'print_emoji_styles'); remove_filter('the_content_feed', 'wp_staticize_emoji'); remove_filter('comment_text_rss', 'wp_staticize_emoji'); remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); // Remove emoji-related TinyMCE plugins add_filter('tiny_mce_plugins', [$this, 'disable_emoji_tinymce']); } // Filter function to disable emoji-related TinyMCE plugins function disable_emoji_tinymce($plugins) { if (is_array($plugins)) { return array_diff($plugins, array('wpemoji')); } else { return array(); } } function get_media_ids(WP_REST_Request $request) { require_once optifer_PATH . 'api/get_media_ids.php'; } function optimize_images(WP_REST_Request $request) { require_once optifer_PATH . 'api/optimize_images.php'; } function delete_images(WP_REST_Request $request) { require_once optifer_PATH . 'api/delete_images.php'; } function clear_cache(WP_REST_Request $request) { require_once optifer_PATH . 'api/clear_cache.php'; } function warmup_cache(WP_REST_Request $request) { require_once optifer_PATH . 'api/warmup_cache.php'; } function store_webp(WP_REST_Request $request) { require_once optifer_PATH . 'api/store_webp.php'; } function store_cache(WP_REST_Request $request) { require_once optifer_PATH . 'api/store_cache.php'; } function store_javascript_cache(WP_REST_Request $request) { require_once optifer_PATH . 'api/store_javascript_cache.php'; } function register_menu() { $svg = ' '; add_menu_page('BerqWP', 'BerqWP', 'manage_options', 'berqwp', [$this, 'admin_page'], 'data:image/svg+xml;base64,' . base64_encode($svg), 10); } function admin_page() { if ($this->is_key_verified) { require_once optifer_PATH . 'admin/admin-page.php'; } else { require_once optifer_PATH . 'admin/intro-page.php'; } } } global $berqWP; $berqWP = new berqWP(); }