Changeset 3263895
- Timestamp:
- 03/29/2025 06:01:38 PM (12 months ago)
- Location:
- etruel-del-post-copies
- Files:
-
- 6 edited
-
tags/6.0/edel-post-copies.php (modified) (13 diffs)
-
tags/6.0/includes/ajax-actions.php (modified) (13 diffs)
-
tags/6.0/readme.txt (modified) (1 diff)
-
trunk/edel-post-copies.php (modified) (13 diffs)
-
trunk/includes/ajax-actions.php (modified) (13 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
etruel-del-post-copies/tags/6.0/edel-post-copies.php
r3261804 r3263895 45 45 class edel_post_copies { 46 46 47 private static $instance = null;47 private static $instance = null; 48 48 public static $prorequired = '2.5'; 49 49 … … 60 60 $this->includes(); 61 61 $this->setup_actions(); 62 $this->load_textdomain();62 //$this->load_textdomain(); 63 63 } 64 64 … … 68 68 add_filter('cron_schedules', array($this, 'wpedpc_cron_recurrence')); 69 69 add_action('init', array($this, 'wpedpc_custom_cron')); 70 add_action('init', array($this, 'load_textdomain')); 70 71 add_filter('wpedpc_env_checks', array($this, 'wpedpc_env_checks')); 71 72 do_action('wpedpc_setup_actions'); … … 82 83 _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin’ huh?', 'etruel-del-post-copies'), '1.6'); 83 84 } 84 85 85 86 private function setup_globals() { 86 87 … … 145 146 public static function autoloader($class_name) { 146 147 $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'; 148 149 if (file_exists($file)) { 149 150 require_once $file; … … 152 153 153 154 public function load_textdomain() { 154 // Set filter for plugin's languagesdirectory155 // textdomain directory 155 156 $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); 176 159 } 177 160 … … 199 182 function wpedpc_cron_recurrence($schedules) { 200 183 $schedules['wpedpc_interval'] = array( 201 'display' => __('Every Five Minutes', 'textdomain'),184 'display' => __('Every Five Minutes', 'textdomain'), 202 185 'interval' => 300, 203 186 ); … … 214 197 function wpedpc_cron_callback() { 215 198 216 $args = array('post_type' => 'wpedpcampaign', 'orderby' => 'ID', 'order' => 'ASC', 'numberposts' => -1);199 $args = array('post_type' => 'wpedpcampaign', 'orderby' => 'ID', 'order' => 'ASC', 'numberposts' => -1); 217 200 $campaigns = get_posts($args); 218 201 foreach ($campaigns as $post) { … … 240 223 foreach ($cronarrayvalue as $key => $value) { 241 224 //steps 242 $step = 1;225 $step = 1; 243 226 if (strstr($value, '/')) 244 227 list($value, $step) = explode('/', $value, 2); … … 249 232 if (strstr($value, '-')) { 250 233 list($first, $last) = explode('-', $value, 2); 251 if (!is_numeric($first) or !is_numeric($last) or $last > 60 or $first > 60) //check234 if (!is_numeric($first) or !is_numeric($last) or $last > 60 or $first > 60) //check 252 235 return false; 253 236 if ($cronarraykey == 'minutes' and $step < 5) //set step ninmum to 5 min. … … 285 268 //Month names 286 269 if (strtolower($value) == 'jan') 287 $value = 1;270 $value = 1; 288 271 if (strtolower($value) == 'feb') 289 $value = 2;272 $value = 2; 290 273 if (strtolower($value) == 'mar') 291 $value = 3;274 $value = 3; 292 275 if (strtolower($value) == 'apr') 293 $value = 4;276 $value = 4; 294 277 if (strtolower($value) == 'may') 295 $value = 5;278 $value = 5; 296 279 if (strtolower($value) == 'jun') 297 $value = 6;280 $value = 6; 298 281 if (strtolower($value) == 'jul') 299 $value = 7;282 $value = 7; 300 283 if (strtolower($value) == 'aug') 301 $value = 8;284 $value = 8; 302 285 if (strtolower($value) == 'sep') 303 $value = 9;286 $value = 9; 304 287 if (strtolower($value) == 'oct') 305 $value = 10;288 $value = 10; 306 289 if (strtolower($value) == 'nov') 307 $value = 11;290 $value = 11; 308 291 if (strtolower($value) == 'dec') 309 $value = 12;292 $value = 12; 310 293 //Week Day names 311 294 if (strtolower($value) == 'sun') 312 $value = 0;295 $value = 0; 313 296 if (strtolower($value) == 'sat') 314 $value = 6;297 $value = 6; 315 298 if (strtolower($value) == 'mon') 316 $value = 1;299 $value = 1; 317 300 if (strtolower($value) == 'tue') 318 $value = 2;301 $value = 2; 319 302 if (strtolower($value) == 'wed') 320 $value = 3;303 $value = 3; 321 304 if (strtolower($value) == 'thu') 322 $value = 4;305 $value = 4; 323 306 if (strtolower($value) == 'fri') 324 $value = 5;307 $value = 5; 325 308 if (!is_numeric($value) or $value > 60) //check 326 309 return false; … … 367 350 if (version_compare($wp_version, '3.1', '<')) { // check WP Version 368 351 $message .= __('- WordPress 3.1 or higher needed!', 'etruel-del-post-copies') . '<br />'; 369 $checks = false;352 $checks = false; 370 353 } 371 354 if (version_compare(phpversion(), '5.4.0', '<')) { // check PHP Version 372 355 $message .= __('- PHP 5.4.0 or higher needed!', 'etruel-del-post-copies') . '<br />'; 373 $checks = false;356 $checks = false; 374 357 } 375 358 //put massage if one … … 383 366 static function wpedpc_env_checks_notice() { 384 367 global $wpedpc_admin_message; 385 echo esc_html($wpedpc_admin_message); 386 } 387 368 echo wp_kses_post($wpedpc_admin_message); 369 } 388 370 } 389 371 -
etruel-del-post-copies/tags/6.0/includes/ajax-actions.php
r3261804 r3263895 1 1 <?php 2 2 3 /** 3 4 * Ajax Actions … … 9 10 * @since 5.0 10 11 */ 11 12 12 // Exit if accessed directly 13 if ( ! defined( 'ABSPATH' ) ) exit;14 13 if (!defined('ABSPATH')) 14 exit; 15 15 16 16 /** … … 21 21 */ 22 22 class wpedpc_ajax_actions { 23 23 24 24 function __construct() { 25 25 26 26 add_action('wp_ajax_wpedpc_show_logs_campaign', array('wpedpc_ajax_actions', 'show_logs_campaign')); 27 27 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')); 32 32 add_action('wp_ajax_wpedpc_delapost', array('wpedpc_ajax_actions', 'del_post')); 33 34 } 33 } 34 35 35 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'])) { 41 45 $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 } 49 54 $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> 51 56 <div id="poststuff" class="metabox-holder"> 52 57 <div id="side-info-column" class="inner-sidebar"> … … 58 63 <tr> 59 64 <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> 65 70 </tr>'; 66 if (!empty($wpedpc_logs)){71 if (!empty($wpedpc_logs)) { 67 72 $i = 0; 68 foreach (array_reverse($wpedpc_logs) as $log) {73 foreach (array_reverse($wpedpc_logs) as $log) { 69 74 $i++; 70 75 $rk = $i; 71 76 72 77 $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) { 85 90 break; 86 91 } … … 90 95 $echoHtml .= '</table></div></div></div></div>'; 91 96 wp_die($echoHtml); 92 93 } 97 } 98 94 99 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 98 108 // Verify campaign_ID exists and sanitize input 99 109 if (!isset($_POST['campaign_ID'])) { 100 110 wp_send_json_error(array('message' => __('Campaign ID must exist.', 'etruel-del-post-copies'))); 101 111 } 102 112 103 113 $post_id = absint($_POST['campaign_ID']); // Ensure it's a valid integer 104 114 $quickdo = 'WPdpc_now'; 105 115 106 116 // Apply the campaign filter 107 117 $response_run = apply_filters('wpedpc_run_campaign', $post_id, $quickdo, array( … … 109 119 'success' => false 110 120 )); 111 121 112 122 // Send JSON response based on the filter result 113 123 if ($response_run['success']) { … … 117 127 } 118 128 } 129 119 130 public static function erase_logs() { 120 131 // 1. Verify nonce for CSRF protection … … 122 133 wp_send_json_error(array('message' => __('Security check failed', 'etruel-del-post-copies'))); 123 134 } 124 135 125 136 // 2. Check if user has proper capabilities 126 137 if (!current_user_can('manage_options')) { 127 138 wp_send_json_error(array('message' => __('Insufficient permissions', 'etruel-del-post-copies'))); 128 139 } 129 140 130 141 // 3. Validate and sanitize campaign ID 131 142 $campaign_id = isset($_REQUEST['campaign_ID']) ? absint($_REQUEST['campaign_ID']) : 0; … … 133 144 wp_send_json_error(array('message' => __('Invalid campaign ID or campaign not found', 'etruel-del-post-copies'))); 134 145 } 135 146 136 147 // 4. Check if user can edit the campaign 137 148 if (!current_user_can('edit_post', $campaign_id)) { 138 149 wp_send_json_error(array('message' => __('Permission denied', 'etruel-del-post-copies'))); 139 150 } 140 151 141 152 // 5. Delete the logs meta key 142 153 if (delete_post_meta($campaign_id, 'logs')) { … … 148 159 149 160 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')) { 151 166 return false; 152 167 } … … 155 170 wp_send_json_error(array('message' => __('Campaign ID must exist.', 'etruel-del-post-copies'))); 156 171 } 157 172 158 173 $post_id = absint($_POST['campaign_ID']); // Ensure it's an integer 159 174 $quickdo = 'WPdpc_show'; 160 175 161 176 // Apply campaign filter 162 177 $response_run = apply_filters('wpedpc_run_campaign', $post_id, $quickdo, array()); 163 178 164 179 // Return the results 165 180 wp_send_json_success(array('results' => $response_run['results'])); 166 181 } 167 182 168 183 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 172 192 // Verify nonce for security 173 193 if (!isset($_POST['url'], $_POST['post_id'], $_POST['campaign_ID'])) { 174 194 wp_send_json_error(array('message' => __('Missing required parameters.', 'etruel-del-post-copies'))); 175 195 } 176 196 177 197 // Extract nonce from URL 178 $url = esc_url_raw($_POST['url']);198 $url = esc_url_raw($_POST['url']); 179 199 parse_str(parse_url($url, PHP_URL_QUERY), $path); 180 200 $nonce = $path['_wpnonce'] ?? ''; 181 182 $post_id = absint($_POST['post_id']);201 202 $post_id = absint($_POST['post_id']); 183 203 $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 185 209 // Security check 186 210 if (!wp_verify_nonce($nonce, 'delete-post_' . $post_id)) { 187 211 wp_send_json_error(array('message' => __('Security check failed.', 'etruel-del-post-copies'))); 188 212 } 189 213 190 214 // Validate campaign exists 191 $campaign = get_post_meta($campaign_id, '_campaign_settings', true); 215 $campaign = new WPEDPC_Campaign($campaign_id); 216 192 217 if (!$campaign) { 193 218 wp_send_json_error(array('message' => __('Campaign not found.', 'etruel-del-post-copies'))); 194 219 } 195 196 220 // 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 201 225 // Get post details 202 226 $post = get_post($post_id); … … 204 228 wp_send_json_error(array('message' => __('Post not found.', 'etruel-del-post-copies'))); 205 229 } 206 230 207 231 $post_title = $post->post_title; 208 $permalink = get_permalink($post_id);209 232 $permalink = get_permalink($post_id); 233 210 234 // Delete media attachments if required 211 235 if ($deletemedia) { 212 236 $attachments = get_children([ 213 237 'post_parent' => $post_id, 214 'post_type' => 'attachment',215 'fields' => 'ids',238 'post_type' => 'attachment', 239 'fields' => 'ids', 216 240 ]); 217 241 218 242 foreach ($attachments as $attachment_id) { 219 243 wp_delete_attachment($attachment_id, $force_delete); 220 244 } 221 245 } 222 246 223 247 // Delete images inside content 224 248 if ($delimgcontent) { … … 231 255 } 232 256 } 233 257 234 258 // Delete all custom fields in one go 235 259 delete_post_meta_by_key($post_id); 236 260 237 261 // Delete the post 238 262 $result = wp_delete_post($post_id, $force_delete); 239 263 240 264 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))); 245 269 } 246 270 } 247 271 248 272 $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 58 58 59 59 == Changelog == 60 = 6.0 Mar 16, 2025 =60 = 6.0 Mar 29, 2025 = 61 61 * Major version. Important release & must update version. 62 62 * **First use should be in a test environment.** -
etruel-del-post-copies/trunk/edel-post-copies.php
r3261804 r3263895 45 45 class edel_post_copies { 46 46 47 private static $instance = null;47 private static $instance = null; 48 48 public static $prorequired = '2.5'; 49 49 … … 60 60 $this->includes(); 61 61 $this->setup_actions(); 62 $this->load_textdomain();62 //$this->load_textdomain(); 63 63 } 64 64 … … 68 68 add_filter('cron_schedules', array($this, 'wpedpc_cron_recurrence')); 69 69 add_action('init', array($this, 'wpedpc_custom_cron')); 70 add_action('init', array($this, 'load_textdomain')); 70 71 add_filter('wpedpc_env_checks', array($this, 'wpedpc_env_checks')); 71 72 do_action('wpedpc_setup_actions'); … … 82 83 _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin’ huh?', 'etruel-del-post-copies'), '1.6'); 83 84 } 84 85 85 86 private function setup_globals() { 86 87 … … 145 146 public static function autoloader($class_name) { 146 147 $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'; 148 149 if (file_exists($file)) { 149 150 require_once $file; … … 152 153 153 154 public function load_textdomain() { 154 // Set filter for plugin's languagesdirectory155 // textdomain directory 155 156 $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); 176 159 } 177 160 … … 199 182 function wpedpc_cron_recurrence($schedules) { 200 183 $schedules['wpedpc_interval'] = array( 201 'display' => __('Every Five Minutes', 'textdomain'),184 'display' => __('Every Five Minutes', 'textdomain'), 202 185 'interval' => 300, 203 186 ); … … 214 197 function wpedpc_cron_callback() { 215 198 216 $args = array('post_type' => 'wpedpcampaign', 'orderby' => 'ID', 'order' => 'ASC', 'numberposts' => -1);199 $args = array('post_type' => 'wpedpcampaign', 'orderby' => 'ID', 'order' => 'ASC', 'numberposts' => -1); 217 200 $campaigns = get_posts($args); 218 201 foreach ($campaigns as $post) { … … 240 223 foreach ($cronarrayvalue as $key => $value) { 241 224 //steps 242 $step = 1;225 $step = 1; 243 226 if (strstr($value, '/')) 244 227 list($value, $step) = explode('/', $value, 2); … … 249 232 if (strstr($value, '-')) { 250 233 list($first, $last) = explode('-', $value, 2); 251 if (!is_numeric($first) or !is_numeric($last) or $last > 60 or $first > 60) //check234 if (!is_numeric($first) or !is_numeric($last) or $last > 60 or $first > 60) //check 252 235 return false; 253 236 if ($cronarraykey == 'minutes' and $step < 5) //set step ninmum to 5 min. … … 285 268 //Month names 286 269 if (strtolower($value) == 'jan') 287 $value = 1;270 $value = 1; 288 271 if (strtolower($value) == 'feb') 289 $value = 2;272 $value = 2; 290 273 if (strtolower($value) == 'mar') 291 $value = 3;274 $value = 3; 292 275 if (strtolower($value) == 'apr') 293 $value = 4;276 $value = 4; 294 277 if (strtolower($value) == 'may') 295 $value = 5;278 $value = 5; 296 279 if (strtolower($value) == 'jun') 297 $value = 6;280 $value = 6; 298 281 if (strtolower($value) == 'jul') 299 $value = 7;282 $value = 7; 300 283 if (strtolower($value) == 'aug') 301 $value = 8;284 $value = 8; 302 285 if (strtolower($value) == 'sep') 303 $value = 9;286 $value = 9; 304 287 if (strtolower($value) == 'oct') 305 $value = 10;288 $value = 10; 306 289 if (strtolower($value) == 'nov') 307 $value = 11;290 $value = 11; 308 291 if (strtolower($value) == 'dec') 309 $value = 12;292 $value = 12; 310 293 //Week Day names 311 294 if (strtolower($value) == 'sun') 312 $value = 0;295 $value = 0; 313 296 if (strtolower($value) == 'sat') 314 $value = 6;297 $value = 6; 315 298 if (strtolower($value) == 'mon') 316 $value = 1;299 $value = 1; 317 300 if (strtolower($value) == 'tue') 318 $value = 2;301 $value = 2; 319 302 if (strtolower($value) == 'wed') 320 $value = 3;303 $value = 3; 321 304 if (strtolower($value) == 'thu') 322 $value = 4;305 $value = 4; 323 306 if (strtolower($value) == 'fri') 324 $value = 5;307 $value = 5; 325 308 if (!is_numeric($value) or $value > 60) //check 326 309 return false; … … 367 350 if (version_compare($wp_version, '3.1', '<')) { // check WP Version 368 351 $message .= __('- WordPress 3.1 or higher needed!', 'etruel-del-post-copies') . '<br />'; 369 $checks = false;352 $checks = false; 370 353 } 371 354 if (version_compare(phpversion(), '5.4.0', '<')) { // check PHP Version 372 355 $message .= __('- PHP 5.4.0 or higher needed!', 'etruel-del-post-copies') . '<br />'; 373 $checks = false;356 $checks = false; 374 357 } 375 358 //put massage if one … … 383 366 static function wpedpc_env_checks_notice() { 384 367 global $wpedpc_admin_message; 385 echo esc_html($wpedpc_admin_message); 386 } 387 368 echo wp_kses_post($wpedpc_admin_message); 369 } 388 370 } 389 371 -
etruel-del-post-copies/trunk/includes/ajax-actions.php
r3261804 r3263895 1 1 <?php 2 2 3 /** 3 4 * Ajax Actions … … 9 10 * @since 5.0 10 11 */ 11 12 12 // Exit if accessed directly 13 if ( ! defined( 'ABSPATH' ) ) exit;14 13 if (!defined('ABSPATH')) 14 exit; 15 15 16 16 /** … … 21 21 */ 22 22 class wpedpc_ajax_actions { 23 23 24 24 function __construct() { 25 25 26 26 add_action('wp_ajax_wpedpc_show_logs_campaign', array('wpedpc_ajax_actions', 'show_logs_campaign')); 27 27 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')); 32 32 add_action('wp_ajax_wpedpc_delapost', array('wpedpc_ajax_actions', 'del_post')); 33 34 } 33 } 34 35 35 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'])) { 41 45 $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 } 49 54 $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> 51 56 <div id="poststuff" class="metabox-holder"> 52 57 <div id="side-info-column" class="inner-sidebar"> … … 58 63 <tr> 59 64 <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> 65 70 </tr>'; 66 if (!empty($wpedpc_logs)){71 if (!empty($wpedpc_logs)) { 67 72 $i = 0; 68 foreach (array_reverse($wpedpc_logs) as $log) {73 foreach (array_reverse($wpedpc_logs) as $log) { 69 74 $i++; 70 75 $rk = $i; 71 76 72 77 $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) { 85 90 break; 86 91 } … … 90 95 $echoHtml .= '</table></div></div></div></div>'; 91 96 wp_die($echoHtml); 92 93 } 97 } 98 94 99 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 98 108 // Verify campaign_ID exists and sanitize input 99 109 if (!isset($_POST['campaign_ID'])) { 100 110 wp_send_json_error(array('message' => __('Campaign ID must exist.', 'etruel-del-post-copies'))); 101 111 } 102 112 103 113 $post_id = absint($_POST['campaign_ID']); // Ensure it's a valid integer 104 114 $quickdo = 'WPdpc_now'; 105 115 106 116 // Apply the campaign filter 107 117 $response_run = apply_filters('wpedpc_run_campaign', $post_id, $quickdo, array( … … 109 119 'success' => false 110 120 )); 111 121 112 122 // Send JSON response based on the filter result 113 123 if ($response_run['success']) { … … 117 127 } 118 128 } 129 119 130 public static function erase_logs() { 120 131 // 1. Verify nonce for CSRF protection … … 122 133 wp_send_json_error(array('message' => __('Security check failed', 'etruel-del-post-copies'))); 123 134 } 124 135 125 136 // 2. Check if user has proper capabilities 126 137 if (!current_user_can('manage_options')) { 127 138 wp_send_json_error(array('message' => __('Insufficient permissions', 'etruel-del-post-copies'))); 128 139 } 129 140 130 141 // 3. Validate and sanitize campaign ID 131 142 $campaign_id = isset($_REQUEST['campaign_ID']) ? absint($_REQUEST['campaign_ID']) : 0; … … 133 144 wp_send_json_error(array('message' => __('Invalid campaign ID or campaign not found', 'etruel-del-post-copies'))); 134 145 } 135 146 136 147 // 4. Check if user can edit the campaign 137 148 if (!current_user_can('edit_post', $campaign_id)) { 138 149 wp_send_json_error(array('message' => __('Permission denied', 'etruel-del-post-copies'))); 139 150 } 140 151 141 152 // 5. Delete the logs meta key 142 153 if (delete_post_meta($campaign_id, 'logs')) { … … 148 159 149 160 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')) { 151 166 return false; 152 167 } … … 155 170 wp_send_json_error(array('message' => __('Campaign ID must exist.', 'etruel-del-post-copies'))); 156 171 } 157 172 158 173 $post_id = absint($_POST['campaign_ID']); // Ensure it's an integer 159 174 $quickdo = 'WPdpc_show'; 160 175 161 176 // Apply campaign filter 162 177 $response_run = apply_filters('wpedpc_run_campaign', $post_id, $quickdo, array()); 163 178 164 179 // Return the results 165 180 wp_send_json_success(array('results' => $response_run['results'])); 166 181 } 167 182 168 183 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 172 192 // Verify nonce for security 173 193 if (!isset($_POST['url'], $_POST['post_id'], $_POST['campaign_ID'])) { 174 194 wp_send_json_error(array('message' => __('Missing required parameters.', 'etruel-del-post-copies'))); 175 195 } 176 196 177 197 // Extract nonce from URL 178 $url = esc_url_raw($_POST['url']);198 $url = esc_url_raw($_POST['url']); 179 199 parse_str(parse_url($url, PHP_URL_QUERY), $path); 180 200 $nonce = $path['_wpnonce'] ?? ''; 181 182 $post_id = absint($_POST['post_id']);201 202 $post_id = absint($_POST['post_id']); 183 203 $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 185 209 // Security check 186 210 if (!wp_verify_nonce($nonce, 'delete-post_' . $post_id)) { 187 211 wp_send_json_error(array('message' => __('Security check failed.', 'etruel-del-post-copies'))); 188 212 } 189 213 190 214 // Validate campaign exists 191 $campaign = get_post_meta($campaign_id, '_campaign_settings', true); 215 $campaign = new WPEDPC_Campaign($campaign_id); 216 192 217 if (!$campaign) { 193 218 wp_send_json_error(array('message' => __('Campaign not found.', 'etruel-del-post-copies'))); 194 219 } 195 196 220 // 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 201 225 // Get post details 202 226 $post = get_post($post_id); … … 204 228 wp_send_json_error(array('message' => __('Post not found.', 'etruel-del-post-copies'))); 205 229 } 206 230 207 231 $post_title = $post->post_title; 208 $permalink = get_permalink($post_id);209 232 $permalink = get_permalink($post_id); 233 210 234 // Delete media attachments if required 211 235 if ($deletemedia) { 212 236 $attachments = get_children([ 213 237 'post_parent' => $post_id, 214 'post_type' => 'attachment',215 'fields' => 'ids',238 'post_type' => 'attachment', 239 'fields' => 'ids', 216 240 ]); 217 241 218 242 foreach ($attachments as $attachment_id) { 219 243 wp_delete_attachment($attachment_id, $force_delete); 220 244 } 221 245 } 222 246 223 247 // Delete images inside content 224 248 if ($delimgcontent) { … … 231 255 } 232 256 } 233 257 234 258 // Delete all custom fields in one go 235 259 delete_post_meta_by_key($post_id); 236 260 237 261 // Delete the post 238 262 $result = wp_delete_post($post_id, $force_delete); 239 263 240 264 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))); 245 269 } 246 270 } 247 271 248 272 $wpedpc_ajax_actions = new wpedpc_ajax_actions(); 249 250 251 252 253 254 255 ?> -
etruel-del-post-copies/trunk/readme.txt
r3261804 r3263895 58 58 59 59 == Changelog == 60 = 6.0 Mar 2 5, 2025 =60 = 6.0 Mar 29, 2025 = 61 61 * Major version. Important release & must update version. 62 62 * **First use should be in a test environment.**
Note: See TracChangeset
for help on using the changeset viewer.