帖子/页面密码存储在wp_posts
中的表post_password
领域
您可以尝试以下演示插件,在的帮助下自动更新post密码wp-cron. 您也可以考虑transients 或custom post meta.
<?php
/**
* 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;
$wpdb->update(
$wpdb->posts,
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\' );
});
您只需修改
$slug
要修改的页面的。
请注意,您需要访问站点才能激活wp cron。
这里我们使用PHP函数uniqid()
生成密码,其形式如下:
我希望您能将此扩展到您的需要。