PluginProbe ʕ •ᴥ•ʔ
Auto Post Cleaner / 3.7.6
Auto Post Cleaner v3.7.6
3.12.0 3.13.1 3.2.4 3.2.5 3.3.0 3.3.10 3.3.11 3.3.8 3.4.2 3.5.3 3.6.0 3.7.0 3.7.1 3.7.2 3.7.3 3.7.5 3.7.6 3.8.0 3.9.0 3.9.4 3.9.6 3.9.7 trunk 3.0.0 3.1.0 3.10.1 3.10.2 3.11.4
delete-old-posts-programmatically / inc / class-delete-old-posts-filters.php
delete-old-posts-programmatically / inc Last commit date
class-delete-old-posts-filters.php 2 years ago class-delete-old-posts-redirects.php 2 years ago class-delete-old-posts.php 2 years ago class-enqueue-assets.php 2 years ago
class-delete-old-posts-filters.php
689 lines
1 <?php
2
3 namespace DEL\OLD\Posts\Cls;
4
5 /**
6 * Make the plugin class.
7 */
8 class Delete_Old_Posts_Filters extends Delete_Old_Posts
9 {
10 private $colors ;
11 private $bcolors ;
12 /**
13 * Hooks init (nothing else) and calls things that need to run right away.
14 */
15 public function __construct()
16 {
17 add_action( 'admin_menu', [ $this, 'deloldp_custom_menu_page' ] );
18 $this->colors = array(
19 'decoration-sky-600 text-sky-600',
20 'decoration-red-600 text-red-600',
21 'decoration-green-600 text-green-600',
22 'decoration-orange-600 text-orange-600',
23 'decoration-indigo-600 text-indigo-600',
24 'decoration-rose-600 text-rose-600',
25 'decoration-purple-600 text-purple-600',
26 'decoration-stone-600 text-stone-600',
27 'decoration-yellow-600 text-yellow-600',
28 'decoration-lime-600 text-lime-600'
29 );
30 $this->bcolors = array(
31 'border-sky-200',
32 'border-red-200',
33 'border-green-200',
34 'border-orange-200',
35 'border-indigo-200',
36 'border-rose-200',
37 'border-purple-200',
38 'border-stone-200',
39 'border-yellow-200',
40 'border-lime-200'
41 );
42 }
43
44 /**
45 * add a custom menu in admin menu
46 */
47 function deloldp_custom_menu_page()
48 {
49 // Add submenu page with same slug as parent to ensure no duplicates
50 $deloldp_filters_submenu = add_submenu_page(
51 'delete-old-posts',
52 esc_html__( 'Filters - Delete old posts automatically' ),
53 esc_html__( 'Filters', 'delete-old-posts' ),
54 'manage_options',
55 'delete-old-posts-filters',
56 [ $this, 'deloldpFilters' ]
57 );
58 }
59
60 /**
61 * Create filters page
62 */
63 function deloldpFilters()
64 {
65 /**
66 * Handle the Filter's form data saving
67 */
68 $this->filtersFormSave();
69 ?>
70 <section class="mx-4 my-8 delop" x-data="deloldp_Start()" x-init="onstart()">
71 <div class="wrap mb-4">
72 <h2><?php
73 esc_html_e( 'Available filters to use when deleting the posts', 'delete-old-posts' );
74 ?></h2>
75 <?php
76 // display info
77 echo $this->deloldp_makeAlert( esc_html__( "Select which filters you would like to apply when deleting your posts from the options below.", "delete-old-posts" ), "info", "is-dismissible" ) ;
78 ?>
79 </div>
80 <div class="max-w-full bg-white border border-inherit p-8 mr-5">
81 <form method="post" action="">
82 <div class="flex flex-row flex-wrap gap-5">
83 <?php
84
85 if ( current_user_can( 'delete_posts' ) & current_user_can( 'delete_others_posts' ) ) {
86 esc_html_e( "\n Once you've decided on the number of days in the past that posts should automatically be deleted, you can refine the criteria for deletion even further. If you want to delete posts of only one type, posts in specific categories, or posts with one or more taxonomies (for custom post types), simply select the appropriate options below. Any posts published before the date you have chosen will then be filtered to make sure only those meeting your additional criteria are deleted. This way, you can be sure that only the posts you want removed are deleted.\n ", "delete-old-posts" );
87 $this->delop_get_form_input( 'cpt' );
88 $this->delop_get_form_input( 'cpt_type' );
89
90 if ( current_user_can( 'manage_categories' ) ) {
91 $this->delop_get_form_input( 'categories' );
92 $this->delop_get_form_input( 'relation' );
93 }
94
95 if ( current_user_can( 'list_users' ) ) {
96 $this->delop_get_form_input( 'users' );
97 }
98 $this->delop_get_form_input( 'postids' );
99 $this->delop_get_form_input( 'search_keywords' );
100 $this->delop_get_form_input( 'attached_img' );
101 } else {
102 esc_html_e( "You don't have rights to delete the posts.", "delete-old-posts" );
103 }
104
105 ?>
106 <div class="w-full flex items-center">
107 <div class="w-full text-right">
108 <button
109 type="submit"
110 class="bg-blue-500 rounded-full font-bold text-white px-4 py-3 transition duration-300 ease-in-out hover:bg-blue-600"
111 >
112 <?php
113 esc_html_e( 'Save and test the deleted posts', 'delete-old-posts' );
114 ?>
115 <svg xmlns="http://www.w3.org/2000/svg" class="inline ml-2 w-6 stroke-current text-white stroke-2" viewBox="0 0 24 24" fill="none" stroke-linecap="round" stroke-linejoin="round">
116 <line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/>
117 </svg>
118 </button>
119 <?php
120 wp_nonce_field( 'delop_filters_save', 'delop_nonce_filters' );
121 ?>
122 </div>
123 </div>
124 </div>
125 </form>
126 </div>
127 </section>
128 <?php
129 }
130
131 /**
132 * Handle the Filter's form change
133 */
134 function filtersFormSave()
135 {
136 // check if filters form was just saved
137
138 if ( isset( $_POST['delop_nonce_filters'] ) && wp_verify_nonce( $_POST['delop_nonce_filters'], 'delop_filters_save' ) ) {
139 // sanitize $_POST vars
140 $filtersOptions = ( isset( $_POST ) ? (array) $_POST : array() );
141 $filtersOptions = filter_var_array( $filtersOptions );
142 // check if any post type selected (at least the default post type have to be selected)
143
144 if ( !isset( $filtersOptions['cpt'] ) || isset( $filtersOptions['cpt'] ) && empty($filtersOptions['cpt']) ) {
145 // set the default post
146 $filtersOptions['cpt'] = array( 'post' );
147 echo $this->deloldp_makeAlert( esc_html__( "At least one post type has to be selected. The default post type have been automatically selected.", "delete-old-posts" ), "warning", "is-dismissible" ) ;
148 }
149
150 // save Filters option into an Option
151 update_option( 'delop_filters', $filtersOptions );
152 // show a list with deleted posts. Test the filter.
153 $this->tryFilter();
154 }
155
156 }
157
158 /**
159 * Create form inputs
160 */
161 function delop_get_form_input( $inputName )
162 {
163 global $dop_fs ;
164 switch ( $inputName ) {
165 case 'cpt':
166 ?>
167 <div class="border border-inherit p-7 relative delop-filter">
168 <span class="dashicons dashicons-admin-post text-4xl mb-4"></span>
169 <?php
170 $helpTxt = sprintf( esc_html__( 'You can choose to delete only the posts from a specific custom post type, or all posts types. If not otherwise specified, only the posts from the %s will be deleted.', 'delete-old-posts' ), '<strong>' . esc_html__( "default post type", "delete-old-posts" ) . '</strong>' );
171 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
172 /**
173 * Get the list with custom post types
174 */
175 // get saved options
176 $toggle_hidden_cpt = $this->getFiltersOpt( 'toggle_hidden_cpt' );
177 $args = array(
178 '_builtin' => false,
179 );
180 if ( !$toggle_hidden_cpt ) {
181 $args['public'] = true;
182 }
183 $getCustomPostTypes = get_post_types( $args );
184 // get saved cpt if form was submited
185 $cpts = $this->getFiltersOpt( 'cpt' );
186 ?>
187 <div class='m-2 max-h-56 overflow-y-scroll'>
188 <?php
189 echo "<div class='text-base'>" ;
190 esc_html_e( 'Choose the post type:', 'delete-old-posts' );
191 echo "</div>" ;
192 echo "\n <label class='block my-2'>\n <input type='checkbox' name='cpt[]' value='post'" ;
193 if ( empty($cpts) || isset( $cpts ) && is_array( $cpts ) && array_search( 'post', $cpts ) !== false ) {
194 echo "checked" ;
195 }
196 echo "/>\n <span class='underline " . $this->colors[0] . " ml-1 decoration-2'>\n Post\n </span>\n </label>" ;
197 $cptColor = 1;
198 if ( is_array( $getCustomPostTypes ) ) {
199 foreach ( $getCustomPostTypes as $customPostType ) {
200 $checked = false;
201 if ( isset( $cpts ) && is_array( $cpts ) && array_search( $customPostType, $cpts ) !== false ) {
202 $checked = true;
203 }
204 echo "\n <label class='block my-2'>\n <input type='checkbox' name='cpt[]' value='" . $customPostType . "'" ;
205 if ( $checked ) {
206 echo "checked" ;
207 }
208 echo " />\n <span class='ml-1 " ;
209 echo ( $checked && isset( $this->colors[$cptColor] ) ? $this->colors[$cptColor] . ' underline decoration-2' : '' ) ;
210 echo "'>\n " . ucfirst( str_replace( "_", " ", $customPostType ) ) . "\n </span>\n </label>" ;
211 $cptColor++;
212 }
213 }
214 echo "\n </div>" ;
215 ?>
216 <!-- Rounded switch -->
217 <?php
218 // get saved options
219 $toggle_hidden_cpt = $this->getFiltersOpt( 'toggle_hidden_cpt' );
220 ?>
221 <label class="relative inline-flex items-center mb-5 cursor-pointer">
222 <input
223 type="checkbox"
224 id="toggle_hidden_cpt"
225 name="toggle_hidden_cpt"
226 value="1"
227 <?php
228 if ( $toggle_hidden_cpt ) {
229 echo "checked" ;
230 }
231 ?>
232 class="sr-only peer"
233 >
234 <div class="w-9 h-5 bg-gray-200 peer-focus:outline-none peer-focus:ring-0 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div>
235 </label>
236 <span class="ms-3 text-sm text-gray-900 dark:text-gray-300 ml-2 leading-6 max-w-[150px] inline-block"><?php
237 _e( 'Show hidden Custom Post Types.', 'delete-old-posts' );
238 ?></span>
239 </div>
240 <?php
241 break;
242 case 'cpt_type':
243 ?>
244 <div class="border border-inherit p-7 relative delop-filter">
245 <span class="dashicons dashicons-post-status text-4xl mb-4"></span>
246 <?php
247 $helpTxt = esc_html__( 'You can choose to delete only the posts by a specific status. The default status used is "publish".', 'delete-old-posts' );
248 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
249 // Generate the checkboxes
250 echo "<div class='text-base'>" ;
251 esc_html_e( 'Choose the post status:', 'delete-old-posts' );
252 echo "</div>" ;
253 $this->delopt_generate_check_box( 'publish', 'Publish' );
254 // $this->delopt_generate_check_box( 'future', 'Future' );
255 $this->delopt_generate_check_box( 'draft', 'Draft' );
256 $this->delopt_generate_check_box( 'pending', 'Pending' );
257 $this->delopt_generate_check_box( 'private', 'Private' );
258 ?>
259 </div>
260 <?php
261 break;
262 case 'categories':
263 // get all custom taxonomies
264 $args = array(
265 'public' => true,
266 '_builtin' => false,
267 );
268 $allCustomTaxonomies = get_taxonomies( $args );
269 // add default category to taxonomies
270 $allCustomTaxonomies = array(
271 'category' => 'category',
272 ) + $allCustomTaxonomies;
273 /**
274 * Get all CPT
275 * Used to find the co;or index for the category box
276 */
277 $args = array(
278 'public' => true,
279 '_builtin' => false,
280 );
281 $getAllCustomPostTypes = get_post_types( $args );
282 /**
283 * display a list of checkboxes for each taxonomy
284 * create the color for the taxonomy border to be the same as color used for the related custom post
285 */
286 // get the list with checked post types
287 $getCustomPostTypes = $this->getFiltersOpt( 'cpt' );
288 // get taxonomies for every checked post type
289 if ( is_array( $getCustomPostTypes ) ) {
290 foreach ( $getCustomPostTypes as $key => $cpt ) {
291 $cptTaxonomies[$key] = get_object_taxonomies( (string) $cpt );
292 }
293 }
294 // list all categories and taxonomies
295 if ( is_array( $allCustomTaxonomies ) ) {
296 foreach ( $allCustomTaxonomies as $category ) {
297 /**
298 * check if category is registered for the current cpt
299 */
300 $catInTaxList = false;
301 if ( isset( $cptTaxonomies ) && is_array( $cptTaxonomies ) ) {
302 foreach ( $cptTaxonomies as $cptIndex => $taxCPTSelected ) {
303
304 if ( in_array( $category, $taxCPTSelected ) ) {
305 $catInTaxList = true;
306 break;
307 // exit loop
308 }
309
310 }
311 }
312 /**
313 * show category if it is in the list of registered taxonomies for the selected post type
314 */
315
316 if ( $catInTaxList ) {
317 /**
318 * find border color index for the box
319 * need to be the same as the color of CPT in the list
320 */
321 $getCPTKeyInAllCPTArray = $this->countArrayUntilTarget( $getAllCustomPostTypes, $getCustomPostTypes[$cptIndex] );
322 // color index will be incremented with 1 (post is not in the CPT array so will need to be counted too)
323 $borderColorIndex = ( $category != 'category' ? $getCPTKeyInAllCPTArray + 1 : 0 );
324 ?>
325 <div class="border p-7 relative max-w-xs <?php
326 echo ( isset( $this->bcolors[$borderColorIndex] ) ? $this->bcolors[$borderColorIndex] : '' ) ;
327 ?> delop-filter">
328 <span class="dashicons dashicons-category text-4xl mb-4"></span>
329 <?php
330 $titleText = esc_html__( 'Choose taxonomies to filter the deleted %s.', 'delete-old-posts' );
331 $helpText = esc_html__( 'You can choose to delete only the custom posts with specific taxonomies. If no taxonomy is selected, the custom posts with %s will be deleted.', 'delete-old-posts' );
332 $strongText = "any taxonomy";
333
334 if ( $category == 'category' ) {
335 $titleText = esc_html__( 'Choose categories to filter the deleted posts.', 'delete-old-posts' );
336 $helpText = esc_html__( 'You can choose to delete only the posts from specific categories. If selected, only post from the selected category (categories) will be deleted. If no category is selected, the posts from %s will be deleted.', 'delete-old-posts' );
337 $strongText = "any category";
338 }
339
340 $helpTxt = sprintf( $helpText, '<strong>' . esc_html__( $strongText, "delete-old-posts" ) . '</strong>' );
341 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
342 ?>
343 <div class="mb-2 text-base">
344 <?php
345 $custompostname = ucfirst( str_replace( "_", " ", $getCustomPostTypes[$cptIndex] ) );
346 $getTaxName = get_taxonomy_labels( get_taxonomy( $category ) );
347 echo sprintf( esc_html__( $titleText, "delete-old-posts" ), "<strong>" . esc_html__( $custompostname, "delete-old-posts" ) . "</strong>" ) ;
348 echo "<br /><strong>" . $getTaxName->name . "</strong> " ;
349 esc_html_e( "list:", 'delete-old-posts' );
350 ?>
351 </div>
352 <div class="max-h-56 overflow-auto">
353 <?php
354 $choosedCats = ( $category == 'category' ? $this->getFiltersOpt( 'post_category' ) : $this->getFiltersOpt( 'tax_input', $category ) );
355 $choosedCats = ( is_array( $choosedCats ) ? $choosedCats : false );
356 /**
357 * Display checkboxes with categories
358 */
359 $cat = get_taxonomy( $category );
360
361 if ( current_user_can( $cat->cap->assign_terms ) ) {
362 // get selected categories if form was previous save
363 $args = array(
364 'taxonomy' => $category,
365 'hierarchical' => true,
366 'title_li' => '',
367 'hide_empty' => false,
368 'selected_cats' => $choosedCats,
369 'popular_cats' => false,
370 'checked_ontop' => true,
371 );
372 wp_terms_checklist( $post_id = 0, $args );
373 }
374
375 ?>
376 </div>
377 </div>
378 <?php
379 }
380
381 }
382 }
383 break;
384 case 'users':
385 // get saved user filter if form was submited
386 $usersFilter = $this->getFiltersOpt( 'userid' );
387 // get all users
388 $users = get_users( array(
389 'fields' => array( 'ID' ),
390 ) );
391 // list users
392 ?>
393 <div class='border border-inherit p-7 relative max-w-xs delop-filter'>
394 <span class="dashicons dashicons-admin-users text-4xl mb-4"></span>
395 <?php
396 $helpTxt = sprintf( esc_html__( 'You can choose to delete only the posts from specific users. By default (no user selected), posts from %s will be deleted.', 'delete-old-posts' ), '<strong>' . esc_html__( "any user", "delete-old-posts" ) . '</strong>' );
397 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
398 ?>
399 <div class='m-2'>
400 <?php
401 echo "<div class='text-base'>" ;
402 esc_html_e( 'Delete only the posts from specific users:', 'delete-old-posts' );
403 echo "</div>" ;
404 echo "\n <div class='max-h-56 overflow-auto'>" ;
405 foreach ( $users as $user ) {
406 $userObj = get_user_by( 'ID', $user->ID );
407 echo "<label class='block my-2'><input type='checkbox' name='userid[]' value='" . $user->ID . "'" ;
408 if ( isset( $usersFilter ) && is_array( $usersFilter ) && array_search( $user->ID, $usersFilter ) !== false ) {
409 echo "checked" ;
410 }
411 echo "/> " . $userObj->display_name . "</label>" ;
412 }
413 echo "\n </div>" ;
414 ?>
415 </div>
416 </div>
417 <?php
418 break;
419 case 'relation':
420 // get saved relation filter if form was submited
421 $relationFilter = $this->getFiltersOpt( 'relation' );
422 if ( empty($relationFilter) ) {
423 $relationFilter = 'OR';
424 }
425 ?>
426 <div class='border border-inherit p-7 relative max-w-xs delop-filter'>
427 <span class="dashicons dashicons-forms text-4xl mb-4"></span>
428 <?php
429 $helpTxt = sprintf( esc_html__( 'Choose the relation applied to selected categories or terms. By default (no relation selected), %s will be used. "All selected categories or terms" mean that the deleted post will need to have relation with all selected categories or terms. "Any selected categories or terms" mean that if the post has relationship with only one of the selected terms, then the post will be deleted.', 'delete-old-posts' ), '<strong>' . esc_html__( "all selected terms", "delete-old-posts" ) . '</strong>' );
430 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
431 ?>
432 <div class='m-2'>
433 <?php
434 echo "<div class='text-base'>" ;
435 esc_html_e( 'Choose the relation applied to selected categories or taxonomies terms:', 'delete-old-posts' );
436 echo "</div>" ;
437 echo "<label class='block my-2'><input type='radio' name='relation' value='AND'" ;
438 if ( isset( $relationFilter ) && $relationFilter == 'AND' ) {
439 echo "checked" ;
440 }
441 echo "/>" . sprintf( esc_html__( "All selected categories or terms (post will need to be in %s selected categories or terms)", "delete-old-posts" ), '<strong>' . esc_html__( 'ALL', 'delete-old-posts' ) . '</strong>' ) . "</label>" ;
442 echo "<label class='block my-2'><input type='radio' name='relation' value='OR'" ;
443 if ( isset( $relationFilter ) && $relationFilter == 'OR' ) {
444 echo "checked" ;
445 }
446 echo "/>" . sprintf( esc_html__( "Any selected categories or terms (post will need to be in %s selected categories or terms)", "delete-old-posts" ), '<strong>' . esc_html__( 'ANY', 'delete-old-posts' ) . '</strong>' ) . "</label>" ;
447 ?>
448 </div>
449 </div>
450 <?php
451 break;
452 case 'postids':
453 ?>
454 <div class="border border-inherit p-7 relative max-w-xs delop-filter">
455 <span class="dashicons dashicons-portfolio text-4xl mb-4"></span>
456 <?php
457 // get saved post ids if form was submited
458 $postids = $this->getFiltersOpt( 'postids' );
459 $helpTxt = sprintf( esc_html__( 'If you have some posts that you %s, write the posts Ids in the text box separated with coma (ex. 1009, 2345, 4563). You can find the post id in the browser location when you edit the post (ex. ?post=2033).', 'delete-old-posts' ), '<strong>' . esc_html__( "don't want to be deleted", "delete-old-posts" ) . '</strong>' );
460 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
461 ?>
462 <div class="m-2">
463 <?php
464 echo "<div class='text-base'>" ;
465 esc_html_e( 'Have some important posts? Enter the post IDs that you want to keep:', 'delete-old-posts' );
466 echo "</div>" ;
467 ?>
468 <label class="block my-2 mt-8">
469 <span><?php
470 esc_html_e( "Post IDs to exclude:", "delete-old-posts" );
471 ?></span>
472 <input class="w-full" type="text" name="postids" value="<?php
473 echo sanitize_text_field( $postids ) ;
474 ?>" />
475 </label>
476 </div>
477 </div>
478 <?php
479 break;
480 case 'search_keywords':
481 ?>
482 <div class="border border-inherit p-7 relative max-w-xs delop-filter">
483 <span class="dashicons dashicons-search text-4xl mb-4"></span>
484 <?php
485 // get saved post ids if form was submited
486 $search_keyword = $this->getFiltersOpt( 'search_keyword' );
487 $search_keyword_negativ = $this->getFiltersOpt( 'search_keyword_negativ' );
488 $helpTxt = sprintf( esc_html__( 'If you want delete only some posts containing some %s, write the keywords to search in the posts here (ex. pillow). If you want to exclude some posts from the search, write your keywords in the "Negative keywords" field below. Eg, "Look for posts that include" = "pillow" and "Exclude from search results" = "sofa", will return posts containing "pillow" but not "sofa".', 'delete-old-posts' ), '<strong>' . esc_html__( "keywords", "delete-old-posts" ) . '</strong>' );
489 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
490 ?>
491 <div class="m-2">
492 <?php
493 echo "<div class='text-base'>" ;
494 esc_html_e( 'Delete only posts that contain the keyword(s):', 'delete-old-posts' );
495 echo "</div>" ;
496 ?>
497 <label class="block my-2">
498 <span><?php
499 esc_html_e( "Look for posts that include the keyword(s):", "delete-old-posts" );
500 ?></span>
501 <input class="w-full" type="text" name="search_keyword" value="<?php
502 echo sanitize_text_field( $search_keyword ) ;
503 ?>" />
504 </label>
505 <label class="block my-2">
506 <span><?php
507 esc_html_e( "Exclude from search results any posts that contain the keyword(s):", "delete-old-posts" );
508 ?></span>
509 <input class="w-full" type="text" name="search_keyword_negativ" value="<?php
510 echo sanitize_text_field( $search_keyword_negativ ) ;
511 ?>" />
512 </label>
513 </div>
514 </div>
515 <?php
516 break;
517 case 'attached_img':
518 ?>
519 <div class="border border-inherit p-7 relative max-w-xs delop-filter">
520 <span class="dashicons dashicons-images-alt2 text-4xl mb-4"></span>
521 <?php
522 // get saved attached_img option if form was submited
523 $attached_img = $this->getFiltersOpt( 'attached_img' );
524 $force_delete_attached_img = $this->getFiltersOpt( 'force_delete_attached_img' );
525 $helpTxt = sprintf( esc_html__( 'If you also want to delete the %s attached to the post, select this option. When the post is deleted, the post thumbnail and all files attached to it will be deleted as well. Use this option carefully because there is no guarantee that the attachment isn\'t still published in some other post (ex. picture galleries).', 'delete-old-posts' ), '<strong>' . esc_html__( "featured image and all files", "delete-old-posts" ) . '</strong>' );
526 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
527 ?>
528 <div class="m-2">
529 <?php
530 echo "<div class='text-base'>" ;
531 esc_html_e( 'Do you want to delete the images attached to the post (featured image and all files attached to it) when the post is deleted? Note: Attachments will not be deleted if used in another post (use "force delete" for that).', 'delete-old-posts' );
532 echo "</div>" ;
533 ?>
534 <label class="block my-2">
535 <span class="font-bold">
536 <?php
537 esc_html_e( "Delete all files attached to post:", "delete-old-posts" );
538 ?>
539 </span>
540 <input class="w-full" type="checkbox" name="attached_img" value="1" <?php
541 if ( !$dop_fs->can_use_premium_code() ) {
542 echo "disabled" ;
543 }
544 ?> <?php
545 if ( $attached_img == 1 ) {
546 echo "checked" ;
547 }
548 ?> />
549 </label>
550 <label class="block my-2">
551 <span class="font-bold">
552 <?php
553 esc_html_e( "Force delete attached files:", "delete-old-posts" );
554 ?>
555 </span>
556 <input
557 class="w-full"
558 type="checkbox"
559 @click="confirmForceDelete()"
560 id="forcedeleteattachedimg"
561 name="force_delete_attached_img"
562 value="1"
563 <?php
564 if ( !$dop_fs->can_use_premium_code() ) {
565 echo "disabled" ;
566 }
567 ?>
568 <?php
569 if ( $force_delete_attached_img == 1 ) {
570 echo "checked" ;
571 }
572 ?>
573 />
574 </label>
575 <?php
576
577 if ( !$dop_fs->can_use_premium_code() ) {
578 echo '
579 <section class="text-red-600">' . esc_html__( 'This option is available in the Professional version.', 'delete-old-posts' ) ;
580 echo '
581 <a href="' . $dop_fs->get_upgrade_url() . '">' . '<u>' . esc_html__( 'Upgrade and activate it.', 'delete-old-posts' ) . '</u>' . '</a>' ;
582 echo '
583 </section>' ;
584 }
585
586 ?>
587 </div>
588 </div>
589 <?php
590 break;
591 }
592 }
593
594 /**
595 * try the filter and see the results
596 */
597 function tryFilter()
598 {
599 global $dop_fs ;
600 // get the posts to delete
601 $nrOfPostsToGet = $this->getNumberOfPosts();
602 $altPostsArray = $this->getAltestPostsObj( $nrOfPostsToGet );
603 ?>
604 <div class="p-5 bg-amber-50">
605 <div class="text-base mb-2">
606 <?php
607 ( !empty($altPostsArray) ? esc_html_e( 'The following ', 'delete-old-posts' ) : esc_html_e( 'No ', 'delete-old-posts' ) );
608 esc_html_e( "posts will be automatically deleted when the next scheduled cron job runs.", "delete-old-posts" );
609 // check if strat deleteing the post option is on off, then show a message to set it on on
610 $toggledelete = false;
611 $getOptionObject = get_option( 'deloldp-post-days-option' );
612 // get user saved options
613 if ( is_object( $getOptionObject ) && property_exists( $getOptionObject, 'params' ) ) {
614 if ( property_exists( $getOptionObject->params, 'toggledelete' ) ) {
615 if ( $getOptionObject->params->toggledelete == 1 ) {
616 $toggledelete = true;
617 }
618 }
619 }
620 if ( !$toggledelete ) {
621 esc_html_e( " Don't forget to set the \"Start deleting posts\" option ON, to start deleting the post automatically in the background.", "delete-old-posts" );
622 }
623 ?>
624 </div>
625 <?php
626 // get saved attached_img option
627 $attached_img_opt = $this->getFiltersOpt( 'attached_img' );
628 foreach ( $altPostsArray as $altPostDataObj ) {
629 if ( is_object( $altPostDataObj ) ) {
630 echo 'Post ' . 'ID <a href="' . get_permalink( $altPostDataObj->ID ) . '" target="_blank">' . $altPostDataObj->ID . '</a> - ' . $altPostDataObj->post_title . ' (' . $altPostDataObj->post_status . ': ' . date( "d M Y H:i", strtotime( $altPostDataObj->post_date ) ) . ')<br />' ;
631 }
632 }
633 ?>
634 </div>
635 <?php
636 }
637
638 /**
639 * count how many elemnts before a target is reached in an array
640 * @param $haystack - array to search
641 * @param $target - value to search
642 */
643 function countArrayUntilTarget( $haystack, $target )
644 {
645 $total = 0;
646 // check if target exists in array
647 if ( !array_search( $target, $haystack ) ) {
648 return 0;
649 }
650 // if target exists count the array elements until target
651 foreach ( $haystack as $key => $value ) {
652 if ( $value == $target ) {
653 break;
654 }
655 $total++;
656 }
657 return $total;
658 }
659
660 /**
661 * Generate a checkbox in form
662 *
663 * @param [string] $value
664 * @param [string] $label
665 * @return void
666 */
667 private function delopt_generate_check_box( $value, $label )
668 {
669 $checked = '';
670 // get saved cpt if form was submited
671 $cpt_type = $this->getFiltersOpt( 'cpt_type' );
672 switch ( $value ) {
673 case 'publish':
674 if ( empty($cpt_type) || isset( $cpt_type ) && is_array( $cpt_type ) && array_search( 'publish', $cpt_type ) !== false ) {
675 $checked = "checked";
676 }
677 break;
678 default:
679 if ( isset( $cpt_type ) && is_array( $cpt_type ) && array_search( $value, $cpt_type ) !== false ) {
680 $checked = "checked";
681 }
682 break;
683 }
684 echo "\n <label class='block my-2'>\n <input type='checkbox' name='cpt_type[]' value='" . $value . "'" ;
685 echo $checked ;
686 echo "/>\n <span class='ml-1 decoration-2'>\n " . esc_html( $label, 'delete-old-posts' ) . "\n </span>\n </label>" ;
687 }
688
689 }