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

feat: enhancements for the Non editing contributor role #3277

Merged
merged 6 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
68 changes: 68 additions & 0 deletions assets/other-scripts/co-authors-plus/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* globals guestAuthorRole, jQuery */

jQuery( document ).ready( function ( $ ) {
$( 'select#role' ).change( function () {
if ( guestAuthorRole.role !== $( this ).val() ) {
deactivateGuestAuthor();
} else {
activateGuestAuthor();
}
} );

const loginLabel = $( 'label[for="user_login"]' )[ 0 ].innerHTML;

function activateGuestAuthor() {
// Make email not required.
$( 'label[for="email"] > span.description' ).hide();
$( '#createuser input[name=email]' ).closest( 'tr' ).removeClass( 'form-required' );

// User login.
if ( 'new' === guestAuthorRole.screen ) {
$( 'label[for="user_login"]' )[ 0 ].innerHTML = guestAuthorRole.displayNameLabel;
} else {
$( 'label[for="user_login"]' ).parents( 'tr' ).hide();
}

// Password.
$( 'label[for="pass1"]' ).parents( 'tr' ).hide();

// Email notification.
$( 'input#send_user_notification' ).parents( 'tr' ).hide();

// User profile fields.
$( 'label[for="rich_editing"]' ).parents( 'tr' ).hide();
$( 'label[for="comment_shortcuts"]' ).parents( 'tr' ).hide();
$( 'label[for="admin_bar_front"]' ).parents( 'tr' ).hide();
$( 'label[for="locale"]' ).parents( 'tr' ).hide();
$( 'tr.user-admin-color-wrap' ).hide();
}

function deactivateGuestAuthor() {
// Make email required.
$( 'label[for="email"] > span.description' ).show();
$( '#createuser input[name=email]' ).closest( 'tr' ).addClass( 'form-required' );

// User login.
if ( 'new' === guestAuthorRole.screen ) {
$( 'label[for="user_login"]' )[ 0 ].innerHTML = loginLabel;
} else {
$( 'label[for="user_login"]' ).parents( 'tr' ).show();
}

// Password.
$( 'label[for="pass1"]' ).parents( 'tr' ).show();

// Email notification.
$( 'input#send_user_notification' ).parents( 'tr' ).show();

// User profile fields.
$( 'label[for="rich_editing"]' ).parents( 'tr' ).show();
$( 'label[for="comment_shortcuts"]' ).parents( 'tr' ).show();
$( 'label[for="admin_bar_front"]' ).parents( 'tr' ).show();
$( 'label[for="locale"]' ).parents( 'tr' ).show();
$( 'tr.user-admin-color-wrap' ).show();
}

// Trigger change event on page load.
$( 'select#role' ).change();
} );
Loading