The logIO() WordPress PHP function writes logging information to a file.
Usage
logIO( $io, $msg );
Example:
logIO( 'input', 'User submitted a form.' );
Parameters
$io (string)
– Required. Whether input or output.$msg (string)
– Required. Information describing the logging reason.
More information
See WordPress Developer Resources: logIO()
Examples
Log a successful user login
In this example, the logIO() function is used to log a successful user login.
function log_successful_login() { logIO( 'input', 'User has successfully logged in.' ); } add_action( 'wp_login', 'log_successful_login' );
Log a failed login attempt
This example logs a failed login attempt using the logIO() function.
function log_failed_login( $username ) { logIO( 'input', 'Failed login attempt for username: ' . $username ); } add_action( 'wp_login_failed', 'log_failed_login' );
Log user registration
Here, the logIO() function is used to log user registration.
function log_user_registration( $user_id ) { logIO( 'input', 'New user registered with user ID: ' . $user_id ); } add_action( 'user_register', 'log_user_registration' );
Log post publication
In this example, the logIO() function logs when a post is published.
function log_post_publication( $post_id ) { logIO( 'input', 'Post published with post ID: ' . $post_id ); } add_action( 'publish_post', 'log_post_publication' );
Log a user logout
This example logs a user logout using the logIO() function.
function log_user_logout() { logIO( 'input', 'User has logged out.' ); } add_action( 'wp_logout', 'log_user_logout' );