Plugin Directory

Changeset 1197804


Ignore:
Timestamp:
07/13/2015 09:54:24 AM (11 years ago)
Author:
PluginCentral
Message:

User can now select Publish or Submit for Review in rule.

Location:
limit-posts/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • limit-posts/trunk/js/LimitPosts.js

    r1196271 r1197804  
    1717        $j('#add_role_submit').css('display', 'block');
    1818        $j('#edit_role_submit').css('display', 'none');
    19         tb_show('New Limit Posts rule','TB_inline?height=275&width=275&inlineId=add-edit-tb');
     19        tb_show('New Limit Posts rule','TB_inline?height=320&width=275&inlineId=add-edit-tb');
    2020        return false;
    2121    });
     
    5555        var userId = $j('#user_select').find(':selected').val();
    5656        var userName = $j('#user_select').find(':selected').text();
     57        var publishAction = $j('#publish_action').find(':selected').text();
    5758        var limit = $j('#limit_number').val();
    5859        var postType = $j('#post_types_select').find(':selected').text();
     
    6768            tableRow.append('<td>'+ userRole +'<input type="hidden" name="limit_posts[rule][' + counter + '][role]" value="'+userRole+'"></td>');
    6869        }
     70        tableRow.append('<td>'+publishAction+'<input type="hidden" name="limit_posts[rule][' + counter + '][publish_action]" value="'+publishAction+'"></td>');
    6971        tableRow.append('<td>'+ limit +'<input type="hidden" name="limit_posts[rule][' + counter + '][limit]" value="'+limit+'"></td>');
    7072        tableRow.append('<td>'+ postType +'<input type="hidden" name="limit_posts[rule][' + counter + '][post_type]" value="'+postType+'"></td>');
     
    9597        $j('#edit_role_submit').css('display', 'block');
    9698       
    97         tb_show('Edit Limit Posts rule', 'TB_inline?height=275&width=275&inlineId=add-edit-tb');
     99        tb_show('Edit Limit Posts rule', 'TB_inline?height=320&width=275&inlineId=add-edit-tb');
    98100    });
    99101   
     
    110112       
    111113        $userOrRolesSelectIndex = 1;
    112         $limitNumberIndex = 2;
    113         $postTypesSelectIndex = 3;
    114         $periodNumberIndex = 4;
    115         $periodDenominatorIndex = 5;
     114        $publishActionSelectIndex = 2;
     115        $limitNumberIndex = 3;
     116        $postTypesSelectIndex = 4;
     117        $periodNumberIndex = 5;
     118        $periodDenominatorIndex = 6;
    116119       
    117120        if(existingValues[0] == 'user'){
     
    120123            $j('#user_select').prop('disabled', false);
    121124            $j('#user_select option[value="'+existingValues[$userOrRolesSelectIndex]+'"]').prop('selected', true);
    122             $limitNumberIndex = 3;
    123             $postTypesSelectIndex = 4;
    124             $periodNumberIndex = 5;
    125             $periodDenominatorIndex = 6;
     125            $publishActionSelectIndex += 1;
     126            $limitNumberIndex += 1;
     127            $postTypesSelectIndex += 1;
     128            $periodNumberIndex += 1;
     129            $periodDenominatorIndex += 1;
    126130        }
    127131        else{
     
    131135            $j('#user_roles_select option[value="'+existingValues[$userOrRolesSelectIndex]+'"]').prop('selected', true);
    132136        }
     137        $j('#publish_action option[value="'+existingValues[$publishActionSelectIndex]+'"]').prop('selected', true);
    133138        $j('#limit_number').val(existingValues[$limitNumberIndex]);
    134139        $j('#post_types_select option[value="'+existingValues[$postTypesSelectIndex]+'"]').prop('selected', true);
  • limit-posts/trunk/limit-posts.php

    r1196271 r1197804  
    44Plugin URI: www.limitposts.com
    55Description: A plugin to allow administrators to limit the number of posts a user can publish in a given time period.
    6 Version: 1.0.1
     6Version: 1.0.3
    77Author: PluginCentral
    88Author URI: https://profiles.wordpress.org/plugincentral/
     
    155155        return implode($postTypesOptions);
    156156    }
    157 
    158     private function getPostStati(){
    159         global $wp_post_statuses;
    160        
    161         $postStatiOptions = array();
    162        
    163         $postStati = get_post_stati('', 'names');
    164         foreach($postStati as $key=>$value){
    165             $postStatiOptions[] = '<option value='.$key.'>'.$value.'</option>';
    166         }
    167        
    168         return implode($postStatiOptions);
    169     }
    170    
     157   
     158    private function getPublishActions(){
     159        $publishActions = array();
     160       
     161        $publishActions[] = '<option value="Publish">Publish</option>';
     162        $publishActions[] = '<option value="Submit For Review">Submit For Review</option>';
     163       
     164        return implode($publishActions);
     165    }
     166
    171167    //Apply any post limit rules which have been set up
    172168    public function applyPostLimtRules(){
     
    175171        global $pagenow;
    176172       
    177         if ($pagenow == 'post-new.php'){
     173        if ($pagenow == 'post-new.php'){  //submit for review and publish
    178174            $limitPostRules = $this->getPluginOptions();
    179175           
     
    207203            //how many posts of this type has this user published within the rules time periods
    208204            $startDateTime = $this->getStartDateTime($releventRule['period_number'], $releventRule['period_denominator']);
    209             $postCount = $this->getPostCount($typenow, $startDateTime);
     205            $postCount = $this->getPostCount($typenow, $startDateTime, $releventRule['publish_action']);
     206           
    210207            if($postCount >= $releventRule['limit']){
    211208                return true;  //limit has been reached
     
    342339    }
    343340   
    344     private function getPostCount($postType, $startDateTime){
     341    private function getPostCount($postType, $startDateTime, $publishAction){
    345342        global $wpdb;
    346343        $userId = get_current_user_id();
    347        
    348344        $query = "SELECT COUNT(ID) FROM $wpdb->posts WHERE ";
    349345        $query .= "post_author=$userId ";
    350346        $query .= "AND post_type='$postType' ";
    351347        $query .= "AND post_date>'".$startDateTime->format('c')."' ";
    352         $query .= "AND post_status='publish'";
     348        if($publishAction == "Publish"){
     349            $query .= "AND post_status='publish'"; 
     350        }
     351        elseif($publishAction == "Submit For Review"){
     352            $query .= "AND post_status='pending'";  //or pending
     353        }
    353354       
    354355        $count = $wpdb->get_var($query);
  • limit-posts/trunk/options-page.php

    r1196271 r1197804  
    2323            </li>
    2424            <li>
    25                 <p class="description narrative">will be limited to publishing&nbsp;</p>
     25                <p class="description narrative">cannot&nbsp;</p>
     26                <select id="publish_action">
     27                    <?php echo $this->getPublishActions(); ?>
     28                </select>
     29            </li>
     30            <li>
     31                <p class="description narrative">more than&nbsp;</p>
    2632                <input type="number" name="limit_number" id="limit_number" min="0" max="9999" value="5">
    2733            </li>
     
    5763                <tr>
    5864                    <th>User/Role</th>
     65                    <th>Action</th>
    5966                    <th>Limit</th>
    6067                    <th>Post Type</th>
     
    6673                <tr>
    6774                    <th>User/Role</th>
     75                    <th>Action</th>
    6876                    <th>Limit</th>
    6977                    <th>Post Type</th>
     
    7886                foreach($limitPostsRules['rule'] as $k => $v){
    7987                    echo '<tr>';
    80                     $role_or_user = 'user';
    81                     if(!isset($v['role_or_user'])){
    82                         $role_or_user = 'role';
    83                     }
    84                     else{
     88                   
     89                    $role_or_user = 'role';
     90                    if(isset($v['role_or_user'])){
    8591                        $role_or_user = $v['role_or_user'];
    8692                    }
     
    95101                    }
    96102                   
     103                    $publish_action = "Publish";
     104                    if(isset($v['publish_action'])){
     105                        $publish_action = $v['publish_action'];
     106                    }
    97107                   
     108                    echo '<td>'.$publish_action.'<input type="hidden" name="limit_posts[rule]['.$count.'][publish_action]" value="'.$publish_action.'"></td>';
    98109                    echo '<td>'.$v['limit'].'<input type="hidden" name="limit_posts[rule]['.$count.'][limit]" value="'.$v['limit'].'"></td>';
    99110                    echo '<td>'.$v['post_type'].'<input type="hidden" name="limit_posts[rule]['.$count.'][post_type]" value="'.$v['post_type'].'"></td>';
  • limit-posts/trunk/readme.txt

    r1196276 r1197804  
    55Requires at least: 4.0.0
    66Tested up to: 4.2.2
    7 Stable tag: 1.0.2
     7Stable tag: 1.0.3
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1010
    11 A plugin to allow administrators to limit the number of posts a user can publish in a given time period.
     11A plugin to allow administrators to limit the number of posts a user can publish or submit for review in a given time period.
    1212
    1313== Description ==
    1414
    15 This plugin allows you to limit the number of posts (any post type, including custom post types) that a user can publish within a specified time period.
     15This plugin allows you to limit the number of posts (any post type, including custom post types) that a user can publish or submit for review within a specified time period.
    1616
    1717You can set up as many limits as you like, for different post types, different user roles, whatever you like. When a user tries to create a new post, the limits are checked, if the user has exceeded any of the limits, they wont be able to publish.
     
    2525*   Make a limit last forever by specifying 9999 years
    2626
    27 In the next version I'll be adding the ability to specify post status, so you can limit the number of revisions or auto drafts (or whatever you like). In a future release I'll also be adding the ability to incorporate this functionality in custom forms.
     27In a future release I'll also be adding the ability to incorporate this functionality in custom forms.
    2828
    2929== Installation ==
     
    7979Rules can now be created for individual users.
    8080
     81= 1.0.3 =
     82Publish or Submit for review can now be chosen for a rule.
     83
    8184== Upgrade Notice ==
    8285
    8386= 1.0 =
    8487Initial release
     88
     89= 1.0.3 =
     90Publish or Submit For Review can now be chosen for a rule.
Note: See TracChangeset for help on using the changeset viewer.