It is my first time and I am writing to you because I have a private project I am working on about a website.

Actually, I am creating a wordpress website and for diverse reasons I need 4 of my accounts (Subscriber role) to change their own passwords automatically every 6 hours (and of course knowing a way to know the new password).

I am kind of an eternal beginner on PHP but I can roughly read some code even if I can't write my own.

In fact, I found this code on this very website from an other user and I was wondering if that could help me to do what I want, by editing few things ?

Thanks for reading and at your disposal for any further question.

Code :

 * Plugin Name: Auto Post-Password Changer
 * Description: Schedule a wp-cron password update event that runs every 2nd day  
 * Plugin URI:  http://wordpress.stackexchange.com/a/174820/26350
 * Author:      Birgir Erlendsson (birgire)
 * Version:     0.0.1

add_action( 'wpse_change_pass_event', function()
    // Update the post password for a given slug.
    // See for example: http://wordpress.stackexchange.com/a/130535/26350

    $slug = 'hello-world'; // Edit this post slug to your needs!

    global $wpdb;
        array( 'post_password' => uniqid() ),
        array( 'post_name'     => $slug    ),
        array( '%s' ),
        array( '%s' )

add_filter( 'cron_schedules', function( $schedules )

// Our custom cron interval:
    $schedules['every_2nd_day'] = array(
        'interval'  => 2 * DAY_IN_SECONDS,
        'display'   => 'Once every second day'

    return $schedules;

register_activation_hook( __FILE__, function()            
    // Start the cron job:
    wp_schedule_event( time(), 'every_2nd_day', 'wpse_change_pass_event' );

register_deactivation_hook( __FILE__, function()
    // Stop the cron job:
    wp_clear_scheduled_hook( 'wpse_change_pass_event' );

From here : Automatically change page password

  • If I ask for some help, it is because I can't get it to work properly and I need someone to help me understanding it and how I could modify this code. There is no need to give me minus points because you think I didn't search more on the internet. Who do you think you are ?... If you don't wanna help, good for you, but leave other people opportunity to help other people. – Johnny John Jul 22 at 4:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.