Plugin Directory

Changeset 3145605


Ignore:
Timestamp:
09/02/2024 09:16:49 PM (18 months ago)
Author:
temak
Message:

v1.0.1

Location:
auto-update-post-date/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • auto-update-post-date/trunk/README.txt

    r3075290 r3145605  
    11=== Auto Update Post Date ===
    22Contributors: temak
    3 Donate link: https://temak.dev/
     3Donate link: https://github.com/sponsors/git-temak
    44Tags: update, posts, bulk, date, auto
    55Requires at least: 3.0.1
    6 Tested up to: 6.4.3
     6Tested up to: 6.6.1
    77Requires PHP: 7.2
    8 Stable tag: 1.0.0
     8Stable tag: 1.0.1
    99License: GPLv3 or later
    1010License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    9191* Initial release
    9292
     93= 1.0.1 =
     94* Fix offset not working correctly in auto mode
     95* Add logs
     96
    9397== Upgrade Notice ==
    9498* None
  • auto-update-post-date/trunk/auto-update-post-date.php

    r3075290 r3145605  
    33Plugin Name: Auto Update Post Date
    44Description: 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.0
     5Version:        1.0.1
    66Author:         Temak
    77Author URI:     https://temak.dev
     
    3737add_action('admin_menu', 'tmaupd_menu_page');
    3838
     39// log events to file
     40function 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
    3949// Load script and styles
    4050function tmaupd_load_scripts_styles()
     
    4252    wp_enqueue_script('cs-jsDatetimePicker', plugin_dir_url(__FILE__) . 'inc/jquery.datetimepicker.full.min.js', array('jquery'), '1.0.0', true);
    4353    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');
    4656}
    4757
  • auto-update-post-date/trunk/inc/aupd.css

    r3075290 r3145605  
    1515}
    1616
    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 {
    1827    max-height: 400px;
    1928    overflow-y: scroll;
    2029    padding: 20px;
    2130    background-color: #0e253d;
     31}
     32
     33#tmaupd_log_area {
     34    color: #fff;
    2235}
    2336
     
    3245    }
    3346}
    34 
    3547
    3648/* checkbox styles */
  • auto-update-post-date/trunk/inc/aupd.js

    r3075290 r3145605  
    11jQuery(document).ready(function($) {
    22
    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');
    77    let taxonomyModeGroup = $('#filter-taxy-radio-group');
    88    let singPostModeGroup = $('#filter-spost-radio-group');
    9     let filterModeChecked = $('#aupd_post_filter_mode_status');
     9    let filterModeChecked = $('#tmaupd_post_filter_mode_status');
    1010    let selectedDateTime = $('#aupd_manual_date_time');
    1111    let dateTimeRow = $('#aupd-container .form-table tr:nth-child(4)');
     
    1313    let taxPostsRow = $('#aupd-container #aupd-taxonomy-posts');
    1414    let singPostPostsRow = $('#aupd-container #aupd-specific-posts-list');
    15     let autoOffsetChecked = $('#aupd_auto_mode_period_offset');
     15    let autoOffsetChecked = $('#tmaupd_auto_mode_period_offset');
    1616    let autoOffsetOptions = $('#aupd-container .aupd_auto_mode_period_offset_value');
    1717
     
    4242            dateTimeRow.show();
    4343            autoFreqRow.hide();
    44             $('#aupd-container #aupd_auto_mode_period_daily').prop('required', false);
     44            $('#aupd-container #tmaupd_auto_mode_period_daily').prop('required', false);
    4545            $('#aupd-container .aupd_auto_mode_period_offset_value > input').val('');
    4646        }
     
    4949            autoFreqRow.show();
    5050            selectedDateTime.val('');
    51             $('#aupd-container #aupd_auto_mode_period_daily').prop('required', true);
     51            $('#aupd-container #tmaupd_auto_mode_period_daily').prop('required', true);
    5252        }
    5353    }
     
    115115    });
    116116
     117    // toggle visibility of log area
     118    $('#tmaupd_view_button').click(function() {
     119        $('#tmaupd_log_area').toggle();
     120    });
     121
    117122});
  • auto-update-post-date/trunk/inc/auto-update-post-date-runner.php

    r3075290 r3145605  
    3737    add_settings_field('tmaupd_manual_date', 'Select date', 'tmaupd_manual_date_callback', 'tmaupd_plugin_settings', 'tmaupd_plugin_section');
    3838    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');
    3940
    4041    register_setting('tmaupd_plugin_settings_group', 'tmaupd_plugin_mode_radio', 'sanitize_text_field');
     
    4344    register_setting('tmaupd_plugin_settings_group', 'tmaupd_manual_date', 'sanitize_text_field');
    4445    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');
    4547}
    4648add_action('admin_init', 'tmaupd_plugin_settings_init');
     
    5052    ?>
    5153    <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 />
    5355    <label for="tmaupd_plugin_mode_manual_radio">Manual</label>
    5456    <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); ?> />
    5658    <label for="tmaupd_plugin_mode_auto_radio">Auto</label>
    5759    <?php
     
    99101    ?>
    100102    <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);?> />
    102104    <label for="tmaupd_post_filter_mode_status">Filter posts</label>
    103105    <br>
     
    107109    <div id="filter-taxy-radio-group">
    108110        <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); ?> />
    110112        <label for="tmaupd_post_filter_mode_taxes">Taxonomies (e.g. categories, tags, etc.)</label>
    111113    </div>
    112114    <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); ?> />
    114116        <label for="tmaupd_post_filter_mode_ind_posts">Specific posts</label>
    115117    </div>
     
    186188    ?>
    187189    <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 />
    189191    <label for="tmaupd_post_dates_pub_mod_date">Published & modified dates</label>
    190192    <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); ?> />
    192194    <label for="tmaupd_post_dates_pub_date">Published date</label>
    193195    <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); ?> />
    195197    <label for="tmaupd_post_dates_mod_date">Modified date</label>
    196198    <?php
     
    200202    $value = get_option('tmaupd_manual_datetime');
    201203    ?>
    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 changed to 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>
    203205    <br>
    204206    <?php
     
    220222    ?>
    221223    <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); ?> />
    223225    <label for="tmaupd_auto_mode_period_daily">Daily</label>
    224226    <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); ?> />
    226228    <label for="tmaupd_auto_mode_period_weekly">Weekly</label>
    227229    <!-- <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); ?> />
    229231    <label for="tmaupd_auto_mode_period_monthly">Monthly</label> -->
    230232    <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);?> />
    232234    <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>
    234236    <br>
    235237    <div class="aupd_auto_mode_period_offset_value">
     
    241243    </div>
    242244    <?php
     245}
     246
     247function 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        }
    243262}
    244263
     
    274293        $offset_mode_val = absint($_POST['tmaupd_auto_mode_period_offset_value']);
    275294        $offset_mode_unit = sanitize_text_field($_POST['tmaupd_auto_mode_period_offset_unit']);
     295        $keep_logs = sanitize_text_field($_POST['tmaupd_keep_log']);
    276296        $plugin_post_types = [];    // store selected post types
    277297
     
    318338            'tmaupd_auto_mode_offset_mode',
    319339            'tmaupd_auto_mode_offset_value',
    320             'tmaupd_auto_mode_offset_unit'
     340            'tmaupd_auto_mode_offset_unit',
     341            'tmaupd_keep_log'
    321342        ];
    322343
     
    333354        update_option('tmaupd_auto_mode_offset_value', $offset_mode_val);
    334355        update_option('tmaupd_auto_mode_offset_unit', $offset_mode_unit);
     356        update_option('tmaupd_keep_log', $keep_logs);
    335357
    336358        foreach($postTypes as $cpt){
     
    391413    $aupd_post_dates_update = get_option('tmaupd_post_dates_update');
    392414    $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');
    394415    $aupd_auto_mode_offset_mode = get_option('tmaupd_auto_mode_offset_mode');
    395416    $aupd_auto_mode_offset_value = get_option('tmaupd_auto_mode_offset_value');
    396417    $aupd_auto_mode_offset_unit = get_option('tmaupd_auto_mode_offset_unit');
     418    $keep_logs = get_option('tmaupd_keep_log') ?: false;
    397419
    398420    // set dates to be updated based on selected option
     
    462484                        '%d'
    463485                    );
     486
     487                    if ($keep_logs && $updated) {
     488                        tmaupd_log_updates(get_the_title() . ' updated successfully');
     489                    }
    464490                }
    465491            }
     
    480506                    '%d'
    481507                );
     508
     509                if ($keep_logs && $updated) {
     510                    tmaupd_log_updates(get_the_title($pid) . ' updated successfully');
     511                }
    482512            }
    483513        }
     
    499529                    '%d'
    500530                );
     531
     532                if ($keep_logs && $updated) {
     533                    tmaupd_log_updates(get_the_title() . ' updated successfully');
     534                }
    501535            }
    502536        }
     
    515549            while ($postsQuery->have_posts()) {
    516550                $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                }
    517571
    518572                // set date to current date
     
    544598                );
    545599
    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');
    549602                }
    550603            }
Note: See TracChangeset for help on using the changeset viewer.