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

Commit

Permalink
Fix phpcs. Fix ESLint.
Browse files Browse the repository at this point in the history
  • Loading branch information
miina committed Feb 14, 2017
1 parent 0edf0de commit 8270875
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 88 deletions.
106 changes: 53 additions & 53 deletions js/customize-snapshots-front.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
/* global jQuery, wp */
/* exported CustomizeSnapshotsFront */
var CustomizeSnapshotsFront = (function( $ ) {
'use strict';
'use strict';

var component = {
data: {
confirmationMsg: '',
action: '',
snapshotsFrontendPublishNonce: '',
errorMsg: ''
}
};
/**
* Init.
*
* @param {object} args Args.
* @returns {void}
*/
component.init = function init( args ) {
_.extend( component.data, args );
var component = {
data: {
confirmationMsg: '',
action: '',
snapshotsFrontendPublishNonce: '',
errorMsg: ''
}
};
/**
* Init.
*
* @param {object} args Args.
* @returns {void}
*/
component.init = function init( args ) {
_.extend( component.data, args );

$( document ).ready( function() {
component.setupPublishButton();
} );
};
$( document ).ready( function() {
component.setupPublishButton();
} );
};

/**
* Set up snapshot frontend publish button.
*
* @returns {void}
*/
component.setupPublishButton = function setupPublishButton() {
var publishBtn = $( '#wp-admin-bar-publish-customize-snapshot a' );
/**
* Set up snapshot frontend publish button.
*
* @returns {void}
*/
component.setupPublishButton = function setupPublishButton() {
var publishBtn = $( '#wp-admin-bar-publish-customize-snapshot a' );

if ( ! publishBtn.length ) {
return;
}
if ( ! publishBtn.length ) {
return;
}

publishBtn.click( function( e ) {
var request;
e.preventDefault();
publishBtn.click( function( e ) {
var request;
e.preventDefault();

if ( ! window.confirm( component.data.confirmationMsg ) ) {
return false;
}
request = wp.ajax.post( component.data.action, {
nonce: component.data.snapshotsFrontendPublishNonce,
uuid: component.data.uuid
} );
request.done( function( data ) {
if ( data && data.success ) {
window.location = e.target.href;
}
} );
request.fail( function( data ) {
window.alert( data.errorMsg );
} );
if ( ! window.confirm( component.data.confirmationMsg ) ) { // eslint-disable-line no-alert
return false;
}
request = wp.ajax.post( component.data.action, {
nonce: component.data.snapshotsFrontendPublishNonce,
uuid: component.data.uuid
} );
request.done( function( data ) {
if ( data && data.success ) {
window.location = e.target.href;
}
} );
request.fail( function( data ) {
window.alert( data.errorMsg ); // eslint-disable-line no-alert
} );

return true;
} );
};
return true;
} );
};

return component;
return component;
})( jQuery );
70 changes: 35 additions & 35 deletions php/class-customize-snapshot-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,17 +346,17 @@ public function enqueue_frontend_scripts() {
}
$handle = 'customize-snapshots-front';
wp_enqueue_script( $handle );
$exports = array(
'confirmationMsg' => __( 'Are you sure that you want to publish the Snapshot?', 'customize-snapshots' ),
'snapshotsFrontendPublishNonce' => wp_create_nonce( 'customize-snapshots-frontend-publish' ),
'action' => 'customize-snapshots-frontend-publish',
'uuid' => $this->snapshot->uuid(),
);
wp_add_inline_script(
$handle,
sprintf( 'CustomizeSnapshotsFront.init( %s )', wp_json_encode( $exports ) ),
'after'
);
$exports = array(
'confirmationMsg' => __( 'Are you sure that you want to publish the Snapshot?', 'customize-snapshots' ),
'snapshotsFrontendPublishNonce' => wp_create_nonce( 'customize-snapshots-frontend-publish' ),
'action' => 'customize-snapshots-frontend-publish',
'uuid' => $this->snapshot->uuid(),
);
wp_add_inline_script(
$handle,
sprintf( 'CustomizeSnapshotsFront.init( %s )', wp_json_encode( $exports ) ),
'after'
);
}

/**
Expand Down Expand Up @@ -499,10 +499,10 @@ public function print_admin_bar_styles() {
content: "\f179";
top: 2px;
}
#wpadminbar #wp-admin-bar-publish-customize-snapshot > .ab-item:before {
content: "\f147";
top: 2px;
}
#wpadminbar #wp-admin-bar-publish-customize-snapshot > .ab-item:before {
content: "\f147";
top: 2px;
}
#wpadminbar #wp-admin-bar-exit-customize-snapshot > .ab-item:before {
content: "\f158";
top: 2px;
Expand Down Expand Up @@ -640,11 +640,11 @@ public function remove_all_non_snapshot_admin_bar_links( $wp_admin_bar ) {
return;
}
$snapshot_admin_bar_node_ids = array(
'customize',
'exit-customize-snapshot',
'inspect-customize-snapshot',
'publish-customize-snapshot',
);
'customize',
'exit-customize-snapshot',
'inspect-customize-snapshot',
'publish-customize-snapshot',
);
foreach ( $wp_admin_bar->get_nodes() as $node ) {
if ( in_array( $node->id, $snapshot_admin_bar_node_ids, true ) || '#' === substr( $node->href, 0, 1 ) ) {
continue;
Expand Down Expand Up @@ -978,14 +978,14 @@ public function get_customize_uuid_param() {
* Publishes changeset from frontend.
*/
public function ajax_snapshot_frontend_publish() {
if ( ! check_ajax_referer( 'customize-snapshots-frontend-publish', 'nonce' ) ) {
status_header( 400 );
wp_send_json_error( 'bad_nonce' );
}
if ( ! check_ajax_referer( 'customize-snapshots-frontend-publish', 'nonce' ) ) {
status_header( 400 );
wp_send_json_error( 'bad_nonce' );
}

if ( ! isset( $_POST['uuid'] ) ) {
return;
}
if ( ! isset( $_POST['uuid'] ) ) {
return;
}

$this->current_snapshot_uuid = esc_attr( $_POST['uuid'] );
$this->ensure_customize_manager();
Expand All @@ -994,13 +994,13 @@ public function ajax_snapshot_frontend_publish() {
) );

if ( is_wp_error( $r ) ) {
$msg = __( 'Publishing failed: ', 'customize-snapshots' );
foreach( $r->errors as $name => $value ){
$msg .= $name . '; ';
}
wp_send_json_error( array( 'errorMsg' => $msg ) );
} else {
$msg = __( 'Publishing failed: ', 'customize-snapshots' );
foreach ( $r->errors as $name => $value ) {
$msg .= $name . '; ';
}
wp_send_json_error( array( 'errorMsg' => $msg ) );
} else {
wp_send_json_success( array( 'success' => true ) );
}
}
}
}
}

0 comments on commit 8270875

Please sign in to comment.