function rocket_cdn_css_properties($buffer) { $zone = array('all', 'css_and_js', 'css'); $cnames = get_rocket_cdn_cnames($zone); /** * Allow a "force deactivation" link to be printed, use at your own risks * * @since 2.0.0 * * @param bool true will print the link */ $do_rocket_cdn_css_properties = apply_filters('do_rocket_cdn_css_properties', true); if (!get_rocket_option('cdn') || !$cnames || !$do_rocket_cdn_css_properties) { return $buffer; } preg_match_all('/url\\((?![\'"]?data)([^\\)]+)\\)/i', $buffer, $matches); if (is_array($matches)) { $i = 0; foreach ($matches[1] as $url) { $url = trim($url, " \t\n\r\v\"'"); $url = get_rocket_cdn_url($url, $zone); $property = str_replace($matches[1][$i], $url, $matches[0][$i]); $buffer = str_replace($matches[0][$i], $property, $buffer); $i++; } } return $buffer; }
function rocket_upgrader() { // Grab some infos $actual_version = get_rocket_option('version'); // You can hook the upgrader to trigger any action when WP Rocket is upgraded // first install if (!$actual_version) { do_action('wp_rocket_first_install'); } elseif (WP_ROCKET_VERSION != $actual_version) { do_action('wp_rocket_upgrade', WP_ROCKET_VERSION, $actual_version); } // If any upgrade has been done, we flush and update version # if (did_action('wp_rocket_first_install') || did_action('wp_rocket_upgrade')) { flush_rocket_htaccess(); rocket_renew_all_boxes(0, array('rocket_warning_plugin_modification')); $options = get_option(WP_ROCKET_SLUG); // do not use get_rocket_option() here $options['version'] = WP_ROCKET_VERSION; $keys = rocket_check_key('live'); if (is_array($keys)) { $options = array_merge($keys, $options); } update_option(WP_ROCKET_SLUG, $options); } else { if (empty($_POST) && rocket_valid_key()) { rocket_check_key('transient_30'); } } /** This filter is documented in inc/admin-bar.php */ if (!rocket_valid_key() && current_user_can(apply_filters('rocket_capacity', 'manage_options')) && (!isset($_GET['page']) || 'wprocket' != $_GET['page'])) { add_action('admin_notices', 'rocket_need_api_key'); } }
function rocket_dns_prefetch($buffer) { $dns_link_tags = ''; $cdn_cnames = get_rocket_cdn_cnames(array('all', 'images', 'css_and_js', 'css', 'js')); // Don't add CNAMES if CDN is disabled HTTPS pages or on specific posts if (!is_rocket_cdn_on_ssl() || is_rocket_post_excluded_option('cdn')) { $cdn_cnames = array(); } $domains = array_merge($cdn_cnames, (array) get_rocket_option('dns_prefetch')); /** * Filter list of domains to prefetch DNS * * @since 1.1.0 * * @param array $domains List of domains to prefetch DNS */ $domains = apply_filters('rocket_dns_prefetch', $domains); if (count($domains)) { foreach ($domains as $domain) { $dns_link_tags .= '<link rel="dns-prefetch" href="' . esc_url($domain) . '" />'; } } // Insert all DNS prefecth tags in head $buffer = preg_replace('/<head(.*)>/', '<head$1><!--[if IE]><![endif]-->' . $dns_link_tags, $buffer, 1); return $buffer; }
/** * Constructor */ protected function __construct() { $this->db = IncPopupDatabase::instance(); // Prepare the URL if (!empty($_REQUEST['orig_request_uri'])) { $this->prepare_url(); add_action('init', array($this, 'revert_url'), 999); // prevent 404. add_action('parse_query', array($this, 'prepare_url')); } /* * URLs for the "from" and "referer" fields are transmitted in reversed * format (moc.elpmaxe//:ptth) * Reason for this is that plugins like iThemes security might block * incoming requests that contain the value "http://". This is how * we bypass that security check. */ if (!empty($_REQUEST['thefrom'])) { $_REQUEST['thefrom'] = strrev($_REQUEST['thefrom']); } if (!empty($_REQUEST['thereferrer'])) { $_REQUEST['thereferrer'] = strrev($_REQUEST['thereferrer']); } // http://premium.wpmudev.org/forums/topic/ive-debugged-a-problem-in-the-latest-version-of-the-popup-pro-plugin if (!empty($_GET['thefrom'])) { $_GET['thefrom'] = strrev($_GET['thefrom']); } if (!empty($_GET['thereferrer'])) { $_GET['thereferrer'] = strrev($_GET['thereferrer']); } if (!empty($_POST['thefrom'])) { $_POST['thefrom'] = strrev($_POST['thefrom']); } if (!empty($_POST['thereferrer'])) { $_POST['thereferrer'] = strrev($_POST['thereferrer']); } lib2()->translate_plugin(PO_LANG, PO_LANG_DIR); // Register the popup post type. add_action('init', array('IncPopupPosttype', 'instance'), 99); // Register the popup post type. add_action('wp_loaded', array('IncPopupDatabase', 'check_db')); // Load active add-ons. add_action('init', array('IncPopup', 'load_optional_files')); // Returns a list of all style infos (id, url, path, deprecated) add_filter('popup-styles', array('IncPopupBase', 'style_infos')); // Ajax handlers to load PopUp data (for logged in users). add_action('wp_ajax_inc_popup', array($this, 'ajax_load_popup')); // Ajax handlers to load PopUp data (for guests). add_action('wp_ajax_nopriv_inc_popup', array($this, 'ajax_load_popup')); // Compatibility with plugins add_filter('popup-output-data', array($this, 'compat_init'), 999, 2); if (function_exists('get_rocket_option') && get_rocket_option('minify_js')) { foreach (array('edit-inc_popup', 'inc_popup', 'inc_popup_page_settings') as $screen) { lib2()->ui->admin_message(__('You are using WP Rocket with JS Minification, which has ' . 'caused some issues in the past. We recommend to disable ' . 'the JS Minification setting in WP Rocket to avoid problems.', PO_LANG), 'err', $screen); } } // Tell Add-ons and extensions that we are set up. do_action('popup-init'); }
function __rocket_fix_cdn_for_avada_theme($vars, $handle) { if ($handle == 'avada-dynamic' && get_rocket_option('cdn')) { $src = get_rocket_cdn_url(get_template_directory_uri() . '/assets/less/theme/dynamic.less'); $vars['template-directory'] = sprintf('~"%s"', dirname(dirname(dirname(dirname($src))))); $vars['lessurl'] = sprintf('~"%s"', dirname($src)); } return $vars; }
function rocket_insert_deferred_js($buffer) { // Don't add anything on 404 page or on a page without these query strings if (is_404() || !empty($_GET) && !isset($_GET['utm_source'], $_GET['utm_medium'], $_GET['utm_campaign']) && !isset($_GET['fb_action_ids'], $_GET['fb_action_types'], $_GET['fb_source']) && !isset($_GET['gclid']) && !isset($_GET['permalink_name']) && !isset($_GET['lp-variation-id']) && !isset($_GET['lang'])) { return; } /** * Filter LABjs file URL * * @since 1.1.0 * * @param string LABjs file URL */ $labjs_src = WP_ROCKET_FRONT_JS_URL . 'LAB.' . WP_ROCKET_LAB_JS_VERSION . '.min.js'; $labjs_src = get_rocket_cdn_url($labjs_src, array('all', 'css_js', 'js')); $labjs_src = apply_filters('rocket_labjs_src', $labjs_src); /** * Filter list of LABjs options * * @since 1.1.0 * * @param array List of LABjs options */ $labjs_options = apply_filters('rocket_labjs_options', array('AlwaysPreserveOrder' => true)); /** * Filter list of Deferred JavaScript files waiting to load * * @since 1.1.0 * * @param array List of Deferred JavaScript files waiting to load */ $deferred_js_wait = apply_filters('rocket_minify_deferred_js_wait', get_rocket_option('deferred_js_wait')); $defer = '<script src="' . $labjs_src . '" data-no-minify="1"></script>'; $defer .= '<script>'; $defer .= '$LAB'; // Set LABjs options // All options is available in http://labjs.com/documentation.php#optionsobject if (count($labjs_options)) { $defer .= '.setOptions(' . json_encode($labjs_options) . ')'; } $deferred_js_files = get_rocket_deferred_js_files(); foreach ($deferred_js_files as $k => $js) { $wait = $deferred_js_wait[$k] == '1' ? '.wait(' . esc_js(apply_filters('rocket_labjs_wait_callback', false, $js)) . ')' : ''; $defer .= '.script("' . esc_js($js) . '")' . $wait; } $defer .= ';</script>'; echo $defer; }
/** * Function used to print all hidden fields from rocket to avoid the loss of these. * * @since 2.1 */ function rocket_hidden_fields($fields) { if (!is_array($fields)) { return; } foreach ($fields as $field) { echo '<input type="hidden" name="wp_rocket_settings[' . $field . ']" value="' . esc_attr(get_rocket_option($field)) . '" />'; } }
function rocket_init() { // Load translations load_plugin_textdomain('rocket', false, dirname(plugin_basename(__FILE__)) . '/languages/'); // Nothing to do if autosave if (defined('DOING_AUTOSAVE')) { return; } // Necessary to call correctly WP Rocket Bot for cache json global $do_rocket_bot_cache_json; $do_rocket_bot_cache_json = false; // Call defines, classes and functions require WP_ROCKET_API_PATH . 'cloudflare.php'; require WP_ROCKET_FUNCTIONS_PATH . 'options.php'; // Last constants define('WP_ROCKET_PLUGIN_NAME', get_rocket_option('wl_plugin_name', 'WP Rocket')); define('WP_ROCKET_PLUGIN_SLUG', sanitize_key(WP_ROCKET_PLUGIN_NAME)); // Call defines, classes and functions require WP_ROCKET_FUNCTIONS_PATH . 'files.php'; require WP_ROCKET_FUNCTIONS_PATH . 'posts.php'; require WP_ROCKET_FUNCTIONS_PATH . 'admin.php'; require WP_ROCKET_FUNCTIONS_PATH . 'formatting.php'; require WP_ROCKET_FUNCTIONS_PATH . 'cdn.php'; require WP_ROCKET_FUNCTIONS_PATH . 'minify.php'; require WP_ROCKET_FUNCTIONS_PATH . 'plugins.php'; require WP_ROCKET_FUNCTIONS_PATH . 'i18n.php'; require WP_ROCKET_FUNCTIONS_PATH . 'bots.php'; require WP_ROCKET_FUNCTIONS_PATH . 'cloudflare.php'; require WP_ROCKET_FUNCTIONS_PATH . 'htaccess.php'; require WP_ROCKET_INC_PATH . 'deprecated.php'; require WP_ROCKET_FRONT_PATH . 'hosting-compatibility.php'; require WP_ROCKET_FRONT_PATH . 'plugin-compatibility.php'; require WP_ROCKET_FRONT_PATH . 'theme-compatibility.php'; require WP_ROCKET_COMMON_PATH . 'admin-bar.php'; require dirname(__FILE__) . '/licence-data.php'; if (rocket_valid_key()) { require WP_ROCKET_COMMON_PATH . 'purge.php'; require WP_ROCKET_COMMON_PATH . 'cron.php'; if (0 < (int) get_rocket_option('cdn')) { require WP_ROCKET_FRONT_PATH . 'cdn.php'; } if (0 < (int) get_rocket_option('do_cloudflare')) { require WP_ROCKET_VENDORS_PATH . 'ip_in_range.php'; require WP_ROCKET_COMMON_PATH . 'cloudflare.php'; } if (defined('SUNRISE') && SUNRISE == 'on' && function_exists('domain_mapping_siteurl')) { require WP_ROCKET_INC_PATH . '/domain-mapping.php'; } } if (is_admin()) { require WP_ROCKET_ADMIN_PATH . 'ajax.php'; require WP_ROCKET_ADMIN_PATH . 'upgrader.php'; require WP_ROCKET_ADMIN_PATH . 'updater.php'; require WP_ROCKET_ADMIN_PATH . 'class-repeater-field.php'; require WP_ROCKET_ADMIN_PATH . 'options.php'; require WP_ROCKET_ADMIN_PATH . 'admin.php'; require WP_ROCKET_ADMIN_PATH . 'plugin-compatibility.php'; require WP_ROCKET_ADMIN_UI_PATH . 'enqueue.php'; require WP_ROCKET_ADMIN_UI_PATH . 'notices.php'; require WP_ROCKET_ADMIN_UI_PATH . 'meta-boxes.php'; } else { if (rocket_valid_key()) { require WP_ROCKET_FRONT_PATH . 'minify.php'; require WP_ROCKET_FRONT_PATH . 'cookie.php'; require WP_ROCKET_FRONT_PATH . 'images.php'; require WP_ROCKET_FRONT_PATH . 'enqueue.php'; require WP_ROCKET_FRONT_PATH . 'dns-prefetch.php'; if (get_rocket_option('deferred_js_files')) { require WP_ROCKET_FRONT_PATH . 'deferred-js.php'; } // Don't insert the LazyLoad file if Rocket LazyLoad is activated if (!rocket_is_plugin_active('rocket-lazy-load/rocket-lazy-load.php')) { require WP_ROCKET_FRONT_PATH . 'lazyload.php'; } } } // You can hook this to trigger any action when WP Rocket is correctly loaded, so, not in AUTOSAVE mode if (rocket_valid_key()) { /** * Fires when WP Rocket is correctly loaded * * @since 1.0 */ do_action('wp_rocket_loaded'); } }
static function createPost($new_post, $post_custom, $post_category, $post_featured_image, $upload_dir, $post_tags) { global $current_user; $wprocket_fields = array('lazyload', 'lazyload_iframes', 'minify_html', 'minify_css', 'minify_js', 'cdn'); $wprocket_activated = false; if (MainWP_Child_WP_Rocket::isActivated()) { if (function_exists('get_rocket_option')) { $wprocket_activated = true; foreach ($wprocket_fields as $field) { if (!isset($post_custom['_rocket_exclude_' . $field])) { // check not exclude only if (!get_rocket_option($field)) { $post_custom['_rocket_exclude_' . $field] = array(true); // set as excluded } } } } } if (!$wprocket_activated) { foreach ($wprocket_fields as $field) { if (isset($post_custom['_rocket_exclude_' . $field])) { unset($post_custom['_rocket_exclude_' . $field]); } } } //Set up a new post (adding addition information) $usr = get_user_by('login', $_POST['user']); //$new_post['post_author'] = $current_user->ID; $is_robot_post = false; if (isset($_POST['isMainWPRobot']) && !empty($_POST['isMainWPRobot'])) { $is_robot_post = true; } $post_author = isset($new_post['post_author']) ? $new_post['post_author'] : $usr->ID; if ($is_robot_post) { if (1 === $post_author) { $new_post['post_author'] = $usr->ID; } else { if (!is_numeric($post_author)) { $user_author = get_user_by('login', $post_author); if ($user_author) { $post_author = $user_author->ID; } else { $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false); $post_author = wp_create_user($post_author, $random_password, $post_author . '@asdf.com'); } } } } else { if (isset($new_post['custom_post_author']) && !empty($new_post['custom_post_author'])) { $_author = get_user_by('login', $new_post['custom_post_author']); if (!empty($_author)) { $new_post['post_author'] = $_author->ID; } else { $new_post['post_author'] = $usr->ID; } unset($new_post['custom_post_author']); } } $post_author = !empty($post_author) ? $post_author : $usr->ID; $new_post['post_author'] = $post_author; $is_ezine_post = !empty($post_custom['_ezine_post_article_source']) ? true : false; $terms = $new_post['_ezin_post_category']; unset($new_post['_ezin_post_category']); $is_post_plus = isset($post_custom['_mainwp_post_plus']) ? true : false; $wp_error = null; if ($is_ezine_post || $is_post_plus) { if (isset($new_post['post_date_gmt']) && !empty($new_post['post_date_gmt'])) { $post_date_timestamp = strtotime($new_post['post_date_gmt']) + get_option('gmt_offset') * 60 * 60; $new_post['post_date'] = date('Y-m-d H:i:s', $post_date_timestamp); $new_post['post_status'] = $post_date_timestamp <= current_time('timestamp') ? 'publish' : 'future'; } else { $new_post['post_status'] = 'publish'; } } $wpr_options = isset($_POST['wpr_options']) ? $_POST['wpr_options'] : array(); //Search for all the images added to the new post //some images have a href tag to click to navigate to the image.. we need to replace this too $foundMatches = preg_match_all('/(<a[^>]+href=\\"(.*?)\\"[^>]*>)?(<img[^>\\/]*src=\\"((.*?)(png|gif|jpg|jpeg))\\")/ix', $new_post['post_content'], $matches, PREG_SET_ORDER); if (($foundMatches > 0 || $is_robot_post && isset($wpr_options['wpr_save_images']) && 'Yes' === $wpr_options['wpr_save_images']) && !$is_ezine_post) { //We found images, now to download them so we can start balbal foreach ($matches as $match) { $hrefLink = $match[2]; $imgUrl = $match[4]; if (!isset($upload_dir['baseurl']) || 0 !== strripos($imgUrl, $upload_dir['baseurl'])) { continue; } if (preg_match('/-\\d{3}x\\d{3}\\.[a-zA-Z0-9]{3,4}$/', $imgUrl, $imgMatches)) { $search = $imgMatches[0]; $replace = '.' . $match[6]; $originalImgUrl = str_replace($search, $replace, $imgUrl); } else { $originalImgUrl = $imgUrl; } try { $downloadfile = MainWP_Helper::uploadImage($originalImgUrl); $localUrl = $downloadfile['url']; $linkToReplaceWith = dirname($localUrl); if ('' !== $hrefLink) { $server = get_option('mainwp_child_server'); $serverHost = parse_url($server, PHP_URL_HOST); if (!empty($serverHost) && strpos($hrefLink, $serverHost) !== false) { $serverHref = 'href="' . $serverHost; $replaceServerHref = 'href="' . parse_url($localUrl, PHP_URL_SCHEME) . '://' . parse_url($localUrl, PHP_URL_HOST); $new_post['post_content'] = str_replace($serverHref, $replaceServerHref, $new_post['post_content']); } else { if (strpos($hrefLink, 'http') !== false) { $lnkToReplace = dirname($hrefLink); if ('http:' !== $lnkToReplace && 'https:' !== $lnkToReplace) { $new_post['post_content'] = str_replace($lnkToReplace, $linkToReplaceWith, $new_post['post_content']); } } } } $lnkToReplace = dirname($imgUrl); if ('http:' !== $lnkToReplace && 'https:' !== $lnkToReplace) { $new_post['post_content'] = str_replace($lnkToReplace, $linkToReplaceWith, $new_post['post_content']); } } catch (Exception $e) { } } } if ($is_post_plus) { $random_publish_date = isset($post_custom['_saved_draft_random_publish_date']) ? $post_custom['_saved_draft_random_publish_date'] : false; $random_publish_date = is_array($random_publish_date) ? current($random_publish_date) : null; if (!empty($random_publish_date)) { $random_date_from = isset($post_custom['_saved_draft_publish_date_from']) ? $post_custom['_saved_draft_publish_date_from'] : 0; $random_date_from = is_array($random_date_from) ? current($random_date_from) : 0; $random_date_to = isset($post_custom['_saved_draft_publish_date_to']) ? $post_custom['_saved_draft_publish_date_to'] : 0; $random_date_to = is_array($random_date_to) ? current($random_date_to) : 0; $now = current_time('timestamp'); if (empty($random_date_from)) { $random_date_from = $now; } if (empty($random_date_to)) { $random_date_to = $now; } if ($random_date_from === $now && $random_date_from === $random_date_to) { $random_date_to = $now + 7 * 24 * 3600; } if ($random_date_from > $random_date_to) { $tmp = $random_date_from; $random_date_from = $random_date_to; $random_date_to = $tmp; } $random_timestamp = rand($random_date_from, $random_date_to); $post_status = $random_timestamp <= current_time('timestamp') ? 'publish' : 'future'; $new_post['post_status'] = $post_status; $new_post['post_date'] = date('Y-m-d H:i:s', $random_timestamp); } } if (isset($post_tags) && '' !== $post_tags) { $new_post['tags_input'] = $post_tags; } //Save the post to the wp remove_filter('content_save_pre', 'wp_filter_post_kses'); // to fix brake scripts or html $post_status = $new_post['post_status']; $new_post['post_status'] = 'auto-draft'; $new_post_id = wp_insert_post($new_post, $wp_error); //Show errors if something went wrong if (is_wp_error($wp_error)) { return $wp_error->get_error_message(); } if (empty($new_post_id)) { return 'Undefined error'; } wp_update_post(array('ID' => $new_post_id, 'post_status' => $post_status)); if (!empty($terms)) { wp_set_object_terms($new_post_id, array_map(intval, $terms), 'category'); } $permalink = get_permalink($new_post_id); $seo_ext_activated = false; if (class_exists('WPSEO_Meta') && class_exists('WPSEO_Admin')) { $seo_ext_activated = true; } //Set custom fields $not_allowed = array('_slug', '_tags', '_edit_lock', '_selected_sites', '_selected_groups', '_selected_by', '_categories', '_edit_last', '_sticky'); $not_allowed[] = '_mainwp_boilerplate_sites_posts'; $not_allowed[] = '_ezine_post_keyword'; $not_allowed[] = '_ezine_post_display_sig'; $not_allowed[] = '_ezine_post_remove_link'; $not_allowed[] = '_ezine_post_grab_image'; $not_allowed[] = '_ezine_post_grab_image_placement'; $not_allowed[] = '_ezine_post_template_id'; $not_allowed[] = '_mainwp_post_plus'; $not_allowed[] = '_saved_as_draft'; $not_allowed[] = '_saved_draft_categories'; $not_allowed[] = '_saved_draft_tags'; $not_allowed[] = '_saved_draft_random_privelege'; $not_allowed[] = '_saved_draft_random_category'; $not_allowed[] = '_saved_draft_random_publish_date'; $not_allowed[] = '_saved_draft_publish_date_from'; $not_allowed[] = '_saved_draft_publish_date_to'; $not_allowed[] = '_post_to_only_existing_categories'; $not_allowed[] = '_mainwp_robot_post_comments'; $post_to_only_existing_categories = false; foreach ($post_custom as $meta_key => $meta_values) { if (!in_array($meta_key, $not_allowed)) { foreach ($meta_values as $meta_value) { if (strpos($meta_key, "_mainwp_spinner_") === 0) { continue; } // not save if (!$seo_ext_activated) { // if Wordpress SEO plugin is not activated do not save yoast post meta if (strpos($meta_key, '_yoast_wpseo_') === false) { add_post_meta($new_post_id, $meta_key, $meta_value); } } else { add_post_meta($new_post_id, $meta_key, $meta_value); } } } else { if ('_sticky' === $meta_key) { foreach ($meta_values as $meta_value) { if ('sticky' === base64_decode($meta_value)) { stick_post($new_post_id); } } } else { if ('_post_to_only_existing_categories' === $meta_key) { if (isset($meta_values[0]) && $meta_values[0]) { $post_to_only_existing_categories = true; } } } } } // yoast seo extension if ($seo_ext_activated) { $_seo_opengraph_image = isset($post_custom[WPSEO_Meta::$meta_prefix . 'opengraph-image']) ? $post_custom[WPSEO_Meta::$meta_prefix . 'opengraph-image'] : array(); $_seo_opengraph_image = current($_seo_opengraph_image); $_server_domain = ''; $_server = get_option('mainwp_child_server'); if (preg_match('/(https?:\\/\\/[^\\/]+\\/).+/', $_server, $matchs)) { $_server_domain = isset($matchs[1]) ? $matchs[1] : ''; } // upload image if it on the server if (!empty($_seo_opengraph_image) && strpos($_seo_opengraph_image, $_server_domain) !== false) { try { $upload = MainWP_Helper::uploadImage($_seo_opengraph_image); //Upload image to WP if (null !== $upload) { update_post_meta($new_post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', $upload['url']); //Add the image to the post! } } catch (Exception $e) { } } } //If categories exist, create them (second parameter of wp_create_categories adds the categories to the post) include_once ABSPATH . 'wp-admin/includes/taxonomy.php'; //Contains wp_create_categories if (isset($post_category) && '' !== $post_category) { $categories = explode(',', $post_category); if (count($categories) > 0) { if (!$post_to_only_existing_categories) { $post_category = wp_create_categories($categories, $new_post_id); } else { $cat_ids = array(); foreach ($categories as $cat) { if ($id = category_exists($cat)) { $cat_ids[] = $id; } } if (count($cat_ids) > 0) { wp_set_post_categories($new_post_id, $cat_ids); } } } } //If featured image exists - set it if (null !== $post_featured_image) { try { $upload = MainWP_Helper::uploadImage($post_featured_image); //Upload image to WP if (null !== $upload) { update_post_meta($new_post_id, '_thumbnail_id', $upload['id']); //Add the thumbnail to the post! } } catch (Exception $e) { } } // post plus extension process if ($is_post_plus) { $random_privelege = isset($post_custom['_saved_draft_random_privelege']) ? $post_custom['_saved_draft_random_privelege'] : null; $random_privelege = is_array($random_privelege) ? current($random_privelege) : null; $random_privelege_base = base64_decode($random_privelege); $random_privelege = maybe_unserialize($random_privelege_base); if (is_array($random_privelege) && count($random_privelege) > 0) { $random_post_authors = array(); foreach ($random_privelege as $role) { $users = get_users(array('role' => $role)); foreach ($users as $user) { $random_post_authors[] = $user->ID; } } if (count($random_post_authors) > 0) { shuffle($random_post_authors); $key = array_rand($random_post_authors); wp_update_post(array('ID' => $new_post_id, 'post_author' => $random_post_authors[$key])); } } $random_category = isset($post_custom['_saved_draft_random_category']) ? $post_custom['_saved_draft_random_category'] : false; $random_category = is_array($random_category) ? current($random_category) : null; if (!empty($random_category)) { $cats = get_categories(array('type' => 'post', 'hide_empty' => 0)); $random_cats = array(); if (is_array($cats)) { foreach ($cats as $cat) { $random_cats[] = $cat->term_id; } } if (count($random_cats) > 0) { shuffle($random_cats); $key = array_rand($random_cats); wp_set_post_categories($new_post_id, array($random_cats[$key]), false); } } } // end of post plus // MainWP Robot if ($is_robot_post) { $all_comments = $post_custom['_mainwp_robot_post_comments']; MainWP_Child_Robot::Instance()->wpr_insertcomments($new_post_id, $all_comments); } $ret['success'] = true; $ret['link'] = $permalink; $ret['added_id'] = $new_post_id; return $ret; }
function rocket_lazyload_iframes($html) { // Don't LazyLoad if process is stopped for these reasons if (!get_rocket_option('lazyload_iframes') || !apply_filters('do_rocket_lazyload_iframes', true) || is_feed() || is_preview() || empty($html) || defined('DONOTLAZYLOAD') && DONOTLAZYLOAD) { return $html; } $matches = array(); preg_match_all('/<iframe\\s+.*?>/', $html, $matches); foreach ($matches[0] as $k => $iframe) { // Don't mess with the Gravity Forms ajax iframe if (strpos($iframe, 'gform_ajax_frame')) { continue; } /** This filter is documented in inc/front/lazyload.php */ $placeholder = apply_filters('rocket_lazyload_placeholder', 'data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs='); $iframe = preg_replace('/<iframe(.*?)src=/is', '<iframe$1src="' . $placeholder . '" data-lazy-src=', $iframe); $html = str_replace($matches[0][$k], $iframe, $html); /** * Filter the LazyLoad HTML output on iframes * * @since 2.6 * * @param array $html Output that will be printed */ $html = apply_filters('rocket_lazyload_iframe_html', $html); } return $html; }
function rocket_clean_post($post_id) { if (defined('DOING_AUTOSAVE')) { return; } $purge_urls = array(); // Get all post infos $post = get_post($post_id); // No purge for specifics conditions if ($post->post_status == 'auto-draft' || empty($post->post_type) || $post->post_type == 'nav_menu_item') { return; } // Get the permalink structure $permalink_structure = get_rocket_sample_permalink($post_id); // Get permalink $permalink = str_replace(array('%postname%', '%pagename%'), $permalink_structure[1], $permalink_structure[0]); // Add permalink if (parse_url($permalink, PHP_URL_PATH) != '/') { array_push($purge_urls, $permalink); } // Add Posts page if ($post->post_type == 'post' && (int) get_option('page_for_posts') > 0) { array_push($purge_urls, get_permalink(get_option('page_for_posts'))); } // Add Post Type archive $post_type_archive = get_post_type_archive_link(get_post_type($post_id)); if ($post_type_archive) { array_push($purge_urls, $post_type_archive); } // Add next post $next_post = get_adjacent_post(false, '', false); if ($next_post) { array_push($purge_urls, get_permalink($next_post)); } // Add next post in same category $next_in_same_cat_post = get_adjacent_post(true, '', false); if ($next_in_same_cat_post && $next_in_same_cat_post != $next_post) { array_push($purge_urls, get_permalink($next_in_same_cat_post)); } // Add previous post $previous_post = get_adjacent_post(false, '', true); if ($previous_post) { array_push($purge_urls, get_permalink($previous_post)); } // Add previous post in same category $previous_in_same_cat_post = get_adjacent_post(true, '', true); if ($previous_in_same_cat_post && $previous_in_same_cat_post != $previous_post) { array_push($purge_urls, get_permalink($previous_in_same_cat_post)); } // Add urls page to purge every time a post is save $cache_purge_pages = get_rocket_option('cache_purge_pages'); if ($cache_purge_pages) { foreach ($cache_purge_pages as $page) { array_push($purge_urls, home_url($page)); } } // Add all terms archive page to purge $purge_terms = get_rocket_post_terms_urls($post_id); if (count($purge_terms)) { $purge_urls = array_merge($purge_urls, $purge_terms); } // Add all dates archive page to purge $purge_dates = get_rocket_post_dates_urls($post_id); if (count($purge_dates)) { $purge_urls = array_merge($purge_urls, $purge_dates); } // Add the author page $purge_author = array(get_author_posts_url($post->post_author)); $purge_urls = array_merge($purge_urls, $purge_author); /** * Fires before cache files related with the post are deleted * * @since 1.3.0 * @param obj $post The post object * @param array $purge_urls URLs cache files to remove */ do_action('before_rocket_clean_post', $post, $purge_urls); /** * Filter URLs cache files to remove * * @since 1.0 * @param array $purge_urls List of URLs cache files to remove */ $purge_urls = apply_filters('rocket_post_purge_urls', $purge_urls); // Purge all files rocket_clean_files($purge_urls); // Never forget to purge homepage and their pagination $lang = false; // WPML if (rocket_is_plugin_active('sitepress-multilingual-cms/sitepress.php')) { $lang = $GLOBALS['sitepress']->get_language_for_element($post_id, 'post_' . get_post_type($post_id)); // Polylang } else { if (rocket_is_plugin_active('polylang/polylang.php')) { $lang = $GLOBALS['polylang']->model->get_post_language($post_id)->slug; } } rocket_clean_home($lang); // Purge all parents $parents = get_post_ancestors($post_id); if (count($parents)) { foreach ($parents as $parent_id) { rocket_clean_post($parent_id); } } /** * Fires after cache files related with the post are deleted * * @since 1.3.0 * @param obj $post The post object * @param array $purge_urls URLs cache files to remove */ do_action('after_rocket_clean_post', $post, $purge_urls); }
/** * Display the repeater field. * * @since 2.2 * @access public * */ public function render() { ?> <fieldset> <?php $this->the_label_screen(); ?> <div id="rkt-drop-<?php echo $this->option; ?> " class="rkt-module rkt-module-drop"> <?php $_option = get_rocket_option($this->option); if ($_option) { foreach ($_option as $key => $value) { $this->the_field($key, $value, true); } // If no values yet, use this template inside } else { $this->the_field(0, '', false); } ?> </div> <?php // Clone Template ?> <div class="rkt-module-model hide-if-js"> <?php $this->the_field(); ?> </div> <p><a href="javascript:void(0)" class="rkt-module-clone hide-if-no-js button-secondary"><?php echo $this->label_add_field; ?> </a></p> </fieldset> <?php }
function __rocket_extract_js_files_from_footer() { global $rocket_enqueue_js_in_footer, $wp_scripts, $pagenow; /** This filter is documented in inc/front/process.php */ $rocket_cache_search = apply_filters('rocket_cache_search', false); if (isset($wp_scripts->in_footer) && !is_array($wp_scripts->in_footer) || !get_rocket_option('minify_js', false) || in_array($pagenow, array('wp-login.php', 'wp-register.php')) || defined('DONOTMINIFYJS') && DONOTMINIFYJS || defined('DONOTCACHEPAGE') && DONOTCACHEPAGE || is_rocket_post_excluded_option('minify_js') || is_404() || is_search() && !$rocket_cache_search) { return; } // Digg Digg (https://wordpress.org/plugins/digg-digg/) if (defined('DD_PLUGIN_URL')) { $rocket_enqueue_js_in_footer[] = DD_PLUGIN_URL . '/js/diggdigg-floating-bar.js'; } // nrelate Flyout (https://wordpress.org/plugins/nrelate-flyout/) if (defined('NRELATE_PLUGIN_VERSION')) { $rocket_enqueue_js_in_footer[] = NRELATE_JS_DEBUG ? 'http://staticrepo.nrelate.com/common_wp/' . NRELATE_PLUGIN_VERSION . '/nrelate_js.js' : NRELATE_ADMIN_URL . '/nrelate_js.min.js'; } $home_host = parse_url(home_url(), PHP_URL_HOST); $deferred_js_files = get_rocket_deferred_js_files(); $excluded_js = get_rocket_exclude_js(); $excluded_external_js = get_rocket_minify_excluded_external_js(); foreach ($wp_scripts->in_footer as $handle) { $script_src = $wp_scripts->registered[$handle]->src; $script_src = strstr($script_src, '/wp-includes/js/') ? $wp_scripts->base_url . $script_src : $script_src; $script_src_cleaned = str_replace(array('http:', 'https:', '//' . $home_host), '', $script_src); if (in_array($handle, $wp_scripts->queue) && !in_array(parse_url($script_src, PHP_URL_HOST), $excluded_external_js) && !in_array($script_src, $deferred_js_files) && !in_array(parse_url($script_src, PHP_URL_PATH), $excluded_js) && !in_array(parse_url($script_src_cleaned, PHP_URL_PATH), $excluded_js)) { // Dequeue JS files without extension if (pathinfo($script_src, PATHINFO_EXTENSION) == '') { wp_dequeue_script($handle); } // Add protocol on external JS to prevent conflict if ($home_host != parse_url($script_src, PHP_URL_HOST) && strpos($script_src, 'http://') === false && strpos($script_src, 'https://') === false) { $script_src = set_url_scheme($script_src); } // Add dependency enqueued in the footer foreach ($wp_scripts->registered[$handle]->deps as $handle_dep) { if (in_array($handle_dep, $wp_scripts->in_footer)) { $src = $wp_scripts->registered[$handle_dep]->src; $src = strstr($src, '/wp-includes/js/') ? $wp_scripts->base_url . $src : $src; $rocket_enqueue_js_in_footer[$handle_dep] = rocket_set_internal_url_scheme($src); } } $rocket_enqueue_js_in_footer[$handle] = rocket_set_internal_url_scheme($script_src); } } }
/** * Determine if the key is valid * * @since 2.2 The function do the live check and update the option */ function rocket_check_key($type = 'transient_1', $data = null) { // Recheck the license $return = rocket_valid_key(); if (!rocket_valid_key() || 'transient_1' == $type && !get_transient('rocket_check_licence_1') || 'transient_30' == $type && !get_transient('rocket_check_licence_30') || 'live' == $type) { $response = wp_remote_get(WP_ROCKET_WEB_VALID, array('timeout' => 30)); $json = !is_wp_error($response) ? json_decode($response['body']) : false; $rocket_options = array(); if ($json) { $rocket_options['consumer_key'] = $json->data->consumer_key; $rocket_options['consumer_email'] = $json->data->consumer_email; if ($json->success) { $rocket_options['secret_key'] = $json->data->secret_key; if (!get_rocket_option('license')) { $rocket_options['license'] = '1'; } if ('live' != $type) { if ('transient_1' == $type) { set_transient('rocket_check_licence_1', true, DAY_IN_SECONDS); } elseif ('transient_30' == $type) { set_transient('rocket_check_licence_30', true, DAY_IN_SECONDS * 30); } } } else { $messages = array('BAD_LICENSE' => __('Your license is not valid.', 'rocket'), 'BAD_NUMBER' => __('You cannot add more websites. Upgrade your account.', 'rocket'), 'BAD_SITE' => __('This website is not allowed.', 'rocket'), 'BAD_KEY' => __('This license key is not accepted.', 'rocket')); $rocket_options['secret_key'] = ''; add_settings_error('general', 'settings_updated', $messages[$json->data->reason], 'error'); } set_transient(WP_ROCKET_SLUG, $rocket_options); $return = (array) $rocket_options; } } return $return; }
function __rocket_rollback() { if (!isset($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'], 'rocket_rollback')) { wp_nonce_ays(''); } $plugin_transient = get_site_transient('update_plugins'); $plugin_folder = plugin_basename(dirname(WP_ROCKET_FILE)); $plugin_file = basename(WP_ROCKET_FILE); $version = WP_ROCKET_LASTVERSION; $c_key = get_rocket_option('consumer_key'); $url = sprintf('http://support.wp-rocket.me/%s/wp-rocket_%s.zip', $c_key, $version); $temp_array = array('slug' => $plugin_folder, 'new_version' => $version, 'url' => 'http://wp-rocket.me', 'package' => $url); $temp_object = (object) $temp_array; $plugin_transient->response[$plugin_folder . '/' . $plugin_file] = $temp_object; set_site_transient('update_plugins', $plugin_transient); $c_key = get_rocket_option('consumer_key'); $transient = get_transient('rocket_warning_rollback'); if (false == $transient) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $title = sprintf(__('%s Update Rollback', 'rocket'), WP_ROCKET_PLUGIN_NAME); $plugin = 'wp-rocket/wp-rocket.php'; $nonce = 'upgrade-plugin_' . $plugin; $url = 'update.php?action=upgrade-plugin&plugin=' . urlencode($plugin); $upgrader_skin = new Plugin_Upgrader_Skin(compact('title', 'nonce', 'url', 'plugin')); $upgrader = new Plugin_Upgrader($upgrader_skin); $upgrader->upgrade($plugin); wp_die('', sprintf(__('%s Update Rollback', 'rocket'), WP_ROCKET_PLUGIN_NAME), array('response' => 200)); } }
function rocket_purge_cron_scheduled() { if (0 < (int) get_rocket_option('purge_cron_interval') && !wp_next_scheduled('rocket_purge_time_event')) { wp_schedule_event(time() + get_rocket_purge_cron_interval(), 'rocket_purge', 'rocket_purge_time_event'); } }
/** * Used to clean and sanitize the settings fields * * @since 1.0 */ function rocket_settings_callback($inputs) { if (isset($_GET['action']) && 'purge_cache' == $_GET['action']) { return $inputs; } /* * Option : Minification CSS & JS */ $inputs['minify_css'] = !empty($inputs['minify_css']) ? 1 : 0; $inputs['minify_js'] = !empty($inputs['minify_js']) ? 1 : 0; /* * Option : Purge delay */ $inputs['purge_cron_interval'] = isset($inputs['purge_cron_interval']) ? (int) $inputs['purge_cron_interval'] : get_rocket_option('purge_cron_interval'); $inputs['purge_cron_unit'] = isset($inputs['purge_cron_unit']) ? $inputs['purge_cron_unit'] : get_rocket_option('purge_cron_unit'); /* * Option : Prefetch DNS requests */ if (!empty($inputs['dns_prefetch'])) { if (!is_array($inputs['dns_prefetch'])) { $inputs['dns_prefetch'] = explode("\n", $inputs['dns_prefetch']); } $inputs['dns_prefetch'] = array_map('trim', $inputs['dns_prefetch']); $inputs['dns_prefetch'] = array_map('esc_url', $inputs['dns_prefetch']); $inputs['dns_prefetch'] = (array) array_filter($inputs['dns_prefetch']); $inputs['dns_prefetch'] = array_unique($inputs['dns_prefetch']); } else { $inputs['dns_prefetch'] = array(); } /* * Option : Empty the cache of the following pages when updating an article */ if (!empty($inputs['cache_purge_pages'])) { if (!is_array($inputs['cache_purge_pages'])) { $inputs['cache_purge_pages'] = explode("\n", $inputs['cache_purge_pages']); } $inputs['cache_purge_pages'] = array_map('trim', $inputs['cache_purge_pages']); $inputs['cache_purge_pages'] = array_map('esc_url', $inputs['cache_purge_pages']); $inputs['cache_purge_pages'] = array_map('rocket_clean_exclude_file', $inputs['cache_purge_pages']); $inputs['cache_purge_pages'] = (array) array_filter($inputs['cache_purge_pages']); $inputs['cache_purge_pages'] = array_unique($inputs['cache_purge_pages']); } else { $inputs['cache_purge_pages'] = array(); } /* * Option : Never cache the following pages */ if (!empty($inputs['cache_reject_uri'])) { if (!is_array($inputs['cache_reject_uri'])) { $inputs['cache_reject_uri'] = explode("\n", $inputs['cache_reject_uri']); } $inputs['cache_reject_uri'] = array_map('trim', $inputs['cache_reject_uri']); $inputs['cache_reject_uri'] = array_map('esc_url', $inputs['cache_reject_uri']); $inputs['cache_reject_uri'] = array_map('rocket_clean_exclude_file', $inputs['cache_reject_uri']); $inputs['cache_reject_uri'] = (array) array_filter($inputs['cache_reject_uri']); $inputs['cache_reject_uri'] = array_unique($inputs['cache_reject_uri']); } else { $inputs['cache_reject_uri'] = array(); } /* * Option : Don't cache pages that use the following cookies */ if (!empty($inputs['cache_reject_cookies'])) { if (!is_array($inputs['cache_reject_cookies'])) { $inputs['cache_reject_cookies'] = explode("\n", $inputs['cache_reject_cookies']); } $inputs['cache_reject_cookies'] = array_map('trim', $inputs['cache_reject_cookies']); $inputs['cache_reject_cookies'] = array_map('rocket_sanitize_cookie', $inputs['cache_reject_cookies']); $inputs['cache_reject_cookies'] = (array) array_filter($inputs['cache_reject_cookies']); $inputs['cache_reject_cookies'] = array_unique($inputs['cache_reject_cookies']); } else { $inputs['cache_reject_cookies'] = array(); } /* * Option : Cache pages that use the following query strings (GET parameters) */ if (!empty($inputs['cache_query_strings'])) { if (!is_array($inputs['cache_query_strings'])) { $inputs['cache_query_strings'] = explode("\n", $inputs['cache_query_strings']); } $inputs['cache_query_strings'] = array_map('trim', $inputs['cache_query_strings']); $inputs['cache_query_strings'] = array_map('sanitize_key', $inputs['cache_query_strings']); $inputs['cache_query_strings'] = (array) array_filter($inputs['cache_query_strings']); $inputs['cache_query_strings'] = array_unique($inputs['cache_query_strings']); } else { $inputs['cache_query_strings'] = array(); } /* * Option : Never send cache pages for these user agents */ if (!empty($inputs['cache_reject_ua'])) { if (!is_array($inputs['cache_reject_ua'])) { $inputs['cache_reject_ua'] = explode("\n", $inputs['cache_reject_ua']); } $inputs['cache_reject_ua'] = array_map('trim', $inputs['cache_reject_ua']); $inputs['cache_reject_ua'] = array_map('rocket_sanitize_ua', $inputs['cache_reject_ua']); $inputs['cache_reject_ua'] = (array) array_filter($inputs['cache_reject_ua']); $inputs['cache_reject_ua'] = array_unique($inputs['cache_reject_ua']); } else { $inputs['cache_reject_ua'] = array(); } /* * Option : CSS files to exclude of the minification */ if (!empty($inputs['exclude_css'])) { if (!is_array($inputs['exclude_css'])) { $inputs['exclude_css'] = explode("\n", $inputs['exclude_css']); } $inputs['exclude_css'] = array_map('trim', $inputs['exclude_css']); $inputs['exclude_css'] = array_map('rocket_clean_exclude_file', $inputs['exclude_css']); $inputs['exclude_css'] = array_map('rocket_sanitize_css', $inputs['exclude_css']); $inputs['exclude_css'] = (array) array_filter($inputs['exclude_css']); $inputs['exclude_css'] = array_unique($inputs['exclude_css']); } else { $inputs['exclude_css'] = array(); } /* * Option : JS files to exclude of the minification */ if (!empty($inputs['exclude_js'])) { if (!is_array($inputs['exclude_js'])) { $inputs['exclude_js'] = explode("\n", $inputs['exclude_js']); } $inputs['exclude_js'] = array_map('trim', $inputs['exclude_js']); $inputs['exclude_js'] = array_map('rocket_clean_exclude_file', $inputs['exclude_js']); $inputs['exclude_js'] = array_map('rocket_sanitize_js', $inputs['exclude_js']); $inputs['exclude_js'] = (array) array_filter($inputs['exclude_js']); $inputs['exclude_js'] = array_unique($inputs['exclude_js']); } else { $inputs['exclude_js'] = array(); } /* * Option : JS files with deferred loading */ if (!empty($inputs['deferred_js_files'])) { $inputs['deferred_js_files'] = array_unique($inputs['deferred_js_files']); $inputs['deferred_js_files'] = array_map('rocket_sanitize_js', $inputs['deferred_js_files']); $inputs['deferred_js_files'] = array_filter($inputs['deferred_js_files']); } else { $inputs['deferred_js_files'] = array(); } if (!$inputs['deferred_js_files']) { $inputs['deferred_js_wait'] = array(); } else { for ($i = 0; $i <= max(array_keys($inputs['deferred_js_files'])); $i++) { if (!isset($inputs['deferred_js_files'][$i])) { unset($inputs['deferred_js_wait'][$i]); } else { $inputs['deferred_js_wait'][$i] = isset($inputs['deferred_js_wait'][$i]) ? '1' : '0'; } } $inputs['deferred_js_files'] = array_values($inputs['deferred_js_files']); ksort($inputs['deferred_js_wait']); $inputs['deferred_js_wait'] = array_values($inputs['deferred_js_wait']); } /* * Option : JS files of the minification to insert in footer */ if (!empty($inputs['minify_js_in_footer'])) { foreach ($inputs['minify_js_in_footer'] as $k => $url) { if (in_array($url, $inputs['deferred_js_files'])) { unset($inputs['minify_js_in_footer'][$k]); } } $inputs['minify_js_in_footer'] = array_filter(array_map('rocket_sanitize_js', array_unique($inputs['minify_js_in_footer']))); } else { $inputs['minify_js_in_footer'] = array(); } /* * Option : WL */ $inputs['wl_plugin_name'] = isset($inputs['wl_plugin_name']) ? wp_strip_all_tags($inputs['wl_plugin_name']) : get_rocket_option('wl_plugin_name'); $inputs['wl_plugin_URI'] = isset($inputs['wl_plugin_URI']) ? esc_url($inputs['wl_plugin_URI']) : get_rocket_option('wl_plugin_URI'); $inputs['wl_author'] = isset($inputs['wl_author']) ? wp_strip_all_tags($inputs['wl_author']) : get_rocket_option('wl_author'); $inputs['wl_author_URI'] = isset($inputs['wl_author_URI']) ? esc_url($inputs['wl_author_URI']) : get_rocket_option('wl_author_URI'); $inputs['wl_description'] = isset($inputs['wl_description']) ? (array) $inputs['wl_description'] : get_rocket_option('wl_description'); $inputs['wl_plugin_slug'] = sanitize_key($inputs['wl_plugin_name']); /* * Option : CDN */ $inputs['cdn_cnames'] = isset($inputs['cdn_cnames']) ? array_unique(array_filter($inputs['cdn_cnames'])) : array(); if (!$inputs['cdn_cnames']) { $inputs['cdn_zone'] = array(); } else { for ($i = 0; $i <= max(array_keys($inputs['cdn_cnames'])); $i++) { if (!isset($inputs['cdn_cnames'][$i])) { unset($inputs['cdn_zone'][$i]); } else { $inputs['cdn_zone'][$i] = isset($inputs['cdn_zone'][$i]) ? $inputs['cdn_zone'][$i] : 'all'; } } $inputs['cdn_cnames'] = array_values($inputs['cdn_cnames']); ksort($inputs['cdn_zone']); $inputs['cdn_zone'] = array_values($inputs['cdn_zone']); } /* * Option : Files to exclude of the CDN process */ if (!empty($inputs['cdn_reject_files'])) { if (!is_array($inputs['cdn_reject_files'])) { $inputs['cdn_reject_files'] = explode("\n", $inputs['cdn_reject_files']); } $inputs['cdn_reject_files'] = array_map('trim', $inputs['cdn_reject_files']); $inputs['cdn_reject_files'] = array_map('rocket_clean_exclude_file', $inputs['cdn_reject_files']); $inputs['cdn_reject_files'] = (array) array_filter($inputs['cdn_reject_files']); $inputs['cdn_reject_files'] = array_unique($inputs['cdn_reject_files']); } else { $inputs['cdn_reject_files'] = array(); } /* * Option: Support */ $fake_options = array('support_summary', 'support_description', 'support_documentation_validation'); foreach ($fake_options as $option) { if (isset($inputs[$option])) { unset($inputs[$option]); } } if (isset($_FILES['import']) && preg_match('/wp-rocket-settings-20\\d{2}-\\d{2}-\\d{2}-[a-f0-9]{13}\\.txt/', $_FILES['import']['name']) && 'text/plain' == $_FILES['import']['type']) { $file_name = $_FILES['import']['name']; $_POST_action = $_POST['action']; $_POST['action'] = 'wp_handle_sideload'; $file = wp_handle_sideload($_FILES['import'], array('mimes' => array('txt' => 'text/plain'))); $_POST['action'] = $_POST_action; $gz = 'gz' . strrev('etalfni'); $settings = @file_get_contents($file['file']); $settings = $gz($settings); $settings = unserialize($settings); file_put_contents($file['file'], ''); @unlink($file['file']); if (is_array($settings)) { $settings['consumer_key'] = $inputs['consumer_key']; $settings['consumer_email'] = $inputs['consumer_email']; $settings['secret_key'] = $inputs['secret_key']; $settings['secret_cache_key'] = $inputs['secret_cache_key']; $settings['minify_css_key'] = $inputs['minify_css_key']; $settings['minify_js_key'] = $inputs['minify_js_key']; $settings['version'] = $inputs['version']; $inputs = $settings; add_settings_error('general', 'settings_updated', __('Settings imported and saved.', 'rocket'), 'updated'); } } if (!rocket_valid_key()) { $checked = rocket_check_key('live'); } else { $checked = rocket_check_key('transient_1'); } if (is_array($checked)) { $inputs['consumer_key'] = $checked['consumer_key']; $inputs['consumer_email'] = $checked['consumer_email']; $inputs['secret_key'] = $checked['secret_key']; } if (rocket_valid_key() && !empty($inputs['secret_key']) && !isset($inputs['ignore'])) { unset($inputs['ignore']); add_settings_error('general', 'settings_updated', __('Settings saved.', 'rocket'), 'updated'); } return $inputs; }
function rocket_force_info_result($res, $action, $args) { if ('plugin_information' == $action && isset($args->slug) && 'wp-rocket' == $args->slug && isset($res->external) && $res->external) { $request = wp_remote_post(WP_ROCKET_WEB_INFO, array('timeout' => 30, 'action' => 'plugin_information', 'request' => serialize($args))); if (is_wp_error($request)) { $res = new WP_Error('plugins_api_failed', sprintf(__('An unexpected error occurred. Something may be wrong with WP-Rocket.me or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.', 'rocket'), WP_ROCKET_WEB_SUPPORT), $request->get_error_message()); } else { $res = maybe_unserialize(wp_remote_retrieve_body($request)); if (!is_object($res) && !is_array($res)) { $res = new WP_Error('plugins_api_failed', sprintf(__('An unexpected error occurred. Something may be wrong with WP-Rocket.me or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.', 'rocket'), WP_ROCKET_WEB_SUPPORT), wp_remote_retrieve_body($request)); } } if (!is_wp_error($res) && rocket_is_white_label()) { $res = (array) $res; $res['name'] = get_rocket_option('wl_plugin_name'); $res['slug'] = sanitize_key($res['name']); $res['author'] = get_rocket_option('wl_author'); $res['homepage'] = get_rocket_option('wl_author_URI'); $res['wl_plugin_URI'] = get_rocket_option('wl_plugin_URI'); $res['author_profile'] = get_rocket_option('wl_author_URI'); $res['sections']['changelog'] = str_replace(array('wp-rocket', 'rocket_'), array($res['slug'], $res['slug'] . '_'), $res['sections']['changelog']); $res['sections']['changelog'] = str_replace(array('WP Rocket', 'WP Rocket', 'WP-Rocket'), $res['name'], $res['sections']['changelog']); $res['sections']['description'] = implode("\n", get_rocket_option('wl_description')); unset($res['sections']['installation'], $res['sections']['faq'], $res['contributors']); $res = (object) $res; } } return $res; }
/** * Generates the configuration file for the current domain based on the values of options * * @since 2.0 * * @return array Names of all config files & The content that will be printed */ function get_rocket_config_file() { $options = get_option(WP_ROCKET_SLUG); if (!$options) { return; } $buffer = '<?php' . "\n"; $buffer .= 'defined( \'ABSPATH\' ) or die( \'Cheatin\\\' uh?\' );' . "\n\n"; if (apply_filters('rocket_override_min_documentRoot', false)) { $buffer .= '$min_documentRoot = \'' . ABSPATH . '\';' . "\n"; } $buffer .= '$rocket_cookie_hash = \'' . COOKIEHASH . '\'' . ";\n"; foreach ($options as $option => $value) { if ($option == 'cache_ssl' || $option == 'cache_mobile' || $option == 'secret_cache_key') { $buffer .= '$rocket_' . $option . ' = \'' . $value . '\';' . "\n"; } if ($option == 'cache_reject_uri') { $buffer .= '$rocket_' . $option . ' = \'' . get_rocket_cache_reject_uri() . '\';' . "\n"; } if ($option == 'cache_query_strings') { $buffer .= '$rocket_' . $option . ' = ' . var_export(get_rocket_cache_query_string(), true) . ';' . "\n"; } if ($option == 'cache_reject_cookies') { $cookies = get_rocket_cache_reject_cookies(); if (get_rocket_option('cache_logged_user')) { $logged_in_cookie = str_replace(COOKIEHASH, '', LOGGED_IN_COOKIE); $cookies = str_replace($logged_in_cookie . '|', '', $cookies); $cookies = trim($cookies, '|'); } $buffer .= '$rocket_' . $option . ' = \'' . $cookies . '\';' . "\n"; } if ($option == 'cache_reject_ua') { $buffer .= '$rocket_' . $option . ' = \'' . get_rocket_cache_reject_ua() . '\';' . "\n"; } } /** This filter is documented in inc/front/htaccess.php */ if (apply_filters('rocket_url_no_dots', false)) { $buffer .= '$rocket_url_no_dots = \'1\';'; } $config_files_path = array(); $urls = array(home_url()); // Check if a translation plugin is activated and this configuration is in subdomain if ($subdomains = get_rocket_i18n_subdomains()) { $urls = $subdomains; } foreach ($urls as $url) { list($host, $path) = get_rocket_parse_url(rtrim($url, '/')); if (!isset($path)) { $config_files_path[] = WP_ROCKET_CONFIG_PATH . strtolower($host) . '.php'; } else { $config_files_path[] = WP_ROCKET_CONFIG_PATH . strtolower($host) . str_replace('/', '.', rtrim($path, '/')) . '.php'; } } /** * Filter the content of all config files * * @since 2.1 * * @param string $buffer The content that will be printed * @param array $config_files_path Names of all config files */ $buffer = apply_filters('rocket_config_file', $buffer, $config_files_path); return array($config_files_path, $buffer); }
/** * Get tag of a group of files or JS minified CSS * * @since 2.1 * * @param array $files List of files to minify (CSS or JS) * @param bool $force_pretty_url (default: true) * @param string $pretty_filename (default: null) The new filename if $force_pretty_url set to true * @return string $tags */ function get_rocket_minify_files($files, $force_pretty_url = true, $pretty_filename = null) { // Get the internal CSS Files // To avoid conflicts with file URLs are too long for browsers, // cut into several parts concatenated files $tags = ''; $data_attr = 'data-minify="1"'; $urls = array(0 => ''); $base_url = WP_ROCKET_URL . 'min/?f='; $files = is_array($files) ? $files : (array) $files; if (count($files)) { $i = 0; foreach ($files as $file) { $file = parse_url($file, PHP_URL_PATH); // Replace "//" by "/" because it cause an issue with Google Code Minify! $file = str_replace('//', '/', $file); /** * Filter the total number of files generated by the minification * * @since 2.1 * * @param string The maximum number of characters in a URL * @param string The file's extension */ $filename_length = apply_filters('rocket_minify_filename_length', 255, pathinfo($file, PATHINFO_EXTENSION)); // +1 : we count the extra comma if (strlen($urls[$i] . $base_url . $file) + 1 >= $filename_length) { $i++; } /** * Filter file to add in minification process * * @since 2.4 * * @param string $file The file path */ $file = apply_filters('rocket_pre_minify_path', $file); $urls[$i] .= $file . ','; } foreach ($urls as $url) { $url = $base_url . rtrim($url, ','); $ext = pathinfo($url, PATHINFO_EXTENSION); if ($force_pretty_url && (defined('SCRIPT_DEBUG') && !SCRIPT_DEBUG)) { /** * Filter the minify URL * * If true returns, * the minify URL like example.com/wp-content/plugins/wp-rocket/min/?f=... * * @since 2.1 * * @param bool */ if (!apply_filters('rocket_minify_debug', false)) { $blog_id = get_current_blog_id(); $pretty_url = !$pretty_filename ? WP_ROCKET_MINIFY_CACHE_URL . $blog_id . '/' . md5($url . get_rocket_option('minify_' . $ext . '_key', create_rocket_uniqid())) . '.' . $ext : WP_ROCKET_MINIFY_CACHE_URL . $blog_id . '/' . $pretty_filename . '.' . $ext; /** * Filter the pretty minify URL * * @since 2.1 * * @param string $pretty_url * @param string $pretty_filename */ $pretty_url = apply_filters('rocket_minify_pretty_url', $pretty_url, $pretty_filename); $url = rocket_fetch_and_cache_minify($url, $pretty_url) ? $pretty_url : $url; } } // If CSS & JS use a CDN $url = get_rocket_cdn_url($url, array('all', 'css_and_js', $ext)); if ($ext == 'css') { /** * Filter CSS file URL with CDN hostname * * @since 2.1 * * @param string $url */ $url = apply_filters('rocket_css_url', $url); $tags .= sprintf('<link rel="stylesheet" href="%s" %s/>', esc_attr($url), $data_attr); } elseif ($ext == 'js') { /** * Filter JavaScript file URL with CDN hostname * * @since 2.1 * * @param string $url */ $url = apply_filters('rocket_js_url', $url); $tags .= sprintf('<script src="%s" %s></script>', esc_attr($url), $data_attr); } } } return $tags; }
function __rocket_save_metabox_options() { if (current_user_can(apply_filters('rocket_capacity', 'manage_options')) && isset($_POST['post_ID'], $_POST['rocket_post_exclude_hidden'], $_POST['_rocketnonce'])) { check_admin_referer('rocket_box_option', '_rocketnonce'); $fields = array('lazyload', 'lazyload_iframes', 'minify_html', 'minify_css', 'minify_js', 'cdn'); foreach ($fields as $field) { if (isset($_POST['rocket_post_exclude_hidden'][$field]) && $_POST['rocket_post_exclude_hidden'][$field]) { if (isset($_POST['rocket_post_exclude'][$field])) { delete_post_meta($_POST['post_ID'], '_rocket_exclude_' . $field); } else { if (get_rocket_option($field)) { update_post_meta($_POST['post_ID'], '_rocket_exclude_' . $field, true); } } } } } }
/** * Purge CloudFlare cache. * * @since 2.5 * * @return void */ function rocket_purge_cloudflare() { if (!is_object($GLOBALS['rocket_cloudflare'])) { return false; } $domain = get_rocket_option('cloudflare_domain'); $GLOBALS['rocket_cloudflare']->fpurge_ts($domain); }
/** * Rules to Cross-origin fonts sharing when CDN is used * * @since 2.4 * * @return string $rules Rules that will be printed */ function get_rocket_htaccess_web_fonts_access() { if (false === get_rocket_option('cdn', false)) { return; } $rules = '# Send CORS headers if browsers request them; enabled by default for images.' . PHP_EOL; $rules .= '<IfModule mod_setenvif.c>' . PHP_EOL; $rules .= '<IfModule mod_headers.c>' . PHP_EOL; $rules .= '# mod_headers, y u no match by Content-Type?!' . PHP_EOL; $rules .= '<FilesMatch "\\.(cur|gif|png|jpe?g|svgz?|ico|webp)$">' . PHP_EOL; $rules .= 'SetEnvIf Origin ":" IS_CORS' . PHP_EOL; $rules .= 'Header set Access-Control-Allow-Origin "*" env=IS_CORS' . PHP_EOL; $rules .= '</FilesMatch>' . PHP_EOL; $rules .= '</IfModule>' . PHP_EOL; $rules .= '</IfModule>' . PHP_EOL . PHP_EOL; $rules .= '# Allow access to web fonts from all domains.' . PHP_EOL; $rules .= '<FilesMatch "\\.(eot|otf|tt[cf]|woff2?)$">' . PHP_EOL; $rules .= '<IfModule mod_headers.c>' . PHP_EOL; $rules .= 'Header set Access-Control-Allow-Origin "*"' . PHP_EOL; $rules .= '</IfModule>' . PHP_EOL; $rules .= '</FilesMatch>' . PHP_EOL . PHP_EOL; /** * Filter rules to Cross-origin fonts sharing * * @since 1.0 * * @param string $rules Rules that will be printed */ $rules = apply_filters('rocket_htaccess_web_fonts_access', $rules); return $rules; }
function rocket_thank_you_license() { if ('1' == get_rocket_option('license')) { $options = get_option(WP_ROCKET_SLUG); $options['license'] = time(); $options['ignore'] = true; update_option(WP_ROCKET_SLUG, $options); ?> <div class="updated"> <p> <b><?php echo WP_ROCKET_PLUGIN_NAME; ?> </b>: <?php _e('Thank you. Your license has been successfully validated!', 'rocket'); ?> <br /> <?php printf(__('Key: <code>%s</code><br>Email: <i>%s</i>', 'rocket'), get_rocket_option('consumer_key'), get_rocket_option('consumer_email')); ?> </p> </div> <?php } }