Changeset 1373586
- Timestamp:
- 03/18/2016 07:51:05 AM (8 years ago)
- Location:
- customize-snapshots/trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
customize-snapshots/trunk/customize-snapshots.php
r1312153 r1373586 4 4 * Plugin URI: https://github.com/xwp/wp-customize-snapshots 5 5 * Description: Allow Customizer states to be drafted, and previewed with a private URL. 6 * Version: 0.3. 06 * Version: 0.3. 7 7 * Author: XWP 8 8 * Author URI: https://xwp.co/ -
customize-snapshots/trunk/js/customize-snapshots.js
r1310567 r1373586 226 226 227 227 if ( url.match( regex ) ) { 228 url = url.replace( regex, '$1' + 'customize_snapshot_uuid=' + response.customize_snapshot_uuid+ '$2' );228 url = url.replace( regex, '$1' + 'customize_snapshot_uuid=' + + '$2' ); 229 229 } else { 230 url = url + separator + 'customize_snapshot_uuid=' + response.customize_snapshot_uuid;230 url = url + separator + 'customize_snapshot_uuid=' + ; 231 231 } 232 232 … … 234 234 scope = 'full'; 235 235 } 236 url += '&scope=' + scope;236 url += '&scope=' + ; 237 237 238 238 // Write over the UUID -
customize-snapshots/trunk/js/customize-snapshots.min.js
r1310567 r1373586 1 var customizeSnapshots=function(a){var b,c,d={},e=wp.customize,f=_customizeSnapshots.uuid,g=_customizeSnapshots.is_preview,h=_customizeSnapshots.snapshot_theme,i=_customizeSnapshots.current_user_can_publish;return d.init=function(){window._wpCustomizeControlsL10n.save=_customizeSnapshots.i18n.publish,window._wpCustomizeControlsL10n.saved=_customizeSnapshots.i18n.published,e.bind("ready",function(){!e.settings.theme.active||h&&h!==e.settings.theme.stylesheet||(d.previewerQuery(),d.addButton(),d.addDialogForm(),d.dialogEvents(),g&&(e.state("saved").set(!1),d.resetSavedStateQuietly()))}),e.bind("save",function(b){return b.fail(function(b){var c="snapshot-dialog-error",d=wp.template(c);b.responseText&&(0===a("#"+c).length&&a("body").append(d({title:_customizeSnapshots.i18n.publish,message:_customizeSnapshots.i18n.permsMsg})),a("#customize-header-actions .spinner").removeClass("is-active"),a("#"+c).dialog({autoOpen:!0,modal:!0}))}),b})},d.previewerQuery=function(){var a=e.previewer.query;e.previewer.query=function(){var b,c=this,d={};return b=a.apply(c,arguments),g&&(e.each(function(a,b){d[b]={value:a(),dirty:!1}}),b.snapshot_customized=JSON.stringify(d),b.snapshot_uuid=f),b}},d.addButton=function(){var b,c,d=a("#customize-header-actions"),e=d.find("#save");d.length&&0===d.find("#snapshot-save").length&&(b=wp.template("snapshot-save"),c={buttonText:i?_customizeSnapshots.i18n.saveButton:_customizeSnapshots.i18n.saveDraftButton},b=a(a.trim(b(c))),i||(b.attr("title",_customizeSnapshots.i18n.permsMsg),b.addClass("button-primary").removeClass("button-secondary")),b.insertAfter(e)),i||e.hide(),d.addClass("button-added")},d.addDialogForm=function(){var b=wp.template("snapshot-dialog-form"),c={title:_customizeSnapshots.i18n.formTitle,is_preview:g,message:_customizeSnapshots.i18n.saveMsg,scope:_customizeSnapshots.scope,scopeTitle:_customizeSnapshots.i18n.scopeTitle,dirtyLabel:_customizeSnapshots.i18n.dirtyLabel,fullLabel:_customizeSnapshots.i18n.fullLabel};a("body").append(b(c))},d.dialogEvents=function(){b=a("#snapshot-dialog-form").dialog({autoOpen:!1,modal:!0,buttons:{Save:{text:_customizeSnapshots.i18n.saveButton,click:d.sendUpdateSnapshotRequest},Cancel:{text:_customizeSnapshots.i18n.cancelButton,click:function(){b.dialog("close")}}},close:function(){c[0].reset()}}),c=b.find("form").on("submit",function(a){a.preventDefault(),b.next(".ui-dialog-buttonpane").find("button:first-child").disabled(!0),d.sendUpdateSnapshotRequest()}),a("#snapshot-save").on("click",function(a){a.preventDefault(),b.dialog("open"),b.find("form input[name=scope]").blur(),b.next(".ui-dialog-buttonpane").find("button").blur()})},d.resetSavedStateQuietly=function(){e.state("saved")._value=!0},d.sendUpdateSnapshotRequest=function(){var c,h,i=a("#customize-header-actions .spinner"),j=b.find('form input[name="scope"]:checked').val();j||(j=b.find('form input[type="hidden"]').val()),b.dialog("close"),i.addClass("is-active"),h={},e.each(function(a,b){h[b]={value:a(),dirty:a._dirty}}),c=wp.ajax.post("customize_update_snapshot",{nonce:_customizeSnapshots.nonce,wp_customize:"on",snapshot_customized:JSON.stringify(h),customize_snapshot_uuid:f,scope:j,preview:g?"on":"off"}),c.done(function(b){var c=wp.customize.previewer.previewUrl(),e=new RegExp("([?&])customize_snapshot_uuid=.*?(&|$)","i"),h=-1!==c.indexOf("?")?"&":"?",k="snapshot-dialog-link",l=wp.template(k);c=c.match(e)?c.replace(e,"$1customize_snapshot_uuid="+ b.customize_snapshot_uuid+"$2"):c+h+"customize_snapshot_uuid="+b.customize_snapshot_uuid,"dirty"!==j&&(j="full"),c+="&scope="+j,g||(f=b.customize_snapshot_next_uuid),a("#"+k).length&&a("#"+k).remove(),a("body").append(l({title:_customizeSnapshots.i18n.previewTitle,url:c})),i.removeClass("is-active"),a("#"+k).dialog({autoOpen:!0,modal:!0}),a("#"+k).find("a").blur(),d.resetSavedStateQuietly()}),c.fail(function(){var b="snapshot-dialog-error",c=wp.template(b);0===a("#"+b).length&&a("body").append(c({title:_customizeSnapshots.i18n.formTitle,message:_customizeSnapshots.i18n.errorMsg})),i.removeClass("is-active"),a("#"+b).dialog({autoOpen:!0,modal:!0})})},d.init(),d}(jQuery);1 var customizeSnapshots=function(a){var b,c,d={},e=wp.customize,f=_customizeSnapshots.uuid,g=_customizeSnapshots.is_preview,h=_customizeSnapshots.snapshot_theme,i=_customizeSnapshots.current_user_can_publish;return d.init=function(){window._wpCustomizeControlsL10n.save=_customizeSnapshots.i18n.publish,window._wpCustomizeControlsL10n.saved=_customizeSnapshots.i18n.published,e.bind("ready",function(){!e.settings.theme.active||h&&h!==e.settings.theme.stylesheet||(d.previewerQuery(),d.addButton(),d.addDialogForm(),d.dialogEvents(),g&&(e.state("saved").set(!1),d.resetSavedStateQuietly()))}),e.bind("save",function(b){return b.fail(function(b){var c="snapshot-dialog-error",d=wp.template(c);b.responseText&&(0===a("#"+c).length&&a("body").append(d({title:_customizeSnapshots.i18n.publish,message:_customizeSnapshots.i18n.permsMsg})),a("#customize-header-actions .spinner").removeClass("is-active"),a("#"+c).dialog({autoOpen:!0,modal:!0}))}),b})},d.previewerQuery=function(){var a=e.previewer.query;e.previewer.query=function(){var b,c=this,d={};return b=a.apply(c,arguments),g&&(e.each(function(a,b){d[b]={value:a(),dirty:!1}}),b.snapshot_customized=JSON.stringify(d),b.snapshot_uuid=f),b}},d.addButton=function(){var b,c,d=a("#customize-header-actions"),e=d.find("#save");d.length&&0===d.find("#snapshot-save").length&&(b=wp.template("snapshot-save"),c={buttonText:i?_customizeSnapshots.i18n.saveButton:_customizeSnapshots.i18n.saveDraftButton},b=a(a.trim(b(c))),i||(b.attr("title",_customizeSnapshots.i18n.permsMsg),b.addClass("button-primary").removeClass("button-secondary")),b.insertAfter(e)),i||e.hide(),d.addClass("button-added")},d.addDialogForm=function(){var b=wp.template("snapshot-dialog-form"),c={title:_customizeSnapshots.i18n.formTitle,is_preview:g,message:_customizeSnapshots.i18n.saveMsg,scope:_customizeSnapshots.scope,scopeTitle:_customizeSnapshots.i18n.scopeTitle,dirtyLabel:_customizeSnapshots.i18n.dirtyLabel,fullLabel:_customizeSnapshots.i18n.fullLabel};a("body").append(b(c))},d.dialogEvents=function(){b=a("#snapshot-dialog-form").dialog({autoOpen:!1,modal:!0,buttons:{Save:{text:_customizeSnapshots.i18n.saveButton,click:d.sendUpdateSnapshotRequest},Cancel:{text:_customizeSnapshots.i18n.cancelButton,click:function(){b.dialog("close")}}},close:function(){c[0].reset()}}),c=b.find("form").on("submit",function(a){a.preventDefault(),b.next(".ui-dialog-buttonpane").find("button:first-child").disabled(!0),d.sendUpdateSnapshotRequest()}),a("#snapshot-save").on("click",function(a){a.preventDefault(),b.dialog("open"),b.find("form input[name=scope]").blur(),b.next(".ui-dialog-buttonpane").find("button").blur()})},d.resetSavedStateQuietly=function(){e.state("saved")._value=!0},d.sendUpdateSnapshotRequest=function(){var c,h,i=a("#customize-header-actions .spinner"),j=b.find('form input[name="scope"]:checked').val();j||(j=b.find('form input[type="hidden"]').val()),b.dialog("close"),i.addClass("is-active"),h={},e.each(function(a,b){h[b]={value:a(),dirty:a._dirty}}),c=wp.ajax.post("customize_update_snapshot",{nonce:_customizeSnapshots.nonce,wp_customize:"on",snapshot_customized:JSON.stringify(h),customize_snapshot_uuid:f,scope:j,preview:g?"on":"off"}),c.done(function(b){var c=wp.customize.previewer.previewUrl(),e=new RegExp("([?&])customize_snapshot_uuid=.*?(&|$)","i"),h=-1!==c.indexOf("?")?"&":"?",k="snapshot-dialog-link",l=wp.template(k);c=c.match(e)?c.replace(e,"$1customize_snapshot_uuid="+,g||(f=b.customize_snapshot_next_uuid),a("#"+k).length&&a("#"+k).remove(),a("body").append(l({title:_customizeSnapshots.i18n.previewTitle,url:c})),i.removeClass("is-active"),a("#"+k).dialog({autoOpen:!0,modal:!0}),a("#"+k).find("a").blur(),d.resetSavedStateQuietly()}),c.fail(function(){var b="snapshot-dialog-error",c=wp.template(b);0===a("#"+b).length&&a("body").append(c({title:_customizeSnapshots.i18n.formTitle,message:_customizeSnapshots.i18n.errorMsg})),i.removeClass("is-active"),a("#"+b).dialog({autoOpen:!0,modal:!0})})},d.init(),d}(jQuery); -
customize-snapshots/trunk/php/class-customize-snapshot-manager.php
r1312153 r1373586 19 19 /** 20 20 * Post type. 21 21 22 * @type string 22 23 */ … … 25 26 /** 26 27 * Action nonce. 28 27 29 * @type string 28 30 */ … … 91 93 } 92 94 93 $uuid = isset( $_REQUEST['customize_snapshot_uuid'] ) ? sanitize_ key( wp_unslash( $_REQUEST['customize_snapshot_uuid']) ) : null; // WPCS: input var ok.94 $scope = isset( $_REQUEST['scope'] ) ? sanitize_ key( wp_unslash( $_REQUEST['scope']) ) : 'dirty'; // WPCS: input var ok.95 $uuid = isset( $_REQUEST['customize_snapshot_uuid'] ) ? sanitize_ ) ) : null; // WPCS: input var ok. 96 $scope = isset( $_REQUEST['scope'] ) ? sanitize_ ) ) : 'dirty'; // WPCS: input var ok. 95 97 $apply_dirty = ( 'dirty' === $scope ); 96 98 … … 98 100 if ( empty( $GLOBALS['wp_customize'] ) || ! ( $GLOBALS['wp_customize'] instanceof \WP_Customize_Manager ) && $uuid ) { 99 101 require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' ); 102 100 103 $GLOBALS['wp_customize'] = new \WP_Customize_Manager(); 104 101 105 } 102 106 $this->customize_manager = $GLOBALS['wp_customize']; … … 147 151 'scope' => $this->snapshot->apply_dirty ? 'dirty' : 'full', 148 152 ); 149 $return_url = add_query_arg( $args, $this->customize_manager->get_return_url() );153 $return_url = add_query_arg( , $this->customize_manager->get_return_url() ); 150 154 $this->customize_manager->set_return_url( $return_url ); 151 155 } … … 160 164 $http_host = isset( $_SERVER['HTTP_HOST'] ) ? wp_unslash( $_SERVER['HTTP_HOST'] ) : parse_url( home_url(), PHP_URL_HOST ); // WPCS: input var ok; sanitization ok. 161 165 $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '/'; // WPCS: input var ok; sanitization ok. 162 return esc_url_raw( ( is_ssl() ? 'https://' : 'http://' ) . $http_host . $request_uri );166 return ; 163 167 } 164 168 … … 169 173 */ 170 174 public function clean_current_url() { 171 return esc_url( remove_query_arg( array( 'customize_snapshot_uuid', 'scope' ), $this->current_url()) );175 return ) ); 172 176 } 173 177 … … 177 181 public function maybe_force_redirect() { 178 182 if ( false === $this->snapshot->is_preview() && isset( $_GET['customize_snapshot_uuid'] ) ) { // WPCS: input var ok. 179 wp_safe_redirect( $this->clean_current_url() );183 wp_safe_redirect( ) ); 180 184 exit; 181 185 } … … 243 247 'current_user_can_publish' => current_user_can( 'customize_publish' ), 244 248 'snapshot_theme' => $snapshot_theme, 245 'scope' => ( isset( $_GET['scope'] ) ? sanitize_ key( wp_unslash( $_GET['scope']) ) : 'dirty' ), // WPCS: input var ok.249 'scope' => ( isset( $_GET['scope'] ) ? sanitize_ ) ) : 'dirty' ), // WPCS: input var ok. 246 250 'i18n' => array( 247 251 'saveButton' => __( 'Save', 'customize-snapshots' ), … … 323 327 false && check_ajax_referer(); // Note: This is a workaround for PHPCS nonce verification check. 324 328 325 $uuid = ! empty( $_POST['snapshot_uuid'] ) ? sanitize_ key( wp_unslash( $_POST['snapshot_uuid']) ) : null; // WPCS: input var ok.329 $uuid = ! empty( $_POST['snapshot_uuid'] ) ? sanitize_ ) ) : null; // WPCS: input var ok. 326 330 if ( current_user_can( 'customize' ) && $uuid && $this->snapshot->is_valid_uuid( $uuid ) ) { 327 331 $this->snapshot_uuid = $uuid; … … 384 388 385 389 // Set the snapshot UUID. 386 $this->snapshot->set_uuid( sanitize_ key( wp_unslash( $_POST['customize_snapshot_uuid']) ) ); // WPCS: input var ok.390 $this->snapshot->set_uuid( sanitize_ ) ) ); // WPCS: input var ok. 387 391 $uuid = $this->snapshot->uuid(); 388 392 $next_uuid = $uuid; … … 431 435 } 432 436 433 $current_url = remove_query_arg( array( 'customize_snapshot_uuid', 'scope' ), $this->current_url() );434 435 437 $args = array(); 436 $uuid = isset( $_GET['customize_snapshot_uuid'] ) ? sanitize_ key( wp_unslash( $_GET['customize_snapshot_uuid']) ) : null; // WPCS: input var ok.437 $scope = isset( $_GET['scope'] ) ? sanitize_ key( wp_unslash( $_GET['scope']) ) : 'dirty'; // WPCS: input var ok.438 $uuid = isset( $_GET['customize_snapshot_uuid'] ) ? sanitize_ ) ) : null; // WPCS: input var ok. 439 $scope = isset( $_GET['scope'] ) ? sanitize_ ) ) : 'dirty'; // WPCS: input var ok. 438 440 439 441 if ( $uuid && $this->snapshot->is_valid_uuid( $uuid ) ) { … … 442 444 } 443 445 444 $args['url'] = urlencode( $current_url);445 $customize_url = add_query_arg( $args, wp_customize_url() );446 $args['url'] = ); 447 $customize_url = add_query_arg( , wp_customize_url() ); 446 448 447 449 $wp_admin_bar->add_menu( -
customize-snapshots/trunk/php/class-customize-snapshot.php
r1312153 r1373586 229 229 'post_type' => Customize_Snapshot_Manager::POST_TYPE, 230 230 'post_status' => array( 'draft', 'publish' ), 231 232 233 231 234 ) ); 232 $posts = $query-> get_posts();235 $posts = $query->; 233 236 remove_action( 'pre_get_posts', array( $this, '_override_wp_query_is_single' ) ); 234 237 -
customize-snapshots/trunk/php/class-plugin.php
r1312153 r1373586 44 44 add_action( 'wp_default_scripts', array( $this, 'register_scripts' ), 11 ); 45 45 add_action( 'wp_default_styles', array( $this, 'register_styles' ), 11 ); 46 add_action( 'user_has_cap', array( $this, 'filter_user_has_cap' ), 10 , 4);46 add_action( 'user_has_cap', array( $this, 'filter_user_has_cap' ), 10 ); 47 47 48 48 $this->customize_snapshot_manager = new Customize_Snapshot_Manager( $this ); … … 78 78 * Add the customize_publish capability to users who can edit_theme_options by default. 79 79 * 80 * @param array $allcaps An array of all the user's capabilities. 81 * @param array $caps Actual capabilities for meta capability. 82 * @param array $args Optional parameters passed to has_cap(), typically object ID. 83 * @param \WP_User $user The user object. 80 * @param array $allcaps An array of all the user's capabilities. 84 81 * @return array All caps. 85 82 */ 86 public function filter_user_has_cap( $allcaps, $caps, $args, $user ) { 87 unset( $caps, $args, $user ); 83 public function filter_user_has_cap( $allcaps ) { 88 84 if ( ! empty( $allcaps['edit_theme_options'] ) ) { 89 85 $allcaps['customize_publish'] = true; 90 86 } 87 91 88 return $allcaps; 92 89 } -
customize-snapshots/trunk/readme.txt
r1312153 r1373586 3 3 Requires at least: 4.3 4 4 Tested up to: trunk 5 Stable tag: 0.3. 05 Stable tag: 0.3. 6 6 License: GPLv2 or later 7 7 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 21 21 22 22 == Changelog == 23 24 25 26 27 23 28 24 29 = 0.3.0 =
Note: See TracChangeset
for help on using the changeset viewer.