Viewing 1 replies (of 1 total)
  • Thread Starter willroy

    (@willroy)

    Ok I ended up adding my own filter, here it is if anyone needs or need to add their own shortcodes that work in the EM Event scope:

    #_EVENTDAYS returns “x day(s)”
    #_EVENTSTARTDATE returns event_start_date

    add_filter('em_event_output','mc_em_event_output',10,4);
    
    function mc_em_event_output($event_string,$obj,$format,$target) {
    
    	//Now let's check out the placeholders.
     	preg_match_all("/(#@?_?[A-Za-z0-9]+)({([^}]+)})?/", $event_string, $placeholders);
     	$replaces = array();
    	foreach($placeholders[1] as $key => $result) {
    		$match = true;
    		$replace = '';
    		$full_result = $placeholders[0][$key];
    		switch( $result ){
    			case '#_EVENTDAYS':
    				// Return number of days
    				if( $obj->event_start_date != $obj->event_end_date){
    					$replace = floor(($obj->end - $obj->start)/(60*60*24)) + 1 . ' days';
    				}else{
    					$replace = 1 . ' day';
    				}
    				break;
    			case '#_EVENTSTARTDATE':
    				// Return event start date
                                   $date_format = ( get_option('dbem_date_format') ) ? get_option('dbem_date_format'):get_option('date_format');
    				if( $obj->event_start_date != $obj->event_end_date){
    					$replace = date_i18n($date_format, $obj->start);
    				}
    				break;
    			default:
    				$replace = $full_result;
    				break;
    		}
    		$replaces[$full_result] = apply_filters('em_event_output_placeholder', $replace, $this, $full_result, $target);
    	}
    	//sort out replacements so that during replacements shorter placeholders don't overwrite longer varieties.
    	krsort($replaces);
    	foreach($replaces as $full_result => $replacement){
    		if( !in_array($full_result, array('#_NOTES','#_EVENTNOTES')) ){
    			$event_string = str_replace($full_result, $replacement , $event_string );
    		}else{
    		    $new_placeholder = str_replace('#_', '__#', $full_result); //this will avoid repeated filters when locations/categories are parsed
    		    $event_string = str_replace($full_result, $new_placeholder , $event_string );
    			$desc_replace[$new_placeholder] = $replacement;
    		}
    	}		
    
    	return $event_string;
    
    }
Viewing 1 replies (of 1 total)

The topic ‘Shortcode for duration of event?’ is closed to new replies.