PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.19.6
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.19.6
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 2 weeks ago AdvancedMathCaptcha.php 1 month ago AeliaCurrencySwitcher.php 11 months ago BeaverBuilder.php 1 year ago CF_Helper.php 5 months ago CURCY_MultiCurrency.php 1 year ago Cloudflare.php 5 months ago CommonHelpers.php 1 year ago CookieNotice.php 1 year ago DownloadManager.php 1 year ago Elementor.php 5 months ago Ezoic.php 1 year ago FusionBuilder.php 1 year ago GeoTargetingWP.php 1 year ago GravityForms.php 1 month 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 month 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 2 weeks ago WPRocket.php 1 year ago WooCommerce.php 2 weeks ago WoocommerceCacheHandler.php 1 year ago YoastSEO.php 1 year ago
TheEventsCalendar.php
183 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 const WIDGET_AJAX_NONCE_ACTION = 'nitropack_widget_output_ajax';
24
25 /**
26 * Check if plugin "The Events Calendar" is active
27 *
28 * @return bool
29 */
30 public static function isActive() { //phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
31 return is_plugin_active( 'the-events-calendar/the-events-calendar.php' );
32 }
33
34 /**
35 * Initialize the integration
36 *
37 * @param string $stage Stage.
38 *
39 * @return void
40 */
41 public function init( $stage ) { //phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
42 if ($this -> isActive()) {
43
44 if (!wp_doing_ajax()) {
45 add_filter( 'dynamic_sidebar_params', [$this, 'filter_dynamic_sidebar_params'] );
46 add_filter( 'widget_output', [$this, 'widget_output_filter'], 10, 4 );
47 }
48 add_action( 'wp_ajax_nitropack_widget_output_ajax', [$this, 'widget_output_ajax'] );
49 add_action( 'wp_ajax_nopriv_nitropack_widget_output_ajax', [$this, 'widget_output_ajax'] );
50 }
51 }
52
53 /**
54 * Filter dynamic sidebar params
55 *
56 * @param array $sidebar_params Sidebar params.
57 *
58 * @return mixed
59 */
60 public function filter_dynamic_sidebar_params( $sidebar_params ) {
61
62 if ( is_admin() ) {
63 return $sidebar_params;
64 }
65
66 global $wp_registered_widgets;
67 $widget_id = $sidebar_params[0]['widget_id'];
68
69 if ( strpos($widget_id, self::WIDGET_ID) !== false) {
70 $wp_registered_widgets[ $widget_id ]['original_callback'] = $wp_registered_widgets[ $widget_id ]['callback'];
71 $wp_registered_widgets[ $widget_id ]['callback'] = [$this, 'custom_widget_callback_function'];
72 }
73 return $sidebar_params;
74 }
75
76 /**
77 * Widget output filter
78 *
79 * @return void
80 */
81 public function custom_widget_callback_function() {
82
83 global $wp_registered_widgets;
84 $original_callback_params = func_get_args();
85
86 $widget_id = $original_callback_params[0]['widget_id'];
87 $original_callback = $wp_registered_widgets[ $widget_id ]['original_callback'];
88
89 $wp_registered_widgets[ $widget_id ]['callback'] = $original_callback;
90
91 $widget_id_base = $original_callback[0]->id_base;
92 $sidebar_id = $original_callback_params[0]['id'];
93
94 if ( is_callable( $original_callback ) ) {
95
96 ob_start();
97 call_user_func_array( $original_callback, $original_callback_params );
98 $widget_output = ob_get_clean();
99
100 echo wp_kses_post(apply_filters( 'widget_output', $widget_output, $widget_id_base, $widget_id, $sidebar_id ));
101 }
102 }
103
104 /**
105 * Filter the widget's output.
106 *
107 * @param string $widget_output The widget's output.
108 * @param string $widget_id_base The widget's base ID.
109 * @param string $widget_id The widget's full ID.
110 * @param string $sidebar_id The current sidebar ID.
111 */
112 public function widget_output_filter( $widget_output, $widget_id_base, $widget_id, $sidebar_id ) {
113
114 wp_enqueue_script( 'nitropack-widget-ajax-script', NITROPACK_PLUGIN_DIR_URL . 'assets/js/widgets_ajax.min.js?np_v=' . NITROPACK_VERSION, array('jquery'), NITROPACK_VERSION, true );
115 wp_localize_script( 'nitropack-widget-ajax-script', 'nitropack_widget_ajax', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
116 $widget_nonce = wp_create_nonce( $this->get_widget_nonce_action( $widget_id, $sidebar_id ) );
117
118 ob_start();
119 ?>
120 <div class="nitropack-widget-ajax" data-widget-id="<?php echo esc_attr($widget_id); ?>" data-sidebar-id="<?php echo esc_attr($sidebar_id); ?>" data-widget-nonce="<?php echo esc_attr( $widget_nonce ); ?>"><img src="<?php echo esc_url(NITROPACK_PLUGIN_DIR_URL . 'assets/img/loading.gif'); ?>" alt="loading" /></div>
121 <?php
122 $widget_output = ob_get_clean();
123
124 return $widget_output;
125 }
126
127 /**
128 * Build widget output nonce action.
129 *
130 * @param string $widget_id The widget's full ID.
131 * @param string $sidebar_id The current sidebar ID.
132 *
133 * @return string
134 */
135 private function get_widget_nonce_action( $widget_id, $sidebar_id ) {
136 return self::WIDGET_AJAX_NONCE_ACTION . '|' . $widget_id . '|' . $sidebar_id;
137 }
138
139 /**
140 * Widget output ajax
141 *
142 * @return void
143 */
144 public function widget_output_ajax(){
145
146 global $wp_registered_sidebars, $wp_registered_widgets;
147
148 $widget_id = isset( $_GET['widget_id'] ) ? sanitize_text_field( wp_unslash( $_GET['widget_id'] ) ) : '';
149 $sidebar_id = isset( $_GET['sidebar_id'] ) ? sanitize_text_field( wp_unslash( $_GET['sidebar_id'] ) ) : '';
150 $widget_nonce = isset( $_GET['widget_nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['widget_nonce'] ) ) : '';
151
152 if (
153 empty( $widget_id ) ||
154 empty( $sidebar_id ) ||
155 empty( $widget_nonce ) ||
156 0 !== strpos( $widget_id, self::WIDGET_ID ) ||
157 ! wp_verify_nonce( $widget_nonce, $this->get_widget_nonce_action( $widget_id, $sidebar_id ) )
158 ) {
159 wp_die();
160 }
161
162 if( isset($wp_registered_widgets[$widget_id]) && isset($wp_registered_sidebars[$sidebar_id]) && isset($wp_registered_widgets[$widget_id]["callback"])) {
163
164 $original_callback = $wp_registered_widgets[$widget_id]['callback'];
165
166 $params = [];
167
168 $params[] = $wp_registered_sidebars[$sidebar_id];
169
170 if (isset($wp_registered_widgets[ $widget_id ]['params'][0])) {
171 $params[] = $wp_registered_widgets[ $widget_id ]['params'][0];
172 }
173
174 if (is_callable($original_callback)) {
175
176 call_user_func_array($original_callback, $params);
177 }
178 }
179
180 wp_die();
181 }
182 }
183