prefix . 'quietadmin_events'; $charset_collate = $wpdb->get_charset_collate(); // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- schema definition, no user input. $sql = "CREATE TABLE {$table_name} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, event_type varchar(40) NOT NULL DEFAULT '', event varchar(120) NOT NULL DEFAULT '', title varchar(255) NOT NULL DEFAULT '', user_id bigint(20) unsigned NOT NULL DEFAULT 0, meta longtext NULL, created_at datetime NOT NULL DEFAULT '1970-01-01 00:00:00', PRIMARY KEY (id), KEY event_type (event_type), KEY created_at (created_at), KEY type_created (event_type,created_at) ) {$charset_collate};"; // phpcs:enable require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( $sql ); update_option( 'quietadmin_db_version', QUIETADMIN_DB_VERSION ); } /** * Creates the client role. * * @since 0.1.0 * * @return void */ public static function install_roles() { $existing = get_role( Roles::CLIENT_ROLE ); if ( null === $existing ) { add_role( Roles::CLIENT_ROLE, __( 'Client (OMS QuietAdmin)', 'oms-quietadmin' ), Roles::client_capabilities() ); } } /** * Removes plugin data on uninstall. * * Called from uninstall.php. Whether data is deleted * is controlled by the `delete_on_uninstall` option (default: off). * * @since 0.1.0 * * @return void */ public static function uninstall() { global $wpdb; $settings = get_option( 'quietadmin_settings', array() ); $delete = is_array( $settings ) && ! empty( $settings['delete_on_uninstall'] ); // Always clean up cron jobs. wp_clear_scheduled_hook( Reports::CRON_DAILY ); wp_clear_scheduled_hook( 'quietadmin_monthly_report' ); if ( ! $delete ) { return; } delete_option( 'quietadmin_settings' ); delete_option( 'quietadmin_db_version' ); delete_option( 'quietadmin_version' ); delete_option( 'quietadmin_pro_version' ); delete_option( 'quietadmin_last_check' ); delete_option( 'quietadmin_status_result' ); delete_option( 'quietadmin_external_status' ); // Remove user meta (Ghost Mode, impersonation). $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE 'quietadmin\_%'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared // Remove transients. $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_quietadmin\_%' OR option_name LIKE '\_transient\_timeout\_quietadmin\_%'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.NotPrepared // Collect plugin capabilities: capabilities_map() returns // role => capabilities, so the capability names are in the // *values* (the keys are role names - the old code mistakenly used // array_keys() and therefore removed nothing). $map = Roles::capabilities_map(); $caps = array(); foreach ( $map as $role_caps ) { foreach ( array_keys( (array) $role_caps ) as $cap ) { $caps[ $cap ] = true; } } // Additionally cover the qa_* capabilities of the client role. foreach ( array_keys( Roles::client_capabilities() ) as $cap ) { if ( 0 === strpos( $cap, 'qa_' ) ) { $caps[ $cap ] = true; } } // Capability added by the premium code. $caps['qa_impersonate'] = true; // Remove capabilities from all affected roles (administrator, // editor, client, and any roles added via filter). foreach ( array_keys( $caps ) as $cap ) { foreach ( array_keys( $map ) as $role_key ) { $wp_role = get_role( $role_key ); if ( $wp_role ) { $wp_role->remove_cap( $cap ); } } } // Remove the client role itself (including leftover capabilities). $role = get_role( Roles::CLIENT_ROLE ); if ( $role ) { foreach ( array_keys( $caps ) as $cap ) { $role->remove_cap( $cap ); } remove_role( Roles::CLIENT_ROLE ); } // Drop the log table. $table_name = $wpdb->prefix . 'quietadmin_events'; $wpdb->query( "DROP TABLE IF EXISTS {$table_name}" ); // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared } }