[wp-trac] [WordPress Trac] #30448: Customizer Manager/Settings classes do not provide public save method to use outside of customize.php

WordPress Trac noreply at wordpress.org
Fri Dec 2 19:35:26 UTC 2016


#30448: Customizer Manager/Settings classes do not provide public save method to
use outside of customize.php
-------------------------+----------------------
 Reporter:  CrazyJaco    |       Owner:
     Type:  enhancement  |      Status:  closed
 Priority:  normal       |   Milestone:
Component:  Customize    |     Version:  4.0
 Severity:  normal       |  Resolution:  invalid
 Keywords:  has-patch    |     Focuses:
-------------------------+----------------------
Changes (by westonruter):

 * status:  new => closed
 * resolution:   => invalid
 * milestone:  Awaiting Review =>


Comment:

 @CrazyJaco The most basic way to do this is just to call
 `$wp_customize->set_post_value( $setting_id, $setting_value )` and then do
 `$wp_customize->get_setting( $setting_id )->save()`. Note that in doing
 this you will need to make sure you have set the current user to one who
 can do the setting's `capability`.

 There is a better approach now with changesets which allows you to get
 access to validation errors and also to ensure that the update is
 transactional (that all get saved rather than only some):

 {{{#!php
 <?php
 $manager = new WP_Customize_Manager();
 do_action( 'customize_register', $manager );
 foreach ( $exported as $setting_id => $setting_value ) {
     $manager->set_post_value( $setting_id, $setting_value );
 }
 $manager->save_changeset_post( array( 'status' => 'publish' ) );
 }}}

 This is similar to what is done now with importing starter content in 4.7
 via `WP_Customize_Manager::import_theme_starter_content()`.

 Let me know how you go with that.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30448#comment:16>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list