PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.1.7
Adminify – White Label, Admin Menu Editor, Login Customizer v3.1.7
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Modules / ActivityLogs / Inc / DB_Table.php

DB_Table.php in Adminify – White Label, Admin Menu Editor, Login Customizer 3.1.7, at Inc/Modules/ActivityLogs/Inc/DB_Table.php

121 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPAdminify\Inc\Modules\ActivityLogs\Inc;
4
5 // no direct access allowed
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8 }
9
10 class DB_Table {
11
12 public function __construct() {
13 // add_action('plugins_loaded', [$this, 'init']);
14 $this->init();
15 }
16
17 // Activation/Deactivation Hook
18 public function init() {
19 add_action( 'wp_initialize_site', [ 'WPAdminify\Inc\Modules\ActivityLogs\Inc\DB_Table', 'adminify_new_mu_site_installer' ], 30 );
20 add_filter( 'wpmu_drop_tables', [ 'WPAdminify\Inc\Modules\ActivityLogs\Inc\DB_Table', 'adminify_mu_drop_tables' ], 30 );
21 }
22
23 public static function adminify_mu_drop_tables( $tables ) {
24 global $wpdb;
25
26 $tables['adminify_activity_logs'] = $wpdb->prefix . 'adminify_activity_logs';
27 $tables['adminify_page_speed'] = $wpdb->prefix . 'adminify_page_speed';
28
29 return $tables;
30 }
31
32 public static function adminify_new_mu_site_installer( $site ) {
33 global $wpdb;
34
35 if ( is_plugin_active_for_network( WP_ADMINIFY_BASE ) ) {
36 $old_blog_id = $wpdb->blogid;
37 switch_to_blog( $site->blog_id );
38 self::adminify_logs_create_table();
39 switch_to_blog( $old_blog_id );
40 }
41 }
42
43 public static function activation_hook( $network_wide ) {
44 global $wpdb;
45
46 if ( function_exists( 'is_multisite' ) && is_multisite() && $network_wide ) {
47 $old_blog_id = $wpdb->blogid;
48
49 $blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" );
50 foreach ( $blog_ids as $blog_id ) {
51 switch_to_blog( $blog_id );
52 self::adminify_logs_create_table();
53 }
54
55 switch_to_blog( $old_blog_id );
56 } else {
57 self::adminify_logs_create_table();
58 }
59 }
60
61 public static function deactivation_hook( $network_deactivating ) {
62 global $wpdb;
63
64 if ( function_exists( 'is_multisite' ) && is_multisite() && $network_deactivating ) {
65 $old_blog_id = $wpdb->blogid;
66
67 $blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs};" );
68 foreach ( $blog_ids as $blog_id ) {
69 switch_to_blog( $blog_id );
70 self::delete_table();
71 }
72
73 switch_to_blog( $old_blog_id );
74 } else {
75 self::delete_table();
76 }
77 }
78
79 protected static function delete_table() {
80 global $wpdb;
81
82 $wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}adminify_activity_logs`;" );
83
84 $admin_role = get_role( 'administrator' );
85 if ( $admin_role && $admin_role->has_cap( 'view_all_adminify_activity_logs' ) ) {
86 $admin_role->remove_cap( 'view_all_adminify_activity_logs' );
87 }
88
89 delete_option( 'adminify_activity_logs_version' );
90 }
91
92
93 protected static function adminify_logs_create_table() {
94 global $wpdb;
95
96 $sql_query = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}adminify_activity_logs` (
97 `log_id` int(11) NOT NULL AUTO_INCREMENT,
98 `user_caps` varchar(70) NOT NULL DEFAULT 'guest',
99 `action` varchar(255) NOT NULL,
100 `object_type` varchar(255) NOT NULL,
101 `object_subtype` varchar(255) NOT NULL DEFAULT '',
102 `object_name` varchar(255) NOT NULL,
103 `object_id` int(11) NOT NULL DEFAULT '0',
104 `user_id` int(11) NOT NULL DEFAULT '0',
105 `log_ip` varchar(55) NOT NULL DEFAULT '127.0.0.1',
106 `log_time` int(11) NOT NULL DEFAULT '0',
107 PRIMARY KEY (`log_id`)
108 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
109
110 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
111 dbDelta( $sql_query );
112
113 $admin_role = get_role( 'administrator' );
114 if ( $admin_role instanceof \WP_Role && ! $admin_role->has_cap( 'view_all_adminify_activity_logs' ) ) {
115 $admin_role->add_cap( 'view_all_adminify_activity_logs' );
116 }
117
118 update_option( 'adminify_activity_logs_version', WP_ADMINIFY_VER );
119 }
120 }
121