PluginProbe ʕ •ᴥ•ʔ
Auto Post Cleaner / 3.3.10
Auto Post Cleaner v3.3.10
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 3 years ago class-delete-old-posts-redirects.php 3 years ago class-delete-old-posts.php 3 years ago class-enqueue-assets.php 3 years ago
class-delete-old-posts-filters.php
610 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
89 if ( current_user_can( 'manage_categories' ) ) {
90 $this->delop_get_form_input( 'categories' );
91 $this->delop_get_form_input( 'relation' );
92 }
93
94 if ( current_user_can( 'list_users' ) ) {
95 $this->delop_get_form_input( 'users' );
96 }
97 $this->delop_get_form_input( 'postids' );
98 $this->delop_get_form_input( 'search_keywords' );
99 $this->delop_get_form_input( 'attached_img' );
100 } else {
101 esc_html_e( "You don't have rights to delete the posts.", "delete-old-posts" );
102 }
103
104 ?>
105 <div class="w-full flex items-center">
106 <div class="w-full text-right">
107 <button
108 type="submit"
109 class="bg-blue-500 rounded-full font-bold text-white px-4 py-3 transition duration-300 ease-in-out hover:bg-blue-600"
110 >
111 <?php
112 esc_html_e( 'Save and test the deleted posts.', 'delete-old-posts' );
113 ?>
114 <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">
115 <line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/>
116 </svg>
117 </button>
118 <?php
119 wp_nonce_field( 'delop_filters_save', 'delop_nonce_filters' );
120 ?>
121 </div>
122 </div>
123 </div>
124 </form>
125 </div>
126 </section>
127 <?php
128 }
129
130 /**
131 * Handle the Filter's form change
132 */
133 function filtersFormSave()
134 {
135 // check if filters form was just saved
136
137 if ( isset( $_POST['delop_nonce_filters'] ) && wp_verify_nonce( $_POST['delop_nonce_filters'], 'delop_filters_save' ) ) {
138 // sanitize $_POST vars
139 $filtersOptions = ( isset( $_POST ) ? (array) $_POST : array() );
140 $filtersOptions = filter_var_array( $filtersOptions );
141 // check if any post type selected (at least the default post type have to be selected)
142
143 if ( !isset( $filtersOptions['cpt'] ) || isset( $filtersOptions['cpt'] ) && empty($filtersOptions['cpt']) ) {
144 // set the default post
145 $filtersOptions['cpt'] = array( 'post' );
146 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" ) ;
147 }
148
149 // save Filters option into an Option
150 update_option( 'delop_filters', $filtersOptions );
151 // show a list with deleted posts. Test the filter.
152 $this->tryFilter();
153 }
154
155 }
156
157 /**
158 * Create form inputs
159 */
160 function delop_get_form_input( $inputName )
161 {
162 global $dop_fs ;
163 switch ( $inputName ) {
164 case 'cpt':
165 ?>
166 <div class="border border-inherit p-7 relative delop-filter">
167 <span class="dashicons dashicons-admin-post text-4xl mb-4"></span>
168 <?php
169 $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>' );
170 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
171 /**
172 * Get the list with custom post types
173 */
174 $args = array(
175 'public' => true,
176 '_builtin' => false,
177 );
178 $getCustomPostTypes = get_post_types( $args );
179 // get saved cpt if form was submited
180 $cpts = $this->getFiltersOpt( 'cpt' );
181 ?>
182 <div class='m-2'>
183 <?php
184 echo "<div class='text-base'>" ;
185 esc_html_e( 'Choose the post type:', 'delete-old-posts' );
186 echo "</div>" ;
187 echo "\n <label class='block my-2'>\n <input type='checkbox' name='cpt[]' value='post'" ;
188 if ( empty($cpts) || isset( $cpts ) && is_array( $cpts ) && array_search( 'post', $cpts ) !== false ) {
189 echo "checked" ;
190 }
191 echo "/>\n <span class='underline " . $this->colors[0] . " ml-1 decoration-2'>\n Post\n </span>\n </label>" ;
192 $cptColor = 1;
193 if ( is_array( $getCustomPostTypes ) ) {
194 foreach ( $getCustomPostTypes as $customPostType ) {
195 $checked = false;
196 if ( isset( $cpts ) && is_array( $cpts ) && array_search( $customPostType, $cpts ) !== false ) {
197 $checked = true;
198 }
199 echo "\n <label class='block my-2'>\n <input type='checkbox' name='cpt[]' value='" . $customPostType . "'" ;
200 if ( $checked ) {
201 echo "checked" ;
202 }
203 echo " />\n <span class='ml-1 " ;
204 echo ( $checked && isset( $this->colors[$cptColor] ) ? $this->colors[$cptColor] . ' underline decoration-2' : '' ) ;
205 echo "'>\n " . ucfirst( str_replace( "_", " ", $customPostType ) ) . "\n </span>\n </label>" ;
206 $cptColor++;
207 }
208 }
209 echo "\n </div>" ;
210 ?>
211 </div>
212 <?php
213 break;
214 case 'categories':
215 // get all custom taxonomies
216 $args = array(
217 'public' => true,
218 '_builtin' => false,
219 );
220 $allCustomTaxonomies = get_taxonomies( $args );
221 // add default category to taxonomies
222 $allCustomTaxonomies = array(
223 'category' => 'category',
224 ) + $allCustomTaxonomies;
225 /**
226 * Get all CPT
227 * Used to find the co;or index for the category box
228 */
229 $args = array(
230 'public' => true,
231 '_builtin' => false,
232 );
233 $getAllCustomPostTypes = get_post_types( $args );
234 /**
235 * display a list of checkboxes for each taxonomy
236 * create the color for the taxonomy border to be the same as color used for the related custom post
237 */
238 // get the list with checked post types
239 $getCustomPostTypes = $this->getFiltersOpt( 'cpt' );
240 // get taxonomies for every checked post type
241 if ( is_array( $getCustomPostTypes ) ) {
242 foreach ( $getCustomPostTypes as $key => $cpt ) {
243 $cptTaxonomies[$key] = get_object_taxonomies( (string) $cpt );
244 }
245 }
246 // list all categories and taxonomies
247 if ( is_array( $allCustomTaxonomies ) ) {
248 foreach ( $allCustomTaxonomies as $category ) {
249 /**
250 * check if category is registered for the current cpt
251 */
252 $catInTaxList = false;
253 if ( isset( $cptTaxonomies ) && is_array( $cptTaxonomies ) ) {
254 foreach ( $cptTaxonomies as $cptIndex => $taxCPTSelected ) {
255
256 if ( in_array( $category, $taxCPTSelected ) ) {
257 $catInTaxList = true;
258 break;
259 // exit loop
260 }
261
262 }
263 }
264 /**
265 * show category if it is in the list of registered taxonomies for the selected post type
266 */
267
268 if ( $catInTaxList ) {
269 /**
270 * find border color index for the box
271 * need to be the same as the color of CPT in the list
272 */
273 $getCPTKeyInAllCPTArray = $this->countArrayUntilTarget( $getAllCustomPostTypes, $getCustomPostTypes[$cptIndex] );
274 // color index will be incremented with 1 (post is not in the CPT array so will need to be counted too)
275 $borderColorIndex = ( $category != 'category' ? $getCPTKeyInAllCPTArray + 1 : 0 );
276 ?>
277 <div class="border p-7 relative max-w-xs <?php
278 echo ( isset( $this->bcolors[$borderColorIndex] ) ? $this->bcolors[$borderColorIndex] : '' ) ;
279 ?> delop-filter">
280 <span class="dashicons dashicons-category text-4xl mb-4"></span>
281 <?php
282 $titleText = esc_html__( 'Choose taxonomies to filter the deleted %s.', 'delete-old-posts' );
283 $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' );
284 $strongText = "any taxonomy";
285
286 if ( $category == 'category' ) {
287 $titleText = esc_html__( 'Choose categories to filter the deleted posts.', 'delete-old-posts' );
288 $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' );
289 $strongText = "any category";
290 }
291
292 $helpTxt = sprintf( $helpText, '<strong>' . esc_html__( $strongText, "delete-old-posts" ) . '</strong>' );
293 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
294 ?>
295 <div class="mb-2 text-base">
296 <?php
297 $custompostname = ucfirst( str_replace( "_", " ", $getCustomPostTypes[$cptIndex] ) );
298 $getTaxName = get_taxonomy_labels( get_taxonomy( $category ) );
299 echo sprintf( esc_html__( $titleText, "delete-old-posts" ), "<strong>" . esc_html__( $custompostname, "delete-old-posts" ) . "</strong>" ) ;
300 echo "<br /><strong>" . $getTaxName->name . "</strong> " ;
301 esc_html_e( "list:", 'delete-old-posts' );
302 ?>
303 </div>
304 <div class="max-h-56 overflow-auto">
305 <?php
306 $choosedCats = ( $category == 'category' ? $this->getFiltersOpt( 'post_category' ) : $this->getFiltersOpt( 'tax_input', $category ) );
307 $choosedCats = ( is_array( $choosedCats ) ? $choosedCats : false );
308 /**
309 * Display checkboxes with categories
310 */
311 $cat = get_taxonomy( $category );
312
313 if ( current_user_can( $cat->cap->assign_terms ) ) {
314 // get selected categories if form was previous save
315 $args = array(
316 'taxonomy' => $category,
317 'hierarchical' => true,
318 'title_li' => '',
319 'hide_empty' => false,
320 'selected_cats' => $choosedCats,
321 'popular_cats' => false,
322 'checked_ontop' => true,
323 );
324 wp_terms_checklist( $post_id = 0, $args );
325 }
326
327 ?>
328 </div>
329 </div>
330 <?php
331 }
332
333 }
334 }
335 break;
336 case 'users':
337 // get saved user filter if form was submited
338 $usersFilter = $this->getFiltersOpt( 'userid' );
339 // get all users
340 $users = get_users( array(
341 'fields' => array( 'ID' ),
342 ) );
343 // list users
344 ?>
345 <div class='border border-inherit p-7 relative max-w-xs delop-filter'>
346 <span class="dashicons dashicons-admin-users text-4xl mb-4"></span>
347 <?php
348 $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>' );
349 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
350 ?>
351 <div class='m-2'>
352 <?php
353 echo "<div class='text-base'>" ;
354 esc_html_e( 'Delete only the posts from specific users:', 'delete-old-posts' );
355 echo "</div>" ;
356 foreach ( $users as $user ) {
357 $userObj = get_user_by( 'ID', $user->ID );
358 echo "<label class='block my-2'><input type='checkbox' name='userid[]' value='" . $user->ID . "'" ;
359 if ( isset( $usersFilter ) && is_array( $usersFilter ) && array_search( $user->ID, $usersFilter ) !== false ) {
360 echo "checked" ;
361 }
362 echo "/> " . $userObj->display_name . "</label>" ;
363 }
364 ?>
365 </div>
366 </div>
367 <?php
368 break;
369 case 'relation':
370 // get saved relation filter if form was submited
371 $relationFilter = $this->getFiltersOpt( 'relation' );
372 if ( empty($relationFilter) ) {
373 $relationFilter = 'AND';
374 }
375 ?>
376 <div class='border border-inherit p-7 relative max-w-xs delop-filter'>
377 <span class="dashicons dashicons-forms text-4xl mb-4"></span>
378 <?php
379 $helpTxt = sprintf( esc_html__( 'Choose the relation applied to terms. By default (no relation selected), %s will be used. "All selected terms" mean that the deleted post will need to have relation with all selected terms. "Any selected 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>' );
380 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
381 ?>
382 <div class='m-2'>
383 <?php
384 echo "<div class='text-base'>" ;
385 esc_html_e( 'Choose the relation applied to taxonomies terms:', 'delete-old-posts' );
386 echo "</div>" ;
387 echo "<label class='block my-2'><input type='radio' name='relation' value='AND'" ;
388 if ( isset( $relationFilter ) && $relationFilter == 'AND' ) {
389 echo "checked" ;
390 }
391 echo "/>" . esc_html__( "All selected terms", "delete-old-posts" ) . "</label>" ;
392 echo "<label class='block my-2'><input type='radio' name='relation' value='OR'" ;
393 if ( isset( $relationFilter ) && $relationFilter == 'OR' ) {
394 echo "checked" ;
395 }
396 echo "/>" . esc_html__( "Any selected terms", "delete-old-posts" ) . "</label>" ;
397 ?>
398 </div>
399 </div>
400 <?php
401 break;
402 case 'postids':
403 ?>
404 <div class="border border-inherit p-7 relative max-w-xs delop-filter">
405 <span class="dashicons dashicons-portfolio text-4xl mb-4"></span>
406 <?php
407 // get saved post ids if form was submited
408 $postids = $this->getFiltersOpt( 'postids' );
409 $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>' );
410 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
411 ?>
412 <div class="m-2">
413 <?php
414 echo "<div class='text-base'>" ;
415 esc_html_e( 'Have some important posts? Enter the post IDs that you want to keep:', 'delete-old-posts' );
416 echo "</div>" ;
417 ?>
418 <label class="block my-2 mt-8">
419 <span><?php
420 esc_html_e( "Post IDs to exclude:", "delete-old-posts" );
421 ?></span>
422 <input class="w-full" type="text" name="postids" value="<?php
423 echo sanitize_text_field( $postids ) ;
424 ?>" />
425 </label>
426 </div>
427 </div>
428 <?php
429 break;
430 case 'search_keywords':
431 ?>
432 <div class="border border-inherit p-7 relative max-w-xs delop-filter">
433 <span class="dashicons dashicons-search text-4xl mb-4"></span>
434 <?php
435 // get saved post ids if form was submited
436 $search_keyword = $this->getFiltersOpt( 'search_keyword' );
437 $search_keyword_negativ = $this->getFiltersOpt( 'search_keyword_negativ' );
438 $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>' );
439 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
440 ?>
441 <div class="m-2">
442 <?php
443 echo "<div class='text-base'>" ;
444 esc_html_e( 'Delete only posts that contain the keyword(s):', 'delete-old-posts' );
445 echo "</div>" ;
446 ?>
447 <label class="block my-2">
448 <span><?php
449 esc_html_e( "Look for posts that include the keyword(s):", "delete-old-posts" );
450 ?></span>
451 <input class="w-full" type="text" name="search_keyword" value="<?php
452 echo sanitize_text_field( $search_keyword ) ;
453 ?>" />
454 </label>
455 <label class="block my-2">
456 <span><?php
457 esc_html_e( "Exclude from search results any posts that contain the keyword(s):", "delete-old-posts" );
458 ?></span>
459 <input class="w-full" type="text" name="search_keyword_negativ" value="<?php
460 echo sanitize_text_field( $search_keyword_negativ ) ;
461 ?>" />
462 </label>
463 </div>
464 </div>
465 <?php
466 break;
467 case 'attached_img':
468 ?>
469 <div class="border border-inherit p-7 relative max-w-xs delop-filter">
470 <span class="dashicons dashicons-images-alt2 text-4xl mb-4"></span>
471 <?php
472 // get saved attached_img option if form was submited
473 $attached_img = $this->getFiltersOpt( 'attached_img' );
474 $force_delete_attached_img = $this->getFiltersOpt( 'force_delete_attached_img' );
475 $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>' );
476 $this->generateHelpTooltip( $helpTxt, 'w-full text-right absolute right-1 top-1', 'text-left right-1' );
477 ?>
478 <div class="m-2">
479 <?php
480 echo "<div class='text-base'>" ;
481 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' );
482 echo "</div>" ;
483 ?>
484 <label class="block my-2">
485 <span class="font-bold">
486 <?php
487 esc_html_e( "Delete all files attached to post:", "delete-old-posts" );
488 ?>
489 </span>
490 <input class="w-full" type="checkbox" name="attached_img" value="1" <?php
491 if ( !$dop_fs->can_use_premium_code() ) {
492 echo "disabled" ;
493 }
494 ?> <?php
495 if ( $attached_img == 1 ) {
496 echo "checked" ;
497 }
498 ?> />
499 </label>
500 <label class="block my-2">
501 <span class="font-bold">
502 <?php
503 esc_html_e( "Force delete attached files:", "delete-old-posts" );
504 ?>
505 </span>
506 <input
507 class="w-full"
508 type="checkbox"
509 @click="confirmForceDelete()"
510 id="forcedeleteattachedimg"
511 name="force_delete_attached_img"
512 value="1"
513 <?php
514 if ( !$dop_fs->can_use_premium_code() ) {
515 echo "disabled" ;
516 }
517 ?>
518 <?php
519 if ( $force_delete_attached_img == 1 ) {
520 echo "checked" ;
521 }
522 ?>
523 />
524 </label>
525 <?php
526
527 if ( !$dop_fs->can_use_premium_code() ) {
528 echo '
529 <section class="text-red-600">' . esc_html__( 'This option is available in the Professional version.', 'delete-old-posts' ) ;
530 echo '
531 <a href="' . $dop_fs->get_upgrade_url() . '">' . '<u>' . esc_html__( 'Upgrade and activate it.', 'delete-old-posts' ) . '</u>' . '</a>' ;
532 echo '
533 </section>' ;
534 }
535
536 ?>
537 </div>
538 </div>
539 <?php
540 break;
541 }
542 }
543
544 /**
545 * try the filter and see the results
546 */
547 function tryFilter()
548 {
549 global $dop_fs ;
550 // get the posts to delete
551 $nrOfPostsToGet = $this->getNumberOfPosts();
552 $altPostsArray = $this->getAltestPostsObj( $nrOfPostsToGet );
553 ?>
554 <div class="p-5 bg-amber-50">
555 <div class="text-base mb-2">
556 <?php
557 ( !empty($altPostsArray) ? esc_html_e( 'The following ', 'delete-old-posts' ) : esc_html_e( 'No ', 'delete-old-posts' ) );
558 esc_html_e( "posts will be automatically deleted when the next scheduled cron job runs.", "delete-old-posts" );
559 // check if strat deleteing the post option is on off, then show a message to set it on on
560 $toggledelete = false;
561 $getOptionObject = get_option( 'deloldp-post-days-option' );
562 // get user saved options
563 if ( is_object( $getOptionObject ) && property_exists( $getOptionObject, 'params' ) ) {
564 if ( property_exists( $getOptionObject->params, 'toggledelete' ) ) {
565 if ( $getOptionObject->params->toggledelete == 1 ) {
566 $toggledelete = true;
567 }
568 }
569 }
570 if ( !$toggledelete ) {
571 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" );
572 }
573 ?>
574 </div>
575 <?php
576 // get saved attached_img option
577 $attached_img_opt = $this->getFiltersOpt( 'attached_img' );
578 foreach ( $altPostsArray as $altPostDataObj ) {
579 if ( is_object( $altPostDataObj ) ) {
580 echo 'Post ' . 'ID <a href="' . get_permalink( $altPostDataObj->ID ) . '" target="_blank">' . $altPostDataObj->ID . '</a> - ' . $altPostDataObj->post_title . ' (published: ' . date( "d M Y H:i", strtotime( $altPostDataObj->post_date ) ) . ')<br />' ;
581 }
582 }
583 ?>
584 </div>
585 <?php
586 }
587
588 /**
589 * count how many elemnts before a target is reached in an array
590 * @param $haystack - array to search
591 * @param $target - value to search
592 */
593 function countArrayUntilTarget( $haystack, $target )
594 {
595 $total = 0;
596 // check if target exists in array
597 if ( !array_search( $target, $haystack ) ) {
598 return 0;
599 }
600 // if target exists count the array elements until target
601 foreach ( $haystack as $key => $value ) {
602 if ( $value == $target ) {
603 break;
604 }
605 $total++;
606 }
607 return $total;
608 }
609
610 }