Skip to content
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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ module.exports = function ( grunt ) {
dist : {
files : {
'build/css/post-admin.css' : 'scss/post-admin.scss'
},
options : {
sourcemap: 'none'
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions build/css/post-admin.css
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%; }
2 changes: 1 addition & 1 deletion build/css/post-admin.min.css
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%}
78 changes: 75 additions & 3 deletions classes/class-editorial-access-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand All @@ -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'] ) ) {
Expand Down Expand Up @@ -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 ) {
Copy link
Owner

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.

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this in 57f8a50

/**
* Setup JS stuff
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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>
Expand All @@ -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 ) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a default value so the column isn't empty.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
*
Expand Down
Binary file modified languages/editorial-access-manager-it_IT.mo
Binary file not shown.
25 changes: 16 additions & 9 deletions languages/editorial-access-manager-it_IT.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

20 changes: 13 additions & 7 deletions languages/editorial-access-manager.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 ""
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 4 additions & 0 deletions scss/post-admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
display: block;
margin-top: 1em;
}
}

.column-editorial-access-manager {
width: 20%;
}