Plugin Directory

Changeset 3207488


Ignore:
Timestamp:
12/13/2024 09:36:17 AM (16 months ago)
Author:
cubixsol
Message:

README.txt

Location:
auto-refresh-post-page
Files:
13 added
12 edited

Legend:

Unmodified
Added
Removed
  • auto-refresh-post-page/README.txt

    r3063386 r3207488  
    11Auto Refresh Post & Page
    2 Tested up to: 6.5
    3 Requires at least: 5.4
    4 Tested up to: 6.5
    5 Requires PHP: 7.0
    6 Stable tag: 1.0.1
     2Tested up to: 6.3
    73License: GPLv2 or later
    84Contributors:
    9 Tags: Auto refresh, Post refresh, Page refresh, Scheduled refresh, Content refresh
     5Tags: Auto refresh, Post refresh, Page refresh, Scheduled refresh, Custom refresh timing, Post type refresh, Automatic refresh, Content refresh
    106
    11 Automate post/page refreshing for up-to-date content & improved user engagement.
    127
    138== Description ==
     
    3429
    3530The current version of the plugin is 1.0.1
     31
     32== New Update ==
     33
     34A select field where user can select the unit of time like Hours, Minutes, Seconds along time field
    3635
    3736
     
    7978Using this plugin, you can schedule the content refresh to keep the website fresh and up-to-date which improves user engagement and show them fresh content.
    8079It also saves time as you don't need to manually refresh the pages and posts.
    81 
    82 == Changelog ==
    83 
    84 =1.0.1=
    85 * improved design
    86 * remove bugs
    87 * increase reponse time
    88 
    89 =1.0.0=
    90 * First stable version
  • auto-refresh-post-page/admin/css/auto-refresh-post-page-admin.css

    r3063383 r3207488  
    11.sucess_msg {
    22  width: 200px;
    3   background-color: #2a2b5f;
     3  background-color: rgb(2, 98, 2);
    44  color: white;
    55  border-radius: 5px;
     
    99  display: grid;
    1010  place-items: center;
    11   margin: 40px 0px ;
     11  margin: 40px 40px ;
    1212  border-radius: 15px;
    1313}
     
    1717input[type="checkbox"] {
    1818  display: inline-block;
     19}
     20input[type=number]{
     21  min-height: 36px;
    1922}
    2023label.cb-tab-content__label {
     
    3033  padding: 10px 25px;
    3134  font-size: 1.3em;
    32   background-color: #2a2b5f;
     35  background-color: rgb(2, 98, 2);
    3336  color: white;
    3437  border-radius: 10px;
    3538  border: 0px;
    3639  cursor: pointer;
    37   margin: 0px 0px ;
     40  margin: 0px 40px ;
    3841}
    3942#cb_global_save_post:hover {
     
    5255  table-layout: fixed;
    5356}
    54 .select_style_all {
    55   padding-top: 30px;
    56   padding-bottom: 30px;
    57 }
    58 .select_check_all {
    59   width: 122px;
    60   float: left;
    61   padding-top: 5px;
    62   padding-left: 10px;
    63 }
    64 .universal_time_input {
    65   width: 200px;
    66   float: left;
    67 }
    6857table.widefatsett {
    6958  background: #fff;
     59}
     60.wp-core-ui select {
     61  padding: 4px 24px 2px 8px;
     62  margin-bottom: 3px;
    7063}
    7164table.widefatsett {
     
    7568.widefatsett {
    7669  border-spacing: 0;
    77   width: 99%;
     70  width: 100%;
    7871  clear: both;
    7972  margin: 0;
     
    116109.widefatsett {
    117110  border-spacing: 0;
    118   width: 99%;
     111  width: 100%;
    119112  clear: both;
    120113  margin: 0;
     
    186179.widefatsett {
    187180  border-spacing: 0;
    188   width: 99%;
     181  width: 100%;
    189182  clear: both;
    190183  margin: 0;
  • auto-refresh-post-page/admin/js/auto-refresh-post-page-admin.js

    r2990642 r3207488  
    2323                  var value = jQuery(this).val();
    2424                  data[key] = value;
    25                 });
     25             
     26                  // Include the selected time unit
     27                  var timeUnitKey = 'time_unit-' + key.split('-')[1];
     28                  var timeUnitValue = jQuery(this).siblings('.js-time-unit').val();
     29                  data[timeUnitKey] = timeUnitValue;
     30              });
    2631                console.log(data);
    2732                // var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
  • auto-refresh-post-page/admin/partials/auto_refresh_post_page-admin-dashboard.php

    r3063383 r3207488  
    88 * @link       https://cubixsol.org/
    99 * @since      1.0.0
    10  *
    1110 *
    1211 * @package    Auto_refresh_post_page
     
    3534 <h1>Set Refresh Frequency</h1>
    3635 <hr class="cb-divider" />
    37     <div class="select_style_all">
    38         <div class="select_check_all">
    39             <input type="checkbox" class="js-select-all">&nbsp;Select All &nbsp;
    40         </div>
    41         <div class="universal_time_input">
    42             <input type="number" placeholder="Enter Time in Seconds globallly" class="timeField" id="timeField" min=0 >
    43         </div>
    44     </div>
     36    <tr>
     37    <th style="text-align: left;">
     38        <input type="checkbox" class="js-select-all">&nbsp;Select All
     39        &nbsp;
     40        <input type="number" placeholder="Enter Time in Seconds globally" class="timeField" id="timeField" min="0" oninput="updateGlobalTime(this)">
     41        <select id="globalTimeUnit" class="globalTimeUnit" onchange="updateGlobalTimeUnit(this)">
     42            <option value="seconds">Seconds</option>
     43            <option value="minutes">Minutes</option>
     44            <option value="hours">Hours</option>
     45        </select>
     46    </th>
     47    </tr>
    4548       
    46  <table class="cb-tab-content__table cb-tab-content__table--padding wp-list-table widefatsett fixedsett striped table-view-list pages">&nbsp;
     49 <table class="cb-tab-content__table cb-tab-content__table--padding wp-list-table widefatsett fixedsett striped table-view-list pages"><br>&nbsp;
    4750       
    4851    <tr>
     
    6164        $post_types = get_post_types( $args, $output, $operator );
    6265         
    63         foreach ( $post_types as $post_type ) { ?>
     66        foreach ($post_types as $post_type) { ?>
    6467            <tr>
    65                 <?php 
    66                     $array_from_db = get_option( 'ARPP_my_option_name' );
    67 
    68                     if(isset($array_from_db[$post_type]) && $array_from_db[$post_type] == 1 ) {
    69                         $checkbox="checked";
    70                     }else{
    71                         $checkbox = "";
    72                     }
    73 
    74                     if(isset($array_from_db["duration-".$post_type]) && $array_from_db["duration-".$post_type] != '' ) {
    75                         $repeat_time=$array_from_db["duration-".$post_type];
    76                     }else{     
    77                         $repeat_time = "";
    78                     }   
     68                <?php
     69                $array_from_db = get_option('ARPP_my_option_name');
     70       
     71                // Checkbox logic: Match the exact key with the `checkbox-` prefix
     72                $checkbox_key = "checkbox-" . $post_type;
     73                $checkbox = isset($array_from_db[$checkbox_key]) && $array_from_db[$checkbox_key] == 1 ? "checked" : "";
     74       
     75                // Time field logic
     76                $duration_key = "duration-" . $post_type;
     77                $repeat_time = isset($array_from_db[$duration_key]) ? $array_from_db[$duration_key] : "";
     78       
     79                // Time unit logic
     80                $time_unit_key = "time_unit-" . $post_type;
     81                $time_unit = isset($array_from_db[$time_unit_key]) ? $array_from_db[$time_unit_key] : "seconds";
    7982                ?>
    80          
    81                 <td class="check_title">
    82                     <input type="checkbox" name="checkbox-<?php echo esc_html($post_type); ?>" value="1"  class="js-cb-customization js-select-single" id="cb-feedback-<?php echo esc_html($post_type); ?>" data-key="feedbackTitle" <?php echo esc_html($checkbox); ?>>
    83                 </td>
    84                 <td>   
    85                     <?php echo esc_html($post_type); ?>&nbsp;
    86                 </td>
     83                <td class="check_title">
     84                    <input type="checkbox" name="checkbox-<?php echo esc_html($post_type); ?>" value="1"
     85                        class="js-cb-customization js-select-single"
     86                        id="cb-feedback-<?php echo esc_html($post_type); ?>"
     87                        <?php echo esc_html($checkbox); ?>>
     88                </td>
    8789                <td>
    88                     <input type="number" name="duration-<?php echo esc_html($post_type); ?>" value="<?php echo esc_html($repeat_time); ?>" placeholder="Enter Time in Seconds" id="time_set_field"  class="js-time-field" min=0 oninput="checkValue(this)">
    89                 </td>
    90             </tr>
     90                    <?php echo esc_html($post_type); ?>&nbsp;
     91                </td>
     92                <td>
     93                    <input type="number" name="duration-<?php echo esc_html($post_type); ?>"
     94                           value="<?php echo esc_html($repeat_time); ?>"
     95                           placeholder="Enter Time in Seconds"
     96                           class="js-time-field"
     97                           min="0">
     98                    <select name="time_unit-<?php echo esc_html($post_type); ?>" class="js-time-unit">
     99                        <option value="seconds" <?php selected($time_unit, 'seconds'); ?>>Seconds</option>
     100                        <option value="minutes" <?php selected($time_unit, 'minutes'); ?>>Minutes</option>
     101                        <option value="hours" <?php selected($time_unit, 'hours'); ?>>Hours</option>
     102                    </select>
     103                </td>
     104            </tr>
    91105    <?php } ?>
    92106 </table>
     
    110124
    111125
    112  function checkValue(input) {
    113     if (input.value < 0) {
    114         alert("Please enter a positive number.");
    115         input.value = 'Enter Time in Seconds';
    116     }
     126function updateGlobalTime(globalInput) {
     127    var timeFields = document.querySelectorAll('.js-time-field');
     128    timeFields.forEach(function(timeField) {
     129        timeField.value = globalInput.value;
     130    });
    117131
    118     if (input.value % 1 !== 0) {
    119         input.value = Math.floor(input.value);
    120         alert("Please enter a value without point");
    121     }
    122    
     132    // Automatically check all individual checkboxes if global input is used
     133    document.querySelectorAll('.js-select-single').forEach(function(checkbox) {
     134        checkbox.checked = true;
     135    });
     136}
     137
     138// Function to update all time unit fields with the global dropdown value
     139function updateGlobalTimeUnit(globalSelect) {
     140    var timeUnits = document.querySelectorAll('.js-time-unit');
     141    timeUnits.forEach(function(timeUnit) {
     142        timeUnit.value = globalSelect.value;
     143    });
     144
     145    // Automatically check all individual checkboxes if global select is used
     146    document.querySelectorAll('.js-select-single').forEach(function(checkbox) {
     147        checkbox.checked = true;
     148    });
     149}
     150
     151// Get the "Select All" checkbox
     152var selectAllCheckbox = document.querySelector('.js-select-all');
     153selectAllCheckbox.addEventListener('click', function() {
     154    var checkboxes = document.querySelectorAll('.js-select-single');
    123155    var timeFields = document.querySelectorAll('.js-time-field');
     156    var timeUnits = document.querySelectorAll('.js-time-unit');
     157    var globalTime = document.querySelector('#timeField').value;
     158    var globalUnit = document.querySelector('#globalTimeUnit').value;
    124159
    125     // Loop through each input field
    126     timeFields.forEach(function(timeField) {
    127         timeField.addEventListener('input', function() {
    128             var checkbox = timeField.previousElement.previousElement;
    129             checkbox.checked = true;
     160    // Apply the global setting to all individual fields and checkboxes
     161    checkboxes.forEach(function(checkbox) {
     162        checkbox.checked = selectAllCheckbox.checked;
     163    });
     164
     165    if (selectAllCheckbox.checked) {
     166        timeFields.forEach(function(timeField) {
     167            timeField.value = globalTime;
    130168        });
    131     });
    132  }
    133    
    134 
    135     // Get the "Select All" checkbox
    136  var selectAllCheckbox = document.querySelector('.js-select-all');
    137  selectAllCheckbox.addEventListener('click',
    138  function() {
    139     var checkboxes = document.querySelectorAll('.js-select-single');
    140     for (var i = 0; i < checkboxes.length; i++) {
    141         // Set the checked property of the checkbox to the same value as the "Select All" checkbox
    142         checkboxes[i].checked = selectAllCheckbox.checked;
    143     }
    144  });
    145 
    146  document.querySelector(".js-select-all").addEventListener("click", function() {
    147     if (this.checked) {
    148         document.querySelector(".timeField").addEventListener("input", function() {
    149             document.querySelectorAll(".js-time-field").forEach(element => element.value = this.value);
    150         });
    151     } else {
    152          document.querySelector(".timeField").removeEventListener("input", function() {
    153             document.querySelectorAll(".js-time-field").forEach(element => element.value = this.value);
     169        timeUnits.forEach(function(timeUnit) {
     170            timeUnit.value = globalUnit;
    154171        });
    155172    }
    156  });
     173});
    157174</script>
    158175
  • auto-refresh-post-page/auto-refresh-post-page.php

    r3063383 r3207488  
    11<?php
     2
    23/**
    34 * The plugin bootstrap file
     
    2526 *
    2627 *
    27  *       
     28 *                                                               
     29 *
    2830 *  ________      ___  ___      ________      ___      ___    ___  ________       ________      ___         
    2931 * |\   ____\    |\  \|\  \    |\   __  \    |\  \    |\  \  /  /||\   ____\     |\   __  \    |\  \         
     
    3436 *     \|_______|    \|_______|    \|_______|    \|__|/__/ /\ __\    |\_________\    \|_______|    \|_______|
    3537 *                                                    |__|/ \|__|    \|_________|       
     38 *                                     
     39 *                                                   
     40 *                                   
    3641 *                                       
    3742 */
     
    4550
    4651// Define plugin constants.
    47 define('ARPP_AUTO_REFRESH_VERSION', '1.0.0');
     52define('ARPP_AUTO_REFRESH_VERSION', '1.0.1');
    4853define('ARPP_AUTO_REFRESH_PLUGIN_URL', plugin_dir_url(__FILE__));
    4954define('ARPP_AUTO_REFRESH_PLUGIN_PATH', plugin_dir_path(__FILE__));
     
    9499function ARPP_store_refresh_settings()
    95100{
    96 
    97     if (!isset($_POST['ARPP_nonce']) || !wp_verify_nonce(sanitize_text_field($_POST['ARPP_nonce']), 'ARPP_store_refresh_settings_nonce')) {
     101    if (!isset($_POST['ARPP_nonce']) || !wp_verify_nonce(sanitize_text_field($_POST['ARPP_nonce']), 'ARPP_store_refresh_settings_nonce')) {
    98102        wp_send_json_error('Invalid nonce.');
    99103    }
    100104
    101     // Ensure the data received is an array and sanitize its elements.
    102     if (!isset($_POST['data']) || !is_array($_POST['data'])) {
    103         return;
    104     }
    105 
    106     $data = sanitize_text_field($_POST['data']);
    107     $new_data = array();
    108 
    109     foreach ($data as $key => $value) {
    110         // Sanitize the key and value.
    111         $key = sanitize_key($key);
    112         $value = sanitize_text_field($value);
    113 
    114         // Handle special case for checkboxes if needed.
    115         if (strpos($key, 'checkbox') !== false) {
    116             $exploded = explode('-', $key);
    117             $new_data[$exploded[1]] = $value;
    118         } else {
    119             $new_data[$key] = $value;
    120         }
    121     }
    122 
    123     // Store the sanitized data in the database.
    124     update_option('ARPP_my_option_name', $new_data);
     105    if (!isset($_POST['data']) || !is_array($_POST['data'])) {
     106        return;
     107    }
     108
     109    $data = $_POST['data'];
     110    $new_data = array();
     111
     112    foreach ($data as $key => $value) {
     113        $key = sanitize_key($key);
     114        $value = sanitize_text_field($value);
     115
     116        // Check for time unit and duration
     117        if (strpos($key, 'time_unit-') === 0 || strpos($key, 'duration-') === 0) {
     118            $new_data[$key] = $value;
     119        } else {
     120            $new_data[$key] = $value === '1' ? 1 : 0;
     121        }
     122    }
     123
     124    // Store the sanitized data
     125    update_option('ARPP_my_option_name', $new_data);
    125126}
    126127
     
    200201function ARPP_setrefreshtime()
    201202{
    202     $array_from_db = get_option('ARPP_my_option_name');
    203 
    204     foreach ($array_from_db as $key => $value) {
    205         // Sanitize the key and value.
    206         $key = sanitize_key($key);
    207         $value = absint($value);
    208 
    209         if ($value === 1) {
    210             $duration_key = "duration-" . $key;
    211             if (array_key_exists($duration_key, $array_from_db)) {
    212                 $seconds = absint($array_from_db[$duration_key]);
    213                 $args = array(
    214                     'post_type' => $key,
    215                     'posts_per_page' => -1
    216                 );
    217                 $pages = get_posts($args);
    218 
    219                 foreach ($pages as $page) {
    220                     update_post_meta($page->ID, 'ARPP_duration_options', $seconds);
    221                 }
    222             }
    223         } elseif ($value === 0) {
    224             $args = array(
    225                 'post_type' => $key,
    226                 'posts_per_page' => -1
    227             );
    228             $pages = get_posts($args);
    229 
    230             foreach ($pages as $page) {
    231                 delete_post_meta($page->ID, 'ARPP_duration_options');
    232             }
    233         }
    234     }
     203    $array_from_db = get_option('ARPP_my_option_name');
     204
     205    foreach ($array_from_db as $key => $value) {
     206        if (strpos($key, 'duration-') === 0) {
     207            $post_type = str_replace('duration-', '', $key);
     208            $seconds = absint($value);
     209
     210            $time_unit_key = "time_unit-" . $post_type;
     211            if (isset($array_from_db[$time_unit_key])) {
     212                switch ($array_from_db[$time_unit_key]) {
     213                    case 'minutes':
     214                        $seconds *= 60;
     215                        break;
     216                    case 'hours':
     217                        $seconds *= 3600;
     218                        break;
     219                }
     220            }
     221
     222            $args = array(
     223                'post_type' => $post_type,
     224                'posts_per_page' => -1
     225            );
     226            $pages = get_posts($args);
     227
     228            foreach ($pages as $page) {
     229                update_post_meta($page->ID, 'ARPP_duration_options', $seconds);
     230            }
     231        }
     232    }
    235233}
    236234
  • auto-refresh-post-page/includes/class-auto_refresh_post_page.php

    r2990642 r3207488  
    8989            $this->version = ARPP_AUTO_REFRESH_VERSION;
    9090        } else {
    91             $this->version = '1.0.0';
     91            $this->version = '1.0.1';
    9292        }
    9393        $this->plugin_name = 'auto_refresh_post_page';
  • auto-refresh-post-page/trunk/README.txt

    r2995733 r3207488  
    2828==Version==
    2929
    30 The current version of the plugin is 1.0.0
     30The current version of the plugin is 1.0.1
     31
     32== New Update ==
     33
     34A select field where user can select the unit of time like Hours, Minutes, Seconds along time field
    3135
    3236
  • auto-refresh-post-page/trunk/admin/css/auto-refresh-post-page-admin.css

    r2989831 r3207488  
    1717input[type="checkbox"] {
    1818  display: inline-block;
     19}
     20input[type=number]{
     21  min-height: 36px;
    1922}
    2023label.cb-tab-content__label {
     
    5457table.widefatsett {
    5558  background: #fff;
     59}
     60.wp-core-ui select {
     61  padding: 4px 24px 2px 8px;
     62  margin-bottom: 3px;
    5663}
    5764table.widefatsett {
  • auto-refresh-post-page/trunk/admin/js/auto-refresh-post-page-admin.js

    r2989831 r3207488  
    2323                  var value = jQuery(this).val();
    2424                  data[key] = value;
    25                 });
     25             
     26                  // Include the selected time unit
     27                  var timeUnitKey = 'time_unit-' + key.split('-')[1];
     28                  var timeUnitValue = jQuery(this).siblings('.js-time-unit').val();
     29                  data[timeUnitKey] = timeUnitValue;
     30              });
    2631                console.log(data);
    2732                // var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
  • auto-refresh-post-page/trunk/admin/partials/auto_refresh_post_page-admin-dashboard.php

    r2989831 r3207488  
    3535 <hr class="cb-divider" />
    3636    <tr>
    37         <th style="text-align: left;">
    38         <input type="checkbox" class="js-select-all">&nbsp;Select All &nbsp;<input type="number" placeholder="Enter Time in Seconds globallly" class="timeField" id="timeField" min=0 >
    39         </th>
     37    <th style="text-align: left;">
     38        <input type="checkbox" class="js-select-all">&nbsp;Select All
     39        &nbsp;
     40        <input type="number" placeholder="Enter Time in Seconds globally" class="timeField" id="timeField" min="0" oninput="updateGlobalTime(this)">
     41        <select id="globalTimeUnit" class="globalTimeUnit" onchange="updateGlobalTimeUnit(this)">
     42            <option value="seconds">Seconds</option>
     43            <option value="minutes">Minutes</option>
     44            <option value="hours">Hours</option>
     45        </select>
     46    </th>
    4047    </tr>
    4148       
     
    5764        $post_types = get_post_types( $args, $output, $operator );
    5865         
    59         foreach ( $post_types as $post_type ) { ?>
     66        foreach ($post_types as $post_type) { ?>
    6067            <tr>
    61                 <?php 
    62                     $array_from_db = get_option( 'ARPP_my_option_name' );
    63 
    64                     if(isset($array_from_db[$post_type]) && $array_from_db[$post_type] == 1 ) {
    65                         $checkbox="checked";
    66                     }else{
    67                         $checkbox = "";
    68                     }
    69 
    70                     if(isset($array_from_db["duration-".$post_type]) && $array_from_db["duration-".$post_type] != '' ) {
    71                         $repeat_time=$array_from_db["duration-".$post_type];
    72                     }else{     
    73                         $repeat_time = "";
    74                     }   
     68                <?php
     69                $array_from_db = get_option('ARPP_my_option_name');
     70       
     71                // Checkbox logic: Match the exact key with the `checkbox-` prefix
     72                $checkbox_key = "checkbox-" . $post_type;
     73                $checkbox = isset($array_from_db[$checkbox_key]) && $array_from_db[$checkbox_key] == 1 ? "checked" : "";
     74       
     75                // Time field logic
     76                $duration_key = "duration-" . $post_type;
     77                $repeat_time = isset($array_from_db[$duration_key]) ? $array_from_db[$duration_key] : "";
     78       
     79                // Time unit logic
     80                $time_unit_key = "time_unit-" . $post_type;
     81                $time_unit = isset($array_from_db[$time_unit_key]) ? $array_from_db[$time_unit_key] : "seconds";
    7582                ?>
    76          
    77                 <td class="check_title">
    78                     <input type="checkbox" name="checkbox-<?php echo esc_html($post_type); ?>" value="1"  class="js-cb-customization js-select-single" id="cb-feedback-<?php echo esc_html($post_type); ?>" data-key="feedbackTitle" <?php echo esc_html($checkbox); ?>>
    79                 </td>
    80                 <td>   
    81                     <?php echo esc_html($post_type); ?>&nbsp;
    82                 </td>
     83                <td class="check_title">
     84                    <input type="checkbox" name="checkbox-<?php echo esc_html($post_type); ?>" value="1"
     85                        class="js-cb-customization js-select-single"
     86                        id="cb-feedback-<?php echo esc_html($post_type); ?>"
     87                        <?php echo esc_html($checkbox); ?>>
     88                </td>
    8389                <td>
    84                     <input type="number" name="duration-<?php echo esc_html($post_type); ?>" value="<?php echo esc_html($repeat_time); ?>" placeholder="Enter Time in Seconds" id="time_set_field"  class="js-time-field" min=0 oninput="checkValue(this)">
    85                 </td>
    86             </tr>
     90                    <?php echo esc_html($post_type); ?>&nbsp;
     91                </td>
     92                <td>
     93                    <input type="number" name="duration-<?php echo esc_html($post_type); ?>"
     94                           value="<?php echo esc_html($repeat_time); ?>"
     95                           placeholder="Enter Time in Seconds"
     96                           class="js-time-field"
     97                           min="0">
     98                    <select name="time_unit-<?php echo esc_html($post_type); ?>" class="js-time-unit">
     99                        <option value="seconds" <?php selected($time_unit, 'seconds'); ?>>Seconds</option>
     100                        <option value="minutes" <?php selected($time_unit, 'minutes'); ?>>Minutes</option>
     101                        <option value="hours" <?php selected($time_unit, 'hours'); ?>>Hours</option>
     102                    </select>
     103                </td>
     104            </tr>
    87105    <?php } ?>
    88106 </table>
     
    106124
    107125
    108  function checkValue(input) {
    109     if (input.value < 0) {
    110         alert("Please enter a positive number.");
    111         input.value = 'Enter Time in Seconds';
    112     }
     126function updateGlobalTime(globalInput) {
     127    var timeFields = document.querySelectorAll('.js-time-field');
     128    timeFields.forEach(function(timeField) {
     129        timeField.value = globalInput.value;
     130    });
    113131
    114     if (input.value % 1 !== 0) {
    115         input.value = Math.floor(input.value);
    116         alert("Please enter a value without point");
    117     }
    118    
     132    // Automatically check all individual checkboxes if global input is used
     133    document.querySelectorAll('.js-select-single').forEach(function(checkbox) {
     134        checkbox.checked = true;
     135    });
     136}
     137
     138// Function to update all time unit fields with the global dropdown value
     139function updateGlobalTimeUnit(globalSelect) {
     140    var timeUnits = document.querySelectorAll('.js-time-unit');
     141    timeUnits.forEach(function(timeUnit) {
     142        timeUnit.value = globalSelect.value;
     143    });
     144
     145    // Automatically check all individual checkboxes if global select is used
     146    document.querySelectorAll('.js-select-single').forEach(function(checkbox) {
     147        checkbox.checked = true;
     148    });
     149}
     150
     151// Get the "Select All" checkbox
     152var selectAllCheckbox = document.querySelector('.js-select-all');
     153selectAllCheckbox.addEventListener('click', function() {
     154    var checkboxes = document.querySelectorAll('.js-select-single');
    119155    var timeFields = document.querySelectorAll('.js-time-field');
     156    var timeUnits = document.querySelectorAll('.js-time-unit');
     157    var globalTime = document.querySelector('#timeField').value;
     158    var globalUnit = document.querySelector('#globalTimeUnit').value;
    120159
    121     // Loop through each input field
    122     timeFields.forEach(function(timeField) {
    123         timeField.addEventListener('input', function() {
    124             var checkbox = timeField.previousElement.previousElement;
    125             checkbox.checked = true;
     160    // Apply the global setting to all individual fields and checkboxes
     161    checkboxes.forEach(function(checkbox) {
     162        checkbox.checked = selectAllCheckbox.checked;
     163    });
     164
     165    if (selectAllCheckbox.checked) {
     166        timeFields.forEach(function(timeField) {
     167            timeField.value = globalTime;
    126168        });
    127     });
    128  }
    129    
    130 
    131     // Get the "Select All" checkbox
    132  var selectAllCheckbox = document.querySelector('.js-select-all');
    133  selectAllCheckbox.addEventListener('click',
    134  function() {
    135     var checkboxes = document.querySelectorAll('.js-select-single');
    136     for (var i = 0; i < checkboxes.length; i++) {
    137         // Set the checked property of the checkbox to the same value as the "Select All" checkbox
    138         checkboxes[i].checked = selectAllCheckbox.checked;
    139     }
    140  });
    141 
    142  document.querySelector(".js-select-all").addEventListener("click", function() {
    143     if (this.checked) {
    144         document.querySelector(".timeField").addEventListener("input", function() {
    145             document.querySelectorAll(".js-time-field").forEach(element => element.value = this.value);
    146         });
    147     } else {
    148          document.querySelector(".timeField").removeEventListener("input", function() {
    149             document.querySelectorAll(".js-time-field").forEach(element => element.value = this.value);
     169        timeUnits.forEach(function(timeUnit) {
     170            timeUnit.value = globalUnit;
    150171        });
    151172    }
    152  });
     173});
    153174</script>
    154175
  • auto-refresh-post-page/trunk/auto-refresh-post-page.php

    r2990567 r3207488  
    1717 * Plugin URI:        https://cubixsol.com/
    1818 * Description:       This is a short description of what the plugin does. It's displayed in the WordPress admin area.
    19  * Version:           1.0.0
     19 * Version:           1.0.1
    2020 * Author:            Cubixsol
    2121 * Author URI:        https://cubixsol.com/our-products/
     
    5050
    5151// Define plugin constants.
    52 define('ARPP_AUTO_REFRESH_VERSION', '1.0.0');
     52define('ARPP_AUTO_REFRESH_VERSION', '1.0.1');
    5353define('ARPP_AUTO_REFRESH_PLUGIN_URL', plugin_dir_url(__FILE__));
    5454define('ARPP_AUTO_REFRESH_PLUGIN_PATH', plugin_dir_path(__FILE__));
     
    9999function ARPP_store_refresh_settings()
    100100{
    101 
    102     if (!isset($_POST['ARPP_nonce']) || !wp_verify_nonce(sanitize_text_field($_POST['ARPP_nonce']), 'ARPP_store_refresh_settings_nonce')) {
     101    if (!isset($_POST['ARPP_nonce']) || !wp_verify_nonce(sanitize_text_field($_POST['ARPP_nonce']), 'ARPP_store_refresh_settings_nonce')) {
    103102        wp_send_json_error('Invalid nonce.');
    104103    }
    105104
    106     // Ensure the data received is an array and sanitize its elements.
    107     if (!isset($_POST['data']) || !is_array($_POST['data'])) {
    108         return;
    109     }
    110 
    111     $data = sanitize_text_field($_POST['data']);
    112     $new_data = array();
    113 
    114     foreach ($data as $key => $value) {
    115         // Sanitize the key and value.
    116         $key = sanitize_key($key);
    117         $value = sanitize_text_field($value);
    118 
    119         // Handle special case for checkboxes if needed.
    120         if (strpos($key, 'checkbox') !== false) {
    121             $exploded = explode('-', $key);
    122             $new_data[$exploded[1]] = $value;
    123         } else {
    124             $new_data[$key] = $value;
    125         }
    126     }
    127 
    128     // Store the sanitized data in the database.
    129     update_option('ARPP_my_option_name', $new_data);
     105    if (!isset($_POST['data']) || !is_array($_POST['data'])) {
     106        return;
     107    }
     108
     109    $data = $_POST['data'];
     110    $new_data = array();
     111
     112    foreach ($data as $key => $value) {
     113        $key = sanitize_key($key);
     114        $value = sanitize_text_field($value);
     115
     116        // Check for time unit and duration
     117        if (strpos($key, 'time_unit-') === 0 || strpos($key, 'duration-') === 0) {
     118            $new_data[$key] = $value;
     119        } else {
     120            $new_data[$key] = $value === '1' ? 1 : 0;
     121        }
     122    }
     123
     124    // Store the sanitized data
     125    update_option('ARPP_my_option_name', $new_data);
    130126}
    131127
     
    205201function ARPP_setrefreshtime()
    206202{
    207     $array_from_db = get_option('ARPP_my_option_name');
    208 
    209     foreach ($array_from_db as $key => $value) {
    210         // Sanitize the key and value.
    211         $key = sanitize_key($key);
    212         $value = absint($value);
    213 
    214         if ($value === 1) {
    215             $duration_key = "duration-" . $key;
    216             if (array_key_exists($duration_key, $array_from_db)) {
    217                 $seconds = absint($array_from_db[$duration_key]);
    218                 $args = array(
    219                     'post_type' => $key,
    220                     'posts_per_page' => -1
    221                 );
    222                 $pages = get_posts($args);
    223 
    224                 foreach ($pages as $page) {
    225                     update_post_meta($page->ID, 'ARPP_duration_options', $seconds);
    226                 }
    227             }
    228         } elseif ($value === 0) {
    229             $args = array(
    230                 'post_type' => $key,
    231                 'posts_per_page' => -1
    232             );
    233             $pages = get_posts($args);
    234 
    235             foreach ($pages as $page) {
    236                 delete_post_meta($page->ID, 'ARPP_duration_options');
    237             }
    238         }
    239     }
     203    $array_from_db = get_option('ARPP_my_option_name');
     204
     205    foreach ($array_from_db as $key => $value) {
     206        if (strpos($key, 'duration-') === 0) {
     207            $post_type = str_replace('duration-', '', $key);
     208            $seconds = absint($value);
     209
     210            $time_unit_key = "time_unit-" . $post_type;
     211            if (isset($array_from_db[$time_unit_key])) {
     212                switch ($array_from_db[$time_unit_key]) {
     213                    case 'minutes':
     214                        $seconds *= 60;
     215                        break;
     216                    case 'hours':
     217                        $seconds *= 3600;
     218                        break;
     219                }
     220            }
     221
     222            $args = array(
     223                'post_type' => $post_type,
     224                'posts_per_page' => -1
     225            );
     226            $pages = get_posts($args);
     227
     228            foreach ($pages as $page) {
     229                update_post_meta($page->ID, 'ARPP_duration_options', $seconds);
     230            }
     231        }
     232    }
    240233}
    241234
  • auto-refresh-post-page/trunk/includes/class-auto_refresh_post_page.php

    r2989831 r3207488  
    8989            $this->version = ARPP_AUTO_REFRESH_VERSION;
    9090        } else {
    91             $this->version = '1.0.0';
     91            $this->version = '1.0.1';
    9292        }
    9393        $this->plugin_name = 'auto_refresh_post_page';
Note: See TracChangeset for help on using the changeset viewer.