PluginProbe
SweepPress: Website Cleanup and Optimization / 2.0
SweepPress: Website Cleanup and Optimization v2.0
trunk 1.1 1.2 1.3 1.4 1.4.1 1.5 1.6 1.7 1.8 2.0 2.1 2.1.1 2.2 2.3 2.3.1 2.4 2.4.1 2.4.2 2.5 2.6 3.0 3.1 3.1.1 3.2 All 39 releases
sweeppress / core / basic / Data.php

Data.php in SweepPress: Website Cleanup and Optimization 2.0, at core/basic/Data.php

134 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dev4Press\Plugin\SweepPress\Basic;
4
5 use Dev4Press\v39\Core\Quick\Str;
6 use Dev4Press\v39\Core\Scope;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 class Data {
13 public static function get_post_types() : array {
14 $list = Cache::instance()->get( 'data', 'post_types' );
15
16 if ( ! $list ) {
17 $raw = get_post_types( array(), 'objects' );
18 $list = wp_list_pluck( $raw, 'label', 'name' );
19
20 Cache::instance()->add( 'data', 'post_types', $list );
21 }
22
23 return $list;
24 }
25
26 public static function get_taxonomies() : array {
27 $list = Cache::instance()->get( 'data', 'taxonomies' );
28
29 if ( ! $list ) {
30 $raw = get_taxonomies( array(), 'objects' );
31 $list = wp_list_pluck( $raw, 'label', 'name' );
32
33 Cache::instance()->add( 'data', 'taxonomies', $list );
34 }
35
36 return $list;
37 }
38
39 public static function get_comment_types() : array {
40 $list = Cache::instance()->get( 'data', 'comment_types' );
41
42 if ( ! $list ) {
43 $list = array(
44 'comment' => __( "Comment", "sweeppress" ),
45 'trackback' => __( "Trackback", "sweeppress" ),
46 'pingback' => __( "Pingback", "sweeppress" ),
47 'gdrts-user-review' => __( "Rating User Review", "sweeppress" )
48 );
49
50 $list_from_db = sweeppress_db()->get_comment_types();
51
52 foreach ( $list_from_db as $type => $label ) {
53 if ( ! isset( $list[ $type ] ) ) {
54 $list_from_db[ $type ] = $label;
55 }
56 }
57
58 Cache::instance()->add( 'data', 'comment_types', $list );
59 }
60
61 return $list;
62 }
63
64 public static function get_database_stats() : array {
65 $list = Cache::instance()->get( 'database', 'stats' );
66
67 if ( ! $list ) {
68 $tables = array(
69 'comments',
70 'commentmeta',
71 'posts',
72 'postmeta',
73 'options',
74 'terms',
75 'termmeta',
76 'term_taxonomy',
77 'term_relationships',
78 'users',
79 'usermeta'
80 );
81
82 $list = array();
83
84 foreach ( $tables as $table ) {
85 $list[ $table ] = sweeppress_db()->get_table_rows_count( sweeppress_db()->prefix . $table );
86 }
87
88 if ( Scope::instance()->is_multisite() ) {
89 $list['sitemeta'] = sweeppress_db()->get_table_rows_count( sweeppress_db()->base_prefix . 'sitemeta' );
90 }
91
92 Cache::instance()->add( 'database', 'stats', $list );
93 }
94
95 return $list;
96 }
97
98 public static function get_db_table_rows( $table ) {
99 $list = Data::get_database_stats();
100
101 return $list[ $table ] ?? 0;
102 }
103
104 public static function get_post_type_title( string $post_type ) : string {
105 $post_types = Data::get_post_types();
106
107 if ( isset( $post_types[ $post_type ] ) ) {
108 return $post_types[ $post_type ];
109 }
110
111 return Str::slug_to_name( $post_type );
112 }
113
114 public static function get_taxonomy_title( string $taxonomy ) : string {
115 $taxonomies = Data::get_taxonomies();
116
117 if ( isset( $taxonomies[ $taxonomy ] ) ) {
118 return $taxonomies[ $taxonomy ];
119 }
120
121 return Str::slug_to_name( $taxonomy );
122 }
123
124 public static function get_comment_type_title( string $comment_type ) : string {
125 $types = Data::get_comment_types();
126
127 if ( isset( $types[ $comment_type ] ) ) {
128 return $types[ $comment_type ];
129 }
130
131 return Str::slug_to_name( $comment_type );
132 }
133 }
134