0

I have exactly a same site like stachexchange. In my theme all users can ask questions. But I want to limit users to post for preventing spam. Example: 1 post per hour. Default new registration role is author. Bainternet's Posts Creation Limits plugin doesn't work with front end and I don't have any shortcode in my theme.

Here is the my posting ask a question front page.Please help me.I am using Robust Q&A Theme.(In themeforest)

    <?php
/**
 * @package WordPress
 * @subpackage Robust Q&A - WPQA
 */
 ?>

<?php
include (TEMPLATEPATH . '/translations.php');
// Define the Post Redirect
$redir = $post->ID;

/////////////////////////////
//$_COOKIE Checkers       //
///////////////////////////

// Get Question Reported Cookie to Display Success Message
if (isset($_COOKIE['content_reported_'.$post->ID])) {
    $reported_content = $_COOKIE['content_reported_'.$post->ID];
    if(isset($reported_content) && $reported_content != NULL) {
        $message = $t_message_sucsess_content_reported;
    }
}

// Get Answer Posted to Question Cookie to Display Success Message
if (isset($_COOKIE['answer_posted_'.$post->ID])) {
    $new_answer_posted = $_COOKIE['answer_posted_'.$post->ID];
    if(isset($new_answer_posted) && $new_answer_posted != NULL) {
        $message = $t_message_answer_success_posted;
    }
}

// Get Comment Posted on Answer Cookie to Display Success Message
if (isset($_COOKIE['comment_posted_'.$post->ID])) {
    $new_comment_posted = $_COOKIE['comment_posted_'.$post->ID];
    if(isset($new_comment_posted) && $new_comment_posted != NULL) {
        $message = $t_message_sucsess_comment_on_answer;
    }
}

// Get Question Already Reported Cookie to Display Error Message
if (isset($_COOKIE['already_reported_'.$post->ID])) {
    $already_reported_question = $_COOKIE['already_reported_'.$post->ID];
    if(isset($already_reported_question) && $already_reported_question != NULL) {
        $message = new WP_Error('already_reported_question', $t_message_already_reported_content);
    }
}

// Get Forgot Question Note Cookie to Display Error Message
if (isset($_COOKIE['forgot_add_note_'.$post->ID])) {
    $forgot_question_note = $_COOKIE['forgot_add_note_'.$post->ID];
    if(isset($forgot_question_note) && $forgot_question_note != NULL) {
        $message = new WP_Error('forgot_question_note', $t_message_forgot_note_text);
    }
}

// Get Question Note Added Cookie to Display Success Message
if (isset($_COOKIE['question_note_added_'.$post->ID])) {
    $question_note_added = $_COOKIE['question_note_added_'.$post->ID];
    if(isset($question_note_added) && $question_note_added != NULL) {
        $message = $t_message_note_added_to_question;
    }
}

// Get Best Answer Selected Cookie to Display Success Message
if (isset($_COOKIE['best_answer_selected_'.$post->ID])) {
    $best_answer_selected = $_COOKIE['best_answer_selected_'.$post->ID];
    if(isset($best_answer_selected) && $best_answer_selected != NULL) {
        $message = $t_message_best_answer_selected;
    }
}

// Get Remove Question Email Alerts Cookie to Display Success Message
if (isset($_COOKIE['removed_question_email_alerts_'.$post->ID])) {
    $remove_message_email_alerts = $_COOKIE['removed_question_email_alerts_'.$post->ID];
    if(isset($remove_message_email_alerts) && $remove_message_email_alerts != NULL) {
        $message = $t_message_email_alerts_removed;
    }
}

if ( isset($_POST['answer_post']) == '1') {
    $answer_content = $_POST['answer_content'];
    $source_link = $_POST['source_link'];
    $message = post_new_answer($answer_content, $source_link);
}

if ( isset($_POST['comment_on_answer_post']) == '1') {
    $comment_content = $_POST['comment_content'];
    $comment_parent_id = $_POST['comment_parent_id'];
    $message = post_new_comment_to_answer($comment_content, $comment_parent_id);
}

if ( isset($_POST['best_answer_post']) == '1') {
    $best_answer_id = $_POST['best_answer_id'];
    $best_answer_parent_question = $_POST['best_answer_parent_question'];
    $message = select_best_answer($best_answer_id, $best_answer_parent_question);
}

if ( isset($_POST['report_content']) == '1') {
    $reported_item_id = $_POST['reported_item_id'];
    $reported_type = $_POST['reported_type'];
    $question_id = $_POST['question_id'];
    $message = report_content_item($reported_item_id, $reported_type, $question_id);
}

if ( isset($_POST['add_note_to_question']) == '1') {
    $add_note_text = $_POST['add_note_text'];
    $question_id = $_POST['question_id'];
    $message = add_note_to_question($add_note_text, $question_id);
}

if ( isset($_POST['remove_email_alerts']) == '1') {
    $question_id = $_POST['remove_alerts_question'];

    $message = remove_question_email_alerts($question_id);
}

get_header();?>

<script type='text/javascript'>
    $(document).ready(function() {
       $('.boxy').boxy({modal: true, closeText: '', draggable: false, unloadOnHide: false});
    });
</script>

    <!-- Main Section -->
    <div id="main">
            <div class="mainContentTop"></div>

        <div id="mainContent">

            <!-- Center Column -->
            <div id="centerCol" class="left">

                <!-- Top Section -->
                <div class="topSection">
                    <!-- Search Form -->
                    <?php //get_search_form(); ?>
                    <!-- Search Form -->

                    <div class="introBox2">
                        <div class="greyBtn addQuestion"><a href="<?php echo home_url(); ?>/<?php echo $t_ask_a_question_permalink;?>/"><span><?php echo $t_ask_question; ?> <img src="<?php echo get_template_directory_uri(); ?>/images/grey-add-btn-icon.jpg" alt="" /></span></a></div>
                        <?php if ( current_user_can('manage_options')) {?>
                            <div class="editPageLink"><?php edit_post_link($t_edit_page_link); ?></div>
                        <?php } ?>
                        <?php include (TEMPLATEPATH . '/breadcrumb.php'); ?>   

                    </div>
                </div>
                <!-- / Top Section -->

                <!-- Left Inner Column -->

                <?php if (have_posts()) : ?>
                    <?php query_posts($query_string . ""); ?>
                    <?php while (have_posts()) : the_post(); ?>

                    <div id="leftColInner" class="left">
                        <?php 
                        if (isset($message)) {
                            display_message($message);
                        } ?>

                        <!-- Report Modal -->                                
                        <div class="reportPop hiddenContent" id="reportPop">
                            <form action="" method="post" name="reportContent">
                                <p><?php echo $t_report_content_message_text; ?></p>
                                <br />
                                <input type="hidden" value="<?php echo $post->ID ?>" name="reported_item_id" />
                                <input type="hidden" value="Question" name="reported_type" />
                                <input type="hidden" value="<?php echo $post->ID; ?>" name="question_id" />
                                <input type="hidden" value="1" name="report_content" />
                                <input type="submit" class="process" value="<?php echo $t_report_question;?>" />
                            </form
                            ><div class="clear"></div>
                        </div>
                        <!-- / Report Modal -->

                        <!-- Question -->
                        <div class="questionPageBox">
                            <div class="questionQuestion">

                                <?php 
                                    // Get data for displaying avatar
                                    $author = $authordata; 
                                    $blog_url = get_template_directory_uri();
                                    $selected_avatar_image = get_user_default_icon($author->ID);
                                    $avatar_image = '/images/default-user-avatar-'.$selected_avatar_image.'.jpg';
                                    $url = $blog_url . $avatar_image ;

                                    // Get data for linking to member profile when clicking avatar image
                                    $main_url = home_url();
                                    $author_name = get_the_author_meta('nicename');
                                    $profile_link = '/'. $t_profile_permalink .'/';
                                    $author_profile_link = $main_url . $profile_link . $author_name;
                                    $email_question_asker = get_post_meta($post->ID, 'alert_asker_emails', true);
                                ?>                 

                                <div class="questionBox" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                                    <div class="contentText">
                                        <h1><?php the_title(); ?></h1>
                                        <a name="<?php the_ID(); ?>"></a>
                                        <p class="entry"><?php the_content(); ?></p>

                                        <!-- Add Note to Question Modal -->                                
                                        <div class="reportPop hiddenContent" id="addNotePop">
                                            <form action="" method="post" name="addNoteToQuestion">
                                                <label><?php echo $t_add_note_popup_heading_text; ?>:</label>
                                                <textarea name="add_note_text"></textarea>
                                                <br /><br />
                                                <input type="hidden" value="<?php echo $post->ID ?>" name="question_id">
                                                <input type="hidden" value="1" name="add_note_to_question" />
                                                <input type="submit" class="process" value="<?php echo $t_add_a_note_link;?>" />
                                            </form
                                            ><div class="clear"></div>
                                        </div>
                                        <!-- / Add Note to Question Modal -->

                                        <!-- Remove Question Email Alerts -->                                
                                        <div class="reportPop hiddenContent" id="removeEmailAlerts">
                                            <form action="" method="post" name="removeEmailAlerts">
                                                <p><?php echo $t_remove_email_alerts_text;?></p>
                                                <br />
                                                <input type="hidden" value="<?php echo $post->ID ?>" name="remove_alerts_question">
                                                <input type="hidden" value="1" name="remove_email_alerts" />
                                                <input type="submit" class="process" value="<?php echo $t_remove_email_alerts_link;?>" />
                                            </form
                                            ><div class="clear"></div>
                                        </div>
                                        <!-- / Remove Question Email Alerts --> 

                                        <?php // Show Question Note if Set
                                        $author_note = get_post_meta($post->ID, 'question_note', true);

                                        if ($author_note != NULL) { ?>
                                            <p class="questionNote"><span><?php echo $t_author_note_heading_text;?>: </span><br /><?php echo $author_note; ?></p>
                                        <?php } ?>

                                        <?php // Show Source Link Code if Set
                                        if (isset($source_link) != NULL) { ?>
                                        <p class="sourceLink"><span><?php echo $t_link_text;?>: </span><a href="#"><?php echo $source_link; ?></a></p>
                                        <?php } ?>

                                        <?php
                                        $posttags = get_the_tags();
                                        if ($posttags) {?>
                                        <p class="tagRow"><?php the_tags($t_tags_text.' ' , ' ', ''); ?></p>
                                        <?php } ?>

                                        <p class="bylineCategory left"><?php echo $t_in_text;?>: <a href="<?php echo home_url(); ?>/<?php echo $t_category_permalink;?>/"><?php the_category(', ','multiple') ?></a> | <?php the_time(get_option( 'date_format' )); ?></p>

                                        <?php // ADD Question Note
                                        global $current_user;
                                        get_currentuserinfo();

                                        if ($post->post_author == $current_user->ID && $author_note == '') { ?>
                                            <p class="addNote left"><span>|</span><a href="#addNotePop" onclick="return; false" class="boxy" title="<?php echo $t_add_a_note_link;?>"><?php echo $t_add_a_note_link;?></a></p>
                                        <?php } ?>

                                        <?php 
                                        $email_question_asker = get_post_meta($post->ID, 'alert_asker_emails',true);

                                        if ($post->post_author == $current_user->ID && $email_question_asker == 'true') {?>
                                            <p class="addNote"><span>|</span>
                                            <a href="#removeEmailAlerts" onclick="return; false" class="boxy" title="<?php echo $t_remove_email_alerts_link;?>"><?php echo $t_remove_email_alerts_link;?></a></p>
                                        <?php } ?>

                                    </div>
                                    <div class="clear"></div>
                                </div>
                                <div class="clear"></div>
                                <div class="bylineBox otherBylineBox"><a href="<?php echo home_url(); ?>/<?php echo $t_profile_permalink;?>/<?php echo $author->user_nicename; ?>/"><span><?php echo $author->display_name; ?><?php echo getPointLevel($author->ID, 'sm'); ?><?php $expert_user = get_user_meta($author->ID, 'expert', true); if($expert_user == 'yes') { ?><img src="<?php echo get_template_directory_uri(); ?>/images/expert-badge-icon.png" alt="<?php echo $t_expert_text;?>" class="expertImg" /><?php } ?></span></a></div>

                                 <?php
                                if (is_user_logged_in()) {
                                ?>

                                <div class="bylineBoxShare" id="report<?php echo $post->ID ?>"><a href="#reportPop" onclick="return; false" class="boxy" title="<?php echo $t_report_question;?>"><span><img src="<?php echo get_template_directory_uri(); ?>/images/flag-this-icon.png" alt="<?php echo $t_report_question;?>" /></span></a></div>

                                <?php } else { ?>
                                <div class="bylineBoxShare"><a href="<?php bloginfo('siteurl'); ?>/<?php echo $t_login_permalink;?>/?redir=<?php echo $redir; ?>" title="<?php echo $t_login_signup_report_content_text;?>"><span><img src="<?php echo get_template_directory_uri(); ?>/images/flag-this-icon.png" alt="<?php echo $t_report_question;?>" /></span></a></div> 

                                <?php } ?>

                                <span class="adminURL" id="<?php echo admin_url();?>"></span>
                                <span class="templateURL" id="<?php echo get_template_directory_uri(); ?>"></span>
                                <?php $post_id = $post->ID;?>
                                <?php $current_like_count = get_post_meta($post_id, 'like_count');?>
                                <?php if (isset($current_like_count[0]) == NULL || $current_like_count[0] == 0){$current_like_count[0] = 0;}?>
                                <span class="likeCount-<?php echo $post_id ?>" id="likeCountCurrent-<?php echo $current_like_count[0]?>"></span>

                                <?php
                                if (is_user_logged_in()) {

                                    global $wpdb;
                                    $current_user_id = get_current_user_id();

                                    $get_user_liked_question_value = "SELECT * FROM " . $wpdb->prefix . "rqa_liked_content WHERE user_id ='". $current_user_id . "' AND like_content_id ='". $post_id . "'" ;
                                    $users_liked_question_value = $wpdb->get_results($get_user_liked_question_value);

                                    if (isset($users_liked_question_value[0]->user_id) == $current_user_id && isset($users_liked_question_value[0]->like_content_id) == $post_id) {

                                    ?>
                                        <div class="likeContent">
                                            <div class="bylineBox right disabledLike"><a href="#" onclick="return false;" class="likeThisContent"><span><img src="<?php echo get_template_directory_uri(); ?>/images/like-icon.png" alt="<?php echo $t_like_text;?>" /><?php if ($current_like_count[0] > 0) { echo $current_like_count[0];} else {echo $t_like_text;} ?></span></a></div>
                                        </div>

                                    <?php } else { ?>

                                        <div class="likeContent">
                                            <div class="bylineBox right likeThisLink" id="like-this-<?php echo $post_id; ?>"><a href="#" onclick="return false;" class="likeThisContent" id="type-post"><span><img src="<?php echo get_template_directory_uri(); ?>/images/like-icon.png" alt="<?php echo $t_like_text;?>" /><?php if ($current_like_count[0] > 0) { echo $current_like_count[0];} else {echo $t_like_text;} ?></span></a></div>
                                        </div>


                                    <?php } ?>

                                <?php } else { ?>
                                <div class="likeContent">
                                     <div class="bylineBox right likeThisLink"><a href="<?php bloginfo('siteurl'); ?>/<?php echo $t_login_permalink;?>/?redir=<?php echo $redir; ?>" title="<?php echo $t_login_signup_like;?>"><span><img src="<?php echo get_template_directory_uri(); ?>/images/like-icon.png" alt="<?php echo $t_like_text;?>" /><?php if ($current_like_count[0] > 0) { echo $current_like_count[0];} else {echo $t_like_text;} ?></span></a></div>
                                </div>
                                <?php } ?>


                                <div class="clear"></div>
                            </div>
                        </div>
                        <!-- / Question -->
                        <?php endwhile; ?>


                                <?php endif; ?>

                                <?php wp_reset_query();?>

                        <div class="answerBar" id="comments">
                            <div class="answerBarInner">

                            <?php
                            // List out the number of Answers - Exlcuding Comments on Answers
                            $answers_count = c_parent_comment_counter($post->ID);

                            // Var to show comments on answers count - not used
                            // $comments_on_answers_count = $post->comment_count - $number_of_parents;

                            if ($answers_count < 1) {?>
                                <h5><?php echo $t_no_answer_yet_answer_now_text;?> </h5>
                            <?php }
                            if ($answers_count == 1) {?>
                                <h5><?php echo $answers_count; ?> <?php echo $t_answer_text;?> </h5>
                            <?php }

                            if ($answers_count > 1) { ?>
                                <h5><?php echo $answers_count; ?> <?php echo $t_answers_text;?> </h5>
                            <?php } ?>

                            </div>
                        </div>

                        <?php comments_template(); ?>

                        <?php
                        // If logged in change nav to My Account and Log Out
                        if ( is_user_logged_in()) { ?>

                           <?php // Users cant post answers ?> 
                           <?php $users_cant_answer = get_option('robust_qa_admin_answer_only');
                            if ($users_cant_answer == true && (!current_user_can('manage_options') && $current_user->expert == 'no')) {?>
                                <p class="bottomMessageBox footnote2"><b><?php echo $t_admins_answer_questions_only_text; ?> <a href="<?php echo home_url(); ?>/<?php echo $t_ask_a_question_permalink;?>/"><?php echo $t_admin_answer_link;?></a></b></p>
                            <?php } else {?>

                                <div class="addAnswer"><a name="answerQuestionForm"></a>
                                    <h4><?php echo $t_answer_this_question_heading;?></h4>

                                    <div class="answerSubmitForm">

                                        <form action="" method="post" name="answerSubmitForm" id="answerSubmitForm">
                                            <div class="clear"></div>
                                            <fieldset><textarea rows="10" cols="40" name="answer_content" id="answer_content" ><?php if (isset($_POST['answer_content'])) { echo $_POST['answer_content']; }?></textarea></fieldset>
                                            <label class="sourceLinkLabel"><?php echo $t_source_link_heading;?>: <span>(<?php echo $t_optional_text;?>)</span></label>
                                            <input type="text" name="source_link" class="sourceLinkInput" value="http://" />
                                            <input type="hidden" name="answer_post" value="1">  
                                            <input type="submit" value="<?php echo $t_add_answer_btn;?>" />
                                            <div class="clear"></div>
                                        </form>
                                    </div>
                                </div>

                            <?php } ?>
                        <?php } else { ?>
                            <div class="clear"></div>
                            <div class="bottomMessageBox2">
                                <h4 class="subHeadh4"><?php echo $t_must_be_logged_in_to_answer;?></h4>
                                <h5><?php echo $t_already_a_member_text;?> <a href="<?php echo home_url();?>/<?php echo $t_login_permalink;?>/?redir=<?php echo $redir; ?>"><?php echo $t_login_text;?></a><br /><?php echo $t_not_member_yet_text;?> <a href="<?php echo home_url();?>/<?php echo $t_signup_permalink?>/?redir=<?php echo the_ID(); ?>"><?php echo $t_signup_text;?></a></h5>

                            </div>
                        <?php } ?>                          

                        <div class="relatedQuestions">
                            <div class="relatedHeader">
                                <?php 
                                $single_cat = get_the_category();
                                $single_parent_cat = get_category($single_cat[0]->category_parent);
                                $main_question_id = get_the_ID();

                                if ($single_cat[0]->category_parent != 0) { ?>
                                <div class="backBtn"><a href="<?php echo home_url(); ?>/<?php echo $t_category_permalink;?>/<?php echo $single_parent_cat->slug; ?>/<?php echo $single_cat[0]->slug; ?>/"><span><?php echo $t_more_category_questions_heading;?></span></a></div>
                                <?php } elseif ($single_cat[0]->category_parent == 0) { ?>
                                <div class="backBtn"><a href="<?php echo home_url(); ?>/<?php echo $t_category_permalink;?>/<?php echo $single_cat[0]->slug; ?>/"><span><?php echo $t_more_category_questions_heading?></span></a></div>
                                <?php } ?>

                                <h5><?php echo $t_related_questions_heading;?>:</h5>
                            </div>
                            <div class="dashedDivider"></div>
                            <ul>
                                <?php 
                                if (have_posts()) : 
                                $args = array(
                                    'posts_per_page' => 5,
                                    'cat' => $single_cat[0]->cat_ID,
                                    'orderby' => 'date',
                                );
                                query_posts($args);

                                ?>
                                <?php while (have_posts()) : the_post();?>

                                <?php if ($post->ID != $main_question_id ) { ?>
                                <li><a href="<?php the_permalink(); ?> "><?php the_title(); ?></a></li>
                                <?php } ?>
                                <?php endwhile; ?>
                            <?php endif; ?>
                            <?php wp_reset_query();?>
                            </ul>
                        </div>

                    <div class="reset"></div>

                </div>
                <!-- / Left Inner Column -->

                <?php get_sidebar(); ?>

            </div>
            <!-- / Center Column -->

            <div class="clear"></div>
        </div>
    </div>
    <div class="mainContentBottom"></div>
    <!-- / Main Section -->

<?php get_footer(); ?>
 <?php if ( is_singular() ) wp_enqueue_script( "comment-reply" ); ?>

1 Answer 1

0

Have you tried the plugin listed here?

http://glue-talk.com/359/wordpress-plugin-limit-post-creation/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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