Skip to content

Instantly share code, notes, and snippets.

@NateWr
Last active October 30, 2019 12:33
Show Gist options
  • Save NateWr/5fd00beb412f78776e9d to your computer and use it in GitHub Desktop.
Save NateWr/5fd00beb412f78776e9d to your computer and use it in GitHub Desktop.
Very simple demonstration of adding placeholder or notice text to the customizer when you want to surface information in the customizer but don't actually need to save data
<?php
/**
* Very simple demonstration of adding placeholder or notice text to the
* customizer when you want to surface information in the customizer but don't
* actually need to save data.
*/
/**
* A dummy control to display placeholder text in the customizer
*
* @see WP_Customize_Control
*/
class Luigi_WP_Customize_Notice_Control extends WP_Customize_Control {
/**
* Control type
*
* @since 0.0.1
*/
public $type = 'notice';
/**
* HTML content to display
*
* @since 0.0.1
*/
public $content = '';
public function render_content() {
if ( !empty( $this->label ) ) : ?>
<div class="customize-control-title">
<?php echo esc_html( $this->label ); ?>
</div>
<?php endif; ?>
<div class="customize-notice-content">
<?php echo $this->content; ?>
</div>
<?php
}
}
/**
* Add a section and control
*
*/
add_action( 'customize_register', 'luigi_customizer_add_controls' );
function luigi_customizer_add_controls( $wp_customize ) {
// In this case, I add a section to surface the custom font features that
// are available if they activate a specific plugin.
if ( !is_plugin_active( 'typecase/typecase.php' ) ) {
$wp_customize->add_section(
'luigi_typecase_placeholder',
array(
'title' => __( 'Theme Fonts', 'luigi' ),
'priority' => 30,
)
);
$wp_customize->add_control(
new Luigi_WP_Customize_Notice_Control(
$wp_customize,
'luigi_typecase_placeholder',
array(
'label' => __( 'Install Typecase', 'luigi' ),
'section' => 'luigi_typecase_placeholder',
'settings' => array(),
'content' => sprintf(
// Translators: 1 and 2 wrap a link to install the plugin. 3 and 4 wrap a link to documentation on this.
__( 'Install and activate the %1$sTypecase plugin%2$s if you would like to change the fonts used on your site. %3$sLearn more%4$s', 'luigi' ),
'<a href="' . esc_url( admin_url( 'plugin-install.php?tab=plugin-information&plugin=typecase' ) ) . '" target="_blank">',
'</a>',
'<a href="http://doc.themeofthecrop.com/themes/luigi/user/faq#typecase" target="_blank">',
'</a>'
),
)
)
);
}
}
@NateWr
Copy link
Author

NateWr commented Mar 29, 2016

Thanks Weston. Updated.

@webd-uk
Copy link

webd-uk commented Oct 30, 2019

The same can be achieved without extending the class ...

            $wp_customize->add_control('luigi_typecase_placeholder', array(
                'label'         => __( 'Install Typecase', 'luigi' ),
                'description'   => sprintf(
						// Translators: 1 and 2 wrap a link to install the plugin. 3 and 4 wrap a link to documentation on this.
						__( 'Install and activate the %1$sTypecase plugin%2$s if you would like to change the fonts used on your site. %3$sLearn more%4$s', 'luigi' ),
						'<a href="' . esc_url( admin_url( 'plugin-install.php?tab=plugin-information&plugin=typecase' ) ) . '" target="_blank">',
						'</a>',
						'<a href="http://doc.themeofthecrop.com/themes/luigi/user/faq#typecase" target="_blank">',
						'</a>'
					),
                'section'       => 'luigi_typecase_placeholder',
                'settings'      => array(),
                'type'          => 'hidden'
            ));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment