我添加了一个简单的Wordpress Custimizer部分。如果您在页面消失之前单击该部分,或者在页面消失之前停止页面加载(这让我相信它与JavaScript相关),就会显示该部分并呈现控件。我不明白为什么?
UPDATE - The section disappears as soon as the preview loads and the JavaScript for the preview is loaded
以下是上述三个动作的视频:
https://drive.google.com/file/d/16lJqbwCMDUanFlp1C1WsVHcTeyAS6MLu/view下面是负责修改自定义程序的类:
<?php
if ( ! defined( \'ABSPATH\' ) ) {
exit; // Exit if accessed directly
}/**
* Kickstarter Theme Customizer Class (class-kickstater-customizer.php)
*
* @package WordPress
* @subpackage OGZ_Kickstarter
* @since 1.0
* @version 1.0
*/
require_once \'customizer/class-kickstarter-cutomizer-controls.php\';
require_once \'customizer/class-kickstarter-cutomizer-sections.php\';
require_once \'customizer/class-kickstarter-cutomizer-settings.php\';
class Kickstarter_Customizer {
/**
* OGZ Kickstarter Theme Mods
*
* @since 1.0.0
* @var array $theme_mods
*/
private $theme_mods;
/**
* Instance of WordPress core WP_Customize_Manager object
*
* @since 1.0.0
* @var WP_Customize_Manager $customizer
*/
private $customizer;
/**
* Kickstarter customizer controls class
*
* @since 1.0.0
* @var Kickstarter_Customizer_Controls $controls
*/
private $controls;
/**
* Kickstarter customizer sections class
*
* @since 1.0.0
* @var Kickstarter_Customizer_Sections $sections
*/
private $sections;
/**
* Kickstarter customizer settings class
*
* @since 1.0.0
* @var Kickstarter_Customizer_Settings $settings
*/
private $settings;
/**
* Kickstarter_Customizer constructor.
*
* @since 1.0.0
* @param array $theme_mods
*/
public function __construct( $theme_mods ) {
global $wp_customize;
$this->customizer = $wp_customize;
$this->theme_mods = $theme_mods;
$this->settings = new Kickstarter_Customizer_Settings( $this->customizer );
$this->controls = new Kickstarter_Customizer_Controls( $this->customizer );
$this->sections = new Kickstarter_Customizer_Sections( $this->customizer );
}
public function init() {
add_action( \'customize_register\', [ $this, \'kickstarter_customizer\' ] );
}
/**
* Adds Kickstarter theme customizer settings
*
* @since 1.0.0
* @return void
*/
public function kickstarter_customizer() {
$this->settings->init();
$this->sections->init();
$this->controls->init();
}
}
设置类:
<?php
if ( ! defined( \'ABSPATH\' ) ) {
exit; // Exit if accessed directly
}/**
* Kickstarter Theme Customizer Settings Class (class-kickstater-customizer-settings.php)
*
* @package WordPress
* @subpackage OGZ_Kickstarter
* @since 1.0
* @version 1.0
*/
require_once \'settings/boolean/class-kickstarter-boolean-setting.php\';
class Kickstarter_Customizer_Settings {
/**
* WordPress Customize Manager
*
* @var WP_Customize_Manager $customizer
*/
private $customizer;
/**
* Kickstarter_Customizer_Settings constructor.
*
* @param WP_Customize_Manager $customizer
*/
public function __construct( $customizer ) {
$this->customizer = $customizer;
}
/**
* Register the kickstarter theme settings
*
* @since 1.0.0
* @return void
*/
public function init() {
/*
* Theme Settings Section Settings
*/
// Theme Layout Choice
$this->customizer->add_setting( \'kickstarter_theme_layout\', [
\'default\' => 0,
\'sanitize_callback\' => \'absint\',
\'transport\' => \'refresh\'
] );
// Mobile Menu Layout Choice
$this->customizer->add_setting( \'kickstarter_mobile_menu_layout\', [
\'default\' => 0,
\'sanitize_callback\' => \'absint\',
\'transport\' => \'refresh\'
] );
// Header Layout Choice
$this->customizer->add_setting( \'kickstarter_header_layout\', [
\'default\' => 0,
\'sanitize_callback\' => \'absint\',
\'transport\' => \'refresh\'
] );
}
截面类别:
<?php
if ( ! defined( \'ABSPATH\' ) ) {
exit; // Exit if accessed directly
}/**
* Kickstarter Theme Customizer Sections Class (class-kickstater-customizer-sections.php)
*
* @package WordPress
* @subpackage OGZ_Kickstarter
* @since 1.0
* @version 1.0
*/
class Kickstarter_Customizer_Sections {
/**
* WordPress Customize Manager
*
* @var WP_Customize_Manager $customizer
*/
private $customizer;
/**
* Kickstarter_Customizer_Settings constructor.
*
* @param WP_Customize_Manager $customizer
*/
public function __construct( $customizer ) {
$this->customizer = $customizer;
}
/**
* Register the kickstarter customizer sections
*
* @since 1.0.0
* @return void
*/
public function init() {
//Add Kickstarter customizer sections
$this->customizer->add_section( \'kickstarter_theme_settings\', [
\'title\' => __( \'Theme Settings\', \'ogz_kickstarter\' ),
\'priority\' => 1,
] );
}
}
控件类:
<?php
if ( ! defined( \'ABSPATH\' ) ) {
exit; // Exit if accessed directly
}/**
* Kickstarter Theme Customizer Controls Class (class-kickstater-customizer-controls.php)
*
* @package WordPress
* @subpackage OGZ_Kickstarter
* @since 1.0
* @version 1.0
*/
class Kickstarter_Customizer_Controls {
/**
* WordPress Customize Manager
*
* @var WP_Customize_Manager $customizer
*/
private $customizer;
/**
* Kickstarter_Customizer_Settings constructor.
*
* @param WP_Customize_Manager $customizer
*/
public function __construct( $customizer ) {
$this->customizer = $customizer;
}
/**
* Registers the Kickstarter Customizer controls
*
* @since 1.0.0
* @return void
*/
public function init() {
// Theme Layout Select Control
$this->customizer->add_control( \'kickstarter_theme_layout\', [
\'type\' => \'select\',
\'priority\' => 5,
\'section\' => \'kickstarter_theme_settings\',
\'label\' => __( \'Theme Layout Style\', \'ogz_kickstarter\' ),
\'choices\' => [
__( \'Boxed Layout\', \'ogz_kickstarter\' ),
__( \'Full Width Layout\', \'ogz_kickstarter\' ),
],
] );
// Mobile Menu Layout Select Control
$this->customizer->add_control( \'kickstarter_mobile_menu_layout\', [
\'type\' => \'select\',
\'priority\' => 10,
\'section\' => \'kickstarter_theme_settings\', // Required, core or custom.
\'label\' => __( \'Mobile Menu Layout Style\', \'ogz_kickstarter\' ),
\'choices\' => [
__( \'Slide Down\', \'ogz_kickstarter\' ),
__( \'Slide Up\', \'ogz_kickstarter\' ),
__( \'Slide In From Left\', \'ogz_kickstarter\' ),
__( \'Slide In From Right\', \'ogz_kickstarter\' ),
__( \'Off Canvas Menu - Slide In From Left\', \'ogz_kickstarter\' ),
__( \'Off Canvas Menu - Slide In From Right\', \'ogz_kickstarter\' ),
],
] );
// Header Layout Select Control
$this->customizer->add_control( \'kickstarter_header_layout\', [
\'type\' => \'select\',
\'label\' => __( \'Header Layout\', \'ogz_kickstarter\' ),
\'section\' => \'kickstarter_theme_settings\', // Required, core or custom.
\'priority\' => 5,
\'choices\' => [
__( \'Left Logo With Right Side Navigation\', \'ogz_kickstarter\' ),
__( \'Centered Logo With Bottom Navigation\', \'ogz_kickstarter\' ),
__( \'Sidebar Like Header Layout\', \'ogz_kickstarter\' ),
__( \'Half Screen Hero With Bottom Navigation\', \'ogz_kickstarter\' ),
__( \'Full Screen Hero\', \'ogz_kickstarter\' ),
],
] );
}
}
有人有什么想法或建议吗?我很感激。