Plugin Directory

Changeset 3132899


Ignore:
Timestamp:
08/08/2024 08:40:12 PM (20 months ago)
Author:
palashwpdev
Message:

"released versiion 1.1.4"

Location:
auto-delete-post
Files:
35 added
3 edited

Legend:

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

    r3041524 r3132899  
    1 <?php 
     1<?php
    22/**
     3 * @package AutoDeletePost
     4 *
    35 * Plugin Name:       Auto Delete Post
    46 * Plugin URI:        https://wordpress.org/plugin/auto-delete-post
    57 * Description:       This plugin automatically deletes a post after a certain time
    6  * Version:           1.1.3
     8 * Version:           1.1.4
    79 * Requires at least: 5.2
     10 * Tested up to:      6.6.1
    811 * Requires PHP:      7.2
    912 * Author:            Shahadat Hossain
    10  * Author URI:        https://www.linkedin.com/in/palash-dev/
     13 * Author URI:        https://www.linkedin.com/in/palash-wp/
    1114 * License:           GPL v2 or later
    1215 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
     
    1518 */
    1619
     20if ( ! defined( 'ABSPATH' ) ) exit; // EXIT IF ACCESSED DIRECTLY
     21
    1722/**
    1823 * All constants
    1924 */
    2025// Constants for version
    21 $adp_version = '1.1.2';
     26$adp_version = '1.1.4';
    2227define( 'ADP_VERSION', $adp_version );
    2328
    2429// Constants for css file path
    25 define( 'ADP_CSS', plugin_dir_url( __FILE__ ) . 'assets/css' );
     30define( 'ADP_CSS', plugin_dir_url( __FILE__ ) . 'assets/css/' );
     31define( 'ADP_JS', plugin_dir_url( __FILE__ ) . 'assets/js/' );
    2632
    27 /**
    28  * All script file inclusion
    29  */
    30 function adp_all_scripts_inclusion() {
    31     wp_enqueue_style( 'style', ADP_CSS . '/style.css', [], ADP_VERSION, 'all' );
    32 }
    33 add_action( 'admin_enqueue_scripts', 'adp_all_scripts_inclusion' );
     33// Include necessary files
     34require_once plugin_dir_path( __FILE__ ) . 'includes/class-auto-delete-option-selection.php';
     35require_once plugin_dir_path( __FILE__ ) . 'includes/class-auto-delete-post.php';
     36require_once plugin_dir_path( __FILE__ ) . 'includes/class-custom-post-column.php';
     37require_once plugin_dir_path( __FILE__ ) . 'includes/class-delete-post-meta-on-restore.php';
     38require_once plugin_dir_path( __FILE__ ) . 'includes/class-quick-edit-option.php';
     39require_once plugin_dir_path( __FILE__ ) . 'assetsManager/assets-manager.php';
     40
     41// Initialize classes
     42new ADP_Auto_Delete_Option_Selection();
     43new ADP_Auto_Delete_Post();
     44new ADP_Custom_Post_Column();
     45new Delete_Post_Meta_On_Post_Restore();
     46new Assets_Manager();
     47new ADP_Quick_Edit();
    3448
    3549/**
     
    4155
    4256    if ( ! class_exists( 'Appsero\Client' ) ) {
    43       require_once __DIR__ . '/appsero/src/Client.php';
     57        require_once __DIR__ . '/appsero/src/Client.php';
    4458    }
    4559
     
    5064
    5165}
    52 
    5366appsero_init_tracker_auto_delete_post();
    54 
    55 
    56 /**
    57  * Creating options of all post type to choose from, where this functionality will be available
    58  */
    59 class ADP_Auto_Delete_Option_Selection {
    60     public function __construct() {
    61         add_action( 'admin_menu', [ $this, 'adding_menu_page_for_all_types' ] );
    62     }
    63 
    64     function adding_menu_page_for_all_types() {
    65         // Adding a menu page with list of custom post types which will be selected for any purpose for (auto delete posts plugin)
    66         add_menu_page(
    67             esc_html__( 'Auto Delete Posts', 'auto-delete-post' ), // title to show in the page tab section
    68             esc_html__( 'Auto Delete Posts', 'auto-delete-post' ), // title to show in the page menu bar
    69             'manage_options', // capability
    70             'adp-post-list', // slug of the page
    71             'adp_posts_list_callback', // callback function
    72             'dashicons-table-col-delete', // icon to show on menu bar
    73             2 // location of the menu in the dashboard where it should be displayed
    74         );
    75 
    76         // duplicating the menu page with 'add_submenu_page' function to display a different title other than the page title used in the 'add_menu_page' function
    77         add_submenu_page(
    78             'adp-post-list', // menu slug
    79             esc_html__( 'All Post Type List', 'auto-delete-post' ), // title to show in the page
    80             esc_html__( 'All Post Type List', 'auto-delete-post' ), // title to show in the submenu page
    81             'manage_options', // capability of the user
    82             'adp-post-list' // mneu slug
    83         );
    84 
    85         // we will have to reuse the 'add_submenu_page' function to show the first submenu under the menu page
    86         add_submenu_page(
    87             'adp-post-list', // menu slug
    88             null, // title to show in the page, but in this case we don't want a second submenu. Therefor we 'nullified' it, thus it will not show any title
    89             null, // title to show in the menu, but in this case we don't want a second submenu. Therefor we 'nullified' it, thus it will not show any title
    90             'manage_options',  // capability
    91             'adp-post-list' // menu slug, in this case it is not doing. We are just using it for the sake of function parameters validity
    92         );
    93 
    94         function adp_posts_list_callback() {
    95             ?>
    96             <div class="wrap">
    97                 <h1><?php esc_html_e( 'Choose from the options, where you want to add this functionality.', 'auto-delete-post' ); ?></h1>
    98                 <ul>
    99                     <?php
    100                     if( isset( $_POST['submit'] )   ) {
    101                         if( empty( $_POST['adp-posts-type-lists'] ) ) {
    102                             $post_types_meta_values = '';
    103                             update_option( 'auto_delete_post_option', $post_types_meta_values );
    104                             echo '<div class="notice notice-success is-dismissible"><p>';
    105                             esc_html_e( 'Saved successfully!', 'auto-delete-post' );
    106                             echo '</p></div>'; // showing the success message after form submission.
    107                         }
    108                         else {
    109                             $post_types_meta_values = $_POST['adp-posts-type-lists'];
    110                             update_option( 'auto_delete_post_option', $post_types_meta_values );   
    111                             echo '<div class="notice notice-success is-dismissible"><p>';
    112                             esc_html_e( 'Saved successfully!', 'auto-delete-post' );
    113                             echo '</p></div>'; // showing the success message after form submission.
    114                         }                       
    115                     }
    116                     $opt_result = get_option( 'auto_delete_post_option' );
    117 
    118                     $post_types_args = [ 'public' => true ];
    119                     $post_types = get_post_types( $post_types_args ); // getting all the post types of WP
    120                        
    121                     unset( $post_types['attachment'] ); // unsettings the builtin post type attachment from the post types list
    122                     ?>
    123                     <form action="<?php esc_url( admin_url( 'options.php' ) ); ?>" method="post">
    124                     <?php                   
    125                     foreach( $post_types as $post_type) {                         
    126                     ?>
    127                     <li>
    128                         <input type="checkbox" name="adp-posts-type-lists[]" id="<?php echo esc_attr( $post_type ); ?>" value="<?php echo esc_attr__( $post_type, 'auto-delete-post' ); ?>"
    129                         <?php
    130                         if( !empty( $opt_result ) ) {
    131                             if( in_array( $post_type, $opt_result ) ){ echo esc_attr( 'checked' ); }
    132                         }
    133                         ?>>
    134                         <label for="<?php echo esc_attr( $post_type ); ?>">
    135                         <?php echo esc_html__( $post_type, 'auto-delete-post' ); ?>
    136                         </label>
    137                     </li>
    138                     <?php
    139                     }
    140                     ?>
    141                     <?php
    142                     submit_button( esc_html__( 'Save', 'auto-delete-post' ), 'primary' ); 
    143                     ?>
    144                     </form>
    145                     <?php
    146                     ?>
    147                 </ul>
    148             </div>
    149             <?php
    150         }
    151     }
    152 }
    153 
    154 $adp_all_selected_post_types_obj = new ADP_Auto_Delete_Option_Selection();
    155 
    156 
    157 /**
    158  * Custom meta box to auto delete a post
    159  */
    160 class ADP_Auto_Delete_Post {
    161     public $post_opt_result;
    162    
    163     public function __construct() {
    164         $this->post_opt_result = get_option( 'auto_delete_post_option' ); // getting the result of all selected post type
    165         add_action( 'add_meta_boxes', [ $this, 'adp_create_auto_delete_post_meta_box' ] );
    166         add_action( 'save_post', [ $this, 'adp_save_auto_delete_post_meta_box' ] );
    167         add_action( 'init', [ $this, 'delete' ] );
    168     }
    169 
    170     // creating custom meta box
    171     public function adp_create_auto_delete_post_meta_box() {
    172         add_meta_box(
    173             'meta_box_for_auto_post_delete', // meta box id
    174             '<p class="adp-meta-box-title">Delete Post Automatically: </p>',
    175             [ $this, 'adp_html_output_for_auto_delete_meta_box' ], // callback function name for html output
    176             $this->post_opt_result
    177         );
    178     }
    179 
    180     // callback function called in the add_meta_box function
    181     public function adp_html_output_for_auto_delete_meta_box( $post ) {
    182             if( ! empty( $_GET['post'] ) ) {
    183                 $current_post_id = sanitize_text_field( $_GET['post'] );
    184                 $meta_date_time_value = get_post_meta( $current_post_id, 'auto_delete_post_time_key', true );
    185             }
    186         ?>
    187             <label for="adp-time"><?php echo esc_html__( 'Select Time', 'auto-delete-post' ); ?></label>
    188             <input class="adp-input" type="datetime-local" name="adp-time" id="adp-time" value="<?php if( !empty( $meta_date_time_value ) ) { echo esc_attr( $meta_date_time_value ); } ?>" />
    189         <?php
    190     }
    191 
    192     // function for saving the value of auto delete meta box value
    193     public function adp_save_auto_delete_post_meta_box( $post_id ) {
    194         if( ! empty( $_POST['adp-time'] ) ) {
    195             $post_time = sanitize_text_field( $_POST['adp-time'] );
    196             update_post_meta( $post_id, 'auto_delete_post_time_key', $post_time );
    197         }
    198     }
    199 
    200     // auto post deletion mechanism
    201     public function delete() {
    202         $adp_custom_query = new WP_Query( array(
    203             'post_type' => $this->post_opt_result,
    204             'posts_per_page' => -1,
    205         ));
    206         if( $adp_custom_query->have_posts() ) {
    207             while( $adp_custom_query->have_posts() ) {
    208                 $adp_custom_query->the_post();
    209                
    210                 $unique_post_id = get_the_ID();
    211                 $final_meta_value = get_post_meta( $unique_post_id, 'auto_delete_post_time_key', true );
    212                 $converted_user_date_time = strtotime( $final_meta_value );
    213                 $converted_in_date_format = date('Y-m-d H:i', $converted_user_date_time).' ';
    214                 $final_user_date_time = strtotime( $converted_in_date_format );
    215                 $current_server_time = current_time('timestamp');
    216                 if( $current_server_time >= $final_user_date_time && $final_user_date_time > 0 ) {
    217                         wp_delete_post( $unique_post_id );
    218                 }
    219             }
    220         }
    221        
    222         wp_reset_postdata();
    223     }
    224 }
    225 
    226 $adp_obj = new ADP_Auto_Delete_Post(); // class initialization
    227 
    228 // Class for creating a custom column on posts list showing the deletion time
    229 class ADP_Custom_Post_Column {
    230     public $counter;
    231 
    232     public function __construct() {
    233         add_filter( 'manage_posts_columns', [ $this, 'custom_post_delete_column' ] ); // filter hook to add a new column on the posts list
    234 
    235         add_action( 'manage_posts_custom_column', [ $this, 'custom_post_delete_column_content' ], 10, 2 ); // action hook to add content in our new custom column on the posts list
    236     }
    237 
    238     // callback of custom column
    239     public function custom_post_delete_column( $column ) {
    240         $column['adp_post_deletion_time_column'] = 'Auto Deletion Time';
    241         return $column;
    242     }
    243 
    244     // callback of custom column content
    245     public function custom_post_delete_column_content( $column_name, $post_id ) {
    246         $this->counter = get_post_meta( $post_id, 'auto_delete_post_time_key', true );
    247         $converted_user_date_time = strtotime( $this->counter );
    248 
    249         if ( empty( $converted_user_date_time ) ) {
    250             $converted_in_date_format = 'Time not set';
    251         } else {
    252             $converted_in_date_format = date( 'Y-m-d h:i A', $converted_user_date_time ) . ' ';
    253         }   
    254 
    255         // $final_user_date_time = strtotime( $converted_in_date_format );
    256         if ( 'adp_post_deletion_time_column' == $column_name ) {
    257             // Display the deletion time
    258             printf( esc_html__( '%s', 'auto-delete-post' ), esc_html( $converted_in_date_format ) );
    259         }
    260     }
    261 }
    262 
    263 $adp_custom_post_columb_obj = new ADP_Custom_Post_Column(); // class initialization
    264 
    265 class Delete_Post_Meta_On_Post_Restore {
    266     public function __construct() {
    267         add_action( 'untrashed_post', [ $this, 'delete_auto_delte_post_meta' ] );
    268     }
    269 
    270     // Deleting post meta on clicking restore for every post
    271     public function delete_auto_delte_post_meta( $post_id ) {
    272         // Specifying the meta key
    273         $meta_key_to_delete = 'auto_delete_post_time_key';
    274 
    275         // Delete the post meta
    276         delete_post_meta( $post_id, $meta_key_to_delete );
    277     }
    278 }
    279 
    280 $adp_delete_post_meta_on_restore = new Delete_Post_Meta_On_Post_Restore(); // class initialization
    281 
    282 
    283 
  • auto-delete-post/trunk/readme.txt

    r3041524 r3132899  
    55Requires PHP: 7.2
    66Requires at least: 5.2
    7 Tested up to: 6.4.3
    8 Version: 1.1.3
    9 Stable tag: 1.1.3
     7Tested up to: 6.6.1
     8Version: 1.1.4
     9Stable tag: 1.1.4
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    35351. Set the default time zone from the WordPress settings option to work correctly according to your timezone
    36362. Select a time and date from the custom meta box field of this plugin
    37 3. Select any main pages of WordPress from the checkbox options in the menu page where you want to add this functionality
     373. You can also select the time from the quick edit option, no need to go to the edit section of any post.
     384. Select any main pages of WordPress from the checkbox options in the menu page where you want to add this functionality
    3839
    3940== Changelog ==
     41= 1.1.4 =
     42Added date time field in the quick edit section of post
    4043
    4144= 1.1.3 =
     
    4447== Upgrade Notice ==
    4548
    46 = 1.1.3 =
     49= 1.1.4 =
    4750There is a upgrade available.
Note: See TracChangeset for help on using the changeset viewer.