manipulations.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?php
  2. /**
  3. * Category Manipulations page view
  4. *
  5. * @since 1.0.0
  6. * @package Studiou_WC_Product_Cat_Manage
  7. */
  8. // If this file is called directly, abort.
  9. if (!defined('WPINC')) {
  10. die;
  11. }
  12. // Get categories with counts for select boxes
  13. $manipulator = new Studiou_WC_Product_Cat_Manage_Manipulator(new Studiou_WC_Product_Cat_Manage_DB());
  14. $categories = $manipulator->get_categories_with_counts();
  15. $media_categories = $manipulator->get_media_categories_with_counts();
  16. ?>
  17. <div class="wrap studiou-wcpcm-wrap">
  18. <h1><?php echo esc_html__('Category Manipulations', 'studiou-wc-product-cat-manage'); ?></h1>
  19. <div class="studiou-wcpcm-notice-area">
  20. <!-- Area for displaying notices -->
  21. </div>
  22. <!-- Move Products Between Categories Operation -->
  23. <div class="studiou-wcpcm-card">
  24. <h2><?php echo esc_html__('Move products between categories', 'studiou-wc-product-cat-manage'); ?></h2>
  25. <p><?php echo esc_html__('This operation allows you to move all products from one category to another. Products will be removed from the source category and added to the target category.', 'studiou-wc-product-cat-manage'); ?></p>
  26. <form id="studiou-wcpcm-move-form" method="post">
  27. <table class="form-table">
  28. <tr>
  29. <th scope="row">
  30. <label for="source_category"><?php echo esc_html__('Source Category', 'studiou-wc-product-cat-manage'); ?></label>
  31. </th>
  32. <td>
  33. <select name="source_category" id="source_category" class="regular-text" required>
  34. <option value=""><?php echo esc_html__('-- Select Source Category --', 'studiou-wc-product-cat-manage'); ?></option>
  35. <?php foreach ($categories as $category): ?>
  36. <option value="<?php echo esc_attr($category['id']); ?>">
  37. <?php echo esc_html($category['display_name']); ?>
  38. </option>
  39. <?php endforeach; ?>
  40. </select>
  41. <p class="description"><?php echo esc_html__('Select the category from which products will be moved.', 'studiou-wc-product-cat-manage'); ?></p>
  42. </td>
  43. </tr>
  44. <tr>
  45. <th scope="row">
  46. <label for="target_category"><?php echo esc_html__('Target Category', 'studiou-wc-product-cat-manage'); ?></label>
  47. </th>
  48. <td>
  49. <select name="target_category" id="target_category" class="regular-text" required>
  50. <option value=""><?php echo esc_html__('-- Select Target Category --', 'studiou-wc-product-cat-manage'); ?></option>
  51. <?php foreach ($categories as $category): ?>
  52. <option value="<?php echo esc_attr($category['id']); ?>">
  53. <?php echo esc_html($category['display_name']); ?>
  54. </option>
  55. <?php endforeach; ?>
  56. </select>
  57. <p class="description"><?php echo esc_html__('Select the category to which products will be moved.', 'studiou-wc-product-cat-manage'); ?></p>
  58. </td>
  59. </tr>
  60. </table>
  61. <div class="submit-buttons">
  62. <button type="submit" class="button button-primary" id="studiou-wcpcm-move-button">
  63. <?php echo esc_html__('Do', 'studiou-wc-product-cat-manage'); ?>
  64. </button>
  65. <span class="spinner"></span>
  66. </div>
  67. </form>
  68. <div class="studiou-wcpcm-move-results" style="display: none;">
  69. <h3><?php echo esc_html__('Move Results', 'studiou-wc-product-cat-manage'); ?></h3>
  70. <div id="studiou-wcpcm-move-message"></div>
  71. </div>
  72. </div>
  73. <!-- Batch Description Between Categories Operation -->
  74. <div class="studiou-wcpcm-card">
  75. <h2><?php echo esc_html__('Batch description between categories', 'studiou-wc-product-cat-manage'); ?></h2>
  76. <p><?php echo esc_html__('This operation allows you to set the same description for multiple categories at once.', 'studiou-wc-product-cat-manage'); ?></p>
  77. <form id="studiou-wcpcm-batch-description-form" method="post">
  78. <table class="form-table">
  79. <tr>
  80. <th scope="row">
  81. <label for="categories_list"><?php echo esc_html__('Select Categories', 'studiou-wc-product-cat-manage'); ?></label>
  82. </th>
  83. <td>
  84. <div class="studiou-wcpcm-categories-list-container">
  85. <div class="studiou-wcpcm-list-actions">
  86. <button type="button" id="studiou-wcpcm-check-all" class="button">
  87. <?php echo esc_html__('Check All', 'studiou-wc-product-cat-manage'); ?>
  88. </button>
  89. <button type="button" id="studiou-wcpcm-uncheck-all" class="button">
  90. <?php echo esc_html__('Uncheck All', 'studiou-wc-product-cat-manage'); ?>
  91. </button>
  92. </div>
  93. <div class="studiou-wcpcm-categories-list" id="categories_list">
  94. <?php foreach ($categories as $category): ?>
  95. <label class="studiou-wcpcm-category-item">
  96. <input type="checkbox" name="selected_categories[]" value="<?php echo esc_attr($category['id']); ?>">
  97. <span><?php echo esc_html($category['display_name']); ?></span>
  98. </label>
  99. <?php endforeach; ?>
  100. </div>
  101. </div>
  102. <p class="description"><?php echo esc_html__('Select the categories for which you want to set the description.', 'studiou-wc-product-cat-manage'); ?></p>
  103. </td>
  104. </tr>
  105. <tr>
  106. <th scope="row">
  107. <label for="category_description"><?php echo esc_html__('Product categories description', 'studiou-wc-product-cat-manage'); ?></label>
  108. </th>
  109. <td>
  110. <textarea name="category_description" id="category_description" rows="5" cols="50" class="large-text"></textarea>
  111. <p class="description"><?php echo esc_html__('Enter the description that will be applied to all selected categories.', 'studiou-wc-product-cat-manage'); ?></p>
  112. </td>
  113. </tr>
  114. </table>
  115. <div class="submit-buttons">
  116. <button type="submit" class="button button-primary" id="studiou-wcpcm-batch-description-button">
  117. <?php echo esc_html__('Do', 'studiou-wc-product-cat-manage'); ?>
  118. </button>
  119. <span class="spinner"></span>
  120. </div>
  121. </form>
  122. <div class="studiou-wcpcm-batch-description-results" style="display: none;">
  123. <h3><?php echo esc_html__('Batch Description Results', 'studiou-wc-product-cat-manage'); ?></h3>
  124. <div id="studiou-wcpcm-batch-description-message"></div>
  125. </div>
  126. </div>
  127. <!-- Delete Products in Category Operation -->
  128. <div class="studiou-wcpcm-card">
  129. <h2><?php echo esc_html__('Delete products in category', 'studiou-wc-product-cat-manage'); ?></h2>
  130. <p><?php echo esc_html__('This operation allows you to permanently delete all products and their variants from selected categories. This action cannot be undone!', 'studiou-wc-product-cat-manage'); ?></p>
  131. <form id="studiou-wcpcm-delete-products-form" method="post">
  132. <table class="form-table">
  133. <tr>
  134. <th scope="row">
  135. <label for="delete_categories_list"><?php echo esc_html__('Select Categories', 'studiou-wc-product-cat-manage'); ?></label>
  136. </th>
  137. <td>
  138. <div class="studiou-wcpcm-categories-list-container">
  139. <div class="studiou-wcpcm-list-actions">
  140. <button type="button" id="studiou-wcpcm-delete-check-all" class="button">
  141. <?php echo esc_html__('Check All', 'studiou-wc-product-cat-manage'); ?>
  142. </button>
  143. <button type="button" id="studiou-wcpcm-delete-uncheck-all" class="button">
  144. <?php echo esc_html__('Uncheck All', 'studiou-wc-product-cat-manage'); ?>
  145. </button>
  146. </div>
  147. <div class="studiou-wcpcm-categories-list" id="delete_categories_list">
  148. <?php foreach ($categories as $category): ?>
  149. <label class="studiou-wcpcm-category-item">
  150. <input type="checkbox" name="delete_categories[]" value="<?php echo esc_attr($category['id']); ?>">
  151. <span><?php echo esc_html($category['display_name']); ?></span>
  152. </label>
  153. <?php endforeach; ?>
  154. </div>
  155. </div>
  156. <p class="description"><?php echo esc_html__('Select the categories from which all products will be permanently deleted.', 'studiou-wc-product-cat-manage'); ?></p>
  157. </td>
  158. </tr>
  159. </table>
  160. <div class="studiou-wcpcm-warning-message">
  161. <p><strong><?php echo esc_html__('WARNING: This operation will permanently delete all products (including variants) in the selected categories. This action cannot be undone!', 'studiou-wc-product-cat-manage'); ?></strong></p>
  162. </div>
  163. <div class="submit-buttons">
  164. <button type="submit" class="button button-primary button-danger" id="studiou-wcpcm-delete-products-button">
  165. <?php echo esc_html__('Delete', 'studiou-wc-product-cat-manage'); ?>
  166. </button>
  167. <span class="spinner"></span>
  168. </div>
  169. </form>
  170. <div class="studiou-wcpcm-delete-progress" style="display: none;">
  171. <h3><?php echo esc_html__('Deletion Progress', 'studiou-wc-product-cat-manage'); ?></h3>
  172. <div class="studiou-wcpcm-progress-bar-container">
  173. <div class="studiou-wcpcm-progress-bar" id="studiou-wcpcm-delete-progress-bar"></div>
  174. </div>
  175. <div class="studiou-wcpcm-progress-text" id="studiou-wcpcm-delete-progress-text"></div>
  176. </div>
  177. <div class="studiou-wcpcm-delete-results" style="display: none;">
  178. <h3><?php echo esc_html__('Deletion Results', 'studiou-wc-product-cat-manage'); ?></h3>
  179. <div id="studiou-wcpcm-delete-message"></div>
  180. </div>
  181. </div>
  182. <!-- Clear Media Categories Operation -->
  183. <div class="studiou-wcpcm-card">
  184. <h2><?php echo esc_html__('Clear Media Categories', 'studiou-wc-product-cat-manage'); ?></h2>
  185. <p><?php echo esc_html__('This operation allows you to permanently delete all media files from selected media categories. This action cannot be undone!', 'studiou-wc-product-cat-manage'); ?></p>
  186. <?php if (empty($media_categories)): ?>
  187. <p><em><?php echo esc_html__('No media categories found. Please install a media category plugin (e.g., Media Library Categories) to use this feature.', 'studiou-wc-product-cat-manage'); ?></em></p>
  188. <?php else: ?>
  189. <form id="studiou-wcpcm-clear-media-form" method="post">
  190. <table class="form-table">
  191. <tr>
  192. <th scope="row">
  193. <label for="clear_media_categories_list"><?php echo esc_html__('Select Media Categories', 'studiou-wc-product-cat-manage'); ?></label>
  194. </th>
  195. <td>
  196. <div class="studiou-wcpcm-categories-list-container">
  197. <div class="studiou-wcpcm-list-actions">
  198. <button type="button" id="studiou-wcpcm-clear-media-check-all" class="button">
  199. <?php echo esc_html__('Check All', 'studiou-wc-product-cat-manage'); ?>
  200. </button>
  201. <button type="button" id="studiou-wcpcm-clear-media-uncheck-all" class="button">
  202. <?php echo esc_html__('Uncheck All', 'studiou-wc-product-cat-manage'); ?>
  203. </button>
  204. </div>
  205. <div class="studiou-wcpcm-categories-list" id="clear_media_categories_list">
  206. <?php foreach ($media_categories as $category): ?>
  207. <label class="studiou-wcpcm-category-item">
  208. <input type="checkbox" name="media_categories[]" value="<?php echo esc_attr($category['id']); ?>">
  209. <span><?php echo esc_html($category['display_name']); ?></span>
  210. </label>
  211. <?php endforeach; ?>
  212. </div>
  213. </div>
  214. <p class="description"><?php echo esc_html__('Select the media categories from which all files will be permanently deleted.', 'studiou-wc-product-cat-manage'); ?></p>
  215. </td>
  216. </tr>
  217. </table>
  218. <div class="studiou-wcpcm-warning-message">
  219. <p><strong><?php echo esc_html__('WARNING: This operation will permanently delete all media files in the selected categories. The files will be removed from the server. This action cannot be undone!', 'studiou-wc-product-cat-manage'); ?></strong></p>
  220. </div>
  221. <div class="submit-buttons">
  222. <button type="submit" class="button button-primary button-danger" id="studiou-wcpcm-clear-media-button">
  223. <?php echo esc_html__('Delete', 'studiou-wc-product-cat-manage'); ?>
  224. </button>
  225. <span class="spinner"></span>
  226. </div>
  227. </form>
  228. <div class="studiou-wcpcm-clear-media-progress" style="display: none;">
  229. <h3><?php echo esc_html__('Deletion Progress', 'studiou-wc-product-cat-manage'); ?></h3>
  230. <div class="studiou-wcpcm-progress-bar-container">
  231. <div class="studiou-wcpcm-progress-bar" id="studiou-wcpcm-clear-media-progress-bar"></div>
  232. </div>
  233. <div class="studiou-wcpcm-progress-text" id="studiou-wcpcm-clear-media-progress-text"></div>
  234. </div>
  235. <div class="studiou-wcpcm-clear-media-results" style="display: none;">
  236. <h3><?php echo esc_html__('Deletion Results', 'studiou-wc-product-cat-manage'); ?></h3>
  237. <div id="studiou-wcpcm-clear-media-message"></div>
  238. </div>
  239. <?php endif; ?>
  240. </div>
  241. <!-- Important Notes -->
  242. <div class="studiou-wcpcm-card">
  243. <h2><?php echo esc_html__('Important Notes', 'studiou-wc-product-cat-manage'); ?></h2>
  244. <ul>
  245. <li><?php echo esc_html__('Products can be assigned to multiple categories. This operation will remove the product from the source category and add it to the target category.', 'studiou-wc-product-cat-manage'); ?></li>
  246. <li><?php echo esc_html__('If a product is only assigned to the source category, it will be moved entirely to the target category.', 'studiou-wc-product-cat-manage'); ?></li>
  247. <li><?php echo esc_html__('If a product is assigned to multiple categories including the source category, it will remain in the other categories and be moved to the target category.', 'studiou-wc-product-cat-manage'); ?></li>
  248. <li><?php echo esc_html__('The operation processes all products regardless of their status (published, draft, private).', 'studiou-wc-product-cat-manage'); ?></li>
  249. <li><?php echo esc_html__('The batch description operation will overwrite the existing descriptions for all selected categories.', 'studiou-wc-product-cat-manage'); ?></li>
  250. <li><strong><?php echo esc_html__('The delete products operation will permanently delete all products and variants from the selected categories. This action cannot be undone!', 'studiou-wc-product-cat-manage'); ?></strong></li>
  251. <li><strong><?php echo esc_html__('The clear media categories operation will permanently delete all media files from the selected media categories and remove them from the server. This action cannot be undone!', 'studiou-wc-product-cat-manage'); ?></strong></li>
  252. </ul>
  253. </div>
  254. </div>