WordPress.org

Forums

[resolved] PHP Guru's Help Needed. (9 posts)

  1. trivum
    Member
    Posted 7 years ago #

    I recently made a hack into the wp-admin/edit.php file so that when users (authors/contributors/etc.) were in their backend and managing their posts, they only saw the posts they had made, not everyone esle's.

    I found this line:

    wp("what_to_show=posts$post_status_q&posts_per_page=15&order=$order&orderby=$orderby");

    and replaced it with the following:

    $thisauthor='';
    if (!current_user_can('edit_others_posts'))
    $thisauthor = '&author=' . $user_ID;
    wp('what_to_show=posts&posts_per_page&=15&order=$order&orderby=$orderby' . $thisauthor);

    That did the trick. But now when I use the filter post option (pending review, published, any), it doesn't work.

    Any idea how I can get both functions to work?

    Thanks for any suggestions.

  2. trivum
    Member
    Posted 7 years ago #

    Anyone with ideas for this? Thanks.

  3. Why did you remove the $post_status_q variable from the call to the wp() function?

    Try adding it back.

  4. trivum
    Member
    Posted 7 years ago #

    Why did you remove the $post_status_q variable from the call to the wp() function?

    Try adding it back.

    I did try that before, but maybe I'm not getting the right syntax or something. I tried it in a few different spots.

    Any suggestions for how it might go?

  5. Exactly the same as you have it in your post above:

    wp("what_to_show=posts$post_status_q&posts_per_page...

    The double quotes around that string are key here. You can't use single quotes like you do in your second example. Whenever you're using $variables inside a string, it must be double quoted.

  6. trivum
    Member
    Posted 7 years ago #

    Thanks for the suggestion, but it still doesn't seem to quite be working. Maybe I'm still doing something wrong. Per your suggestions, this is what I'm putting in:

    $thisauthor='';
    if (!current_user_can('edit_others_posts'))
    $thisauthor = '&author=' . $user_ID;
    wp("what_to_show=posts&post_status_q&posts_per_page&=15&order=$order&orderby=$orderby" . $thisauthor);
  7. Kafkaesqui

    Posted 7 years ago #

    Still not right. Compare Otto's line to yours:

    $post_status_q

    vs.

    &post_status_q

    Use the dollar sign (making it a PHP variable), not the ampersand, to prefix post_status_q.

  8. Yep. What's more, your code is overkill. Eliminate all that extra variable and concatenation work.

    Edit: Removed non-working code. I guess I'm confused about what you were trying to do in the first place.

  9. trivum
    Member
    Posted 7 years ago #

    Great! Excellent! Everything seems to work - I put in the $ instead of the &. Not knowing php, I didn't even notice at first.

    Otto - your more streamlined code didn't seem to work for me. I wasn't able to see any posts under Manage when I tried it, but maybe it was just how my particular system was interacting with it.

    By the way, if either of you have any say-so about the core code, I would suggest adding this. I think it would help a lot if the users that are contributing to the blog don't have to wade through everyone else's posts in their Manage section. It makes it much more user-friendly. I can also see situations (such as mine) where the Administrator wants the contributors to feel they have their own personal backend section.

Topic Closed

This topic has been closed to new replies.

About this Topic