Make WordPress Core

Opened 14 years ago

Closed 12 years ago

#17912 closed defect (bug) (duplicate)

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

Reported by: itsalltech1's profile 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 14 years ago.
17912.diff (1.8 KB) - added by MikeHansenMe 12 years ago.

Download all attachments as: .zip

Change History (17)

#1 @scribu
14 years ago

  • Keywords reporter-feedback added

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

#2 @itsalltech1
14 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 14 years ago by scribu (previous) (diff)

#3 @itsalltech1
14 years ago

  • Keywords reporter-feedback removed

#4 @itsalltech1
14 years ago

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

#5 @duck_
14 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.

#6 @itsalltech1
14 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?

#7 @itsalltech1
14 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; ?>

#8 @itsalltech1
14 years ago

  • Keywords close reporter-feedback removed

@jakub.tyrcha
14 years ago

#9 @jakub.tyrcha
14 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

#10 @itsalltech1
14 years ago

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

Please see next comment.

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

#11 @itsalltech1
14 years ago

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

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

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

#12 @jakub.tyrcha
14 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

#13 @MikeHansenMe
12 years 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 years ago by MikeHansenMe (previous) (diff)

@MikeHansenMe
12 years ago

#14 @MikeHansenMe
12 years ago

  • Cc mdhansen@… added

#15 @nacin
12 years 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.