PluginProbe ʕ •ᴥ•ʔ
Auto Post Cleaner / 3.5.3
Auto Post Cleaner v3.5.3
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 3 years ago class-delete-old-posts.php 2 years ago class-enqueue-assets.php 3 years ago
class-delete-old-posts-filters.php
662 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 removed.\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 $args = array(
176 'public' => true,
177 '_builtin' => false,
178 );
179 $getCustomPostTypes = get_post_types( $args );
180 // get saved cpt if form was submited
181 $cpts = $this->getFiltersOpt( 'cpt' );
182 ?>
183 <div class='m-2'>
184 <?php
185 echo "<div class='text-base'>" ;
186 esc_html_e( 'Choose the post type:', 'delete-old-posts' );
187 echo "</div>" ;
188 echo "\n <label class='block my-2'>\n <input type='checkbox' name='cpt[]' value='post'" ;
189 if ( empty($cpts) || isset( $cpts ) && is_array( $cpts ) && array_search( 'post', $cpts ) !== false ) {
190 echo "checked" ;
191 }
192 echo "/>\n <span class='underline " . $this->colors[0] . " ml-1 decoration-2'>\n Post\n </span>\n </label>" ;
193 $cptColor = 1;
194 if ( is_array( $getCustomPostTypes ) ) {
195 foreach ( $getCustomPostTypes as $customPostType ) {
196 $checked = false;
197 if ( isset( $cpts ) && is_array( $cpts ) && array_search( $customPostType, $cpts ) !== false ) {
198 $checked = true;
199 }
200 echo "\n <label class='block my-2'>\n <input type='checkbox' name='cpt[]' value='" . $customPostType . "'" ;
201 if ( $checked ) {
202 echo "checked" ;
203 }
204 echo " />\n <span class='ml-1 " ;
205 echo ( $checked && isset( $this->colors[$cptColor] ) ? $this->colors[$cptColor] . ' underline decoration-2' : '' ) ;
206 echo "'>\n " . ucfirst( str_replace( "_", " ", $customPostType ) ) . "\n </span>\n </label>" ;
207 $cptColor++;
208 }
209 }
210 echo "\n </div>" ;
211 ?>
212 </div>
213 <?php
214 break;
215 case 'cpt_type':
216 ?>
217 <div class="border border-inherit p-7 relative delop-filter">
218 <span class="dashicons dashicons-post-status text-4xl mb-4"></span>
219 <?php
220 $helpTxt = esc_html__( 'You can choose to delete only the posts by a specific status. The default status used is "publish".', 'delete-old-posts' );
221 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
222 // Generate the checkboxes
223 echo "<div class='text-base'>" ;
224 esc_html_e( 'Choose the post status:', 'delete-old-posts' );
225 echo "</div>" ;
226 $this->delopt_generate_check_box( 'publish', 'Publish' );
227 // $this->delopt_generate_check_box( 'future', 'Future' );
228 $this->delopt_generate_check_box( 'draft', 'Draft' );
229 $this->delopt_generate_check_box( 'pending', 'Pending' );
230 $this->delopt_generate_check_box( 'private', 'Private' );
231 ?>
232 </div>
233 <?php
234 break;
235 case 'categories':
236 // get all custom taxonomies
237 $args = array(
238 'public' => true,
239 '_builtin' => false,
240 );
241 $allCustomTaxonomies = get_taxonomies( $args );
242 // add default category to taxonomies
243 $allCustomTaxonomies = array(
244 'category' => 'category',
245 ) + $allCustomTaxonomies;
246 /**
247 * Get all CPT
248 * Used to find the co;or index for the category box
249 */
250 $args = array(
251 'public' => true,
252 '_builtin' => false,
253 );
254 $getAllCustomPostTypes = get_post_types( $args );
255 /**
256 * display a list of checkboxes for each taxonomy
257 * create the color for the taxonomy border to be the same as color used for the related custom post
258 */
259 // get the list with checked post types
260 $getCustomPostTypes = $this->getFiltersOpt( 'cpt' );
261 // get taxonomies for every checked post type
262 if ( is_array( $getCustomPostTypes ) ) {
263 foreach ( $getCustomPostTypes as $key => $cpt ) {
264 $cptTaxonomies[$key] = get_object_taxonomies( (string) $cpt );
265 }
266 }
267 // list all categories and taxonomies
268 if ( is_array( $allCustomTaxonomies ) ) {
269 foreach ( $allCustomTaxonomies as $category ) {
270 /**
271 * check if category is registered for the current cpt
272 */
273 $catInTaxList = false;
274 if ( isset( $cptTaxonomies ) && is_array( $cptTaxonomies ) ) {
275 foreach ( $cptTaxonomies as $cptIndex => $taxCPTSelected ) {
276
277 if ( in_array( $category, $taxCPTSelected ) ) {
278 $catInTaxList = true;
279 break;
280 // exit loop
281 }
282
283 }
284 }
285 /**
286 * show category if it is in the list of registered taxonomies for the selected post type
287 */
288
289 if ( $catInTaxList ) {
290 /**
291 * find border color index for the box
292 * need to be the same as the color of CPT in the list
293 */
294 $getCPTKeyInAllCPTArray = $this->countArrayUntilTarget( $getAllCustomPostTypes, $getCustomPostTypes[$cptIndex] );
295 // color index will be incremented with 1 (post is not in the CPT array so will need to be counted too)
296 $borderColorIndex = ( $category != 'category' ? $getCPTKeyInAllCPTArray + 1 : 0 );
297 ?>
298 <div class="border p-7 relative max-w-xs <?php
299 echo ( isset( $this->bcolors[$borderColorIndex] ) ? $this->bcolors[$borderColorIndex] : '' ) ;
300 ?> delop-filter">
301 <span class="dashicons dashicons-category text-4xl mb-4"></span>
302 <?php
303 $titleText = esc_html__( 'Choose taxonomies to filter the deleted %s.', 'delete-old-posts' );
304 $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' );
305 $strongText = "any taxonomy";
306
307 if ( $category == 'category' ) {
308 $titleText = esc_html__( 'Choose categories to filter the deleted posts.', 'delete-old-posts' );
309 $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' );
310 $strongText = "any category";
311 }
312
313 $helpTxt = sprintf( $helpText, '<strong>' . esc_html__( $strongText, "delete-old-posts" ) . '</strong>' );
314 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
315 ?>
316 <div class="mb-2 text-base">
317 <?php
318 $custompostname = ucfirst( str_replace( "_", " ", $getCustomPostTypes[$cptIndex] ) );
319 $getTaxName = get_taxonomy_labels( get_taxonomy( $category ) );
320 echo sprintf( esc_html__( $titleText, "delete-old-posts" ), "<strong>" . esc_html__( $custompostname, "delete-old-posts" ) . "</strong>" ) ;
321 echo "<br /><strong>" . $getTaxName->name . "</strong> " ;
322 esc_html_e( "list:", 'delete-old-posts' );
323 ?>
324 </div>
325 <div class="max-h-56 overflow-auto">
326 <?php
327 $choosedCats = ( $category == 'category' ? $this->getFiltersOpt( 'post_category' ) : $this->getFiltersOpt( 'tax_input', $category ) );
328 $choosedCats = ( is_array( $choosedCats ) ? $choosedCats : false );
329 /**
330 * Display checkboxes with categories
331 */
332 $cat = get_taxonomy( $category );
333
334 if ( current_user_can( $cat->cap->assign_terms ) ) {
335 // get selected categories if form was previous save
336 $args = array(
337 'taxonomy' => $category,
338 'hierarchical' => true,
339 'title_li' => '',
340 'hide_empty' => false,
341 'selected_cats' => $choosedCats,
342 'popular_cats' => false,
343 'checked_ontop' => true,
344 );
345 wp_terms_checklist( $post_id = 0, $args );
346 }
347
348 ?>
349 </div>
350 </div>
351 <?php
352 }
353
354 }
355 }
356 break;
357 case 'users':
358 // get saved user filter if form was submited
359 $usersFilter = $this->getFiltersOpt( 'userid' );
360 // get all users
361 $users = get_users( array(
362 'fields' => array( 'ID' ),
363 ) );
364 // list users
365 ?>
366 <div class='border border-inherit p-7 relative max-w-xs delop-filter'>
367 <span class="dashicons dashicons-admin-users text-4xl mb-4"></span>
368 <?php
369 $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>' );
370 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
371 ?>
372 <div class='m-2'>
373 <?php
374 echo "<div class='text-base'>" ;
375 esc_html_e( 'Delete only the posts from specific users:', 'delete-old-posts' );
376 echo "</div>" ;
377 echo "\n <div class='max-h-56 overflow-auto'>" ;
378 foreach ( $users as $user ) {
379 $userObj = get_user_by( 'ID', $user->ID );
380 echo "<label class='block my-2'><input type='checkbox' name='userid[]' value='" . $user->ID . "'" ;
381 if ( isset( $usersFilter ) && is_array( $usersFilter ) && array_search( $user->ID, $usersFilter ) !== false ) {
382 echo "checked" ;
383 }
384 echo "/> " . $userObj->display_name . "</label>" ;
385 }
386 echo "\n </div>" ;
387 ?>
388 </div>
389 </div>
390 <?php
391 break;
392 case 'relation':
393 // get saved relation filter if form was submited
394 $relationFilter = $this->getFiltersOpt( 'relation' );
395 if ( empty($relationFilter) ) {
396 $relationFilter = 'OR';
397 }
398 ?>
399 <div class='border border-inherit p-7 relative max-w-xs delop-filter'>
400 <span class="dashicons dashicons-forms text-4xl mb-4"></span>
401 <?php
402 $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>' );
403 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
404 ?>
405 <div class='m-2'>
406 <?php
407 echo "<div class='text-base'>" ;
408 esc_html_e( 'Choose the relation applied to selected categories or taxonomies terms:', 'delete-old-posts' );
409 echo "</div>" ;
410 echo "<label class='block my-2'><input type='radio' name='relation' value='AND'" ;
411 if ( isset( $relationFilter ) && $relationFilter == 'AND' ) {
412 echo "checked" ;
413 }
414 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>" ;
415 echo "<label class='block my-2'><input type='radio' name='relation' value='OR'" ;
416 if ( isset( $relationFilter ) && $relationFilter == 'OR' ) {
417 echo "checked" ;
418 }
419 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>" ;
420 ?>
421 </div>
422 </div>
423 <?php
424 break;
425 case 'postids':
426 ?>
427 <div class="border border-inherit p-7 relative max-w-xs delop-filter">
428 <span class="dashicons dashicons-portfolio text-4xl mb-4"></span>
429 <?php
430 // get saved post ids if form was submited
431 $postids = $this->getFiltersOpt( 'postids' );
432 $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>' );
433 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
434 ?>
435 <div class="m-2">
436 <?php
437 echo "<div class='text-base'>" ;
438 esc_html_e( 'Have some important posts? Enter the post IDs that you want to keep:', 'delete-old-posts' );
439 echo "</div>" ;
440 ?>
441 <label class="block my-2 mt-8">
442 <span><?php
443 esc_html_e( "Post IDs to exclude:", "delete-old-posts" );
444 ?></span>
445 <input class="w-full" type="text" name="postids" value="<?php
446 echo sanitize_text_field( $postids ) ;
447 ?>" />
448 </label>
449 </div>
450 </div>
451 <?php
452 break;
453 case 'search_keywords':
454 ?>
455 <div class="border border-inherit p-7 relative max-w-xs delop-filter">
456 <span class="dashicons dashicons-search text-4xl mb-4"></span>
457 <?php
458 // get saved post ids if form was submited
459 $search_keyword = $this->getFiltersOpt( 'search_keyword' );
460 $search_keyword_negativ = $this->getFiltersOpt( 'search_keyword_negativ' );
461 $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>' );
462 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
463 ?>
464 <div class="m-2">
465 <?php
466 echo "<div class='text-base'>" ;
467 esc_html_e( 'Delete only posts that contain the keyword(s):', 'delete-old-posts' );
468 echo "</div>" ;
469 ?>
470 <label class="block my-2">
471 <span><?php
472 esc_html_e( "Look for posts that include the keyword(s):", "delete-old-posts" );
473 ?></span>
474 <input class="w-full" type="text" name="search_keyword" value="<?php
475 echo sanitize_text_field( $search_keyword ) ;
476 ?>" />
477 </label>
478 <label class="block my-2">
479 <span><?php
480 esc_html_e( "Exclude from search results any posts that contain the keyword(s):", "delete-old-posts" );
481 ?></span>
482 <input class="w-full" type="text" name="search_keyword_negativ" value="<?php
483 echo sanitize_text_field( $search_keyword_negativ ) ;
484 ?>" />
485 </label>
486 </div>
487 </div>
488 <?php
489 break;
490 case 'attached_img':
491 ?>
492 <div class="border border-inherit p-7 relative max-w-xs delop-filter">
493 <span class="dashicons dashicons-images-alt2 text-4xl mb-4"></span>
494 <?php
495 // get saved attached_img option if form was submited
496 $attached_img = $this->getFiltersOpt( 'attached_img' );
497 $force_delete_attached_img = $this->getFiltersOpt( 'force_delete_attached_img' );
498 $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>' );
499 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
500 ?>
501 <div class="m-2">
502 <?php
503 echo "<div class='text-base'>" ;
504 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' );
505 echo "</div>" ;
506 ?>
507 <label class="block my-2">
508 <span class="font-bold">
509 <?php
510 esc_html_e( "Delete all files attached to post:", "delete-old-posts" );
511 ?>
512 </span>
513 <input class="w-full" type="checkbox" name="attached_img" value="1" <?php
514 if ( !$dop_fs->can_use_premium_code() ) {
515 echo "disabled" ;
516 }
517 ?> <?php
518 if ( $attached_img == 1 ) {
519 echo "checked" ;
520 }
521 ?> />
522 </label>
523 <label class="block my-2">
524 <span class="font-bold">
525 <?php
526 esc_html_e( "Force delete attached files:", "delete-old-posts" );
527 ?>
528 </span>
529 <input
530 class="w-full"
531 type="checkbox"
532 @click="confirmForceDelete()"
533 id="forcedeleteattachedimg"
534 name="force_delete_attached_img"
535 value="1"
536 <?php
537 if ( !$dop_fs->can_use_premium_code() ) {
538 echo "disabled" ;
539 }
540 ?>
541 <?php
542 if ( $force_delete_attached_img == 1 ) {
543 echo "checked" ;
544 }
545 ?>
546 />
547 </label>
548 <?php
549
550 if ( !$dop_fs->can_use_premium_code() ) {
551 echo '
552 <section class="text-red-600">' . esc_html__( 'This option is available in the Professional version.', 'delete-old-posts' ) ;
553 echo '
554 <a href="' . $dop_fs->get_upgrade_url() . '">' . '<u>' . esc_html__( 'Upgrade and activate it.', 'delete-old-posts' ) . '</u>' . '</a>' ;
555 echo '
556 </section>' ;
557 }
558
559 ?>
560 </div>
561 </div>
562 <?php
563 break;
564 }
565 }
566
567 /**
568 * try the filter and see the results
569 */
570 function tryFilter()
571 {
572 global $dop_fs ;
573 // get the posts to delete
574 $nrOfPostsToGet = $this->getNumberOfPosts();
575 $altPostsArray = $this->getAltestPostsObj( $nrOfPostsToGet );
576 ?>
577 <div class="p-5 bg-amber-50">
578 <div class="text-base mb-2">
579 <?php
580 ( !empty($altPostsArray) ? esc_html_e( 'The following ', 'delete-old-posts' ) : esc_html_e( 'No ', 'delete-old-posts' ) );
581 esc_html_e( "posts will be automatically deleted when the next scheduled cron job runs.", "delete-old-posts" );
582 // check if strat deleteing the post option is on off, then show a message to set it on on
583 $toggledelete = false;
584 $getOptionObject = get_option( 'deloldp-post-days-option' );
585 // get user saved options
586 if ( is_object( $getOptionObject ) && property_exists( $getOptionObject, 'params' ) ) {
587 if ( property_exists( $getOptionObject->params, 'toggledelete' ) ) {
588 if ( $getOptionObject->params->toggledelete == 1 ) {
589 $toggledelete = true;
590 }
591 }
592 }
593 if ( !$toggledelete ) {
594 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" );
595 }
596 ?>
597 </div>
598 <?php
599 // get saved attached_img option
600 $attached_img_opt = $this->getFiltersOpt( 'attached_img' );
601 foreach ( $altPostsArray as $altPostDataObj ) {
602 if ( is_object( $altPostDataObj ) ) {
603 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 />' ;
604 }
605 }
606 ?>
607 </div>
608 <?php
609 }
610
611 /**
612 * count how many elemnts before a target is reached in an array
613 * @param $haystack - array to search
614 * @param $target - value to search
615 */
616 function countArrayUntilTarget( $haystack, $target )
617 {
618 $total = 0;
619 // check if target exists in array
620 if ( !array_search( $target, $haystack ) ) {
621 return 0;
622 }
623 // if target exists count the array elements until target
624 foreach ( $haystack as $key => $value ) {
625 if ( $value == $target ) {
626 break;
627 }
628 $total++;
629 }
630 return $total;
631 }
632
633 /**
634 * Generate a checkbox in form
635 *
636 * @param [string] $value
637 * @param [string] $label
638 * @return void
639 */
640 private function delopt_generate_check_box( $value, $label )
641 {
642 $checked = '';
643 // get saved cpt if form was submited
644 $cpt_type = $this->getFiltersOpt( 'cpt_type' );
645 switch ( $value ) {
646 case 'publish':
647 if ( empty($cpt_type) || isset( $cpt_type ) && is_array( $cpt_type ) && array_search( 'publish', $cpt_type ) !== false ) {
648 $checked = "checked";
649 }
650 break;
651 default:
652 if ( isset( $cpt_type ) && is_array( $cpt_type ) && array_search( $value, $cpt_type ) !== false ) {
653 $checked = "checked";
654 }
655 break;
656 }
657 echo "\n <label class='block my-2'>\n <input type='checkbox' name='cpt_type[]' value='" . $value . "'" ;
658 echo $checked ;
659 echo "/>\n <span class='ml-1 decoration-2'>\n " . esc_html( $label, 'delete-old-posts' ) . "\n </span>\n </label>" ;
660 }
661
662 }