-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display editorial access settings to administrators in posts/pages lists #7
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
#eam_access_manager label { | ||
display: block; | ||
margin-top: 1em; } | ||
|
||
.column-editorial-access-manager { | ||
width: 20%; } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
#eam_access_manager label{display:block;margin-top:1em} | ||
#eam_access_manager label{display:block;margin-top:1em}.column-editorial-access-manager{width:20%} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ); | ||
} | ||
|
||
/** | ||
|
@@ -43,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'] ) ) { | ||
|
@@ -102,7 +116,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 +202,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 +277,7 @@ public function meta_box_access_manager( $post ) { | |
<?php if ( 'administrator' == $role_name ) : ?>selected disabled | ||
<?php elseif ( in_array( $role_name, $allowed_roles ) ) : ?>selected<?php endif;?> | ||
> | ||
<?php echo esc_attr( ucwords( $role_name ) ); ?> | ||
<?php echo esc_attr( translate_user_role( $wp_roles->roles[ $role_name ]['name'] ) ); ?> | ||
</option> | ||
<?php endforeach; ?> | ||
</select> | ||
|
@@ -286,6 +301,63 @@ public function meta_box_access_manager( $post ) { | |
<?php | ||
} | ||
|
||
/** | ||
* Add access manager column | ||
* | ||
* @param array $columns | ||
* @since 0.1.2 | ||
*/ | ||
public function manage_columns( $columns ) { | ||
if ( current_user_can( 'manage_options' ) ) { | ||
$columns['editorial-access-manager'] = __( 'Editorial access', 'editorial-access-manager' ); | ||
} | ||
return $columns; | ||
} | ||
|
||
/** | ||
* Populate access manager column cells | ||
* | ||
* @param string $column_name | ||
* @param int $post_id | ||
* @since 0.1.2 | ||
*/ | ||
public function manage_custom_column( $column_name, $post_id ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a default value so the column isn't empty. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was made on purpose (empty cell = EAM not set), but it wouldn't be a problem to use a default string. Any ideas about what text to use (i.e. "Off")? |
||
if ( $column_name == 'editorial-access-manager' ) { | ||
$eam = get_post_meta( $post_id, 'eam_enable_custom_access', true ); | ||
if ( ! empty( $eam ) ) { | ||
if ( 'roles' == $eam ) { | ||
$roles = get_post_meta( $post_id, 'eam_allowed_roles', true ); | ||
array_unshift( $roles, 'administrator' ); | ||
global $wp_roles; | ||
$role_names = array(); | ||
echo '<strong>' . __( 'Roles', 'editorial-access-manager' ) . ':</strong><br />'; | ||
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 '<strong>' . __( 'Users', 'editorial-access-manager' ) . ':</strong><br />'; | ||
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 | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ msgstr "" | |
"Project-Id-Version: Editorial Access Manager v0.1.1\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: \n" | ||
"PO-Revision-Date: 2014-10-03 19:51:57+0000\n" | ||
"PO-Revision-Date: 2014-10-03 23:12:10+0000\n" | ||
"Last-Translator: marco-chiesi <[email protected]>\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" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,8 @@ | |
display: block; | ||
margin-top: 1em; | ||
} | ||
} | ||
|
||
.column-editorial-access-manager { | ||
width: 20%; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to separate out the JS from the CSS. I don't want the JS loaded here for no reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Would you prefer to use different conditions for JS and CSS or to use 2 separate CSS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this in 57f8a50