_presets = Presets::get_all(); } /** * Load all field objects and add them to the sections set. * * @since 1.0.0 */ public function load_fields() { $this->_sections = Options::get_sections(); $this->_fields = Options::get_fields(); foreach ( $this->_fields as $key => $field ) { $this->_sections[ $field->args['section'] ]['fields'][] = $field; } $this->_options = Options::get_options(); } /** * Render the options page content. * * @since 1.0.0 */ public function page_content() { wp_enqueue_script( 'woodmart-admin-options', WOODMART_ASSETS . '/js/options.js', array(), WOODMART_VERSION, true ); wp_enqueue_script( 'xts-helpers', WOODMART_SCRIPTS . '/scripts/global/helpers.min.js', array(), WOODMART_VERSION, true ); wp_enqueue_script( 'xts-tabs', WOODMART_SCRIPTS . '/scripts/elements/tabs.js', array(), WOODMART_VERSION, true ); $wrapper_classes = ''; if ( isset( $_GET['preset'] ) ) { // phpcs:ignore $wrapper_classes .= ' xts-preset-active'; } $current_preset_id = Presets::get_current_preset(); $all_presets = Presets::get_all(); if ( $current_preset_id ) { $title = $all_presets[ $current_preset_id ]['name']; } else { $title = esc_html__( 'Theme settings', 'woodmart' ); } $wrapper_classes .= ' xts-builder-' . woodmart_get_current_page_builder(); do_action( 'xts_before_theme_settings' ); if ( isset( $_GET['settings-updated'] ) ) { // phpcs:ignore do_action( 'xts_theme_settings_save' ); } ?>
    display_sections_tree(); ?>
display_message(); ?> display_sections(); ?>
_sections ); $first_tab = key( $this->_sections ); $current_tab = $first_tab; if ( isset( $this->_options['last_tab'] ) && isset( $_GET['settings-updated'] ) ) { $current_tab = $this->_options['last_tab']; } elseif ( isset( $_GET['tab'] ) ) { $current_tab = $_GET['tab']; } if ( ! isset( $this->_sections[ $current_tab ]['fields'] ) ) { $parent_id = $this->_sections[ $current_tab ]['id']; foreach ( $this->_sections as $section ) { if ( ! empty( $section['parent'] ) && $section['parent'] === $parent_id ) { $current_tab = $section['id']; break; } } } return $current_tab; } /** * Display saved/imported message. * * @since 1.0.0 */ private function display_message() { $message = $this->get_last_message(); $text = false; if ( 'save' === $message ) { $text = esc_html__( 'Settings are successfully saved.', 'woodmart' ); } elseif ( 'import' === $message ) { $text = esc_html__( 'New options are successfully imported.', 'woodmart' ); } elseif ( 'reset' === $message ) { $text = esc_html__( 'All options are set to default values.', 'woodmart' ); } if ( $text ) { echo '
' . $text . '
'; // phpcs:ignore } } /** * Get last message. * * @since 1.0.0 */ private function get_last_message() { return ( isset( $this->_options['last_message'] ) && isset( $_GET['settings-updated'] ) ) ? $this->_options['last_message'] : ''; // phpcs:ignore } /** * Display sections navigation tree. * * @since 1.0.0 */ private function display_sections_tree() { $current_tab = $this->get_last_tab(); $active_parent = ''; if ( isset( $this->_sections[ $current_tab ]['parent'] ) ) { $active_parent = $this->_sections[ $current_tab ]['parent']; } foreach ( $this->_sections as $key => $section ) { if ( isset( $section['parent'] ) ) { continue; } $subsections = array_filter( $this->_sections, function( $el ) use ( $section ) { return isset( $el['parent'] ) && $el['parent'] === $section['id']; } ); $classes = ''; if ( $key === $current_tab || $key === $active_parent ) { $classes .= ' xts-active-nav'; } if ( is_array( $subsections ) && count( $subsections ) > 0 ) { $classes .= ' xts-has-child'; } ?>
  • 0 ) : ?>
  • _sections as $key => $section ) { ?>

    args['t_tab'] ) ) { $tabs[ $field->args['t_tab']['id'] ][ $field->args['t_tab']['tab'] ] = [ 'icon' => isset( $field->args['t_tab']['icon'] ) ? $field->args['t_tab']['icon'] : '', 'title' => $field->args['t_tab']['tab'], ]; } } } $printed_tabs = false; $printed_tab = false; $printed_group = false; if ( isset( $section['fields'] ) ) { foreach ( $section['fields'] as $field ) { if ( $printed_tab && ( ! isset( $field->args['t_tab'] ) || $printed_tab !== $field->args['t_tab']['tab'] ) ) { echo '
    '; $printed_tab = false; } if ( $printed_tabs && ( ! isset( $field->args['t_tab'] ) || $printed_tabs !== $field->args['t_tab']['id'] ) ) { echo '
    '; echo ''; $printed_tabs = false; } if ( $printed_group && ( ! isset( $field->args['group'] ) || $printed_group !== $field->args['group'] ) ) { echo ''; $printed_group = false; } if ( isset( $field->args['group'] ) && $printed_group !== $field->args['group'] ) { $printed_group = $field->args['group']; echo '
    ' . esc_html( $printed_group ) . '
    '; echo '
    '; } if ( isset( $field->args['t_tab'] ) && $printed_tabs !== $field->args['t_tab']['id'] ) { $attrs = ''; if ( isset( $field->args['t_tab']['requires'] ) ) { $data = ''; foreach ( $field->args['t_tab']['requires'] as $dependency ) { if ( is_array( $dependency['value'] ) ) { $dependency['value'] = implode( ',', $dependency['value'] ); } $data .= $dependency['key'] . ':' . $dependency['compare'] . ':' . $dependency['value'] . ';'; } $attrs .= 'data-dependency="' . esc_attr( $data ) . '"'; } echo '
    '; echo '
    '; if ( isset( $field->args['t_tab']['title'] ) ) { echo '

    ' . $field->args['t_tab']['title'] . '

    '; } echo '
    '; echo '
      '; foreach ( $tabs[ $field->args['t_tab']['id'] ] as $tab ) { $classes = ''; if ( ! empty( $tab['icon'] ) ) { $classes .= ' ' . $tab['icon']; } echo '
    • ' . $tab['title'] . '
    • '; // phpcs:ignore } echo '
    '; echo '
    '; echo '
    '; echo '
    '; $printed_tabs = $field->args['t_tab']['id']; } if ( isset( $field->args['t_tab'] ) && $printed_tab !== $field->args['t_tab']['tab'] ) { echo '
    '; $printed_tab = $field->args['t_tab']['tab']; } if ( $this->is_inherit_field( $field->get_id() ) ) { $field->inherit_value( true ); } $field->render( null, Presets::get_current_preset() ); } if ( $printed_tab ) { echo '
    '; $printed_tab = false; } if ( $printed_tabs ) { echo '
    '; echo '
    '; $printed_tabs = false; } if ( $printed_group ) { echo '
    '; $printed_group = false; } } ?> _options[ Presets::get_current_preset() ] ) || ! isset( $this->_options[ Presets::get_current_preset() ]['fields_to_save'] ) ) { return ''; } return $this->_options[ Presets::get_current_preset() ]['fields_to_save']; } /** * Is field by id inherits value. * * @since 1.0.0 * * @param int $id Field's id. * * @return bool */ private function is_inherit_field( $id ) { return false === strpos( $this->get_fields_to_save(), $id ); } } Page::get_instance();