tab.php
217 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 | * |
| 9 | * @package YITH\PluginFramework\Templates |
| 10 | */ |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
| 13 | |
| 14 | global $post; |
| 15 | $classes = apply_filters( 'yith_plugin_fw_metabox_class', $class, $post ); |
| 16 | $classes = yith_plugin_fw_remove_duplicate_classes( $classes ); |
| 17 | $ul_style = count( $tabs ) <= 1 ? 'display:none;' : ''; |
| 18 | $i = 0; |
| 19 | do_action( 'yit_before_metaboxes_tab' ); |
| 20 | |
| 21 | // Allow SVGs. |
| 22 | $label_extra_allowed_tags = array( |
| 23 | 'svg' => array( |
| 24 | 'class' => true, |
| 25 | 'aria-hidden' => true, |
| 26 | 'aria-labelledby' => true, |
| 27 | 'role' => true, |
| 28 | 'xmlns' => true, |
| 29 | 'width' => true, |
| 30 | 'height' => true, |
| 31 | 'viewbox' => true, |
| 32 | 'version' => true, |
| 33 | 'x' => true, |
| 34 | 'y' => true, |
| 35 | 'style' => true, |
| 36 | ), |
| 37 | 'circle' => array( |
| 38 | 'class' => true, |
| 39 | 'cx' => true, |
| 40 | 'cy' => true, |
| 41 | 'r' => true, |
| 42 | ), |
| 43 | 'g' => array( 'fill' => true ), |
| 44 | 'polyline' => array( |
| 45 | 'class' => true, |
| 46 | 'points' => true, |
| 47 | ), |
| 48 | 'polygon' => array( |
| 49 | 'class' => true, |
| 50 | 'points' => true, |
| 51 | ), |
| 52 | 'line' => array( |
| 53 | 'class' => true, |
| 54 | 'x1' => true, |
| 55 | 'x2' => true, |
| 56 | 'y1' => true, |
| 57 | 'y2' => true, |
| 58 | ), |
| 59 | 'title' => array( 'title' => true ), |
| 60 | 'path' => array( |
| 61 | 'class' => true, |
| 62 | 'd' => true, |
| 63 | 'fill' => true, |
| 64 | ), |
| 65 | 'rect' => array( |
| 66 | 'class' => true, |
| 67 | 'x' => true, |
| 68 | 'y' => true, |
| 69 | 'fill' => true, |
| 70 | 'width' => true, |
| 71 | 'height' => true, |
| 72 | ), |
| 73 | 'style' => array( |
| 74 | 'type' => true, |
| 75 | ), |
| 76 | ); |
| 77 | |
| 78 | $label_allowed_tags = array_merge( wp_kses_allowed_html( 'post' ), $label_extra_allowed_tags ); |
| 79 | $label_allowed_tags = apply_filters( 'yith_plugin_fw_metabox_label_allowed_tags', $label_allowed_tags, $meta_box_id ); |
| 80 | |
| 81 | ?> |
| 82 | <div class="yith-plugin-fw metaboxes-tab <?php echo esc_attr( $classes ); ?>"> |
| 83 | <?php do_action( 'yit_before_metaboxes_labels' ); ?> |
| 84 | <ul class="metaboxes-tabs clearfix yith-plugin-fw__tabs" style="<?php echo esc_attr( $ul_style ); ?>" data-tab-additional-active-class="tabs"> |
| 85 | <?php foreach ( $tabs as $key => $_tab ) : ?> |
| 86 | |
| 87 | <?php |
| 88 | if ( empty( $_tab['fields'] ) ) { |
| 89 | continue; |
| 90 | } |
| 91 | $anchor_id = 'yith-plugin-fw-metabox-tab-' . urldecode( $key ) . '-anchor'; |
| 92 | |
| 93 | // Parse deps for the tab visibility. |
| 94 | if ( isset( $_tab['deps'] ) ) { |
| 95 | $_tab['deps']['target-id'] = isset( $_tab['deps']['target-id'] ) ? $_tab['deps']['target-id'] : $anchor_id; |
| 96 | if ( isset( $_tab['deps']['id'] ) && strpos( $_tab['deps']['id'], '_' ) !== 0 ) { |
| 97 | $_tab['deps']['id'] = '_' . $_tab['deps']['id']; |
| 98 | } |
| 99 | if ( isset( $_tab['deps']['ids'] ) && strpos( $_tab['deps']['ids'], '_' ) !== 0 ) { |
| 100 | $_tab['deps']['ids'] = '_' . $_tab['deps']['ids']; |
| 101 | } |
| 102 | |
| 103 | $_tab['deps']['type'] = 'hideme'; |
| 104 | } |
| 105 | |
| 106 | $class = 'yith-plugin-fw__tab'; |
| 107 | if ( ! $i ) { |
| 108 | $class .= ' tabs yith-plugin-fw__tab--active'; |
| 109 | } |
| 110 | $i ++; |
| 111 | ?> |
| 112 | <li id="<?php echo esc_attr( $anchor_id ); ?>" class="<?php echo esc_attr( $class ); ?>" <?php echo yith_field_deps_data( $_tab ); ?>> |
| 113 | <a href="#<?php echo esc_attr( urldecode( $key ) ); ?>" class="yith-plugin-fw__tab__handler"> |
| 114 | <?php echo wp_kses( $_tab['label'], $label_allowed_tags ); ?> |
| 115 | </a> |
| 116 | </li> |
| 117 | <?php endforeach; ?> |
| 118 | </ul> |
| 119 | |
| 120 | <?php do_action( 'yit_after_metaboxes_labels' ); ?> |
| 121 | |
| 122 | <?php |
| 123 | if ( isset( $_tab['label'] ) ) { |
| 124 | do_action( 'yit_before_metabox_option_' . urldecode( $key ) ); |
| 125 | } |
| 126 | ?> |
| 127 | |
| 128 | <?php wp_nonce_field( 'metaboxes-fields-nonce', 'yit_metaboxes_nonce' ); ?> |
| 129 | |
| 130 | <?php foreach ( $tabs as $key => $_tab ) : ?> |
| 131 | <div class="tabs-panel yith-plugin-fw__tab-panel" id="<?php echo esc_attr( urldecode( $key ) ); ?>"> |
| 132 | <?php |
| 133 | if ( empty( $_tab['fields'] ) ) { |
| 134 | continue; |
| 135 | } |
| 136 | |
| 137 | $_tab['fields'] = apply_filters( 'yit_metabox_' . $key . '_tab_fields', $_tab['fields'] ); |
| 138 | ?> |
| 139 | |
| 140 | <?php foreach ( $_tab['fields'] as $id_tab => $field ) : ?> |
| 141 | <?php |
| 142 | $field_name = $field['name']; |
| 143 | $field_name = str_replace( 'yit_metaboxes[', '', $field_name ); |
| 144 | $pos = strpos( $field_name, ']' ); |
| 145 | if ( $pos ) { |
| 146 | $field_name = substr_replace( $field_name, '', $pos, 1 ); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * APPLY_FILTER: yith_plugin_fw_metabox_{meta_box_id}_field_pre_get_value |
| 151 | * Allow filtering values for meta-box fields instead of retrieving them by post_meta(s). |
| 152 | * |
| 153 | * @param mixed|null $value The value to be filtered. Set 'null' to retrieve it by the related post_meta (Default: null). |
| 154 | * @param int $post_id The post ID. |
| 155 | * @param string $field_name The field name. |
| 156 | * @param array $field The field. |
| 157 | * |
| 158 | * @since 3.7.6 |
| 159 | */ |
| 160 | $value = apply_filters( "yith_plugin_fw_metabox_{$meta_box_id}_field_pre_get_value", null, $post->ID, $field_name, $field ); |
| 161 | if ( is_null( $value ) ) { |
| 162 | $value = yit_get_post_meta( $post->ID, $field_name ); |
| 163 | } |
| 164 | |
| 165 | $field['value'] = false === $value ? ( isset( $field['std'] ) ? $field['std'] : '' ) : $value; |
| 166 | $field['checkboxgroup'] = ( 'checkbox' === $field['type'] && isset( $field['checkboxgroup'] ) ) ? ' ' . $field['checkboxgroup'] : ''; |
| 167 | $container_classes = 'the-metabox ' . $field['type'] . $field['checkboxgroup'] . ' clearfix '; |
| 168 | $extra_row_class = isset( $field['extra_row_class'] ) ? $field['extra_row_class'] : ''; |
| 169 | |
| 170 | $container_classes .= empty( $field['label'] ) ? 'no-label' : ''; |
| 171 | $container_classes .= ' ' . $extra_row_class; |
| 172 | |
| 173 | ?> |
| 174 | <div class="<?php echo esc_attr( $container_classes ); ?>"> |
| 175 | <?php |
| 176 | $field_template_path = yith_plugin_fw_get_field_template_path( $field ); |
| 177 | if ( $field_template_path ) { |
| 178 | $display_row = 'hidden' !== $field['type']; |
| 179 | $display_row = isset( $field['yith-display-row'] ) ? ! ! $field['yith-display-row'] : $display_row; |
| 180 | $field['display-field-only'] = in_array( $field['type'], array( 'hidden', 'html', 'sep', 'simple-text', 'title', 'list-table' ), true ); |
| 181 | |
| 182 | if ( $display_row ) { |
| 183 | |
| 184 | $field_row_path = apply_filters( 'yith_plugin_fw_metabox_field_row_template_path', YIT_CORE_PLUGIN_TEMPLATE_PATH . '/metaboxes/field-row.php', $field ); |
| 185 | file_exists( $field_row_path ) && include $field_row_path; |
| 186 | } else { |
| 187 | yith_plugin_fw_get_field( $field, true ); |
| 188 | } |
| 189 | } else { |
| 190 | // Backward compatibility. |
| 191 | $args = apply_filters( |
| 192 | 'yit_fw_metaboxes_type_args', |
| 193 | array( |
| 194 | 'basename' => YIT_CORE_PLUGIN_PATH, |
| 195 | 'path' => '/metaboxes/types/', |
| 196 | 'type' => $field['type'], |
| 197 | 'args' => array( 'args' => $field ), |
| 198 | ) |
| 199 | ); |
| 200 | $basename = $args['basename']; |
| 201 | $field_path = $args['path']; |
| 202 | $field_type = $args['type']; |
| 203 | $field_args = $args['args']; |
| 204 | |
| 205 | yit_plugin_get_template( $basename, $field_path . $field_type . '.php', $field_args ); |
| 206 | } |
| 207 | ?> |
| 208 | </div> |
| 209 | <?php endforeach ?> |
| 210 | </div> |
| 211 | <?php endforeach ?> |
| 212 | </div> |
| 213 | |
| 214 | <?php |
| 215 | |
| 216 | do_action( 'yit_after_metaboxes_tab' ); |
| 217 |