Changeset 3145605
- Timestamp:
- 09/02/2024 09:16:49 PM (18 months ago)
- Location:
- auto-update-post-date/trunk
- Files:
-
- 5 edited
-
README.txt (modified) (2 diffs)
-
auto-update-post-date.php (modified) (3 diffs)
-
inc/aupd.css (modified) (2 diffs)
-
inc/aupd.js (modified) (5 diffs)
-
inc/auto-update-post-date-runner.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
auto-update-post-date/trunk/README.txt
r3075290 r3145605 1 1 === Auto Update Post Date === 2 2 Contributors: temak 3 Donate link: https:// temak.dev/3 Donate link: https://github.com/sponsors/git-temak 4 4 Tags: update, posts, bulk, date, auto 5 5 Requires at least: 3.0.1 6 Tested up to: 6. 4.36 Tested up to: 6.6.1 7 7 Requires PHP: 7.2 8 Stable tag: 1.0. 08 Stable tag: 1.0.1 9 9 License: GPLv3 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 91 91 * Initial release 92 92 93 = 1.0.1 = 94 * Fix offset not working correctly in auto mode 95 * Add logs 96 93 97 == Upgrade Notice == 94 98 * None -
auto-update-post-date/trunk/auto-update-post-date.php
r3075290 r3145605 3 3 Plugin Name: Auto Update Post Date 4 4 Description: Keep your WordPress content evergreen with Auto Update Post Date – a simple WP plugin designed to effortlessly update your posts and boost SEO. Bid farewell to outdated information as this plugin takes care of the heavy lifting for you! 5 Version: 1.0. 05 Version: 1.0.1 6 6 Author: Temak 7 7 Author URI: https://temak.dev … … 37 37 add_action('admin_menu', 'tmaupd_menu_page'); 38 38 39 // log events to file 40 function tmaupd_log_updates($log, $date = true){ 41 $filename = plugin_dir_path(__FILE__). 'aupd_log.txt'; 42 if ($date){ 43 file_put_contents($filename, $log . ' - ' . date('Y-m-d H:i:s') . "\n\n", FILE_APPEND); 44 } else { 45 file_put_contents($filename, $log . "\n\n", FILE_APPEND); 46 } 47 } 48 39 49 // Load script and styles 40 50 function tmaupd_load_scripts_styles() … … 42 52 wp_enqueue_script('cs-jsDatetimePicker', plugin_dir_url(__FILE__) . 'inc/jquery.datetimepicker.full.min.js', array('jquery'), '1.0.0', true); 43 53 wp_enqueue_style('cs-jsDatetimePickerStyle', plugin_dir_url(__FILE__) . 'inc/jquery.datetimepicker.min.css', array(), '1.0.0', 'all'); 44 wp_enqueue_script('tmaupdscript', plugin_dir_url(__FILE__) . 'inc/aupd.js', array('jquery'), '1.0. 0', true);45 wp_enqueue_style('tmaupdstyles', plugin_dir_url(__FILE__) . 'inc/aupd.css', array(), '1.0. 0', 'all');54 wp_enqueue_script('tmaupdscript', plugin_dir_url(__FILE__) . 'inc/aupd.js', array('jquery'), '1.0.1', true); 55 wp_enqueue_style('tmaupdstyles', plugin_dir_url(__FILE__) . 'inc/aupd.css', array(), '1.0.1', 'all'); 46 56 } 47 57 -
auto-update-post-date/trunk/inc/aupd.css
r3075290 r3145605 15 15 } 16 16 17 .aupd-all-posts-list { 17 #tmaupd_view_button { 18 margin: 20px 0; 19 background-color: #111; 20 color: #fff; 21 border-radius: 4px; 22 padding: 10px 25px; 23 width: fit-content; 24 } 25 26 .aupd-all-posts-list, #tmaupd_log_area { 18 27 max-height: 400px; 19 28 overflow-y: scroll; 20 29 padding: 20px; 21 30 background-color: #0e253d; 31 } 32 33 #tmaupd_log_area { 34 color: #fff; 22 35 } 23 36 … … 32 45 } 33 46 } 34 35 47 36 48 /* checkbox styles */ -
auto-update-post-date/trunk/inc/aupd.js
r3075290 r3145605 1 1 jQuery(document).ready(function($) { 2 2 3 let manualModeChecked = $('# aupd_plugin_mode_manual_radio');4 let autoModeChecked = $('# aupd_plugin_mode_auto_radio');5 let taxonomyModeChecked = $('# aupd_post_filter_mode_taxes');6 let singPostModeChecked = $('# aupd_post_filter_mode_ind_posts');3 let manualModeChecked = $('#tmaupd_plugin_mode_manual_radio'); 4 let autoModeChecked = $('#tmaupd_plugin_mode_auto_radio'); 5 let taxonomyModeChecked = $('#tmaupd_post_filter_mode_taxes'); 6 let singPostModeChecked = $('#tmaupd_post_filter_mode_ind_posts'); 7 7 let taxonomyModeGroup = $('#filter-taxy-radio-group'); 8 8 let singPostModeGroup = $('#filter-spost-radio-group'); 9 let filterModeChecked = $('# aupd_post_filter_mode_status');9 let filterModeChecked = $('#tmaupd_post_filter_mode_status'); 10 10 let selectedDateTime = $('#aupd_manual_date_time'); 11 11 let dateTimeRow = $('#aupd-container .form-table tr:nth-child(4)'); … … 13 13 let taxPostsRow = $('#aupd-container #aupd-taxonomy-posts'); 14 14 let singPostPostsRow = $('#aupd-container #aupd-specific-posts-list'); 15 let autoOffsetChecked = $('# aupd_auto_mode_period_offset');15 let autoOffsetChecked = $('#tmaupd_auto_mode_period_offset'); 16 16 let autoOffsetOptions = $('#aupd-container .aupd_auto_mode_period_offset_value'); 17 17 … … 42 42 dateTimeRow.show(); 43 43 autoFreqRow.hide(); 44 $('#aupd-container # aupd_auto_mode_period_daily').prop('required', false);44 $('#aupd-container #tmaupd_auto_mode_period_daily').prop('required', false); 45 45 $('#aupd-container .aupd_auto_mode_period_offset_value > input').val(''); 46 46 } … … 49 49 autoFreqRow.show(); 50 50 selectedDateTime.val(''); 51 $('#aupd-container # aupd_auto_mode_period_daily').prop('required', true);51 $('#aupd-container #tmaupd_auto_mode_period_daily').prop('required', true); 52 52 } 53 53 } … … 115 115 }); 116 116 117 // toggle visibility of log area 118 $('#tmaupd_view_button').click(function() { 119 $('#tmaupd_log_area').toggle(); 120 }); 121 117 122 }); -
auto-update-post-date/trunk/inc/auto-update-post-date-runner.php
r3075290 r3145605 37 37 add_settings_field('tmaupd_manual_date', 'Select date', 'tmaupd_manual_date_callback', 'tmaupd_plugin_settings', 'tmaupd_plugin_section'); 38 38 add_settings_field('tmaupd_auto_mode_period', 'Select frequency', 'tmaupd_auto_mode_period_callback', 'tmaupd_plugin_settings', 'tmaupd_plugin_section'); 39 add_settings_field('tmaupd_keep_log', 'Keep log', 'tmaupd_keep_log_callback', 'tmaupd_plugin_settings', 'tmaupd_plugin_section'); 39 40 40 41 register_setting('tmaupd_plugin_settings_group', 'tmaupd_plugin_mode_radio', 'sanitize_text_field'); … … 43 44 register_setting('tmaupd_plugin_settings_group', 'tmaupd_manual_date', 'sanitize_text_field'); 44 45 register_setting('tmaupd_plugin_settings_group', 'tmaupd_auto_mode_period', 'sanitize_text_field'); 46 register_setting('tmaupd_plugin_settings_group', 'tmaupd_keep_log', 'sanitize_text_field'); 45 47 } 46 48 add_action('admin_init', 'tmaupd_plugin_settings_init'); … … 50 52 ?> 51 53 <p>Set how you want to update post dates; manually or let the plugin automatically update post dates periodically.</p> 52 <input id=" aupd_plugin_mode_manual_radio" type="radio" name="tmaupd_plugin_mode_radio" value="manual_mode" <?php checked('manual_mode', $value); ?> required />54 <input id="tmaupd_plugin_mode_manual_radio" type="radio" name="tmaupd_plugin_mode_radio" value="manual_mode" <?php checked('manual_mode', $value); ?> required /> 53 55 <label for="tmaupd_plugin_mode_manual_radio">Manual</label> 54 56 <br> 55 <input id=" aupd_plugin_mode_auto_radio" type="radio" name="tmaupd_plugin_mode_radio" value="auto_mode" <?php checked('auto_mode', $value); ?> />57 <input id="tmaupd_plugin_mode_auto_radio" type="radio" name="tmaupd_plugin_mode_radio" value="auto_mode" <?php checked('auto_mode', $value); ?> /> 56 58 <label for="tmaupd_plugin_mode_auto_radio">Auto</label> 57 59 <?php … … 99 101 ?> 100 102 <br> 101 <input id=" aupd_post_filter_mode_status" type="checkbox" name="tmaupd_post_filter_mode_status" value="checked" <?php echo esc_attr($filter_on);?> />103 <input id="tmaupd_post_filter_mode_status" type="checkbox" name="tmaupd_post_filter_mode_status" value="checked" <?php echo esc_attr($filter_on);?> /> 102 104 <label for="tmaupd_post_filter_mode_status">Filter posts</label> 103 105 <br> … … 107 109 <div id="filter-taxy-radio-group"> 108 110 <br> 109 <input id=" aupd_post_filter_mode_taxes" type="radio" name="tmaupd_post_filter_mode" value="taxonomy_mode" <?php checked('taxonomy_mode', $filter_mode); ?> />111 <input id="tmaupd_post_filter_mode_taxes" type="radio" name="tmaupd_post_filter_mode" value="taxonomy_mode" <?php checked('taxonomy_mode', $filter_mode); ?> /> 110 112 <label for="tmaupd_post_filter_mode_taxes">Taxonomies (e.g. categories, tags, etc.)</label> 111 113 </div> 112 114 <div id="filter-spost-radio-group"> 113 <input id=" aupd_post_filter_mode_ind_posts" type="radio" name="tmaupd_post_filter_mode" value="individual_post_mode" <?php checked('individual_post_mode', $filter_mode); ?> />115 <input id="tmaupd_post_filter_mode_ind_posts" type="radio" name="tmaupd_post_filter_mode" value="individual_post_mode" <?php checked('individual_post_mode', $filter_mode); ?> /> 114 116 <label for="tmaupd_post_filter_mode_ind_posts">Specific posts</label> 115 117 </div> … … 186 188 ?> 187 189 <p>Select if the published date or modified date of the post should be updated, or both. Default is <i><strong>modified date</i></strong>.</p> 188 <input id=" aupd_post_dates_pub_mod_date" type="radio" name="tmaupd_post_dates_update" value="tmaupd_pub_mod_date" <?php checked('tmaupd_pub_mod_date', $value); ?> required />190 <input id="tmaupd_post_dates_pub_mod_date" type="radio" name="tmaupd_post_dates_update" value="tmaupd_pub_mod_date" <?php checked('tmaupd_pub_mod_date', $value); ?> required /> 189 191 <label for="tmaupd_post_dates_pub_mod_date">Published & modified dates</label> 190 192 <br> 191 <input id=" aupd_post_dates_pub_date" type="radio" name="tmaupd_post_dates_update" value="tmaupd_pub_date" <?php checked('tmaupd_pub_date', $value); ?> />193 <input id="tmaupd_post_dates_pub_date" type="radio" name="tmaupd_post_dates_update" value="tmaupd_pub_date" <?php checked('tmaupd_pub_date', $value); ?> /> 192 194 <label for="tmaupd_post_dates_pub_date">Published date</label> 193 195 <br> 194 <input id=" aupd_post_dates_mod_date" type="radio" name="tmaupd_post_dates_update" value="tmaupd_mod_date" <?php checked('tmaupd_mod_date', $value); ?> />196 <input id="tmaupd_post_dates_mod_date" type="radio" name="tmaupd_post_dates_update" value="tmaupd_mod_date" <?php checked('tmaupd_mod_date', $value); ?> /> 195 197 <label for="tmaupd_post_dates_mod_date">Modified date</label> 196 198 <?php … … 200 202 $value = get_option('tmaupd_manual_datetime'); 201 203 ?> 202 <p>Set the date and time to be updated on all selected posts. Note that selecting a future date will make your post status to be changedto scheduled.</p>204 <p>Set the date and time to be updated on all selected posts. Note that selecting a future date will set your post status to scheduled.</p> 203 205 <br> 204 206 <?php … … 220 222 ?> 221 223 <p>Set how frequently the post dates should be updated. Default is <i><strong>weekly</i></strong>.</p> 222 <input id=" aupd_auto_mode_period_daily" type="radio" name="tmaupd_auto_mode_freq" value="daily" <?php checked('daily', $value); ?> />224 <input id="tmaupd_auto_mode_period_daily" type="radio" name="tmaupd_auto_mode_freq" value="daily" <?php checked('daily', $value); ?> /> 223 225 <label for="tmaupd_auto_mode_period_daily">Daily</label> 224 226 <br> 225 <input id=" aupd_auto_mode_period_weekly" type="radio" name="tmaupd_auto_mode_freq" value="weekly" <?php checked('weekly', $value); ?> />227 <input id="tmaupd_auto_mode_period_weekly" type="radio" name="tmaupd_auto_mode_freq" value="weekly" <?php checked('weekly', $value); ?> /> 226 228 <label for="tmaupd_auto_mode_period_weekly">Weekly</label> 227 229 <!-- <br> 228 <input id=" aupd_auto_mode_period_monthly" type="radio" name="tmaupd_auto_mode_freq" value="monthly" <?php //checked('monthly', $value); ?> />230 <input id="tmaupd_auto_mode_period_monthly" type="radio" name="tmaupd_auto_mode_freq" value="monthly" <?php //checked('monthly', $value); ?> /> 229 231 <label for="tmaupd_auto_mode_period_monthly">Monthly</label> --> 230 232 <br><br> 231 <input type="checkbox" id=" aupd_auto_mode_period_offset" name="tmaupd_auto_mode_offset" value="checked" <?php echo esc_html($offset_ticked);?> />233 <input type="checkbox" id="tmaupd_auto_mode_period_offset" name="tmaupd_auto_mode_offset" value="checked" <?php echo esc_html($offset_ticked);?> /> 232 234 <label for="tmaupd_auto_mode_period_offset">Offset post dates?</label><br> 233 <sub>Tick this option if you don't want all updated posts to have the same publish time and you would like to offset the selected posts by set time<br><i><strong>e.g. 15 mins offset means that if Post 1's date is 1 Jan 2024, 09: 00, Post 2's date will be 1 Jan 2024, 09:15.</i></strong></sub>235 <sub>Tick this option if you don't want all updated posts to have the same publish time and you would like to offset the selected posts by set time<br><i><strong>e.g. 15 mins offset means that if Post 1's date is 1 Jan 2024, 09:30, Post 2's date will be any time between Post 1's date and 1 Jan 2024, 09:45.</i></strong></sub> 234 236 <br> 235 237 <div class="aupd_auto_mode_period_offset_value"> … … 241 243 </div> 242 244 <?php 245 } 246 247 function tmaupd_keep_log_callback() { 248 $value = get_option('tmaupd_keep_log'); 249 ?> 250 <p>Tick this to keep a log of posts that are updated.</p> 251 <input id="tmaupd_keep_log" type="checkbox" name="tmaupd_keep_log" value="checked" <?php echo esc_attr($value);?> /> 252 <label for="tmaupd_keep_log">Keep log</label> 253 <br> 254 <?php 255 // show log file content 256 $log_file = trailingslashit(dirname(plugin_dir_path(__FILE__))) . 'aupd_log.txt'; 257 if (file_exists($log_file) && filesize($log_file) > 0) { 258 $log_content = file_get_contents($log_file); 259 echo '<div id="tmaupd_view_button"><button data-viewstate="false">View Log</button></div>'; 260 echo '<textarea id="tmaupd_log_area" readonly rows="20" cols="100">' . esc_html($log_content) . '</textarea>'; 261 } 243 262 } 244 263 … … 274 293 $offset_mode_val = absint($_POST['tmaupd_auto_mode_period_offset_value']); 275 294 $offset_mode_unit = sanitize_text_field($_POST['tmaupd_auto_mode_period_offset_unit']); 295 $keep_logs = sanitize_text_field($_POST['tmaupd_keep_log']); 276 296 $plugin_post_types = []; // store selected post types 277 297 … … 318 338 'tmaupd_auto_mode_offset_mode', 319 339 'tmaupd_auto_mode_offset_value', 320 'tmaupd_auto_mode_offset_unit' 340 'tmaupd_auto_mode_offset_unit', 341 'tmaupd_keep_log' 321 342 ]; 322 343 … … 333 354 update_option('tmaupd_auto_mode_offset_value', $offset_mode_val); 334 355 update_option('tmaupd_auto_mode_offset_unit', $offset_mode_unit); 356 update_option('tmaupd_keep_log', $keep_logs); 335 357 336 358 foreach($postTypes as $cpt){ … … 391 413 $aupd_post_dates_update = get_option('tmaupd_post_dates_update'); 392 414 $aupd_manual_datetime = ($aupd_plugin_mode_radio == 'manual_mode') ? get_option('tmaupd_manual_datetime') : null; 393 $aupd_auto_mode_freq = get_option('tmaupd_auto_mode_freq');394 415 $aupd_auto_mode_offset_mode = get_option('tmaupd_auto_mode_offset_mode'); 395 416 $aupd_auto_mode_offset_value = get_option('tmaupd_auto_mode_offset_value'); 396 417 $aupd_auto_mode_offset_unit = get_option('tmaupd_auto_mode_offset_unit'); 418 $keep_logs = get_option('tmaupd_keep_log') ?: false; 397 419 398 420 // set dates to be updated based on selected option … … 462 484 '%d' 463 485 ); 486 487 if ($keep_logs && $updated) { 488 tmaupd_log_updates(get_the_title() . ' updated successfully'); 489 } 464 490 } 465 491 } … … 480 506 '%d' 481 507 ); 508 509 if ($keep_logs && $updated) { 510 tmaupd_log_updates(get_the_title($pid) . ' updated successfully'); 511 } 482 512 } 483 513 } … … 499 529 '%d' 500 530 ); 531 532 if ($keep_logs && $updated) { 533 tmaupd_log_updates(get_the_title() . ' updated successfully'); 534 } 501 535 } 502 536 } … … 515 549 while ($postsQuery->have_posts()) { 516 550 $postsQuery->the_post(); 551 552 if ($aupd_auto_mode_offset_mode == 'checked') { 553 $offset_value = $aupd_auto_mode_offset_value; 554 $offset_unit = $aupd_auto_mode_offset_unit; 555 556 $offset_in_seconds = 0; 557 558 switch ($offset_unit) { 559 case 'hours': 560 $offset_in_seconds = $offset_value * 3600; 561 break; 562 default: 563 $offset_in_seconds = $offset_value * 60; 564 break; 565 } 566 567 $min_time = strtotime($current_date) - $offset_in_seconds; 568 $random_time = mt_rand($min_time, strtotime($current_date)); 569 $current_date = date($upd_date_format, $random_time); 570 } 517 571 518 572 // set date to current date … … 544 598 ); 545 599 546 if ($aupd_auto_mode_offset_mode == 'checked') { 547 $offset = strtotime('+' . $aupd_auto_mode_offset_value . $aupd_auto_mode_offset_unit, time()); 548 $current_date = gmdate($upd_date_format, $offset); 600 if ($keep_logs && $updated) { 601 tmaupd_log_updates(get_the_title() . ' updated successfully'); 549 602 } 550 603 }
Note: See TracChangeset
for help on using the changeset viewer.