Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/themify-.../includes
File: tbp-maps-pro-integration.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Enable displaying Posts in the Builder Maps Pro addon
[3] Fix | Delete
*
[4] Fix | Delete
* @return array
[5] Fix | Delete
*/
[6] Fix | Delete
function tbp_maps_pro_posts_data_provider( $providers ) {
[7] Fix | Delete
class Maps_Pro_Data_Provider_Posts extends Maps_Pro_Data_Provider {
[8] Fix | Delete
[9] Fix | Delete
function get_id() {
[10] Fix | Delete
return 'posts';
[11] Fix | Delete
}
[12] Fix | Delete
[13] Fix | Delete
function get_label() {
[14] Fix | Delete
return __( 'Posts', 'tbp' );
[15] Fix | Delete
}
[16] Fix | Delete
[17] Fix | Delete
function get_options() {
[18] Fix | Delete
return array(
[19] Fix | Delete
array(
[20] Fix | Delete
'label' => __( 'Custom Field for Address', 'tbp' ),
[21] Fix | Delete
'id' => 'custom_field',
[22] Fix | Delete
'type' => 'autocomplete',
[23] Fix | Delete
'dataset' => 'custom_fields',
[24] Fix | Delete
'help' => __( 'Name of the custom field that will be used as the location for marker. Accepts both human-readable address and Lat/Lng values.', 'tbp' ),
[25] Fix | Delete
),
[26] Fix | Delete
array(
[27] Fix | Delete
'type' => 'query_posts',
[28] Fix | Delete
'id' => 'post_type_post',
[29] Fix | Delete
'tax_id' => 'tax',
[30] Fix | Delete
'term_id' => 'tax_category',
[31] Fix | Delete
'slug_id' => 'post_slug',
[32] Fix | Delete
),
[33] Fix | Delete
array(
[34] Fix | Delete
'id' => 'per_page',
[35] Fix | Delete
'type' => 'number',
[36] Fix | Delete
'label' => __( 'Posts Per Page', 'tbp' ),
[37] Fix | Delete
'help' => __( 'Enter the number of post to display.', 'tbp' )
[38] Fix | Delete
),
[39] Fix | Delete
array(
[40] Fix | Delete
'id' => 'order',
[41] Fix | Delete
'type' => 'select',
[42] Fix | Delete
'label' => __( 'Order', 'tbp' ),
[43] Fix | Delete
'help' => __( 'Descending = show newer posts first', 'tbp' ),
[44] Fix | Delete
'order' =>true
[45] Fix | Delete
),
[46] Fix | Delete
array(
[47] Fix | Delete
'id' => 'orderby',
[48] Fix | Delete
'type' => 'select',
[49] Fix | Delete
'label' => __( 'Order By', 'tbp' ),
[50] Fix | Delete
'options' => array(
[51] Fix | Delete
'date' => __( 'Date', 'tbp' ),
[52] Fix | Delete
'ID' => __( 'ID', 'tbp' ),
[53] Fix | Delete
'author' => __( 'Author', 'tbp' ),
[54] Fix | Delete
'title' => __( 'Title', 'tbp' ),
[55] Fix | Delete
'name' => __( 'Name', 'tbp' ),
[56] Fix | Delete
'modified' => __( 'Modified', 'tbp' ),
[57] Fix | Delete
'rand' => __( 'Random', 'tbp' ),
[58] Fix | Delete
'comment_count' => __( 'Comment Count', 'tbp' )
[59] Fix | Delete
)
[60] Fix | Delete
),
[61] Fix | Delete
array(
[62] Fix | Delete
'id' => 'offset',
[63] Fix | Delete
'type' => 'number',
[64] Fix | Delete
'label' => __( 'Offset', 'tbp' ),
[65] Fix | Delete
'help' => __( 'Enter the number of post to displace or pass over.', 'tbp' )
[66] Fix | Delete
),
[67] Fix | Delete
array(
[68] Fix | Delete
'label' => __( 'PTB Map field', 'tbp' ),
[69] Fix | Delete
'id' => 'ptb_map_field',
[70] Fix | Delete
'type' => 'select',
[71] Fix | Delete
'dataset' => 'ptb_map_fields', // "tb_select_dataset_ptb_map_fields" filter will populate this field
[72] Fix | Delete
'wrap_class' => function_exists( 'run_ptb' ) ? '' : 'tb_hide',
[73] Fix | Delete
'help' => sprintf( __( 'Select the field that will be used as the location for marker. Requires <a href="%s">PTB Extra Fields</a> addon.', 'tbp' ), 'https://themify.me/ptb-addons/extra-fields' ),
[74] Fix | Delete
'binding' => array(
[75] Fix | Delete
'empty' => array( 'show' => array( 'custom_field' ) ),
[76] Fix | Delete
'not_empty' => array( 'hide' => array( 'custom_field' ) ),
[77] Fix | Delete
),
[78] Fix | Delete
),
[79] Fix | Delete
array(
[80] Fix | Delete
'id' => 'marker_icon',
[81] Fix | Delete
'type' => 'image',
[82] Fix | Delete
'label' => __('Icon', 'tbp')
[83] Fix | Delete
),
[84] Fix | Delete
);
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
function get_items( $settings ) {
[88] Fix | Delete
global $post;
[89] Fix | Delete
[90] Fix | Delete
$settings = wp_parse_args( $settings, array(
[91] Fix | Delete
'per_page' => 5,
[92] Fix | Delete
'custom_field' => '',
[93] Fix | Delete
'ptb_map_field' => '',
[94] Fix | Delete
'marker_icon' => '',
[95] Fix | Delete
'post_type_post' => 'post',
[96] Fix | Delete
'term_type' => 'category',
[97] Fix | Delete
'tax' => 'category',
[98] Fix | Delete
'post_slug' => '',
[99] Fix | Delete
'offset' => '',
[100] Fix | Delete
'order' => 'desc',
[101] Fix | Delete
'orderby' => 'date',
[102] Fix | Delete
) );
[103] Fix | Delete
$args = array(
[104] Fix | Delete
'post_status' => 'publish',
[105] Fix | Delete
'post_type' => $settings['post_type_post'],
[106] Fix | Delete
'posts_per_page' => $settings['per_page'],
[107] Fix | Delete
'order' => $settings['order'],
[108] Fix | Delete
'orderby' => $settings['orderby'],
[109] Fix | Delete
'no_found_rows'=>true,
[110] Fix | Delete
'ignore_sticky_posts'=>true,
[111] Fix | Delete
'suppress_filters' => false,
[112] Fix | Delete
'offset' => $settings['offset'],
[113] Fix | Delete
);
[114] Fix | Delete
if ( $settings['term_type'] === 'post_slug' ) {
[115] Fix | Delete
if ( $settings['post_slug'] !== '' ) {
[116] Fix | Delete
$args['post__in'] = Themify_Builder_Model::parse_slug_to_ids( $settings['post_slug'], $args['post_type'] );
[117] Fix | Delete
}
[118] Fix | Delete
} else {
[119] Fix | Delete
$terms = isset( $settings[ "tax_{$settings['tax']}" ] ) ? $settings[ "tax_{$settings['tax']}" ] : ( isset( $settings['tax_category'] ) ? $settings['tax_category'] : false );
[120] Fix | Delete
if ( $terms === false ) {
[121] Fix | Delete
return;
[122] Fix | Delete
}
[123] Fix | Delete
// deal with how category fields are saved
[124] Fix | Delete
$terms = preg_replace('/\|[multiple|single]*$/', '', $terms);
[125] Fix | Delete
[126] Fix | Delete
$temp_terms = explode(',', $terms);
[127] Fix | Delete
$new_terms = array();
[128] Fix | Delete
$is_string = false;
[129] Fix | Delete
foreach ( $temp_terms as $t ) {
[130] Fix | Delete
if ( ! is_numeric( $t ) ) {
[131] Fix | Delete
$is_string = true;
[132] Fix | Delete
}
[133] Fix | Delete
if ( '' !== $t ) {
[134] Fix | Delete
array_push( $new_terms, trim( $t ) );
[135] Fix | Delete
}
[136] Fix | Delete
}
[137] Fix | Delete
if ( ! empty( $new_terms ) && ! in_array( '0', $new_terms ) ) {
[138] Fix | Delete
$args['tax_query'] = array(
[139] Fix | Delete
array(
[140] Fix | Delete
'taxonomy' => $settings['tax'],
[141] Fix | Delete
'field' => $is_string ? 'slug' : 'id',
[142] Fix | Delete
'terms' => $new_terms,
[143] Fix | Delete
'operator' => ( '-' === substr( $terms, 0, 1 ) ) ? 'NOT IN' : 'IN'
[144] Fix | Delete
)
[145] Fix | Delete
);
[146] Fix | Delete
}
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
$query = new WP_Query( apply_filters( 'tb_maps_pro_query', $args, $settings ) );
[150] Fix | Delete
if ( is_object( $post ) ){
[151] Fix | Delete
$saved_post = clone $post;
[152] Fix | Delete
}
[153] Fix | Delete
$items = array();
[154] Fix | Delete
while ( $query->have_posts() ) {
[155] Fix | Delete
$query->the_post();
[156] Fix | Delete
[157] Fix | Delete
$item = $this->get_item( $settings );
[158] Fix | Delete
if ( ! empty( $item ) ) {
[159] Fix | Delete
$items[] = $item;
[160] Fix | Delete
}
[161] Fix | Delete
}
[162] Fix | Delete
if ( isset( $saved_post ) && is_object( $saved_post ) ) {
[163] Fix | Delete
$post = $saved_post;
[164] Fix | Delete
setup_postdata( $saved_post );
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
return $items;
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
function get_item( $settings ) {
[171] Fix | Delete
if ( ! empty ( $settings['ptb_map_field'] ) ) {
[172] Fix | Delete
$meta_key = explode( ':', $settings['ptb_map_field']);
[173] Fix | Delete
$meta_key = !empty($meta_key[1]) ? ('ptb_' . $meta_key[1]) : $settings['ptb_map_field'];
[174] Fix | Delete
$address = get_post_meta( get_the_id(), $meta_key, true );
[175] Fix | Delete
if ( is_array( $address ) ) {
[176] Fix | Delete
$address = json_decode( $address['place'], true );
[177] Fix | Delete
$address = $address['location']['lat'] . ', ' . $address['location']['lng'];
[178] Fix | Delete
}
[179] Fix | Delete
} else {
[180] Fix | Delete
$address = get_post_meta( get_the_id(), $settings['custom_field'], true );
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
// skip posts that don't have the designated "address" meta field
[184] Fix | Delete
if ( ! $address ) {
[185] Fix | Delete
return false;
[186] Fix | Delete
}
[187] Fix | Delete
$text = sprintf(
[188] Fix | Delete
'
[189] Fix | Delete
<div style="float: left; margin-right: 10px;">
[190] Fix | Delete
<a href="%2$s">
[191] Fix | Delete
<img src="%1$s" alt="%3$s" />
[192] Fix | Delete
</a>
[193] Fix | Delete
</div>
[194] Fix | Delete
<div>
[195] Fix | Delete
<a href="%2$s"><strong>%3$s</strong></a>
[196] Fix | Delete
</div>
[197] Fix | Delete
<div>
[198] Fix | Delete
%4$s
[199] Fix | Delete
</div>',
[200] Fix | Delete
esc_attr( get_the_post_thumbnail_url( get_the_id(), 'thumbnail' ) ),
[201] Fix | Delete
esc_attr( get_permalink() ),
[202] Fix | Delete
esc_html( get_the_title() ),
[203] Fix | Delete
esc_html( get_the_excerpt() )
[204] Fix | Delete
);
[205] Fix | Delete
return array(
[206] Fix | Delete
'title' => $text,
[207] Fix | Delete
'image' => $settings['marker_icon'],
[208] Fix | Delete
'address' => $address,
[209] Fix | Delete
);
[210] Fix | Delete
}
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
$providers['posts'] = 'Maps_Pro_Data_Provider_Posts';
[214] Fix | Delete
return $providers;
[215] Fix | Delete
}
[216] Fix | Delete
add_filter( 'tb_maps_pro_data_providers', 'tbp_maps_pro_posts_data_provider' );
[217] Fix | Delete
[218] Fix | Delete
[219] Fix | Delete
/**
[220] Fix | Delete
* Handles filling dynamic values for the "ptb_map_field" option in Maps Pro
[221] Fix | Delete
*
[222] Fix | Delete
* @return array
[223] Fix | Delete
*/
[224] Fix | Delete
function tbp_maps_pro_posts_map_fields( $values ) {
[225] Fix | Delete
return array(
[226] Fix | Delete
'options' => array_merge(
[227] Fix | Delete
array( '' => '' ),
[228] Fix | Delete
Tbp_Utils::get_ptb_fields_by_type( 'map' )
[229] Fix | Delete
),
[230] Fix | Delete
);
[231] Fix | Delete
}
[232] Fix | Delete
add_filter( 'tb_select_dataset_ptb_map_fields', 'tbp_maps_pro_posts_map_fields' );
[233] Fix | Delete
[234] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function