PluginProbe
WP Directory Kit / trunk
WP Directory Kit vtrunk
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 All 37 releases
wpdirectorykit / shortcodes / shortcode-wdk-listing-fields-section.php

shortcode-wdk-listing-fields-section.php in WP Directory Kit trunk, at shortcodes/shortcode-wdk-listing-fields-section.php

116 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 /*
8 * Widget [wdk-listing-fields-section], show latest listings in list view
9 * atts list:
10 *
11 * section_id (int) - section id
12 * post_id (int) - post_id
13 * field_label_hide (string) - yes|no, default no, hide labels
14 * field_group_icon_enable (string) - yes|no, default yes, show labels
15 * label_suffix (string) - text after label, can be ":"
16 * label_prefix (string) - text before label, can be ":"
17 * hide_onempty_complete (string) - yes|no, default yes, hide section if all fields empty
18 * custom_class (string) - custom css class
19 *
20 * Layout path :
21 * get_template_directory().'/wpdirectorykit/shortcodes/views/shortcode-wdk-listing-fields-section.php'
22 * WPDIRECTORYKIT_PATH.'shortcodes/views/shortcode-wdk-listing-fields-section.php'
23 */
24
25 add_shortcode('wdk-listing-fields-section', 'shortcode_wdk_listing_fields_section');
26 function shortcode_wdk_listing_fields_section($atts, $content){
27 $atts = shortcode_atts(array(
28 'id'=>NULL,
29 'section_id'=>'',
30 'post_id'=>'',
31 'field_label_hide'=>'',
32 'label_suffix'=>':',
33 'label_prefix'=>'',
34 'field_group_icon_enable'=>'no',
35 'hide_onempty_complete'=>'yes',
36 'custom_class'=>'',
37 ), $atts);
38 $data = array();
39
40 /* settings from atts */
41 $data['settings'] = $atts;
42 $data['id_element'] = '';
43
44 /* load css/js */
45
46 $WMVC = &wdk_get_instance();
47 $WMVC->model('listingfield_m');
48 $WMVC->model('field_m');
49 $WMVC->model('listing_m');
50 $WMVC->load_helper('listing');
51
52 global $wdk_listing_id;
53 $post_id = $wdk_listing_id;
54 if (!empty($data['settings']['post_id'])) {
55 $post_id = (int)$data['settings']['post_id'];
56 }
57
58 $data['post_id'] = $post_id;
59
60 $data['section_label'] = 'Example Section';
61 $data['sections_data'] = $WMVC->field_m->get_fields_section();
62 $data['section_data'] = array();
63
64 if(!empty($data['settings']['section_id'])){
65 $data['section_label'] = wdk_field_label($data['settings']['section_id']);
66 if(isset($data['sections_data'][$data['settings']['section_id']]))
67 $data['section_data'] = $data['sections_data'][$data['settings']['section_id']];
68 }
69
70
71 $post_data = get_post($post_id);
72 if (
73 !$post_data ||
74 $post_data->post_type !== 'wdk-listing' ||
75 $post_data->post_status !== 'publish' ||
76 post_password_required($post_data)
77 ) {
78 return '';
79 }
80
81 if (
82 !wdk_field_value('is_activated', $post_id, false) || !wdk_field_value('is_approved', $post_id,false)
83 ) {
84 return __( 'Listing is not public', 'wpdirectorykit' );
85 }
86
87 if(!empty($data['settings']['field_id']))
88 $data['field_label'] = wdk_field_label($data['settings']['field_id']);
89
90 if(empty($data['section_data'])){
91 return false;
92 }
93
94 /* return false if no content */
95 if($data['settings']['hide_onempty_complete'] == 'yes') {
96 $complete_empty = true;
97 foreach($data['section_data']['fields'] as $field) {
98
99 if(wdk_field_value('category_id', $post_id) && wdk_depend_is_hidden_field(wmvc_show_data('idfield', $field), wdk_field_value('category_id', $post_id))) {
100 continue;
101 }
102
103 if(!empty(wdk_field_value (wmvc_show_data('idfield', $field), $post_id))){
104 $complete_empty = false;
105 break;
106 }
107 }
108
109 if($complete_empty)
110 return false;
111 }
112
113 return wdk_shortcodes_view('shortcode-wdk-listing-fields-section', $data);
114 }
115
116 ?>