Create New Item
×
Item Type
File
Folder
Item Name
×
Search file in folder and subfolders...
File Manager
/
wp-content
/
plugins
/
wp-rocket
/
inc
/
functions
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php defined('ABSPATH') || exit; function rocket_need_api_key() { $message = ''; $errors = (array) get_transient('rocket_check_key_errors'); foreach ($errors as $error) { $message .= '<p>' . $error . '</p>'; } ?> <div class="notice notice-error"> <p><strong><?php echo esc_html(WP_ROCKET_PLUGIN_NAME); ?></strong> <?php echo esc_html(_n('There seems to be an issue validating your license. Please see the error message below.', 'There seems to be an issue validating your license. You can see the error messages below.', count($errors), 'rocket')); ?> </p> <?php echo wp_kses_post($message); ?> </div> <?php } function rocket_renew_all_boxes($uid = null, $keep_this = array()) { delete_metadata('user', $uid, 'rocket_boxes', null === $uid); if (!empty($keep_this) && null !== $uid) { if (!is_array($keep_this)) { $keep_this = (array) $keep_this; } foreach ($keep_this as $kt) { rocket_dismiss_box($kt); } } } function rocket_renew_box($function, $uid = 0) { global $current_user; $uid = 0 === $uid ? $current_user->ID : $uid; $actual = get_user_meta($uid, 'rocket_boxes', true); if ($actual && false !== array_search($function, $actual, true)) { unset($actual[array_search($function, $actual, true)]); update_user_meta($uid, 'rocket_boxes', $actual); } } function rocket_dismiss_box($function) { $actual = get_user_meta(get_current_user_id(), 'rocket_boxes', true); $actual = array_merge((array) $actual, [$function]); $actual = array_filter($actual); $actual = array_unique($actual); update_user_meta(get_current_user_id(), 'rocket_boxes', $actual); delete_transient($function); } function create_rocket_uniqid() { return str_replace('.', '', uniqid('', true)); } function rocket_get_active_plugins() { $plugins = []; $active_plugins = array_intersect_key(get_plugins(), array_flip(array_filter(array_keys(get_plugins()), 'is_plugin_active'))); foreach ($active_plugins as $plugin) { $plugins[] = $plugin['Name']; } return $plugins; } function rocket_is_ssl_website() { if (isset($_SERVER['HTTPS'])) { $https = sanitize_text_field(wp_unslash($_SERVER['HTTPS'])); if ('on' === strtolower($https)) { return true; } if ('1' === (string) $https) { return true; } } elseif (isset($_SERVER['SERVER_PORT']) && '443' === (string) sanitize_text_field(wp_unslash($_SERVER['SERVER_PORT']))) { return true; } return false; } function get_rocket_documentation_url() { $langs = ['fr_FR' => 'fr.']; $lang = get_locale(); $prefix = isset($langs[$lang]) ? $langs[$lang] : ''; $url = "https://{$prefix}docs.wp-rocket.me/?utm_source=wp_plugin&utm_medium=wp_rocket"; return $url; } function get_rocket_faq_url() { $langs = ['de' => 1, 'es' => 1, 'fr' => 1, 'it' => 1]; $locale = explode('_', get_locale()); $lang = isset($langs[$locale[0]]) ? $locale[0] . '/' : ''; $url = WP_ROCKET_WEB_MAIN . "{$lang}faq/?utm_source=wp_plugin&utm_medium=wp_rocket"; return $url; } function rocket_get_plugin_activation_link($plugin) { $activation_url = wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin . '&plugin_status=all&paged=1&s', 'activate-plugin_' . $plugin); return $activation_url; } function rocket_is_plugin_installed($plugin) { $installed_plugins = get_plugins(); return isset($installed_plugins[$plugin]); } function rocket_after_update_single_options($old_value, $value) { if ($old_value !== $value) { flush_rocket_htaccess(); rocket_generate_config_file(); } } function rocket_after_update_array_options($old_value, $value) { $options = ['purchase_page', 'jigoshop_cart_page_id', 'jigoshop_checkout_page_id', 'jigoshop_myaccount_page_id']; foreach ($options as $val) { if (!isset($old_value[$val]) && isset($value[$val]) || isset($old_value[$val], $value[$val]) && $old_value[$val] !== $value[$val]) { flush_rocket_htaccess(); rocket_generate_config_file(); break; } } } function rocket_is_mobile_plugin_active() { return \WP_Rocket\Subscriber\Third_Party\Plugins\Mobile_Subscriber::is_mobile_plugin_active(); } function rocket_allow_json_mime_type($wp_get_mime_types) { $wp_get_mime_types['json'] = 'application/json'; return $wp_get_mime_types; } function rocket_check_json_filetype($wp_check_filetype_and_ext, $file, $filename, $mimes) { if (!empty($wp_check_filetype_and_ext['ext']) && !empty($wp_check_filetype_and_ext['type'])) { return $wp_check_filetype_and_ext; } $wp_filetype = wp_check_filetype($filename, $mimes); if ('json' !== $wp_filetype['ext']) { return $wp_check_filetype_and_ext; } if (empty($wp_filetype['type'])) { $wp_filetype['type'] = 'application/json'; } if (!extension_loaded('fileinfo')) { return $wp_check_filetype_and_ext; } $finfo = finfo_open(FILEINFO_MIME_TYPE); $real_mime = finfo_file($finfo, $file); finfo_close($finfo); if ('text/plain' !== $real_mime) { return $wp_check_filetype_and_ext; } $wp_check_filetype_and_ext = array_merge($wp_check_filetype_and_ext, $wp_filetype); return $wp_check_filetype_and_ext; } function rocket_data_collection_preview_table() { $data = rocket_analytics_data(); if (!$data) { return; } $html = '<table class="wp-rocket-data-table widefat striped">'; $html .= '<tbody>'; $html .= '<tr>'; $html .= '<td class="column-primary">'; $html .= sprintf('<strong>%s</strong>', __('Server type:', 'rocket')); $html .= '</td>'; $html .= '<td>'; $html .= sprintf('<code>%s</code>', $data['web_server']); $html .= '</td>'; $html .= '</tr>'; $html .= '<tr>'; $html .= '<td class="column-primary">'; $html .= sprintf('<strong>%s</strong>', __('PHP version number:', 'rocket')); $html .= '</td>'; $html .= '<td>'; $html .= sprintf('<code>%s</code>', $data['php_version']); $html .= '</td>'; $html .= '</tr>'; $html .= '<tr>'; $html .= '<td class="column-primary">'; $html .= sprintf('<strong>%s</strong>', __('WordPress version number:', 'rocket')); $html .= '</td>'; $html .= '<td>'; $html .= sprintf('<code>%s</code>', $data['wordpress_version']); $html .= '</td>'; $html .= '</tr>'; $html .= '<tr>'; $html .= '<td class="column-primary">'; $html .= sprintf('<strong>%s</strong>', __('WordPress multisite:', 'rocket')); $html .= '</td>'; $html .= '<td>'; $html .= sprintf('<code>%s</code>', $data['multisite'] ? 'true' : 'false'); $html .= '</td>'; $html .= '</tr>'; $html .= '<tr>'; $html .= '<td class="column-primary">'; $html .= sprintf('<strong>%s</strong>', __('Current theme:', 'rocket')); $html .= '</td>'; $html .= '<td>'; $html .= sprintf('<code>%s</code>', $data['current_theme']); $html .= '</td>'; $html .= '</tr>'; $html .= '<tr>'; $html .= '<td class="column-primary">'; $html .= sprintf('<strong>%s</strong>', __('Current site language:', 'rocket')); $html .= '</td>'; $html .= '<td>'; $html .= sprintf('<code>%s</code>', $data['locale']); $html .= '</td>'; $html .= '</tr>'; $html .= '<tr>'; $html .= '<td class="column-primary">'; $html .= sprintf('<strong>%s</strong>', __('Active plugins:', 'rocket')); $html .= '</td>'; $html .= '<td>'; $html .= sprintf('<em>%s</em>', __('Plugin names of all active plugins', 'rocket')); $html .= '</td>'; $html .= '</tr>'; $html .= '<tr>'; $html .= '<td class="column-primary">'; $html .= sprintf('<strong>%s</strong>', __('Anonymized WP Rocket settings:', 'rocket')); $html .= '</td>'; $html .= '<td>'; $html .= sprintf('<em>%s</em>', __('Which WP Rocket settings are active', 'rocket')); $html .= '</td>'; $html .= '</tr>'; $html .= '</tbody>'; $html .= '</table>'; return $html; } function rocket_settings_import_redirect($message, $status) { add_settings_error('general', 'settings_updated', $message, $status); set_transient('settings_errors', get_settings_errors(), 30); $goback = add_query_arg('settings-updated', 'true', wp_get_referer()); wp_safe_redirect(esc_url_raw($goback)); die; }