Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

how can i check if the current post belongs to the current author? this is my basic code; `

if($curpost) {
                wpuf_edit_show_form($curpost);
            } else {
                $error = "there is no post.";
            }

`

also how can i add the same control to these action; `

function wpuf_user_dashboard_post_list() {
    global $wpdb, $userdata;

    get_currentuserinfo(); // grabs the user info and puts into vars

    //delete post
    if ($_REQUEST['action'] == "del")
    {
        check_admin_referer('wpuf_del');
        wp_delete_post($_REQUEST['pid']);
        echo '<div class="success">deleted.</div>';
    }

    //get the posts
    $sql = "SELECT ID, post_title, post_name, post_status, post_date "
            . "FROM $wpdb->posts "
            . "WHERE post_author = $userdata->ID AND post_type = 'post' "
            . "AND (post_status = 'publish' OR post_status = 'pending' OR post_status = 'draft') ";

    $posts = $wpdb->get_results($sql);
    $count = 1;
    //d($posts);

`

thanks.

share|improve this question
    
There are dozens of Qs about this topic. –  kaiser Oct 29 '11 at 11:13

1 Answer 1

up vote 1 down vote accepted

A compacted version that does not load the globals yet calls upon them directly.

if(
    is_user_logged_in() and // Force user validation... STUFF
    !empty($GLOBALS['post']) and // Check if a $post exists in globals
    !empty($GLOBALS['current_user']) and // Check if current_user exists in globals
    ($GLOBALS['current_user']->ID == $GLOBALS['post']->post_author) // Match User IDs
){
    // This is your Author speaking, use the Force!
}

Regards.

share|improve this answer
1  
thank you earnesto –  boranb Oct 29 '11 at 15:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.