diff --git a/src/js/_enqueues/admin/post.js b/src/js/_enqueues/admin/post.js
index d50fe6007d33b..dc6c9a2339b57 100644
--- a/src/js/_enqueues/admin/post.js
+++ b/src/js/_enqueues/admin/post.js
@@ -302,7 +302,7 @@ window.wp = window.wp || {};
* All post and postbox controls and functionality.
*/
jQuery( function($) {
- var stamp, visibility, $submitButtons, updateVisibility, updateText,
+ var stamp, visibility, $submitButtons, updateVisibility, updateText, getSelectedVisibility, setSelectedVisibility,
$textarea = $('#content'),
$document = $(document),
postId = $('#post_ID').val() || 0,
@@ -720,6 +720,12 @@ jQuery( function($) {
if ( $('#submitdiv').length ) {
stamp = $('#timestamp').html();
visibility = $('#post-visibility-display').html();
+ getSelectedVisibility = function() {
+ return $postVisibilitySelect.find( 'input[name="visibility"]:checked' ).val();
+ };
+ setSelectedVisibility = function( value ) {
+ $( '#visibility-radio-' + value ).prop( 'checked', true );
+ };
/**
* When the visibility of a post changes sub-options should be shown or hidden.
@@ -730,7 +736,7 @@ jQuery( function($) {
*/
updateVisibility = function() {
// Show sticky for public posts.
- if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) {
+ if ( getSelectedVisibility() != 'public' ) {
$('#sticky').prop('checked', false);
$('#sticky-span').hide();
} else {
@@ -738,7 +744,7 @@ jQuery( function($) {
}
// Show password input field for password protected post.
- if ( $postVisibilitySelect.find('input:radio:checked').val() != 'password' ) {
+ if ( getSelectedVisibility() != 'password' ) {
$('#password-span').hide();
} else {
$('#password-span').show();
@@ -821,7 +827,7 @@ jQuery( function($) {
}
// Add "privately published" to post status when applies.
- if ( $postVisibilitySelect.find('input:radio:checked').val() == 'private' ) {
+ if ( getSelectedVisibility() == 'private' ) {
$('#publish').val( __( 'Update' ) );
if ( 0 === optPublish.length ) {
postStatus.append('');
@@ -872,7 +878,7 @@ jQuery( function($) {
if ( $postVisibilitySelect.is(':hidden') ) {
updateVisibility();
$postVisibilitySelect.slideDown( 'fast', function() {
- $postVisibilitySelect.find( 'input[type="radio"]' ).first().trigger( 'focus' );
+ $postVisibilitySelect.find( 'input[name="visibility"]' ).first().trigger( 'focus' );
} );
$(this).hide();
}
@@ -881,18 +887,19 @@ jQuery( function($) {
// Cancel visibility selection area and hide it from view.
$postVisibilitySelect.find('.cancel-post-visibility').on( 'click', function( event ) {
$postVisibilitySelect.slideUp('fast');
- $('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true);
+ setSelectedVisibility( $( '#hidden-post-visibility' ).val() );
$('#post_password').val($('#hidden-post-password').val());
$('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked'));
$('#post-visibility-display').html(visibility);
$('#visibility .edit-visibility').show().trigger( 'focus' );
+ updateVisibility();
updateText();
event.preventDefault();
});
// Set the selected visibility as current.
$postVisibilitySelect.find('.save-post-visibility').on( 'click', function( event ) { // Crazyhorse branch - multiple OK cancels.
- var visibilityLabel = '', selectedVisibility = $postVisibilitySelect.find('input:radio:checked').val();
+ var visibilityLabel = '', selectedVisibility = getSelectedVisibility();
$postVisibilitySelect.slideUp('fast');
$('#visibility .edit-visibility').show().trigger( 'focus' );
@@ -919,7 +926,7 @@ jQuery( function($) {
});
// When the selection changes, update labels.
- $postVisibilitySelect.find('input:radio').on( 'change', function() {
+ $postVisibilitySelect.find( 'input[name="visibility"]' ).on( 'change', function() {
updateVisibility();
});
diff --git a/src/wp-admin/css/edit.css b/src/wp-admin/css/edit.css
index f1dd76ac31474..0f04b620e3523 100644
--- a/src/wp-admin/css/edit.css
+++ b/src/wp-admin/css/edit.css
@@ -334,10 +334,6 @@ form#tags-filter {
min-width: 0;
}
-#side-sortables input#post_password {
- width: 94%
-}
-
#side-sortables .tagsdiv #newtag {
flex: 1;
min-width: 0;
@@ -712,6 +708,42 @@ form#tags-filter {
margin-top: 3px;
}
+#post-visibility-select input#post_password {
+ box-sizing: border-box;
+ width: 100%;
+ max-width: 100%;
+}
+
+#post-visibility-fieldset {
+ margin: 0;
+ padding: 0;
+ border: 0;
+}
+
+#post-visibility-fieldset input,
+#post-visibility-select input#sticky {
+ margin: 2px 3px 5px 0;
+ vertical-align: middle;
+}
+
+#post-visibility-select #sticky-span,
+#post-visibility-select #password-span {
+ display: block;
+ margin-top: 8px;
+}
+
+#post-visibility-select #sticky-span {
+ margin-left: 0;
+}
+
+#post-visibility-select input#post_password {
+ margin-top: 3px;
+}
+
+#post-visibility-select p {
+ margin: 12px 0 0;
+}
+
#linksubmitdiv .inside, /* Old Link Manager back-compat. */
#poststuff #submitdiv .inside {
margin: 0;
diff --git a/src/wp-admin/includes/meta-boxes.php b/src/wp-admin/includes/meta-boxes.php
index 535a00cd3fe94..eec3d29a6da30 100644
--- a/src/wp-admin/includes/meta-boxes.php
+++ b/src/wp-admin/includes/meta-boxes.php
@@ -208,17 +208,19 @@ function post_submit_meta_box( $post, $args = array() ) {
- />
+
diff --git a/tests/phpunit/tests/admin/includesMetaBoxes.php b/tests/phpunit/tests/admin/includesMetaBoxes.php new file mode 100644 index 0000000000000..ab3d7d3268377 --- /dev/null +++ b/tests/phpunit/tests/admin/includesMetaBoxes.php @@ -0,0 +1,59 @@ +user->create( array( 'role' => 'editor' ) ); + } + + public function test_post_submit_meta_box_renders_visibility_controls() { + $post = self::factory()->post->create_and_get( + array( + 'post_author' => self::$editor_id, + 'post_status' => 'draft', + ) + ); + + wp_set_current_user( self::$editor_id ); + + $output = $this->render_post_submit_meta_box( $post ); + + $this->assertStringContainsString( '