| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; // Exit if accessed directly. |
| 5 |
} |
| 6 |
|
| 7 |
/* |
| 8 |
* Widget [wdk-listing-field-value-prefix], show latest listings in list view |
| 9 |
* atts list: |
| 10 |
* |
| 11 |
* field_id (int) - field id |
| 12 |
* post_id (int) - post_id |
| 13 |
* |
| 14 |
* Layout path : |
| 15 |
* get_template_directory().'/wpdirectorykit/shortcodes/views/shortcode-latest-listings-list.php' |
| 16 |
* WPDIRECTORYKIT_PATH.'shortcodes/views/shortcode-latest-listings-list.php' |
| 17 |
*/ |
| 18 |
|
| 19 |
add_shortcode('wdk-listing-field-value-prefix', 'shortcode_wdk_listing_field_value_prefix'); |
| 20 |
function shortcode_wdk_listing_field_value_prefix($atts, $content){ |
| 21 |
$atts = shortcode_atts(array( |
| 22 |
'id'=>NULL, |
| 23 |
'field_id'=>'', |
| 24 |
'post_id'=>'', |
| 25 |
'enable_html'=>'', |
| 26 |
), $atts); |
| 27 |
$data = array(); |
| 28 |
|
| 29 |
/* settings from atts */ |
| 30 |
$data['settings'] = $atts; |
| 31 |
$data['id_element'] = ''; |
| 32 |
|
| 33 |
/* load css/js */ |
| 34 |
|
| 35 |
$WMVC = &wdk_get_instance(); |
| 36 |
$WMVC->model('listingfield_m'); |
| 37 |
$WMVC->model('listing_m'); |
| 38 |
$WMVC->load_helper('listing'); |
| 39 |
global $wdk_listing_id; |
| 40 |
$post_id = $wdk_listing_id; |
| 41 |
if (!empty($data['settings']['post_id'])) { |
| 42 |
$post_id = $data['settings']['post_id']; |
| 43 |
} |
| 44 |
|
| 45 |
$data['field_value'] = ''; |
| 46 |
$data['field_prefix'] = ''; |
| 47 |
$data['field_suffix'] = ''; |
| 48 |
|
| 49 |
/* Allow only public built-in fields. */ |
| 50 |
$allowed_fields = array( |
| 51 |
'post_title', 'category_id', 'location_id', 'post_content' |
| 52 |
); |
| 53 |
|
| 54 |
$field_id = (string) $data['settings']['field_id']; |
| 55 |
if ( |
| 56 |
!is_numeric($field_id) && |
| 57 |
!in_array($field_id, $allowed_fields, true) |
| 58 |
) { |
| 59 |
return ''; |
| 60 |
} |
| 61 |
|
| 62 |
$post_data = get_post($post_id); |
| 63 |
if ( |
| 64 |
!$post_data || |
| 65 |
$post_data->post_type !== 'wdk-listing' || |
| 66 |
$post_data->post_status !== 'publish' || |
| 67 |
post_password_required($post_data) |
| 68 |
) { |
| 69 |
return ''; |
| 70 |
} |
| 71 |
|
| 72 |
if ( is_numeric($data['settings']['field_id']) && wdk_field_option($data['settings']['field_id'], 'is_visible_frontend') != 1 ) { |
| 73 |
return ''; |
| 74 |
} |
| 75 |
|
| 76 |
if ( |
| 77 |
!wdk_field_value('is_activated', $post_id, false) || !wdk_field_value('is_approved', $post_id,false) |
| 78 |
) { |
| 79 |
return __( 'Listing is not public', 'wpdirectorykit' ); |
| 80 |
} |
| 81 |
|
| 82 |
if(!empty($data['settings']['field_id'])){ |
| 83 |
if(strpos($data['settings']['field_id'],'__') !== FALSE){ |
| 84 |
$data['settings']['field_id'] = substr($data['settings']['field_id'], strpos($data['settings']['field_id'],'__')+2); |
| 85 |
} |
| 86 |
|
| 87 |
$data['field_prefix'] = wdk_field_option ($data['settings']['field_id'], 'prefix'); |
| 88 |
$data['field_suffix'] = wdk_field_option ($data['settings']['field_id'], 'suffix'); |
| 89 |
} |
| 90 |
|
| 91 |
$data['is_edit_mode']= false; |
| 92 |
|
| 93 |
/* return false if no content */ |
| 94 |
if(wdk_field_value($data['settings']['field_id'], $post_id) == '') |
| 95 |
return false; |
| 96 |
|
| 97 |
$data['field_prefix'] = apply_filters( 'wpdirectorykit/listing/field/prefix', $data['field_prefix'], $data['settings']['field_id']); |
| 98 |
|
| 99 |
return wdk_shortcodes_view('shortcode-wdk-listing-field-value-prefix', $data); |
| 100 |
} |
| 101 |
|
| 102 |
?> |