WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 12 months ago

#17912 closed defect (bug) (duplicate)

WordPress not "realizing" that I'm an author on 404 error page

Reported by: itsalltech1 Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2
Component: General Keywords: has-patch needs-testing dev-feedback
Focuses: Cc:

Description

Hello.

I have a link in my header that only appears if a user is an author or higher; it's the new post link. The link appears on all pages when I'm logged in as an author, except when there is a 404 error. On a 404 error page, the link doesn't display (almost as if WordPress thinks I'm not an author, just a subscriber).

WordPress does still pickup that I'm logged in, however, as the link below the new post link is to logout (and it displays that).

Attachments (2)

17912.patch (537 bytes) - added by jakub.tyrcha 3 years ago.
17912.diff (1.8 KB) - added by MikeHansenMe 12 months ago.

Download all attachments as: .zip

Change History (17)

comment:1 scribu3 years ago

  • Keywords reporter-feedback added

Please post the code that generates that link. Otherwise, there's not much we can do.

comment:2 itsalltech13 years ago

<?php
if ( is_user_logged_in() && current_user_can('edit_post') ) {?>
<div id="settings">
                <a href="#" class="button">
                    <span class="txt">
                    <div style="float:left;margin-right:5px">
   <?php global $userdata; get_currentuserinfo(); echo get_avatar( $userdata->ID, '16' ); ?>
</div>
<span style="float:left">
                    <?php global $current_user;
      get_currentuserinfo();

      echo $current_user->user_login . "\n";
?>
</span>
                     </span>
                    <span class="ar">&#9660;</span>
                </a>
                <div class="menu">
                    <ul>
                        <li><a style="text-decoration:none" href="/wp-admin/post-new.php">New Post</a></li>

[SNIP]

<?php } ?>
Last edited 3 years ago by scribu (previous) (diff)

comment:3 itsalltech13 years ago

  • Keywords reporter-feedback removed

comment:4 itsalltech13 years ago

Is there any update on this? The issue still occurs in WordPress 3.2 RC3

comment:5 duck_3 years ago

  • Keywords close reporter-feedback added

It seems to me that this code appears in one of your theme's files that isn't included on a 404 when 404.php will be loaded. If this is the case then there is nothing that WordPress can do.

comment:6 itsalltech13 years ago

I'm a bit confused on that. I'm loading that code in the header.php file, meaning that it should still load on a 404 page, correct? Or do I need to copy the exact header.php file into 404.php?

comment:7 itsalltech13 years ago

I tried placing the following code directly in the 404.php and it still didn't work...

<?php if( current_user_can('edit_post') ) : ?> <a href="<?php bloginfo("url")?>/wp-admin/post-new.php"><?php _e('New Post', ''); ?></a> <?php endif; ?>

comment:8 itsalltech13 years ago

  • Keywords close reporter-feedback removed

jakub.tyrcha3 years ago

comment:9 jakub.tyrcha3 years ago

  • Keywords has-patch dev-feedback added

This patch does the trick, but I would love to hear some feedback about the potential problems with the if ( ! $post_type) thing

comment:10 itsalltech13 years ago

  • Cc be.roth@… added
  • Keywords needs-review added; has-patch dev-feedback removed

Please see next comment.

Last edited 3 years ago by itsalltech1 (previous) (diff)

comment:11 itsalltech13 years ago

  • Keywords has-patch needs-testing dev-feedback added; needs-review removed

Disregard that last comment. The patch does the trick - I was applying it around line 830, but 880. Thanks for solving. Now, seems like a few tests have to be run and that's that.

Version 0, edited 3 years ago by itsalltech1 (next)

comment:12 jakub.tyrcha3 years ago

Yeah the patch does work, but I have serious doubts about the conditional line and unless one of the devs who knows well this particular line of code gives it a go, I seriously doubt it will make the core

comment:13 MikeHansenMe12 months ago

When I am viewing a 404 page with the code above in my header.php file I run into a few problem.

$args = array_slice( func_get_args(), 2 );

Grabs any extra parameters. Later in the code it uses $args[0] without even checking that it is set. This causes a ton of undefined index and later does

$post = get_post( $args[0] );

and assumes $post is post data when it is actually an empty array, causing even more undefined index notices.

My patch just breaks out when they are not set. No need for conditional checks when there are other notices anyways.

Last edited 12 months ago by MikeHansenMe (previous) (diff)

MikeHansenMe12 months ago

comment:14 MikeHansenMe12 months ago

  • Cc mdhansen@… added

comment:15 nacin12 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

current_user_can('edit_post') is incorrect. edit_post is a meta capability, requiring a second argument. This is a duplicate of #13905 — if the post doesn't exist, then breaking out and requiring no cap seems like the wrong thing to do.

Note: See TracTickets for help on using tickets.