-
-
Save soderlind/fb6cc3d38ee4364a9cff0f66d3eb85d5 to your computer and use it in GitHub Desktop.
Plugin Customizer, full source at https://github.com/soderlind/plugin-customizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$customize_register_priority = 9; | |
add_action( 'wp_loaded', function() { | |
add_action( 'customize_register', array( $this, 'customizer_plugin_settings' ) ); | |
}, $customize_register_priority ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Parameters sent to the previewer script is: | |
* url The custom permalink to the default template. The last part, newsletter in the exmple below | |
* will translate to newsletter.php in the templates folder. | |
*/ | |
$default_url = array( | |
'url' => home_url( 'plugin-customizer/templates/newsletter/?' . PLUGIN_CUSTOMIZER_PARAM_NAME . '=' . PLUGIN_CUSTOMIZER_PARAM_VALUE ), | |
); | |
/** | |
* Add a template to a section. key = section name, value = url to template. | |
* | |
* The last part, title and content in the exmple below, will translate to title.php | |
* and content.php in the templates folder. | |
*/ | |
$section_urls = array( | |
// 'newsletter_title_section' => home_url( 'plugin-customizer/templates/title/' ), | |
// 'newsletter_content_section' => home_url( 'plugin-customizer/templates/content/' ), | |
); | |
wp_add_inline_script( | |
$handle, | |
sprintf( 'PluginCustomizer.init( %s, %s );', | |
wp_json_encode( $default_url ), | |
wp_json_encode( $section_urls ) | |
), | |
'after' | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function rewrite_rule( $wp_rewrite ) { | |
$new_rules = array( | |
'plugin-customizer/templates/(.*)$' => sprintf( 'index.php?plugin-customizer-template=%s',$wp_rewrite->preg_index( 1 ) ), | |
); | |
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules; | |
return $wp_rewrite->rules; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$customize_register_priority = 9; | |
add_action( 'wp_loaded', function() { | |
add_action( 'customize_register', array( $this, 'customizer_plugin_settings' ) ); | |
}, $customize_register_priority ); | |
/** | |
* Bailout if not called from the plugin menu links. | |
*/ | |
if ( ! isset( $_GET[ PLUGIN_CUSTOMIZER_PARAM_NAME ] ) || PLUGIN_CUSTOMIZER_PARAM_VALUE !== wp_unslash( $_GET[ PLUGIN_CUSTOMIZER_PARAM_NAME ] ) ) { | |
return; | |
} | |
add_action( 'wp_loaded', function() { | |
add_action( 'customize_register', array( $this, 'customizer_plugin_sections' ) ); | |
add_action( 'customize_register', array( $this, 'customizer_plugin_controls' ) ); | |
}, $customize_register_priority ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment