Plugin Directory

Changeset 3263895


Ignore:
Timestamp:
03/29/2025 06:01:38 PM (12 months ago)
Author:
etruel
Message:

6.0 Mar 29, 2025

Location:
etruel-del-post-copies
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • etruel-del-post-copies/tags/6.0/edel-post-copies.php

    r3261804 r3263895  
    4545    class edel_post_copies {
    4646
    47         private static $instance = null;
     47        private static $instance   = null;
    4848        public static $prorequired = '2.5';
    4949
     
    6060            $this->includes();
    6161            $this->setup_actions();
    62             $this->load_textdomain();
     62            //$this->load_textdomain();
    6363        }
    6464
     
    6868            add_filter('cron_schedules', array($this, 'wpedpc_cron_recurrence'));
    6969            add_action('init', array($this, 'wpedpc_custom_cron'));
     70            add_action('init', array($this, 'load_textdomain'));
    7071            add_filter('wpedpc_env_checks', array($this, 'wpedpc_env_checks'));
    7172            do_action('wpedpc_setup_actions');
     
    8283            _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin’ huh?', 'etruel-del-post-copies'), '1.6');
    8384        }
    84  
     85
    8586        private function setup_globals() {
    8687
     
    145146        public static function autoloader($class_name) {
    146147            $class = strtolower(str_replace('_', '-', $class_name));
    147             $file = plugin_dir_path(__FILE__) . '/includes/class-' . $class . '.php';
     148            $file  = plugin_dir_path(__FILE__) . '/includes/class-' . $class . '.php';
    148149            if (file_exists($file)) {
    149150                require_once $file;
     
    152153
    153154        public function load_textdomain() {
    154             // Set filter for plugin's languages directory
     155            // textdomain directory
    155156            $lang_dir = dirname(plugin_basename(__FILE__)) . '/languages/';
    156             $lang_dir = apply_filters('wpedpc_languages_directory', $lang_dir);
    157 
    158             // Traditional WordPress plugin locale filter
    159             $locale = apply_filters('plugin_locale', get_locale(), 'etruel-del-post-copies');
    160             $mofile = sprintf('%1$s-%2$s.mo', 'etruel-del-post-copies', $locale);
    161 
    162             // Setup paths to current locale file
    163             $mofile_local = $lang_dir . $mofile;
    164             $mofile_global = WP_LANG_DIR . '/etruel-del-post-copies/' . $mofile;
    165 
    166             if (file_exists($mofile_global)) {
    167                 // Look in global /wp-content/languages/etruel-del-post-copies/ folder
    168                 load_textdomain('etruel-del-post-copies', $mofile_global);
    169             } elseif (file_exists($mofile_local)) {
    170                 // Look in local /wp-content/plugins/etruel-del-post-copies/languages/ folder
    171                 load_textdomain('etruel-del-post-copies', $mofile_local);
    172             } else {
    173                 // Load the default language files
    174                 load_plugin_textdomain('etruel-del-post-copies', false, $lang_dir);
    175             }
     157            // Load the default language files
     158            load_plugin_textdomain('etruel-del-post-copies', false, $lang_dir);
    176159        }
    177160
     
    199182        function wpedpc_cron_recurrence($schedules) {
    200183            $schedules['wpedpc_interval'] = array(
    201                 'display' => __('Every Five Minutes', 'textdomain'),
     184                'display'  => __('Every Five Minutes', 'textdomain'),
    202185                'interval' => 300,
    203186            );
     
    214197        function wpedpc_cron_callback() {
    215198
    216             $args = array('post_type' => 'wpedpcampaign', 'orderby' => 'ID', 'order' => 'ASC', 'numberposts' => -1);
     199            $args      = array('post_type' => 'wpedpcampaign', 'orderby' => 'ID', 'order' => 'ASC', 'numberposts' => -1);
    217200            $campaigns = get_posts($args);
    218201            foreach ($campaigns as $post) {
     
    240223                foreach ($cronarrayvalue as $key => $value) {
    241224                    //steps
    242                     $step = 1;
     225                    $step  = 1;
    243226                    if (strstr($value, '/'))
    244227                        list($value, $step) = explode('/', $value, 2);
     
    249232                    if (strstr($value, '-')) {
    250233                        list($first, $last) = explode('-', $value, 2);
    251                         if (!is_numeric($first) or!is_numeric($last) or $last > 60 or $first > 60) //check
     234                        if (!is_numeric($first) or !is_numeric($last) or $last > 60 or $first > 60) //check
    252235                            return false;
    253236                        if ($cronarraykey == 'minutes' and $step < 5)  //set step ninmum to 5 min.
     
    285268                        //Month names
    286269                        if (strtolower($value) == 'jan')
    287                             $value = 1;
     270                            $value              = 1;
    288271                        if (strtolower($value) == 'feb')
    289                             $value = 2;
     272                            $value              = 2;
    290273                        if (strtolower($value) == 'mar')
    291                             $value = 3;
     274                            $value              = 3;
    292275                        if (strtolower($value) == 'apr')
    293                             $value = 4;
     276                            $value              = 4;
    294277                        if (strtolower($value) == 'may')
    295                             $value = 5;
     278                            $value              = 5;
    296279                        if (strtolower($value) == 'jun')
    297                             $value = 6;
     280                            $value              = 6;
    298281                        if (strtolower($value) == 'jul')
    299                             $value = 7;
     282                            $value              = 7;
    300283                        if (strtolower($value) == 'aug')
    301                             $value = 8;
     284                            $value              = 8;
    302285                        if (strtolower($value) == 'sep')
    303                             $value = 9;
     286                            $value              = 9;
    304287                        if (strtolower($value) == 'oct')
    305                             $value = 10;
     288                            $value              = 10;
    306289                        if (strtolower($value) == 'nov')
    307                             $value = 11;
     290                            $value              = 11;
    308291                        if (strtolower($value) == 'dec')
    309                             $value = 12;
     292                            $value              = 12;
    310293                        //Week Day names
    311294                        if (strtolower($value) == 'sun')
    312                             $value = 0;
     295                            $value              = 0;
    313296                        if (strtolower($value) == 'sat')
    314                             $value = 6;
     297                            $value              = 6;
    315298                        if (strtolower($value) == 'mon')
    316                             $value = 1;
     299                            $value              = 1;
    317300                        if (strtolower($value) == 'tue')
    318                             $value = 2;
     301                            $value              = 2;
    319302                        if (strtolower($value) == 'wed')
    320                             $value = 3;
     303                            $value              = 3;
    321304                        if (strtolower($value) == 'thu')
    322                             $value = 4;
     305                            $value              = 4;
    323306                        if (strtolower($value) == 'fri')
    324                             $value = 5;
     307                            $value              = 5;
    325308                        if (!is_numeric($value) or $value > 60) //check
    326309                            return false;
     
    367350            if (version_compare($wp_version, '3.1', '<')) { // check WP Version
    368351                $message .= __('- WordPress 3.1 or higher needed!', 'etruel-del-post-copies') . '<br />';
    369                 $checks = false;
     352                $checks  = false;
    370353            }
    371354            if (version_compare(phpversion(), '5.4.0', '<')) { // check PHP Version
    372355                $message .= __('- PHP 5.4.0 or higher needed!', 'etruel-del-post-copies') . '<br />';
    373                 $checks = false;
     356                $checks  = false;
    374357            }
    375358            //put massage if one
     
    383366        static function wpedpc_env_checks_notice() {
    384367            global $wpedpc_admin_message;
    385             echo esc_html($wpedpc_admin_message);
    386         }
    387 
     368            echo wp_kses_post($wpedpc_admin_message);
     369        }
    388370    }
    389371
  • etruel-del-post-copies/tags/6.0/includes/ajax-actions.php

    r3261804 r3263895  
    11<?php
     2
    23/**
    34 * Ajax Actions
     
    910 * @since       5.0
    1011 */
    11 
    1212// Exit if accessed directly
    13 if ( ! defined( 'ABSPATH' ) ) exit;
    14 
     13if (!defined('ABSPATH'))
     14    exit;
    1515
    1616/**
     
    2121 */
    2222class wpedpc_ajax_actions {
    23    
     23
    2424    function __construct() {
    25        
     25
    2626        add_action('wp_ajax_wpedpc_show_logs_campaign', array('wpedpc_ajax_actions', 'show_logs_campaign'));
    2727        add_action('wpedpc_show_logs_campaign', array('wpedpc_ajax_actions', 'show_logs'));
    28         add_action('wp_ajax_wpedpc_run',  array('wpedpc_ajax_actions', 'run_campaign'));
    29         add_action('wp_ajax_wpdpc_now',  array('wpedpc_ajax_actions', 'run_campaign'));
    30         add_action('wp_ajax_wpdpc_logerase',  array('wpedpc_ajax_actions', 'erase_logs'));
    31         add_action('wp_ajax_wpdpc_show',  array('wpedpc_ajax_actions', 'show'));
     28        add_action('wp_ajax_wpedpc_run', array('wpedpc_ajax_actions', 'run_campaign'));
     29        add_action('wp_ajax_wpdpc_now', array('wpedpc_ajax_actions', 'run_campaign'));
     30        add_action('wp_ajax_wpdpc_logerase', array('wpedpc_ajax_actions', 'erase_logs'));
     31        add_action('wp_ajax_wpdpc_show', array('wpedpc_ajax_actions', 'show'));
    3232        add_action('wp_ajax_wpedpc_delapost', array('wpedpc_ajax_actions', 'del_post'));
    33        
    34     }
     33    }
     34
    3535    static function show_logs_campaign() {
    36         if(!isset( $_POST['nonce'] ) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')){
    37             return false;
    38         }
    39 
    40         if ( isset( $_POST['post_id'] ) ) {
     36        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')) {
     37            return false;
     38        }
     39
     40        if (!current_user_can('manage_options')) {
     41            return false;
     42        }
     43
     44        if (isset($_POST['post_id'])) {
    4145            $post_id = $_POST['post_id'];
    42             do_action('wpedpc_show_logs_campaign', $post_id );
    43         }
    44     }
    45     static function show_logs($post_id){
    46         if( ! current_user_can( 'manage_options' ) ) {
    47             return false;
    48         }       
     46            do_action('wpedpc_show_logs_campaign', $post_id);
     47        }
     48    }
     49
     50    static function show_logs($post_id) {
     51        if (!current_user_can('manage_options')) {
     52            return false;
     53        }
    4954        $wpedpc_logs = get_post_meta($post_id, 'logs', true);
    50         $echoHtml = '<h2>'.__('Delete Post Copies Logs', 'etruel-del-post-copies').'</h2>
     55        $echoHtml    = '<h2>' . __('Delete Post Copies Logs', 'etruel-del-post-copies') . '</h2>
    5156                <div id="poststuff" class="metabox-holder">
    5257                <div id="side-info-column" class="inner-sidebar">
     
    5863                        <tr>
    5964                            <th scope="col">#</th>
    60                             <th scope="col">'.__('Date', 'etruel-del-post-copies').'</th>
    61                             <th scope="col">'.__('Mode', 'etruel-del-post-copies').'</th>
    62                             <th scope="col">'.__('Status', 'etruel-del-post-copies').'</th>
    63                             <th scope="col">'.__('Finished In', 'etruel-del-post-copies' ).'</th>
    64                             <th scope="col">'.__('Removed', 'etruel-del-post-copies').'</th>
     65                            <th scope="col">' . __('Date', 'etruel-del-post-copies') . '</th>
     66                            <th scope="col">' . __('Mode', 'etruel-del-post-copies') . '</th>
     67                            <th scope="col">' . __('Status', 'etruel-del-post-copies') . '</th>
     68                            <th scope="col">' . __('Finished In', 'etruel-del-post-copies') . '</th>
     69                            <th scope="col">' . __('Removed', 'etruel-del-post-copies') . '</th>
    6570                        </tr>';
    66         if(!empty($wpedpc_logs)){
     71        if (!empty($wpedpc_logs)) {
    6772            $i = 0;
    68             foreach(array_reverse($wpedpc_logs) as $log) {
     73            foreach (array_reverse($wpedpc_logs) as $log) {
    6974                $i++;
    7075                $rk = $i;
    71                        
     76
    7277                $echoHtml .= '<tr>
    73                                 <td>'.$rk.'</td>
    74                                 <td>'.date('Y-m-d H:i:s', $log['started']).'</td>
    75                                 <td>'.((intval($log['mode']) == 1) ? __('Manual', 'etruel-del-post-copies') : __('Auto', 'etruel-del-post-copies')).'</td>
    76                                 <td>'.((intval($log['status']) == 0) ? __('OK', 'etruel-del-post-copies') : sprintf(
    77                                     // translators: %s represents the number of errors found.   
    78                                     __('%s errors', 'etruel-del-post-copies'), intval($log['status']))).'</td>
    79                                 <td>'.round($log['took'], 3).' '.__('seconds', 'etruel-del-post-copies').'</td>
    80                                 <td>'.sprintf(
    81                                     // translators: %s represents the number of errors found.   
    82                                     __('%s posts', 'etruel-del-post-copies'), intval($log['removed'])).'</td>
    83                             </tr>'; 
    84                 if($i >= 40) {
     78                                <td>' . $rk . '</td>
     79                                <td>' . date('Y-m-d H:i:s', $log['started']) . '</td>
     80                                <td>' . ((intval($log['mode']) == 1) ? __('Manual', 'etruel-del-post-copies') : __('Auto', 'etruel-del-post-copies')) . '</td>
     81                                <td>' . ((intval($log['status']) == 0) ? __('OK', 'etruel-del-post-copies') : sprintf(
     82                                // translators: %s represents the number of errors found.   
     83                                __('%s errors', 'etruel-del-post-copies'), intval($log['status']))) . '</td>
     84                                <td>' . round($log['took'], 3) . ' ' . __('seconds', 'etruel-del-post-copies') . '</td>
     85                                <td>' . sprintf(
     86                                // translators: %s represents the number of errors found.   
     87                                __('%s posts', 'etruel-del-post-copies'), intval($log['removed'])) . '</td>
     88                            </tr>';
     89                if ($i >= 40) {
    8590                    break;
    8691                }
     
    9095        $echoHtml .= '</table></div></div></div></div>';
    9196        wp_die($echoHtml);
    92 
    93     }
     97    }
     98
    9499    public static function run_campaign() {
    95         if(!isset( $_POST['nonce'] ) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')){
    96             return false;
    97         }
     100        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')) {
     101            return false;
     102        }
     103
     104        if (!current_user_can('manage_options')) {
     105            return false;
     106        }
     107
    98108        // Verify campaign_ID exists and sanitize input
    99109        if (!isset($_POST['campaign_ID'])) {
    100110            wp_send_json_error(array('message' => __('Campaign ID must exist.', 'etruel-del-post-copies')));
    101111        }
    102    
     112
    103113        $post_id = absint($_POST['campaign_ID']); // Ensure it's a valid integer
    104114        $quickdo = 'WPdpc_now';
    105    
     115
    106116        // Apply the campaign filter
    107117        $response_run = apply_filters('wpedpc_run_campaign', $post_id, $quickdo, array(
     
    109119            'success' => false
    110120        ));
    111    
     121
    112122        // Send JSON response based on the filter result
    113123        if ($response_run['success']) {
     
    117127        }
    118128    }
     129
    119130    public static function erase_logs() {
    120131        // 1. Verify nonce for CSRF protection
     
    122133            wp_send_json_error(array('message' => __('Security check failed', 'etruel-del-post-copies')));
    123134        }
    124    
     135
    125136        // 2. Check if user has proper capabilities
    126137        if (!current_user_can('manage_options')) {
    127138            wp_send_json_error(array('message' => __('Insufficient permissions', 'etruel-del-post-copies')));
    128139        }
    129    
     140
    130141        // 3. Validate and sanitize campaign ID
    131142        $campaign_id = isset($_REQUEST['campaign_ID']) ? absint($_REQUEST['campaign_ID']) : 0;
     
    133144            wp_send_json_error(array('message' => __('Invalid campaign ID or campaign not found', 'etruel-del-post-copies')));
    134145        }
    135    
     146
    136147        // 4. Check if user can edit the campaign
    137148        if (!current_user_can('edit_post', $campaign_id)) {
    138149            wp_send_json_error(array('message' => __('Permission denied', 'etruel-del-post-copies')));
    139150        }
    140    
     151
    141152        // 5. Delete the logs meta key
    142153        if (delete_post_meta($campaign_id, 'logs')) {
     
    148159
    149160    public static function show() {
    150         if(!isset( $_POST['nonce'] ) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')){
     161        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')) {
     162            return false;
     163        }
     164
     165        if (!current_user_can('manage_options')) {
    151166            return false;
    152167        }
     
    155170            wp_send_json_error(array('message' => __('Campaign ID must exist.', 'etruel-del-post-copies')));
    156171        }
    157    
     172
    158173        $post_id = absint($_POST['campaign_ID']); // Ensure it's an integer
    159174        $quickdo = 'WPdpc_show';
    160    
     175
    161176        // Apply campaign filter
    162177        $response_run = apply_filters('wpedpc_run_campaign', $post_id, $quickdo, array());
    163    
     178
    164179        // Return the results
    165180        wp_send_json_success(array('results' => $response_run['results']));
    166181    }
    167    
     182
    168183    public static function del_post() {
    169         if(!isset( $_POST['nonce'] ) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')){
    170             return false;
    171         }
     184        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')) {
     185            return false;
     186        }
     187
     188        if (!current_user_can('manage_options')) {
     189            return false;
     190        }
     191
    172192        // Verify nonce for security
    173193        if (!isset($_POST['url'], $_POST['post_id'], $_POST['campaign_ID'])) {
    174194            wp_send_json_error(array('message' => __('Missing required parameters.', 'etruel-del-post-copies')));
    175195        }
    176    
     196
    177197        // Extract nonce from URL
    178         $url = esc_url_raw($_POST['url']);
     198        $url   = esc_url_raw($_POST['url']);
    179199        parse_str(parse_url($url, PHP_URL_QUERY), $path);
    180200        $nonce = $path['_wpnonce'] ?? '';
    181    
    182         $post_id = absint($_POST['post_id']);
     201
     202        $post_id    = absint($_POST['post_id']);
    183203        $campaign_id = absint($_POST['campaign_ID']);
    184    
     204
     205        if (!current_user_can('edit_post', $campaign_id)) {
     206            wp_send_json_error(array('message' => __('Permission denied', 'etruel-del-post-copies')));
     207        }
     208
    185209        // Security check
    186210        if (!wp_verify_nonce($nonce, 'delete-post_' . $post_id)) {
    187211            wp_send_json_error(array('message' => __('Security check failed.', 'etruel-del-post-copies')));
    188212        }
    189    
     213
    190214        // Validate campaign exists
    191         $campaign = get_post_meta($campaign_id, '_campaign_settings', true);
     215        $campaign = new WPEDPC_Campaign($campaign_id);
     216
    192217        if (!$campaign) {
    193218            wp_send_json_error(array('message' => __('Campaign not found.', 'etruel-del-post-copies')));
    194219        }
    195    
    196220        // Extract deletion settings
    197         $deletemedia = $campaign['deletemedia'] ?? false;
    198         $delimgcontent = $campaign['delimgcontent'] ?? false;
    199         $force_delete = empty($campaign['movetotrash']);
    200    
     221        $deletemedia   = $campaign->deletemedia ?? false;
     222        $delimgcontent = $campaign->delimgcontent ?? false;
     223        $force_delete  = empty($campaign->movetotrash);
     224
    201225        // Get post details
    202226        $post = get_post($post_id);
     
    204228            wp_send_json_error(array('message' => __('Post not found.', 'etruel-del-post-copies')));
    205229        }
    206    
     230
    207231        $post_title = $post->post_title;
    208         $permalink = get_permalink($post_id);
    209    
     232        $permalink  = get_permalink($post_id);
     233
    210234        // Delete media attachments if required
    211235        if ($deletemedia) {
    212236            $attachments = get_children([
    213237                'post_parent' => $post_id,
    214                 'post_type'   => 'attachment',
    215                 'fields'      => 'ids',
     238                'post_type'   => 'attachment',
     239                'fields'      => 'ids',
    216240            ]);
    217    
     241
    218242            foreach ($attachments as $attachment_id) {
    219243                wp_delete_attachment($attachment_id, $force_delete);
    220244            }
    221245        }
    222    
     246
    223247        // Delete images inside content
    224248        if ($delimgcontent) {
     
    231255            }
    232256        }
    233    
     257
    234258        // Delete all custom fields in one go
    235259        delete_post_meta_by_key($post_id);
    236    
     260
    237261        // Delete the post
    238262        $result = wp_delete_post($post_id, $force_delete);
    239    
     263
    240264        if (!$result) {
    241             wp_send_json_error(array('message' => sprintf(__('Error deleting post %1$s - %2$s', 'etruel-del-post-copies'), $post_id, $permalink)));
    242         }
    243    
    244         wp_send_json_success(array('message' => sprintf(__("'%1$s' (ID #%2$s) Deleted!", 'etruel-del-post-copies'), $post_title, $post_id)));
     265            wp_send_json_error(array('message' => sprintf(__('Error deleting post %1s - %2s', 'etruel-del-post-copies'), $post_id, $permalink)));
     266        }
     267
     268        wp_send_json_success(array('message' => sprintf(__("'%1s' (ID #%2s) Deleted!", 'etruel-del-post-copies'), $post_title, $post_id)));
    245269    }
    246270}
    247271
    248272$wpedpc_ajax_actions = new wpedpc_ajax_actions();
    249 
    250 
    251 
    252 
    253 
    254 
    255 ?>
  • etruel-del-post-copies/tags/6.0/readme.txt

    r3256732 r3263895  
    5858
    5959== Changelog ==
    60 = 6.0 Mar 16, 2025 =
     60= 6.0 Mar 29, 2025 =
    6161* Major version. Important release & must update version.
    6262* **First use should be in a test environment.**
  • etruel-del-post-copies/trunk/edel-post-copies.php

    r3261804 r3263895  
    4545    class edel_post_copies {
    4646
    47         private static $instance = null;
     47        private static $instance   = null;
    4848        public static $prorequired = '2.5';
    4949
     
    6060            $this->includes();
    6161            $this->setup_actions();
    62             $this->load_textdomain();
     62            //$this->load_textdomain();
    6363        }
    6464
     
    6868            add_filter('cron_schedules', array($this, 'wpedpc_cron_recurrence'));
    6969            add_action('init', array($this, 'wpedpc_custom_cron'));
     70            add_action('init', array($this, 'load_textdomain'));
    7071            add_filter('wpedpc_env_checks', array($this, 'wpedpc_env_checks'));
    7172            do_action('wpedpc_setup_actions');
     
    8283            _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&#8217; huh?', 'etruel-del-post-copies'), '1.6');
    8384        }
    84  
     85
    8586        private function setup_globals() {
    8687
     
    145146        public static function autoloader($class_name) {
    146147            $class = strtolower(str_replace('_', '-', $class_name));
    147             $file = plugin_dir_path(__FILE__) . '/includes/class-' . $class . '.php';
     148            $file  = plugin_dir_path(__FILE__) . '/includes/class-' . $class . '.php';
    148149            if (file_exists($file)) {
    149150                require_once $file;
     
    152153
    153154        public function load_textdomain() {
    154             // Set filter for plugin's languages directory
     155            // textdomain directory
    155156            $lang_dir = dirname(plugin_basename(__FILE__)) . '/languages/';
    156             $lang_dir = apply_filters('wpedpc_languages_directory', $lang_dir);
    157 
    158             // Traditional WordPress plugin locale filter
    159             $locale = apply_filters('plugin_locale', get_locale(), 'etruel-del-post-copies');
    160             $mofile = sprintf('%1$s-%2$s.mo', 'etruel-del-post-copies', $locale);
    161 
    162             // Setup paths to current locale file
    163             $mofile_local = $lang_dir . $mofile;
    164             $mofile_global = WP_LANG_DIR . '/etruel-del-post-copies/' . $mofile;
    165 
    166             if (file_exists($mofile_global)) {
    167                 // Look in global /wp-content/languages/etruel-del-post-copies/ folder
    168                 load_textdomain('etruel-del-post-copies', $mofile_global);
    169             } elseif (file_exists($mofile_local)) {
    170                 // Look in local /wp-content/plugins/etruel-del-post-copies/languages/ folder
    171                 load_textdomain('etruel-del-post-copies', $mofile_local);
    172             } else {
    173                 // Load the default language files
    174                 load_plugin_textdomain('etruel-del-post-copies', false, $lang_dir);
    175             }
     157            // Load the default language files
     158            load_plugin_textdomain('etruel-del-post-copies', false, $lang_dir);
    176159        }
    177160
     
    199182        function wpedpc_cron_recurrence($schedules) {
    200183            $schedules['wpedpc_interval'] = array(
    201                 'display' => __('Every Five Minutes', 'textdomain'),
     184                'display'  => __('Every Five Minutes', 'textdomain'),
    202185                'interval' => 300,
    203186            );
     
    214197        function wpedpc_cron_callback() {
    215198
    216             $args = array('post_type' => 'wpedpcampaign', 'orderby' => 'ID', 'order' => 'ASC', 'numberposts' => -1);
     199            $args      = array('post_type' => 'wpedpcampaign', 'orderby' => 'ID', 'order' => 'ASC', 'numberposts' => -1);
    217200            $campaigns = get_posts($args);
    218201            foreach ($campaigns as $post) {
     
    240223                foreach ($cronarrayvalue as $key => $value) {
    241224                    //steps
    242                     $step = 1;
     225                    $step  = 1;
    243226                    if (strstr($value, '/'))
    244227                        list($value, $step) = explode('/', $value, 2);
     
    249232                    if (strstr($value, '-')) {
    250233                        list($first, $last) = explode('-', $value, 2);
    251                         if (!is_numeric($first) or!is_numeric($last) or $last > 60 or $first > 60) //check
     234                        if (!is_numeric($first) or !is_numeric($last) or $last > 60 or $first > 60) //check
    252235                            return false;
    253236                        if ($cronarraykey == 'minutes' and $step < 5)  //set step ninmum to 5 min.
     
    285268                        //Month names
    286269                        if (strtolower($value) == 'jan')
    287                             $value = 1;
     270                            $value              = 1;
    288271                        if (strtolower($value) == 'feb')
    289                             $value = 2;
     272                            $value              = 2;
    290273                        if (strtolower($value) == 'mar')
    291                             $value = 3;
     274                            $value              = 3;
    292275                        if (strtolower($value) == 'apr')
    293                             $value = 4;
     276                            $value              = 4;
    294277                        if (strtolower($value) == 'may')
    295                             $value = 5;
     278                            $value              = 5;
    296279                        if (strtolower($value) == 'jun')
    297                             $value = 6;
     280                            $value              = 6;
    298281                        if (strtolower($value) == 'jul')
    299                             $value = 7;
     282                            $value              = 7;
    300283                        if (strtolower($value) == 'aug')
    301                             $value = 8;
     284                            $value              = 8;
    302285                        if (strtolower($value) == 'sep')
    303                             $value = 9;
     286                            $value              = 9;
    304287                        if (strtolower($value) == 'oct')
    305                             $value = 10;
     288                            $value              = 10;
    306289                        if (strtolower($value) == 'nov')
    307                             $value = 11;
     290                            $value              = 11;
    308291                        if (strtolower($value) == 'dec')
    309                             $value = 12;
     292                            $value              = 12;
    310293                        //Week Day names
    311294                        if (strtolower($value) == 'sun')
    312                             $value = 0;
     295                            $value              = 0;
    313296                        if (strtolower($value) == 'sat')
    314                             $value = 6;
     297                            $value              = 6;
    315298                        if (strtolower($value) == 'mon')
    316                             $value = 1;
     299                            $value              = 1;
    317300                        if (strtolower($value) == 'tue')
    318                             $value = 2;
     301                            $value              = 2;
    319302                        if (strtolower($value) == 'wed')
    320                             $value = 3;
     303                            $value              = 3;
    321304                        if (strtolower($value) == 'thu')
    322                             $value = 4;
     305                            $value              = 4;
    323306                        if (strtolower($value) == 'fri')
    324                             $value = 5;
     307                            $value              = 5;
    325308                        if (!is_numeric($value) or $value > 60) //check
    326309                            return false;
     
    367350            if (version_compare($wp_version, '3.1', '<')) { // check WP Version
    368351                $message .= __('- WordPress 3.1 or higher needed!', 'etruel-del-post-copies') . '<br />';
    369                 $checks = false;
     352                $checks  = false;
    370353            }
    371354            if (version_compare(phpversion(), '5.4.0', '<')) { // check PHP Version
    372355                $message .= __('- PHP 5.4.0 or higher needed!', 'etruel-del-post-copies') . '<br />';
    373                 $checks = false;
     356                $checks  = false;
    374357            }
    375358            //put massage if one
     
    383366        static function wpedpc_env_checks_notice() {
    384367            global $wpedpc_admin_message;
    385             echo esc_html($wpedpc_admin_message);
    386         }
    387 
     368            echo wp_kses_post($wpedpc_admin_message);
     369        }
    388370    }
    389371
  • etruel-del-post-copies/trunk/includes/ajax-actions.php

    r3261804 r3263895  
    11<?php
     2
    23/**
    34 * Ajax Actions
     
    910 * @since       5.0
    1011 */
    11 
    1212// Exit if accessed directly
    13 if ( ! defined( 'ABSPATH' ) ) exit;
    14 
     13if (!defined('ABSPATH'))
     14    exit;
    1515
    1616/**
     
    2121 */
    2222class wpedpc_ajax_actions {
    23    
     23
    2424    function __construct() {
    25        
     25
    2626        add_action('wp_ajax_wpedpc_show_logs_campaign', array('wpedpc_ajax_actions', 'show_logs_campaign'));
    2727        add_action('wpedpc_show_logs_campaign', array('wpedpc_ajax_actions', 'show_logs'));
    28         add_action('wp_ajax_wpedpc_run',  array('wpedpc_ajax_actions', 'run_campaign'));
    29         add_action('wp_ajax_wpdpc_now',  array('wpedpc_ajax_actions', 'run_campaign'));
    30         add_action('wp_ajax_wpdpc_logerase',  array('wpedpc_ajax_actions', 'erase_logs'));
    31         add_action('wp_ajax_wpdpc_show',  array('wpedpc_ajax_actions', 'show'));
     28        add_action('wp_ajax_wpedpc_run', array('wpedpc_ajax_actions', 'run_campaign'));
     29        add_action('wp_ajax_wpdpc_now', array('wpedpc_ajax_actions', 'run_campaign'));
     30        add_action('wp_ajax_wpdpc_logerase', array('wpedpc_ajax_actions', 'erase_logs'));
     31        add_action('wp_ajax_wpdpc_show', array('wpedpc_ajax_actions', 'show'));
    3232        add_action('wp_ajax_wpedpc_delapost', array('wpedpc_ajax_actions', 'del_post'));
    33        
    34     }
     33    }
     34
    3535    static function show_logs_campaign() {
    36         if(!isset( $_POST['nonce'] ) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')){
    37             return false;
    38         }
    39 
    40         if ( isset( $_POST['post_id'] ) ) {
     36        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')) {
     37            return false;
     38        }
     39
     40        if (!current_user_can('manage_options')) {
     41            return false;
     42        }
     43
     44        if (isset($_POST['post_id'])) {
    4145            $post_id = $_POST['post_id'];
    42             do_action('wpedpc_show_logs_campaign', $post_id );
    43         }
    44     }
    45     static function show_logs($post_id){
    46         if( ! current_user_can( 'manage_options' ) ) {
    47             return false;
    48         }       
     46            do_action('wpedpc_show_logs_campaign', $post_id);
     47        }
     48    }
     49
     50    static function show_logs($post_id) {
     51        if (!current_user_can('manage_options')) {
     52            return false;
     53        }
    4954        $wpedpc_logs = get_post_meta($post_id, 'logs', true);
    50         $echoHtml = '<h2>'.__('Delete Post Copies Logs', 'etruel-del-post-copies').'</h2>
     55        $echoHtml    = '<h2>' . __('Delete Post Copies Logs', 'etruel-del-post-copies') . '</h2>
    5156                <div id="poststuff" class="metabox-holder">
    5257                <div id="side-info-column" class="inner-sidebar">
     
    5863                        <tr>
    5964                            <th scope="col">#</th>
    60                             <th scope="col">'.__('Date', 'etruel-del-post-copies').'</th>
    61                             <th scope="col">'.__('Mode', 'etruel-del-post-copies').'</th>
    62                             <th scope="col">'.__('Status', 'etruel-del-post-copies').'</th>
    63                             <th scope="col">'.__('Finished In', 'etruel-del-post-copies' ).'</th>
    64                             <th scope="col">'.__('Removed', 'etruel-del-post-copies').'</th>
     65                            <th scope="col">' . __('Date', 'etruel-del-post-copies') . '</th>
     66                            <th scope="col">' . __('Mode', 'etruel-del-post-copies') . '</th>
     67                            <th scope="col">' . __('Status', 'etruel-del-post-copies') . '</th>
     68                            <th scope="col">' . __('Finished In', 'etruel-del-post-copies') . '</th>
     69                            <th scope="col">' . __('Removed', 'etruel-del-post-copies') . '</th>
    6570                        </tr>';
    66         if(!empty($wpedpc_logs)){
     71        if (!empty($wpedpc_logs)) {
    6772            $i = 0;
    68             foreach(array_reverse($wpedpc_logs) as $log) {
     73            foreach (array_reverse($wpedpc_logs) as $log) {
    6974                $i++;
    7075                $rk = $i;
    71                        
     76
    7277                $echoHtml .= '<tr>
    73                                 <td>'.$rk.'</td>
    74                                 <td>'.date('Y-m-d H:i:s', $log['started']).'</td>
    75                                 <td>'.((intval($log['mode']) == 1) ? __('Manual', 'etruel-del-post-copies') : __('Auto', 'etruel-del-post-copies')).'</td>
    76                                 <td>'.((intval($log['status']) == 0) ? __('OK', 'etruel-del-post-copies') : sprintf(
    77                                     // translators: %s represents the number of errors found.   
    78                                     __('%s errors', 'etruel-del-post-copies'), intval($log['status']))).'</td>
    79                                 <td>'.round($log['took'], 3).' '.__('seconds', 'etruel-del-post-copies').'</td>
    80                                 <td>'.sprintf(
    81                                     // translators: %s represents the number of errors found.   
    82                                     __('%s posts', 'etruel-del-post-copies'), intval($log['removed'])).'</td>
    83                             </tr>'; 
    84                 if($i >= 40) {
     78                                <td>' . $rk . '</td>
     79                                <td>' . date('Y-m-d H:i:s', $log['started']) . '</td>
     80                                <td>' . ((intval($log['mode']) == 1) ? __('Manual', 'etruel-del-post-copies') : __('Auto', 'etruel-del-post-copies')) . '</td>
     81                                <td>' . ((intval($log['status']) == 0) ? __('OK', 'etruel-del-post-copies') : sprintf(
     82                                // translators: %s represents the number of errors found.   
     83                                __('%s errors', 'etruel-del-post-copies'), intval($log['status']))) . '</td>
     84                                <td>' . round($log['took'], 3) . ' ' . __('seconds', 'etruel-del-post-copies') . '</td>
     85                                <td>' . sprintf(
     86                                // translators: %s represents the number of errors found.   
     87                                __('%s posts', 'etruel-del-post-copies'), intval($log['removed'])) . '</td>
     88                            </tr>';
     89                if ($i >= 40) {
    8590                    break;
    8691                }
     
    9095        $echoHtml .= '</table></div></div></div></div>';
    9196        wp_die($echoHtml);
    92 
    93     }
     97    }
     98
    9499    public static function run_campaign() {
    95         if(!isset( $_POST['nonce'] ) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')){
    96             return false;
    97         }
     100        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')) {
     101            return false;
     102        }
     103
     104        if (!current_user_can('manage_options')) {
     105            return false;
     106        }
     107
    98108        // Verify campaign_ID exists and sanitize input
    99109        if (!isset($_POST['campaign_ID'])) {
    100110            wp_send_json_error(array('message' => __('Campaign ID must exist.', 'etruel-del-post-copies')));
    101111        }
    102    
     112
    103113        $post_id = absint($_POST['campaign_ID']); // Ensure it's a valid integer
    104114        $quickdo = 'WPdpc_now';
    105    
     115
    106116        // Apply the campaign filter
    107117        $response_run = apply_filters('wpedpc_run_campaign', $post_id, $quickdo, array(
     
    109119            'success' => false
    110120        ));
    111    
     121
    112122        // Send JSON response based on the filter result
    113123        if ($response_run['success']) {
     
    117127        }
    118128    }
     129
    119130    public static function erase_logs() {
    120131        // 1. Verify nonce for CSRF protection
     
    122133            wp_send_json_error(array('message' => __('Security check failed', 'etruel-del-post-copies')));
    123134        }
    124    
     135
    125136        // 2. Check if user has proper capabilities
    126137        if (!current_user_can('manage_options')) {
    127138            wp_send_json_error(array('message' => __('Insufficient permissions', 'etruel-del-post-copies')));
    128139        }
    129    
     140
    130141        // 3. Validate and sanitize campaign ID
    131142        $campaign_id = isset($_REQUEST['campaign_ID']) ? absint($_REQUEST['campaign_ID']) : 0;
     
    133144            wp_send_json_error(array('message' => __('Invalid campaign ID or campaign not found', 'etruel-del-post-copies')));
    134145        }
    135    
     146
    136147        // 4. Check if user can edit the campaign
    137148        if (!current_user_can('edit_post', $campaign_id)) {
    138149            wp_send_json_error(array('message' => __('Permission denied', 'etruel-del-post-copies')));
    139150        }
    140    
     151
    141152        // 5. Delete the logs meta key
    142153        if (delete_post_meta($campaign_id, 'logs')) {
     
    148159
    149160    public static function show() {
    150         if(!isset( $_POST['nonce'] ) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')){
     161        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')) {
     162            return false;
     163        }
     164
     165        if (!current_user_can('manage_options')) {
    151166            return false;
    152167        }
     
    155170            wp_send_json_error(array('message' => __('Campaign ID must exist.', 'etruel-del-post-copies')));
    156171        }
    157    
     172
    158173        $post_id = absint($_POST['campaign_ID']); // Ensure it's an integer
    159174        $quickdo = 'WPdpc_show';
    160    
     175
    161176        // Apply campaign filter
    162177        $response_run = apply_filters('wpedpc_run_campaign', $post_id, $quickdo, array());
    163    
     178
    164179        // Return the results
    165180        wp_send_json_success(array('results' => $response_run['results']));
    166181    }
    167    
     182
    168183    public static function del_post() {
    169         if(!isset( $_POST['nonce'] ) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')){
    170             return false;
    171         }
     184        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'etruel-del-post-copies')) {
     185            return false;
     186        }
     187
     188        if (!current_user_can('manage_options')) {
     189            return false;
     190        }
     191
    172192        // Verify nonce for security
    173193        if (!isset($_POST['url'], $_POST['post_id'], $_POST['campaign_ID'])) {
    174194            wp_send_json_error(array('message' => __('Missing required parameters.', 'etruel-del-post-copies')));
    175195        }
    176    
     196
    177197        // Extract nonce from URL
    178         $url = esc_url_raw($_POST['url']);
     198        $url   = esc_url_raw($_POST['url']);
    179199        parse_str(parse_url($url, PHP_URL_QUERY), $path);
    180200        $nonce = $path['_wpnonce'] ?? '';
    181    
    182         $post_id = absint($_POST['post_id']);
     201
     202        $post_id    = absint($_POST['post_id']);
    183203        $campaign_id = absint($_POST['campaign_ID']);
    184    
     204
     205        if (!current_user_can('edit_post', $campaign_id)) {
     206            wp_send_json_error(array('message' => __('Permission denied', 'etruel-del-post-copies')));
     207        }
     208
    185209        // Security check
    186210        if (!wp_verify_nonce($nonce, 'delete-post_' . $post_id)) {
    187211            wp_send_json_error(array('message' => __('Security check failed.', 'etruel-del-post-copies')));
    188212        }
    189    
     213
    190214        // Validate campaign exists
    191         $campaign = get_post_meta($campaign_id, '_campaign_settings', true);
     215        $campaign = new WPEDPC_Campaign($campaign_id);
     216
    192217        if (!$campaign) {
    193218            wp_send_json_error(array('message' => __('Campaign not found.', 'etruel-del-post-copies')));
    194219        }
    195    
    196220        // Extract deletion settings
    197         $deletemedia = $campaign['deletemedia'] ?? false;
    198         $delimgcontent = $campaign['delimgcontent'] ?? false;
    199         $force_delete = empty($campaign['movetotrash']);
    200    
     221        $deletemedia   = $campaign->deletemedia ?? false;
     222        $delimgcontent = $campaign->delimgcontent ?? false;
     223        $force_delete  = empty($campaign->movetotrash);
     224
    201225        // Get post details
    202226        $post = get_post($post_id);
     
    204228            wp_send_json_error(array('message' => __('Post not found.', 'etruel-del-post-copies')));
    205229        }
    206    
     230
    207231        $post_title = $post->post_title;
    208         $permalink = get_permalink($post_id);
    209    
     232        $permalink  = get_permalink($post_id);
     233
    210234        // Delete media attachments if required
    211235        if ($deletemedia) {
    212236            $attachments = get_children([
    213237                'post_parent' => $post_id,
    214                 'post_type'   => 'attachment',
    215                 'fields'      => 'ids',
     238                'post_type'   => 'attachment',
     239                'fields'      => 'ids',
    216240            ]);
    217    
     241
    218242            foreach ($attachments as $attachment_id) {
    219243                wp_delete_attachment($attachment_id, $force_delete);
    220244            }
    221245        }
    222    
     246
    223247        // Delete images inside content
    224248        if ($delimgcontent) {
     
    231255            }
    232256        }
    233    
     257
    234258        // Delete all custom fields in one go
    235259        delete_post_meta_by_key($post_id);
    236    
     260
    237261        // Delete the post
    238262        $result = wp_delete_post($post_id, $force_delete);
    239    
     263
    240264        if (!$result) {
    241             wp_send_json_error(array('message' => sprintf(__('Error deleting post %1$s - %2$s', 'etruel-del-post-copies'), $post_id, $permalink)));
    242         }
    243    
    244         wp_send_json_success(array('message' => sprintf(__("'%1$s' (ID #%2$s) Deleted!", 'etruel-del-post-copies'), $post_title, $post_id)));
     265            wp_send_json_error(array('message' => sprintf(__('Error deleting post %1s - %2s', 'etruel-del-post-copies'), $post_id, $permalink)));
     266        }
     267
     268        wp_send_json_success(array('message' => sprintf(__("'%1s' (ID #%2s) Deleted!", 'etruel-del-post-copies'), $post_title, $post_id)));
    245269    }
    246270}
    247271
    248272$wpedpc_ajax_actions = new wpedpc_ajax_actions();
    249 
    250 
    251 
    252 
    253 
    254 
    255 ?>
  • etruel-del-post-copies/trunk/readme.txt

    r3261804 r3263895  
    5858
    5959== Changelog ==
    60 = 6.0 Mar 25, 2025 =
     60= 6.0 Mar 29, 2025 =
    6161* Major version. Important release & must update version.
    6262* **First use should be in a test environment.**
Note: See TracChangeset for help on using the changeset viewer.