PluginProbe
My WP Customize Admin/Frontend / trunk
My WP Customize Admin/Frontend vtrunk
1.27.4 1.27.3 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.10 1.10.1 1.10.2 1.11 1.12 1.12.1 1.12.2 1.13 1.13.1 1.13.2 1.14 1.15.0 1.16 1.17.0 All 76 releases
my-wp / shortcode / modules / mywp.shortcode.module.update_count.php

mywp.shortcode.module.update_count.php in My WP Customize Admin/Frontend trunk, at shortcode/modules/mywp.shortcode.module.update_count.php

107 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 if( ! class_exists( 'MywpShortcodeAbstractModule' ) ) {
8 return false;
9 }
10
11 if ( ! class_exists( 'MywpShortcodeModuleUpdateCount' ) ) :
12
13 final class MywpShortcodeModuleUpdateCount extends MywpShortcodeAbstractModule {
14
15 protected static $id = 'mywp_update_count';
16
17 public static function do_shortcode( $atts = false , $content = false , $tag = false ) {
18
19 $type = 'total';
20
21 if( ! empty( $atts['type'] ) ) {
22
23 $type = strip_tags( $atts['type'] );
24
25 }
26
27 $update_count = self::get_update_count( $type );
28
29 if( empty( $update_count ) ) {
30
31 return $content;
32
33 }
34
35 if( ! empty( $atts['tag'] ) ) {
36
37 $class = 'update';
38
39 if( $type === 'plugins' ) {
40
41 $class = 'plugin';
42
43 } elseif( $type === 'themes' ) {
44
45 $class = 'theme';
46
47 } elseif( $type === 'translations' ) {
48
49 $class = 'translation';
50
51 }
52
53 $content = sprintf(
54 '<span class="update-plugins count-%d"><span class="%s-count">%s</span></span>',
55 $update_count,
56 $class,
57 number_format_i18n( $update_count )
58 );
59
60 } else {
61
62 $content = $update_count;
63
64 }
65
66 $content = apply_filters( 'mywp_shortcode_update_count' , $content , $atts );
67
68 return $content;
69
70 }
71
72 private static function get_update_count( $type = '' ) {
73
74 if( empty( $type ) ) {
75
76 return 0;
77
78 }
79
80 $type = strip_tags( $type );
81
82 $wp_update_data = wp_get_update_data();
83
84 if( ! isset( $wp_update_data['counts'][ $type ] ) ) {
85
86 MywpHelper::error_not_found_message( $type , sprintf( '[%s] shortcode' , self::$id ) );
87
88 return 0;
89
90 }
91
92 if( empty( $wp_update_data['counts'] ) ) {
93
94 return 0;
95
96 }
97
98 return (int) $wp_update_data['counts'][ $type ];
99
100 }
101
102 }
103
104 MywpShortcodeModuleUpdateCount::init();
105
106 endif;
107