| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | if ( ! defined( 'ABSPATH' ) ) { |
| 14: | exit; |
| 15: | } |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | function epl_shortcode_listing_meta_doc_callback( $atts ) { |
| 29: | |
| 30: | $atts = shortcode_atts( |
| 31: | array( |
| 32: | 'post_type' => '', |
| 33: | ), |
| 34: | $atts |
| 35: | ); |
| 36: | |
| 37: | $meta_boxes = epl_get_meta_boxes(); |
| 38: | ob_start(); |
| 39: | ?> |
| 40: | <style> |
| 41: | ul.striped-list { |
| 42: | list-style-type: none; |
| 43: | margin: 0; |
| 44: | padding: 0; |
| 45: | } |
| 46: | ul.striped-list > li:nth-of-type(odd) { |
| 47: | background-color: rgba(78, 168, 234, 0.1) ; |
| 48: | } |
| 49: | ul.striped-list > li { |
| 50: | border-bottom: 1px solid rgb(221,221,221); |
| 51: | padding: 6px; |
| 52: | } |
| 53: | ul.striped-list > li:last-child { |
| 54: | border-bottom: none; |
| 55: | } |
| 56: | .epl-meta-opt-list { |
| 57: | margin-left: 35px !important; |
| 58: | } |
| 59: | </style> |
| 60: | <?php |
| 61: | if ( ! empty( $meta_boxes ) ) { |
| 62: | foreach ( $meta_boxes as $epl_meta_box ) { |
| 63: | |
| 64: | $epl_meta_box['post_type'] = (array) $epl_meta_box['post_type']; |
| 65: | |
| 66: | if ( ! empty( $atts['post_type'] ) && ! in_array( $atts['post_type'], $epl_meta_box['post_type'], true ) ) { |
| 67: | continue; |
| 68: | } |
| 69: | |
| 70: | |
| 71: | echo '<h4>' . esc_html( $epl_meta_box['label'] ) . '</h4>'; |
| 72: | |
| 73: | if ( ! empty( $epl_meta_box['groups'] ) ) { |
| 74: | foreach ( $epl_meta_box['groups'] as $group ) { |
| 75: | |
| 76: | echo '<div class="epl-meta-group-wrap">'; |
| 77: | |
| 78: | |
| 79: | if ( ! empty( $group['label'] ) ) { |
| 80: | echo '<h4>' . esc_html( $group['label'] ) . '</h4>'; |
| 81: | } |
| 82: | |
| 83: | $fields = $group['fields']; |
| 84: | $fields = array_filter( $fields ); |
| 85: | if ( ! empty( $fields ) ) { |
| 86: | |
| 87: | echo '<ul class="striped-list epl-meta-fields-list">'; |
| 88: | |
| 89: | foreach ( $fields as $field ) { |
| 90: | |
| 91: | if ( isset( $field['exclude'] ) && ! empty( $field['exclude'] ) ) { |
| 92: | if ( ! empty( $atts['post_type'] ) && in_array( $atts['post_type'], $field['exclude'], true ) ) { |
| 93: | continue; |
| 94: | } |
| 95: | } |
| 96: | |
| 97: | if ( isset( $field['include'] ) && ! empty( $field['include'] ) ) { |
| 98: | if ( ! empty( $atts['post_type'] ) && ! in_array( $atts['post_type'], $field['include'], true ) ) { |
| 99: | continue; |
| 100: | } |
| 101: | } |
| 102: | |
| 103: | echo '<li class="epl-meta-field-item">'; |
| 104: | |
| 105: | switch ( $field['type'] ) { |
| 106: | |
| 107: | case 'text': |
| 108: | echo '<strong>' . esc_attr( $field['name'] ) . '</strong><span class="epl-meta-sep"> :: </span>' . esc_attr( $field['type'] ); |
| 109: | break; |
| 110: | |
| 111: | case 'checkbox_single': |
| 112: | echo '<strong>' . esc_attr( $field['name'] ) . '</strong><span class="epl-meta-sep"> :: </span> "yes" or "no"'; |
| 113: | break; |
| 114: | |
| 115: | case 'select': |
| 116: | echo '<strong>' . esc_attr( $field['name'] ) . '</strong><span class="epl-meta-sep"> :: </span>' . esc_attr( $field['type'] ) . ' (drop down options) '; |
| 117: | |
| 118: | echo '<ul class="epl-meta-opt-list">'; |
| 119: | foreach ( $field['opts'] as $opt_key => $opt_label ) { |
| 120: | $label = is_array( $opt_label ) ? $opt_label['label'] : $opt_label; |
| 121: | echo '<li class="epl-meta-opt-item">'; |
| 122: | echo esc_attr( $label ); |
| 123: | echo '</li>'; |
| 124: | } |
| 125: | echo '</ul>'; |
| 126: | break; |
| 127: | |
| 128: | default: |
| 129: | echo '<strong>' . esc_attr( $field['name'] ) . '</strong><span class="epl-meta-sep"> :: </span>' . esc_attr( $field['type'] ); |
| 130: | break; |
| 131: | } |
| 132: | echo '</li>'; |
| 133: | } |
| 134: | echo '</ul>'; |
| 135: | } |
| 136: | echo '</div><hr>'; |
| 137: | } |
| 138: | } |
| 139: | } |
| 140: | } |
| 141: | return ob_get_clean(); |
| 142: | } |
| 143: | add_shortcode( 'listing_meta_doc', 'epl_shortcode_listing_meta_doc_callback' ); |
| 144: | |