<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[4080] sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc: Rosetta: Add role manager for custom roles which are used on the main site.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/4080">4080</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/4080","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>ocean90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-09-16 15:50:43 +0000 (Fri, 16 Sep 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Rosetta: Add role manager for custom roles which are used on the main site.
See <a href="http://meta.trac.wordpress.org/ticket/2003">#2003</a>, <a href="http://meta.trac.wordpress.org/ticket/1398">#1398</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincsiteclasslocalemainphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/site/class-locale-main.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincuserclassrolemanagerphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/class-role-manager.php</a></li>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincuserroleclassgeneraltranslationeditorphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-general-translation-editor.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincuserroleclasslocalemanagerphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-locale-manager.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincuserroleclassrolephp">sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-role.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincuserroleclasstranslationeditorphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-translation-editor.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincsiteclasslocalemainphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/site/class-locale-main.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/site/class-locale-main.php 2016-09-16 14:39:24 UTC (rev 4079)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/site/class-locale-main.php 2016-09-16 15:50:43 UTC (rev 4080)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4,7 +4,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Rosetta\Filter;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Rosetta\Jetpack;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Rosetta\User;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use WordPressdotorg\Rosetta\User\Role;
</ins><span class="cx" style="display: block; padding: 0 10px"> use WP_Site;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use WP_User;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> class Locale_Main implements Site {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -48,6 +50,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $user_sync->setup();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->initialize_jetpack_customizations();
+ $this->initialize_user_role_customizations();
+ }
+
+ /**
+ * Initializes customizations for Jetpack.
+ */
+ private function initialize_jetpack_customizations() {
</ins><span class="cx" style="display: block; padding: 0 10px"> $jetpack_module_manager = new Jetpack\Module_Manager( [
</span><span class="cx" style="display: block; padding: 0 10px"> 'stats',
</span><span class="cx" style="display: block; padding: 0 10px"> 'videopress',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -57,8 +67,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ] );
</span><span class="cx" style="display: block; padding: 0 10px"> $jetpack_module_manager->setup();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Options for Jetpack's sharing module.
</ins><span class="cx" style="display: block; padding: 0 10px"> $options = new Filter\Options();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Options for Jetpack's sharing module.
</del><span class="cx" style="display: block; padding: 0 10px"> $options->add_option(
</span><span class="cx" style="display: block; padding: 0 10px"> ( new Filter\Option() )
</span><span class="cx" style="display: block; padding: 0 10px"> ->set_name( 'sharing-options' )
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -86,4 +96,57 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> $options->setup();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * Initializes user role customizations.
+ */
+ private function initialize_user_role_customizations() {
+ $role_manager = new User\Role_Manager();
+ $role_manager->add_role( new Role\Locale_Manager() );
+ $role_manager->add_role( new Role\General_Translation_Editor() );
+ $role_manager->add_role( new Role\Translation_Editor() );
+ $role_manager->setup();
+
+ add_action( 'set_user_role', [ $this, 'restore_translation_editor_role' ], 10, 3 );
+ add_filter( 'editable_roles', [ $this, 'remove_administrator_from_editable_roles' ] );
+ }
+
+ /**
+ * Restores the "(General) Translation Editor" role if an user is promoted.
+ *
+ * @param int $user_id The user ID.
+ * @param string $role The new role.
+ * @param array $old_roles An array of the user's previous roles.
+ */
+ public function restore_translation_editor_role( $user_id, $role, $old_roles ) {
+ if (
+ Role\General_Translation_Editor::get_name() !== $role &&
+ in_array( Role\Translation_Editor::get_name(), $old_roles, true )
+ ) {
+ $user = new WP_User( $user_id );
+ $user->add_role( Role\Translation_Editor::get_name() );
+ }
+
+ if (
+ Role\Translation_Editor::get_name() !== $role &&
+ in_array( Role\General_Translation_Editor::get_name(), $old_roles, true )
+ ) {
+ $user = new WP_User( $user_id );
+ $user->add_role( Role\General_Translation_Editor::get_name() );
+ }
+ }
+
+ /**
+ * Removes "Administrator" role from the list of editable roles.
+ *
+ * @param array $roles List of roles.
+ * @return array Filtered list of editable roles.
+ */
+ public function remove_administrator_from_editable_roles( $roles ) {
+ if ( ! is_super_admin() && ! is_main_site() ) {
+ unset( $roles['administrator'] );
+ }
+
+ return $roles;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincuserclassrolemanagerphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/class-role-manager.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/class-role-manager.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/class-role-manager.php 2016-09-16 15:50:43 UTC (rev 4080)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,214 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Rosetta\User;
+
+use WordPressdotorg\Rosetta\User\Role\Role;
+use WP_Error;
+
+class Role_Manager {
+
+ /**
+ * Array of roles, keyed by role name.
+ *
+ * @var Role[]
+ */
+ private $roles;
+
+ /**
+ * Array of roles, keyed by display name.
+ *
+ * @var Role[]
+ */
+ private $roles_by_display_name;
+
+ /**
+ * Array of role names, which are not editable.
+ *
+ * @var array
+ */
+ private $non_editable_roles;
+
+ /**
+ * Constructor.
+ *
+ * @param array $roles An array of roles.
+ */
+ public function __construct( array $roles = [] ) {
+ foreach ( $roles as $role ) {
+ $this->add_role( $role );
+ }
+ }
+
+ /**
+ * Adds a role to the manager.
+ *
+ * @param Role $role The role.
+ */
+ public function add_role( Role $role ) {
+ $this->roles[ $role::get_name() ] = $role;
+ $this->roles_by_display_name[ $role::get_display_name() ] = $role;
+ if ( ! $role::is_editable_role() ) {
+ $this->non_editable_roles[] = $role::get_name();
+ }
+ }
+
+ /**
+ * Checks status of roles and registers the filters.
+ */
+ public function setup() {
+ if ( ! $this->roles ) {
+ return;
+ }
+
+ foreach ( $this->roles as $role ) {
+ $role_status = $this->role_exists( $role );
+ if ( is_wp_error( $role_status ) ) {
+ switch ( $role_status->get_error_code() ) {
+ case 'role_does_not_exist' :
+ $this->create_role( $role );
+ break;
+ case 'outdated_role_exists' :
+ $this->upgrade_role( $role );
+ break;
+ }
+ }
+ }
+
+ add_filter( 'user_has_cap', [ $this, 'add_dynamic_capabilities' ], 10, 4 );
+ add_filter( 'gettext_with_context', [ $this, 'translate_user_roles' ], 10, 4 );
+ add_filter( 'editable_roles', [ $this, 'filter_editable_roles' ] );
+ }
+
+ /**
+ * Checks the status of a role.
+ *
+ * @param Role $role The role to check.
+ *
+ * @return true|WP_Error True if role exists, WP_Error if role doesn't exist ('role_does_not_exist')
+ * or role needs an update ('outdated_role_exists').
+ */
+ public function role_exists( Role $role ) {
+ $existing_role = get_role( $role::get_name() );
+
+ if ( null === $existing_role ) {
+ return new WP_Error( 'role_does_not_exist' );
+ }
+
+ $current_caps = $existing_role->capabilities;
+ $role_caps = $role::get_capabilities();
+
+ ksort( $current_caps );
+ ksort( $role_caps );
+
+ if ( $current_caps !== $role_caps ) {
+ return new WP_Error( 'outdated_role_exists' );
+ }
+
+ return true;
+ }
+
+ /**
+ * Upgrades an existing roles.
+ *
+ * @param Role $role The role to upgrade.
+ *
+ * @return true|WP_Error True on success, WP_Error if role doesn't exist.
+ */
+ public function upgrade_role( Role $role ) {
+ $role_object = get_role( $role::get_name() );
+
+ if ( null === $role_object ) {
+ return new WP_Error( 'role_does_not_exists' );
+ }
+
+ $old_caps = array_keys( $role_object->capabilities );
+ $new_caps = array_keys( $role::get_capabilities() );
+
+ $removed_caps = array_diff( $old_caps, $new_caps );
+ $added_caps = array_diff( $new_caps, $old_caps );
+
+ foreach ( $removed_caps as $removed_cap ) {
+ $role_object->remove_cap( $removed_cap );
+ }
+
+ foreach ( $added_caps as $added_cap ) {
+ $role_object->add_cap( $added_cap );
+ }
+
+ return true;
+ }
+
+ /**
+ * Creates a new role.
+ *
+ * @param Role $role The role to create.
+ *
+ * @return WP_Error|\WP_Role WP_Error if role exists, WP_Role if role was created.
+ */
+ public function create_role( Role $role ) {
+ $existing_role = get_role( $role::get_name() );
+
+ if ( null !== $existing_role ) {
+ return new WP_Error( 'role_exists' );
+ }
+
+ return add_role( $role::get_name(), $role::get_display_name(), $role::get_capabilities() );
+ }
+
+ /**
+ * Translates the display name of a role.
+ *
+ * @param string $translation Translated text.
+ * @param string $text Text to translate.
+ * @param string $context Context information for the translators.
+ * @param string $domain Text domain.
+ * @return string Translated user role.
+ */
+ public function translate_user_roles( $translation, $text, $context, $domain ) {
+ if ( 'default' !== $domain || 'User role' !== $context ) {
+ return $translation;
+ }
+
+ if ( isset( $this->roles_by_display_name[ $text ] ) ) {
+ $role = $this->roles_by_display_name[ $text ];
+ return $role::get_display_name( true /* $translated */ );
+ }
+
+ return $translation;
+ }
+
+ /**
+ * Filters user's capabilities.
+ *
+ * @param array $allcaps An array of all the user's capabilities.
+ * @param array $caps Actual capabilities for meta capability.
+ * @param array $args Optional parameters passed to has_cap(), typically object ID.
+ * @param WP_User $user The user object.
+ * @return array An array of user's capabilities.
+ */
+ public function add_dynamic_capabilities( $allcaps, $caps, $args, $user ) {
+ foreach ( $user->roles as $user_role ) {
+ if ( isset( $this->roles[ $user_role ] ) ) {
+ $role = $this->roles[ $user_role ];
+ $allcaps = array_merge( $allcaps, $role::get_dynamic_capabilities() );
+ }
+ }
+
+ return $allcaps;
+ }
+
+ /**
+ * Filters list of editable roles.
+ *
+ * @see get_editable_roles()
+ *
+ * @param array $roles Array of roles.
+ * @return array Filtered array of roles.
+ */
+ public function filter_editable_roles( $roles ) {
+ if ( empty( $this->non_editable_roles ) ) {
+ return $roles;
+ }
+
+ return array_diff_key( $roles, array_flip( $this->non_editable_roles ) );
+ }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincuserroleclassgeneraltranslationeditorphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-general-translation-editor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-general-translation-editor.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-general-translation-editor.php 2016-09-16 15:50:43 UTC (rev 4080)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,68 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Rosetta\User\Role;
+
+class General_Translation_Editor implements Role {
+
+ /**
+ * Retrieves the name of this role.
+ *
+ * @return string The name of this role.
+ */
+ public static function get_name() {
+ return 'general_translation_editor';
+ }
+
+ /**
+ * Retrieves the display name of this role.
+ *
+ * @param bool $translated Whether the name should be translated or not.
+ * @return string. The display name.
+ */
+ public static function get_display_name( $translated = false ) {
+ return $translated ? __( 'General Translation Editor', 'rosetta' ) : 'General Translation Editor';
+ }
+
+ /**
+ * Retrieves the capabilities of this role.
+ *
+ * @return array Array of capabilities.
+ */
+ public static function get_capabilities() {
+ return [];
+ }
+
+ /**
+ * Retrieves the dynamic capabilities for this role.
+ *
+ * @return array Array of dynamic capabilities.
+ */
+ public static function get_dynamic_capabilities() {
+ return [
+ // Core.
+ 'read' => true,
+
+ // Custom.
+ 'manage_translation_editors' => true,
+ ];
+ }
+
+ /**
+ * Whether this role is an additional role.
+ *
+ * @return bool True if role is additional, false if not.
+ */
+ public static function is_additional_role() {
+ return true;
+ }
+
+ /**
+ * Whether this role is an editable role.
+ *
+ * @see get_editable_roles()
+ *
+ * @return bool True if role is editable, false if not.
+ */
+ public static function is_editable_role() {
+ return false;
+ }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincuserroleclasslocalemanagerphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-locale-manager.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-locale-manager.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-locale-manager.php 2016-09-16 15:50:43 UTC (rev 4080)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,96 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Rosetta\User\Role;
+
+class Locale_Manager implements Role {
+
+ /**
+ * Retrieves the name of this role.
+ *
+ * @return string The name of this role.
+ */
+ public static function get_name() {
+ return 'locale_manager';
+ }
+
+ /**
+ * Retrieves the display name of this role.
+ *
+ * @param bool $translated Whether the name should be translated or not.
+ * @return string. The display name.
+ */
+ public static function get_display_name( $translated = false ) {
+ return $translated ? __( 'Locale Manager', 'rosetta' ) : 'Locale Manager';
+ }
+
+ /**
+ * Retrieves the capabilities of this role.
+ *
+ * @return array Array of capabilities.
+ */
+ public static function get_capabilities() {
+ return [];
+ }
+
+ /**
+ * Retrieves the dynamic capabilities for this role.
+ *
+ * @return array Array of dynamic capabilities.
+ */
+ public static function get_dynamic_capabilities() {
+ return [
+ // Core.
+ 'read' => true,
+ 'moderate_comments' => true,
+ 'manage_categories' => true,
+ 'manage_links' => true,
+ 'upload_files' => true,
+ 'edit_pages' => true,
+ 'publish_pages' => true,
+ 'delete_pages' => true,
+ 'edit_private_pages' => true,
+ 'delete_private_pages' => true,
+ 'read_private_pages' => true,
+ 'edit_published_pages' => true,
+ 'delete_published_pages' => true,
+ 'edit_others_pages' => true,
+ 'delete_others_pages' => true,
+ 'edit_posts' => true,
+ 'publish_posts' => true,
+ 'delete_posts' => true,
+ 'edit_private_posts' => true,
+ 'delete_private_posts' => true,
+ 'read_private_posts' => true,
+ 'edit_published_posts' => true,
+ 'delete_published_posts' => true,
+ 'edit_others_posts' => true,
+ 'delete_others_posts' => true,
+ 'edit_theme_options' => true,
+ 'list_users' => true,
+ 'promote_users' => true,
+ 'remove_users' => true,
+
+ // Custom.
+ 'manage_translation_editors' => true,
+ ];
+ }
+
+ /**
+ * Whether this role is an additional role.
+ *
+ * @return bool True if role is additional, false if not.
+ */
+ public static function is_additional_role() {
+ return false;
+ }
+
+ /**
+ * Whether this role is an editable role.
+ *
+ * @see get_editable_roles()
+ *
+ * @return bool True if role is editable, false if not.
+ */
+ public static function is_editable_role() {
+ return true;
+ }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincuserroleclassrolephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-role.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-role.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-role.php 2016-09-16 15:50:43 UTC (rev 4080)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,50 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Rosetta\User\Role;
+
+interface Role {
+
+ /**
+ * Retrieves the name of this role.
+ *
+ * @return string The name of this role.
+ */
+ public static function get_name();
+
+ /**
+ * Retrieves the display name of this role.
+ *
+ * @param bool $translated Whether the name should be translated or not.
+ * @return string. The display name.
+ */
+ public static function get_display_name( $translated = false );
+
+ /**
+ * Retrieves the capabilities of this role.
+ *
+ * @return array Array of capabilities.
+ */
+ public static function get_capabilities();
+
+ /**
+ * Retrieves the dynamic capabilities for this role.
+ *
+ * @return array Array of dynamic capabilities.
+ */
+ public static function get_dynamic_capabilities();
+
+ /**
+ * Whether this role is an additional role.
+ *
+ * @return bool True if role is additional, false if not.
+ */
+ public static function is_additional_role();
+
+ /**
+ * Whether this role is an editable role.
+ *
+ * @see get_editable_roles()
+ *
+ * @return bool True if role is editable, false if not.
+ */
+ public static function is_editable_role();
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincuserroleclasstranslationeditorphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-translation-editor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-translation-editor.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/user/role/class-translation-editor.php 2016-09-16 15:50:43 UTC (rev 4080)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,65 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Rosetta\User\Role;
+
+class Translation_Editor implements Role {
+
+ /**
+ * Retrieves the name of this role.
+ *
+ * @return string The name of this role.
+ */
+ public static function get_name() {
+ return 'translation_editor';
+ }
+
+ /**
+ * Retrieves the display name of this role.
+ *
+ * @param bool $translated Whether the name should be translated or not.
+ * @return string. The display name.
+ */
+ public static function get_display_name( $translated = false ) {
+ return $translated ? __( 'Translation Editor', 'rosetta' ) : 'Translation Editor';
+ }
+
+ /**
+ * Retrieves the capabilities of this role.
+ *
+ * @return array Array of capabilities.
+ */
+ public static function get_capabilities() {
+ return [];
+ }
+
+ /**
+ * Retrieves the dynamic capabilities for this role.
+ *
+ * @return array Array of dynamic capabilities.
+ */
+ public static function get_dynamic_capabilities() {
+ return [
+ // Core.
+ 'read' => true,
+ ];
+ }
+
+ /**
+ * Whether this role is an additional role.
+ *
+ * @return bool True if role is additional, false if not.
+ */
+ public static function is_additional_role() {
+ return true;
+ }
+
+ /**
+ * Whether this role is an editable role.
+ *
+ * @see get_editable_roles()
+ *
+ * @return bool True if role is editable, false if not.
+ */
+ public static function is_editable_role() {
+ return false;
+ }
+}
</ins></span></pre>
</div>
</div>
</body>
</html>