Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Get usr role as the restruictions don't work properly src: http://docs.appthemes.com/tutorials/wordpress-check-user-role-function/
- function check_user_role( $role, $user_id = null ) {
- if ( is_numeric( $user_id ) )
- $user = get_userdata( $user_id );
- else
- $user = wp_get_current_user();
- if ( empty( $user ) )
- return false;
- return in_array( $role, (array) $user->roles );}
- //Source from this site http://wordpress.stackexchange.com/questions/30331/update-post-counts-published-draft-unattached-in-admin-interface/53791#53791
- //Update with only current user counts
- foreach( array( 'edit-post', 'edit-page', 'upload' ) as $hook )
- add_filter( "views_$hook" , 'wpse_30331_custom_view_count', 10, 1);
- function wpse_30331_custom_view_count( $views )
- {
- global $current_screen;
- switch( $current_screen->id )
- {
- case 'edit-post':
- $views = wpse_30331_manipulate_views( 'post', $views );
- break;
- case 'edit-page':
- $views = wpse_30331_manipulate_views( 'page', $views );
- break; case 'upload':
- $views = wpse_30331_manipulate_views( 'attachment', $views );
- break;
- }
- return $views;}
- function wpse_30331_manipulate_views( $what, $views ){
- global $user_ID, $wpdb;
- /*
- * This is not working for me, 'artist' and 'administrator' are passing this condition (?)
- */
- if ( !current_user_can('delete_users') )
- return $views;
- /*
- * This needs refining, and maybe a better method
- * e.g. Attachments have completely different counts
- */
- $total = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE (post_status = 'publish' OR post_status = 'draft' OR post_status = 'pending') AND (post_author = '$user_ID' AND post_type = '$what' ) ");
- $publish = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_author = '$user_ID' AND post_type = '$what' ");
- $draft = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'draft' AND post_author = '$user_ID' AND post_type = '$what' ");
- $pending = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'pending' AND post_author = '$user_ID' AND post_type = '$what' ");
- /*
- * Only tested with Posts/Pages
- * - there are moments where Draft and Pending shouldn't return any value
- */
- $views['all'] = preg_replace( '/\(.+\)/U', '('.$total.')', $views['all'] );
- $views['publish'] = preg_replace( '/\(.+\)/U', '('.$publish.')', $views['publish'] );
- $views['draft'] = preg_replace( '/\(.+\)/U', '('.$draft.')', $views['draft'] );
- $views['pending'] = preg_replace( '/\(.+\)/U', '('.$pending.')', $views['pending'] );
- // Debug info
- //echo 'Default counts: <pre>'.print_r($views,true).'</pre>';
- //echo '<hr><hr>';
- //echo 'Query for this screen of this post_type: <b>'.$what.'</b><pre>'.print_r($wp_query,true).'</pre>';
- return $views;}
- if (!current_user_can('delete_users')) {
- add_filter('parse_query', 'wpse_30331_manipulate_views' );
- add_filter('parse_query', 'wpse_30331_custom_view_count' );
- }
- //end counts update
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement