_presets = Presets::get_all(); } /** * Load all field objects and add them to the sections set. * * @since 1.0.0 */ private 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(); } /** * Add theme settings links to the admin bar. * * @since 1.0.0 * * @param object $admin_bar Admin bar object. */ public function admin_bar_links( $admin_bar ) { $admin_bar->add_node( array( 'id' => 'theme-dashboard', 'title' => esc_html__( 'Theme Dashboard', 'woodmart' ), 'href' => admin_url( 'admin.php?page=xtemos_options' ), 'meta' => array( 'title' => esc_html__( 'Theme Dashboard', 'woodmart' ), ), ) ); $admin_bar->add_node( array( 'id' => 'theme-settings', 'title' => esc_html__( 'Theme Settings', 'woodmart' ), 'href' => admin_url( 'admin.php?page=xtemos_options' ), 'parent' => 'theme-dashboard', 'meta' => array( 'title' => esc_html__( 'Theme Settings', 'woodmart' ), ), ) ); $header = whb_get_header(); $hb_url = admin_url( 'admin.php?page=woodmart_dashboard&tab=builder' ); if ( $header && ! is_admin() ) { $header_id = $header->get_id(); $hb_url = admin_url( 'admin.php?page=woodmart_dashboard&tab=builder#/builder/' . $header_id ); } $admin_bar->add_node( array( 'id' => 'header-builder', 'title' => esc_html__( 'Edit header', 'woodmart' ), 'href' => $hb_url, 'parent' => 'theme-dashboard', 'meta' => array( 'title' => esc_html__( 'Edit header', 'woodmart' ), ), ) ); $active_presets = Presets::get_active_presets(); $all_presets = Presets::get_all(); if ( $active_presets ) { $admin_bar->add_node( array( 'id' => 'theme-settings-presets', 'title' => esc_html__( 'Active presets', 'woodmart' ), 'href' => admin_url( 'admin.php?page=xtemos_options' ), 'parent' => 'theme-dashboard', 'meta' => array( 'title' => esc_html__( 'Active presets', 'woodmart' ), ), ) ); foreach ( $active_presets as $preset ) { $name = isset( $all_presets[ $preset ]['name'] ) ? $all_presets[ $preset ]['name'] : 'Preset name'; $admin_bar->add_node( array( 'id' => 'theme-settings-presets-' . $preset, 'title' => $name, 'href' => admin_url( 'admin.php?page=xtemos_options&preset=' . $preset ), 'parent' => 'theme-settings-presets', 'meta' => array( 'title' => $name, ), ) ); } } } /** * Callback to register a page in the dashboard. * * @since 1.0.0 */ public function admin_page() { $this->load_fields(); $logo = WOODMART_ASSETS . '/images/theme-admin-icon.svg'; if ( woodmart_get_opt( 'white_label_sidebar_icon_logo' ) && woodmart_get_opt( 'white_label' ) ) { $image_data = woodmart_get_opt( 'white_label_sidebar_icon_logo' ); if ( isset( $image_data['url'] ) && $image_data['url'] ) { $logo = wp_get_attachment_image_url( $image_data['id'] ); } } // Create admin page. add_menu_page( esc_html__( 'Theme Settings', 'woodmart' ), esc_html__( 'Theme Settings', 'woodmart' ), 'manage_options', 'xtemos_options', array( &$this, 'page_content' ), $logo, 61 ); foreach ( $this->_sections as $key => $section ) { if ( isset( $section['parent'] ) ) { continue; } add_submenu_page( 'xtemos_options', $section['name'], $section['name'], 'manage_options', 'xtemos_options&tab=' . $key, array( &$this, 'page_content' ) ); } remove_submenu_page( 'xtemos_options', 'xtemos_options' ); } /** * Render the options page content. * * @since 1.0.0 */ public function page_content() { $wrapper_classes = ''; if ( isset( $_GET['preset'] ) ) { // phpcs:ignore $wrapper_classes .= ' xts-preset-active'; } ?>

Woodmart

    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']; } 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 ) { ?>

    $field ) { if ( $previus_group && ( ! isset( $field->args['group'] ) || $previus_group !== $field->args['group'] ) ) { echo '
    '; $previus_group = false; } if ( isset( $field->args['group'] ) && $previus_group !== $field->args['group'] ) { $previus_group = $field->args['group']; echo '
    ' . esc_html( $previus_group ) . '
    '; echo '
    '; } if ( $this->is_inherit_field( $field->get_id() ) ) { $field->inherit_value( true ); } $field->render( null, Presets::get_current_preset() ); } if ( $previus_group ) { echo '
    '; $previus_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();