public function setUp() { global $wp_rewrite; $this->wp_rewrite = $wp_rewrite; $wp_rewrite = new WP_Rewrite(); $wp_rewrite->init(); $this->rewritecode = $wp_rewrite->rewritecode; $this->rewritereplace = $wp_rewrite->rewritereplace; $this->queryreplace = $wp_rewrite->queryreplace; }
function process_post($post_id) { global $wpdb, $wp_rewrite, $sitepress; if (!isset($wp_rewrite)) { require_once ABSPATH . WPINC . '/rewrite.php'; $wp_rewrite = new WP_Rewrite(); } $rewrite = $wp_rewrite->wp_rewrite_rules(); delete_post_meta($post_id, '_alp_broken_links'); $post = $wpdb->get_row("SELECT * FROM {$wpdb->posts} WHERE ID={$post_id}"); $home_url = $sitepress->language_url($_POST['icl_post_language']); $int1 = preg_match_all('@<a([^>]*)href="((' . rtrim($home_url, '/') . ')?/([^"^>^#]+))"([^>]*)>@i', $post->post_content, $alp_matches1); $int2 = preg_match_all('@<a([^>]*)href=\'((' . rtrim($home_url, '/') . ')?/([^\'^>^#]+))\'([^>]*)>@i', $post->post_content, $alp_matches2); for ($i = 0; $i < 6; $i++) { $alp_matches[$i] = array_merge((array) $alp_matches1[$i], (array) $alp_matches2[$i]); } $sitepress_settings = $sitepress->get_settings(); if ($int1 || $int2) { $url_parts = parse_url(rtrim(get_option('home'), '/') . '/'); foreach ($alp_matches[4] as $k => $m) { if (0 === strpos($m, 'wp-content')) { continue; } if ($sitepress_settings['language_negotiation_type'] == 1) { $m_orig = $m; $exp = explode('/', $m, 2); $lang = $exp[0]; if ($wpdb->get_var("SELECT code FROM {$wpdb->prefix}icl_languages WHERE code='{$lang}'")) { $m = $exp[1]; } else { $m = $m_orig; unset($m_orig); $lang = false; } } elseif ($sitepress_settings['language_negotiation_type'] == 2) { // } $pathinfo = ''; $req_uri = '/' . $m; $req_uri_array = explode('?', $req_uri); $req_uri = $req_uri_array[0]; // separate anchor $req_uri_array = explode('#', $req_uri); $req_uri = $req_uri_array[0]; $anchor = $req_uri_array[1]; $self = '/index.php'; $home_path = parse_url(get_option('home')); if (isset($home_path['path'])) { $home_path = $home_path['path']; } else { $home_path = ''; } $home_path = trim($home_path, '/'); $req_uri = str_replace($pathinfo, '', rawurldecode($req_uri)); $req_uri = trim($req_uri, '/'); $req_uri = preg_replace("|^{$home_path}|", '', $req_uri); $req_uri = trim($req_uri, '/'); $pathinfo = trim($pathinfo, '/'); $pathinfo = preg_replace("|^{$home_path}|", '', $pathinfo); $pathinfo = trim($pathinfo, '/'); $self = trim($self, '/'); $self = preg_replace("|^{$home_path}|", '', $self); $self = trim($self, '/'); if (!empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo)) { $request = $pathinfo; } else { // If the request uri is the index, blank it out so that we don't try to match it against a rule. if ($req_uri == $wp_rewrite->index) { $req_uri = ''; } $request = $req_uri; } $this_request = $request; $request_match = $request; foreach ((array) $rewrite as $match => $query) { // If the requesting file is the anchor of the match, prepend it // to the path info. if (!empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request) { $request_match = $req_uri . '/' . $request; } if (preg_match("!^{$match}!", $request_match, $matches) || preg_match("!^{$match}!", urldecode($request_match), $matches)) { // Got a match. $matched_rule = $match; // Trim the query of everything up to the '?'. $query = preg_replace("!^.+\\?!", '', $query); // Substitute the substring matches into the query. eval("@\$query = \"" . addslashes($query) . "\";"); $matched_query = $query; // Parse the query. parse_str($query, $perma_query_vars); break; } } $post_name = $category_name = $tax_name = false; if (isset($perma_query_vars['pagename'])) { $post_name = preg_replace('#((.*)/)#', '', $perma_query_vars['pagename']); $post_type = 'page'; } elseif (isset($perma_query_vars['name'])) { $post_name = $perma_query_vars['name']; $post_type = 'post'; } elseif (isset($perma_query_vars['category_name'])) { $category_name = $perma_query_vars['category_name']; } else { foreach ($this->custom_post_query_vars as $k => $v) { if (isset($perma_query_vars[$v])) { $post_name = $perma_query_vars[$v]; $post_type = $k; $post_qv = $v; break; } } foreach ($this->taxonomies_query_vars as $k => $v) { if (isset($perma_query_vars[$v])) { $tax_name = $perma_query_vars[$v]; $tax_type = $v; break; } } } if ($post_name) { $name = $wpdb->escape($post_name); //$post_type = isset($perma_query_vars['pagename']) ? 'page' : 'post'; $p = $wpdb->get_row("SELECT ID, post_type FROM {$wpdb->posts} WHERE post_name='{$name}' AND post_type ='{$post_type}'"); if ($p) { if ($post_type == 'page') { $qvid = 'page_id'; } else { $qvid = 'p'; } if ($sitepress_settings['language_negotiation_type'] == 1 && $lang) { $langprefix = '/' . $lang; } else { $langprefix = ''; } $perm_url = '(' . rtrim($home_url, '/') . ')?' . $langprefix . '/' . $m; $regk = '@href=["\'](' . $perm_url . ')["\']@i'; if ($anchor) { $anchor = "#" . $anchor; } else { $anchor = ""; } // check if this is an offsite url if ($p->post_type == 'page' && ($offsite_url = get_post_meta($p->ID, '_cms_nav_offsite_url', true))) { $regv = 'href="' . $offsite_url . $anchor . '"'; } else { $regv = 'href="' . '/' . ltrim($url_parts['path'], '/') . '?' . $qvid . '=' . $p->ID . $anchor . '"'; } $def_url[$regk] = $regv; } else { $alp_broken_links[$alp_matches[2][$k]] = array(); $p = $wpdb->get_results("SELECT ID, post_type FROM {$wpdb->posts} WHERE post_name LIKE '{$name}%' AND post_type IN('post','page')"); if ($p) { foreach ($p as $post_suggestion) { if ($post_suggestion->post_type == 'page') { $qvid = 'page_id'; } else { $qvid = 'p'; } $alp_broken_links[$alp_matches[2][$k]]['suggestions'][] = array('absolute' => '/' . ltrim($url_parts['path'], '/') . '?' . $qvid . '=' . $post_suggestion->ID, 'perma' => '/' . ltrim(str_replace(get_option('home'), '', get_permalink($post_suggestion->ID)), '/')); } } } } elseif ($category_name) { $name = $wpdb->escape($category_name); $c = $wpdb->get_row("SELECT term_id FROM {$wpdb->terms} WHERE slug='{$name}'"); if ($c) { /* not used ?? */ if ($sitepress_settings['language_negotiation_type'] == 1 && $lang) { $langprefix = '/' . $lang; } else { $langprefix = ''; } /* not used ?? */ $perm_url = '(' . rtrim($home_url, '/') . ')?' . $langprefix . '/' . $m; $regk = '@href=[\'"](' . $perm_url . ')[\'"]@i'; $url_parts = parse_url(rtrim(get_option('home'), '/') . '/'); $regv = 'href="' . '/' . ltrim($url_parts['path'], '/') . '?cat_ID=' . $c->term_id . '"'; $def_url[$regk] = $regv; } else { $alp_broken_links[$alp_matches[2][$k]] = array(); $c = $wpdb->get_results("SELECT term_id FROM {$wpdb->terms} WHERE slug LIKE '{$name}%'"); if ($c) { foreach ($c as $cat_suggestion) { $alp_broken_links[$alp_matches[2][$k]]['suggestions'][] = array('absolute' => '?cat_ID=' . $cat_suggestion->term_id, 'perma' => '/' . ltrim(str_replace(get_option('home'), '', get_category_link($cat_suggestion->term_id)), '/')); } } } } elseif ($tax_name) { if ($sitepress_settings['language_negotiation_type'] == 1 && $lang) { $langprefix = '/' . $lang; } else { $langprefix = ''; } $perm_url = '(' . rtrim($home_url, '/') . ')?' . $langprefix . '/' . $m; $regk = '@href=["\'](' . $perm_url . ')["\']@i'; if ($anchor) { $anchor = "#" . $anchor; } else { $anchor = ""; } $regv = 'href="' . '/' . ltrim($url_parts['path'], '/') . '?' . $tax_type . '=' . $tax_name . $anchor . '"'; $def_url[$regk] = $regv; } } $post_content = $post->post_content; if ($def_url) { $post_content = preg_replace(array_keys($def_url), array_values($def_url), $post_content); } $tx_qvs = is_array($this->taxonomies_query_vars) && !empty($this->taxonomies_query_vars) ? '|' . join('|', $this->taxonomies_query_vars) : ''; $post_qvs = is_array($this->custom_posts_query_vars) && !empty($this->custom_posts_query_vars) ? '|' . join('|', $this->custom_posts_query_vars) : ''; $int = preg_match_all('@href=[\'"](' . rtrim(get_option('home'), '/') . '/?\\?(p|page_id' . $tx_qvs . $post_qvs . ')=([0-9a-z-]+)(#.+)?)[\'"]@i', $post_content, $matches2); if ($int) { $url_parts = parse_url(rtrim(get_option('home'), '/') . '/'); $post_content = preg_replace('@href=[\'"](' . rtrim(get_option('home'), '/') . '/?\\?(p|page_id' . $tx_qvs . $post_qvs . ')=([0-9a-z-]+)(#.+)?)[\'"]@i', 'href="' . '/' . ltrim($url_parts['path'], '/') . '?$2=$3$4"', $post_content); } if ($post_content) { $wpdb->update($wpdb->posts, array('post_content' => $post_content), array('ID' => $post_id)); } } update_post_meta($post_id, '_alp_processed', time()); if ($alp_broken_links) { update_post_meta($post_id, '_alp_broken_links', $alp_broken_links); } }
public function setup() { global $wp_rewrite; $wp_rewrite = new WP_Rewrite(); //set the permalink structure $wp_rewrite->set_permalink_structure('/blog/%year%/%monthnum%/%day%/%postname%/'); //register test post_types $args = array('hierarchical' => false, 'public' => true, 'has_archive' => true, 'publicly_queryable' => true, 'rewrite' => array('slug' => 'flat-posts', 'with_front' => false, 'pages' => true, 'feeds' => true), 'capability_type' => 'page'); register_post_type('flat_post_type', $args); $args = array('hierarchical' => false, 'public' => true, 'has_archive' => true, 'publicly_queryable' => true, 'rewrite' => array('slug' => 'flat-posts-no-page', 'with_front' => false, 'pages' => false, 'feeds' => false), 'capability_type' => 'page'); register_post_type('flat_no_pages', $args); $args = array('hierarchical' => true, 'public' => true, 'has_archive' => true, 'publicly_queryable' => true, 'rewrite' => array('slug' => 'hierarchical-posts', 'with_front' => false, 'pages' => true, 'feeds' => true), 'capability_type' => 'page'); register_post_type('hier_post_type', $args); }
/** * Updates the global wp_rewrite instance if it is wrong * * @param string $taxonomy * @return bool|string FALSE or the original string for later restore */ private function fix_term_base($taxonomy) { $expected = $this->get_expected_base($taxonomy); $existing = $this->wp_rewrite->get_extra_permastruct($taxonomy); if (!$this->update_required($expected, $existing)) { return FALSE; } $this->set_permastruct($taxonomy, $expected); return $existing; }
/** * Called on plugin activation and upgrading. * * @see register_activation_hook */ function openid_activate_plugin() { global $wp_rewrite; // if first time activation, set OpenID capability for administrators if (get_option('openid_plugin_revision') === false) { global $wp_roles; $role = $wp_roles->get_role('administrator'); if ($role) { $role->add_cap('use_openid_provider'); } } // for some reason, show_on_front is not always set, causing is_front_page() to fail $show_on_front = get_option('show_on_front'); if (empty($show_on_front)) { update_option('show_on_front', 'posts'); } // Add custom OpenID options add_option('openid_enable_commentform', true); add_option('openid_plugin_enabled', true); add_option('openid_plugin_revision', 0); add_option('openid_db_revision', 0); add_option('openid_enable_approval', false); add_option('openid_xrds_returnto', true); add_option('openid_comment_displayname_length', 12); openid_create_tables(); openid_migrate_old_data(); // setup schedule cleanup wp_clear_scheduled_hook('cleanup_openid'); wp_schedule_event(time(), 'hourly', 'cleanup_openid'); // flush rewrite rules if (!isset($wp_rewrite)) { $wp_rewrite = new WP_Rewrite(); } $wp_rewrite->flush_rules(); // set current revision update_option('openid_plugin_revision', OPENID_PLUGIN_REVISION); openid_remove_historical_options(); }
/** * The base method for creating a new Rewrite rule * * @param array|string $regex The regular expression to catch the URL * @param array $args The arguments in which the regular expression "alias" to * * @return Tribe__Events__Rewrite */ public function add($regex, $args = array()) { $regex = (array) $regex; $default = array(); $args = array_filter(wp_parse_args($args, $default)); $url = add_query_arg($args, 'index.php'); // Optional Trailing Slash $regex[] = '?$'; // Glue the pieces with slashes $regex = implode('/', array_filter($regex)); // Add the Bases to the regex foreach ($this->bases as $key => $value) { $regex = str_replace(array('{{ ' . $key . ' }}', '{{' . $key . '}}'), $value, $regex); } // Apply the Preg Indexes to the URL preg_match_all('/%([0-9])/', $url, $matches); foreach (end($matches) as $index) { $url = str_replace('%' . $index, $this->rewrite->preg_index($index), $url); } // Add the rule $this->rules[$regex] = $url; return $this; }
/** * Build an OpenID service URL. * * @param string $service service to build URL for * @param string $scheme URL scheme to use for URL (see site_url()) * @return string service URL * @see site_url */ function openid_service_url($service, $scheme = null) { global $wp_rewrite; if (!$wp_rewrite) $wp_rewrite = new WP_Rewrite(); if (!defined('OPENID_SSL') || !OPENID_SSL) $scheme = null; $url = site_url('/', $scheme); if ($wp_rewrite->using_permalinks()) { $url .= 'index.php/openid/' . $service; } else { $url .= '?openid=' . $service; } return $url; }
/** * Load either 1.0 or 2.0 theme engine, based on several critical and evolving criteron. * Theme and plugin developers are advised to check and filter this function as needed. * * @since 3.9 * * @return bool $activate Whether or not to activate the 2.0 theme engine. */ function _wpsc_maybe_activate_theme_engine_v2() { $activate = true; global $wp_rewrite; if (!is_a($wp_rewrite, 'WP_Rewrite')) { $wp_rewrite = new WP_Rewrite(); } // The theme engine routing mechanism (WPSC_Router) is not currently equipped to work without pretty permalinks. if (!$wp_rewrite->using_permalinks()) { $activate = false; } // We're also not currently able to work as expected when using "Almost Pretty" permalinks, where PATHINFO is not enabled. if ($wp_rewrite->using_index_permalinks()) { $activate = false; } // In the future, this check will be more refined. As of 3.9, the current Gold Cart release is incompatible with the 2.0 theme engine. if (defined('WPSC_GOLD_VERSION')) { $activate = false; } // If an active theme is dependent on 1.0 theme template files from 3.8. if (_wpsc_theme_engine_v2_has_old_templates()) { $activate = false; } // If any plugins or theme functionality are hooking into 1.0 template hooks, we don't activate 2.0. if (_wpsc_theme_engine_v1_has_actions()) { $activate = false; } $activate = apply_filters('_wpsc_maybe_activate_theme_engine_v2', $activate); $new_theme_engine = $activate ? '2.0' : '1.0'; $old_theme_engine = get_option('wpsc_get_active_theme_engine'); if ($old_theme_engine !== $new_theme_engine) { // _wpsc_action_flush_rewrite_rules lives here. require_once WPSC_FILE_PATH . '/wpsc-admin/init.php'; do_action('wpsc_updated_theme_engine', $new_theme_engine, $old_theme_engine); do_action("wpsc_updated_theme_engine_from_{$old_theme_engine}_to_{$new_theme_engine}"); add_action('shutdown', '_wpsc_action_flush_rewrite_rules'); update_option('wpsc_get_active_theme_engine', $new_theme_engine); $location = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : home_url(); // Redirect ensures that both templates will not be loaded, fixing fatal errors, etc. wp_safe_redirect(esc_url_raw($location)); exit; } return $activate; }
public function get_taxonomy_rules() { $rules = array($this->cat_base . '([^/]+)/(\\d{4}-\\d{2}-\\d{2})/?$' => 'index.php?tribe_events_cat=' . $this->rewrite->preg_index(2) . '&post_type=' . TribeEvents::POSTTYPE . '&eventDisplay=day' . '&eventDate=' . $this->rewrite->preg_index(3), $this->tag_base . '([^/]+)/(\\d{4}-\\d{2}-\\d{2})/?$' => 'index.php?tag=' . $this->rewrite->preg_index(2) . '&post_type=' . TribeEvents::POSTTYPE . '&eventDisplay=day' . '&eventDate=' . $this->rewrite->preg_index(3)); return $rules; }
/** * This is a callback function to enable custom post type archive pages. * This function will add new rewrite rules to the global $wp_rewrite variable. * Custom rewrite rules will support feeds and paging without any extra coding. (yeeey) * This function will be called by 'generate_rewrite_rules' filter. * Note that it is necessary to flush permalinks for this method to be called. * It might be useful to know that these rewrite rules will create new param called 'post_type_index'. * It can be used to check whether we are in custom post archive. * @param WP_Rewrite $wp_rewrite object that contains all the routing data * @return WP_Rewrite modified $wp_rewrite with my custom rewrite rules */ function pta_register_post_type_rewrite_rules($wp_rewrite) { extract(pta_get_settings()); if (empty($enabled_post_type_archives)) { return $wp_rewrite; } // if we don't have any enabled post type archives then might as well quit $custom_rules = array(); $url_base = $url_base == '' ? $url_base : $url_base . '/'; if ($use_rewrite_slug) { $customisations = $enabled_post_type_customisations; // just to make it shorter foreach ($enabled_post_type_archives as $post_type_slug) { $post_type = get_post_type_object($post_type_slug); if (!isset($post_type)) { continue; } // omg post type doesn't exist - continue with next one if (isset($customisations[$post_type_slug]) and !empty($customisations[$post_type_slug]['rewrite_slug'])) { $post_type = $enabled_post_type_customisations[$post_type_slug]['rewrite_slug']; } elseif (!empty($post_type->rewrite) and !empty($post_type->rewrite['slug'])) { $post_type = $post_type->rewrite['slug']; } else { $post_type = $post_type_slug; } $custom_rules["{$url_base}({$post_type})/([0-9]+)/([0-9]{1,2})/([0-9]{1,2})/?\$"] = "index.php?post_type_index=1&post_type={$post_type_slug}&year=" . $wp_rewrite->preg_index(2) . '&monthnum=' . $wp_rewrite->preg_index(3) . '&day=' . $wp_rewrite->preg_index(4); $custom_rules["{$url_base}({$post_type})/([0-9]+)/([0-9]{1,2})/?\$"] = "index.php?post_type_index=1&post_type={$post_type_slug}&year=" . $wp_rewrite->preg_index(2) . '&monthnum=' . $wp_rewrite->preg_index(3); $custom_rules["{$url_base}({$post_type})/([0-9]+/?\$)"] = "index.php?post_type_index=1&post_type={$post_type_slug}&year=" . $wp_rewrite->preg_index(2); $custom_rules["{$url_base}({$post_type})/page/?([0-9]{1,})/?\$"] = "index.php?post_type_index=1&post_type={$post_type_slug}&paged=" . $wp_rewrite->preg_index(2); $custom_rules["{$url_base}({$post_type})/(feed|rdf|rss|rss2|atom)/?\$"] = "index.php?post_type_index=1&post_type={$post_type_slug}&feed=" . $wp_rewrite->preg_index(2); $custom_rules["{$url_base}({$post_type})/?\$"] = "index.php?post_type_index=1&post_type={$post_type_slug}"; } } else { $enabled_post_type_archives = implode('|', $enabled_post_type_archives); $custom_rules = array("{$url_base}({$enabled_post_type_archives})/([0-9]+)/([0-9]{1,2})/([0-9]{1,2})/?\$" => 'index.php?post_type_index=1&post_type=' . $wp_rewrite->preg_index(1) . '&year=' . $wp_rewrite->preg_index(2) . '&monthnum=' . $wp_rewrite->preg_index(3) . '&day=' . $wp_rewrite->preg_index(4), "{$url_base}({$enabled_post_type_archives})/([0-9]+)/([0-9]{1,2})/?\$" => 'index.php?post_type_index=1&post_type=' . $wp_rewrite->preg_index(1) . '&year=' . $wp_rewrite->preg_index(2) . '&monthnum=' . $wp_rewrite->preg_index(3), "{$url_base}({$enabled_post_type_archives})/([0-9]+)/?\$" => 'index.php?post_type_index=1&post_type=' . $wp_rewrite->preg_index(1) . '&year=' . $wp_rewrite->preg_index(2), "{$url_base}({$enabled_post_type_archives})/page/?([0-9]{1,})/?\$" => 'index.php?post_type_index=1&post_type=' . $wp_rewrite->preg_index(1) . '&paged=' . $wp_rewrite->preg_index(2), "{$url_base}({$enabled_post_type_archives})/(feed|rdf|rss|rss2|atom)/?\$" => 'index.php?post_type_index=1&post_type=' . $wp_rewrite->preg_index(1) . '&feed=' . $wp_rewrite->preg_index(2), "{$url_base}({$enabled_post_type_archives})/?\$" => 'index.php?post_type_index=1&post_type=' . $wp_rewrite->preg_index(1)); } $wp_rewrite->rules = array_merge($custom_rules, $wp_rewrite->rules); // merge existing rules with custom ones return $wp_rewrite; }
$listitems[$key + $page] = $value; } foreach ($listitems as $position => $item) { $sql .= sprintf('WHEN %d THEN %d ', $item, $position); } $sql .= $endQuery; $wpdb->query($sql); } exitAction(''); } /** Admin action Ends Here * * Video Search Starts Here */ $video_search = filter_input(INPUT_GET, 'video_search'); /** Get parmalink URL */ $wp_rewrite = new WP_Rewrite(); $link = $wp_rewrite->get_page_permastruct(); /** Check video search is exist */ if (!empty($video_search) && !empty($link)) { /** Convert non-sef URL to seo friendly URL for video serach */ $location = home_url() . '/search/' . urlencode($video_search); /** Redirect to the search url */ header("Location: {$location}", true, 301); exitAction(''); } /** Video Search Ends Here * * Video Detail Page action Starts Here * Fucntion to include rss file */ add_action('wp_ajax_rss', 'rss_function'); add_action('wp_ajax_nopriv_rss', 'rss_function');
/** * Check if the standard rules for a normal WordPress installation (not network * based) are inside the main htaccess file. This only applies to websites that * have permalinks enabled, or 3rd-party plugins that require custom rules * (generally based on mod_deflate) to compress and/or generate static files for * cache. * * @param string $rules Content of the main htaccess file. * @return boolean True if the htaccess has the standard rules, false otherwise. */ function sucuriscan_htaccess_is_standard($rules = false) { if ($rules === false) { $rules = ''; $htaccess_path = SucuriScan::get_htaccess_path(); if ($htaccess_path) { $rules = @file_get_contents($htaccess_path); } } if (is_string($rules) && !empty($rules)) { $rewrite = new WP_Rewrite(); $standard = $rewrite->mod_rewrite_rules(); return (bool) (strpos($rules, $standard) !== false); } return false; }
/** * Register bbPress-specific rewrite rules for uri's that are not * setup for us by way of custom post types or taxonomies. This includes: * - Front-end editing * - Topic views * - User profiles * * @since bbPress (r2688) * @param WP_Rewrite $wp_rewrite bbPress-sepecific rules are appended in * $wp_rewrite->rules */ public static function generate_rewrite_rules($wp_rewrite) { // Slugs $view_slug = bbp_get_view_slug(); $user_slug = bbp_get_user_slug(); // Unique rewrite ID's $edit_id = bbp_get_edit_rewrite_id(); $view_id = bbp_get_view_rewrite_id(); $user_id = bbp_get_user_rewrite_id(); $favs_id = bbp_get_user_favorites_rewrite_id(); $subs_id = bbp_get_user_subscriptions_rewrite_id(); $tops_id = bbp_get_user_topics_rewrite_id(); $reps_id = bbp_get_user_replies_rewrite_id(); // Rewrite rule matches used repeatedly below $root_rule = '/([^/]+)/?$'; $edit_rule = '/([^/]+)/edit/?$'; $feed_rule = '/([^/]+)/feed/?$'; $page_rule = '/([^/]+)/page/?([0-9]{1,})/?$'; // User profile rules $tops_rule = '/([^/]+)/topics/?$'; $reps_rule = '/([^/]+)/replies/?$'; $favs_rule = '/([^/]+)/' . bbp_get_user_favorites_slug() . '/?$'; $subs_rule = '/([^/]+)/' . bbp_get_user_subscriptions_slug() . '/?$'; $tops_page_rule = '/([^/]+)/topics/page/?([0-9]{1,})/?$'; $reps_page_rule = '/([^/]+)/replies/page/?([0-9]{1,})/?$'; $favs_page_rule = '/([^/]+)/' . bbp_get_user_favorites_slug() . '/page/?([0-9]{1,})/?$'; $subs_page_rule = '/([^/]+)/' . bbp_get_user_subscriptions_slug() . '/page/?([0-9]{1,})/?$'; // New bbPress specific rules to merge with existing that are not // handled automatically by custom post types or taxonomy types $bbp_rules = array(bbp_get_forum_slug() . $edit_rule => 'index.php?' . bbp_get_forum_post_type() . '=' . $wp_rewrite->preg_index(1) . '&' . $edit_id . '=1', bbp_get_topic_slug() . $edit_rule => 'index.php?' . bbp_get_topic_post_type() . '=' . $wp_rewrite->preg_index(1) . '&' . $edit_id . '=1', bbp_get_reply_slug() . $edit_rule => 'index.php?' . bbp_get_reply_post_type() . '=' . $wp_rewrite->preg_index(1) . '&' . $edit_id . '=1', bbp_get_topic_tag_tax_slug() . $edit_rule => 'index.php?' . bbp_get_topic_tag_tax_id() . '=' . $wp_rewrite->preg_index(1) . '&' . $edit_id . '=1', $user_slug . $tops_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $tops_id . '=1&paged=' . $wp_rewrite->preg_index(2), $user_slug . $reps_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $reps_id . '=1&paged=' . $wp_rewrite->preg_index(2), $user_slug . $favs_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $favs_id . '=1&paged=' . $wp_rewrite->preg_index(2), $user_slug . $subs_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $subs_id . '=1&paged=' . $wp_rewrite->preg_index(2), $user_slug . $tops_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $tops_id . '=1', $user_slug . $reps_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $reps_id . '=1', $user_slug . $favs_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $favs_id . '=1', $user_slug . $subs_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $subs_id . '=1', $user_slug . $edit_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $edit_id . '=1', $user_slug . $root_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1), $view_slug . $page_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index(1) . '&paged=' . $wp_rewrite->preg_index(2), $view_slug . $feed_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index(1) . '&feed=' . $wp_rewrite->preg_index(2), $view_slug . $root_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index(1)); // Merge bbPress rules with existing $wp_rewrite->rules = array_merge($bbp_rules, $wp_rewrite->rules); // Return merged rules return $wp_rewrite; }
private function initialize_rewrite($current_language, $default_language, $sitepress) { global $wp_rewrite; if (!isset($wp_rewrite)) { require_once ABSPATH . WPINC . '/rewrite.php'; $wp_rewrite = new WP_Rewrite(); } if ($current_language == $default_language) { $rewrite = $wp_rewrite->wp_rewrite_rules(); } else { remove_filter('option_rewrite_rules', array($sitepress, 'rewrite_rules_filter')); if (class_exists('WPML_Slug_Translation')) { remove_filter('option_rewrite_rules', array('WPML_Slug_Translation', 'rewrite_rules_filter'), 1); } $rewrite = $wp_rewrite->wp_rewrite_rules(); if (class_exists('WPML_Slug_Translation')) { add_filter('option_rewrite_rules', array('WPML_Slug_Translation', 'rewrite_rules_filter'), 1, 1); } } return $this->all_rewrite_rules($rewrite); }
/** * Add rewrite rules for .well-known. * * @param WP_Rewrite $wp_rewrite */ public static function rewrite_rules($wp_rewrite) { $well_known_rules = array('.well-known/(.+)' => 'index.php?well-known=' . $wp_rewrite->preg_index(1)); $wp_rewrite->rules = $well_known_rules + $wp_rewrite->rules; }
/** * Load either 1.0 or 2.0 theme engine, based on several critical and evolving criteron. * Theme and plugin developers are advised to check and filter this function as needed. * * @since 3.9 * * @return bool $activate Whether or not to activate the 2.0 theme engine. */ function _wpsc_maybe_activate_theme_engine_v2() { $activate = false; global $wp_rewrite; if (!is_a($wp_rewrite, 'WP_Rewrite')) { $wp_rewrite = new WP_Rewrite(); } // The theme engine routing mechanism (WPSC_Router) is not currently equipped to work without pretty permalinks. if (!$wp_rewrite->using_permalinks()) { $activate = false; } // We're also not currently able to work as expected when using "Almost Pretty" permalinks, where PATHINFO is not enabled. if ($wp_rewrite->using_index_permalinks()) { $activate = false; } // In the future, this check will be more refined. As of 3.9, the current Gold Cart release is incompatible with the 2.0 theme engine. if (defined('WPSC_GOLD_VERSION')) { $activate = false; } // If an active theme is dependent on 1.0 theme template files from 3.8. if (_wpsc_theme_engine_v2_has_old_templates()) { $activate = false; } // If any plugins or theme functionality are hooking into 1.0 template hooks, we don't activate 2.0. if (_wpsc_theme_engine_v1_has_actions()) { $activate = false; } $activate = apply_filters('_wpsc_maybe_activate_theme_engine_v2', $activate); $new_theme_engine = $activate ? '2.0' : '1.0'; $old_theme_engine = get_option('wpsc_get_active_theme_engine'); if ($old_theme_engine !== $new_theme_engine) { do_action('wpsc_updated_theme_engine', $new_theme_engine, $old_theme_engine); do_action("wpsc_updated_theme_engine_from_{$old_theme_engine}_to_{$new_theme_engine}"); add_action('shutdown', '_wpsc_action_flush_rewrite_rules'); update_option('wpsc_get_active_theme_engine', $new_theme_engine); } return $activate; }
/** * Load either 1.0 or 2.0 theme engine, based on several critical and evolving criteron. * Theme and plugin developers are advised to check and filter this function as needed. * * @since 3.9 * @return bool $activate Whether or not to activate the 2.0 theme engine. */ function _wpsc_maybe_activate_theme_engine_v2() { $activate = true; global $wp_rewrite; if (!is_a($wp_rewrite, 'WP_Rewrite')) { $wp_rewrite = new WP_Rewrite(); } // The theme engine routing mechanism (WPSC_Router) is not currently equipped to work without pretty permalinks. if (!$wp_rewrite->using_permalinks()) { $activate = false; } // We're also not currently able to work as expected when using "Almost Pretty" permalinks, where PATHINFO is not enabled. if ($wp_rewrite->using_index_permalinks()) { $activate = false; } // In the future, this check will be more refined. As of 3.9, the current Gold Cart release is incompatible with the 2.0 theme engine. if (defined('WPSC_GOLD_VERSION')) { $activate = false; } // If an active theme is dependent on 1.0 theme template files from 3.8. if (_wpsc_theme_engine_v2_has_old_templates()) { $activate = false; } // If any plugins or theme functionality are hooking into 1.0 template hooks, we don't activate 2.0. if (_wpsc_theme_engine_v1_has_actions()) { $activate = false; } return apply_filters('_wpsc_maybe_activate_theme_engine_v2', $activate); }
function wpi_flush_rewrite_rules() { global $wp_rewrite; $wp_rewrite = new WP_Rewrite(); $wp_rewrite->flush_rules(); }
function _process_generic_text($source_text, &$alp_broken_links) { global $wpdb, $wp_rewrite, $sitepress, $sitepress_settings; $sitepress_settings = $sitepress->get_settings(); $default_language = $sitepress->get_default_language(); $current_language = $sitepress->get_current_language(); $cache_key_args = array($default_language, $current_language, md5($source_text), md5(implode('', $alp_broken_links))); $cache_key = md5(json_encode($cache_key_args)); $cache_group = '_process_generic_text'; $found = false; $text = wp_cache_get($cache_key, $cache_group, false, $found); if ($found) { return $text; } $text = $source_text; if (!isset($wp_rewrite)) { require_once ABSPATH . WPINC . '/rewrite.php'; $wp_rewrite = new WP_Rewrite(); } if ($current_language == $default_language) { $rewrite = $wp_rewrite->wp_rewrite_rules(); } else { remove_filter('option_rewrite_rules', array($sitepress, 'rewrite_rules_filter')); if (class_exists('WPML_Slug_Translation')) { remove_filter('option_rewrite_rules', array('WPML_Slug_Translation', 'rewrite_rules_filter'), 1); } $rewrite = $wp_rewrite->wp_rewrite_rules(); add_filter('option_rewrite_rules', array($sitepress, 'rewrite_rules_filter')); if (class_exists('WPML_Slug_Translation')) { add_filter('option_rewrite_rules', array('WPML_Slug_Translation', 'rewrite_rules_filter'), 1, 1); } } $rewrite = $this->all_rewrite_rules($rewrite); $home_url = $sitepress->language_url(empty($_POST['icl_post_language']) ? false : $_POST['icl_post_language']); if ($sitepress_settings['language_negotiation_type'] == 3) { $home_url = preg_replace("#\\?lang=([a-z-]+)#i", '', $home_url); } $home_url = str_replace("?", "\\?", $home_url); if ($sitepress_settings['urls']['directory_for_default_language']) { $default_language = $sitepress->get_default_language(); $home_url = str_replace($default_language . "/", "", $home_url); } $int1 = preg_match_all('@<a([^>]*)href="((' . rtrim($home_url, '/') . ')?/([^"^>^\\[^\\]]+))"([^>]*)>@i', $text, $alp_matches1); $int2 = preg_match_all('@<a([^>]*)href=\'((' . rtrim($home_url, '/') . ')?/([^\'^>^\\[^\\]]+))\'([^>]*)>@i', $text, $alp_matches2); $alp_matches = array(); for ($i = 0; $i < 6; $i++) { $alp_matches[$i] = array_merge((array) $alp_matches1[$i], (array) $alp_matches2[$i]); } if ($int1 || $int2) { $url_parts = parse_url(rtrim(get_home_url(), '/') . '/'); foreach ($alp_matches[4] as $k => $m) { if (0 === strpos($m, 'wp-content')) { continue; } $lang = false; if ($sitepress_settings['language_negotiation_type'] == 1 && $sitepress_settings['urls']['directory_for_default_language'] != 1) { $m_orig = $m; $exp = explode('/', $m, 2); $lang = $exp[0]; if ($wpdb->get_var("SELECT code FROM {$wpdb->prefix}icl_languages WHERE code='{$lang}'")) { $m = $exp[1]; } else { $m = $m_orig; unset($m_orig); $lang = false; } } $pathinfo = ''; $req_uri = '/' . $m; $req_uri_array = explode('?', $req_uri); $req_uri = $req_uri_array[0]; $req_uri_params = ''; if (isset($req_uri_array[1])) { $req_uri_params = $req_uri_array[1]; } // separate anchor $req_uri_array = explode('#', $req_uri); $req_uri = $req_uri_array[0]; $anchor = isset($req_uri_array[1]) ? $req_uri_array[1] : false; $home_path = parse_url(get_home_url()); if (isset($home_path['path'])) { $home_path = $home_path['path']; } else { $home_path = ''; } $home_path = trim($home_path, '/'); $req_uri = str_replace($pathinfo, '', rawurldecode($req_uri)); $req_uri = trim($req_uri, '/'); $req_uri = preg_replace("|^{$home_path}|", '', $req_uri); $req_uri = trim($req_uri, '/'); $pathinfo = trim($pathinfo, '/'); $pathinfo = preg_replace("|^{$home_path}|", '', $pathinfo); $pathinfo = trim($pathinfo, '/'); if (!empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo)) { $request = $pathinfo; } else { // If the request uri is the index, blank it out so that we don't try to match it against a rule. if ($req_uri == $wp_rewrite->index) { $req_uri = ''; } $request = $req_uri; } $request_match = $request; $permalink_query_vars = array(); foreach ((array) $rewrite as $match => $query) { // If the requesting file is the anchor of the match, prepend it // to the path info. if (!empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request) { $request_match = $req_uri . '/' . $request; } if (preg_match("!^{$match}!", $request_match, $matches) || preg_match("!^{$match}!", urldecode($request_match), $matches)) { // Got a match. // Trim the query of everything up to the '?'. $query = preg_replace("!^.+\\?!", '', $query); // Substitute the substring matches into the query. $query = addslashes(WP_MatchesMapRegex::apply($query, $matches)); // Parse the query. parse_str($query, $permalink_query_vars); break; } } $post_name = $category_name = $tax_name = false; if (isset($permalink_query_vars['pagename'])) { $icl_post_lang = isset($_POST['icl_post_language']) ? $_POST['icl_post_language'] : $current_language; $sitepress->switch_lang($icl_post_lang); $page_by_path = get_page_by_path($permalink_query_vars['pagename']); $sitepress->switch_lang($current_language); if (!empty($page_by_path->post_type)) { $post_name = $permalink_query_vars['pagename']; $post_type = 'page'; } else { $post_name = $permalink_query_vars['pagename']; $post_type = 'post'; } } elseif (isset($permalink_query_vars['name'])) { $post_name = $permalink_query_vars['name']; $post_type = 'post'; } elseif (isset($permalink_query_vars['category_name'])) { $category_name = $permalink_query_vars['category_name']; } elseif (isset($permalink_query_vars['p'])) { // case or /archives/%post_id $post_data_prepared = $wpdb->prepare("SELECT post_type, post_name FROM {$wpdb->posts} WHERE id=%d", $permalink_query_vars['p']); list($post_type, $post_name) = $wpdb->get_row($post_data_prepared, ARRAY_N); } else { if (empty($this->custom_post_query_vars) or empty($this->taxonomies_query_vars)) { $this->init_query_vars(); } foreach ($this->custom_post_query_vars as $query_vars_key => $query_vars_value) { if (isset($permalink_query_vars[$query_vars_value])) { $post_name = $permalink_query_vars[$query_vars_value]; $post_type = $query_vars_key; break; } } foreach ($this->taxonomies_query_vars as $query_vars_value) { if (isset($permalink_query_vars[$query_vars_value])) { $tax_name = $permalink_query_vars[$query_vars_value]; $tax_type = $query_vars_value; break; } } } if ($post_name && isset($post_type)) { $icl_post_lang = isset($_POST['icl_post_language']) ? $_POST['icl_post_language'] : $current_language; $sitepress->switch_lang($icl_post_lang); $p = get_page_by_path($post_name, OBJECT, $post_type); $sitepress->switch_lang($current_language); if (empty($p)) { // fail safe if ($post_id = url_to_postid($home_path . '/' . $post_name)) { $p = get_post($post_id); } } if ($p) { if ($post_type == 'page') { $qvid = 'page_id'; } else { $qvid = 'p'; } if ($sitepress_settings['language_negotiation_type'] == 1 && $lang) { $langprefix = '/' . $lang; } else { $langprefix = ''; } $perm_url = '(' . rtrim($home_url, '/') . ')?' . $langprefix . '/' . str_replace('?', '\\?', $m); $regk = '@href=["\'](' . $perm_url . ')["\']@i'; if ($anchor) { $anchor = "#" . $anchor; } else { $anchor = ""; } // check if this is an offsite url if ($p->post_type == 'page' && ($offsite_url = get_post_meta($p->ID, '_cms_nav_offsite_url', true))) { $regv = 'href="' . $offsite_url . $anchor . '"'; } else { $regv = 'href="' . '/' . ltrim($url_parts['path'], '/') . '?' . $qvid . '=' . $p->ID; if ($req_uri_params != '') { $regv .= '&' . $req_uri_params; } $regv .= $anchor . '"'; } $def_url[$regk] = $regv; } else { $alp_broken_links[$alp_matches[2][$k]] = array(); $name = esc_sql($post_name); $p = $wpdb->get_results("SELECT ID, post_type FROM {$wpdb->posts} WHERE post_name LIKE '{$name}%' AND post_type IN('post','page')"); if ($p) { foreach ($p as $post_suggestion) { if ($post_suggestion->post_type == 'page') { $qvid = 'page_id'; } else { $qvid = 'p'; } $alp_broken_links[$alp_matches[2][$k]]['suggestions'][] = array('absolute' => '/' . ltrim($url_parts['path'], '/') . '?' . $qvid . '=' . $post_suggestion->ID, 'perma' => '/' . ltrim(str_replace(site_url(), '', get_permalink($post_suggestion->ID)), '/')); } } } } elseif ($category_name) { if (false !== strpos($category_name, '/')) { $splits = explode('/', $category_name); $category_name = array_pop($splits); $category_parent = array_pop($splits); $category_parent_id = $wpdb->get_var($wpdb->prepare("SELECT term_id FROM {$wpdb->terms} WHERE slug=%s", $category_parent)); $c = $wpdb->get_row($wpdb->prepare("SELECT t.term_id FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} x ON x.term_id=t.term_id AND x.taxonomy='category' AND x.parent=%d AND t.slug=%s", $category_parent_id, $category_name)); } else { $c = $wpdb->get_row($wpdb->prepare("SELECT term_id FROM {$wpdb->terms} WHERE slug=%s", $category_name)); } if ($c) { /* not used ?? */ if ($sitepress_settings['language_negotiation_type'] == 1 && $lang) { $langprefix = '/' . $lang; } else { $langprefix = ''; } /* not used ?? */ $perm_url = '(' . rtrim($home_url, '/') . ')?' . $langprefix . '/' . $m; $regk = '@href=[\'"](' . $perm_url . ')[\'"]@i'; $url_parts = parse_url(rtrim(get_home_url(), '/') . '/'); $regv = 'href="' . '/' . ltrim($url_parts['path'], '/') . '?cat_ID=' . $c->term_id . '"'; $def_url[$regk] = $regv; } elseif (isset($name)) { $alp_broken_links[$alp_matches[2][$k]] = array(); $c_prepared = $wpdb->prepare("SELECT term_id FROM {$wpdb->terms} WHERE slug LIKE %s", array($name . '%')); $c = $wpdb->get_results($c_prepared); if ($c) { foreach ($c as $cat_suggestion) { $perma = '/' . ltrim(str_replace(get_home_url(), '', get_category_link($cat_suggestion->term_id)), '/'); $alp_broken_links[$alp_matches[2][$k]]['suggestions'][] = array('absolute' => '?cat_ID=' . $cat_suggestion->term_id, 'perma' => $perma); } } } } elseif ($tax_name && isset($tax_type)) { if ($sitepress_settings['language_negotiation_type'] == 1 && $lang) { $langprefix = '/' . $lang; } else { $langprefix = ''; } $perm_url = '(' . rtrim($home_url, '/') . ')?' . $langprefix . '/' . $m; $regk = '@href=["\'](' . $perm_url . ')["\']@i'; if ($anchor) { $anchor = "#" . $anchor; } else { $anchor = ""; } $regv = 'href="' . '/' . ltrim($url_parts['path'], '/') . '?' . $tax_type . '=' . $tax_name . $anchor . '"'; $def_url[$regk] = $regv; } } if (!empty($def_url)) { $text = preg_replace(array_keys($def_url), array_values($def_url), $text); } $tx_qvs = !empty($this->taxonomies_query_vars) && is_array($this->taxonomies_query_vars) ? '|' . join('|', $this->taxonomies_query_vars) : ''; $post_qvs = !empty($this->custom_posts_query_vars) && is_array($this->custom_posts_query_vars) ? '|' . join('|', $this->custom_posts_query_vars) : ''; $int = preg_match_all('@href=[\'"](' . rtrim(get_home_url(), '/') . '/?\\?(p|page_id' . $tx_qvs . $post_qvs . ')=([0-9a-z-]+)(#.+)?)[\'"]@i', $text, $matches2); if ($int) { $url_parts = parse_url(rtrim(get_home_url(), '/') . '/'); $text = preg_replace('@href=[\'"](' . rtrim(get_home_url(), '/') . '/?\\?(p|page_id' . $tx_qvs . $post_qvs . ')=([0-9a-z-]+)(#.+)?)[\'"]@i', 'href="' . '/' . ltrim($url_parts['path'], '/') . '?$2=$3$4"', $text); } } wp_cache_set($cache_key, $text, $cache_group); return $text; }
/** * Generates all the rewrite rules for a given post type. * * The rewrite rules allow a post type to be filtered by all possible combinations & permutations * of taxonomies that apply to the specified post type and additional query_vars specified with * the $queryVars parameter. * * Must be called from a function hooked to the 'generate_rewrite_rules' action so that the global * $wpRewrite->preg_index function returns the correct value. * * You have to use pre_get_posts, query_vars filters to add the category/tag rewrites correctly. * See for example ~/kpt-intranet-blog/src/KptIntranetBlog/Theme/Component/UserImageComponent.php * * @param \WP_Rewrite $wpRewrite * @param string|object $postType The post type for which you wish to create the rewrite rules * @param array $queryVars optional Non-taxonomy query vars you wish to create rewrite rules for. Rules will be created to capture any single string for the query_var, that is, a rule of the form '/query_var/(.+)/' * * @author Brent Shepherd <*****@*****.**> * @since 1.0 * @url http://thereforei.am/2011/10/28/advanced-taxonomy-queries-with-pretty-urls/ */ function generateRewriteRulesForPostType($wpRewrite, $postType, $queryVars = array()) { if (!is_object($postType)) { $postType = get_post_type_object($postType); } $newRewriteRules = array(); $taxonomies = get_object_taxonomies($postType->name, 'objects'); // Add taxonomy filters to the query vars array foreach ($taxonomies as $taxonomy) { if ($taxonomy->query_var == 'category_name' || $taxonomy->query_var == 'post_tag') { $queryVars[] = $taxonomy->rewrite['slug']; } else { $queryVars[] = $taxonomy->query_var; } } // Loop over all the possible combinations of the query vars for ($i = 1; $i <= count($queryVars); $i++) { $newRewriteRule = $postType->rewrite['slug'] . '/'; $newQueryString = 'index.php?post_type=' . $postType->name; // Prepend the rewrites & queries for ($n = 1; $n <= $i; $n++) { $newRewriteRule .= '(' . implode('|', $queryVars) . ')/(.+?)/'; $newQueryString .= '&' . $wpRewrite->preg_index($n * 2 - 1) . '=' . $wpRewrite->preg_index($n * 2); } // Allow paging of filtered post type - WordPress expects 'page' in the URL but uses 'paged' in the query string so paging doesn't fit into our regex $newPagedRewriteRule = $newRewriteRule . 'page/([0-9]{1,})/'; $newPagedQueryString = $newQueryString . '&paged=' . $wpRewrite->preg_index($i * 2 + 1); // Make the trailing backslash optional $newPagedRewriteRule = $newPagedRewriteRule . '?$'; $newRewriteRule = $newRewriteRule . '?$'; // Add the new rewrites $newRewriteRules = array($newPagedRewriteRule => $newPagedQueryString, $newRewriteRule => $newQueryString) + $newRewriteRules; } $wpRewrite->rules = $newRewriteRules + $wpRewrite->rules; }