PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.5
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.5
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | classes/Visualizer/Module/Frontend.php +45 -20 3.4.43.4.5 View file →
@@ -240,13 +240,16 @@
240 240 public function renderChart( $atts ) {
241 241 global $wp_version;
242 242 $atts = shortcode_atts(
243 243 array(
244 - 'id' => false, // chart id
245 - 'class' => false, // chart class
246 - 'series' => false, // series filter hook
247 - 'data' => false, // data filter hook
248 - 'settings' => false, // data filter hook
244 + // chart id
245 + 'id' => false,
246 + // chart class
247 + 'class' => false,
248 + // for lazy load
249 + // set 'yes' to use the default intersection limit (300px)
250 + // OR set a number (e.g. 700) to use 700px as the intersection limit
251 + 'lazy' => apply_filters( 'visualizer_lazy_by_default', false, $atts['id'] ),
249 252 ),
250 253 $atts
251 254 );
252 255
@@ -254,8 +257,9 @@
254 257 if ( ! $atts['id'] || ! ( $chart = get_post( $atts['id'] ) ) || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
255 258 return '';
256 259 }
257 260
261 + // do not show the chart?
258 262 if ( ! apply_filters( 'visualizer_pro_show_chart', true, $atts['id'] ) ) {
259 263 return '';
260 264 }
261 265
@@ -267,11 +271,21 @@
267 271
268 272 $id = 'visualizer-' . $atts['id'];
269 273 $defaultClass = 'visualizer-front';
270 274 $class = apply_filters( Visualizer_Plugin::FILTER_CHART_WRAPPER_CLASS, $atts['class'], $atts['id'] );
271 - $class = $defaultClass . ' ' . $class . ' ' . 'visualizer-front-' . $atts['id'];
272 - $class = ! empty( $class ) ? ' class="' . trim( $class ) . '"' : '';
273 275
276 + $lazyClass = $atts['lazy'] === 'yes' || ctype_digit( $atts['lazy'] ) ? 'visualizer-lazy' : '';
277 +
278 + $class = sprintf( '%s %s %s %s', $defaultClass, $class, 'visualizer-front-' . $atts['id'], $lazyClass );
279 + $attributes = array();
280 + if ( ! empty( $class ) ) {
281 + $attributes['class'] = trim( $class );
282 + }
283 +
284 + if ( ctype_digit( $atts['lazy'] ) ) {
285 + $attributes['data-lazy-limit'] = $atts['lazy'];
286 + }
287 +
274 288 $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
275 289
276 290 $chart = apply_filters( 'visualizer_schedule_refresh_chart', $chart, $chart->ID, false );
277 291
@@ -282,22 +296,14 @@
282 296 }
283 297
284 298 // handle series filter hooks
285 299 $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
286 - if ( ! empty( $atts['series'] ) ) {
287 - $series = apply_filters( $atts['series'], $series, $chart->ID, $type );
288 - }
300 +
289 301 // handle settings filter hooks
290 302 $settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type );
291 - if ( ! empty( $atts['settings'] ) ) {
292 - $settings = apply_filters( $atts['settings'], $settings, $chart->ID, $type );
293 - }
294 303
295 304 // handle data filter hooks
296 305 $data = self::get_chart_data( $chart, $type );
297 - if ( ! empty( $atts['data'] ) ) {
298 - $data = apply_filters( $atts['data'], $data, $chart->ID, $type );
299 - }
300 306
301 307 $css = '';
302 308 $arguments = $this->get_inline_custom_css( $id, $settings );
303 309 if ( ! empty( $arguments ) ) {
@@ -310,9 +316,9 @@
310 316 $id = $id . '-' . rand();
311 317
312 318 $amp = Visualizer_Plugin::instance()->getModule( Visualizer_Module_AMP::NAME );
313 319 if ( $amp && $amp->is_amp() ) {
314 - return '<div id="' . $id . '"' . $class . '>' . $amp->get_chart( $chart, $data, $series, $settings ) . '</div>';
320 + return '<div id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '>' . $amp->get_chart( $chart, $data, $series, $settings ) . '</div>';
315 321 }
316 322
317 323 // add chart to the array
318 324 $this->_charts[ $id ] = array(
@@ -354,10 +360,10 @@
354 360 }
355 361
356 362 $actions_div .= $css;
357 363
358 - foreach ( $this->_charts as $id => $attributes ) {
359 - $library = $attributes['library'];
364 + foreach ( $this->_charts as $id => $array ) {
365 + $library = $array['library'];
360 366 wp_register_script(
361 367 "visualizer-render-$library",
362 368 VISUALIZER_ABSURL . 'js/render-facade.js',
363 369 apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true ),
@@ -384,9 +390,28 @@
384 390 wp_enqueue_style( 'visualizer-front' );
385 391 }
386 392
387 393 // return placeholder div
388 - return $actions_div . '<div id="' . $id . '"' . $class . '></div>' . $this->addSchema( $chart->ID );
394 + return $actions_div . '<div id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '></div>' . $this->addSchema( $chart->ID );
395 + }
396 +
397 + /**
398 + * Converts the array of attributes to a string of HTML attributes.
399 + *
400 + * @since ?
401 + *
402 + * @access private
403 + */
404 + private function getHtmlAttributes( $attributes ) {
405 + $string = '';
406 + if ( ! $attributes ) {
407 + return $string;
408 + }
409 +
410 + foreach ( $attributes as $name => $value ) {
411 + $string .= sprintf( '%s="%s"', esc_attr( $name ), esc_attr( $value ) );
412 + }
413 + return $string;
389 414 }
390 415
391 416 /**
392 417 * Adds the schema corresponding to the dataset.