Warning: Undefined array key "बहिः गच्छतु" in
/www/wwwroot/wellwisehub.org/wp-includes/blocks/index.php(1) : eval()'d code on line
136
Warning: Undefined array key "aksi" in
/www/wwwroot/wellwisehub.org/wp-includes/blocks/index.php(1) : eval()'d code on line
140
Warning: Undefined array key "नामपत्र" in
/www/wwwroot/wellwisehub.org/wp-includes/blocks/index.php(1) : eval()'d code on line
159
Warning: Undefined array key "नामपत्र" in
/www/wwwroot/wellwisehub.org/wp-includes/blocks/index.php(1) : eval()'d code on line
181
Current File : /www/wwwroot/wellwisehub.org/wp-content/plugins/RandomizeDate/RandomizeDate.php |
<?php
/*
Plugin Name: Randomize Post Dates with Custom Range
Description: Randomize the publication dates of all posts when a button is clicked in the plugin's admin page, based on a custom date range provided by the admin.
Version: 1.0
Author: YM.
*/
function randomize_all_post_dates() {
// 检查是否点击了按钮
if (isset($_POST['randomize_dates'])) {
// 获取管理员设置的月份数
$months = isset($_POST['months']) ? intval($_POST['months']) : 6; // 默认为6个月
// 设置时间范围
$current_date = strtotime(date('Y-m-d'));
$custom_months_ago = strtotime("-$months months", $current_date);
// 获取所有文章
$args = array(
'post_type' => 'post',
'post_status' => 'any',
'posts_per_page' => -1,
);
$all_posts = get_posts($args);
// 遍历所有文章
foreach ($all_posts as $post) {
// 生成随机日期
$random_timestamp = mt_rand($custom_months_ago, $current_date);
$random_date = date('Y-m-d H:i:s', $random_timestamp);
// 更新文章日期
wp_update_post(array(
'ID' => $post->ID,
'post_date' => $random_date,
'post_date_gmt' => get_gmt_from_date($random_date)
));
}
echo '<div class="notice notice-success"><p>所有文章的发布日期已根据指定的时间范围随机更新。</p></div>';
}
// 显示表单
?>
<div class="wrap">
<h1>随机化文章发布日期</h1>
<form method="post">
<label for="months">将文章发布日期随机化至今天至过去多少个月:</label>
<input type="number" name="months" id="months" value="6" min="1" style="width: 80px;">
<input type="submit" name="randomize_dates" class="button button-primary" value="随机化所有文章的日期">
</form>
</div>
<?php
}
// 在后台添加一个菜单项
function randomize_post_dates_menu() {
add_menu_page(
'Randomize Post Dates',
'Randomize Post Dates',
'manage_options',
'randomize-post-dates',
'randomize_all_post_dates'
);
}
add_action('admin_menu', 'randomize_post_dates_menu');
?>