Advertisement
cipher87

Masonry Order Settings conflict with Events Calendar Pro fix

Feb 15th, 2018
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.56 KB | None | 0 0
  1. <?php
  2.  
  3. if ( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  4.  
  5.  
  6. //if either calendar plugin or modified version of the plugin that is included in the theme is available we can make use of it, otherwise return
  7.  
  8. if ( !class_exists( 'Tribe__Events__Main' ) ) return false;
  9.  
  10. define( 'AVIA_EVENT_PATH', AVIA_BASE . 'config-events-calendar/' );
  11.  
  12. include( 'event-mod-css-dynamic.php');
  13.  
  14.  
  15. //register my own styles
  16. if(!function_exists('avia_events_register_assets'))
  17. {
  18.     if(!is_admin()){ add_action('wp_enqueue_scripts', 'avia_events_register_assets',15); }
  19.    
  20.     function avia_events_register_assets($styleUrl)
  21.     {
  22.         wp_enqueue_style( 'avia-events-cal', AVIA_BASE_URL.'config-events-calendar/event-mod.css');
  23.     }
  24. }
  25.  
  26.  
  27. //register own default template
  28. if(!function_exists('avia_events_tempalte_paths'))
  29. {
  30.     add_action('tribe_events_template', 'avia_events_tempalte_paths', 10, 2);
  31.    
  32.     function avia_events_tempalte_paths($file, $template)
  33.     {
  34.         $redirect = array('default-template.php' , 'single-event.php' , 'pro/map.php' );
  35.        
  36.         if(in_array($template, $redirect))
  37.         {
  38.             $file = AVIA_EVENT_PATH . "views/".$template;
  39.         }
  40.        
  41.         return $file;
  42.     }
  43. }
  44.  
  45.  
  46. //remove ability to change some of the avialble options (eg: template choice)
  47.  
  48. if(!function_exists('avia_events_general_tab'))
  49. {
  50.     add_action('option_tribe_events_calendar_options', 'avia_events_perma_options', 10);
  51.    
  52.     function avia_events_perma_options($options)
  53.     {
  54.         $edit_elements  = array('tribeEventsTemplate' => '', 'stylesheetOption' => 'full' , 'tribeDisableTribeBar'=>false); // stylesheetOption: skeleton, full, tribe
  55.         $options= array_merge($options, $edit_elements);
  56.        
  57.         return $options;
  58.     }
  59. }
  60.  
  61. //edit/remove some of the options from general tab
  62. if(!function_exists('avia_events_general_tab'))
  63. {
  64.     add_action('tribe_general_settings_tab_fields', 'avia_events_general_tab', 10);
  65.    
  66.     function avia_events_general_tab($options)
  67.     {
  68.         $edit_elements  = array('info-start' => array('html' => '<div id="modern-tribe-info">'),
  69.                 'upsell-info', 'upsell-info', 'donate-link-info', 'donate-link-pro-info', 'donate-link-heading', 'donate-link', 'info-end'=> array('html'=> avia_tribe_ref()."</div>"));
  70.                
  71.         $options        = avia_events_modify_options($options, $edit_elements);
  72.         return $options;
  73.     }
  74. }
  75.  
  76. //edit/remove some of the options from display tab
  77. if(!function_exists('avia_events_display_tab'))
  78. {
  79.     add_action('tribe_display_settings_tab_fields', 'avia_events_display_tab', 10);
  80.    
  81.     function avia_events_display_tab($options)
  82.     {
  83.         $edit_elements  = array('info-start', 'info-box-title', 'info-box-description', 'info-end', 'stylesheetOption', 'tribeEventsTemplate', 'tribeDisableTribeBar');
  84.         $options        = avia_events_modify_options($options, $edit_elements);
  85.        
  86.         return $options;
  87.     }
  88. }
  89.  
  90.  
  91.  
  92. if(!function_exists('avia_events_modify_options'))
  93. {
  94.     function avia_events_modify_options($options, $edit_elements)
  95.     {
  96.         foreach($edit_elements as $key => $element)
  97.             {
  98.                 if(is_array($element))
  99.                 {
  100.                     $options[$key] = array_merge_recursive($options, $element);
  101.                 }
  102.                 else
  103.                 {
  104.                     if(array_key_exists($element, $options)) unset($options[$element]);
  105.                 }
  106.             }
  107.            
  108.             return $options;
  109.     }
  110. }
  111.  
  112.  
  113. if(!function_exists('avia_events_upsell'))
  114. {
  115.     $tec = Tribe__Events__Main::instance();
  116.     remove_action( 'tribe_events_cost_table', array($tec, 'maybeShowMetaUpsell'));
  117.     add_action( 'tribe_events_cost_table', 'avia_events_upsell', 10);
  118.  
  119.     function avia_events_upsell()
  120.     {  
  121.         if(!class_exists( 'Tribe__Events__Pro__Main' )){
  122.    
  123.         ?><tr class="eventBritePluginPlug">
  124.         <td colspan="2" class="tribe_sectionheader">
  125.         <h4><?php _e('Additional Functionality', 'avia_framework'); ?></h4>
  126.         </td>
  127.         </tr>
  128.         <tr class="eventBritePluginPlug">
  129.         <td colspan="2">
  130.         <?php echo avia_tribe_ref(); ?>
  131.         </td>
  132.         </tr><?php
  133.        
  134.         }
  135.     }
  136. }
  137.  
  138. if(!function_exists('avia_tribe_ref'))
  139. {
  140.  
  141. function avia_tribe_ref()
  142. {
  143.     if(class_exists( 'Tribe__Events__Pro__Main' )) return "";
  144.  
  145.     $output = "<p>";
  146.     $output .= __('Looking for additional functionality including recurring events, ticket sales, publicly submitted events, new views and more?', 'avia_framework' )." ";
  147.     $output .=  __('Check out the', 'avia_framework' ).
  148.                 " <a href='http://mbsy.co/6cr37'>".
  149.                 __('available add-ons', 'avia_framework' ).
  150.                 "</a>";
  151.    
  152.     $output .= "</p>";
  153.     return $output;
  154.    
  155.     }
  156. }
  157.  
  158.  
  159. /*modfiy post navigation*/
  160.  
  161. if(!function_exists('avia_events_custom_post_nav'))
  162. {
  163.     add_action( 'avia_post_nav_entries', 'avia_events_custom_post_nav', 10);
  164.  
  165.     function avia_events_custom_post_nav($entry)
  166.     {
  167.         if(tribe_is_event())
  168.         {
  169.             $final = $links = $entry = array();
  170.             $links['next'] = tribe_get_next_event_link("{-{%title%}-}");
  171.             $links['prev'] = tribe_get_prev_event_link("{-{%title%}-}");
  172.                
  173.             foreach($links as $key => $link)
  174.             {
  175.                 preg_match('/^<a.*?href=(["\'])(.*?)\1.*$/', $link, $m);
  176.                 $final[$key]['link_url'] = !empty($m[2]) ? $m[2] : "";
  177.                
  178.                 preg_match('/\{\-\{(.+)\}\-\}/', $link, $m2);
  179.                 $final[$key]['link_text'] = !empty($m2[1]) ? $m2[1] : "";
  180.                
  181.                 if(!empty($final[$key]['link_text']))
  182.                 {
  183.                     $entry[$key] = new stdClass();
  184.                     $entry[$key]->av_custom_link  = $final[$key]['link_url'];
  185.                     $entry[$key]->av_custom_title = $final[$key]['link_text'];
  186.                     $entry[$key]->av_custom_image = false;
  187.                 }
  188.                
  189.             }
  190.         }
  191.         return $entry;
  192.     }
  193. }
  194.  
  195. /*modfiy breadcrumb navigation*/
  196. if(!function_exists('avia_events_breadcrumb'))
  197. {
  198.     add_filter('avia_breadcrumbs_trail','avia_events_breadcrumb');
  199.  
  200.     function avia_events_breadcrumb($trail)
  201.     {
  202.         global $avia_config, $wp_query;
  203.        
  204.         if(is_404() && isset($wp_query) && !empty($wp_query->tribe_is_event))
  205.         {
  206.             $events = __('Events','avia_framework');
  207.             $events_link = '<a href="'.tribe_get_events_link().'">'.$events.'</a>';
  208.             $last = array_pop($trail);
  209.             $trail[] = $events_link;
  210.             $trail['trail_end'] = __('No Events Found','avia_framework');
  211.         }
  212.        
  213.         if((isset($avia_config['currently_viewing']) && $avia_config['currently_viewing'] == 'events') || tribe_is_month() || get_post_type() === Tribe__Events__Main::POSTTYPE || is_tax(Tribe__Events__Main::TAXONOMY) )
  214.         {  
  215.             $events = __('Events','avia_framework');
  216.             $events_link = '<a href="'.tribe_get_events_link().'">'.$events.'</a>';
  217.            
  218.             if(is_tax(Tribe__Events__Main::TAXONOMY) )
  219.             {
  220.                 $last = array_pop($trail);
  221.                 $trail[] = $events_link;
  222.                 $trail[] = $last;
  223.             }
  224.             else if(tribe_is_month() || (tribe_is_upcoming() && !is_singular()))
  225.             {
  226.                 $trail[] = $events_link;
  227.             }
  228.             else if(tribe_is_event())
  229.             {
  230.                 $last = array_pop($trail);
  231.                 $trail[] = $events_link;
  232.                 $trail[] = $last;
  233.             }
  234.  
  235.             if(isset($avia_config['events_trail'] )) $trail = $avia_config['events_trail'] ;
  236.         }
  237.            
  238.         return $trail;
  239.     }
  240.  
  241. }
  242.  
  243.  
  244. /*additional markup*/
  245. if(!function_exists('avia_events_content_wrap'))
  246. {
  247.     add_action( 'tribe_events_before_the_event_title', 'avia_events_content_wrap', 10);
  248.  
  249.     function avia_events_content_wrap()
  250.     {
  251.         echo "<div class='av-tribe-events-content-wrap'>";
  252.     }
  253. }
  254.  
  255. if(!function_exists('avia_events_open_outer_wrap'))
  256. {
  257.     add_action( 'tribe_events_after_the_event_title', 'avia_events_open_outer_wrap', 10);
  258.  
  259.     function avia_events_open_outer_wrap()
  260.     {
  261.         echo "<div class='av-tribe-events-outer-content-wrap'>";
  262.     }
  263. }
  264.  
  265. if(!function_exists('avia_events_open_inner_wrap'))
  266. {
  267.     add_action( 'tribe_events_after_the_meta', 'avia_events_open_inner_wrap', 10);
  268.  
  269.     function avia_events_open_inner_wrap()
  270.     {
  271.         echo "<div class='av-tribe-events-inner-content-wrap'>";
  272.     }
  273. }
  274.  
  275.  
  276. if(!function_exists('avia_events_close_div'))
  277. {
  278.     /*call 3 times, once for wrappper, outer and inner wrap*/
  279.     add_action( 'tribe_events_after_the_content', 'avia_events_close_div', 1000);
  280.     add_action( 'tribe_events_after_the_content', 'avia_events_close_div', 1001);
  281.     add_action( 'tribe_events_after_the_content', 'avia_events_close_div', 1003);
  282.  
  283.     function avia_events_close_div()
  284.     {
  285.         echo "</div>";
  286.     }
  287. }
  288.  
  289.  
  290.  
  291.  
  292.  
  293. /*PRO PLUGIN*/
  294. if ( !class_exists( 'Tribe__Events__Pro__Main' ) ) return false;
  295.  
  296. /*move related events*/
  297. $tec = Tribe__Events__Pro__Main::instance();
  298. remove_action( 'tribe_events_single_event_after_the_meta', array( $tec, 'register_related_events_view' ) );
  299. add_action( 'tribe_events_single_event_after_the_content', array( $tec, 'register_related_events_view' ) );
  300.  
  301.  
  302. if( ! function_exists( 'avia_events_modify_recurring_event_query' ) )
  303. {
  304.     /**
  305.      * Selecting checkbox Recurring event instances in Events -> Settings -> General might might break our queries because of GROUP BY clause.
  306.      * Reason is probably if multiple posttypes are part of the query.
  307.      *
  308.      * @added_by Günter
  309.      * @since 4.2.4
  310.      * @param array $query
  311.      * @param array $params
  312.      * @return array
  313.      */
  314.     function avia_events_modify_recurring_event_query( array $query, array $params )
  315.     {
  316.         remove_filter( 'posts_request', array( 'Tribe__Events__Pro__Recurrence__Queries', 'collapse_sql' ), 10, 2 );
  317.  
  318.         return $query;
  319.     }
  320. }
  321.  
  322. if( ! function_exists( 'avia_events_reset_recurring_event_query' ) )
  323. {
  324.     /**
  325.      * Add the previously removed filter again
  326.      *
  327.      * @added_by Günter
  328.      * @since 4.2.4
  329.      */
  330.     function avia_events_reset_recurring_event_query()
  331.     {
  332.         if( false === has_filter( 'posts_request', array( 'Tribe__Events__Pro__Recurrence__Queries', 'collapse_sql' ) ) )
  333.         {
  334.             add_filter( 'posts_request', array( 'Tribe__Events__Pro__Recurrence__Queries', 'collapse_sql' ), 10, 2 );
  335.         }
  336.     }
  337. }
  338.    
  339. add_filter( 'avia_masonry_entries_query', 'avia_events_modify_recurring_event_query', 10, 2 );
  340. add_action( 'ava_after_masonry_entries_query', 'avia_events_reset_recurring_event_query', 10 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement