Changeset 1197804
- Timestamp:
- 07/13/2015 09:54:24 AM (11 years ago)
- Location:
- limit-posts/trunk
- Files:
-
- 4 edited
-
js/LimitPosts.js (modified) (7 diffs)
-
limit-posts.php (modified) (5 diffs)
-
options-page.php (modified) (5 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
limit-posts/trunk/js/LimitPosts.js
r1196271 r1197804 17 17 $j('#add_role_submit').css('display', 'block'); 18 18 $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'); 20 20 return false; 21 21 }); … … 55 55 var userId = $j('#user_select').find(':selected').val(); 56 56 var userName = $j('#user_select').find(':selected').text(); 57 var publishAction = $j('#publish_action').find(':selected').text(); 57 58 var limit = $j('#limit_number').val(); 58 59 var postType = $j('#post_types_select').find(':selected').text(); … … 67 68 tableRow.append('<td>'+ userRole +'<input type="hidden" name="limit_posts[rule][' + counter + '][role]" value="'+userRole+'"></td>'); 68 69 } 70 tableRow.append('<td>'+publishAction+'<input type="hidden" name="limit_posts[rule][' + counter + '][publish_action]" value="'+publishAction+'"></td>'); 69 71 tableRow.append('<td>'+ limit +'<input type="hidden" name="limit_posts[rule][' + counter + '][limit]" value="'+limit+'"></td>'); 70 72 tableRow.append('<td>'+ postType +'<input type="hidden" name="limit_posts[rule][' + counter + '][post_type]" value="'+postType+'"></td>'); … … 95 97 $j('#edit_role_submit').css('display', 'block'); 96 98 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'); 98 100 }); 99 101 … … 110 112 111 113 $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; 116 119 117 120 if(existingValues[0] == 'user'){ … … 120 123 $j('#user_select').prop('disabled', false); 121 124 $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; 126 130 } 127 131 else{ … … 131 135 $j('#user_roles_select option[value="'+existingValues[$userOrRolesSelectIndex]+'"]').prop('selected', true); 132 136 } 137 $j('#publish_action option[value="'+existingValues[$publishActionSelectIndex]+'"]').prop('selected', true); 133 138 $j('#limit_number').val(existingValues[$limitNumberIndex]); 134 139 $j('#post_types_select option[value="'+existingValues[$postTypesSelectIndex]+'"]').prop('selected', true); -
limit-posts/trunk/limit-posts.php
r1196271 r1197804 4 4 Plugin URI: www.limitposts.com 5 5 Description: A plugin to allow administrators to limit the number of posts a user can publish in a given time period. 6 Version: 1.0. 16 Version: 1.0.3 7 7 Author: PluginCentral 8 8 Author URI: https://profiles.wordpress.org/plugincentral/ … … 155 155 return implode($postTypesOptions); 156 156 } 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 171 167 //Apply any post limit rules which have been set up 172 168 public function applyPostLimtRules(){ … … 175 171 global $pagenow; 176 172 177 if ($pagenow == 'post-new.php'){ 173 if ($pagenow == 'post-new.php'){ //submit for review and publish 178 174 $limitPostRules = $this->getPluginOptions(); 179 175 … … 207 203 //how many posts of this type has this user published within the rules time periods 208 204 $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 210 207 if($postCount >= $releventRule['limit']){ 211 208 return true; //limit has been reached … … 342 339 } 343 340 344 private function getPostCount($postType, $startDateTime ){341 private function getPostCount($postType, $startDateTime, $publishAction){ 345 342 global $wpdb; 346 343 $userId = get_current_user_id(); 347 348 344 $query = "SELECT COUNT(ID) FROM $wpdb->posts WHERE "; 349 345 $query .= "post_author=$userId "; 350 346 $query .= "AND post_type='$postType' "; 351 347 $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 } 353 354 354 355 $count = $wpdb->get_var($query); -
limit-posts/trunk/options-page.php
r1196271 r1197804 23 23 </li> 24 24 <li> 25 <p class="description narrative">will be limited to publishing </p> 25 <p class="description narrative">cannot </p> 26 <select id="publish_action"> 27 <?php echo $this->getPublishActions(); ?> 28 </select> 29 </li> 30 <li> 31 <p class="description narrative">more than </p> 26 32 <input type="number" name="limit_number" id="limit_number" min="0" max="9999" value="5"> 27 33 </li> … … 57 63 <tr> 58 64 <th>User/Role</th> 65 <th>Action</th> 59 66 <th>Limit</th> 60 67 <th>Post Type</th> … … 66 73 <tr> 67 74 <th>User/Role</th> 75 <th>Action</th> 68 76 <th>Limit</th> 69 77 <th>Post Type</th> … … 78 86 foreach($limitPostsRules['rule'] as $k => $v){ 79 87 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'])){ 85 91 $role_or_user = $v['role_or_user']; 86 92 } … … 95 101 } 96 102 103 $publish_action = "Publish"; 104 if(isset($v['publish_action'])){ 105 $publish_action = $v['publish_action']; 106 } 97 107 108 echo '<td>'.$publish_action.'<input type="hidden" name="limit_posts[rule]['.$count.'][publish_action]" value="'.$publish_action.'"></td>'; 98 109 echo '<td>'.$v['limit'].'<input type="hidden" name="limit_posts[rule]['.$count.'][limit]" value="'.$v['limit'].'"></td>'; 99 110 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 5 5 Requires at least: 4.0.0 6 6 Tested up to: 4.2.2 7 Stable tag: 1.0. 27 Stable tag: 1.0.3 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 10 11 A plugin to allow administrators to limit the number of posts a user can publish in a given time period.11 A plugin to allow administrators to limit the number of posts a user can publish or submit for review in a given time period. 12 12 13 13 == Description == 14 14 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.15 This 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. 16 16 17 17 You 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. … … 25 25 * Make a limit last forever by specifying 9999 years 26 26 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). Ina future release I'll also be adding the ability to incorporate this functionality in custom forms.27 In a future release I'll also be adding the ability to incorporate this functionality in custom forms. 28 28 29 29 == Installation == … … 79 79 Rules can now be created for individual users. 80 80 81 = 1.0.3 = 82 Publish or Submit for review can now be chosen for a rule. 83 81 84 == Upgrade Notice == 82 85 83 86 = 1.0 = 84 87 Initial release 88 89 = 1.0.3 = 90 Publish or Submit For Review can now be chosen for a rule.
Note: See TracChangeset
for help on using the changeset viewer.