type = $args['type']; if ( isset( $args['callback'] )) $this->callback = $args['callback']; if ( isset( $args['wp_customize'] )) $this->wp_customize = $args['wp_customize']; } public function add_panel( $id, $args ) { if ( isset( $this->wp_customize )) { $args = wp_parse_args( $args, array( 'priority' => 30, 'capability' => 'edit_theme_options', 'theme_supports' => '' )); $this->wp_customize->add_panel( $id, $args ); } else { $this->panels[$id] = $args; $this->panels[$id]['href'] = '#' . $id; } } public function add_section( $id, $args ) { if ( isset( $this->wp_customize )) { $args = wp_parse_args( $args, array( 'priority' => 30 )); $this->wp_customize->add_section( $id, $args ); } else $this->sections[$id] = $args; } public function add_control( $id_base, $args = array() ) { if ( isset( $this->section )) $args['section'] = $this->section; if ( isset( $this->wp_customize )) { $this->wp_customize->add_control( new $id_base( $this->wp_customize, $args )); return; } $control = new $id_base( $this, $args ); if ( $this->type === 'widget' ) $control->widget(); else if ( $this->type === 'echo' ) $control->callback(); else if ( $this->type === 'tabs' ) $this->controls[$control->section][] = array( $control, 'callback' ); } public function add_sub_control( $id_base, $args ) { if ( $this->type === 'tabs' ) { $control = new $id_base( $this, $args ); $this->sub_controls[$control->control][$control->control_value][] = array( $control, 'callback' ); } else $this->add_control( $id_base, $args ); } public function add_setting( $id, $args ) { $this->settings[$id] = $args; } public function get_setting() {} public function buildTabs() { foreach( $this->panels as $id => $args ) echo '
  • ' . esc_html( $args['title'] ) . '
  • '; } public function buildSubTabs( $panel ) { foreach( $this->sections as $id => $args ) if ( $args['panel'] === $panel ) echo '
  • ' . esc_html( $args['title'] ) . '
  • '; } public function buildContent( $content_id = '' ) { foreach( $this->panels as $id => $args ) { if ( !empty( $content_id ) && isset( $this->panels[$content_id] ) && $content_id !== $id ) continue; echo '
    '; if ( isset( $args['callback'] )) { call_user_func( $args['callback'] ); } else { echo '
    '; echo ''; echo '
    '; echo '
    '; foreach( $this->sections as $k => $args ) { if ( $args['panel'] === $id ) { echo '
    '; foreach( $this->controls[$k] as $callback ) { call_user_func( $callback ); //$this->loop( $callback ); } echo '
    '; } } echo '
    '; } echo '
    '; } } public function loop( $callback = '' ) { if ( isset( $this->sub_controls[$callback[0]->id] )) { foreach( $this->sub_controls[$callback[0]->id] as $value => $controls ) { foreach( $controls as $callback ) { echo '
    '; call_user_func( $callback ); //$this->loop( $callback ); echo '
    '; } } } } }