AdvancedMathCaptcha.php
3 years ago
AeliaCurrencySwitcher.php
3 years ago
BeaverBuilder.php
4 years ago
CF_Helper.php
3 years ago
Cloudflare.php
2 years ago
CommonHelpers.php
3 years ago
CookieNotice.php
4 years ago
DownloadManager.php
4 years ago
Elementor.php
3 years ago
Ezoic.php
4 years ago
FusionBuilder.php
4 years ago
GeoTargetingWP.php
2 years ago
GravityForms.php
2 years ago
JetPackNP.php
3 years ago
NginxHelper.php
2 years ago
RC.php
3 years ago
RankMathNP.php
3 years ago
ShortPixel.php
4 years ago
SquirrlySEO.php
3 years ago
TheEventsCalendar.php
3 years ago
ThriveTheme.php
4 years ago
WCML.php
3 years ago
WPBakeryNP.php
3 years ago
WPCacheHelper.php
3 years ago
WPForms.php
3 years ago
WPRocket.php
4 years ago
Woocommerce.php
4 years ago
WoocommerceCacheHandler.php
4 years ago
YoastSEO.php
3 years ago
TheEventsCalendar.php
157 lines
| 1 | <?php |
| 2 | /** |
| 3 | * TheEventsCalendar Class |
| 4 | * |
| 5 | * @package nitropack |
| 6 | */ |
| 7 | |
| 8 | namespace NitroPack\Integration\Plugin; |
| 9 | |
| 10 | if ( ! function_exists( 'is_plugin_active' ) ) { |
| 11 | include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * TheEventsCalendar Class |
| 16 | */ |
| 17 | class TheEventsCalendar { |
| 18 | |
| 19 | const STAGE = 'early'; |
| 20 | |
| 21 | const WIDGET_ID = 'tribe-widget-events-list'; |
| 22 | |
| 23 | /** |
| 24 | * Check if plugin "The Events Calendar" is active |
| 25 | * |
| 26 | * @return bool |
| 27 | */ |
| 28 | public static function isActive() { //phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
| 29 | return is_plugin_active( 'the-events-calendar/the-events-calendar.php' ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Initialize the integration |
| 34 | * |
| 35 | * @param string $stage Stage. |
| 36 | * |
| 37 | * @return void |
| 38 | */ |
| 39 | public function init( $stage ) { //phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found |
| 40 | if ($this -> isActive()) { |
| 41 | |
| 42 | if (!wp_doing_ajax()) { |
| 43 | add_filter( 'dynamic_sidebar_params', [$this, 'filter_dynamic_sidebar_params'] ); |
| 44 | add_filter( 'widget_output', [$this, 'widget_output_filter'], 10, 4 ); |
| 45 | } |
| 46 | add_action( 'wp_ajax_nitropack_widget_output_ajax', [$this, 'widget_output_ajax'] ); |
| 47 | add_action( 'wp_ajax_nopriv_nitropack_widget_output_ajax', [$this, 'widget_output_ajax'] ); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Filter dynamic sidebar params |
| 53 | * |
| 54 | * @param array $sidebar_params Sidebar params. |
| 55 | * |
| 56 | * @return mixed |
| 57 | */ |
| 58 | public function filter_dynamic_sidebar_params( $sidebar_params ) { |
| 59 | |
| 60 | if ( is_admin() ) { |
| 61 | return $sidebar_params; |
| 62 | } |
| 63 | |
| 64 | global $wp_registered_widgets; |
| 65 | $widget_id = $sidebar_params[0]['widget_id']; |
| 66 | |
| 67 | if ( strpos($widget_id, self::WIDGET_ID) !== false) { |
| 68 | $wp_registered_widgets[ $widget_id ]['original_callback'] = $wp_registered_widgets[ $widget_id ]['callback']; |
| 69 | $wp_registered_widgets[ $widget_id ]['callback'] = [$this, 'custom_widget_callback_function']; |
| 70 | } |
| 71 | return $sidebar_params; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Widget output filter |
| 76 | * |
| 77 | * @return void |
| 78 | */ |
| 79 | public function custom_widget_callback_function() { |
| 80 | |
| 81 | global $wp_registered_widgets; |
| 82 | $original_callback_params = func_get_args(); |
| 83 | |
| 84 | $widget_id = $original_callback_params[0]['widget_id']; |
| 85 | $original_callback = $wp_registered_widgets[ $widget_id ]['original_callback']; |
| 86 | |
| 87 | $wp_registered_widgets[ $widget_id ]['callback'] = $original_callback; |
| 88 | |
| 89 | $widget_id_base = $original_callback[0]->id_base; |
| 90 | $sidebar_id = $original_callback_params[0]['id']; |
| 91 | |
| 92 | if ( is_callable( $original_callback ) ) { |
| 93 | |
| 94 | ob_start(); |
| 95 | call_user_func_array( $original_callback, $original_callback_params ); |
| 96 | $widget_output = ob_get_clean(); |
| 97 | |
| 98 | echo wp_kses_post(apply_filters( 'widget_output', $widget_output, $widget_id_base, $widget_id, $sidebar_id )); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Filter the widget's output. |
| 104 | * |
| 105 | * @param string $widget_output The widget's output. |
| 106 | * @param string $widget_id_base The widget's base ID. |
| 107 | * @param string $widget_id The widget's full ID. |
| 108 | * @param string $sidebar_id The current sidebar ID. |
| 109 | */ |
| 110 | public function widget_output_filter( $widget_output, $widget_id_base, $widget_id, $sidebar_id ) { |
| 111 | |
| 112 | wp_enqueue_script( 'nitropack-widget-ajax-script', NITROPACK_PLUGIN_DIR_URL . 'view/javascript/widgets_ajax.js?np_v=' . NITROPACK_VERSION, array('jquery'), NITROPACK_VERSION, true ); |
| 113 | wp_localize_script( 'nitropack-widget-ajax-script', 'nitropack_widget_ajax', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); |
| 114 | |
| 115 | ob_start(); |
| 116 | ?> |
| 117 | <div class="nitropack-widget-ajax" data-widget-id="<?php echo esc_attr($widget_id); ?>" data-sidebar-id="<?php echo esc_attr($sidebar_id); ?>"><img src="<?php echo esc_url(NITROPACK_PLUGIN_DIR_URL . 'view/images/loading.gif'); ?>" alt="loading" /></div> |
| 118 | <?php |
| 119 | $widget_output = ob_get_clean(); |
| 120 | |
| 121 | return $widget_output; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Widget output ajax |
| 126 | * |
| 127 | * @return void |
| 128 | */ |
| 129 | public function widget_output_ajax(){ |
| 130 | |
| 131 | global $wp_registered_sidebars, $wp_registered_widgets; |
| 132 | |
| 133 | $widget_id = isset($_GET['widget_id']) ? sanitize_text_field(wp_unslash($_GET['widget_id'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 134 | $sidebar_id = isset($_GET['sidebar_id']) ? sanitize_text_field(wp_unslash($_GET['sidebar_id'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 135 | |
| 136 | if( !empty($widget_id) && isset($wp_registered_widgets[$widget_id]) && isset($wp_registered_sidebars[$sidebar_id]) && isset($wp_registered_widgets[$widget_id]["callback"])) { |
| 137 | |
| 138 | $original_callback = $wp_registered_widgets[$widget_id]['callback']; |
| 139 | |
| 140 | $params = []; |
| 141 | |
| 142 | $params[] = $wp_registered_sidebars[$sidebar_id]; |
| 143 | |
| 144 | if (isset($wp_registered_widgets[ $widget_id ]['params'][0])) { |
| 145 | $params[] = $wp_registered_widgets[ $widget_id ]['params'][0]; |
| 146 | } |
| 147 | |
| 148 | if (is_callable($original_callback)) { |
| 149 | |
| 150 | call_user_func_array($original_callback, $params); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | wp_die(); |
| 155 | } |
| 156 | } |
| 157 |