is_v2_adv_list_widget() ) { return; } /** * Allow filtering of whether the event list or the advanced event list widget should be primary. * * @since 5.3.0 * * @param bool $adv_primary Whether the advanced list widget is primary. */ $advanced_primary = apply_filters( 'tribe_events_views_v2_advanced_list_widget_primary', false ); if ( $advanced_primary && ! tribe_events_views_v2_is_enabled() ) { $this->primary_id_base = 'tribe-events-adv-list-widget'; $this->alternative_id_base = 'tribe-events-list-widget'; } add_filter( "option_widget_{$this->primary_id_base}", [ $this, 'merge_list_widget_options' ] ); } /** * Function that determines which version of the widget we should load based on the ECP version. * * @since 5.3.0 * * @return boolean */ public function is_v2_adv_list_widget() { if ( ! defined( 'Tribe__Events__Pro__Main::VERSION' ) ) { return true; } return version_compare( \Tribe__Events__Pro__Main::VERSION, '5.3.0-dev', '>=' ); } /** * Remap the widget id_base for the Pro Advanced List Widget. * * @since 5.3.0 * * @param array $widget_areas An array of widgets areas with the saved widgets in each location. * * @return array $widget_areas A modified array of widgets areas with the saved widgets in each location. */ public function remap_list_widget_id_bases( $widget_areas ) { if ( ! is_array( $widget_areas ) ) { return $widget_areas; } if ( ! $this->is_v2_adv_list_widget() ) { return $widget_areas; } foreach ( $widget_areas as $key => $widget_location ) { if ( ! is_array( $widget_location ) ) { continue; } foreach ( $widget_location as $widget_key => $widget ) { $widget_areas[ $key ][ $widget_key ] = str_replace( $this->alternative_id_base, $this->primary_id_base, $widget ); } } return $widget_areas; } /** * Merge the Event List and Advanced List Widget Options. * * @since 5.3.0 * * @param array $widgets An array of saved widgets. * * @return array $widgets The modified array of saved widgets. */ public function merge_list_widget_options( $widgets ) { if ( ! is_array( $widgets ) ) { return $widgets; } // Get the saved alternative widgets. $alternative_options = get_option( "widget_{$this->alternative_id_base}" ); if ( ! is_array( $alternative_options ) ) { return $widgets; } // Combine arrays and keep the array keys. return $widgets + $alternative_options; } }