From fbe4f67387df9df4e53c3b6025abef80e5b201cb Mon Sep 17 00:00:00 2001 From: Marco Chiesi Date: Sat, 4 Oct 2014 01:16:19 +0200 Subject: [PATCH 1/2] Display editorial access settings to administrators in posts/pages lists --- Gruntfile.js | 3 + build/css/post-admin.css | 3 + build/css/post-admin.min.css | 2 +- classes/class-editorial-access-manager.php | 66 +++++++++++++++++++- languages/editorial-access-manager-it_IT.mo | Bin 659 -> 707 bytes languages/editorial-access-manager-it_IT.po | 25 +++++--- languages/editorial-access-manager.pot | 20 +++--- package.json | 6 ++ scss/post-admin.scss | 4 ++ 9 files changed, 110 insertions(+), 19 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index f45e4c4..8625d53 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -17,6 +17,9 @@ module.exports = function ( grunt ) { dist : { files : { 'build/css/post-admin.css' : 'scss/post-admin.scss' + }, + options : { + sourcemap: 'none' } } }, diff --git a/build/css/post-admin.css b/build/css/post-admin.css index 0e1d5d7..cbab9d3 100644 --- a/build/css/post-admin.css +++ b/build/css/post-admin.css @@ -1,3 +1,6 @@ #eam_access_manager label { display: block; margin-top: 1em; } + +.column-editorial-access-manager { + width: 20%; } diff --git a/build/css/post-admin.min.css b/build/css/post-admin.min.css index 5ff92d0..042b9cf 100644 --- a/build/css/post-admin.min.css +++ b/build/css/post-admin.min.css @@ -1 +1 @@ -#eam_access_manager label{display:block;margin-top:1em} \ No newline at end of file +#eam_access_manager label{display:block;margin-top:1em}.column-editorial-access-manager{width:20%} \ No newline at end of file diff --git a/classes/class-editorial-access-manager.php b/classes/class-editorial-access-manager.php index 0f5e507..2d0055b 100644 --- a/classes/class-editorial-access-manager.php +++ b/classes/class-editorial-access-manager.php @@ -20,6 +20,10 @@ public function setup() { add_action( 'save_post', array( $this, 'action_save_post' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'action_admin_enqueue_scripts' ) ); add_filter( 'map_meta_cap', array( $this, 'filter_map_meta_cap' ), 100, 4 ); + add_filter( 'manage_pages_columns', array( $this, 'manage_columns' ) ); + add_action( 'manage_pages_custom_column', array( $this, 'manage_custom_column' ), 10, 2 ); + add_filter( 'manage_posts_columns', array( $this, 'manage_columns' ) ); + add_action( 'manage_posts_custom_column', array( $this, 'manage_custom_column' ), 10, 2 ); } /** @@ -102,7 +106,7 @@ public function filter_map_meta_cap( $caps, $cap, $user_id, $args ) { */ public function action_admin_enqueue_scripts( $hook ) { - if ( 'post.php' == $hook || 'post-new.php' == $hook ) { + if ( 'post.php' == $hook || 'post-new.php' == $hook || 'edit.php' == $hook ) { /** * Setup JS stuff */ @@ -188,6 +192,7 @@ public function action_save_post( $post_id ) { * @since 0.1.0 */ public function meta_box_access_manager( $post ) { + global $wp_roles; $post_type_object = get_post_type_object( get_post_type( $post->ID ) ); // By default every user and every role with the edit_others_posts cap can edit this post @@ -262,7 +267,7 @@ public function meta_box_access_manager( $post ) { selected disabled selected > - + roles[ $role_name ]['name'] ) ); ?> @@ -286,6 +291,63 @@ public function meta_box_access_manager( $post ) { ' . __( 'Roles', 'editorial-access-manager' ) . ':
'; + foreach ( $roles as $role ) { + if ( ! empty( $wp_roles->roles[ $role ]['name'] ) ) { + $role_names[] = translate_user_role( $wp_roles->roles[ $role ]['name'] ); + } + } + sort( $role_names ); + echo implode( ', ', $role_names ); + } + if ( 'users' == $eam ) { + $users = get_post_meta( $post_id, 'eam_allowed_users', true ); + $admins = get_users( array( 'role' => 'administrator', 'fields' => 'ID' ) ); + $users = array_merge( $users, $admins ); + $user_names = array(); + echo '' . __( 'Users', 'editorial-access-manager' ) . ':
'; + foreach ( $users as $user ) { + $user_object = get_userdata( $user ); + if ( ! empty( $user_object ) ) { + $user_names[] = $user_object->user_login; + } + } + sort( $user_names ); + echo implode( ', ', $user_names ); + } + } + } + } + /** * Return singleton instance of class * diff --git a/languages/editorial-access-manager-it_IT.mo b/languages/editorial-access-manager-it_IT.mo index 891b37258f063bbc92f24c5651e959f4aecf0652..0c5912626b6819f56083053652271b57ab33801f 100644 GIT binary patch delta 245 zcmbQtdYHBTo)F7a1|Z-BVi_P#0das}4TJ*I5oFZ3o|k> zFay~-K$;au8$f9@ApIT4w*k`9K-z?ffk6mJ2LNeF1_nKbWFSKvC{PQeK?Y6*((FKb z9gqeYv<*nJ0qH$Jnqjg&ql6%XYf5HGeof>2b3z!%V!8G&CkhX2rWs?E6HR404)k7B>(^b delta 213 zcmX@iI+?Zpo)F7a1|Z-7Vi_Qg0das}4uk^J5\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -20,38 +20,45 @@ msgstr "" "X-Poedit-SearchPath-0: .\n" "X-Textdomain-Support: yes" -#: classes/class-editorial-access-manager.php:137 +#: classes/class-editorial-access-manager.php:141 #@ editorial-access-manager msgid "Editorial Access Manager" msgstr "Gestione accesso editoriale" -#: classes/class-editorial-access-manager.php:248 +#: classes/class-editorial-access-manager.php:253 #@ editorial-access-manager msgid "Enable custom access management by" msgstr "Criterio gestione accessi" -#: classes/class-editorial-access-manager.php:250 +#: classes/class-editorial-access-manager.php:255 #@ editorial-access-manager msgid "Off" -msgstr "Disattivata" +msgstr "Nessuno" -#: classes/class-editorial-access-manager.php:251 +#: classes/class-editorial-access-manager.php:256 +#: classes/class-editorial-access-manager.php:323 #@ editorial-access-manager msgid "Roles" msgstr "Ruoli" -#: classes/class-editorial-access-manager.php:252 +#: classes/class-editorial-access-manager.php:257 +#: classes/class-editorial-access-manager.php:337 #@ editorial-access-manager msgid "Users" msgstr "Utenti" -#: classes/class-editorial-access-manager.php:257 +#: classes/class-editorial-access-manager.php:262 #@ editorial-access-manager msgid "Manage access for roles:" msgstr "Gestione accesso ruoli:" -#: classes/class-editorial-access-manager.php:272 +#: classes/class-editorial-access-manager.php:277 #@ editorial-access-manager msgid "Manage access for users:" msgstr "Gestione accesso utenti:" +#: classes/class-editorial-access-manager.php:302 +#@ editorial-access-manager +msgid "Editorial access" +msgstr "Accesso editoriale" + diff --git a/languages/editorial-access-manager.pot b/languages/editorial-access-manager.pot index 20682d9..c4568ac 100644 --- a/languages/editorial-access-manager.pot +++ b/languages/editorial-access-manager.pot @@ -5,7 +5,7 @@ msgstr "" "Project-Id-Version: Editorial Access Manager 0.1.1\n" "Report-Msgid-Bugs-To: " "https://github.com/tlovett1/editorial-access-manager/issues\n" -"POT-Creation-Date: 2014-10-03 19:26:08+00:00\n" +"POT-Creation-Date: 2014-10-03 23:09:27+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -29,30 +29,36 @@ msgstr "" msgid "Editorial Access Manager" msgstr "" -#: classes/class-editorial-access-manager.php:247 +#: classes/class-editorial-access-manager.php:253 msgid "Enable custom access management by" msgstr "" -#: classes/class-editorial-access-manager.php:249 +#: classes/class-editorial-access-manager.php:255 msgid "Off" msgstr "" -#: classes/class-editorial-access-manager.php:250 +#: classes/class-editorial-access-manager.php:256 +#: classes/class-editorial-access-manager.php:323 msgid "Roles" msgstr "" -#: classes/class-editorial-access-manager.php:251 +#: classes/class-editorial-access-manager.php:257 +#: classes/class-editorial-access-manager.php:337 msgid "Users" msgstr "" -#: classes/class-editorial-access-manager.php:256 +#: classes/class-editorial-access-manager.php:262 msgid "Manage access for roles:" msgstr "" -#: classes/class-editorial-access-manager.php:271 +#: classes/class-editorial-access-manager.php:277 msgid "Manage access for users:" msgstr "" +#: classes/class-editorial-access-manager.php:302 +msgid "Editorial access" +msgstr "" + #. Author URI of the plugin/theme msgid "http://www.taylorlovett.com" msgstr "" diff --git a/package.json b/package.json index 51534bf..c9ca95c 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,15 @@ { "name": "editorial-access-manager-wp", "version": "0.1.0", + "repository": { + "type": "git", + "url": "git://github.com/tlovett1/editorial-access-manager.git" + }, "devDependencies": { "grunt": "^0.4.5", + "grunt-contrib-cssmin": "^0.10.0", "grunt-contrib-jshint": "~0.8.0", + "grunt-contrib-sass": "^0.8.1", "grunt-contrib-uglify": "0.2.0", "grunt-contrib-watch": "0.5.3", "grunt-wp-i18n": "^0.4.8" diff --git a/scss/post-admin.scss b/scss/post-admin.scss index af80ddc..ff27307 100644 --- a/scss/post-admin.scss +++ b/scss/post-admin.scss @@ -3,4 +3,8 @@ display: block; margin-top: 1em; } +} + +.column-editorial-access-manager { + width: 20%; } \ No newline at end of file From f5f69dcce2659e4b398bd8af5f0f804ea0d1b8fb Mon Sep 17 00:00:00 2001 From: Marco Chiesi Date: Sat, 4 Oct 2014 01:53:28 +0200 Subject: [PATCH 2/2] Handle delete_* capabilities consistently --- classes/class-editorial-access-manager.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/classes/class-editorial-access-manager.php b/classes/class-editorial-access-manager.php index 2d0055b..a2e1b00 100644 --- a/classes/class-editorial-access-manager.php +++ b/classes/class-editorial-access-manager.php @@ -47,7 +47,17 @@ public function load_textdomain() { * @return array */ public function filter_map_meta_cap( $caps, $cap, $user_id, $args ) { - if ( 'edit_post' == $cap || 'publish_posts' == $cap || 'edit_others_posts' == $cap || 'edit_page' == $cap || 'publish_pages' == $cap || 'edit_others_pages' == $cap ) { + $eam_caps = array( + 'edit_page', + 'edit_post', + 'edit_others_pages', + 'edit_others_posts', + 'publish_posts', + 'publish_pages', + 'delete_page', + 'delete_post', + ); + if ( in_array( $cap, $eam_caps ) ) { $post_id = ( isset( $args[0] ) ) ? (int) $args[0] : null; if ( ! $post_id && ! empty( $_GET['post'] ) ) {