roles ) ? implode( ',', (array) $user->roles ) : ''; Softvolt_Ai_Bodyguard_Logger::log( 'info', 'login_success', sprintf( /* translators: 1: user login, 2: roles */ __( 'User "%1$s" logged in (%2$s).', 'ai-guardwall' ), $user_login, $roles ), array( 'roles' => $roles ), $user->ID ); } public static function logout( $user_id ) { Softvolt_Ai_Bodyguard_Logger::log( 'info', 'logout', sprintf( /* translators: %d: user ID */ __( 'User #%d logged out.', 'ai-guardwall' ), (int) $user_id ), array(), (int) $user_id ); } public static function user_register( $user_id ) { $user = get_userdata( $user_id ); if ( ! $user ) { return; } $roles = implode( ',', (array) $user->roles ); Softvolt_Ai_Bodyguard_Logger::log( 'notice', 'user_created', sprintf( /* translators: 1: user login, 2: user email, 3: roles */ __( 'User "%1$s" (%2$s) was created with role: %3$s.', 'ai-guardwall' ), $user->user_login, $user->user_email, $roles ), array( 'new_user' => $user_id ) ); if ( in_array( 'administrator', (array) $user->roles, true ) ) { Softvolt_Ai_Bodyguard_Logger::log( 'critical', 'new_admin', sprintf( /* translators: %s: user login */ __( 'New ADMINISTRATOR account "%s" was created.', 'ai-guardwall' ), $user->user_login ), array( 'new_user' => $user_id ) ); do_action( 'svabg_new_admin_user', $user_id, 'user_register' ); } } public static function user_deleted( $id, $reassign ) { Softvolt_Ai_Bodyguard_Logger::log( 'notice', 'user_deleted', sprintf( /* translators: 1: ID, 2: value */ __( 'User #%1$d was deleted (content reassigned to #%2$s).', 'ai-guardwall' ), (int) $id, $reassign ? (string) $reassign : '-' ) ); } public static function role_changed( $user_id, $role, $old_roles ) { $user = get_userdata( $user_id ); $name = $user ? $user->user_login : '#' . $user_id; Softvolt_Ai_Bodyguard_Logger::log( 'notice', 'user_role_changed', sprintf( /* translators: 1: name, 2: list of old roles, 3: role */ __( 'Role of "%1$s" changed from %2$s to %3$s.', 'ai-guardwall' ), $name, implode( ',', (array) $old_roles ), $role ), array( 'target' => $user_id ) ); if ( 'administrator' === $role && ! in_array( 'administrator', (array) $old_roles, true ) ) { Softvolt_Ai_Bodyguard_Logger::log( 'critical', 'new_admin', sprintf( /* translators: %s: name */ __( 'User "%s" was promoted to ADMINISTRATOR.', 'ai-guardwall' ), $name ), array( 'target' => $user_id ) ); do_action( 'svabg_new_admin_user', $user_id, 'set_user_role' ); } } public static function profile_update( $user_id, $old ) { $user = get_userdata( $user_id ); if ( ! $user || ! $old ) { return; } $changes = array(); if ( $user->user_email !== $old->user_email ) { $changes[] = sprintf( 'email %s → %s', $old->user_email, $user->user_email ); } if ( $user->user_pass !== $old->user_pass ) { $changes[] = 'password'; } if ( $user->user_login !== $old->user_login ) { $changes[] = sprintf( 'username %s → %s', $old->user_login, $user->user_login ); } if ( ! empty( $changes ) ) { Softvolt_Ai_Bodyguard_Logger::log( 'notice', 'user_updated', sprintf( /* translators: 1: user login, 2: list of changes */ __( 'User "%1$s" updated: %2$s.', 'ai-guardwall' ), $user->user_login, implode( ', ', $changes ) ), array( 'target' => $user_id ) ); } } public static function plugin_activated( $plugin ) { Softvolt_Ai_Bodyguard_Logger::log( 'notice', 'plugin_change', sprintf( /* translators: %s: plugin */ __( 'Plugin activated: %s', 'ai-guardwall' ), $plugin ) ); } public static function plugin_deactivated( $plugin ) { Softvolt_Ai_Bodyguard_Logger::log( 'notice', 'plugin_change', sprintf( /* translators: %s: plugin */ __( 'Plugin deactivated: %s', 'ai-guardwall' ), $plugin ) ); } public static function plugin_deleted( $plugin, $deleted ) { if ( $deleted ) { Softvolt_Ai_Bodyguard_Logger::log( 'notice', 'plugin_change', sprintf( /* translators: %s: plugin */ __( 'Plugin deleted: %s', 'ai-guardwall' ), $plugin ) ); } } public static function upgrader( $upgrader, $options ) { $type = isset( $options['type'] ) ? $options['type'] : ''; $action = isset( $options['action'] ) ? $options['action'] : ''; $items = array(); foreach ( array( 'plugins', 'themes' ) as $key ) { if ( ! empty( $options[ $key ] ) ) { $items = array_merge( $items, (array) $options[ $key ] ); } } if ( 'core' === $type ) { $items[] = 'WordPress core'; } Softvolt_Ai_Bodyguard_Logger::log( 'notice', 'plugin' === $type ? 'plugin_change' : ( 'theme' === $type ? 'theme_change' : 'option_change' ), sprintf( /* translators: 1: type, 2: action, 3: list of items */ __( '%1$s %2$s: %3$s', 'ai-guardwall' ), ucfirst( $type ), $action, implode( ', ', $items ) ) ); // Files changed: invalidate the cached official checksums for the changed plugins. if ( 'plugin' === $type ) { foreach ( $items as $file ) { $slug = dirname( $file ); delete_transient( 'svabg_plugin_sums_' . md5( $slug ) ); } } } public static function theme_switched( $new_name, $new_theme, $old_theme ) { Softvolt_Ai_Bodyguard_Logger::log( 'notice', 'theme_change', sprintf( /* translators: %s: new name */ __( 'Theme switched to "%s".', 'ai-guardwall' ), $new_name ) ); } public static function theme_deleted( $stylesheet, $deleted ) { if ( $deleted ) { Softvolt_Ai_Bodyguard_Logger::log( 'notice', 'theme_change', sprintf( /* translators: %s: stylesheet */ __( 'Theme deleted: %s', 'ai-guardwall' ), $stylesheet ) ); } } public static function option_updated( $option, $old, $new ) { $watch = array( 'siteurl', 'home', 'admin_email', 'default_role', 'users_can_register', 'active_plugins', 'template', 'stylesheet', 'upload_path', 'upload_url_path', 'blog_public', 'WPLANG' ); if ( ! in_array( $option, $watch, true ) ) { return; } $fmt = function ( $v ) { return Softvolt_Ai_Bodyguard_Helpers::trim_text( is_scalar( $v ) ? (string) $v : Softvolt_Ai_Bodyguard_Helpers::esc_json( $v ), 300 ); }; Softvolt_Ai_Bodyguard_Logger::log( 'notice', 'option_change', sprintf( /* translators: 1: option, 2: value, 3: value */ __( 'Option "%1$s" changed from "%2$s" to "%3$s".', 'ai-guardwall' ), $option, $fmt( $old ), $fmt( $new ) ) ); } public static function file_editor() { // Only a real save from the editor: WordPress's own nonce for this file (its action names the file, so // the file name is read with it), checked before anything else; WordPress checks it again before saving. if ( ! current_user_can( 'edit_plugins' ) && ! current_user_can( 'edit_themes' ) ) { return; } if ( ! isset( $_POST['nonce'], $_POST['file'] ) ) { return; } $nonce = sanitize_text_field( wp_unslash( $_POST['nonce'] ) ); $file = sanitize_text_field( wp_unslash( $_POST['file'] ) ); $theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : ''; // The action WordPress signs the editor's nonce with: one per theme file, or one per plugin file. $action = '' !== $theme ? 'edit-theme_' . $theme . '_' . $file : 'edit-plugin_' . $file; if ( ! wp_verify_nonce( $nonce, $action ) ) { return; } if ( ! current_user_can( '' !== $theme ? 'edit_themes' : 'edit_plugins' ) ) { return; } Softvolt_Ai_Bodyguard_Logger::log( 'warning', 'file_edit', sprintf( /* translators: %s: file */ __( 'The built-in file editor was used on: %s', 'ai-guardwall' ), $file ) ); } public static function password_reset( $user ) { Softvolt_Ai_Bodyguard_Logger::log( 'notice', 'user_updated', sprintf( /* translators: %s: user login */ __( 'Password reset completed for "%s".', 'ai-guardwall' ), $user->user_login ), array(), $user->ID ); } public static function retrieve_password( $user_login ) { Softvolt_Ai_Bodyguard_Logger::log( 'info', 'user_updated', sprintf( /* translators: %s: user login */ __( 'Password reset requested for "%s".', 'ai-guardwall' ), $user_login ) ); } public static function app_password( $user_id, $item ) { $name = isset( $item['name'] ) ? $item['name'] : ''; Softvolt_Ai_Bodyguard_Logger::log( 'notice', 'user_updated', sprintf( /* translators: 1: name, 2: user ID */ __( 'Application password "%1$s" created for user #%2$d.', 'ai-guardwall' ), $name, (int) $user_id ), array(), (int) $user_id ); } }