Changeset 3302346
- Timestamp:
- 05/28/2025 03:42:45 PM (9 months ago)
- Location:
- delete-posts-by-url/trunk
- Files:
-
- 3 edited
-
assets/css/admin.css (modified) (4 diffs)
-
assets/js/admin.js (modified) (5 diffs)
-
delete-posts-by-url.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
delete-posts-by-url/trunk/assets/css/admin.css
r3302285 r3302346 5 5 } 6 6 7 .bdbu-header { 8 display: flex; 9 align-items: center; 10 margin-bottom: 30px; 11 gap: 20px; 7 .dpbu-header { 8 margin-bottom: 20px; 9 padding: 20px; 10 background: #fff; 11 border: 1px solid #ccd0d4; 12 box-shadow: 0 1px 1px rgba(0,0,0,.04); 12 13 } 13 14 14 .bdbu-logo { 15 .dpbu-header h1 { 16 margin: 0; 17 padding: 0; 18 font-size: 23px; 19 font-weight: 400; 20 line-height: 1.3; 21 } 22 23 .dpbu-logo { 15 24 width: 64px; 16 25 height: 64px; … … 18 27 } 19 28 20 .bdbu-branding { 21 margin-left: auto; 22 text-align: right; 29 .dpbu-branding { 30 margin-top: 10px; 23 31 font-size: 13px; 24 32 color: #646970; 25 33 } 26 34 27 . bdbu-branding a {35 .dpbu-branding a { 28 36 color: #2271b1; 29 37 text-decoration: none; 30 38 } 31 39 32 . bdbu-branding a:hover {40 .dpbu-branding a:hover { 33 41 color: #135e96; 34 42 } 35 43 36 .bdbu-options { 44 .dpbu-options { 45 margin-bottom: 20px; 46 padding: 20px; 37 47 background: #fff; 38 border: 1px solid #c3c4c7; 39 border-radius: 4px; 40 padding: 20px; 41 margin-bottom: 30px; 48 border: 1px solid #ccd0d4; 49 box-shadow: 0 1px 1px rgba(0,0,0,.04); 50 } 51 52 .dpbu-options label { 53 display: block; 54 margin-bottom: 10px; 42 55 } 43 56 … … 55 68 } 56 69 57 .bdbu-input { 70 .dpbu-input { 71 margin-bottom: 20px; 72 padding: 20px; 58 73 background: #fff; 59 border: 1px solid #c3c4c7; 60 border-radius: 4px; 61 padding: 20px; 62 margin-bottom: 30px; 74 border: 1px solid #ccd0d4; 75 box-shadow: 0 1px 1px rgba(0,0,0,.04); 63 76 } 64 77 … … 68 81 } 69 82 70 .bdbu-progress { 71 background: #fff; 72 border: 1px solid #c3c4c7; 73 border-radius: 4px; 74 padding: 20px; 75 margin-bottom: 30px; 83 .dpbu-examples { 84 margin: 10px 0; 85 padding-left: 20px; 86 color: #646970; 76 87 } 77 88 78 .progress-bar { 89 .dpbu-progress { 90 margin: 20px 0; 91 } 92 93 .dpbu-progress .progress-bar { 79 94 height: 20px; 95 background-color: #f0f0f1; 96 border: 1px solid #c3c4c7; 97 border-radius: 3px; 98 overflow: hidden; 99 } 100 101 .dpbu-progress .progress-bar div { 102 height: 100%; 80 103 background-color: #2271b1; 81 104 width: 0; 82 border-radius: 10px;83 105 transition: width 0.3s ease; 84 106 } 85 107 86 .progress-text { 87 text-align: center; 88 margin-top: 10px; 89 color: #646970; 108 .dpbu-results { 109 margin-top: 20px; 110 padding: 20px; 111 background: #fff; 112 border: 1px solid #ccd0d4; 113 box-shadow: 0 1px 1px rgba(0,0,0,.04); 90 114 } 91 115 92 .bdbu-results { 93 background: #fff; 94 border: 1px solid #c3c4c7; 95 border-radius: 4px; 96 padding: 20px; 116 .dpbu-results h3 { 117 margin-top: 0; 118 } 119 120 .dpbu-results .results-content { 121 margin-top: 10px; 122 } 123 124 .dpbu-results .success { 125 color: #00a32a; 126 } 127 128 .dpbu-results .error { 129 color: #d63638; 97 130 } 98 131 -
delete-posts-by-url/trunk/assets/js/admin.js
r3302285 r3302346 1 1 jQuery(document).ready(function($) { 2 const form = $('# bdbu-delete-form');3 const progress = $('. bdbu-progress');4 const progressBar = $('.progress-bar');5 const progressText = $('.progress-text');6 const results = $('. bdbu-results');7 const resultsContent = $('.results-content');2 const form = $('#dpbu-delete-form'); 3 const progress = $('.dpbu-progress'); 4 const progressBar = progress.find('.progress-bar'); 5 const progressText = progress.find('.progress-text'); 6 const results = $('.dpbu-results'); 7 const resultsContent = results.find('.results-content'); 8 8 const submitButton = form.find('button[type="submit"]'); 9 9 … … 11 11 e.preventDefault(); 12 12 13 const urls = $('textarea[name="urls"]').val().trim() .split('\n').filter(url => url.trim());14 if (!urls .length) {15 displayError('Please enter at least one URL.');13 const urls = $('textarea[name="urls"]').val().trim(); 14 if (!urls) { 15 alert(dpbuAdmin.messages.noUrls); 16 16 return; 17 17 } 18 18 19 if (!confirm( bdbuAdmin.confirmMsg)) {19 if (!confirm(dpbuAdmin.confirmMsg)) { 20 20 return; 21 21 } 22 22 23 23 const formData = new FormData(this); 24 formData.append('action', ' bdbu_process_urls');25 formData.append('nonce', bdbuAdmin.nonce);24 formData.append('action', 'dpbu_process_urls'); 25 formData.append('nonce', dpbuAdmin.nonce); 26 26 27 27 // Reset and show progress 28 28 progress.show(); 29 results.hide(); 29 30 progressBar.width('0%'); 30 31 progressText.text('Processing...'); 31 results.hide();32 resultsContent.empty();33 32 submitButton.prop('disabled', true); 34 33 … … 44 43 45 44 $.ajax({ 46 url: bdbuAdmin.ajaxurl,45 url: dpbuAdmin.ajaxurl, 47 46 type: 'POST', 48 47 data: formData, … … 55 54 56 55 if (response.success) { 57 displayResults(response.data); 56 const data = response.data; 57 let html = ''; 58 59 if (data.deleted.length > 0) { 60 html += '<h4 class="success">Successfully Deleted:</h4><ul>'; 61 data.deleted.forEach(function(item) { 62 html += '<li>' + item.title + ' (' + item.url + ')</li>'; 63 }); 64 html += '</ul>'; 65 } 66 67 if (data.failed.length > 0) { 68 html += '<h4 class="error">Failed to Delete:</h4><ul>'; 69 data.failed.forEach(function(item) { 70 html += '<li>' + item.url + ' - ' + item.reason + '</li>'; 71 }); 72 html += '</ul>'; 73 } 74 75 if (data.not_found.length > 0) { 76 html += '<h4 class="error">Not Found:</h4><ul>'; 77 data.not_found.forEach(function(url) { 78 html += '<li>' + url + '</li>'; 79 }); 80 html += '</ul>'; 81 } 82 83 resultsContent.html(html); 84 results.show(); 58 85 } else { 59 displayError(response.data.message);86 alert(response.data.message || 'An error occurred'); 60 87 } 61 88 }, … … 74 101 }); 75 102 76 function displayResults(data) {77 let html = '';78 let totalProcessed = data.deleted.length + data.failed.length + data.not_found.length;79 80 html += '<div class="notice notice-info"><p>' +81 'Processed ' + totalProcessed + ' URLs in total.</p></div>';82 83 if (data.deleted.length > 0) {84 html += '<div class="notice notice-success"><p>' +85 data.deleted.length + ' posts have been deleted successfully:</p><ul>';86 87 data.deleted.forEach(function(item) {88 html += '<li>' + escapeHtml(item.title) + ' (' + escapeHtml(item.url) + ')</li>';89 });90 91 html += '</ul></div>';92 }93 94 if (data.failed.length > 0) {95 html += '<div class="notice notice-error"><p>' +96 'Failed to delete ' + data.failed.length + ' posts:</p><ul>';97 98 data.failed.forEach(function(item) {99 html += '<li>' + escapeHtml(item.url) + ' - ' + escapeHtml(item.reason) + '</li>';100 });101 102 html += '</ul></div>';103 }104 105 if (data.not_found.length > 0) {106 html += '<div class="notice notice-warning"><p>' +107 data.not_found.length + ' URLs could not be matched to posts:</p><ul>';108 109 data.not_found.forEach(function(url) {110 html += '<li>' + escapeHtml(url) + '</li>';111 });112 113 html += '</ul></div>';114 }115 116 results.show();117 resultsContent.html(html);118 119 // Scroll to results120 $('html, body').animate({121 scrollTop: results.offset().top - 50122 }, 500);123 }124 125 103 function displayError(message) { 126 104 const html = '<div class="notice notice-error"><p>' + escapeHtml(message) + '</p></div>'; -
delete-posts-by-url/trunk/delete-posts-by-url.php
r3302285 r3302346 18 18 defined('ABSPATH') || exit; 19 19 20 class BDBU_Delete_Posts {20 class DPBU_Delete_Posts { 21 21 private static $instance = null; 22 22 private $deleted_items = []; … … 33 33 add_action('admin_menu', [$this, 'add_admin_menu']); 34 34 add_action('admin_enqueue_scripts', [$this, 'enqueue_assets']); 35 add_action('wp_ajax_ bdbu_process_urls', [$this, 'ajax_process_urls']);35 add_action('wp_ajax_dpbu_process_urls', [$this, 'ajax_process_urls']); 36 36 } 37 37 … … 42 42 43 43 wp_enqueue_style( 44 ' bdbu-admin',44 'dpbu-admin', 45 45 plugins_url('assets/css/admin.css', __FILE__), 46 46 [], 47 '2. 0'47 '2.4.1' 48 48 ); 49 49 50 50 wp_enqueue_script( 51 ' bdbu-admin',51 'dpbu-admin', 52 52 plugins_url('assets/js/admin.js', __FILE__), 53 53 ['jquery'], 54 '2. 0',54 '2.4.1', 55 55 true 56 56 ); 57 57 58 wp_localize_script(' bdbu-admin', 'bdbuAdmin', [58 wp_localize_script('dpbu-admin', 'dpbuAdmin', [ 59 59 'ajaxurl' => admin_url('admin-ajax.php'), 60 'nonce' => wp_create_nonce(' bdbu_process_urls'),60 'nonce' => wp_create_nonce('dpbu_process_urls'), 61 61 'confirmMsg' => __('Are you sure you want to delete these posts? This action cannot be undone.', 'delete-posts-by-url'), 62 62 ]); … … 87 87 ?> 88 88 <div class="wrap"> 89 <div class=" bdbu-header">89 <div class="dpbu-header"> 90 90 <img src="<?php echo esc_url(plugins_url('assets/images/icon-128x128.png', __FILE__)); ?>" 91 91 alt="<?php echo esc_attr__('Delete Posts By URL', 'delete-posts-by-url'); ?>" 92 92 class="bdbu-logo"> 93 93 <h1><?php echo esc_html__('Delete Posts By URL', 'delete-posts-by-url'); ?></h1> 94 <div class=" bdbu-branding">94 <div class="dpbu-branding"> 95 95 <?php echo sprintf( 96 96 /* translators: %s: Better Ranking URL */ … … 107 107 </div> 108 108 109 <form id=" bdbu-delete-form" method="post">110 <div class=" bdbu-options">109 <form id="dpbu-delete-form" method="post"> 110 <div class="dpbu-options"> 111 111 <h2><?php echo esc_html__('Options', 'delete-posts-by-url'); ?></h2> 112 112 … … 130 130 </div> 131 131 132 <div class=" bdbu-input">132 <div class="dpbu-input"> 133 133 <h2><?php echo esc_html__('URLs', 'delete-posts-by-url'); ?></h2> 134 134 <p><?php echo esc_html__('Paste one URL per line:', 'delete-posts-by-url'); ?></p> 135 <p class="description"><?php echo esc_html__('Examples:', 'delete-posts-by-url'); ?></p> 136 <ul class="dpbu-examples"> 137 <li><?php echo esc_html(home_url('/sample-post/')); ?> (<?php echo esc_html__('Absolute URL', 'delete-posts-by-url'); ?>)</li> 138 <li>/sample-post/ (<?php echo esc_html__('Relative URL', 'delete-posts-by-url'); ?>)</li> 139 </ul> 135 140 <textarea name="urls" rows="10" cols="60" class="large-text"></textarea> 136 141 </div> 137 142 138 <div class=" bdbu-progress" style="display: none;">143 <div class="dpbu-progress" style="display: none;"> 139 144 <div class="progress-bar"></div> 140 145 <div class="progress-text"></div> 141 146 </div> 142 147 143 <div class=" bdbu-results" style="display: none;">148 <div class="dpbu-results" style="display: none;"> 144 149 <h3><?php echo esc_html__('Results', 'delete-posts-by-url'); ?></h3> 145 150 <div class="results-content"></div> 146 151 </div> 147 152 148 <?php wp_nonce_field(' bdbu_process_urls', 'bdbu_nonce'); ?>153 <?php wp_nonce_field('dpbu_process_urls', 'dpbu_nonce'); ?> 149 154 <button type="submit" class="button button-primary"> 150 155 <?php echo esc_html__('Process URLs', 'delete-posts-by-url'); ?> … … 156 161 157 162 public function ajax_process_urls(): void { 158 check_ajax_referer(' bdbu_process_urls', 'nonce');163 check_ajax_referer('dpbu_process_urls', 'nonce'); 159 164 160 165 if (!current_user_can('manage_options')) { … … 277 282 // Initialize the plugin 278 283 add_action('plugins_loaded', function() { 279 BDBU_Delete_Posts::get_instance();284 DPBU_Delete_Posts::get_instance(); 280 285 });
Note: See TracChangeset
for help on using the changeset viewer.