Plugin Directory

Changeset 2793124


Ignore:
Timestamp:
10/02/2022 06:32:58 PM (4 years ago)
Author:
palashwpdev
Message:

Added the init hook to work properly.

Location:
auto-delete-post
Files:
6 added
2 edited

Legend:

Unmodified
Added
Removed
  • auto-delete-post/trunk/auto-delete-post.php

    r2790974 r2793124  
    44 * Plugin URI:        https://wordpress.org/plugin/auto-delete-post
    55 * Description:       This plugin automatically deletes a post after a certain time
    6  * Version:           1.1
     6 * Version:           1.1.1
    77 * Requires at least: 5.2
    88 * Requires PHP:      7.2
     
    1818 * All constants
    1919 */
    20 
    2120// Constants for version
    22 $adp_version = '1.1';
     21$adp_version = '1.1.1';
    2322define( 'ADP_VERSION', $adp_version );
    2423
     
    4140        add_action( 'add_meta_boxes', [ $this, 'adp_create_auto_delete_post_meta_box' ] );
    4241        add_action( 'save_post', [ $this, 'adp_save_auto_delete_post_meta_box' ] );
     42        add_action( 'init', [ $this, 'delete' ] );
    4343    }
    4444
     
    7272        }
    7373    }
     74
     75    // auto post deletion mechanism
     76    public function delete() {
     77        $adp_custom_query = new WP_Query( array(
     78            'post_type' => 'post',
     79            'posts_per_page' => -1,
     80        ));
     81        if( $adp_custom_query->have_posts() ) {
     82            while( $adp_custom_query->have_posts() ) {
     83                $adp_custom_query->the_post();
     84               
     85                $unique_post_id = get_the_ID();
     86                $final_meta_value = get_post_meta( $unique_post_id, 'auto_delete_post_time_key', true );
     87                $converted_user_date_time = strtotime( $final_meta_value );
     88                $converted_in_date_format = date('Y-m-d H:i', $converted_user_date_time).' ';
     89                $final_user_date_time = strtotime( $converted_in_date_format );
     90                $current_server_time = current_time('timestamp');
     91                if( $current_server_time >= $final_user_date_time && $final_user_date_time > 0 ) {
     92                        wp_delete_post( $unique_post_id );
     93                }
     94            }
     95        }
     96       
     97        wp_reset_postdata();
     98    }
    7499}
    75100
    76101$obj = new ADP_Auto_Delete_Post(); // class initialization
    77102
    78 // auto post deletion mechanism   
    79 add_action( 'wp_head', 'delete' );
    80 function delete() {
    81     $adp_custom_query = new WP_Query( array(
    82         'post_type' => 'post',
    83         'posts_per_page' => -1,
    84     ));
    85     if( $adp_custom_query->have_posts() ) {
    86         while( $adp_custom_query->have_posts() ) {
    87             $adp_custom_query->the_post();
    88            
    89             $unique_post_id = get_the_ID();
    90             $final_meta_value = get_post_meta( $unique_post_id, 'auto_delete_post_time_key', true );
    91             $converted_user_date_time = strtotime( $final_meta_value );
    92             $converted_in_date_format = date('Y-m-d H:i', $converted_user_date_time).' ';
    93             $final_user_date_time = strtotime( $converted_in_date_format );
    94             $current_server_time = current_time('timestamp');
    95             if( $current_server_time >= $final_user_date_time && $final_user_date_time > 0 ) {
    96                     wp_delete_post( $unique_post_id );
    97             }
    98         }
    99     }
    100    
    101     wp_reset_postdata();
    102    
    103 }
     103
     104
  • auto-delete-post/trunk/readme.txt

    r2790983 r2793124  
    66Requires at least: 5.2
    77Tested up to: 6.0
    8 Version: 1.1
    9 Stable tag: 1.1
     8Version: 1.1.1
     9Stable tag: 1.1.1
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1212
    1313== Description ==
    14 Delete your any blog post automatically after a certain time. This plugin will help you to delete a post after expiration of the given time which you can set during a post publish. Set a time from the time and date input field, refresh your front end and be tension free! The plugin will do the rest.
     14Delete your any blog post automatically after a certain time. This plugin will help you to delete a post after expiration of the given time which you can set during a post publish. Set a time from the time and date input field and be tension free! The plugin will do the rest for you.
    1515
    1616
     
    3838== Changelog ==
    3939
    40 = 1.1 =
    41 Fixed some bug.
     40= 1.1.1 =
     41Done some minor changes.
    4242
    4343== Upgrade Notice ==
    4444
    45 = 1.1 =
     45= 1.1.1 =
    4646There is a upgrade available.
Note: See TracChangeset for help on using the changeset viewer.