本文整理汇总了PHP中WP_Query::set_404方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::set_404方法的具体用法?PHP WP_Query::set_404怎么用?PHP WP_Query::set_404使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Query
的用法示例。
在下文中一共展示了WP_Query::set_404方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set404
/**
* {@inheritdoc}
*/
public function set404($message = 'Not Found')
{
$this->_cms->trigger(AbstractEvents::EVENT_SHUTDOWN);
$this->_cms->trigger(AbstractEvents::EVENT_SHUTDOWN . '.404', [&$message]);
Ob::clean();
$this->_wp_query->set_404();
status_header(404);
$this->noCache();
\_default_wp_die_handler($message, $message, array('response' => 404, 'back_link' => true));
}
示例2: redirect
/**
* Hijack requests for potential sitemaps and XSL files.
*
* @param \WP_Query $query Main query instance.
*/
public function redirect($query)
{
if (!$query->is_main_query()) {
return;
}
$xsl = get_query_var('xsl');
if (!empty($xsl)) {
$this->xsl_output($xsl);
$this->sitemap_close();
return;
}
$type = get_query_var('sitemap');
if (empty($type)) {
return;
}
$this->set_n(get_query_var('sitemap_n'));
if (!$this->get_sitemap_from_cache($type, $this->current_page)) {
$this->build_sitemap($type);
}
if ($this->bad_sitemap) {
$query->set_404();
status_header(404);
return;
}
$this->output();
$this->sitemap_close();
}
示例3: bbp_parse_query
/**
* Add checks for bbPress conditions to parse_query action
*
* If it's a user page, WP_Query::bbp_is_single_user is set to true.
* If it's a user edit page, WP_Query::bbp_is_single_user_edit is set to true
* and the the 'wp-admin/includes/user.php' file is included.
* In addition, on user/user edit pages, WP_Query::home is set to false & query
* vars 'bbp_user_id' with the displayed user id and 'author_name' with the
* displayed user's nicename are added.
*
* If it's a forum edit, WP_Query::bbp_is_forum_edit is set to true
* If it's a topic edit, WP_Query::bbp_is_topic_edit is set to true
* If it's a reply edit, WP_Query::bbp_is_reply_edit is set to true.
*
* If it's a view page, WP_Query::bbp_is_view is set to true
* If it's a search page, WP_Query::bbp_is_search is set to true
*
* @since bbPress (r2688)
*
* @param WP_Query $posts_query
*
* @uses get_query_var() To get {@link WP_Query} query var
* @uses is_email() To check if the string is an email
* @uses get_user_by() To try to get the user by email and nicename
* @uses get_userdata() to get the user data
* @uses current_user_can() To check if the current user can edit the user
* @uses is_user_member_of_blog() To check if user profile page exists
* @uses WP_Query::set_404() To set a 404 status
* @uses apply_filters() Calls 'enable_edit_any_user_configuration' with true
* @uses bbp_get_view_query_args() To get the view query args
* @uses bbp_get_forum_post_type() To get the forum post type
* @uses bbp_get_topic_post_type() To get the topic post type
* @uses bbp_get_reply_post_type() To get the reply post type
* @uses remove_action() To remove the auto save post revision action
*/
function bbp_parse_query($posts_query)
{
// Bail if $posts_query is not the main loop
if (!$posts_query->is_main_query()) {
return;
}
// Bail if filters are suppressed on this query
if (true === $posts_query->get('suppress_filters')) {
return;
}
// Bail if in admin
if (is_admin()) {
return;
}
// Get query variables
$bbp_view = $posts_query->get(bbp_get_view_rewrite_id());
$bbp_user = $posts_query->get(bbp_get_user_rewrite_id());
$is_edit = $posts_query->get(bbp_get_edit_rewrite_id());
// It is a user page - We'll also check if it is user edit
if (!empty($bbp_user)) {
/** Find User *********************************************************/
// Setup the default user variable
$the_user = false;
// If using pretty permalinks, use the email or slug
if (get_option('permalink_structure')) {
// Email was passed
if (is_email($bbp_user)) {
$the_user = get_user_by('email', $bbp_user);
// Try nicename
} else {
$the_user = get_user_by('slug', $bbp_user);
}
}
// No user found by slug/email, so try the ID if it's numeric
if (empty($the_user) && is_numeric($bbp_user)) {
$the_user = get_user_by('id', $bbp_user);
}
// 404 and bail if user does not have a profile
if (empty($the_user->ID) || !bbp_user_has_profile($the_user->ID)) {
$posts_query->set_404();
return;
}
/** User Exists *******************************************************/
$is_favs = $posts_query->get(bbp_get_user_favorites_rewrite_id());
$is_subs = $posts_query->get(bbp_get_user_subscriptions_rewrite_id());
$is_topics = $posts_query->get(bbp_get_user_topics_rewrite_id());
$is_replies = $posts_query->get(bbp_get_user_replies_rewrite_id());
// View or edit?
if (!empty($is_edit)) {
// We are editing a profile
$posts_query->bbp_is_single_user_edit = true;
// Load the core WordPress contact methods
if (!function_exists('_wp_get_user_contactmethods')) {
include_once ABSPATH . 'wp-includes/registration.php';
}
// Load the edit_user functions
if (!function_exists('edit_user')) {
require_once ABSPATH . 'wp-admin/includes/user.php';
}
// Load the grant/revoke super admin functions
if (is_multisite() && !function_exists('revoke_super_admin')) {
require_once ABSPATH . 'wp-admin/includes/ms.php';
}
// Editing a user
$posts_query->bbp_is_edit = true;
//.........这里部分代码省略.........
示例4: bbp_parse_query
/**
* Add checks for bbPress conditions to parse_query action
*
* If it's a user page, WP_Query::bbp_is_single_user is set to true.
* If it's a user edit page, WP_Query::bbp_is_single_user_edit is set to true
* and the the 'wp-admin/includes/user.php' file is included.
* In addition, on user/user edit pages, WP_Query::home is set to false & query
* vars 'bbp_user_id' with the displayed user id and 'author_name' with the
* displayed user's nicename are added.
*
* If it's a forum edit, WP_Query::bbp_is_forum_edit is set to true
* If it's a topic edit, WP_Query::bbp_is_topic_edit is set to true
* If it's a reply edit, WP_Query::bbp_is_reply_edit is set to true.
*
* If it's a view page, WP_Query::bbp_is_view is set to true
*
* @since bbPress (r2688)
*
* @param WP_Query $posts_query
*
* @uses get_query_var() To get {@link WP_Query} query var
* @uses is_email() To check if the string is an email
* @uses get_user_by() To try to get the user by email and nicename
* @uses WP_User to get the user data
* @uses WP_Query::set_404() To set a 404 status
* @uses current_user_can() To check if the current user can edit the user
* @uses apply_filters() Calls 'enable_edit_any_user_configuration' with true
* @uses bbp_get_view_query_args() To get the view query args
* @uses bbp_get_forum_post_type() To get the forum post type
* @uses bbp_get_topic_post_type() To get the topic post type
* @uses bbp_get_reply_post_type() To get the reply post type
* @uses remove_action() To remove the auto save post revision action
*/
function bbp_parse_query($posts_query)
{
// Bail if $posts_query is not the main loop
if (!$posts_query->is_main_query()) {
return;
}
// Bail if filters are suppressed on this query
if (true == $posts_query->get('suppress_filters')) {
return;
}
// Bail if in admin
if (is_admin()) {
return;
}
// Get query variables
$bbp_user = $posts_query->get(bbp_get_user_rewrite_id());
$bbp_view = $posts_query->get(bbp_get_view_rewrite_id());
$is_edit = $posts_query->get(bbp_get_edit_rewrite_id());
// It is a user page - We'll also check if it is user edit
if (!empty($bbp_user)) {
// Not a user_id so try email and slug
if (!is_numeric($bbp_user)) {
// Email was passed
if (is_email($bbp_user)) {
$bbp_user = get_user_by('email', $bbp_user);
// Try nicename
} else {
$bbp_user = get_user_by('slug', $bbp_user);
}
// If we were successful, set to ID
if (is_object($bbp_user)) {
$bbp_user = $bbp_user->ID;
}
}
// Create new user
$user = new WP_User($bbp_user);
// Bail if no user
if (!isset($user) || empty($user) || empty($user->ID)) {
$posts_query->set_404();
return;
}
/** User Exists *******************************************************/
// View or edit?
if (!empty($is_edit)) {
// We are editing a profile
$posts_query->bbp_is_single_user_edit = true;
// Load the core WordPress contact methods
if (!function_exists('_wp_get_user_contactmethods')) {
include_once ABSPATH . 'wp-includes/registration.php';
}
// Load the edit_user functions
if (!function_exists('edit_user')) {
require_once ABSPATH . 'wp-admin/includes/user.php';
}
// Editing a user
$posts_query->bbp_is_edit = true;
// We are viewing a profile
} else {
$posts_query->bbp_is_single_user = true;
}
// Make sure 404 is not set
$posts_query->is_404 = false;
// Correct is_home variable
$posts_query->is_home = false;
// Set bbp_user_id for future reference
$posts_query->set('bbp_user_id', $user->ID);
// Set author_name as current user's nicename to get correct posts
//.........这里部分代码省略.........