tab.php
117 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This file belongs to the YIT Plugin Framework. |
| 4 | * This source file is subject to the GNU GENERAL PUBLIC LICENSE (GPL 3.0) |
| 5 | * that is bundled with this package in the file LICENSE.txt. |
| 6 | * It is also available through the world-wide-web at this URL: |
| 7 | * http://www.gnu.org/licenses/gpl-3.0.txt |
| 8 | * |
| 9 | * @var array $tabs |
| 10 | * @var string $class |
| 11 | */ |
| 12 | |
| 13 | if ( !defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } // Exit if accessed directly |
| 16 | |
| 17 | global $post; |
| 18 | $classes = apply_filters( 'yith_plugin_fw_metabox_class', $class, $post ); |
| 19 | $classes = yith_plugin_fw_remove_duplicate_classes( $classes ); |
| 20 | |
| 21 | do_action( 'yit_before_metaboxes_tab' ) ?> |
| 22 | <div class="yith-plugin-fw metaboxes-tab <?php echo esc_attr( $classes ) ?>"> |
| 23 | <?php do_action( 'yit_before_metaboxes_labels' ) ?> |
| 24 | <ul class="metaboxes-tabs clearfix"<?php if ( count( $tabs ) <= 1 ) : ?> style="display:none;"<?php endif; ?>> |
| 25 | <?php |
| 26 | $i = 0; |
| 27 | foreach ( $tabs as $key => $tab ) : |
| 28 | if ( !isset( $tab[ 'fields' ] ) || empty( $tab[ 'fields' ] ) ) { |
| 29 | continue; |
| 30 | } |
| 31 | $anchor_id = 'yith-plugin-fw-metabox-tab-' . urldecode( $key ) . '-anchor'; |
| 32 | |
| 33 | // parse deps for the tab visibility |
| 34 | if ( isset( $tab[ 'deps' ] ) ) { |
| 35 | $tab[ 'deps' ][ 'target-id' ] = isset( $tab[ 'deps' ][ 'target-id' ] ) ? $tab[ 'deps' ][ 'target-id' ] : $anchor_id; |
| 36 | if ( isset( $tab[ 'deps' ][ 'id' ] ) && strpos( $tab[ 'deps' ][ 'id' ], '_' ) !== 0 ) |
| 37 | $tab[ 'deps' ][ 'id' ] = '_' . $tab[ 'deps' ][ 'id' ]; |
| 38 | if ( isset( $tab[ 'deps' ][ 'ids' ] ) && strpos( $tab[ 'deps' ][ 'ids' ], '_' ) !== 0 ) |
| 39 | $tab[ 'deps' ][ 'ids' ] = '_' . $tab[ 'deps' ][ 'ids' ]; |
| 40 | |
| 41 | $tab[ 'deps' ][ 'type' ] = 'hideme'; |
| 42 | } |
| 43 | ?> |
| 44 | <li id="<?php echo $anchor_id ?>" <?php if ( !$i ) : ?>class="tabs"<?php endif ?> <?php echo yith_field_deps_data( $tab ); ?>> |
| 45 | <a href="#<?php echo urldecode( $key ) ?>"><?php echo $tab[ 'label' ] ?></a></li><?php |
| 46 | $i++; |
| 47 | endforeach; |
| 48 | ?> |
| 49 | </ul> |
| 50 | <?php do_action( 'yit_after_metaboxes_labels' ) ?> |
| 51 | <?php if ( isset( $tab[ 'label' ] ) ) : ?> |
| 52 | <?php do_action( 'yit_before_metabox_option_' . urldecode( $key ) ); ?> |
| 53 | <?php endif ?> |
| 54 | |
| 55 | <?php |
| 56 | // Use nonce for verification |
| 57 | wp_nonce_field( 'metaboxes-fields-nonce', 'yit_metaboxes_nonce' ); |
| 58 | ?> |
| 59 | <?php foreach ( $tabs as $key => $tab ) : |
| 60 | |
| 61 | ?> |
| 62 | <div class="tabs-panel" id="<?php echo urldecode( $key ) ?>"> |
| 63 | <?php |
| 64 | if ( !isset( $tab[ 'fields' ] ) ) { |
| 65 | continue; |
| 66 | } |
| 67 | |
| 68 | $tab[ 'fields' ] = apply_filters( 'yit_metabox_' . $key . '_tab_fields', $tab[ 'fields' ] ); |
| 69 | |
| 70 | foreach ( $tab[ 'fields' ] as $id_tab => $field ) : |
| 71 | $field_name = $field[ 'name' ]; |
| 72 | $field_name = str_replace( 'yit_metaboxes[', '', $field_name ); |
| 73 | if ( $pos = strpos( $field_name, ']' ) ) { |
| 74 | $field_name = substr_replace( $field_name, '', $pos, 1 ); |
| 75 | } |
| 76 | $value = yit_get_post_meta( $post->ID, $field_name ); |
| 77 | $field['value'] = false === $value ? ( isset( $field['std'] ) ? $field['std'] : '' ) : $value; |
| 78 | $field['checkboxgroup'] = ( $field['type'] == 'checkbox' && isset( $field['checkboxgroup'] ) ) ? " " . $field['checkboxgroup'] : ""; |
| 79 | $container_classes = "the-metabox " . $field['type'] . $field['checkboxgroup'] . " clearfix "; |
| 80 | $container_classes .= empty( $field['label'] ) ? 'no-label' : ''; |
| 81 | |
| 82 | ?> |
| 83 | <div class="<?php echo $container_classes ?>"> |
| 84 | <?php |
| 85 | if ( $field_template_path = yith_plugin_fw_get_field_template_path( $field ) ) { |
| 86 | $display_row = 'hidden' !== $field[ 'type' ]; |
| 87 | $display_row = isset( $field[ 'yith-display-row' ] ) ? !!$field[ 'yith-display-row' ] : $display_row; |
| 88 | $field[ 'display-field-only' ] = in_array( $field[ 'type' ], array( 'hidden', 'html', 'sep', 'simple-text', 'title', 'list-table' ) ); |
| 89 | |
| 90 | if ( $display_row ) { |
| 91 | |
| 92 | $field_row_path = apply_filters( 'yith_plugin_fw_metabox_field_row_template_path', YIT_CORE_PLUGIN_TEMPLATE_PATH . '/metaboxes/field-row.php', $field ); |
| 93 | file_exists( $field_row_path ) && include( $field_row_path ); |
| 94 | } else { |
| 95 | |
| 96 | yith_plugin_fw_get_field( $field, true ); |
| 97 | } |
| 98 | } else { |
| 99 | // backward compatibility |
| 100 | $args = apply_filters( 'yit_fw_metaboxes_type_args', array( |
| 101 | 'basename' => YIT_CORE_PLUGIN_PATH, |
| 102 | 'path' => '/metaboxes/types/', |
| 103 | 'type' => $field[ 'type' ], |
| 104 | 'args' => array( 'args' => $field ) |
| 105 | ) |
| 106 | ); |
| 107 | extract( $args ); |
| 108 | yit_plugin_get_template( $basename, $path . $type . '.php', $args ); |
| 109 | } |
| 110 | ?> |
| 111 | </div> |
| 112 | <?php endforeach ?> |
| 113 | </div> |
| 114 | <?php endforeach ?> |
| 115 | </div> |
| 116 | |
| 117 | <?php do_action( 'yit_after_metaboxes_tab' ); |