GC_Customize_Manager::__construct()
最后更新于:2021-11-27 03:20:17
GC_Customize_Manager::__construct( array$args=array())Constructor.
参数
- $args
-
(array) (Optional) Args.
-
‘changeset_uuid’
(null|string|false) Changeset UUID, thepost_name
for the customize_changeset post containing the customized state. Defaults tonull
resulting in a UUID to be immediately generated. Iffalse
is provided, then then the changeset UUID will be determined duringafter_setup_theme
: when thecustomize_changeset_branching
filter returns false, then the default UUID will be that of the most recentcustomize_changeset
post that has a status other than ‘auto-draft’, ‘publish’, or ‘trash’. Otherwise, if changeset branching is enabled, then a random UUID will be used. -
‘theme’
(string) Theme to be previewed (for theme switch). Defaults to customize_theme or theme query params. -
‘messenger_channel’
(string) Messenger channel. Defaults to customize_messenger_channel query param. -
‘settings_previewed’
(bool) If settings should be previewed. Defaults to true. -
‘branching’
(bool) If changeset branching is allowed; otherwise, changesets are linear. Defaults to true. -
‘autosaved’
(bool) If data from a changeset’s autosaved revision should be loaded if it exists. Defaults to false.
Default value: array()
-
‘changeset_uuid’
源文件
文件: gc-includes/class-gc-customize-manager.php
public function __construct( $args = array() ) {
$args = array_merge(
array_fill_keys( array( 'changeset_uuid', 'theme', 'messenger_channel', 'settings_previewed', 'autosaved', 'branching' ), null ),
$args
);
// Note that the UUID format will be validated in the setup_theme() method.
if ( ! isset( $args['changeset_uuid'] ) ) {
$args['changeset_uuid'] = gc_generate_uuid4();
}
// The theme and messenger_channel should be supplied via $args,
// but they are also looked at in the $_REQUEST global here for back-compat.
if ( ! isset( $args['theme'] ) ) {
if ( isset( $_REQUEST['customize_theme'] ) ) {
$args['theme'] = gc_unslash( $_REQUEST['customize_theme'] );
} elseif ( isset( $_REQUEST['theme'] ) ) { // Deprecated.
$args['theme'] = gc_unslash( $_REQUEST['theme'] );
}
}
if ( ! isset( $args['messenger_channel'] ) && isset( $_REQUEST['customize_messenger_channel'] ) ) {
$args['messenger_channel'] = sanitize_key( gc_unslash( $_REQUEST['customize_messenger_channel'] ) );
}
$this->original_stylesheet = get_stylesheet();
$this->theme = gc_get_theme( 0 === validate_file( $args['theme'] ) ? $args['theme'] : null );
$this->messenger_channel = $args['messenger_channel'];
$this->_changeset_uuid = $args['changeset_uuid'];
foreach ( array( 'settings_previewed', 'autosaved', 'branching' ) as $key ) {
if ( isset( $args[ $key ] ) ) {
$this->$key = (bool) $args[ $key ];
}
}
require_once ABSPATH . GCINC . '/class-gc-customize-setting.php';
require_once ABSPATH . GCINC . '/class-gc-customize-panel.php';
require_once ABSPATH . GCINC . '/class-gc-customize-section.php';
require_once ABSPATH . GCINC . '/class-gc-customize-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-color-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-media-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-upload-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-image-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-background-image-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-background-position-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-cropped-image-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-site-icon-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-header-image-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-theme-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-code-editor-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-widget-area-customize-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-widget-form-customize-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-nav-menu-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-nav-menu-item-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-nav-menu-location-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-nav-menu-name-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-nav-menu-locations-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-nav-menu-auto-add-control.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-nav-menus-panel.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-themes-panel.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-themes-section.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-sidebar-section.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-nav-menu-section.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-custom-css-setting.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-filter-setting.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-header-image-setting.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-background-image-setting.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-nav-menu-item-setting.php';
require_once ABSPATH . GCINC . '/customize/class-gc-customize-nav-menu-setting.php';
/**
* Filters the core Customizer components to load.
*
* This allows Core components to be excluded from being instantiated by
* filtering them out of the array. Note that this filter generally runs
* during the {@see 'plugins_loaded'} action, so it cannot be added
* in a theme.
*
* @since 4.4.0
*
* @see GC_Customize_Manager::__construct()
*
* @param string[] $components Array of core components to load.
* @param GC_Customize_Manager $this GC_Customize_Manager instance.
*/
$components = apply_filters( 'customize_loaded_components', $this->components, $this );
require_once ABSPATH . GCINC . '/customize/class-gc-customize-selective-refresh.php';
$this->selective_refresh = new GC_Customize_Selective_Refresh( $this );
if ( in_array( 'widgets', $components, true ) ) {
require_once ABSPATH . GCINC . '/class-gc-customize-widgets.php';
$this->widgets = new GC_Customize_Widgets( $this );
}
if ( in_array( 'nav_menus', $components, true ) ) {
require_once ABSPATH . GCINC . '/class-gc-customize-nav-menus.php';
$this->nav_menus = new GC_Customize_Nav_Menus( $this );
}
add_action( 'setup_theme', array( $this, 'setup_theme' ) );
add_action( 'gc_loaded', array( $this, 'gc_loaded' ) );
// Do not spawn cron (especially the alternate cron) while running the Customizer.
remove_action( 'init', 'gc_cron' );
// Do not run update checks when rendering the controls.
remove_action( 'admin_init', '_maybe_update_core' );
remove_action( 'admin_init', '_maybe_update_plugins' );
remove_action( 'admin_init', '_maybe_update_themes' );
add_action( 'gc_ajax_customize_save', array( $this, 'save' ) );
add_action( 'gc_ajax_customize_trash', array( $this, 'handle_changeset_trash_request' ) );
add_action( 'gc_ajax_customize_refresh_nonces', array( $this, 'refresh_nonces' ) );
add_action( 'gc_ajax_customize_load_themes', array( $this, 'handle_load_themes_request' ) );
add_filter( 'heartbeat_settings', array( $this, 'add_customize_screen_to_heartbeat_settings' ) );
add_filter( 'heartbeat_received', array( $this, 'check_changeset_lock_with_heartbeat' ), 10, 3 );
add_action( 'gc_ajax_customize_override_changeset_lock', array( $this, 'handle_override_changeset_lock_request' ) );
add_action( 'gc_ajax_customize_dismiss_autosave_or_lock', array( $this, 'handle_dismiss_autosave_or_lock_request' ) );
add_action( 'customize_register', array( $this, 'register_controls' ) );
add_action( 'customize_register', array( $this, 'register_dynamic_settings' ), 11 ); // Allow code to create settings first.
add_action( 'customize_controls_init', array( $this, 'prepare_controls' ) );
add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_control_scripts' ) );
// Render Common, Panel, Section, and Control templates.
add_action( 'customize_controls_print_footer_scripts', array( $this, 'render_panel_templates' ), 1 );
add_action( 'customize_controls_print_footer_scripts', array( $this, 'render_section_templates' ), 1 );
add_action( 'customize_controls_print_footer_scripts', array( $this, 'render_control_templates' ), 1 );
// Export header video settings with the partial response.
add_filter( 'customize_render_partials_response', array( $this, 'export_header_video_settings' ), 10, 3 );
// Export the settings to JS via the _gcCustomizeSettings variable.
add_action( 'customize_controls_print_footer_scripts', array( $this, 'customize_pane_settings' ), 1000 );
// Add theme update notices.
if ( current_user_can( 'install_themes' ) || current_user_can( 'update_themes' ) ) {
require_once ABSPATH . 'gc-admin/includes/update.php';
add_action( 'customize_controls_print_footer_scripts', 'gc_print_admin_notice_templates' );
}
}