Current Path : /storage/v11800/shoptimizer-latest/public_html/wp-content/plugins/pagespeed/ |
Linux v11800 5.3.0-1023-aws #25~18.04.1-Ubuntu SMP Fri Jun 5 15:19:18 UTC 2020 aarch64
|
Current File : /storage/v11800/shoptimizer-latest/public_html/wp-content/plugins/pagespeed/pagespeed_config.php |
<?php
require_once WP_PLUGIN_DIR . '/pagespeed/index-wp-mysql-for-speed/index-wp-mysql-for-speed.php';
function pagespeed_check_for_updates($checked_data) {
if (empty($checked_data->checked)) {
return $checked_data;
}
$request_args = array(
'slug' => 'pagespeed', // replace with your plugin's slug
'version' => PAGESPEED_VERSION // define this constant in your plugin
);
$request_string = http_build_query($request_args);
$url = 'https://my.nestify.io/home/pluginupdate/?' . $request_string; // replace with your update API URL
// Make the request
$response = wp_remote_get($url);
if (is_wp_error($response) || wp_remote_retrieve_response_code($response) != 200) {
return $checked_data;
}
$response_body = wp_remote_retrieve_body($response);
$version_info = json_decode($response_body);
if (false != $version_info && is_object($version_info) && isset($version_info->new_version)) {
// If there is a new version, modify the $checked_data object
$checked_data->response['pagespeed/pagespeed.php'] = (object)array(
'slug' => 'pagespeed',
'new_version' => $version_info->new_version,
'url' => $version_info->url, // Your plugin's homepage or changelog URL
'package' => $version_info->package // The ZIP package URL
);
}
return $checked_data;
}
add_filter('pre_set_site_transient_update_plugins', 'pagespeed_check_for_updates');
$pagespeedcss_options = get_option('pagespeedcss_options');
if (isset($pagespeedcss_options['pagespeed_css_optimization']) && $pagespeedcss_options['pagespeed_css_optimization'] == '1') {
require_once WP_PLUGIN_DIR . '/pagespeed/autoptimize/autoptimize.php';
}
function pagespeed_remove_autoptimize_submenu() {
remove_submenu_page('options-general.php', 'autoptimize');
remove_submenu_page('options-general.php', 'nginx');
remove_submenu_page('tools.php', 'imfs_settings');
}
add_action('admin_menu', 'pagespeed_remove_autoptimize_submenu', 10000);
function pagespeed_remove_autoptimize_from_top_navbar($wp_admin_bar) {
$wp_admin_bar->remove_node('autoptimize');
}
add_action('admin_bar_menu', 'pagespeed_remove_autoptimize_from_top_navbar', 10000);
add_action('update_option_pagespeedcss_options', 'pagespeedcss_option_update_handler', 10, 3);
function pagespeedcss_option_update_handler($old_value, $value, $option) {
$agregatecss = '';
$inlinecss = '';
if (!empty($value['pagespeed_css_minify_combine']) && !empty($value['pagespeed_css_minify_combine']) == '1') {
$agregatecss = 'on';
}
if (!empty($value['pagespeed_css_inline']) && $value['pagespeed_css_inline'] == '1') {
$inlinecss = 'on';
}
if (!empty($value['pagespeed_css_optimization']) && $value['pagespeed_css_optimization'] == '1') {
if(!isset($value['pagespeed_css_minify_combine']) || !isset($value['pagespeed_css_inline'])) {
$value['pagespeed_css_minify_combine'] = '0';
$value['pagespeed_css_inline'] = '0';
update_option('pagespeedcss_options', $value);
}
$autoptimize_options = [
["option_name" => "autoptimize_cache_clean", "option_value" => ""],
["option_name" => "autoptimize_cache_fallback", "option_value" => "on"],
["option_name" => "autoptimize_cache_nogzip", "option_value" => "on"],
["option_name" => "autoptimize_ccss_version", "option_value" => "AO_3.1.10"],
["option_name" => "autoptimize_cdn_url", "option_value" => ""],
["option_name" => "autoptimize_css", "option_value" => "on"],
["option_name" => "autoptimize_css_aggregate", "option_value" => $agregatecss],
["option_name" => "autoptimize_css_datauris", "option_value" => ""],
["option_name" => "autoptimize_css_defer", "option_value" => ""],
["option_name" => "autoptimize_css_defer_inline", "option_value" => ""],
["option_name" => "autoptimize_css_exclude", "option_value" => ", admin-bar.min.css, dashicons.min.css, wp-content/cache/, wp-content/uploads/"],
["option_name" => "autoptimize_css_include_inline", "option_value" => $agregatecss],
["option_name" => "autoptimize_css_inline", "option_value" => $inlinecss],
["option_name" => "autoptimize_css_justhead", "option_value" => ""],
["option_name" => "autoptimize_enable_meta_ao_settings", "option_value" => ""],
["option_name" => "autoptimize_enable_site_config", "option_value" => "on"],
["option_name" => "autoptimize_html", "option_value" => ""],
["option_name" => "autoptimize_html_keepcomments", "option_value" => ""],
["option_name" => "autoptimize_html_minify_inline", "option_value" => ""],
["option_name" => "autoptimize_imgopt_launched", "option_value" => "on"],
["option_name" => "autoptimize_installed_before_compatibility", "option_value" => ""],
["option_name" => "autoptimize_js", "option_value" => ""],
["option_name" => "autoptimize_js_aggregate", "option_value" => ""],
["option_name" => "autoptimize_js_defer_inline", "option_value" => "on"],
["option_name" => "autoptimize_js_defer_not_aggregate", "option_value" => "on"],
["option_name" => "autoptimize_js_exclude", "option_value" => ""],
["option_name" => "autoptimize_js_forcehead", "option_value" => ""],
["option_name" => "autoptimize_js_include_inline", "option_value" => ""],
["option_name" => "autoptimize_js_justhead", "option_value" => ""],
["option_name" => "autoptimize_js_trycatch", "option_value" => ""],
["option_name" => "autoptimize_minify_excluded", "option_value" => ""],
["option_name" => "autoptimize_optimize_checkout", "option_value" => ""],
["option_name" => "autoptimize_optimize_logged", "option_value" => "on"],
["option_name" => "autoptimize_service_availablity", "option_value" => 'a:2:{s:12:"extra_imgopt";a:3:{s:6:"status";s:2:"up";s:5:"hosts";a:1:{i:1;s:28:"https://sp-ao.shortpixel.ai/";}s:16:"launch-threshold";s:4:"4096";}s:7:"critcss";a:2:{s:6:"status";s:2:"up";s:5:"hosts";a:1:{i:1;s:24:"https://criticalcss.com/";}}}'],
["option_name" => "autoptimize_version", "option_value" => "3.1.10"]
];
// Iterate over the options and update each one.
foreach ($autoptimize_options as $option) {
update_option($option['option_name'], $option['option_value']);
}
if (class_exists('autoptimizeCache')) {
autoptimizeCache::clearall();
}
do_action('rt_nginx_helper_purge_all');
do_action( 'rt_nginx_helper_after_purge_all' );
}
}
add_action('update_option_pagespeedimage_options', 'pagespeedimage_option_update_handler', 10, 3);
function pagespeedimage_option_update_handler($old_value, $value, $option) {
if (isset($value['pagespeed_image_optimization'])) {
$curl_url = 'https://my.nestify.io/cdn/webp/' . CDN_SITE_ID;
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $curl_url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $value,
CURLOPT_RETURNTRANSFER => true,
// Timeout the request after 5 seconds
CURLOPT_TIMEOUT => 5,
]);
try {
$result = curl_exec($ch);
curl_close($ch);
} catch (\Exception $e) {
error_log(' Exception: ' . $e->getMessage());
}
}
}
function pagespeed_lazyload_video_shortcode($atts) {
// Extract shortcode attributes
$atts = shortcode_atts(array(
'id' => '', // Video ID
'type' => 'youtube', // Video platform: youtube or vimeo
'thumbnail' => '', // Optional custom thumbnail image URL
), $atts, 'lazyload_video');
if (empty($atts['id'])) {
return 'No video specified.';
}
$unique_id = uniqid('video_container_'); // Unique ID for each video container
// Determine the platform and set appropriate URLs
$thumbnail_url = '';
$video_url = '';
if ($atts['type'] === 'vimeo') {
$video_url = "https://player.vimeo.com/video/{$atts['id']}";
// Default Vimeo thumbnail if none is provided
$thumbnail_url = $atts['thumbnail'] ?: "https://placehold.it/560x315&text=Vimeo+Video";
} elseif ($atts['type'] === 'youtube') {
$video_url = "https://www.youtube.com/embed/{$atts['id']}?autoplay=1";
// Use YouTube's thumbnail URL if none is provided
$thumbnail_url = $atts['thumbnail'] ?: "https://img.youtube.com/vi_webp/{$atts['id']}/maxresdefault.webp";
}
$html = <<<HTML
<div id="{$unique_id}" class="video-container" style="position: relative; width: 560px; height: 315px; cursor: pointer;">
<img src="{$thumbnail_url}" alt="Play Video" style="width: 100%; height: 100%;">
<div class="play-button" style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 0; height: 0; border-style: solid; border-width: 20px 0 20px 30px; border-color: transparent transparent transparent #ffffff;"></div>
</div>
<script>
document.getElementById("{$unique_id}").addEventListener('click', function() {
this.innerHTML = '<iframe width="560" height="315" src="{$video_url}" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>';
});
</script>
HTML;
return $html;
}
add_shortcode('lazyload_video', 'pagespeed_lazyload_video_shortcode');
function pagespeed_wp_optimization() {
$options = get_option('pagespeedwp_options');
// Disable Emojis
if (!empty($options['disable_emojis'])) {
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');
}
// Disable Dashicons
if (!empty($options['disable_dashicons'])) {
wp_deregister_style('dashicons');
}
// Disable Embeds
if (!empty($options['disable_embeds'])) {
remove_action('wp_head', 'wp_oembed_add_discovery_links');
remove_action('wp_head', 'wp_oembed_add_host_js');
add_filter('embed_oembed_discover', '__return_false');
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
remove_action('rest_api_init', 'wp_oembed_register_route');
}
// Disable XML-RPC
if (!empty($options['disable_xml_rpc'])) {
add_filter('xmlrpc_enabled', '__return_false');
}
// Remove jQuery Migrate
if (!empty($options['remove_jquery_migrate'])) {
add_action('wp_default_scripts', function($scripts) {
if (!is_admin() && isset($scripts->registered['jquery'])) {
$script = $scripts->registered['jquery'];
if ($script->deps) { // Check whether the script has any dependencies
$script->deps = array_diff($script->deps, array('jquery-migrate'));
}
}
});
}
// Hide WP Version
if (!empty($options['hide_wp_version'])) {
remove_action('wp_head', 'wp_generator');
}
// Remove wlwmanifest Link
if (!empty($options['remove_wlwmanifest_link'])) {
remove_action('wp_head', 'wlwmanifest_link');
}
// Remove RSD Link
if (!empty($options['remove_rsd_link'])) {
remove_action('wp_head', 'rsd_link');
}
// Remove Shortlink
if (!empty($options['remove_shortlink'])) {
remove_action('wp_head', 'wp_shortlink_wp_head', 10);
}
// Disable RSS Feeds
if (!empty($options['disable_rss_feeds'])) {
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);
}
// Disable Self Pingbacks
if (!empty($options['disable_self_pingbacks'])) {
add_filter('pre_ping', 'pagespeed_prevent_self_pingbacks');
}
// Disable REST API for non-administrators
if (!empty($options['disable_rest_api'])) {
add_filter('rest_authentication_errors', function($result) {
if (!is_user_logged_in()) {
return new WP_Error('rest_not_logged_in', 'You are not currently logged in.', array('status' => 401));
}
if (!current_user_can('edit_posts')) {
return new WP_Error('rest_not_allowed', 'You are not allowed to access the REST API.', array('status' => 403));
}
return $result;
});
}
// Remove REST API Links
if (!empty($options['remove_rest_api_links'])) {
remove_action('wp_head', 'rest_output_link_wp_head', 10);
remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);
}
// Disable Password Strength Meter
if (!empty($options['disable_password_strength_meter'])) {
wp_dequeue_script('wp-password-strength-meter');
}
// Disable Comments
if (!empty($options['disable_comments'])) {
foreach (get_post_types() as $post_type) {
if (post_type_supports($post_type, 'comments')) {
remove_post_type_support($post_type, 'comments');
remove_post_type_support($post_type, 'trackbacks');
}
}
// Close comments on the front-end
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);
// Hide existing comments
add_filter('comments_array', '__return_empty_array', 10, 2);
// Remove comments page in admin menu
add_action('admin_menu', function() {
remove_menu_page('edit-comments.php');
});
add_action('admin_init', function() {
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url());
exit;
}
});
// Remove comments links from admin bar
add_action('init', function() {
if (is_admin_bar_showing()) {
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
}
});
}
// Add Blank Favicon
if (!empty($options['add_blank_favicon'])) {
$icon = '<link rel="icon" href="data:image/x-icon;,">';
add_action('wp_head', function() use ($icon) { echo $icon; });
}
// Remove Global Styles
if (!empty($options['remove_global_styles'])) {
remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles');
remove_action('wp_footer', 'wp_enqueue_global_styles', 1);
}
}
add_action('init', 'pagespeed_wp_optimization');
function pagespeed_remove_comments_admin_bar_links() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('comments');
}
$options = get_option('pagespeedwp_options');
if (!empty($options['disable_comments'])) {
add_action('wp_before_admin_bar_render', 'pagespeed_remove_comments_admin_bar_links');
}
add_action('update_option_pagespeeddb_options', 'pagespeeddb_option_update_handler', 10, 3);
function pagespeeddb_option_update_handler($old_value, $value, $option) {
$options = get_option('pagespeeddb_options');
global $wpdb;
// Ensure you have the correct and updated options values
$options = get_option('pagespeeddb_options');
// Check and clean post revisions
if (!empty($options['pagespeed_db_post_revisions'])) {
$wpdb->query("DELETE FROM $wpdb->posts WHERE post_type = 'revision'");
}
// Check and clean auto-drafts
if (!empty($options['pagespeed_db_auto_drafts'])) {
$wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'");
}
// Check and clean trashed posts
if (!empty($options['pagespeed_db_trashed_posts'])) {
$wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'trash'");
}
// Check and clean spam comments
if (!empty($options['pagespeed_db_spam_comments'])) {
$wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'");
}
// Check and clean trashed comments
if (!empty($options['pagespeed_db_trashed_comments'])) {
$wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'");
}
// Check and clean expired transients
if (!empty($options['pagespeed_db_expired_transients'])) {
$expired_transients = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '\_transient\_timeout\_%' AND option_value < UNIX_TIMESTAMP()");
foreach ($expired_transients as $transient) {
$transient_name = str_replace('_timeout', '', $transient);
$wpdb->query($wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name = %s OR option_name = %s", $transient, $transient_name));
}
}
// Check and clean all transients
if (!empty($options['pagespeed_db_all_transients'])) {
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '\_transient\_%'");
}
update_option('pagespeeddb_options', array());
}