Advertisement
Beee

new_em_get_event_shortcode

Aug 30th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.25 KB | None | 0 0
  1. <?php
  2.     // this caused the issue
  3.     function new_em_get_event_shortcode( $atts, $format = '' ) {
  4.         global $EM_Event, $post;
  5.         $return         = '';
  6.         $the_event      = is_object( $EM_Event ) ? clone( $EM_Event ) : null; // save global temporarily
  7.         $atts           = (array) $atts;
  8.         $atts['format'] = ( $format != '' || empty( $atts['format'] ) ) ? $format : $atts['format'];
  9.         $atts['format'] = html_entity_decode( $atts['format'] ); // shorcode doesn't accept html
  10.         if ( ! empty( $atts['event'] ) && is_numeric( $atts['event'] ) ) {
  11.             $EM_Event = em_get_event( $atts['event'] );
  12.             $return   = ( ! empty( $atts['format'] ) ) ? $EM_Event->output( $atts['format'] ) : $EM_Event->output_single();
  13.         } elseif ( ! empty( $atts['post_id'] ) && is_numeric( $atts['post_id'] ) ) {
  14.             $EM_Event = em_get_event( $atts['post_id'], 'post_id' );
  15.             $return   = ( ! empty( $atts['format'] ) ) ? $EM_Event->output( $atts['format'] ) : $EM_Event->output_single();
  16.         }
  17.         // no specific event or post id supplied, check globals
  18.         if ( ! empty( $EM_Event ) ) {
  19.             $return = ( ! empty( $atts['format'] ) ) ? $EM_Event->output( $atts['format'] ) : $EM_Event->output_single();
  20.         } elseif ( $post->post_type == EM_POST_TYPE_EVENT ) {
  21.             $EM_Event = em_get_event( $post->ID, 'post_id' );
  22.             $return   = ( ! empty( $atts['format'] ) ) ? $EM_Event->output( $atts['format'] ) : $EM_Event->output_single();
  23.         }
  24.         $EM_Event = is_object( $the_event ) ? $the_event : $EM_Event; //reset global
  25.  
  26.         return do_shortcode( $return );
  27.     }
  28.     add_shortcode( 'event', 'new_em_get_event_shortcode' );
  29.  
  30.     // this fixed the issue
  31.     function new_em_get_event_shortcode( $atts, $format = '' ) {
  32.         global $post;
  33.         $return           = '';
  34.         $atts             = (array) $atts;
  35.         $atts[ 'format' ] = ( $format != '' || empty( $atts[ 'format' ] ) ) ? $format : $atts[ 'format' ];
  36.         $atts[ 'format' ] = html_entity_decode( $atts[ 'format' ] ); //shorcode doesn't accept html
  37.         if ( ! empty( $atts[ 'event' ] ) && is_numeric( $atts[ 'event' ] ) ) {
  38.             $EM_Event = em_get_event( $atts[ 'event' ] );
  39.             $return   = ( ! empty( $atts[ 'format' ] ) ) ? $EM_Event->output( $atts[ 'format' ] ) : $EM_Event->output_single();
  40.         } elseif ( ! empty( $atts[ 'post_id' ] ) && is_numeric( $atts[ 'post_id' ] ) ) {
  41.             $EM_Event = em_get_event( $atts[ 'post_id' ], 'post_id' );
  42.             $return   = ( ! empty( $atts[ 'format' ] ) ) ? $EM_Event->output( $atts[ 'format' ] ) : $EM_Event->output_single();
  43.         }
  44.         //no specific event or post id supplied, check globals
  45.         if ( ! empty( $EM_Event ) ) {
  46.             $return = ( ! empty( $atts[ 'format' ] ) ) ? $EM_Event->output( $atts[ 'format' ] ) : $EM_Event->output_single();
  47.         } elseif ( $post->post_type == EM_POST_TYPE_EVENT ) {
  48.             $EM_Event = em_get_event( $post->ID, 'post_id' );
  49.             $return   = ( ! empty( $atts[ 'format' ] ) ) ? $EM_Event->output( $atts[ 'format' ] ) : $EM_Event->output_single();
  50.         }
  51.  
  52.         return do_shortcode( $return );
  53.     }
  54.     add_shortcode( 'event', 'new_em_get_event_shortcode' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement