| 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 |
|