Created
October 3, 2017 17:04
-
-
Save wpmudev-sls/c1aed5c8f7bcdf0f9c756c9b9756d09a to your computer and use it in GitHub Desktop.
Recent Global Events shortcode. Requires "Post Indexer" and Events+ plugins. Provides shortcode: `[global_recent_events]` allong with several atts
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 | |
/** | |
* Plugin Name: Recent Global Events | |
* Plugin URI: http://premium.wpmudev.org | |
* Description: Recent Global Evens function and shortcode. Requires "Post Indexer" and Events+ plugins. Provides shortcode: `[global_recent_events]` allong with several atts | |
* Author: Panos Lyrakis @ WPMUDEV | |
* Author URI: http://premium.wpmudev.org | |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
if( ! class_exists( 'WPMUDEV_Recent_Global_Events' ) ){ | |
class WPMUDEV_Recent_Global_Events { | |
var $build = 1; | |
var $db; | |
private static $_instance = null; | |
public static function get_instance() { | |
if( is_null( self::$_instance ) ){ | |
self::$_instance = new WPMUDEV_Recent_Global_Events(); | |
} | |
return self::$_instance; | |
} | |
private function __construct() { | |
global $wpdb; | |
if( ! class_exists('Eab_EventsHub') ){ | |
return; | |
} | |
$this->db =& $wpdb; | |
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_events_front_style' ), 999 ); | |
add_shortcode( 'global_recent_events', array( &$this, 'display_recent_posts_shortcode') ); | |
} | |
public function enqueue_events_front_style(){ | |
global $post; | |
if ( has_shortcode( $post->post_content, 'global_recent_events' ) ){ | |
wp_enqueue_style('eab_front'); | |
} | |
} | |
public function display_recent_posts($tmp_number,$tmp_title_characters = 0,$tmp_content_characters = 0,$tmp_title_content_divider = '<br />',$tmp_title_before,$tmp_title_after,$tmp_global_before,$tmp_global_after,$tmp_before,$tmp_after,$tmp_title_link = 'no',$tmp_show_avatars = 'yes', $tmp_avatar_size = 16, $posttype = 'post', $output = true) { | |
global $network_query, $network_post; | |
$network_query = network_query_posts( array( 'post_type' => $posttype, 'posts_per_page' => $tmp_number )); | |
$html = ''; | |
if( network_have_posts() ) { | |
$html .= $tmp_global_before; | |
$default_avatar = get_option('default_avatar'); | |
while( network_have_posts()) { | |
network_the_post(); | |
$html .= $tmp_before; | |
if ( $tmp_title_characters > 0 ) { | |
$html .= $tmp_title_before; | |
if ( $tmp_show_avatars == 'yes' ) { | |
$the_author = network_get_the_author_id(); | |
$html .= get_avatar( $the_author, $tmp_avatar_size, $default_avatar) . ' '; | |
} | |
$the_title = network_get_the_title(); | |
if ( $tmp_title_link == 'no' ) { | |
$html .= substr($the_title,0,$tmp_title_characters); | |
} | |
else { | |
if( $posttype != 'incsub_event' && class_exists( 'Eab_Template' ) ){ | |
$html .= '<a href="' . network_get_permalink() . '" >' . substr($the_title,0,$tmp_title_characters) . '</a>'; | |
} | |
else{ | |
ob_start(); | |
$event = &network_get_post(); | |
switch_to_blog( $event->BLOG_ID ); | |
?> | |
<div class="event <?php echo Eab_Template::get_status_class($event); ?>" style="clear:both; margin-bottom: 80px;"> | |
<div class="wpmudevevents-header entry-header"> | |
<h3><?php echo Eab_Template::get_event_link($event); ?></h3> | |
</div> | |
<div style="clear:both;"> | |
<a href="<?php echo network_get_permalink(); ?>" class="wpmudevevents-viewevent"><?php _e('View event', Eab_EventsHub::TEXT_DOMAIN); ?></a> | |
<?php | |
echo Eab_Template::get_event_details($event); | |
?> | |
<?php | |
echo Eab_Template::get_rsvp_form($event); | |
?> | |
</div> | |
</div> | |
<hr /> | |
<?php | |
restore_current_blog(); | |
$html .= ob_get_clean(); | |
} | |
} | |
$html .= $tmp_title_after; | |
} | |
$html .= $tmp_title_content_divider; | |
if ( $tmp_content_characters > 0 ) { | |
$the_content = network_get_the_content(); | |
$html .= substr(strip_tags($the_content),0,$tmp_content_characters); | |
} | |
$html .= $tmp_after; | |
} | |
$html .= $tmp_global_after; | |
} | |
if($output) { | |
echo $html; | |
} else { | |
return $html; | |
} | |
} | |
function display_recent_posts_shortcode($atts, $content = null, $code = "") { | |
$defaults = array( 'number' => 5, | |
'title_characters' => 250, | |
'content_characters' => 0, | |
'title_content_divider' => '<br />', | |
'title_before' => '', | |
'title_after' => '', | |
'global_before' => '',//'<ul>', | |
'global_after' => '',//'</ul>', | |
'before' => '',//'<li>', | |
'after' => '',//'</li>', | |
'title_link' => 'yes', | |
'show_avatars' => 'no', | |
'avatar_size' => 16, | |
'posttype' => 'incsub_event' | |
); | |
extract(shortcode_atts($defaults, $atts)); | |
$html = ''; | |
$html .= $this->display_recent_posts( $number, $title_characters, $content_characters, $title_content_divider, $title_before, $title_after, $global_before, $global_after, $before, $after, $title_link, $show_avatars, $avatar_size, $posttype, false); | |
return $html; | |
} | |
} | |
add_action( 'plugins_loaded', function(){ | |
$GLOBALS['WPMUDEV_Recent_Global_Events'] = WPMUDEV_Recent_Global_Events::get_instance(); | |
}, 10 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment