Created
December 12, 2017 22:59
-
-
Save dfinnema/e82368a83fc6f05b4b893f712c462149 to your computer and use it in GitHub Desktop.
xt-facebook-events - Extension No Event Text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Extension for xt-facebook-events | |
* | |
* adds custom text when no events are loaded | |
* | |
*/ | |
function dfc_shortcode_fb_events_hook_shortcode( $atts_o ) { | |
// Lets check if the FB Events Plugin is active, no point otherwise displaying all this | |
if (!function_exists('is_plugin_active')) { | |
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); | |
} | |
if (!is_plugin_active('xt-facebook-events/xt-facebook-events.php')) { | |
return "Sorry an error occurred and no Events could be displayed"; | |
} | |
$event_args = array( | |
'page_id' => '', | |
'max_events' => 10, | |
'new_window' => 1, | |
'type' => 'page', | |
); | |
$atts = wp_parse_args( (array) $atts_o, $event_args ); | |
// Load the Facebook Events Plugin and check if there are any upcoming events | |
$fb = new XT_Facebook_Events_Facebook(); | |
$fb_r = $fb->get_events_for_facebook_page($atts); | |
if ($fb_r == false) { | |
// No upcoming events lets display that | |
return '<p class="text-center">No Upcoming Events</p>'; | |
} else { | |
// Upcoming events found, lets convert the $atts back to shortcode format | |
$instance = $atts_o; | |
$attr_array = array(); | |
if( isset( $instance['max_events'] ) && $instance['max_events'] != '' ){ | |
$attr_array[]= 'max_events ="'.esc_attr( $instance["max_events"] ).'"'; | |
} | |
if( isset( $instance['page_id'] ) && $instance['page_id'] != '' ){ | |
$attr_array[]= 'page_id ="'.esc_attr( $instance["page_id"] ).'"'; | |
} | |
if( isset( $instance['new_window'] ) && $instance['new_window'] != '' ){ | |
$attr_array[]= 'new_window ="1"'; | |
} | |
if(isset( $instance['display_style'] ) && $instance['display_style'] != '' ){ | |
$attr_array[]= 'style = '. esc_attr( $instance['display_style'] ); | |
} | |
if( $instance['display_event_image'] ){ | |
$attr_array[]= 'display_event_image ="1"'; | |
} | |
if( $instance['display_event_location'] ){ | |
$attr_array[]= 'display_event_location ="1"'; | |
} | |
if( $instance['display_event_enddate'] ){ | |
$attr_array[]= 'display_event_enddate ="1"'; | |
} | |
if( $instance['display_event_desc'] ){ | |
$attr_array[]= 'display_event_desc ="1"'; | |
} | |
$attr_str = implode(' ', $attr_array ); | |
// Lets send the data to the plugin to do what it does normally | |
return do_shortcode( '[wpfb_events ' . $attr_str . ']' ); | |
} | |
} | |
add_shortcode( 'dfc_fb_events' , 'dfc_shortcode_fb_events_hook_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment