Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am setting up a custom author edit comments admin page so that the author can only see their comments or comments made to their post. Each author can control a handful of posts.

I have a function set up to call another to display the comments on a per post basis.

Function 1:

function ds_user_edit_comments( $post_id, $status, $pgnum ){
global $wp_roles,$current_user;
get_currentuserinfo();

$post_id = $_GET['pid'];
$status = $_GET['status'];
$pgnum = $_GET['pgnum'];

$posttype = get_post_type( $post_id );

switch( $posttype ):

    case 'boutique':
        $baseurl = admin_url('index.php?page=user_boutique_comments');
    break;

    case 'designer':
        $baseurl = admin_url('index.php?page=user_designer_comments');
    break;

    case 'consultant':
        $baseurl = admin_url('index.php?page=user_consultant_comments');
    break;

    case 'lingerie-publication':
        $baseurl = admin_url('index.php?page=user_publication_comments');
    break;

    case 'photographer':
        $baseurl = admin_url('index.php?page=user_photographer_comments');
    break;

    default:
    break;

endswitch;

?>

<div class="wrap">

    <h2>Comments for: <?php echo get_post_title( $post_id ); ?></h2>

    <ul class="subsubsub">
        <li><a href="<?php echo $baseurl; ?>&pid=<?php echo $post_id; ?>&status=all">All</a></li>
        <li><a href="<?php echo $baseurl; ?>&pid=<?php echo $post_id; ?>&status=hold">Pending</a></li>
        <li><a href="<?php echo $baseurl; ?>&pid=<?php echo $post_id; ?>&status=approved">Approved</a></li>
        <li><a href="<?php echo $baseurl; ?>&pid=<?php echo $post_id; ?>&status=spam">Spam</a></li>
        <li><a href="<?php echo $baseurl; ?>&pid=<?php echo $post_id; ?>&status=trash">Trash</a></li>
    </ul>

    <form id="comments-form" method="get" action="">

        <p class="searchbox">@TODO - COMMENTS SEARCH</p>

        <?php ds_user_comment_list( $post_id, $status ); ?>

    </form>

</div>
<!-- /end .wrap -->

<?php 
}//end ds_user_edit_comments

Function 2:

//displays the list of comments for a particular post_id
function ds_user_comment_list( $post_id, $status = '', $pagenum = 1 ){
$com_edit_url = admin_url('comment.php?action=editcomment&c=');
if( !$status ) $status = 'all';

//for paging
if( $pagenum = 1 ):
    $offset = 0;
else:
    $offset = (20*$pagenum);
endif;

if( $status != 'all' ):
    $args = array(
                  'post_id' => $post_id,
                  'offset' => $offset,
                  'status' => $status
                  //'number' => 20 //for paging
                  );
else:
    $args = array(
                  'post_id' => $post_id,
                  'offset' => $offset,
                  //'number' => 20 //for paging
                  );    
endif;

$comments = get_comments( $args );

if( $comments ):
?>

<table class="widefat fixed comments" cellspacing="0">

    <tbody id="the-comment-list" class="list:comments">

    <?php
    foreach( $comments as $comment ):
        $u_id = $comment->user_id;
        $profile_id = get_user_entry_postid( $u_id, 'lingerista' );
        $profile_avatar = get_the_post_thumbnail( $profile_id, 'mini-profile' );
    ?>
        <tr id="comment-<?php echo $comment->comment_ID; ?>" class="<?php echo $comment->comment_status; ?>">

            <th scope="row">&nbsp;</th>

            <td class="author column-author">
                <strong>
                    <?php echo $profile_avatar; ?>                        
                    <?php echo $comment->comment_author; ?>                    
                </strong>
            </td>

            <td class="comment column-comment">
                <div class="submitted-on">
                    Submitted on: <a href="<?php echo get_the_permalink($comment->comment_post_ID); ?>#<?php echo $comment->comment_ID; ?>" title="view this comment">
                        <?php echo $comment->comment_date; ?>
                    </a>
                </div>

                <?php echo $comment->comment_content; ?>

            </td>

            <td class="response column-response">n/a</td>

        </tr>        
    <?php
    endforeach;
    ?>

    </tbody>

    <thead>
        <th></th>
        <th>Commentor</th>
        <th>Comment</th>
        <th>In Response To</th>
    </thead>

    <tfoot>
        <th></th>
        <th>Commentor</th>
        <th>Comment</th>
        <th>In Response To</th>
    </tfoot>

</table>    

<?php
else:
?>
<p>No comments yet.</p>
<?php 
endif;//end if comments 
?>

<?php
}//end ds_user_comment_list

And my sub menu page:

//comments editing 
add_submenu_page( 'user_boutique_entry', 'Comments', 'Comments', 'read', 'user_boutique_comments&pid='.$boutique_id.'&status=all&pgnum=1', ds_user_edit_comments );

$boutique_id is obtained with another function preceding the user menu function.

I think it has to do with passing the variables as part of the URLs but am unsure. I'd like to use the same function for each of the post types. Users can control one of five different post types. I'd hat to have to write out functions for each post type.

So can I pass variables in the URL in admin sub menus, and if so, what am I missing?

Thanx for the help!

share|improve this question
Tired using add_query_arg and add_query_var but still get the 'Access Denied ' message. I can't be the only person who has tried this. What alternatives do I have to adding a variable to the URL? Anyone Please! – dkmojo Oct 23 '11 at 17:39
I ended up using jQuery functions to get my paging to work. Not exactly what I had wanted but until the WP_List_Table class is finalized it's the best I've got. Thanx. – dkmojo Oct 24 '11 at 18:20

closed as too localized by toscho Oct 7 '12 at 18:16

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.