Using the Customizer as Plugin Settings Page, Hide default panels
-
In my toying around with WordPress I decided I’d give plugins a try. Everything’s going pretty good, but I’ve run into one hangup.
I was more or less following this: https://www.youtube.com/watch?v=7usuZRBsyk8
(Note: I am not using Woo Commerce as he is)
In an attempt to create a plugin settings page within the customizer.
Basically, in the video he adds a button to a settings page that opens a customizer instance to customize something about his plugin.
My hangup comes with the section where he has us add a query arg to the url…
$url = add_query_arg( 'wc-email-customizer', 'true', $url );
And then says to hide the default customizer settings on THIS page only, not the default customizer paged accessed through the appearance menu… using this code.
add_filter( 'customize_control_active', 'control_filter', 10, 2 ); function control_filter( $active, $control ) { if ( in_array( $control->section, array( 'wc_email_header', 'wc_email_body', 'wc_email_footer', 'wc_email_send' ) ) ){ return true; } return false; }
He states in the video “And what it does, is if you return true, show the control, if you return false, hide the control. So if that flag is present… show it, otherwise hide it.”
The flag he’s talking about is the wc-email-customizer query arg we just added to the url.
However, while experimenting with this, all this function does is hide any sections not in that array all the time, regardless of whether or not wc-email-customizer is present in the url.
Does anyone know what I am missing? Or how to make this work?
My Relevant code:
Main Plugin PHP File
function ezt_plugin_settings_page(){ add_submenu_page( 'edit.php?post_type=ez-testimonial', 'Ez Testimonials Settings', 'Settings', 'manage_options', 'ezt_settings', 'ezt_plugin_settings_callback' ); } add_action( 'admin_menu', 'ezt_plugin_settings_page' ); require_once ( plugin_dir_path(__FILE__) . 'ezt-settings.php' );
ezt-settings.php
function ezt_plugin_settings_callback(){ //Get customizer url $url = admin_url( 'customize.php' ); $url = add_query_arg( 'wc-email-customizer', 'true', $url ); ?> <div class="container-fluid"> <div class="row"> <h2 id="ezt-settings-heading">EZ Testimonials Settings</h2> </div> <div class="row"> <!-- esc url --> <a class="btn btn-default" href="<?php echo $url; ?>">Customize</a> </div> </div> <?php } add_filter( 'customize_control_active', 'control_filter', 10, 2 ); function control_filter( $active, $control ) { if ( in_array( $control->section, array( 'wc_email_header', 'wc_email_body', 'wc_email_footer', 'wc_email_send' ) ) ){ return true; } return false; }
- The topic ‘Using the Customizer as Plugin Settings Page, Hide default panels’ is closed to new replies.