PluginProbe
Counters Block – showcase your stats with animated numbers / trunk
Counters Block – showcase your stats with animated numbers vtrunk
2.0.8 2.0.7 trunk 1.0.0 1.0.1 1.0.2 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6
counters-block / build / render.php

render.php in Counters Block – showcase your stats with animated numbers trunk, at build/render.php

70 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 $id = wp_unique_id( 'ctrbCounters-' );
3
4 // Process dynamic data sources
5 $is_premium = function_exists( 'ctrbIsPremium' ) ? ctrbIsPremium() : false;
6
7 if ( $is_premium && isset( $attributes['counters'] ) && is_array( $attributes['counters'] ) ) {
8 foreach ( $attributes['counters'] as $index => $counter ) {
9 $number_settings = isset( $counter['number'] ) ? $counter['number'] : array();
10 $data_source = isset( $attributes['dataSource'] ) ? $attributes['dataSource'] : 'static';
11
12 if ( 'wp_stats' === $data_source ) {
13 $stat_type = isset( $number_settings['statType'] ) ? $number_settings['statType'] : 'posts';
14 $dynamic_value = 0;
15
16 switch ( $stat_type ) {
17 case 'posts':
18 $dynamic_value = ctrbGetWpPostsCount();
19 break;
20 case 'pages':
21 $dynamic_value = ctrbGetWpPagesCount();
22 break;
23 case 'comments':
24 $dynamic_value = ctrbGetWpCommentsCount();
25 break;
26 case 'users':
27 $dynamic_value = ctrbGetWpUsersCount();
28 break;
29 }
30
31 $attributes['counters'][ $index ]['number']['end'] = (int) $dynamic_value;
32 } elseif ( 'wc_stats' === $data_source ) {
33 $stat_type = isset( $number_settings['statType'] ) ? $number_settings['statType'] : 'sales';
34 $dynamic_value = 0;
35
36 if ( class_exists( 'WooCommerce' ) ) {
37 switch ( $stat_type ) {
38 case 'sales':
39 $dynamic_value = ctrbGetWcSales();
40 break;
41 case 'orders':
42 $dynamic_value = ctrbGetWcOrdersCount();
43 break;
44 case 'products':
45 $dynamic_value = ctrbGetWcProductsCount();
46 break;
47 case 'customers':
48 $dynamic_value = ctrbGetWcCustomersCount();
49 break;
50 }
51 }
52
53 $attributes['counters'][ $index ]['number']['end'] = (float) $dynamic_value;
54 }
55 }
56 }
57
58 extract( $attributes );
59
60 // if( isset( $icon['class'] ) && !empty( $icon['class'] ) ){
61 // wp_enqueue_style( 'font-awesome-7' );
62 // }
63 // wp_enqueue_style( 'font-awesome-7' );
64 ?>
65 <div
66 <?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_block_wrapper_attributes() is properly escaped ?>
67 <?php echo get_block_wrapper_attributes(); ?>
68 id='<?php echo esc_attr( $id ); ?>'
69 data-attributes='<?php echo esc_attr( wp_json_encode( $attributes ) ); ?>'
70 ></div>