PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.18.8
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.18.8
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / classes / Integration / Plugin / TheEventsCalendar.php
nitropack / classes / Integration / Plugin Last commit date
ACF.php 1 year ago AdvancedMathCaptcha.php 1 year ago AeliaCurrencySwitcher.php 11 months ago BeaverBuilder.php 1 year ago CF_Helper.php 1 year ago CURCY_MultiCurrency.php 1 year ago Cloudflare.php 1 year ago CommonHelpers.php 1 year ago CookieNotice.php 1 year ago DownloadManager.php 1 year ago Elementor.php 6 months ago Ezoic.php 1 year ago FusionBuilder.php 1 year ago GeoTargetingWP.php 1 year ago GravityForms.php 1 year ago JetPackNP.php 1 year ago MPG.php 11 months ago NginxHelper.php 1 year ago RC.php 11 months ago RankMathNP.php 1 year ago ShortPixel.php 1 year ago SquirrlySEO.php 1 year ago TheEventsCalendar.php 1 year ago ThriveTheme.php 1 year ago WCML.php 1 year ago WPBakeryNP.php 1 year ago WPCacheHelper.php 1 year ago WPForms.php 1 year ago WPML.php 1 year ago WPRocket.php 1 year ago WooCommerce.php 11 months ago WoocommerceCacheHandler.php 1 year ago YoastSEO.php 1 year 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