• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP is_robots函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中is_robots函数的典型用法代码示例。如果您正苦于以下问题:PHP is_robots函数的具体用法?PHP is_robots怎么用?PHP is_robots使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了is_robots函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: add_snippet

 /**
  * Add custom javascript within head section.
  *
  * @since 1.0.0
  */
 public function add_snippet()
 {
     if (\is_admin()) {
         return;
     }
     if (\is_feed()) {
         return;
     }
     if (\is_robots()) {
         return;
     }
     if (\is_trackback()) {
         return;
     }
     $disable_recording = boolval(\get_post_meta(\get_the_id(), 'smartlook_disable_rec', true));
     // Disable recording for this content type
     if ($disable_recording) {
         return;
     }
     $snippet = trim(\get_option('smartlook_snippet'));
     if (empty($snippet)) {
         return;
     }
     echo $snippet;
 }
开发者ID:s3rgiosan,项目名称:wpsmartlook,代码行数:30,代码来源:Frontend.php


示例2: my_template_redirect

function my_template_redirect()
{
    global $wp, $ocmx_post_types;
    $wp->query_vars["post_type"] = "";
    $ocmx_post_types = array();
    $ocmx_post_types[] = "quote";
    $ocmx_post_types[] = "info-box";
    $ocmx_post_types[] = "portfolio";
    if (in_array($wp->query_vars["post_type"], $ocmx_post_types)) {
        if (is_robots()) {
            do_action('do_robots');
            return;
        } elseif (is_feed()) {
            do_feed();
            return;
        } elseif (is_trackback()) {
            include ABSPATH . 'wp-trackback.php';
            return;
        } elseif ($wp->query_vars["name"]) {
            include TEMPLATEPATH . "/single-" . $wp->query_vars["post_type"] . ".php";
            die;
        } else {
            include TEMPLATEPATH . "/" . $wp->query_vars["post_type"] . ".php";
            die;
        }
    }
}
开发者ID:shimion,项目名称:git,代码行数:27,代码来源:post-type-redirect.php


示例3: bogo_init

function bogo_init()
{
    bogo_languages();
    if (!(is_admin() || is_robots() || is_feed() || is_trackback())) {
        $locale = get_locale();
        if (!isset($_COOKIE['lang']) || $_COOKIE['lang'] != $locale) {
            setcookie('lang', $locale, 0, '/');
        }
    }
}
开发者ID:karthikakamalanathan,项目名称:wp-cookieLawInfo,代码行数:10,代码来源:bogo.php


示例4: wp_footer

 function wp_footer()
 {
     if (!is_admin() && !is_feed() && !is_robots() && !is_trackback()) {
         $text = get_option('shfs_insert_footer', '');
         $text = convert_smilies($text);
         $text = do_shortcode($text);
         if ($text != '') {
             echo $text, "\n";
         }
     }
 }
开发者ID:prashantbarca,项目名称:prashant.at,代码行数:11,代码来源:shfs.php


示例5: pt_footer

/**
 *
 *
 * @desc Display blog footer. Show Publishthis logo if needed
 */
function pt_footer()
{
    global $publishthis;
    if (!is_admin() && !is_feed() && !is_robots() && !is_trackback()) {
        try {
            echo pt_curated_by(), "\n";
            echo "<script type='text/javascript' src='http://curateby.publishthis.com/clients.js'></script>";
        } catch (Exception $ex) {
        }
    }
}
开发者ID:humanmade,项目名称:vip-mu-plugins-public,代码行数:16,代码来源:ptfooter.php


示例6: stats_template_redirect

function stats_template_redirect()
{
    global $wp_the_query, $current_user, $stats_footer;
    if (is_feed() || is_robots() || is_trackback()) {
        return;
    }
    $options = stats_get_options();
    // Ensure this is always setup for the check below
    $options['reg_users'] = empty($options['reg_users']) ? false : true;
    if (!$options['reg_users'] && !empty($current_user->ID)) {
        return;
    }
    add_action('wp_footer', 'stats_footer', 101);
    add_action('wp_head', 'stats_add_shutdown_action');
    $blog = Jetpack::get_option('id');
    $tz = get_option('gmt_offset');
    $v = 'ext';
    $j = sprintf('%s:%s', JETPACK__API_VERSION, JETPACK__VERSION);
    if ($wp_the_query->is_single || $wp_the_query->is_page || $wp_the_query->is_posts_page) {
        // Store and reset the queried_object and queried_object_id
        // Otherwise, redirect_canonical() will redirect to home_url( '/' ) for show_on_front = page sites where home_url() is not all lowercase.
        // Repro:
        // 1. Set home_url = http://ExamPle.com/
        // 2. Set show_on_front = page
        // 3. Set page_on_front = something
        // 4. Visit http://example.com/
        $queried_object = isset($wp_the_query->queried_object) ? $wp_the_query->queried_object : null;
        $queried_object_id = isset($wp_the_query->queried_object_id) ? $wp_the_query->queried_object_id : null;
        $post = $wp_the_query->get_queried_object_id();
        $wp_the_query->queried_object = $queried_object;
        $wp_the_query->queried_object_id = $queried_object_id;
    } else {
        $post = '0';
    }
    $http = is_ssl() ? 'https' : 'http';
    $week = gmdate('YW');
    $data = stats_array(compact('v', 'j', 'blog', 'post', 'tz'));
    $stats_footer = <<<END

\t<script src="{$http}://stats.wordpress.com/e-{$week}.js" type="text/javascript"></script>
\t<script type="text/javascript">
\tst_go({{$data}});
\tvar load_cmc = function(){linktracker_init({$blog},{$post},2);};
\tif ( typeof addLoadEvent != 'undefined' ) addLoadEvent(load_cmc);
\telse load_cmc();
\t</script>
END;
    if (isset($options['hide_smile']) && $options['hide_smile']) {
        $stats_footer .= "\n<style type='text/css'>img#wpstats{display:none}</style>";
    }
}
开发者ID:lu-inc,项目名称:growingminds,代码行数:51,代码来源:stats.php


示例7: is_active

 /**
  * Is Active?
  */
 function is_active()
 {
     // Always allow access to robots.txt
     if (is_robots()) {
         return false;
     }
     if ((bool) get_option('password_protected_status')) {
         if (!defined('DONOTCACHEPAGE')) {
             define('DONOTCACHEPAGE', true);
         }
         return true;
     }
     return false;
 }
开发者ID:adams0917,项目名称:woocommerce_eht,代码行数:17,代码来源:password-protected.php


示例8: add_snippet

 /**
  * Add custom javascript within head section.
  *
  * @since 1.0.0
  */
 public function add_snippet()
 {
     if (\is_admin()) {
         return;
     }
     if (\is_feed()) {
         return;
     }
     if (\is_robots()) {
         return;
     }
     if (\is_trackback()) {
         return;
     }
     $snippet = trim(\get_option('jaco_snippet'));
     if (empty($snippet)) {
         return;
     }
     echo $snippet;
 }
开发者ID:s3rgiosan,项目名称:wpjaco,代码行数:25,代码来源:Frontend.php


示例9: stats_template_redirect

function stats_template_redirect()
{
    global $wp_the_query, $current_user, $stats_footer;
    if (is_feed() || is_robots() || is_trackback()) {
        return;
    }
    $options = stats_get_options();
    // Ensure this is always setup for the check below
    $options['reg_users'] = empty($options['reg_users']) ? false : true;
    if (!$options['reg_users'] && !empty($current_user->ID)) {
        return;
    }
    add_action('wp_footer', 'stats_footer', 101);
    add_action('wp_head', 'stats_add_shutdown_action');
    $blog = Jetpack::get_option('id');
    $v = 'ext';
    $j = sprintf('%s:%s', JETPACK__API_VERSION, JETPACK__VERSION);
    if ($wp_the_query->is_single || $wp_the_query->is_page || $wp_the_query->is_posts_page) {
        $post = $wp_the_query->get_queried_object_id();
    } else {
        $post = '0';
    }
    $http = is_ssl() ? 'https' : 'http';
    $week = gmdate('YW');
    $data = stats_array(compact('v', 'j', 'blog', 'post'));
    $stats_footer = <<<END

\t<script src="{$http}://stats.wordpress.com/e-{$week}.js" type="text/javascript"></script>
\t<script type="text/javascript">
\tst_go({{$data}});
\tvar load_cmc = function(){linktracker_init({$blog},{$post},2);};
\tif ( typeof addLoadEvent != 'undefined' ) addLoadEvent(load_cmc);
\telse load_cmc();
\t</script>
END;
    if (isset($options['hide_smile']) && $options['hide_smile']) {
        $stats_footer .= "\n<style type='text/css'>img#wpstats{display:none}</style>";
    }
}
开发者ID:Bencheci,项目名称:blueRavenStudiosProject,代码行数:39,代码来源:stats.php


示例10: add_snippet

 /**
  * Add custom javascript within footer section.
  *
  * Note: I'm using double quotes instead of single quotes to maintain the script's original structure.
  *
  * @since 1.0.0
  */
 public function add_snippet()
 {
     if (\is_admin()) {
         return;
     }
     if (\is_feed()) {
         return;
     }
     if (\is_robots()) {
         return;
     }
     if (\is_trackback()) {
         return;
     }
     echo "<script><!--//--><![CDATA[//><!—\r\n";
     /**
      * Filter the default netscope analytics variable.
      *
      * @since  1.1.0
      * @param  string Default variable name.
      * @return string Possibly-modified variable name.
      */
     $netscope_var = \apply_filters('wpnetscope_default_netscope_var', 'GEMIUS');
     // netScope analytics tag
     printf("var %s = '%s';", \esc_html($netscope_var), \esc_html($this->get_netscope_tag()));
     // netScope account ID
     $identifier = trim(\get_option('netscope_gemius_identifier'));
     if (!empty($identifier)) {
         printf("var pp_gemius_identifier = '%s';", \esc_html($identifier));
     }
     // netScope extra parameters
     $extraparameters = $netscope_var;
     printf("var pp_gemius_extraparameters = new Array('gA='+%s);", \esc_html($extraparameters));
     echo "var pp_gemius_event = pp_gemius_event || function() {var x = window.gemius_sevents = window.gemius_sevents || []; x[x.length]=arguments;}; ( function(d,t) { var ex; try { var gt=d.createElement(t),s=d.getElementsByTagName(t)[0],l='http'+((location.protocol=='https:')?'s://secure':'://data'); gt.async='true'; gt.src=l+'.netscope.marktest.pt/netscope-gemius.js'; s.parentNode.appendChild(gt);} catch (ex){}}(document,'script'));";
     echo "\r\n//--><!]]></script>";
 }
开发者ID:s3rgiosan,项目名称:wpnetscope,代码行数:43,代码来源:Frontend.php


示例11:

                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
} else {
    // Process feeds and trackbacks even if not using themes.
    if (is_robots()) {
        do_action('do_robots');
        return;
    } else {
        if (is_feed()) {
            do_feed();
            return;
        } else {
            if (is_trackback()) {
                include ABSPATH . '/wp-trackback.php';
                return;
            }
        }
    }
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:31,代码来源:template-loader.php


示例12: redirect_canonical

/**
 * 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'))) {
//.........这里部分代码省略.........
开发者ID:laiello,项目名称:cartonbank,代码行数:101,代码来源:canonical.php


示例13: redirect_canonical

/**
 * 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']) ) {
//.........这里部分代码省略.........
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:101,代码来源:canonical.php


示例14: stats_template_redirect

function stats_template_redirect()
{
    global $current_user, $stats_footer;
    if (is_feed() || is_robots() || is_trackback() || is_preview()) {
        return;
    }
    // Should we be counting this user's views?
    if (!empty($current_user->ID)) {
        $count_roles = stats_get_option('count_roles');
        if (!array_intersect($current_user->roles, $count_roles)) {
            return;
        }
    }
    add_action('wp_footer', 'stats_footer', 101);
    add_action('wp_head', 'stats_add_shutdown_action');
    $script = set_url_scheme('//stats.wp.com/e-' . gmdate('YW') . '.js');
    $data = stats_build_view_data();
    $data_stats_array = stats_array($data);
    $stats_footer = <<<END
<script type='text/javascript' src='{$script}' async defer></script>
<script type='text/javascript'>
\t_stq = window._stq || [];
\t_stq.push([ 'view', {{$data_stats_array}} ]);
\t_stq.push([ 'clickTrackerInit', '{$data['blog']}', '{$data['post']}' ]);
</script>

END;
}
开发者ID:iamtakashi,项目名称:jetpack,代码行数:28,代码来源:stats.php


示例15: wpcf7_cleanup_upload_files

function wpcf7_cleanup_upload_files()
{
    if (is_admin() || 'GET' != $_SERVER['REQUEST_METHOD'] || is_robots() || is_feed() || is_trackback()) {
        return;
    }
    $dir = trailingslashit(wpcf7_upload_tmp_dir());
    if (!is_dir($dir) || !is_readable($dir) || !wp_is_writable($dir)) {
        return;
    }
    if ($handle = @opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file == "." || $file == ".." || $file == ".htaccess") {
                continue;
            }
            $mtime = @filemtime($dir . $file);
            if ($mtime && time() < $mtime + 60) {
                // less than 60 secs old
                continue;
            }
            wpcf7_rmdir_p(path_join($dir, $file));
        }
        closedir($handle);
    }
}
开发者ID:flasomm,项目名称:Montkailash,代码行数:24,代码来源:file.php


示例16: mf_change_template

 function mf_change_template()
 {
     global $post;
     // Check global post
     if (empty($post)) {
         return;
     }
     // Process feeds and trackbacks even if not using themes.
     if (is_robots()) {
         do_action('do_robots');
         return;
     } elseif (is_feed()) {
         do_feed();
         return;
     } elseif (is_trackback()) {
         include ABSPATH . 'wp-trackback.php';
         return;
     }
     // Check if the post has a special template
     $template = get_post_meta($post->ID, '_wp_mf_page_template', true);
     if (!$template || $template == 'default') {
         return;
     }
     $template = TEMPLATEPATH . '/' . $template;
     if ($template = apply_filters('template_include', $template)) {
         include $template;
         die;
     }
     return;
 }
开发者ID:GafaMX,项目名称:operaciondespierta.org,代码行数:30,代码来源:main.php


示例17: redirect_canonical

/**
 * 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);
            }
        }
//.........这里部分代码省略.........
开发者ID:hadywisam,项目名称:WordPress,代码行数:101,代码来源:canonical.php


示例18: is_single

 /**
  * Gets post/page ID if current page is singular
  *
  * @since	3.1.2
  */
 public function is_single()
 {
     if ((is_single() || is_page()) && !is_front_page() && !is_preview() && !is_trackback() && !is_feed() && !is_robots()) {
         global $post;
         $this->current_post_id = is_object($post) ? $post->ID : 0;
     } else {
         $this->current_post_id = 0;
     }
 }
开发者ID:Chouby,项目名称:wordpress-popular-posts,代码行数:14,代码来源:wordpress-popular-posts.php


示例19: check_canonical_url

 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;
 }
开发者ID:rochellecanale,项目名称:wordpress,代码行数:55,代码来源:frontend-links.php


示例20: handle_404

 /**
  * Set the Headers for 404, if nothing is found for requested URL.
  *
  * Issue a 404 if a request doesn't match any posts and doesn't match
  * any object (e.g. an existing-but-empty category, tag, author) and a 404 was not already
  * issued, and if the request was not a search or the homepage.
  *
  * Otherwise, issue a 200.
  *
  * This sets headers after posts have been queried. handle_404() really means "handle status."
  * By inspecting the result of querying posts, seemingly successful requests can be switched to
  * a 404 so that canonical redirection logic can kick in.
  *
  * @since 2.0.0
  * @access public
  *
  * @global WP_Query $wp_query
  */
 public function handle_404()
 {
     global $wp_query;
     /**
      * Filter whether to short-circuit default header status handling.
      *
      * Returning a non-false value from the filter will short-circuit the handling
      * and return early.
      *
      * @since 4.5.0
      *
      * @param bool     $preempt  Whether to short-circuit default header status handling. Default false.
      * @param WP_Query $wp_query WordPress Query object.
      */
     if (false !== apply_filters('pre_handle_404', false, $wp_query)) {
         return;
     }
     // If we've already issued a 404, bail.
     if (is_404()) {
         return;
     }
     // Never 404 for the admin, robots, or if we found posts.
     if (is_admin() || is_robots() || $wp_query->posts) {
         $success = true;
         if (is_singular()) {
             $p = false;
             if ($wp_query->post instanceof WP_Post) {
                 $p = clone $wp_query->post;
             }
             // Only set X-Pingback for single posts that allow pings.
             if ($p && pings_open($p)) {
                 @header('X-Pingback: ' . get_bloginfo('pingback_url'));
             }
             // check for paged content that exceeds the max number of pages
             $next = '<!--nextpage-->';
             if ($p && false !== strpos($p->post_content, $next) && !empty($this->query_vars['page'])) {
                 $page = trim($this->query_vars['page'], '/');
                 $success = (int) $page <= substr_count($p->post_content, $next) + 1;
             }
         }
         if ($success) {
             status_header(200);
             return;
         }
     }
     // We will 404 for paged queries, as no posts were found.
     if (!is_paged()) {
         // Don't 404 for authors without posts as long as they matched an author on this site.
         $author = get_query_var('author');
         if (is_author() && is_numeric($author) && $author > 0 && is_user_member_of_blog($author)) {
             status_header(200);
             return;
         }
         // Don't 404 for these queries if they matched an object.
         if ((is_tag() || is_category() || is_tax() || is_post_type_archive()) && get_queried_object()) {
             status_header(200);
             return;
         }
         // Don't 404 for these queries either.
         if (is_home() || is_search() || is_feed()) {
             status_header(200);
             return;
         }
     }
     // Guess it's time to 404.
     $wp_query->set_404();
     status_header(404);
     nocache_headers();
 }
开发者ID:qaryas,项目名称:qaryas_site,代码行数:87,代码来源:class-wp.php



注:本文中的is_robots函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP is_role_switched函数代码示例发布时间:2022-05-15
下一篇:
PHP is_restored_user函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap