Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Merge 7aee799 into 856d135
Browse files Browse the repository at this point in the history
  • Loading branch information
PatelUtkarsh committed Aug 17, 2016
2 parents 856d135 + 7aee799 commit d15b2e1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
58 changes: 33 additions & 25 deletions js/customize-snapshots.js
Expand Up @@ -56,7 +56,9 @@

component.extendPreviewerQuery();
component.addButtons();
component.addSchedule();
if ( component.data.currentUserCanPublish ) {
component.addSchedule();
}

$( '#snapshot-save' ).on( 'click', function( event ) {
var scheduleDate;
Expand Down Expand Up @@ -209,34 +211,36 @@
snapshotButton.insertAfter( publishButton );

// Schedule button.
scheduleButton = wp.template( 'snapshot-schedule-button' );
scheduleButton = $( $.trim( scheduleButton( {} ) ) );
scheduleButton.insertAfter( snapshotButton );
if ( component.data.currentUserCanPublish ) {
scheduleButton = wp.template( 'snapshot-schedule-button' );
scheduleButton = $( $.trim( scheduleButton( {} ) ) );
scheduleButton.insertAfter( snapshotButton );

if ( ! component.data.editLink ) {
scheduleButton.hide();
}
if ( ! component.data.editLink ) {
scheduleButton.hide();
}

api.state( 'change', function() {
scheduleButton.toggle( api.state( 'snapshot-saved' ).get() && api.state( 'snapshot-exists' ).get() );
} );
api.state( 'change', function() {
scheduleButton.toggle( api.state( 'snapshot-saved' ).get() && api.state( 'snapshot-exists' ).get() );
} );

api.state( 'snapshot-exists' ).bind( function( exist ) {
scheduleButton.toggle( exist );
} );
api.state( 'snapshot-exists' ).bind( function( exist ) {
scheduleButton.toggle( exist );
} );

api.state( 'snapshot-saved' ).bind( function( saved ) {
snapshotButton.prop( 'disabled', saved );
} );
api.state( 'snapshot-saved' ).bind( function( saved ) {
snapshotButton.prop( 'disabled', saved );
} );

api.state( 'saved' ).bind( function( saved ) {
if ( saved ) {
snapshotButton.prop( 'disabled', true );
}
} );
api.bind( 'change', function() {
snapshotButton.prop( 'disabled', false );
} );
api.state( 'saved' ).bind( function( saved ) {
if ( saved ) {
snapshotButton.prop( 'disabled', true );
}
} );
api.bind( 'change', function() {
snapshotButton.prop( 'disabled', false );
} );
}

api.state( 'snapshot-exists' ).bind( function( exists ) {
var buttonText, permsMsg;
Expand Down Expand Up @@ -303,6 +307,10 @@

component.scheduleContainerDisplayed = new api.Value();

if ( ! component.data.currentUserCanPublish ) {
return;
}

// Inject the UI.
if ( _.isEmpty( component.schedule.container ) ) {
if ( '0000-00-00 00:00:00' === component.data.publishDate ) {
Expand Down Expand Up @@ -425,7 +433,7 @@
sliceBegin = 0,
sliceEnd = -2;

if ( _.isEmpty( component.schedule.container ) ) {
if ( _.isEmpty( component.schedule.container ) || ! component.data.currentUserCanPublish ) {
return;
}

Expand Down
4 changes: 4 additions & 0 deletions php/class-customize-snapshot-manager.php
Expand Up @@ -1079,6 +1079,10 @@ public function handle_update_snapshot_request() {
status_header( 400 );
wp_send_json_error( 'bad_status' );
}
if ( 'future' === $status && ! current_user_can( 'customize_publish' ) ) {
status_header( 400 );
wp_send_json_error( 'customize_not_allowed' );
}
$publish_date = isset( $_POST['publish_date'] ) ? $_POST['publish_date'] : '';
if ( 'future' === $status ) {
$publish_date_obj = new \DateTime( $publish_date );
Expand Down
4 changes: 4 additions & 0 deletions php/class-post-type.php
Expand Up @@ -585,6 +585,10 @@ public function filter_user_has_cap( $allcaps, $caps ) {
$allcaps[ $granted_cap ] = current_user_can( 'customize' );
}

if ( ! current_user_can( 'customize_publish' ) || empty( $allcaps['customize_publish'] ) ) {
$allcaps[ $post_type_obj->cap->publish_posts ] = false;
}

if ( ! current_user_can( 'edit_others_posts' ) ) {
$allcaps[ $post_type_obj->cap->edit_others_posts ] = false;
}
Expand Down

0 comments on commit d15b2e1

Please sign in to comment.