add_confirm('Style Updated'); } else { //A new style, so we either add it to the end of the array, or start it off at index 1 if it's the first item to be added. if( count($my_em_styles) > 0 ){ $my_em_styles[] = $_REQUEST['style_name']; }else{ $my_em_styles[1] = $_REQUEST['style_name']; } $EM_Notices->add_confirm('Style Added'); } update_option('my_em_styles',$my_em_styles); } elseif( $_REQUEST['action'] == "style_delete" && wp_verify_nonce($_REQUEST['_wpnonce'], 'style_delete') ){ //Unset the style from the array and save if(is_array($_REQUEST['styles'])){ foreach($_REQUEST['styles'] as $id){ unset($my_em_styles[$id]); } update_option('my_em_styles',$my_em_styles); $EM_Notices->add_confirm('Styles Deleted'); } } } my_em_styles_table_layout(); } function my_em_styles_table_layout() { global $EM_Notices, $my_em_styles; ?>

Styles

Style

' />

or Add New

styles = $wpdb->get_col("SELECT meta_value FROM ".EM_META_TABLE." WHERE object_id='{$EM_Event->id}' AND meta_key='event-style'", 0 ); } add_action('em_event','my_em_styles_event_load',1,1); function my_em_styles_metabox(){ global $EM_Event; $my_em_styles = (is_array(get_option('my_em_styles'))) ? get_option('my_em_styles'):array(); ?>

Event Styles

$style ):?>
styles = array(); foreach( $_POST['event_styles'] as $style_id ){ if( array_key_exists($style_id, $my_em_styles) ){ $ids_to_add[] = "({$EM_Event->id}, 'event-style', '$style_id')"; $EM_Event->styles[] = $style_id; } } //First delete any old saves $wpdb->query("DELETE FROM ".EM_META_TABLE." WHERE object_id='{$EM_Event->id}' AND meta_key='event-style'"); if( count($ids_to_add) > 0 ){ $wpdb->query("INSERT INTO ".EM_META_TABLE." (object_id, meta_key, meta_value) VALUES ".implode(',',$ids_to_add)); } } return $result; } add_filter('em_event_save','my_em_styles_event_save',1,2); //search stuff for the style function my_em_styles_search_form(){ $my_em_styles = (is_array(get_option('my_em_styles'))) ? get_option('my_em_styles'):array(); ?> $EM_Event){ if( !in_array($args['style'],$EM_Event->styles) ){ unset($events[$event_key]); } } } return $events; } add_filter('em_events_get','my_em_styles_events_get',1,2); function my_em_styles_event_output_condition($replacement, $condition, $match, $EM_Event){ //check if there is a conditional tag for a specific style id if( is_object($EM_Event) && preg_match('/^has_style_(.+)$/',$condition, $matches) && is_array( $EM_Event->styles ) ){ if( in_array($matches[1],$EM_Event->styles) ){ //this event has the desired style id, so show the replacement $replacement = preg_replace("/\{\/?$condition\}/", '', $match); }else{ //no style, don't show the conditional $replacement = ''; } } return $replacement; } add_action('em_event_output_condition', 'my_em_styles_event_output_condition', 1, 4); function my_em_styles_rewrite_rules_array($rules){ //get the slug of the event page $events_page_id = get_option ( 'dbem_events_page' ); $events_page = get_post($events_page_id); $my_em_rules = array(); if( is_object($events_page) ){ $events_slug = $events_page->post_name; $my_em_rules[$events_slug.'/styles$'] = 'index.php?pagename='.$events_slug.'&styles_page=1'; //events with scope $my_em_rules[$events_slug.'/style/(\d+)$'] = 'index.php?pagename='.$events_slug.'&style_id=$matches[1]'; //events with scope } return $my_em_rules + $rules; } add_filter('rewrite_rules_array','my_em_styles_rewrite_rules_array'); function my_em_styles_query_vars($vars){ array_push($vars, 'style_id','styles_page'); return $vars; } add_filter('query_vars','my_em_styles_query_vars'); function my_em_styles_content($content){ global $wp_query; $my_em_styles = (is_array(get_option('my_em_styles'))) ? get_option('my_em_styles'):array(); if( is_numeric($wp_query->get('style_id')) ){ $content = EM_Events::output(array('style'=>$wp_query->get('style_id'))); }elseif($wp_query->get('styles_page')){ $content =''; foreach($my_em_styles as $style_id => $style_name){ $content .= "

$style_name

"; $content .= EM_Events::output(array('style'=>$style_id)); } } return $content; } add_filter('em_content_pre','my_em_styles_content'); function my_em_styles_content_page_title_pre($content){ global $wp_query; $my_em_styles = (is_array(get_option('my_em_styles'))) ? get_option('my_em_styles'):array(); if( is_numeric($wp_query->get('style_id')) ){ $content = $my_em_styles[$wp_query->get('style_id')]; }elseif($wp_query->get('styles_page')){ $content ='Styles'; } return $content; } add_filter('em_content_page_title_pre','my_em_styles_content_page_title_pre'); function my_em_styles_placeholders($replace, $EM_Event, $result){ global $wp_query, $wp_rewrite; switch( $result ){ case '#_STYLES': $replace = 'none'; if( count($EM_Event->styles) > 0 ){ $my_em_styles = (is_array(get_option('my_em_styles'))) ? get_option('my_em_styles'):array(); $styles = array(); foreach( $my_em_styles as $id => $name ){ if(in_array($id, $EM_Event->styles)){ $styles[] = $name; } } $replace = implode(', ', $styles); } break; } return $replace; } add_filter('em_event_output_placeholder_pre','my_em_styles_placeholders',1,3); ?>