Action hook 'customize_register'

in WP Core File wp-includes/theme.php at line 3683

View Source

customize_register

Action Hook
Description
Publishes a snapshot's changes.

Hook Information

File Location wp-includes/theme.php View on GitHub
Hook Type Action
Line Number 3683

Hook Parameters

Type Name Description
string $new_status New post status.
string $old_status Old post status.
WP_Post $changeset_post Changeset post object. function _wp_customize_publish_changeset( $new_status, $old_status, $changeset_post ) { global $wp_customize; $is_publishing_changeset = ( 'customize_changeset' === $changeset_post->post_type && 'publish' === $new_status && 'publish' !== $old_status ); if ( ! $is_publishing_changeset ) { return; } if ( empty( $wp_customize ) ) { require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $changeset_post->post_name, 'settings_previewed' => false, ) ); } if ( ! did_action( 'customize_register' ) ) { /* When running from CLI or Cron, the customize_register action will need to be triggered in order for core, themes, and plugins to register their settings. Normally core will add_action( 'customize_register' ) at priority 10 to register the core settings, and if any themes/plugins also add_action( 'customize_register' ) at the same priority, they will have a $wp_customize with those settings registered since they call add_action() afterward, normally. However, when manually doing the customize_register action after the setup_theme, then the order will be reversed for two actions added at priority 10, resulting in the core settings no longer being available as expected to themes/plugins. So the following manually calls the method that registers the core settings up front before doing the action.

Usage Examples

Basic Usage
<?php
// Hook into customize_register
add_action('customize_register', 'my_custom_function', 10, 3);

function my_custom_function($new_status, $old_status, $changeset_post) {
    // Your custom code here
}

Source Code Context

wp-includes/theme.php:3683 - How this hook is used in WordPress core
<?php
3678  		 */
3679  		remove_action( 'customize_register', array( $wp_customize, 'register_controls' ) );
3680  		$wp_customize->register_controls();
3681  
3682  		/** This filter is documented in wp-includes/class-wp-customize-manager.php */
3683  		do_action( 'customize_register', $wp_customize );
3684  	}
3685  	$wp_customize->_publish_changeset_values( $changeset_post->ID );
3686  
3687  	/*
3688  	 * Trash the changeset post if revisions are not enabled. Unpublished

PHP Documentation

<?php
/**
 * Publishes a snapshot's changes.
 *
 * @since 4.7.0
 * @access private
 *
 * @global WP_Customize_Manager $wp_customize Customizer instance.
 *
 * @param string  $new_status     New post status.
 * @param string  $old_status     Old post status.
 * @param WP_Post $changeset_post Changeset post object.
 */
function _wp_customize_publish_changeset( $new_status, $old_status, $changeset_post ) {
	global $wp_customize;

	$is_publishing_changeset = (
		'customize_changeset' === $changeset_post->post_type
		&&
		'publish' === $new_status
		&&
		'publish' !== $old_status
	);
	if ( ! $is_publishing_changeset ) {
		return;
	}

	if ( empty( $wp_customize ) ) {
		require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
		$wp_customize = new WP_Customize_Manager(
			array(
				'changeset_uuid'     => $changeset_post->post_name,
				'settings_previewed' => false,
			)
		);
	}

	if ( ! did_action( 'customize_register' ) ) {
		/*
		 * When running from CLI or Cron, the customize_register action will need
		 * to be triggered in order for core, themes, and plugins to register their
		 * settings. Normally core will add_action( 'customize_register' ) at
		 * priority 10 to register the core settings, and if any themes/plugins
		 * also add_action( 'customize_register' ) at the same priority, they
		 * will have a $wp_customize with those settings registered since they
		 * call add_action() afterward, normally. However, when manually doing
		 * the customize_register action after the setup_theme, then the order
		 * will be reversed for two actions added at priority 10, resulting in
		 * the core settings no longer being available as expected to themes/plugins.
		 * So the following manually calls the method that registers the core
		 * settings up front before doing the action.
		 */
Quick Info
  • Hook Type: Action
  • Parameters: 3
  • File: wp-includes/theme.php
Related Hooks

Related hooks will be displayed here in future updates.