function getWpTemplate() { if (defined('WP_USE_THEMES') && WP_USE_THEMES) { $template = false; if (is_404() && ($template = get_404_template())) { } elseif (is_search() && ($template = get_search_template())) { } elseif (is_tax() && ($template = get_taxonomy_template())) { } elseif (is_front_page() && ($template = get_front_page_template())) { } elseif (is_home() && ($template = get_home_template())) { } elseif (is_attachment() && ($template = get_attachment_template())) { } elseif (is_single() && ($template = get_single_template())) { } elseif (is_page() && ($template = get_page_template())) { } elseif (is_category() && ($template = get_category_template())) { } elseif (is_tag() && ($template = get_tag_template())) { } elseif (is_author() && ($template = get_author_template())) { } elseif (is_date() && ($template = get_date_template())) { } elseif (is_archive() && ($template = get_archive_template())) { } elseif (is_comments_popup() && ($template = get_comments_popup_template())) { } elseif (is_paged() && ($template = get_paged_template())) { } else { $template = get_index_template(); } return str_replace(ABSPATH, '', $template); } else { return null; } }
/** * Enqueue required javascript libraries. * * @action: init **/ function js_setup() { if (is_single() || is_comments_popup() || is_admin()) { wp_enqueue_script('jquery'); wp_enqueue_script('jquery.textnode', '/' . PLUGINDIR . '/openid/files/jquery.textnode.min.js', array('jquery'), WPOPENID_PLUGIN_REVISION); wp_enqueue_script('jquery.xpath', '/' . PLUGINDIR . '/openid/files/jquery.xpath.min.js', array('jquery'), WPOPENID_PLUGIN_REVISION); wp_enqueue_script('openid', '/' . PLUGINDIR . '/openid/files/openid.min.js', array('jquery', 'jquery.textnode'), WPOPENID_PLUGIN_REVISION); } }
/** * Copy-pasta of wp-includes/template-loader.php */ private function load_template() { do_action('template_redirect'); $template = false; if (is_404() && ($template = get_404_template())) { } elseif (is_search() && ($template = get_search_template())) { } elseif (is_front_page() && ($template = get_front_page_template())) { } elseif (is_home() && ($template = get_home_template())) { } elseif (is_post_type_archive() && ($template = get_post_type_archive_template())) { } elseif (is_tax() && ($template = get_taxonomy_template())) { } elseif (is_attachment() && ($template = get_attachment_template())) { remove_filter('the_content', 'prepend_attachment'); } elseif (is_single() && ($template = get_single_template())) { } elseif (is_page() && ($template = get_page_template())) { } elseif (is_category() && ($template = get_category_template())) { } elseif (is_tag() && ($template = get_tag_template())) { } elseif (is_author() && ($template = get_author_template())) { } elseif (is_date() && ($template = get_date_template())) { } elseif (is_archive() && ($template = get_archive_template())) { } elseif (is_comments_popup() && ($template = get_comments_popup_template())) { } elseif (is_paged() && ($template = get_paged_template())) { } else { $template = get_index_template(); } /** * Filter the path of the current template before including it. * * @since 3.0.0 * * @param string $template The path of the template to include. */ if ($template = apply_filters('template_include', $template)) { $template_contents = file_get_contents($template); $included_header = $included_footer = false; if (false !== stripos($template_contents, 'get_header();')) { do_action('get_header', null); locate_template('header.php', true, false); $included_header = true; } include $template; if (false !== stripos($template_contents, 'get_footer();')) { do_action('get_footer', null); locate_template('footer.php', true, false); $included_footer = true; } if ($included_header && $included_footer) { global $wp_scripts; $wp_scripts->done = array(); } } return; }
function include_type() { global $gantry; $is_wp3 = version_compare($gantry->platform->platform_version, "3.0", ">="); $main_body_template = false; // get the main template page loaded $template_page = basename($gantry->retrieveTemp('template', 'page_name')); // load main body layout of the exact match is there (shortcut) if ('index.php' != strtolower($template_page) && ($main_body_template = $this->locate_type(array($template_page)))) { // see if we need to load any subcases of the mainbody for the template page used } elseif ($main_body_template = $this->get_taxonomy_page($template_page)) { } elseif ($main_body_template = $this->get_single_page($template_page)) { } elseif ($main_body_template = $this->get_page_page($template_page)) { } elseif ($main_body_template = $this->get_category_page($template_page)) { } elseif ($main_body_template = $this->get_tag_page($template_page)) { } elseif ($main_body_template = $this->get_author_page($template_page)) { // load based on query options (used for index.php template) } elseif (is_404() && ($main_body_template = $this->get_404_type())) { } elseif (is_search() && ($main_body_template = $this->get_search_type())) { } elseif (is_tax() && ($main_body_template = $this->get_taxonomy_type())) { } elseif ($is_wp3 && is_front_page() && ($main_body_template = $this->get_front_page_type())) { } elseif (is_home() && ($main_body_template = $this->get_home_type())) { } elseif (is_attachment() && ($main_body_template = $this->get_attachment_type())) { remove_filter('the_content', 'prepend_attachment'); } elseif (is_single() && ($main_body_template = $this->get_single_type())) { } elseif (is_page() && ($main_body_template = $this->get_page_type())) { } elseif (is_category() && ($main_body_template = $this->get_category_type())) { } elseif (is_tag() && ($main_body_template = $this->get_tag_type())) { } elseif (is_author() && ($main_body_template = $this->get_author_type())) { } elseif (is_date() && ($main_body_template = $this->get_date_type())) { } elseif (is_archive() && ($main_body_template = $this->get_archive_type())) { } elseif (is_comments_popup() && ($main_body_template = $this->get_comments_popup_type())) { } elseif (is_paged() && ($main_body_template = $this->get_paged_type())) { } else { $main_body_template = $this->get_index_type(); } if ($main_body_template = apply_filters('gantry_mainbody_include', $main_body_template)) { include $main_body_template; } return; }
function xtreme_get_template() { global $wp; if (defined('WP_USE_THEMES') && constant('WP_USE_THEMES')) { if (is_404() && ($template = get_404_template())) { return redefine_pagenow($template); } elseif (is_search() && ($template = get_search_template())) { return redefine_pagenow($template); } elseif (is_tax() && ($template = get_taxonomy_template())) { return redefine_pagenow($template); } elseif (is_front_page() && ($template = get_front_page_template())) { return redefine_pagenow($template); } elseif (is_home() && ($template = get_home_template())) { return redefine_pagenow($template); } elseif (is_attachment() && ($template = get_attachment_template())) { return redefine_pagenow($template); } elseif (is_single() && ($template = get_single_template())) { return redefine_pagenow($template); } elseif (is_page() && ($template = get_page_template())) { return redefine_pagenow($template); } elseif (is_category() && ($template = get_category_template())) { return redefine_pagenow($template); } elseif (is_tag() && ($template = get_tag_template())) { return redefine_pagenow($template); } elseif (is_author() && ($template = get_author_template())) { return redefine_pagenow($template); } elseif (is_date() && ($template = get_date_template())) { return redefine_pagenow($template); } elseif (is_archive() && ($template = get_archive_template())) { return redefine_pagenow($template); } elseif (is_comments_popup() && ($template = get_comments_popup_template())) { return redefine_pagenow($template); } elseif (is_paged() && ($template = get_paged_template())) { return redefine_pagenow($template); } else { $template = get_index_template(); return redefine_pagenow($template); } } }
function check_template() { if (is_404() && ($template = get_404_template())) { $this->template = $template; } elseif (is_search() && ($template = get_search_template())) { $this->template = $template; } elseif (is_tax() && ($template = get_taxonomy_template())) { $this->template = $template; } elseif (is_home() && ($template = get_home_template())) { $this->template = $template; } elseif (is_attachment() && ($template = get_attachment_template())) { $this->template = $template; } elseif (is_single() && ($template = get_single_template())) { $this->template = $template; } elseif (is_page() && ($template = get_page_template())) { $this->template = $template; } elseif (is_category() && ($template = get_category_template())) { $this->template = $template; } elseif (is_tag() && ($template = get_tag_template())) { $this->template = $template; } elseif (is_author() && ($template = get_author_template())) { $this->template = $template; } elseif (is_date() && ($template = get_date_template())) { $this->template = $template; } elseif (is_archive() && ($template = get_archive_template())) { $this->template = $template; } elseif (is_comments_popup() && ($template = get_comments_popup_template())) { $this->template = $template; } elseif (is_paged() && ($template = get_paged_template())) { $this->template = $template; } else { $this->template = function_exists('get_index_template') ? get_index_template() : TEMPLATEPATH . "/index.php"; } $this->template = apply_filters('template_include', $this->template); // Hook into the footer so we can echo the active template add_action('wp_footer', array(&$this, 'show_template'), 100); }
/** * Are likes visible in this context? * * Some of this code was taken and modified from sharing_display() to ensure * similar logic and filters apply here, too. */ function is_likes_visible() { global $wp_current_filter; // Used to check 'get_the_excerpt' filter global $post; // Used to apply 'sharing_show' filter // Never show on feeds or previews if (is_feed() || is_preview() || is_comments_popup()) { $enabled = false; // Not a feed or preview, so what is it? } else { if (in_the_loop()) { // If in the loop, check if the current post is likeable $enabled = $this->is_post_likeable(); } else { // Otherwise, check and see if likes are enabled sitewide $enabled = $this->is_enabled_sitewide(); } if (post_password_required()) { $enabled = false; } /** Other Checks ******************************************************/ // Do not show on excerpts if (in_array('get_the_excerpt', (array) $wp_current_filter)) { $enabled = false; // Sharing Setting Overrides **************************************** } else { // Single post if (is_singular('post')) { if (!$this->is_single_post_enabled()) { $enabled = false; } // Single page } elseif (is_page()) { if (!$this->is_single_page_enabled()) { $enabled = false; } // Attachment } elseif (is_attachment()) { if (!$this->is_attachment_enabled()) { $enabled = false; } // All other loops } elseif (!$this->is_index_enabled()) { $enabled = false; } } } // Check that the post is a public, published post. if ('attachment' == $post->post_type) { $post_status = get_post_status($post->post_parent); } else { $post_status = $post->post_status; } if ('publish' != $post_status) { $enabled = false; } // Run through the sharing filters $enabled = apply_filters('sharing_show', $enabled, $post); return (bool) apply_filters('wpl_is_likes_visible', $enabled); }
/** * Redirects incoming links to the proper URL based on the site url. * * Search engines consider www.somedomain.com and somedomain.com to be two * different URLs when they both go to the same location. This SEO enhancement * prevents penality for duplicate content by redirecting all incoming links to * one or the other. * * Prevents redirection for feeds, trackbacks, searches, comment popup, and * admin URLs. Does not redirect on IIS, page/post previews, and on form data. * * Will also attempt to find the correct link when a user enters a URL that does * not exist based on exact WordPress query. Will instead try to parse the URL * or query in an attempt to figure the correct page to go to. * * @since 2.3.0 * @uses $wp_rewrite * @uses $is_IIS * * @param string $requested_url Optional. The URL that was requested, used to * figure if redirect is needed. * @param bool $do_redirect Optional. Redirect to the new URL. * @return null|false|string Null, if redirect not needed. False, if redirect * not needed or the string of the URL */ function redirect_canonical($requested_url = null, $do_redirect = true) { global $wp_rewrite, $is_IIS, $wp_query, $wpdb; if (is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || isset($_POST) && count($_POST) || is_preview() || is_robots()) { return; } if (!$requested_url) { // build the URL in the address bar $requested_url = is_ssl() ? 'https://' : 'http://'; $requested_url .= $_SERVER['HTTP_HOST']; $requested_url .= $_SERVER['REQUEST_URI']; } $original = @parse_url($requested_url); if (false === $original) { return; } // Some PHP setups turn requests for / into /index.php in REQUEST_URI // See: http://trac.wordpress.org/ticket/5017 // See: http://trac.wordpress.org/ticket/7173 // Disabled, for now: // $original['path'] = preg_replace('|/index\.php$|', '/', $original['path']); $redirect = $original; $redirect_url = false; // Notice fixing if (!isset($redirect['path'])) { $redirect['path'] = ''; } if (!isset($redirect['query'])) { $redirect['query'] = ''; } if (is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p'))) { $vars = $wpdb->get_results($wpdb->prepare("SELECT post_type, post_parent FROM {$wpdb->posts} WHERE ID = %d", $id)); if (isset($vars[0]) && ($vars = $vars[0])) { if ('revision' == $vars->post_type && $vars->post_parent > 0) { $id = $vars->post_parent; } if ($redirect_url = get_permalink($id)) { $redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id', 'post_type'), $redirect['query']); } } } // These tests give us a WP-generated permalink if (is_404()) { // Redirect ?page_id, ?p=, ?attachment_id= to their respective url's $id = max(get_query_var('p'), get_query_var('page_id'), get_query_var('attachment_id')); if ($id && ($redirect_post = get_post($id))) { $post_type_obj = get_post_type_object($redirect_post->post_type); if ($post_type_obj->public) { $redirect_url = get_permalink($redirect_post); $redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id', 'post_type'), $redirect['query']); } } if (!$redirect_url) { $redirect_url = redirect_guess_404_permalink(); } } elseif (is_object($wp_rewrite) && $wp_rewrite->using_permalinks()) { // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101 if (is_attachment() && !empty($_GET['attachment_id']) && !$redirect_url) { if ($redirect_url = get_attachment_link(get_query_var('attachment_id'))) { $redirect['query'] = remove_query_arg('attachment_id', $redirect['query']); } } elseif (is_single() && !empty($_GET['p']) && !$redirect_url) { if ($redirect_url = get_permalink(get_query_var('p'))) { $redirect['query'] = remove_query_arg(array('p', 'post_type'), $redirect['query']); } if (get_query_var('page')) { $redirect_url = trailingslashit($redirect_url) . user_trailingslashit(get_query_var('page'), 'single_paged'); $redirect['query'] = remove_query_arg('page', $redirect['query']); } } elseif (is_single() && !empty($_GET['name']) && !$redirect_url) { if ($redirect_url = get_permalink($wp_query->get_queried_object_id())) { $redirect['query'] = remove_query_arg('name', $redirect['query']); } } elseif (is_page() && !empty($_GET['page_id']) && !$redirect_url) { if ($redirect_url = get_permalink(get_query_var('page_id'))) { $redirect['query'] = remove_query_arg('page_id', $redirect['query']); } } elseif (is_page() && !is_feed() && isset($wp_query->queried_object) && 'page' == get_option('show_on_front') && $wp_query->queried_object->ID == get_option('page_on_front') && !$redirect_url) { $redirect_url = home_url('/'); } elseif (is_home() && !empty($_GET['page_id']) && 'page' == get_option('show_on_front') && get_query_var('page_id') == get_option('page_for_posts') && !$redirect_url) { if ($redirect_url = get_permalink(get_option('page_for_posts'))) { $redirect['query'] = remove_query_arg('page_id', $redirect['query']); } } elseif (!empty($_GET['m']) && (is_year() || is_month() || is_day())) { $m = get_query_var('m'); switch (strlen($m)) { case 4: // Yearly $redirect_url = get_year_link($m); break; case 6: // Monthly $redirect_url = get_month_link(substr($m, 0, 4), substr($m, 4, 2)); break; case 8: // Daily $redirect_url = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2)); break; } if ($redirect_url) { $redirect['query'] = remove_query_arg('m', $redirect['query']); } // now moving on to non ?m=X year/month/day links } elseif (is_day() && get_query_var('year') && get_query_var('monthnum') && !empty($_GET['day'])) { if ($redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day'))) { $redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']); } } elseif (is_month() && get_query_var('year') && !empty($_GET['monthnum'])) { if ($redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum'))) { $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']); } } elseif (is_year() && !empty($_GET['year'])) { if ($redirect_url = get_year_link(get_query_var('year'))) { $redirect['query'] = remove_query_arg('year', $redirect['query']); } } elseif (is_author() && !empty($_GET['author']) && preg_match('|^[0-9]+$|', $_GET['author'])) { $author = get_userdata(get_query_var('author')); if (false !== $author && ($redirect_url = get_author_posts_url($author->ID, $author->user_nicename))) { $redirect['query'] = remove_query_arg('author', $redirect['query']); } } elseif (is_category() || is_tag() || is_tax()) { // Terms (Tags/categories) $term_count = 0; foreach (array('category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and') as $key) { $term_count += count($wp_query->query_vars[$key]); } $obj = $wp_query->get_queried_object(); if ($term_count <= 1 && !empty($obj->term_id) && ($tax_url = get_term_link((int) $obj->term_id, $obj->taxonomy)) && !is_wp_error($tax_url)) { if (is_category()) { $redirect['query'] = remove_query_arg(array('category_name', 'category', 'cat'), $redirect['query']); } elseif (is_tag()) { $redirect['query'] = remove_query_arg(array('tag', 'tag_id'), $redirect['query']); } elseif (is_tax()) { // Custom taxonomies will have a custom query var, remove those too: $tax = get_taxonomy($obj->taxonomy); if (false !== $tax->query_var) { $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']); } else { $redirect['query'] = remove_query_arg(array('term', 'taxonomy'), $redirect['query']); } } $tax_url = parse_url($tax_url); if (!empty($tax_url['query'])) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=.. parse_str($tax_url['query'], $query_vars); $redirect['query'] = add_query_arg($query_vars, $redirect['query']); } else { // Taxonomy is accessable via a "pretty-URL" $redirect['path'] = $tax_url['path']; } } } elseif (is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false) { $category = get_term_by('slug', get_query_var('category_name'), 'category'); $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids')); if (!$category || is_wp_error($category) || !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms)) { $redirect_url = get_permalink($wp_query->get_queried_object_id()); } } // paging and feeds if (get_query_var('paged') || is_feed() || get_query_var('cpage')) { if (!$redirect_url) { $redirect_url = $requested_url; } $paged_redirect = @parse_url($redirect_url); while (preg_match('#/page/?[0-9]+?(/+)?$#', $paged_redirect['path']) || preg_match('#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $paged_redirect['path']) || preg_match('#/comment-page-[0-9]+(/+)?$#', $paged_redirect['path'])) { // Strip off paging and feed $paged_redirect['path'] = preg_replace('#/page/?[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing paging $paged_redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $paged_redirect['path']); // strip off feed endings $paged_redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing comment paging } $addl_path = ''; if (is_feed()) { $addl_path = !empty($addl_path) ? trailingslashit($addl_path) : ''; if (get_query_var('withcomments')) { $addl_path .= 'comments/'; } $addl_path .= user_trailingslashit('feed/' . (get_default_feed() == get_query_var('feed') || 'feed' == get_query_var('feed') ? '' : get_query_var('feed')), 'feed'); $redirect['query'] = remove_query_arg('feed', $redirect['query']); } if (get_query_var('paged') > 0) { $paged = get_query_var('paged'); $redirect['query'] = remove_query_arg('paged', $redirect['query']); if (!is_feed()) { if ($paged > 1 && !is_single()) { $addl_path = (!empty($addl_path) ? trailingslashit($addl_path) : '') . user_trailingslashit("page/{$paged}", 'paged'); } elseif (!is_single()) { $addl_path = !empty($addl_path) ? trailingslashit($addl_path) : ''; } } elseif ($paged > 1) { $redirect['query'] = add_query_arg('paged', $paged, $redirect['query']); } } if (get_option('page_comments') && ('newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 || 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1)) { $addl_path = (!empty($addl_path) ? trailingslashit($addl_path) : '') . user_trailingslashit('comment-page-' . get_query_var('cpage'), 'commentpaged'); $redirect['query'] = remove_query_arg('cpage', $redirect['query']); } $paged_redirect['path'] = user_trailingslashit(preg_replace('|/index.php/?$|', '/', $paged_redirect['path'])); // strip off trailing /index.php/ if (!empty($addl_path) && $wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false) { $paged_redirect['path'] = trailingslashit($paged_redirect['path']) . 'index.php/'; } if (!empty($addl_path)) { $paged_redirect['path'] = trailingslashit($paged_redirect['path']) . $addl_path; } $redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path']; $redirect['path'] = $paged_redirect['path']; } } // tack on any additional query vars $redirect['query'] = preg_replace('#^\\??&*?#', '', $redirect['query']); if ($redirect_url && !empty($redirect['query'])) { if (strpos($redirect_url, '?') !== false) { $redirect_url .= '&'; } else { $redirect_url .= '?'; } $redirect_url .= $redirect['query']; } if ($redirect_url) { $redirect = @parse_url($redirect_url); } // www.example.com vs example.com $user_home = @parse_url(home_url()); if (!empty($user_home['host'])) { $redirect['host'] = $user_home['host']; } if (empty($user_home['path'])) { $user_home['path'] = '/'; } // Handle ports if (!empty($user_home['port'])) { $redirect['port'] = $user_home['port']; } else { unset($redirect['port']); } // trailing /index.php $redirect['path'] = preg_replace('|/index.php/*?$|', '/', $redirect['path']); // Remove trailing spaces from the path $redirect['path'] = preg_replace('#(%20| )+$#', '', $redirect['path']); if (!empty($redirect['query'])) { // Remove trailing spaces from certain terminating query string args $redirect['query'] = preg_replace('#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query']); // Clean up empty query strings $redirect['query'] = trim(preg_replace('#(^|&)(p|page_id|cat|tag)=?(&|$)#', '&', $redirect['query']), '&'); // Remove redundant leading ampersands $redirect['query'] = preg_replace('#^\\??&*?#', '', $redirect['query']); } // strip /index.php/ when we're not using PATHINFO permalinks if (!$wp_rewrite->using_index_permalinks()) { $redirect['path'] = str_replace('/index.php/', '/', $redirect['path']); } // trailing slashes if (is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_front_page() || is_front_page() && get_query_var('paged') > 1)) { $user_ts_type = ''; if (get_query_var('paged') > 0) { $user_ts_type = 'paged'; } else { foreach (array('single', 'category', 'page', 'day', 'month', 'year', 'home') as $type) { $func = 'is_' . $type; if (call_user_func($func)) { $user_ts_type = $type; break; } } } $redirect['path'] = user_trailingslashit($redirect['path'], $user_ts_type); } elseif (is_front_page()) { $redirect['path'] = trailingslashit($redirect['path']); } // Strip multiple slashes out of the URL if (strpos($redirect['path'], '//') > -1) { $redirect['path'] = preg_replace('|/+|', '/', $redirect['path']); } // Always trailing slash the Front Page URL if (trailingslashit($redirect['path']) == trailingslashit($user_home['path'])) { $redirect['path'] = trailingslashit($redirect['path']); } // Ignore differences in host capitalization, as this can lead to infinite redirects // Only redirect no-www <=> yes-www if (strtolower($original['host']) == strtolower($redirect['host']) || strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host'])) { $redirect['host'] = $original['host']; } $compare_original = array($original['host'], $original['path']); if (!empty($original['port'])) { $compare_original[] = $original['port']; } if (!empty($original['query'])) { $compare_original[] = $original['query']; } $compare_redirect = array($redirect['host'], $redirect['path']); if (!empty($redirect['port'])) { $compare_redirect[] = $redirect['port']; } if (!empty($redirect['query'])) { $compare_redirect[] = $redirect['query']; } if ($compare_original !== $compare_redirect) { $redirect_url = $redirect['scheme'] . '://' . $redirect['host']; if (!empty($redirect['port'])) { $redirect_url .= ':' . $redirect['port']; } $redirect_url .= $redirect['path']; if (!empty($redirect['query'])) { $redirect_url .= '?' . $redirect['query']; } } if (!$redirect_url || $redirect_url == $requested_url) { return false; } // Note that you can use the "redirect_canonical" filter to cancel a canonical redirect for whatever reason by returning FALSE $redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url); if (!$redirect_url || $redirect_url == $requested_url) { // yes, again -- in case the filter aborted the request return false; } if ($do_redirect) { // protect against chained redirects if (!redirect_canonical($redirect_url, false)) { wp_redirect($redirect_url, 301); exit; } else { // Debug // die("1: $redirect_url<br />2: " . redirect_canonical( $redirect_url, false ) ); return false; } } else { return $redirect_url; } }
/** * Redirects incoming links to the proper URL based on the site url. * * Search engines consider www.somedomain.com and somedomain.com to be two * different URLs when they both go to the same location. This SEO enhancement * prevents penality for duplicate content by redirecting all incoming links to * one or the other. * * Prevents redirection for feeds, trackbacks, searches, comment popup, and * admin URLs. Does not redirect on IIS, page/post previews, and on form data. * * Will also attempt to find the correct link when a user enters a URL that does * not exist based on exact WordPress query. Will instead try to parse the URL * or query in an attempt to figure the correct page to go to. * * @since 2.3.0 * @uses $wp_rewrite * @uses $is_IIS * * @param string $requested_url Optional. The URL that was requested, used to * figure if redirect is needed. * @param bool $do_redirect Optional. Redirect to the new URL. * @return null|false|string Null, if redirect not needed. False, if redirect * not needed or the string of the URL */ function redirect_canonical($requested_url=null, $do_redirect=true) { global $wp_rewrite, $is_IIS, $wp_query, $wpdb; if ( is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || ( isset($_POST) && count($_POST) ) || is_preview() || is_robots() ) return; if ( !$requested_url ) { // build the URL in the address bar $requested_url = ( !empty($_SERVER['HTTPS'] ) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://'; $requested_url .= $_SERVER['HTTP_HOST']; $requested_url .= $_SERVER['REQUEST_URI']; } $original = @parse_url($requested_url); if ( false === $original ) return; // Some PHP setups turn requests for / into /index.php in REQUEST_URI // See: http://trac.wordpress.org/ticket/5017 // See: http://trac.wordpress.org/ticket/7173 // Disabled, for now: // $original['path'] = preg_replace('|/index\.php$|', '/', $original['path']); $redirect = $original; $redirect_url = false; // Notice fixing if ( !isset($redirect['path']) ) $redirect['path'] = ''; if ( !isset($redirect['query']) ) $redirect['query'] = ''; if ( is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p')) ) { $vars = $wpdb->get_results( $wpdb->prepare("SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id) ); if ( isset($vars[0]) && $vars = $vars[0] ) { if ( 'revision' == $vars->post_type && $vars->post_parent > 0 ) $id = $vars->post_parent; if ( $redirect_url = get_permalink($id) ) $redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id'), $redirect['query']); } } // These tests give us a WP-generated permalink if ( is_404() ) { $redirect_url = redirect_guess_404_permalink(); } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) { // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101 if ( is_single() && !empty($_GET['p']) && ! $redirect_url ) { if ( $redirect_url = get_permalink(get_query_var('p')) ) $redirect['query'] = remove_query_arg('p', $redirect['query']); if ( get_query_var( 'page' ) ) { $redirect_url = trailingslashit( $redirect_url ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' ); $redirect['query'] = remove_query_arg( 'page', $redirect['query'] ); } } elseif ( is_page() && !empty($_GET['page_id']) && ! $redirect_url ) { if ( $redirect_url = get_permalink(get_query_var('page_id')) ) $redirect['query'] = remove_query_arg('page_id', $redirect['query']); } elseif ( !empty($_GET['m']) && ( is_year() || is_month() || is_day() ) ) { $m = get_query_var('m'); switch ( strlen($m) ) { case 4: // Yearly $redirect_url = get_year_link($m); break; case 6: // Monthly $redirect_url = get_month_link( substr($m, 0, 4), substr($m, 4, 2) ); break; case 8: // Daily $redirect_url = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2)); break; } if ( $redirect_url ) $redirect['query'] = remove_query_arg('m', $redirect['query']); // now moving on to non ?m=X year/month/day links } elseif ( is_day() && get_query_var('year') && get_query_var('monthnum') && !empty($_GET['day']) ) { if ( $redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day')) ) $redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']); } elseif ( is_month() && get_query_var('year') && !empty($_GET['monthnum']) ) { if ( $redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum')) ) $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']); } elseif ( is_year() && !empty($_GET['year']) ) { if ( $redirect_url = get_year_link(get_query_var('year')) ) $redirect['query'] = remove_query_arg('year', $redirect['query']); } elseif ( is_category() && !empty($_GET['cat']) ) { if ( $redirect_url = get_category_link(get_query_var('cat')) ) $redirect['query'] = remove_query_arg('cat', $redirect['query']); } elseif ( is_author() && !empty($_GET['author']) ) { $author = get_userdata(get_query_var('author')); if ( false !== $author && $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) ) $redirect['query'] = remove_query_arg('author', $redirect['author']); } // paging and feeds if ( get_query_var('paged') || is_feed() || get_query_var('cpage') ) { if ( !$redirect_url ) $redirect_url = $requested_url; $paged_redirect = @parse_url($redirect_url); while ( preg_match( '#/page/[0-9]+?(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/comment-page-[0-9]+(/+)?$#', $paged_redirect['path'] ) ) { // Strip off paging and feed $paged_redirect['path'] = preg_replace('#/page/[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing paging $paged_redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+)?$#', '/', $paged_redirect['path']); // strip off feed endings $paged_redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing comment paging } $addl_path = ''; if ( is_feed() ) { $addl_path = !empty( $addl_path ) ? trailingslashit($addl_path) : ''; if ( get_query_var( 'withcomments' ) ) $addl_path .= 'comments/'; $addl_path .= user_trailingslashit( 'feed/' . ( ( 'rss2' == get_query_var('feed') || 'feed' == get_query_var('feed') ) ? '' : get_query_var('feed') ), 'feed' ); $redirect['query'] = remove_query_arg( 'feed', $redirect['query'] ); } if ( get_query_var('paged') > 0 ) { $paged = get_query_var('paged'); $redirect['query'] = remove_query_arg( 'paged', $redirect['query'] ); if ( !is_feed() ) { if ( $paged > 1 && !is_single() ) { $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit("page/$paged", 'paged'); } elseif ( !is_single() ) { $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit($paged_redirect['path'], 'paged'); } } elseif ( $paged > 1 ) { $redirect['query'] = add_query_arg( 'paged', $paged, $redirect['query'] ); } } if ( get_option('page_comments') && ( ( 'newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 ) || ( 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1 ) ) ) { $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( 'comment-page-' . get_query_var('cpage'), 'commentpaged' ); $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] ); } $paged_redirect['path'] = user_trailingslashit( preg_replace('|/index.php/?$|', '/', $paged_redirect['path']) ); // strip off trailing /index.php/ if ( !empty( $addl_path ) && $wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false ) $paged_redirect['path'] = trailingslashit($paged_redirect['path']) . 'index.php/'; if ( !empty( $addl_path ) ) $paged_redirect['path'] = trailingslashit($paged_redirect['path']) . $addl_path; $redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path']; $redirect['path'] = $paged_redirect['path']; } } // tack on any additional query vars $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); if ( $redirect_url && !empty($redirect['query']) ) { if ( strpos($redirect_url, '?') !== false ) $redirect_url .= '&'; else $redirect_url .= '?'; $redirect_url .= $redirect['query']; } if ( $redirect_url ) $redirect = @parse_url($redirect_url); // www.example.com vs example.com $user_home = @parse_url(get_option('home')); if ( !empty($user_home['host']) ) $redirect['host'] = $user_home['host']; if ( empty($user_home['path']) ) $user_home['path'] = '/'; // Handle ports if ( !empty($user_home['port']) ) $redirect['port'] = $user_home['port']; else unset($redirect['port']); // trailing /index.php $redirect['path'] = preg_replace('|/index.php/*?$|', '/', $redirect['path']); // Remove trailing spaces from the path $redirect['path'] = preg_replace( '#(%20| )+$#', '', $redirect['path'] ); if ( !empty( $redirect['query'] ) ) { // Remove trailing spaces from certain terminating query string args $redirect['query'] = preg_replace( '#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query'] ); // Clean up empty query strings $redirect['query'] = trim(preg_replace( '#(^|&)(p|page_id|cat|tag)=?(&|$)#', '&', $redirect['query']), '&'); // Remove redundant leading ampersands $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); } // strip /index.php/ when we're not using PATHINFO permalinks if ( !$wp_rewrite->using_index_permalinks() ) $redirect['path'] = str_replace('/index.php/', '/', $redirect['path']); // trailing slashes if ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_front_page() || ( is_front_page() && (get_query_var('paged') > 1) ) ) ) { $user_ts_type = ''; if ( get_query_var('paged') > 0 ) { $user_ts_type = 'paged'; } else { foreach ( array('single', 'category', 'page', 'day', 'month', 'year', 'home') as $type ) { $func = 'is_' . $type; if ( call_user_func($func) ) { $user_ts_type = $type; break; } } } $redirect['path'] = user_trailingslashit($redirect['path'], $user_ts_type); } elseif ( is_front_page() ) { $redirect['path'] = trailingslashit($redirect['path']); } // Always trailing slash the Front Page URL if ( trailingslashit( $redirect['path'] ) == trailingslashit( $user_home['path'] ) ) $redirect['path'] = trailingslashit($redirect['path']); // Ignore differences in host capitalization, as this can lead to infinite redirects // Only redirect no-www <=> yes-www if ( strtolower($original['host']) == strtolower($redirect['host']) || ( strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host']) ) ) $redirect['host'] = $original['host']; $compare_original = array($original['host'], $original['path']); if ( !empty( $original['port'] ) ) $compare_original[] = $original['port']; if ( !empty( $original['query'] ) ) $compare_original[] = $original['query']; $compare_redirect = array($redirect['host'], $redirect['path']); if ( !empty( $redirect['port'] ) ) $compare_redirect[] = $redirect['port']; if ( !empty( $redirect['query'] ) ) $compare_redirect[] = $redirect['query']; if ( $compare_original !== $compare_redirect ) { $redirect_url = $redirect['scheme'] . '://' . $redirect['host']; if ( !empty($redirect['port']) ) $redirect_url .= ':' . $redirect['port']; $redirect_url .= $redirect['path']; if ( !empty($redirect['query']) ) $redirect_url .= '?' . $redirect['query']; } if ( !$redirect_url || $redirect_url == $requested_url ) return false; // Note that you can use the "redirect_canonical" filter to cancel a canonical redirect for whatever reason by returning FALSE $redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url); if ( !$redirect_url || $redirect_url == $requested_url ) // yes, again -- in case the filter aborted the request return false; if ( $do_redirect ) { // protect against chained redirects if ( !redirect_canonical($redirect_url, false) ) { wp_redirect($redirect_url, 301); exit(); } else { // Debug // die("1: $redirect_url<br />2: " . redirect_canonical( $redirect_url, false ) ); return false; } } else { return $redirect_url; } }
/** * Are likes visible in this context? * * Some of this code was taken and modified from sharing_display() to ensure * similar logic and filters apply here, too. */ function is_likes_visible() { global $post, $wp_current_filter; // Used to apply 'sharing_show' filter // Never show on feeds or previews if (is_feed() || is_preview() || is_comments_popup()) { $enabled = false; // Not a feed or preview, so what is it? } else { if (in_the_loop()) { // If in the loop, check if the current post is likeable $enabled = $this->is_post_likeable(); } else { // Otherwise, check and see if likes are enabled sitewide $enabled = $this->is_enabled_sitewide(); } if (post_password_required()) { $enabled = false; } if (in_array('get_the_excerpt', (array) $wp_current_filter)) { $enabled = false; } // Sharing Setting Overrides **************************************** // Single post including custom post types if (is_single()) { if (!$this->is_single_post_enabled($post->post_type)) { $enabled = false; } // Single page } elseif (is_page() && !is_front_page()) { if (!$this->is_single_page_enabled()) { $enabled = false; } // Attachment } elseif (is_attachment()) { if (!$this->is_attachment_enabled()) { $enabled = false; } // All other loops } elseif (!$this->is_index_enabled()) { $enabled = false; } } if (is_object($post)) { // Check that the post is a public, published post. if ('attachment' == $post->post_type) { $post_status = get_post_status($post->post_parent); } else { $post_status = $post->post_status; } if ('publish' != $post_status) { $enabled = false; } } // Run through the sharing filters /** This filter is documented in modules/sharedaddy/sharing-service.php */ $enabled = apply_filters('sharing_show', $enabled, $post); /** * Filters whether the Likes should be visible or not. * Allows overwriting the options set in Settings > Sharing. * * @since 2.2.0 * * @param bool $enabled Should the Likes be visible? */ return (bool) apply_filters('wpl_is_likes_visible', $enabled); }
public function check_canonical_url($requested_url = '', $do_redirect = true) { global $wp_query, $post, $is_IIS; // don't redirect in same cases as WP if (is_trackback() || is_search() || is_comments_popup() || is_admin() || is_preview() || is_robots() || $is_IIS && !iis7_supports_permalinks()) { return; } // don't redirect mysite.com/?attachment_id= to mysite.com/en/?attachment_id= if (1 == $this->options['force_lang'] && is_attachment() && isset($_GET['attachment_id'])) { return; } // if the default language code is not hidden and the static front page url contains the page name // the customizer lands here and the code below would redirect to the list of posts if (isset($_POST['wp_customize'], $_POST['customized'])) { return; } // don't redirect if we are on a static front page if ($this->options['redirect_lang'] && isset($this->page_on_front) && is_page($this->page_on_front)) { return; } if (empty($requested_url)) { $requested_url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; } if (is_single() || is_page()) { if (isset($post->ID) && $this->model->is_translated_post_type($post->post_type)) { $language = $this->model->get_post_language((int) $post->ID); } } elseif (is_category() || is_tag() || is_tax()) { $obj = $wp_query->get_queried_object(); if ($this->model->is_translated_taxonomy($obj->taxonomy)) { $language = $this->model->get_term_language((int) $obj->term_id); } } elseif ($wp_query->is_posts_page) { $obj = $wp_query->get_queried_object(); $language = $this->model->get_post_language((int) $obj->ID); } if (empty($language)) { $language = $this->curlang; $redirect_url = $requested_url; } else { // first get the canonical url evaluated by WP $redirect_url = !($redirect_url = redirect_canonical($requested_url, false)) ? $requested_url : $redirect_url; // then get the right language code in url $redirect_url = $this->options['force_lang'] ? $this->links_model->switch_language_in_link($redirect_url, $language) : $this->links_model->remove_language_from_link($redirect_url); // works only for default permalinks } // allow plugins to change the redirection or even cancel it by setting $redirect_url to false $redirect_url = apply_filters('pll_check_canonical_url', $redirect_url, $language); // the language is not correctly set so let's redirect to the correct url for this object if ($do_redirect && $redirect_url && $requested_url != $redirect_url) { wp_redirect($redirect_url, 301); exit; } return $redirect_url; }
} else if ( is_page() && get_page_template() ) { include(get_page_template()); exit; } else if ( is_category() && get_category_template()) { include(get_category_template()); exit; } else if ( is_author() && get_author_template() ) { include(get_author_template()); exit; } else if ( is_date() && get_date_template() ) { include(get_date_template()); exit; } else if ( is_archive() && get_archive_template() ) { include(get_archive_template()); exit; } else if ( is_comments_popup() && get_comments_popup_template() ) { include(get_comments_popup_template()); exit; } else if ( is_paged() && get_paged_template() ) { include(get_paged_template()); exit; } else if ( file_exists(TEMPLATEPATH . "/index.php") ) { include(TEMPLATEPATH . "/index.php"); exit; } } else { // Process feeds and trackbacks even if not using themes. if ( is_feed() && empty($doing_rss) ) { include(ABSPATH . '/wp-feed.php'); exit; } else if ( is_trackback() && empty($doing_trackback) ) {
/** * Dynamic body class based on page * * @since 0.1 */ function hybrid_body_class() { global $wp_query, $hybrid_settings; $class = array(); if (is_front_page() || is_home()) { $class[] = 'home'; $class[] = 'front-page'; } elseif (is_attachment()) { global $post; $class[] = 'attachment'; if (wp_attachment_is_image($post->ID)) { $class[] = 'attachment-image'; } $mime = get_post_mime_type($post->ID); $class[] = 'attachment-' . str_replace('/', '-', $mime); } elseif (is_single()) { $class[] = 'single'; $class[] = 'single-' . $wp_query->post->ID; if (function_exists('is_sticky')) { if (is_sticky($wp_query->post->ID)) { $class[] = 'single-sticky'; } } } elseif (is_page()) { $class[] = 'page page-' . $wp_query->post->ID; if (is_page_template()) { $class[] = 'page-template'; $class[] = 'page-template-' . str_replace('.php', '', get_post_meta($wp_query->post->ID, '_wp_page_template', true)); } } elseif (is_category()) { $cat = $wp_query->get_queried_object(); $class[] = 'category'; $class[] = 'category-' . $cat->slug; } elseif (is_tag()) { $tags = $wp_query->get_queried_object(); $class[] = 'tag'; $class[] = 'tag-' . $tags->slug; } elseif (is_search()) { $class[] = 'search'; } elseif (is_404()) { $class[] = 'error-404'; } elseif (is_year()) { $class[] = 'year'; } elseif (is_month()) { $class[] = 'month'; } elseif (is_day()) { $class[] = 'day'; } elseif (is_time()) { $class[] = 'time'; } elseif (is_author()) { $author = $wp_query->get_queried_object(); $class[] = 'author'; $class[] = ' author-' . $author->user_nicename; } if (is_user_logged_in()) { $class[] = 'logged-in'; } else { $class[] = 'not-logged-in'; } if (is_date()) { $class[] = 'date'; } if (is_archive()) { $class[] = 'archive'; } if (is_paged()) { $class[] = 'paged'; } if ((($page = $wp_query->get('paged')) || ($page = $wp_query->get('page'))) && $page > 1) { $class[] = 'paged'; $class[] = 'paged-' . $page; if (is_home() || is_front_page()) { $class[] = 'home-paged-' . $page; } elseif (is_attachment()) { $class[] = 'attachment-paged-' . $page; } elseif (is_single()) { $class[] = 'single-paged-' . $page; } elseif (is_page()) { $class[] = 'page-paged-' . $page; } elseif (is_category()) { $class[] = 'category-paged-' . $page; } elseif (is_tag()) { $class[] = 'tag-paged-' . $page; } elseif (is_date()) { $class[] = 'date-paged-' . $page; } elseif (is_author()) { $class[] = 'author-paged-' . $page; } elseif (is_search()) { $class[] = 'search-paged-' . $page; } } if (is_comments_popup()) { $class[] = 'comments-popup'; } if ($hybrid_settings['primary_inserts_default']) { if (!is_sidebar_active(__('Primary Home', 'hybrid')) && !is_sidebar_active(hybrid_primary_var())) { $class[] = 'no-primary-widgets'; $no_primary_widgets = true; } } else { if (!is_sidebar_active(hybrid_primary_var())) { $class[] = 'no-primary-widgets'; $no_primary_widgets = true; } } if ($hybrid_settings['secondary_inserts_default']) { if (!is_sidebar_active(__('Secondary Home', 'hybrid')) && !is_sidebar_active(hybrid_secondary_var())) { $class[] = 'no-secondary-widgets'; $no_secondary_widgets = true; } } else { if (!is_sidebar_active(hybrid_secondary_var())) { $class[] = 'no-secondary-widgets'; $no_secondary_widgets = true; } } if (is_page_template('no-widgets.php')) { $class[] = 'no-widgets'; $no_widgets = true; } if ($no_widgets || $no_primary_widgets && $no_secondary_widgets) { $class[] = 'no-default-widgets'; } else { $class[] = 'has-widgets'; } $class = join(' ', $class); echo $class; }
/** * Print debug information regarding the current state of the page to the screen. * * @access public * @static * @param array $options * @param bool $comment (default: false) * @return void */ public static function debug_info(array $options, $comment = false) { global $post; $output = array(); $output[] = $comment ? '<!--' : '<pre>'; $output[] = '######################## HaG DEBUG INFO ########################'; $output[] = sprintf('404: %b', is_404()); $output[] = sprintf('Search: %b', is_search()); $output[] = sprintf('Archive: %b', is_archive()); $output[] = sprintf('Custom Taxonomy Archive: %b', is_tax()); $output[] = sprintf('Category Archive: %b', is_category()); $output[] = sprintf('Tag Archive: %b', is_tag()); $output[] = sprintf('Author Archive: %b', is_author()); $output[] = sprintf('Date Archive: %b', is_date()); $output[] = sprintf('Year Archive: %b', is_year()); $output[] = sprintf('Month Archive: %b', is_month()); $output[] = sprintf('Day Archive: %b', is_day()); $output[] = sprintf('Custom Post-Type Archive: %b', is_post_type_archive()); $output[] = sprintf('Paged: %b', is_paged()); $output[] = sprintf('Singular Page: %b', is_singular()); $output[] = sprintf('Single Post Page: %b', is_single()); $output[] = sprintf('Attachment Post: %b', is_attachment()); $output[] = sprintf('Static Page: %b', is_page()); $output[] = sprintf('Custom Static Page: %b', is_page_template()); $output[] = sprintf('Site Front Page: %b', is_front_page()); $output[] = sprintf('Posts Home Page: %b', is_home()); $output[] = sprintf('Comments Popup Page: %b', is_comments_popup()); $output[] = '######################## QUERY ############################'; ob_start(); var_dump(get_queried_object()); $output[] = $comment ? ob_get_clean() : htmlentities(ob_get_clean()); $output[] = '######################## $POST ########################'; ob_start(); var_dump($post); $output[] = $comment ? ob_get_clean() : htmlentities(ob_get_clean()); $output[] = '######################## $OPTIONS ########################'; ob_start(); var_dump($options); $output[] = $comment ? ob_get_clean() : htmlentities(ob_get_clean()); $output[] = $comment ? '-->' : '</pre>'; echo implode(PHP_EOL, $output); }
/** * Are likes visible in this context? * * Some of this code was taken and modified from sharing_display() to ensure * similar logic and filters apply here, too. */ function is_likes_visible() { require_once JETPACK__PLUGIN_DIR . '/sync/class.jetpack-sync-settings.php'; if (Jetpack_Sync_Settings::is_syncing()) { return false; } global $post, $wp_current_filter; // Used to apply 'sharing_show' filter // @todo: Remove this block when 4.5 is the minimum global $wp_version; $comment_popup = false; if (version_compare($wp_version, '4.5-alpha', '<=')) { $comment_popup = is_comments_popup(); } // End 4.5 conditional block. // Never show on feeds or previews if (is_feed() || is_preview() || $comment_popup) { // @todo: Remove $comment_popup when 4.5 is minimum. $enabled = false; // Not a feed or preview, so what is it? } else { if (in_the_loop()) { // If in the loop, check if the current post is likeable $enabled = $this->is_post_likeable(); } else { // Otherwise, check and see if likes are enabled sitewide $enabled = $this->is_enabled_sitewide(); } if (post_password_required()) { $enabled = false; } if (in_array('get_the_excerpt', (array) $wp_current_filter)) { $enabled = false; } // Sharing Setting Overrides **************************************** // Single post including custom post types if (is_single()) { if (!$this->is_single_post_enabled($post->post_type)) { $enabled = false; } // Single page } elseif (is_page() && !is_front_page()) { if (!$this->is_single_page_enabled()) { $enabled = false; } // Attachment } elseif (is_attachment()) { if (!$this->is_attachment_enabled()) { $enabled = false; } // All other loops } elseif (!$this->is_index_enabled()) { $enabled = false; } } if (is_object($post)) { // Check that the post is a public, published post. if ('attachment' == $post->post_type) { $post_status = get_post_status($post->post_parent); } else { $post_status = $post->post_status; } if ('publish' != $post_status) { $enabled = false; } } // Run through the sharing filters /** This filter is documented in modules/sharedaddy/sharing-service.php */ $enabled = apply_filters('sharing_show', $enabled, $post); /** * Filters whether the Likes should be visible or not. * Allows overwriting the options set in Settings > Sharing. * * @module likes * * @since 2.2.0 * * @param bool $enabled Should the Likes be visible? */ return (bool) apply_filters('wpl_is_likes_visible', $enabled); }
/** * Enqueue required javascript libraries. * * @action: init **/ function openid_js_setup() { if (is_single() || is_comments_popup() || is_admin()) { wp_enqueue_script('jquery'); //wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script('jquery.textnode', openid_plugin_url() . '/f/jquery.textnode.min.js', array('jquery'), OPENID_PLUGIN_REVISION); wp_enqueue_script('jquery.xpath', openid_plugin_url() . '/f/jquery.xpath.min.js', array('jquery'), OPENID_PLUGIN_REVISION); $js_file = defined('WP_DEBUG') && WP_DEBUG ? 'openid.js' : 'openid.min.js'; wp_enqueue_script('openid', openid_plugin_url() . '/f/' . $js_file, array('jquery', 'jquery.textnode'), OPENID_PLUGIN_REVISION); } }
/** * Redirects incoming links to the proper URL based on the site url. * * Search engines consider www.somedomain.com and somedomain.com to be two * different URLs when they both go to the same location. This SEO enhancement * prevents penalty for duplicate content by redirecting all incoming links to * one or the other. * * Prevents redirection for feeds, trackbacks, searches, comment popup, and * admin URLs. Does not redirect on IIS, page/post previews, and on form data. * * Will also attempt to find the correct link when a user enters a URL that does * not exist based on exact WordPress query. Will instead try to parse the URL * or query in an attempt to figure the correct page to go to. * * @since 2.3.0 * @uses $wp_rewrite * @uses $is_IIS * * @param string $requested_url Optional. The URL that was requested, used to * figure if redirect is needed. * @param bool $do_redirect Optional. Redirect to the new URL. * @return null|false|string Null, if redirect not needed. False, if redirect * not needed or the string of the URL */ function redirect_canonical( $requested_url = null, $do_redirect = true ) { global $wp_rewrite, $is_IIS, $wp_query, $wpdb; if ( is_trackback() || is_search() || is_comments_popup() || is_admin() || !empty($_POST) || is_preview() || is_robots() || $is_IIS ) return; if ( !$requested_url ) { // build the URL in the address bar $requested_url = is_ssl() ? 'https://' : 'http://'; $requested_url .= $_SERVER['HTTP_HOST']; $requested_url .= $_SERVER['REQUEST_URI']; } $original = @parse_url($requested_url); if ( false === $original ) return; // Some PHP setups turn requests for / into /index.php in REQUEST_URI // See: http://trac.wordpress.org/ticket/5017 // See: http://trac.wordpress.org/ticket/7173 // Disabled, for now: // $original['path'] = preg_replace('|/index\.php$|', '/', $original['path']); $redirect = $original; $redirect_url = false; // Notice fixing if ( !isset($redirect['path']) ) $redirect['path'] = ''; if ( !isset($redirect['query']) ) $redirect['query'] = ''; if ( is_feed() && ( $id = get_query_var( 'p' ) ) ) { if ( $redirect_url = get_post_comments_feed_link( $id, get_query_var( 'feed' ) ) ) { $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed'), $redirect_url ); $redirect['path'] = parse_url( $redirect_url, PHP_URL_PATH ); } } if ( is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p')) ) { $vars = $wpdb->get_results( $wpdb->prepare("SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id) ); if ( isset($vars[0]) && $vars = $vars[0] ) { if ( 'revision' == $vars->post_type && $vars->post_parent > 0 ) $id = $vars->post_parent; if ( $redirect_url = get_permalink($id) ) $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url ); } } // These tests give us a WP-generated permalink if ( is_404() ) { // Redirect ?page_id, ?p=, ?attachment_id= to their respective url's $id = max( get_query_var('p'), get_query_var('page_id'), get_query_var('attachment_id') ); if ( $id && $redirect_post = get_post($id) ) { $post_type_obj = get_post_type_object($redirect_post->post_type); if ( $post_type_obj->public ) { $redirect_url = get_permalink($redirect_post); $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url ); } } if ( ! $redirect_url ) { if ( $redirect_url = redirect_guess_404_permalink( $requested_url ) ) { $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url ); } } } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) { // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101 if ( is_attachment() && !empty($_GET['attachment_id']) && ! $redirect_url ) { if ( $redirect_url = get_attachment_link(get_query_var('attachment_id')) ) $redirect['query'] = remove_query_arg('attachment_id', $redirect['query']); } elseif ( is_single() && !empty($_GET['p']) && ! $redirect_url ) { if ( $redirect_url = get_permalink(get_query_var('p')) ) $redirect['query'] = remove_query_arg(array('p', 'post_type'), $redirect['query']); } elseif ( is_single() && !empty($_GET['name']) && ! $redirect_url ) { if ( $redirect_url = get_permalink( $wp_query->get_queried_object_id() ) ) $redirect['query'] = remove_query_arg('name', $redirect['query']); } elseif ( is_page() && !empty($_GET['page_id']) && ! $redirect_url ) { if ( $redirect_url = get_permalink(get_query_var('page_id')) ) $redirect['query'] = remove_query_arg('page_id', $redirect['query']); } elseif ( is_page() && !is_feed() && isset($wp_query->queried_object) && 'page' == get_option('show_on_front') && $wp_query->queried_object->ID == get_option('page_on_front') && ! $redirect_url ) { $redirect_url = home_url('/'); } elseif ( is_home() && !empty($_GET['page_id']) && 'page' == get_option('show_on_front') && get_query_var('page_id') == get_option('page_for_posts') && ! $redirect_url ) { if ( $redirect_url = get_permalink(get_option('page_for_posts')) ) $redirect['query'] = remove_query_arg('page_id', $redirect['query']); } elseif ( !empty($_GET['m']) && ( is_year() || is_month() || is_day() ) ) { $m = get_query_var('m'); switch ( strlen($m) ) { case 4: // Yearly $redirect_url = get_year_link($m); break; case 6: // Monthly $redirect_url = get_month_link( substr($m, 0, 4), substr($m, 4, 2) ); break; case 8: // Daily $redirect_url = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2)); break; } if ( $redirect_url ) $redirect['query'] = remove_query_arg('m', $redirect['query']); // now moving on to non ?m=X year/month/day links } elseif ( is_day() && get_query_var('year') && get_query_var('monthnum') && !empty($_GET['day']) ) { if ( $redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day')) ) $redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']); } elseif ( is_month() && get_query_var('year') && !empty($_GET['monthnum']) ) { if ( $redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum')) ) $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']); } elseif ( is_year() && !empty($_GET['year']) ) { if ( $redirect_url = get_year_link(get_query_var('year')) ) $redirect['query'] = remove_query_arg('year', $redirect['query']); } elseif ( is_author() && !empty($_GET['author']) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) { $author = get_userdata(get_query_var('author')); if ( ( false !== $author ) && $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_author = %d AND $wpdb->posts.post_status = 'publish' LIMIT 1", $author->ID ) ) ) { if ( $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) ) $redirect['query'] = remove_query_arg('author', $redirect['query']); } } elseif ( is_category() || is_tag() || is_tax() ) { // Terms (Tags/categories) $term_count = 0; foreach ( $wp_query->tax_query->queries as $tax_query ) $term_count += count( $tax_query['terms'] ); $obj = $wp_query->get_queried_object(); if ( $term_count <= 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) ) && !is_wp_error($tax_url) ) { if ( !empty($redirect['query']) ) { // Strip taxonomy query vars off the url. $qv_remove = array( 'term', 'taxonomy'); if ( is_category() ) { $qv_remove[] = 'category_name'; $qv_remove[] = 'cat'; } elseif ( is_tag() ) { $qv_remove[] = 'tag'; $qv_remove[] = 'tag_id'; } else { // Custom taxonomies will have a custom query var, remove those too: $tax_obj = get_taxonomy( $obj->taxonomy ); if ( false !== $tax_obj->query_var ) $qv_remove[] = $tax_obj->query_var; } $rewrite_vars = array_diff( array_keys($wp_query->query), array_keys($_GET) ); if ( !array_diff($rewrite_vars, array_keys($_GET)) ) { // Check to see if all the Query vars are coming from the rewrite, none are set via $_GET $redirect['query'] = remove_query_arg($qv_remove, $redirect['query']); //Remove all of the per-tax qv's // Create the destination url for this taxonomy $tax_url = parse_url($tax_url); if ( ! empty($tax_url['query']) ) { // Taxonomy accessible via ?taxonomy=..&term=.. or any custom qv.. parse_str($tax_url['query'], $query_vars); $redirect['query'] = add_query_arg($query_vars, $redirect['query']); } else { // Taxonomy is accessible via a "pretty-URL" $redirect['path'] = $tax_url['path']; } } else { // Some query vars are set via $_GET. Unset those from $_GET that exist via the rewrite foreach ( $qv_remove as $_qv ) { if ( isset($rewrite_vars[$_qv]) ) $redirect['query'] = remove_query_arg($_qv, $redirect['query']); } } } } } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false && $cat = get_query_var( 'category_name' ) ) { $category = get_category_by_path( $cat ); $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids')); if ( (!$category || is_wp_error($category)) || ( !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms) ) ) $redirect_url = get_permalink($wp_query->get_queried_object_id()); } // Post Paging if ( is_singular() && ! is_front_page() && get_query_var('page') ) { if ( !$redirect_url ) $redirect_url = get_permalink( get_queried_object_id() ); $redirect_url = trailingslashit( $redirect_url ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' ); $redirect['query'] = remove_query_arg( 'page', $redirect['query'] ); } // paging and feeds if ( get_query_var('paged') || is_feed() || get_query_var('cpage') ) { while ( preg_match( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $redirect['path'] ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $redirect['path'] ) || preg_match( '#/comment-page-[0-9]+(/+)?$#', $redirect['path'] ) ) { // Strip off paging and feed $redirect['path'] = preg_replace("#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/', $redirect['path']); // strip off any existing paging $redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path']); // strip off feed endings $redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $redirect['path']); // strip off any existing comment paging } $addl_path = ''; if ( is_feed() && in_array( get_query_var('feed'), $wp_rewrite->feeds ) ) { $addl_path = !empty( $addl_path ) ? trailingslashit($addl_path) : ''; if ( !is_singular() && get_query_var( 'withcomments' ) ) $addl_path .= 'comments/'; if ( ( 'rss' == get_default_feed() && 'feed' == get_query_var('feed') ) || 'rss' == get_query_var('feed') ) $addl_path .= user_trailingslashit( 'feed/' . ( ( get_default_feed() == 'rss2' ) ? '' : 'rss2' ), 'feed' ); else $addl_path .= user_trailingslashit( 'feed/' . ( ( get_default_feed() == get_query_var('feed') || 'feed' == get_query_var('feed') ) ? '' : get_query_var('feed') ), 'feed' ); $redirect['query'] = remove_query_arg( 'feed', $redirect['query'] ); } elseif ( is_feed() && 'old' == get_query_var('feed') ) { $old_feed_files = array( 'wp-atom.php' => 'atom', 'wp-commentsrss2.php' => 'comments_rss2', 'wp-feed.php' => get_default_feed(), 'wp-rdf.php' => 'rdf', 'wp-rss.php' => 'rss2', 'wp-rss2.php' => 'rss2', ); if ( isset( $old_feed_files[ basename( $redirect['path'] ) ] ) ) { $redirect_url = get_feed_link( $old_feed_files[ basename( $redirect['path'] ) ] ); wp_redirect( $redirect_url, 301 ); die(); } } if ( get_query_var('paged') > 0 ) { $paged = get_query_var('paged'); $redirect['query'] = remove_query_arg( 'paged', $redirect['query'] ); if ( !is_feed() ) { if ( $paged > 1 && !is_single() ) { $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit("$wp_rewrite->pagination_base/$paged", 'paged'); } elseif ( !is_single() ) { $addl_path = !empty( $addl_path ) ? trailingslashit($addl_path) : ''; } } elseif ( $paged > 1 ) { $redirect['query'] = add_query_arg( 'paged', $paged, $redirect['query'] ); } } if ( get_option('page_comments') && ( ( 'newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 ) || ( 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1 ) ) ) { $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( 'comment-page-' . get_query_var('cpage'), 'commentpaged' ); $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] ); } $redirect['path'] = user_trailingslashit( preg_replace('|/index.php/?$|', '/', $redirect['path']) ); // strip off trailing /index.php/ if ( !empty( $addl_path ) && $wp_rewrite->using_index_permalinks() && strpos($redirect['path'], '/index.php/') === false ) $redirect['path'] = trailingslashit($redirect['path']) . 'index.php/'; if ( !empty( $addl_path ) ) $redirect['path'] = trailingslashit($redirect['path']) . $addl_path; $redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path']; } if ( 'wp-register.php' == basename( $redirect['path'] ) ) { if ( is_multisite() ) $redirect_url = apply_filters( 'wp_signup_location', site_url( 'wp-signup.php' ) ); else $redirect_url = site_url( 'wp-login.php?action=register' ); wp_redirect( $redirect_url, 301 ); die(); } } // tack on any additional query vars $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); if ( $redirect_url && !empty($redirect['query']) ) { parse_str( $redirect['query'], $_parsed_query ); $redirect = @parse_url($redirect_url); if ( ! empty( $_parsed_query['name'] ) && ! empty( $redirect['query'] ) ) { parse_str( $redirect['query'], $_parsed_redirect_query ); if ( empty( $_parsed_redirect_query['name'] ) ) unset( $_parsed_query['name'] ); } $_parsed_query = rawurlencode_deep( $_parsed_query ); $redirect_url = add_query_arg( $_parsed_query, $redirect_url ); } if ( $redirect_url ) $redirect = @parse_url($redirect_url); // www.example.com vs example.com $user_home = @parse_url(home_url()); if ( !empty($user_home['host']) ) $redirect['host'] = $user_home['host']; if ( empty($user_home['path']) ) $user_home['path'] = '/'; // Handle ports if ( !empty($user_home['port']) ) $redirect['port'] = $user_home['port']; else unset($redirect['port']); // trailing /index.php $redirect['path'] = preg_replace('|/index.php/*?$|', '/', $redirect['path']); // Remove trailing spaces from the path $redirect['path'] = preg_replace( '#(%20| )+$#', '', $redirect['path'] ); if ( !empty( $redirect['query'] ) ) { // Remove trailing spaces from certain terminating query string args $redirect['query'] = preg_replace( '#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query'] ); // Clean up empty query strings $redirect['query'] = trim(preg_replace( '#(^|&)(p|page_id|cat|tag)=?(&|$)#', '&', $redirect['query']), '&'); // Redirect obsolete feeds $redirect['query'] = preg_replace( '#(^|&)feed=rss(&|$)#', '$1feed=rss2$3', $redirect['query'] ); // Remove redundant leading ampersands $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); } // strip /index.php/ when we're not using PATHINFO permalinks if ( !$wp_rewrite->using_index_permalinks() ) $redirect['path'] = str_replace('/index.php/', '/', $redirect['path']); // trailing slashes if ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_front_page() || ( is_front_page() && (get_query_var('paged') > 1) ) ) ) { $user_ts_type = ''; if ( get_query_var('paged') > 0 ) { $user_ts_type = 'paged'; } else { foreach ( array('single', 'category', 'page', 'day', 'month', 'year', 'home') as $type ) { $func = 'is_' . $type; if ( call_user_func($func) ) { $user_ts_type = $type; break; } } } $redirect['path'] = user_trailingslashit($redirect['path'], $user_ts_type); } elseif ( is_front_page() ) { $redirect['path'] = trailingslashit($redirect['path']); } // Strip multiple slashes out of the URL if ( strpos($redirect['path'], '//') > -1 ) $redirect['path'] = preg_replace('|/+|', '/', $redirect['path']); // Always trailing slash the Front Page URL if ( trailingslashit( $redirect['path'] ) == trailingslashit( $user_home['path'] ) ) $redirect['path'] = trailingslashit($redirect['path']); // Ignore differences in host capitalization, as this can lead to infinite redirects // Only redirect no-www <=> yes-www if ( strtolower($original['host']) == strtolower($redirect['host']) || ( strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host']) ) ) $redirect['host'] = $original['host']; $compare_original = array($original['host'], $original['path']); if ( !empty( $original['port'] ) ) $compare_original[] = $original['port']; if ( !empty( $original['query'] ) ) $compare_original[] = $original['query']; $compare_redirect = array($redirect['host'], $redirect['path']); if ( !empty( $redirect['port'] ) ) $compare_redirect[] = $redirect['port']; if ( !empty( $redirect['query'] ) ) $compare_redirect[] = $redirect['query']; if ( $compare_original !== $compare_redirect ) { $redirect_url = $redirect['scheme'] . '://' . $redirect['host']; if ( !empty($redirect['port']) ) $redirect_url .= ':' . $redirect['port']; $redirect_url .= $redirect['path']; if ( !empty($redirect['query']) ) $redirect_url .= '?' . $redirect['query']; } if ( !$redirect_url || $redirect_url == $requested_url ) return false; // Hex encoded octets are case-insensitive. if ( false !== strpos($requested_url, '%') ) { if ( !function_exists('lowercase_octets') ) { function lowercase_octets($matches) { return strtolower( $matches[0] ); } } $requested_url = preg_replace_callback('|%[a-fA-F0-9][a-fA-F0-9]|', 'lowercase_octets', $requested_url); } // Note that you can use the "redirect_canonical" filter to cancel a canonical redirect for whatever reason by returning false $redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url); if ( !$redirect_url || $redirect_url == $requested_url ) // yes, again -- in case the filter aborted the request return false; if ( $do_redirect ) { // protect against chained redirects if ( !redirect_canonical($redirect_url, false) ) { wp_redirect($redirect_url, 301); exit(); } else { // Debug // die("1: $redirect_url<br />2: " . redirect_canonical( $redirect_url, false ) ); return false; } } else { return $redirect_url; } }
/** * Returns current group * * @return string */ function get_group() { static $group = null; if ($group === null) { switch (true) { case is_404() && ($template = get_404_template()): case is_search() && ($template = get_search_template()): case is_tax() && ($template = get_taxonomy_template()): case is_home() && ($template = get_home_template()): case is_attachment() && ($template = get_attachment_template()): case is_single() && ($template = get_single_template()): case is_page() && ($template = get_page_template()): case is_category() && ($template = get_category_template()): case is_tag() && ($template = get_tag_template()): case is_author() && ($template = get_author_template()): case is_date() && ($template = get_date_template()): case is_archive() && ($template = get_archive_template()): case is_comments_popup() && ($template = get_comments_popup_template()): case is_paged() && ($template = get_paged_template()): $group = basename($template, '.php'); break; default: $group = 'default'; break; } } return $group; }
/** * Redirects incoming links to the proper URL based on the site url. * * Search engines consider www.somedomain.com and somedomain.com to be two * different URLs when they both go to the same location. This SEO enhancement * prevents penalty for duplicate content by redirecting all incoming links to * one or the other. * * Prevents redirection for feeds, trackbacks, searches, comment popup, and * admin URLs. Does not redirect on non-pretty-permalink-supporting IIS 7+, * page/post previews, WP admin, Trackbacks, robots.txt, searches, or on POST * requests. * * Will also attempt to find the correct link when a user enters a URL that does * not exist based on exact WordPress query. Will instead try to parse the URL * or query in an attempt to figure the correct page to go to. * * @since 2.3.0 * * @global WP_Rewrite $wp_rewrite * @global bool $is_IIS * @global WP_Query $wp_query * @global wpdb $wpdb WordPress database abstraction object. * * @param string $requested_url Optional. The URL that was requested, used to * figure if redirect is needed. * @param bool $do_redirect Optional. Redirect to the new URL. * @return string|void The string of the URL, if redirect needed. */ function redirect_canonical($requested_url = null, $do_redirect = true) { global $wp_rewrite, $is_IIS, $wp_query, $wpdb, $wp; if (isset($_SERVER['REQUEST_METHOD']) && !in_array(strtoupper($_SERVER['REQUEST_METHOD']), array('GET', 'HEAD'))) { return; } // If we're not in wp-admin and the post has been published and preview nonce // is non-existent or invalid then no need for preview in query if (is_preview() && get_query_var('p') && 'publish' == get_post_status(get_query_var('p'))) { if (!isset($_GET['preview_id']) || !isset($_GET['preview_nonce']) || !wp_verify_nonce($_GET['preview_nonce'], 'post_preview_' . (int) $_GET['preview_id'])) { $wp_query->is_preview = false; } } if (is_trackback() || is_search() || is_comments_popup() || is_admin() || is_preview() || is_robots() || $is_IIS && !iis7_supports_permalinks()) { return; } if (!$requested_url && isset($_SERVER['HTTP_HOST'])) { // build the URL in the address bar $requested_url = is_ssl() ? 'https://' : 'http://'; $requested_url .= $_SERVER['HTTP_HOST']; $requested_url .= $_SERVER['REQUEST_URI']; } $original = @parse_url($requested_url); if (false === $original) { return; } $redirect = $original; $redirect_url = false; // Notice fixing if (!isset($redirect['path'])) { $redirect['path'] = ''; } if (!isset($redirect['query'])) { $redirect['query'] = ''; } // If the original URL ended with non-breaking spaces, they were almost // certainly inserted by accident. Let's remove them, so the reader doesn't // see a 404 error with no obvious cause. $redirect['path'] = preg_replace('|(%C2%A0)+$|i', '', $redirect['path']); // It's not a preview, so remove it from URL if (get_query_var('preview')) { $redirect['query'] = remove_query_arg('preview', $redirect['query']); } if (is_feed() && ($id = get_query_var('p'))) { if ($redirect_url = get_post_comments_feed_link($id, get_query_var('feed'))) { $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed'), $redirect_url); $redirect['path'] = parse_url($redirect_url, PHP_URL_PATH); } } if (is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p'))) { $vars = $wpdb->get_results($wpdb->prepare("SELECT post_type, post_parent FROM {$wpdb->posts} WHERE ID = %d", $id)); if (isset($vars[0]) && ($vars = $vars[0])) { if ('revision' == $vars->post_type && $vars->post_parent > 0) { $id = $vars->post_parent; } if ($redirect_url = get_permalink($id)) { $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type'), $redirect_url); } } } // These tests give us a WP-generated permalink if (is_404()) { // Redirect ?page_id, ?p=, ?attachment_id= to their respective url's $id = max(get_query_var('p'), get_query_var('page_id'), get_query_var('attachment_id')); if ($id && ($redirect_post = get_post($id))) { $post_type_obj = get_post_type_object($redirect_post->post_type); if ($post_type_obj->public) { $redirect_url = get_permalink($redirect_post); $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type'), $redirect_url); } } if (get_query_var('day') && get_query_var('monthnum') && get_query_var('year')) { $year = get_query_var('year'); $month = get_query_var('monthnum'); $day = get_query_var('day'); $date = sprintf('%04d-%02d-%02d', $year, $month, $day); if (!wp_checkdate($month, $day, $year, $date)) { $redirect_url = get_month_link($year, $month); $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('year', 'monthnum', 'day'), $redirect_url); } } elseif (get_query_var('monthnum') && get_query_var('year') && 12 < get_query_var('monthnum')) { $redirect_url = get_year_link(get_query_var('year')); $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('year', 'monthnum'), $redirect_url); } if (!$redirect_url) { if ($redirect_url = redirect_guess_404_permalink()) { $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type'), $redirect_url); } } if (get_query_var('page') && $wp_query->post && false !== strpos($wp_query->post->post_content, '<!--nextpage-->')) { $redirect['path'] = rtrim($redirect['path'], (int) get_query_var('page') . '/'); $redirect['query'] = remove_query_arg('page', $redirect['query']); $redirect_url = get_permalink($wp_query->post->ID); } } elseif (is_object($wp_rewrite) && $wp_rewrite->using_permalinks()) { // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101 if (is_attachment() && !array_diff(array_keys($wp->query_vars), array('attachment', 'attachment_id')) && !$redirect_url) { if (!empty($_GET['attachment_id'])) { $redirect_url = get_attachment_link(get_query_var('attachment_id')); if ($redirect_url) { $redirect['query'] = remove_query_arg('attachment_id', $redirect['query']); } } else { $redirect_url = get_attachment_link(); } } elseif (is_single() && !empty($_GET['p']) && !$redirect_url) { if ($redirect_url = get_permalink(get_query_var('p'))) { $redirect['query'] = remove_query_arg(array('p', 'post_type'), $redirect['query']); } } elseif (is_single() && !empty($_GET['name']) && !$redirect_url) { if ($redirect_url = get_permalink($wp_query->get_queried_object_id())) { $redirect['query'] = remove_query_arg('name', $redirect['query']); } } elseif (is_page() && !empty($_GET['page_id']) && !$redirect_url) { if ($redirect_url = get_permalink(get_query_var('page_id'))) { $redirect['query'] = remove_query_arg('page_id', $redirect['query']); } } elseif (is_page() && !is_feed() && isset($wp_query->queried_object) && 'page' == get_option('show_on_front') && $wp_query->queried_object->ID == get_option('page_on_front') && !$redirect_url) { $redirect_url = home_url('/'); } elseif (is_home() && !empty($_GET['page_id']) && 'page' == get_option('show_on_front') && get_query_var('page_id') == get_option('page_for_posts') && !$redirect_url) { if ($redirect_url = get_permalink(get_option('page_for_posts'))) { $redirect['query'] = remove_query_arg('page_id', $redirect['query']); } } elseif (!empty($_GET['m']) && (is_year() || is_month() || is_day())) { $m = get_query_var('m'); switch (strlen($m)) { case 4: // Yearly $redirect_url = get_year_link($m); break; case 6: // Monthly $redirect_url = get_month_link(substr($m, 0, 4), substr($m, 4, 2)); break; case 8: // Daily $redirect_url = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2)); break; } if ($redirect_url) { $redirect['query'] = remove_query_arg('m', $redirect['query']); } // now moving on to non ?m=X year/month/day links } elseif (is_day() && get_query_var('year') && get_query_var('monthnum') && !empty($_GET['day'])) { if ($redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day'))) { $redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']); } } elseif (is_month() && get_query_var('year') && !empty($_GET['monthnum'])) { if ($redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum'))) { $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']); } } elseif (is_year() && !empty($_GET['year'])) { if ($redirect_url = get_year_link(get_query_var('year'))) { $redirect['query'] = remove_query_arg('year', $redirect['query']); } } elseif (is_author() && !empty($_GET['author']) && preg_match('|^[0-9]+$|', $_GET['author'])) { $author = get_userdata(get_query_var('author')); if (false !== $author && $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_author = %d AND {$wpdb->posts}.post_status = 'publish' LIMIT 1", $author->ID))) { if ($redirect_url = get_author_posts_url($author->ID, $author->user_nicename)) { $redirect['query'] = remove_query_arg('author', $redirect['query']); } } } elseif (is_category() || is_tag() || is_tax()) { // Terms (Tags/categories) $term_count = 0; foreach ($wp_query->tax_query->queried_terms as $tax_query) { $term_count += count($tax_query['terms']); } $obj = $wp_query->get_queried_object(); if ($term_count <= 1 && !empty($obj->term_id) && ($tax_url = get_term_link((int) $obj->term_id, $obj->taxonomy)) && !is_wp_error($tax_url)) { if (!empty($redirect['query'])) { // Strip taxonomy query vars off the url. $qv_remove = array('term', 'taxonomy'); if (is_category()) { $qv_remove[] = 'category_name'; $qv_remove[] = 'cat'; } elseif (is_tag()) { $qv_remove[] = 'tag'; $qv_remove[] = 'tag_id'; } else { // Custom taxonomies will have a custom query var, remove those too: $tax_obj = get_taxonomy($obj->taxonomy); if (false !== $tax_obj->query_var) { $qv_remove[] = $tax_obj->query_var; } } $rewrite_vars = array_diff(array_keys($wp_query->query), array_keys($_GET)); if (!array_diff($rewrite_vars, array_keys($_GET))) { // Check to see if all the Query vars are coming from the rewrite, none are set via $_GET $redirect['query'] = remove_query_arg($qv_remove, $redirect['query']); //Remove all of the per-tax qv's // Create the destination url for this taxonomy $tax_url = parse_url($tax_url); if (!empty($tax_url['query'])) { // Taxonomy accessible via ?taxonomy=..&term=.. or any custom qv.. parse_str($tax_url['query'], $query_vars); $redirect['query'] = add_query_arg($query_vars, $redirect['query']); } else { // Taxonomy is accessible via a "pretty-URL" $redirect['path'] = $tax_url['path']; } } else { // Some query vars are set via $_GET. Unset those from $_GET that exist via the rewrite foreach ($qv_remove as $_qv) { if (isset($rewrite_vars[$_qv])) { $redirect['query'] = remove_query_arg($_qv, $redirect['query']); } } } } } } elseif (is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false && ($cat = get_query_var('category_name'))) { $category = get_category_by_path($cat); $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids')); if (!$category || is_wp_error($category) || !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms)) { $redirect_url = get_permalink($wp_query->get_queried_object_id()); } } // Post Paging if (is_singular() && !is_front_page() && get_query_var('page')) { if (!$redirect_url) { $redirect_url = get_permalink(get_queried_object_id()); } $redirect_url = trailingslashit($redirect_url) . user_trailingslashit(get_query_var('page'), 'single_paged'); $redirect['query'] = remove_query_arg('page', $redirect['query']); } // paging and feeds if (get_query_var('paged') || is_feed() || get_query_var('cpage')) { while (preg_match("#/{$wp_rewrite->pagination_base}/?[0-9]+?(/+)?\$#", $redirect['path']) || preg_match('#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $redirect['path']) || preg_match("#/{$wp_rewrite->comments_pagination_base}-[0-9]+(/+)?\$#", $redirect['path'])) { // Strip off paging and feed $redirect['path'] = preg_replace("#/{$wp_rewrite->pagination_base}/?[0-9]+?(/+)?\$#", '/', $redirect['path']); // strip off any existing paging $redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path']); // strip off feed endings $redirect['path'] = preg_replace("#/{$wp_rewrite->comments_pagination_base}-[0-9]+?(/+)?\$#", '/', $redirect['path']); // strip off any existing comment paging } $addl_path = ''; if (is_feed() && in_array(get_query_var('feed'), $wp_rewrite->feeds)) { $addl_path = !empty($addl_path) ? trailingslashit($addl_path) : ''; if (!is_singular() && get_query_var('withcomments')) { $addl_path .= 'comments/'; } if ('rss' == get_default_feed() && 'feed' == get_query_var('feed') || 'rss' == get_query_var('feed')) { $addl_path .= user_trailingslashit('feed/' . (get_default_feed() == 'rss2' ? '' : 'rss2'), 'feed'); } else { $addl_path .= user_trailingslashit('feed/' . (get_default_feed() == get_query_var('feed') || 'feed' == get_query_var('feed') ? '' : get_query_var('feed')), 'feed'); } $redirect['query'] = remove_query_arg('feed', $redirect['query']); } elseif (is_feed() && 'old' == get_query_var('feed')) { $old_feed_files = array('wp-atom.php' => 'atom', 'wp-commentsrss2.php' => 'comments_rss2', 'wp-feed.php' => get_default_feed(), 'wp-rdf.php' => 'rdf', 'wp-rss.php' => 'rss2', 'wp-rss2.php' => 'rss2'); if (isset($old_feed_files[basename($redirect['path'])])) { $redirect_url = get_feed_link($old_feed_files[basename($redirect['path'])]); wp_redirect($redirect_url, 301); die; } } if (get_query_var('paged') > 0) { $paged = get_query_var('paged'); $redirect['query'] = remove_query_arg('paged', $redirect['query']); if (!is_feed()) { if ($paged > 1 && !is_single()) { $addl_path = (!empty($addl_path) ? trailingslashit($addl_path) : '') . user_trailingslashit("{$wp_rewrite->pagination_base}/{$paged}", 'paged'); } elseif (!is_single()) { $addl_path = !empty($addl_path) ? trailingslashit($addl_path) : ''; } } elseif ($paged > 1) { $redirect['query'] = add_query_arg('paged', $paged, $redirect['query']); } } if (get_option('page_comments') && ('newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 || 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1)) { $addl_path = (!empty($addl_path) ? trailingslashit($addl_path) : '') . user_trailingslashit($wp_rewrite->comments_pagination_base . '-' . get_query_var('cpage'), 'commentpaged'); $redirect['query'] = remove_query_arg('cpage', $redirect['query']); } $redirect['path'] = user_trailingslashit(preg_replace('|/' . preg_quote($wp_rewrite->index, '|') . '/?$|', '/', $redirect['path'])); // strip off trailing /index.php/ if (!empty($addl_path) && $wp_rewrite->using_index_permalinks() && strpos($redirect['path'], '/' . $wp_rewrite->index . '/') === false) { $redirect['path'] = trailingslashit($redirect['path']) . $wp_rewrite->index . '/'; } if (!empty($addl_path)) { $redirect['path'] = trailingslashit($redirect['path']) . $addl_path; } $redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path']; } if ('wp-register.php' == basename($redirect['path'])) { if (is_multisite()) { /** This filter is documented in wp-login.php */ $redirect_url = apply_filters('wp_signup_location', network_site_url('wp-signup.php')); } else { $redirect_url = wp_registration_url(); } wp_redirect($redirect_url, 301); die; } } // tack on any additional query vars $redirect['query'] = preg_replace('#^\\??&*?#', '', $redirect['query']); if ($redirect_url && !empty($redirect['query'])) { parse_str($redirect['query'], $_parsed_query); $redirect = @parse_url($redirect_url); if (!empty($_parsed_query['name']) && !empty($redirect['query'])) { parse_str($redirect['query'], $_parsed_redirect_query); if (empty($_parsed_redirect_query['name'])) { unset($_parsed_query['name']); } } $_parsed_query = rawurlencode_deep($_parsed_query); $redirect_url = add_query_arg($_parsed_query, $redirect_url); } if ($redirect_url) { $redirect = @parse_url($redirect_url); } // www.example.com vs example.com $user_home = @parse_url(home_url()); if (!empty($user_home['host'])) { $redirect['host'] = $user_home['host']; } if (empty($user_home['path'])) { $user_home['path'] = '/'; } // Handle ports if (!empty($user_home['port'])) { $redirect['port'] = $user_home['port']; } else { unset($redirect['port']); } // trailing /index.php $redirect['path'] = preg_replace('|/' . preg_quote($wp_rewrite->index, '|') . '/*?$|', '/', $redirect['path']); // Remove trailing spaces from the path $redirect['path'] = preg_replace('#(%20| )+$#', '', $redirect['path']); if (!empty($redirect['query'])) { // Remove trailing spaces from certain terminating query string args $redirect['query'] = preg_replace('#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query']); // Clean up empty query strings $redirect['query'] = trim(preg_replace('#(^|&)(p|page_id|cat|tag)=?(&|$)#', '&', $redirect['query']), '&'); // Redirect obsolete feeds $redirect['query'] = preg_replace('#(^|&)feed=rss(&|$)#', '$1feed=rss2$2', $redirect['query']); // Remove redundant leading ampersands $redirect['query'] = preg_replace('#^\\??&*?#', '', $redirect['query']); } // strip /index.php/ when we're not using PATHINFO permalinks if (!$wp_rewrite->using_index_permalinks()) { $redirect['path'] = str_replace('/' . $wp_rewrite->index . '/', '/', $redirect['path']); } // trailing slashes if (is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_front_page() || is_front_page() && get_query_var('paged') > 1)) { $user_ts_type = ''; if (get_query_var('paged') > 0) { $user_ts_type = 'paged'; } else { foreach (array('single', 'category', 'page', 'day', 'month', 'year', 'home') as $type) { $func = 'is_' . $type; if (call_user_func($func)) { $user_ts_type = $type; break; } } } $redirect['path'] = user_trailingslashit($redirect['path'], $user_ts_type); } elseif (is_front_page()) { $redirect['path'] = trailingslashit($redirect['path']); } // Strip multiple slashes out of the URL if (strpos($redirect['path'], '//') > -1) { $redirect['path'] = preg_replace('|/+|', '/', $redirect['path']); } // Always trailing slash the Front Page URL if (trailingslashit($redirect['path']) == trailingslashit($user_home['path'])) { $redirect['path'] = trailingslashit($redirect['path']); } // Ignore differences in host capitalization, as this can lead to infinite redirects // Only redirect no-www <=> yes-www if (strtolower($original['host']) == strtolower($redirect['host']) || strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host'])) { $redirect['host'] = $original['host']; } $compare_original = array($original['host'], $original['path']); if (!empty($original['port'])) { $compare_original[] = $original['port']; } if (!empty($original['query'])) { $compare_original[] = $original['query']; } $compare_redirect = array($redirect['host'], $redirect['path']); if (!empty($redirect['port'])) { $compare_redirect[] = $redirect['port']; } if (!empty($redirect['query'])) { $compare_redirect[] = $redirect['query']; } if ($compare_original !== $compare_redirect) { $redirect_url = $redirect['scheme'] . '://' . $redirect['host']; if (!empty($redirect['port'])) { $redirect_url .= ':' . $redirect['port']; } $redirect_url .= $redirect['path']; if (!empty($redirect['query'])) { $redirect_url .= '?' . $redirect['query']; } } if (!$redirect_url || $redirect_url == $requested_url) { return; } // Hex encoded octets are case-insensitive. if (false !== strpos($requested_url, '%')) { if (!function_exists('lowercase_octets')) { function lowercase_octets($matches) { return strtolower($matches[0]); } } $requested_url = preg_replace_callback('|%[a-fA-F0-9][a-fA-F0-9]|', 'lowercase_octets', $requested_url); } /** * Filter the canonical redirect URL. * * Returning false to this filter will cancel the redirect. * * @since 2.3.0 * * @param string $redirect_url The redirect URL. * @param string $requested_url The requested URL. */ $redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url); // yes, again -- in case the filter aborted the request if (!$redirect_url || $redirect_url == $requested_url) { return; } if ($do_redirect) { // protect against chained redirects if (!redirect_canonical($redirect_url, false)) { wp_redirect($redirect_url, 301); exit; } else { // Debug // die("1: $redirect_url<br />2: " . redirect_canonical( $redirect_url, false ) ); return; } } else { return $redirect_url; } }
private function getContent() { $template = false; if (is_404() && ($template = get_404_template())) { } elseif (is_search() && ($template = get_search_template())) { } elseif (is_tax() && ($template = get_taxonomy_template())) { } elseif (is_front_page() && ($template = get_front_page_template())) { } elseif (is_home() && ($template = get_home_template())) { } elseif (is_attachment() && ($template = get_attachment_template())) { remove_filter('the_content', 'prepend_attachment'); } elseif (is_single() && ($template = get_single_template())) { } elseif (is_page() && ($template = get_page_template())) { } elseif (is_category() && ($template = get_category_template())) { } elseif (is_tag() && ($template = get_tag_template())) { } elseif (is_author() && ($template = get_author_template())) { } elseif (is_date() && ($template = get_date_template())) { } elseif (is_archive() && ($template = get_archive_template())) { } elseif (is_comments_popup() && ($template = get_comments_popup_template())) { } elseif (is_paged() && ($template = get_paged_template())) { } else { $template = get_index_template(); } if ($template = apply_filters('template_include', $template)) { ob_start(); include $template; $contents = ob_get_contents(); ob_end_clean(); return $contents; } else { return; } }
/** * Get the identifier for the active page * * @return null|string */ public static function get_page() { $page = null; /** * See: https://codex.wordpress.org/Conditional_Tags */ switch (true) { case is_404(): $page = 'error'; break; case is_search(): $page = 'search'; break; /** * Case is_home() return true when on the posts list page, * This is usually the page that shows the latest 10 posts. */ /** * Case is_home() return true when on the posts list page, * This is usually the page that shows the latest 10 posts. */ case is_home(): $page = 'home'; break; /** * Case is_front_page() returns true if the user is on the page or page of posts that is set to the front page * on Settings->Reading->Front page displays */ /** * Case is_front_page() returns true if the user is on the page or page of posts that is set to the front page * on Settings->Reading->Front page displays */ case is_front_page(): $page = 'front_page'; break; case is_post_type_archive(): $page = 'post-type-archive'; break; case is_page_template(): $page = 'custom'; break; case is_single(): $page = 'single'; break; case is_page(): $page = 'page'; break; case is_attachment(): $page = 'attachment'; break; case is_comments_popup(): $page = 'comments-popup'; break; case is_tax(): $page = 'taxonomy'; break; case is_tag(): $page = 'tag'; break; case is_date(): $page = 'date'; break; case is_category(): $page = 'category'; break; case is_author(): $page = 'author'; break; case is_archive(): $page = 'archive'; break; } /** * Filter: override for page selection */ $page = self::filter('page-' . $page, $page); $page = self::filter('page', $page); return $page; }
/** * Print jQuery call to modify comment form. * * @action: comment_form **/ function openid_comment_form() { global $wp_scripts; if (!is_user_logged_in() && (is_single() || is_comments_popup()) && isset($wp_scripts) && $wp_scripts->query('openid')) { echo '<script type="text/javascript">add_openid_to_comment_form()</script>'; } }
public function templateLoad($defaultView = '') { global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; $content = ''; /** * Loads the correct template based on the visitor's url * @package WordPress */ if (defined('WP_USE_THEMES') && WP_USE_THEMES) { do_action('template_redirect'); } /** * Filter whether to allow 'HEAD' requests to generate content. * * Provides a significant performance bump by exiting before the page * content loads for 'HEAD' requests. See #14348. * * @since 3.5.0 * * @param bool $exit Whether to exit without generating any content for 'HEAD' requests. Default true. */ if ('HEAD' === $_SERVER['REQUEST_METHOD'] && apply_filters('exit_on_http_head', true)) { exit; } // Process feeds and trackbacks even if not using themes. if (is_robots()) { /** * Fired when the template loader determines a robots.txt request. * * @since 2.1.0 */ do_action('do_robots'); return $content; } elseif (is_feed()) { do_feed(); return $content; } elseif (is_trackback()) { include ABSPATH . 'wp-trackback.php'; return $content; } if (defined('WP_USE_THEMES') && WP_USE_THEMES) { $template = false; if (is_404() && ($template = get_404_template())) { } elseif (is_search() && ($template = get_search_template())) { } elseif (is_front_page() && ($template = get_front_page_template())) { } elseif (is_home() && ($template = get_home_template())) { } elseif (is_post_type_archive() && ($template = get_post_type_archive_template())) { } elseif (is_tax() && ($template = get_taxonomy_template())) { } elseif (is_attachment() && ($template = get_attachment_template())) { remove_filter('the_content', 'prepend_attachment'); } elseif (is_single() && ($template = get_single_template())) { } elseif (is_page() && ($template = get_page_template())) { } elseif (is_category() && ($template = get_category_template())) { } elseif (is_tag() && ($template = get_tag_template())) { } elseif (is_author() && ($template = get_author_template())) { } elseif (is_date() && ($template = get_date_template())) { } elseif (is_archive() && ($template = get_archive_template())) { } elseif (is_comments_popup() && ($template = get_comments_popup_template())) { } elseif (is_paged() && ($template = get_paged_template())) { } else { $template = get_index_template(); } /** * Filter the path of the current template before including it. * * @since 3.0.0 * * @param string $template The path of the template to include. */ if ($template = apply_filters('template_include', $this->defaultView ?: $template)) { load_template($template, false); } return $content; } }
/** * add_filter the_content. */ function wp_social_bookmarking_light_the_content($content) { if (is_feed() || is_404() || is_robots() || is_comments_popup() || function_exists('is_ktai') && is_ktai()) { return $content; } $options = wp_social_bookmarking_light_options(); if ($options['single_page'] && !is_singular()) { return $content; } if (!$options['is_page'] && is_page()) { return $content; } $out = wp_social_bookmarking_light_output($options['services'], get_permalink(), get_the_title()); if ($out == '') { return $content; } if ($options['position'] == 'top') { return "{$out}{$content}"; } else { if ($options['position'] == 'bottom') { return "{$content}{$out}"; } else { if ($options['position'] == 'both') { return "{$out}{$content}{$out}"; } } } return $content; }
/** * Gets all the crumbs for the current page. Uses the template hierarchy and the * provided options to determine which crumbs to return. * * @access public * @static * @param array $options * @return array */ public static function get_crumbs(array $options) { $crumbs = self::get_home_crumbs($options); if (is_front_page() || is_home()) { return $crumbs; } elseif (is_404()) { return array_merge($crumbs, self::get_404_crumbs($options)); } elseif (is_search()) { return array_merge($crumbs, self::get_search_crumbs($options)); } elseif (is_date()) { return array_merge($crumbs, self::get_date_archive_crumbs($options)); } elseif (is_author()) { return array_merge($crumbs, self::get_author_crumbs($options)); } elseif (is_post_type_archive()) { return array_merge($crumbs, self::get_post_type_crumbs($options)); } elseif (is_category() || is_tag() || is_tax()) { return array_merge($crumbs, self::get_taxonomy_crumbs($options)); } elseif (is_comments_popup()) { return array_merge($crumbs, self::get_comment_popup_crumbs($options)); } elseif (is_attachment()) { return $crumbs; } elseif (is_singular()) { return array_merge($crumbs, self::get_singular_crumbs($options)); } else { return $crumbs; } }
/** * HideMyWP::wp() * * Disable WP components when permalink is enabled * @return */ function wp() { if ((is_feed() || is_comment_feed()) && !isset($_GET['feed']) && !$this->opt('feed_enable')) { $this->block_access(); } if (is_author() && !isset($_GET['author']) && !isset($_GET['author']) && !$this->opt('author_enable')) { $this->block_access(); } if (is_search() && !isset($_GET['s']) && !$this->opt('search_enable')) { $this->block_access(); } if (is_paged() && !isset($_GET['paged']) && !$this->opt('paginate_enable')) { $this->block_access(); } if (is_page() && !isset($_GET['page_id']) && !isset($_GET['pagename']) && !$this->opt('page_enable')) { $this->block_access(); } if (is_single() && !isset($_GET['p']) && !$this->opt('post_enable')) { $this->block_access(); } if (is_category() && !isset($_GET['cat']) && !$this->opt('category_enable')) { $this->block_access(); } if (is_tag() && !isset($_GET['tag']) && !$this->opt('tag_enable')) { $this->block_access(); } if ((is_date() || is_time()) && !isset($_GET['monthnum']) && !isset($_GET['m']) && !isset($_GET['w']) && !isset($_GET['second']) && !isset($_GET['year']) && !isset($_GET['day']) && !isset($_GET['hour']) && !isset($_GET['second']) && !isset($_GET['minute']) && !isset($_GET['calendar']) && $this->opt('disable_archive')) { $this->block_access(); } if ((is_tax() || is_post_type_archive() || is_trackback() || is_comments_popup() || is_attachment()) && !isset($_GET['post_type']) && !isset($_GET['taxonamy']) && !isset($_GET['attachment']) && !isset($_GET['attachment_id']) && !isset($_GET['preview']) && $this->opt('disable_other_wp')) { $this->block_access(); } if (!is_404() && !is_home() && (stristr($_SERVER['HTTP_USER_AGENT'], 'BuiltWith') || stristr($_SERVER['HTTP_USER_AGENT'], '2ip.ru'))) { wp_redirect(home_url()); } }
include $template; return; } else { if (is_author() && ($template = get_author_template())) { include $template; return; } else { if (is_date() && ($template = get_date_template())) { include $template; return; } else { if (is_archive() && ($template = get_archive_template())) { include $template; return; } else { if (is_comments_popup() && ($template = get_comments_popup_template())) { include $template; return; } else { if (is_paged() && ($template = get_paged_template())) { include $template; return; } else { if (file_exists(TEMPLATEPATH . "/index.php")) { if (is_attachment()) { add_filter('the_content', 'prepend_attachment'); } include TEMPLATEPATH . "/index.php"; return; } }
/** * @param bool $compile */ protected function prepareTemplates($compile) { if (is_404()) { $this->prepareTemplate('404'); } if (is_search()) { $this->prepareTemplate('search'); } if (is_front_page()) { $this->prepareTemplate('front_page'); } if (is_home()) { $this->prepareTemplate('home'); } if (is_post_type_archive()) { $this->prepareTemplate('archive'); } if (is_tax()) { $this->prepareTemplate('taxonomy'); } if (is_attachment()) { $this->prepareTemplate('attachment'); } if (is_single()) { $this->prepareTemplate('single'); } if (is_page()) { $this->prepareTemplate('page'); } if (is_category()) { $this->prepareTemplate('category'); } if (is_tag()) { $this->prepareTemplate('tag'); } if (is_author()) { $this->prepareTemplate('author'); } if (is_date()) { $this->prepareTemplate('date'); } if (is_archive()) { $this->prepareTemplate('archive'); } if (is_comments_popup()) { $this->prepareTemplate('comments_popup'); } if (is_paged()) { $this->prepareTemplate('paged'); } $this->prepareTemplate('index'); }
/** * Returns current template * * @return string */ function get_template() { static $template = null; if ($template === null) { switch (true) { case is_404() && ($template_file = get_404_template()): case is_search() && ($template_file = get_search_template()): case is_tax() && ($template_file = get_taxonomy_template()): case is_front_page() && function_exists('get_front_page_template') && ($template_file = get_front_page_template()): case is_home() && ($template_file = get_home_template()): case is_attachment() && ($template_file = get_attachment_template()): case is_single() && ($template_file = get_single_template()): case is_page() && ($template_file = get_page_template()): case is_category() && ($template_file = get_category_template()): case is_tag() && ($template_file = get_tag_template()): case is_author() && ($template_file = get_author_template()): case is_date() && ($template_file = get_date_template()): case is_archive() && ($template_file = get_archive_template()): case is_comments_popup() && ($template_file = get_comments_popup_template()): case is_paged() && ($template_file = get_paged_template()): break; default: if (function_exists('get_index_template')) { $template_file = get_index_template(); } else { $template_file = 'index.php'; } break; } $template = basename($template_file, '.php'); } return $template; }
function redirect_canonical($requested_url = NULL, $do_redirect = true) { global $wp_rewrite, $posts, $is_IIS; if (is_feed() || is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || isset($_POST) && count($_POST)) { return; } if (!$requested_url) { // build the URL in the address bar $requested_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://'; $requested_url .= $_SERVER['HTTP_HOST']; $requested_url .= $_SERVER['REQUEST_URI']; } $original = @parse_url($requested_url); if (false === $original) { return; } // Some PHP setups turn requests for / into /index.php in REQUEST_URI $original['path'] = preg_replace('|/index\\.php$|', '/', $original['path']); $redirect = $original; $redirect_url = false; // These tests give us a WP-generated permalink if (is_404()) { $redirect_url = redirect_guess_404_permalink(); } elseif (is_object($wp_rewrite) && $wp_rewrite->using_permalinks()) { // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101 if (is_single() && isset($_GET['p'])) { if ($redirect_url = get_permalink(get_query_var('p'))) { $redirect['query'] = remove_query_arg('p', $redirect['query']); } } elseif (is_page() && isset($_GET['page_id'])) { if ($redirect_url = get_permalink(get_query_var('page_id'))) { $redirect['query'] = remove_query_arg('page_id', $redirect['query']); } } elseif (isset($_GET['m']) && (is_year() || is_month() || is_day())) { $m = get_query_var('m'); switch (strlen($m)) { case 4: // Yearly $redirect_url = get_year_link($m); break; case 6: // Monthly $redirect_url = get_month_link(substr($m, 0, 4), substr($m, 4, 2)); break; case 8: // Daily $redirect_url = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2)); break; } if ($redirect_url) { $redirect['query'] = remove_query_arg('m', $redirect['query']); } // now moving on to non ?m=X year/month/day links } elseif (is_day() && get_query_var('year') && get_query_var('monthnum') && isset($_GET['day'])) { if ($redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day'))) { $redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']); } } elseif (is_month() && get_query_var('year') && isset($_GET['monthnum'])) { if ($redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum'))) { $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']); } } elseif (is_year() && isset($_GET['year'])) { if ($redirect_url = get_year_link(get_query_var('year'))) { $redirect['query'] = remove_query_arg('year', $redirect['query']); } } elseif (is_category() && isset($_GET['cat'])) { if ($redirect_url = get_category_link(get_query_var('cat'))) { $redirect['query'] = remove_query_arg('cat', $redirect['query']); } } elseif (is_author() && isset($_GET['author'])) { $author = get_userdata(get_query_var('author')); if (false !== $author && ($redirect_url = get_author_link(false, $author->ID, $author->user_nicename))) { $redirect['query'] = remove_query_arg('author', $redirect['author']); } } // paging if ($paged = get_query_var('paged')) { if ($paged > 0) { if (!$redirect_url) { $redirect_url = $requested_url; } $paged_redirect = @parse_url($redirect_url); $paged_redirect['path'] = preg_replace('|/page/[0-9]+?(/+)?$|', '/', $paged_redirect['path']); // strip off any existing paging $paged_redirect['path'] = preg_replace('|/index.php/?$|', '/', $paged_redirect['path']); // strip off trailing /index.php/ if ($paged > 1 && !is_single()) { $paged_redirect['path'] = trailingslashit($paged_redirect['path']); if ($wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false) { $paged_redirect['path'] .= 'index.php/'; } $paged_redirect['path'] .= user_trailingslashit("page/{$paged}", 'paged'); } elseif (!is_home() && !is_single()) { $paged_redirect['path'] = user_trailingslashit($paged_redirect['path'], 'paged'); } $redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path']; $redirect['path'] = $paged_redirect['path']; } $redirect['query'] = remove_query_arg('paged', $redirect['query']); } } // tack on any additional query vars if ($redirect_url && $redirect['query']) { if (strpos($redirect_url, '?') !== false) { $redirect_url .= '&'; } else { $redirect_url .= '?'; } $redirect_url .= $redirect['query']; } if ($redirect_url) { $redirect = @parse_url($redirect_url); } // www.example.com vs example.com $user_home = @parse_url(get_option('home')); $redirect['host'] = $user_home['host']; // Handle ports if (isset($user_home['port'])) { $redirect['port'] = $user_home['port']; } else { unset($redirect['port']); } // trailing /index.php/ $redirect['path'] = preg_replace('|/index.php/$|', '/', $redirect['path']); // strip /index.php/ when we're not using PATHINFO permalinks if (!$wp_rewrite->using_index_permalinks()) { $redirect['path'] = str_replace('/index.php/', '/', $redirect['path']); } // trailing slashes if (is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_home() || is_home() && get_query_var('paged') > 1)) { $user_ts_type = ''; if (get_query_var('paged') > 0) { $user_ts_type = 'paged'; } else { foreach (array('single', 'category', 'page', 'day', 'month', 'year') as $type) { $func = 'is_' . $type; if (call_user_func($func)) { $user_ts_type = $type; } break; } } $redirect['path'] = user_trailingslashit($redirect['path'], $user_ts_type); } elseif (is_home()) { $redirect['path'] = trailingslashit($redirect['path']); } // Always trailing slash the 'home' URL if ($redirect['path'] == $user_home['path']) { $redirect['path'] = trailingslashit($redirect['path']); } // Ignore differences in host capitalization, as this can lead to infinite redirects if (strtolower($original['host']) == strtolower($redirect['host'])) { $redirect['host'] = $original['host']; } if (array($original['host'], $original['port'], $original['path'], $original['query']) !== array($redirect['host'], $redirect['port'], $redirect['path'], $redirect['query'])) { $redirect_url = $redirect['scheme'] . '://' . $redirect['host']; if (isset($redirect['port'])) { $redirect_url .= ':' . $redirect['port']; } $redirect_url .= $redirect['path']; if ($redirect['query']) { $redirect_url .= '?' . $redirect['query']; } } if ($redirect_url && $redirect_url != $requested_url) { // var_dump($redirect_url); die(); $redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url); if ($do_redirect) { // protect against chained redirects if (!redirect_canonical($redirect_url, false)) { wp_redirect($redirect_url, 301); exit; } else { return false; } } else { return $redirect_url; } } else { return false; } }