- Create unique and main Setting or a Page (It will shows on Wordpress Admin sidebar)
add_menu_page()
- Create Sub pages (Child for the above)
add_submenu_page()
- Create a page inside settings menu
add_options_page()
Customizer.php
<?php
/**
* Created by PhpStorm.
* User: sibin
* Date: 12/7/2017
* Time: 6:21 PM
*/
if(class_exists('WP_Customize_Control')){
class WP_Custom_Editor_Control extends WP_Customize_Control{
public function __construct( WP_Customize_Manager $manager, $id, array $args = array() ) {
parent::__construct( $manager, $id, $args );
add_action('customize_controls_enqueue_scripts', function(){
wp_enqueue_script('h4_living_customizer',get_template_directory_uri().'/inc/theme-customizer.js',[], false, true);
});
}
public function render_content() {
?>
<div>
<label for=""><?php echo $this->label?></label>
<textarea class="wp-editor-area" style="display: none;"
type="hidden" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
<?php
wp_editor($this->value(),$this->id,[
'textarea_name' => $this->id,
'textarea_rows' => 5,
]);
?>
</div>
<?php
do_action('admin_footer');
do_action('admin_print_footer_scripts');
}
}
}
add_action('customize_register', 'default_value_for_h4_living');
function default_value_for_h4_living($wp_customize){
/* FOOTER COPYRIGHT */
if(class_exists('WP_Custom_Editor_Control')){
$date_year = date('Y');
$wp_customize->add_setting('footer_copyright',[
'default' => "© $date_year"
]);
$wp_customize->add_section('h4_footer_copyright',[
'title' => __('Footer Credit','h4living'),
'priority' => 40,
'description' => __('Add Footer credit','h4living')
]);
$wp_customize->add_control( new WP_Custom_Editor_Control($wp_customize,'footer_copyright',[
'label' => __('Footer Credit', 'h4living'),
'section' => 'h4_footer_copyright',
'settings' => 'footer_copyright'
]));
}
/* END FOOTER COPYRIGHT */
}
Customizer.js
(function ($) {
wp.customEditor = {
init: function () {
$(window).on('load', function () {
$('textarea.wp-editor-area').each(function () {
var textArea = $(this),
id = textArea.attr('id');
var input = $('[data-customize-setting-link='+id+']'),
editor = tinyMCE.get(id),
setChange,
content;
if (editor) {
editor.on('change',function (ed) {
editor.save();
content = editor.getContent();
clearTimeout(setChange);
setChange = setTimeout(function () {
console.log(input.get(0));
input.val(content).trigger('change')
}, 500)
});
}
textArea.css({
visibility: 'visible'
}).on('keyup', function () {
console.log('HELLO WORLD');
content = textArea.val();
clearTimeout(setChange);
setChange = setTimeout(function () {
input.val(content).trigger('change');
}, 500);
});
});
});
}
};
wp.customEditor.init();
})(jQuery);