tab.php
166 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The Template for displaying meta-box tabs. |
| 4 | * |
| 5 | * @var array $tabs The tabs. |
| 6 | * @var string $class The CSS Class. |
| 7 | * @var string $meta_box_id The ID of the meta-box. |
| 8 | * @package YITH\PluginFramework\Templates |
| 9 | */ |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
| 12 | |
| 13 | global $post; |
| 14 | $classes = apply_filters( 'yith_plugin_fw_metabox_class', $class, $post ); |
| 15 | $classes = yith_plugin_fw_remove_duplicate_classes( $classes ); |
| 16 | $ul_style = count( $tabs ) <= 1 ? 'display:none;' : ''; |
| 17 | $i = 0; |
| 18 | do_action( 'yit_before_metaboxes_tab' ); |
| 19 | |
| 20 | // Allow style for SVGs. |
| 21 | $label_extra_allowed_tags = array( |
| 22 | 'style' => array( |
| 23 | 'type' => true, |
| 24 | ), |
| 25 | ); |
| 26 | |
| 27 | $label_allowed_tags = array_merge( wp_kses_allowed_html( 'post' ), yith_plugin_fw_kses_allowed_svg_tags(), $label_extra_allowed_tags ); |
| 28 | $label_allowed_tags = apply_filters( 'yith_plugin_fw_metabox_label_allowed_tags', $label_allowed_tags, $meta_box_id ); |
| 29 | |
| 30 | ?> |
| 31 | <div class="yith-plugin-fw metaboxes-tab <?php echo esc_attr( $classes ); ?>"> |
| 32 | <?php do_action( 'yit_before_metaboxes_labels' ); ?> |
| 33 | <ul class="metaboxes-tabs clearfix yith-plugin-fw__tabs" style="<?php echo esc_attr( $ul_style ); ?>" data-tab-additional-active-class="tabs"> |
| 34 | <?php foreach ( $tabs as $key => $_tab ) : ?> |
| 35 | |
| 36 | <?php |
| 37 | if ( empty( $_tab['fields'] ) ) { |
| 38 | continue; |
| 39 | } |
| 40 | $anchor_id = 'yith-plugin-fw-metabox-tab-' . urldecode( $key ) . '-anchor'; |
| 41 | |
| 42 | // Parse deps for the tab visibility. |
| 43 | if ( isset( $_tab['deps'] ) ) { |
| 44 | $_tab['deps']['target-id'] = isset( $_tab['deps']['target-id'] ) ? $_tab['deps']['target-id'] : $anchor_id; |
| 45 | if ( isset( $_tab['deps']['id'] ) && strpos( $_tab['deps']['id'], '_' ) !== 0 ) { |
| 46 | $_tab['deps']['id'] = '_' . $_tab['deps']['id']; |
| 47 | } |
| 48 | if ( isset( $_tab['deps']['ids'] ) && strpos( $_tab['deps']['ids'], '_' ) !== 0 ) { |
| 49 | $_tab['deps']['ids'] = '_' . $_tab['deps']['ids']; |
| 50 | } |
| 51 | |
| 52 | $_tab['deps']['type'] = 'hideme'; |
| 53 | } |
| 54 | |
| 55 | $class = 'yith-plugin-fw__tab'; |
| 56 | if ( ! $i ) { |
| 57 | $class .= ' tabs yith-plugin-fw__tab--active'; |
| 58 | } |
| 59 | $i ++; |
| 60 | ?> |
| 61 | <li id="<?php echo esc_attr( $anchor_id ); ?>" class="<?php echo esc_attr( $class ); ?>" <?php echo yith_field_deps_data( $_tab ); ?>> |
| 62 | <a href="#<?php echo esc_attr( urldecode( $key ) ); ?>" class="yith-plugin-fw__tab__handler"> |
| 63 | <?php echo wp_kses( $_tab['label'], $label_allowed_tags ); ?> |
| 64 | </a> |
| 65 | </li> |
| 66 | <?php endforeach; ?> |
| 67 | </ul> |
| 68 | |
| 69 | <?php do_action( 'yit_after_metaboxes_labels' ); ?> |
| 70 | |
| 71 | <?php |
| 72 | if ( isset( $_tab['label'] ) ) { |
| 73 | do_action( 'yit_before_metabox_option_' . urldecode( $key ) ); |
| 74 | } |
| 75 | ?> |
| 76 | |
| 77 | <?php wp_nonce_field( 'metaboxes-fields-nonce', 'yit_metaboxes_nonce' ); ?> |
| 78 | |
| 79 | <?php foreach ( $tabs as $key => $_tab ) : ?> |
| 80 | <div class="tabs-panel yith-plugin-fw__tab-panel" id="<?php echo esc_attr( urldecode( $key ) ); ?>"> |
| 81 | <?php |
| 82 | if ( empty( $_tab['fields'] ) ) { |
| 83 | continue; |
| 84 | } |
| 85 | |
| 86 | $_tab['fields'] = apply_filters( 'yit_metabox_' . $key . '_tab_fields', $_tab['fields'] ); |
| 87 | ?> |
| 88 | |
| 89 | <?php foreach ( $_tab['fields'] as $id_tab => $field ) : ?> |
| 90 | <?php |
| 91 | $field_name = $field['name']; |
| 92 | $field_name = str_replace( 'yit_metaboxes[', '', $field_name ); |
| 93 | $pos = strpos( $field_name, ']' ); |
| 94 | if ( $pos ) { |
| 95 | $field_name = substr_replace( $field_name, '', $pos, 1 ); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * APPLY_FILTER: yith_plugin_fw_metabox_{meta_box_id}_field_pre_get_value |
| 100 | * Allow filtering values for meta-box fields instead of retrieving them by post_meta(s). |
| 101 | * |
| 102 | * @param mixed|null $value The value to be filtered. Set 'null' to retrieve it by the related post_meta (Default: null). |
| 103 | * @param int $post_id The post ID. |
| 104 | * @param string $field_name The field name. |
| 105 | * @param array $field The field. |
| 106 | * |
| 107 | * @since 3.7.6 |
| 108 | */ |
| 109 | $value = apply_filters( "yith_plugin_fw_metabox_{$meta_box_id}_field_pre_get_value", null, $post->ID, $field_name, $field ); |
| 110 | if ( is_null( $value ) ) { |
| 111 | $value = yit_get_post_meta( $post->ID, $field_name ); |
| 112 | } |
| 113 | |
| 114 | $field['value'] = false === $value ? ( isset( $field['std'] ) ? $field['std'] : '' ) : $value; |
| 115 | $field['checkboxgroup'] = ( 'checkbox' === $field['type'] && isset( $field['checkboxgroup'] ) ) ? ' ' . $field['checkboxgroup'] : ''; |
| 116 | $container_classes = 'the-metabox ' . $field['type'] . $field['checkboxgroup'] . ' clearfix '; |
| 117 | $extra_row_class = isset( $field['extra_row_class'] ) ? $field['extra_row_class'] : ''; |
| 118 | |
| 119 | $container_classes .= empty( $field['label'] ) ? 'no-label' : ''; |
| 120 | $container_classes .= ' ' . $extra_row_class; |
| 121 | |
| 122 | ?> |
| 123 | <div class="<?php echo esc_attr( $container_classes ); ?>"> |
| 124 | <?php |
| 125 | $field_template_path = yith_plugin_fw_get_field_template_path( $field ); |
| 126 | if ( $field_template_path ) { |
| 127 | $display_row = 'hidden' !== $field['type']; |
| 128 | $display_row = isset( $field['yith-display-row'] ) ? ! ! $field['yith-display-row'] : $display_row; |
| 129 | $field['display-field-only'] = in_array( $field['type'], array( 'hidden', 'html', 'sep', 'simple-text', 'title', 'list-table' ), true ); |
| 130 | |
| 131 | if ( $display_row ) { |
| 132 | |
| 133 | $field_row_path = apply_filters( 'yith_plugin_fw_metabox_field_row_template_path', YIT_CORE_PLUGIN_TEMPLATE_PATH . '/metaboxes/field-row.php', $field ); |
| 134 | file_exists( $field_row_path ) && include $field_row_path; |
| 135 | } else { |
| 136 | yith_plugin_fw_get_field( $field, true ); |
| 137 | } |
| 138 | } else { |
| 139 | // Backward compatibility. |
| 140 | $args = apply_filters( |
| 141 | 'yit_fw_metaboxes_type_args', |
| 142 | array( |
| 143 | 'basename' => YIT_CORE_PLUGIN_PATH, |
| 144 | 'path' => '/metaboxes/types/', |
| 145 | 'type' => $field['type'], |
| 146 | 'args' => array( 'args' => $field ), |
| 147 | ) |
| 148 | ); |
| 149 | $basename = $args['basename']; |
| 150 | $field_path = $args['path']; |
| 151 | $field_type = $args['type']; |
| 152 | $field_args = $args['args']; |
| 153 | |
| 154 | yit_plugin_get_template( $basename, $field_path . $field_type . '.php', $field_args ); |
| 155 | } |
| 156 | ?> |
| 157 | </div> |
| 158 | <?php endforeach ?> |
| 159 | </div> |
| 160 | <?php endforeach ?> |
| 161 | </div> |
| 162 | |
| 163 | <?php |
| 164 | |
| 165 | do_action( 'yit_after_metaboxes_tab' ); |
| 166 |