Skip to content

Instantly share code, notes, and snippets.

@soderlind
Last active September 26, 2017 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soderlind/d24d64cecca2d820fd273decb767b6c7 to your computer and use it in GitHub Desktop.
Save soderlind/d24d64cecca2d820fd273decb767b6c7 to your computer and use it in GitHub Desktop.
Using Customizer Blank Slate with your theme
<?php
/**
* Append the customizer url, in Admin Bar, with the parameters that triggers Customizer Blank Slate.
*
* @author soderlind
* @version 1.0.0
* @param string $url The complete admin area URL including scheme and path.
* @param string $path Path relative to the admin area URL. Blank string if no path is specified.
* @param int|null $blog_id Site ID, or null for the current site.
*/
function add_admin_bar_customizer_blank_slate_url_param( $url, $path, $blog_id ) {
if ( false !== strpos( $path, 'customize.php' ) ) {
$url = add_query_arg( 'customizer_blank_slate' , 'on', $url );
}
return $url;
}
/**
* Append the customizer url, in the Admin Menu (Appearance->Customize), with the parameters
* that triggers Customizer Blank Slate.
*
* @author soderlind
* @version 1.0.0
*/
function add_admin_menu_customizer_blank_slate_url_param() {
global $submenu;
if ( isset( $submenu['themes.php'] ) ) {
$tmp_menu = $submenu['themes.php'];
array_walk_recursive( $tmp_menu, function( &$tmp_menu ) {
if ( false !== strpos( $tmp_menu, 'customize.php' ) ) {
$tmp_menu = add_query_arg( 'customizer_blank_slate' , 'on', $tmp_menu );
}
} );
$submenu['themes.php'] = $tmp_menu;
}
}
<?php
namespace My\Customizer\Theme\Demo;
add_action( 'wp_loaded', function() {
add_action( 'customize_register', __NAMESPACE__ . '\register_blank_slate_ui' );
add_action( 'customize_register', __NAMESPACE__ . '\register_blank_slate_setting' );
/**
* Simple Customizer Demo
*
* TODO: Replace with actual settings
* @param \WP_Customize_Manager $wp_customize
*/
function register_blank_slate_setting( \WP_Customize_Manager $wp_customize ) {
$wp_customize->add_setting( 'etfrtb_site_name', [
'sanitize_callback' => 'sanitize_text_field',
'transport' => 'postMessage',
'capability' => 'manage_options',
'autoload' => false,
] );
}
/**
* TODO: Replace with actual section and control.
*
* @param \WP_Customize_Manager $wp_customize
*/
function register_blank_slate_ui( \WP_Customize_Manager $wp_customize ) {
register_blank_slate_setting( $wp_customize );
$wp_customize->add_section( 'etfrtb-email-designer', [
'title' => 'Test Section',
] );
$wp_customize->add_control( 'etfrtb_site_name', [
'label' => 'Test Label',
'section' => 'etfrtb-email-designer',
] );
}
}, 9 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment