Changeset 3132899
- Timestamp:
- 08/08/2024 08:40:12 PM (20 months ago)
- Location:
- auto-delete-post
- Files:
-
- 35 added
- 3 edited
-
assets/screenshot-3.png (modified) (previous)
-
assets/screenshot-4.png (added)
-
tags/1.1.4 (added)
-
tags/1.1.4/appsero (added)
-
tags/1.1.4/appsero/composer.json (added)
-
tags/1.1.4/appsero/composer.lock (added)
-
tags/1.1.4/appsero/readme.md (added)
-
tags/1.1.4/appsero/src (added)
-
tags/1.1.4/appsero/src/Client.php (added)
-
tags/1.1.4/appsero/src/Insights.php (added)
-
tags/1.1.4/appsero/src/License.php (added)
-
tags/1.1.4/assets (added)
-
tags/1.1.4/assets/css (added)
-
tags/1.1.4/assets/css/style.css (added)
-
tags/1.1.4/assets/js (added)
-
tags/1.1.4/assets/js/adp-quick-edit.js (added)
-
tags/1.1.4/assetsManager (added)
-
tags/1.1.4/assetsManager/assets-manager.php (added)
-
tags/1.1.4/auto-delete-post.php (added)
-
tags/1.1.4/includes (added)
-
tags/1.1.4/includes/class-auto-delete-option-selection.php (added)
-
tags/1.1.4/includes/class-auto-delete-post.php (added)
-
tags/1.1.4/includes/class-custom-post-column.php (added)
-
tags/1.1.4/includes/class-delete-post-meta-on-restore.php (added)
-
tags/1.1.4/includes/class-quick-edit-option.php (added)
-
tags/1.1.4/readme.txt (added)
-
trunk/assets/js (added)
-
trunk/assets/js/adp-quick-edit.js (added)
-
trunk/assetsManager (added)
-
trunk/assetsManager/assets-manager.php (added)
-
trunk/auto-delete-post.php (modified) (4 diffs)
-
trunk/includes (added)
-
trunk/includes/class-auto-delete-option-selection.php (added)
-
trunk/includes/class-auto-delete-post.php (added)
-
trunk/includes/class-custom-post-column.php (added)
-
trunk/includes/class-delete-post-meta-on-restore.php (added)
-
trunk/includes/class-quick-edit-option.php (added)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
auto-delete-post/trunk/auto-delete-post.php
r3041524 r3132899 1 <?php 1 <?php 2 2 /** 3 * @package AutoDeletePost 4 * 3 5 * Plugin Name: Auto Delete Post 4 6 * Plugin URI: https://wordpress.org/plugin/auto-delete-post 5 7 * Description: This plugin automatically deletes a post after a certain time 6 * Version: 1.1. 38 * Version: 1.1.4 7 9 * Requires at least: 5.2 10 * Tested up to: 6.6.1 8 11 * Requires PHP: 7.2 9 12 * Author: Shahadat Hossain 10 * Author URI: https://www.linkedin.com/in/palash- dev/13 * Author URI: https://www.linkedin.com/in/palash-wp/ 11 14 * License: GPL v2 or later 12 15 * License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 15 18 */ 16 19 20 if ( ! defined( 'ABSPATH' ) ) exit; // EXIT IF ACCESSED DIRECTLY 21 17 22 /** 18 23 * All constants 19 24 */ 20 25 // Constants for version 21 $adp_version = '1.1. 2';26 $adp_version = '1.1.4'; 22 27 define( 'ADP_VERSION', $adp_version ); 23 28 24 29 // Constants for css file path 25 define( 'ADP_CSS', plugin_dir_url( __FILE__ ) . 'assets/css' ); 30 define( 'ADP_CSS', plugin_dir_url( __FILE__ ) . 'assets/css/' ); 31 define( 'ADP_JS', plugin_dir_url( __FILE__ ) . 'assets/js/' ); 26 32 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 34 require_once plugin_dir_path( __FILE__ ) . 'includes/class-auto-delete-option-selection.php'; 35 require_once plugin_dir_path( __FILE__ ) . 'includes/class-auto-delete-post.php'; 36 require_once plugin_dir_path( __FILE__ ) . 'includes/class-custom-post-column.php'; 37 require_once plugin_dir_path( __FILE__ ) . 'includes/class-delete-post-meta-on-restore.php'; 38 require_once plugin_dir_path( __FILE__ ) . 'includes/class-quick-edit-option.php'; 39 require_once plugin_dir_path( __FILE__ ) . 'assetsManager/assets-manager.php'; 40 41 // Initialize classes 42 new ADP_Auto_Delete_Option_Selection(); 43 new ADP_Auto_Delete_Post(); 44 new ADP_Custom_Post_Column(); 45 new Delete_Post_Meta_On_Post_Restore(); 46 new Assets_Manager(); 47 new ADP_Quick_Edit(); 34 48 35 49 /** … … 41 55 42 56 if ( ! class_exists( 'Appsero\Client' ) ) { 43 require_once __DIR__ . '/appsero/src/Client.php';57 require_once __DIR__ . '/appsero/src/Client.php'; 44 58 } 45 59 … … 50 64 51 65 } 52 53 66 appsero_init_tracker_auto_delete_post(); 54 55 56 /**57 * Creating options of all post type to choose from, where this functionality will be available58 */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 section68 esc_html__( 'Auto Delete Posts', 'auto-delete-post' ), // title to show in the page menu bar69 'manage_options', // capability70 'adp-post-list', // slug of the page71 'adp_posts_list_callback', // callback function72 'dashicons-table-col-delete', // icon to show on menu bar73 2 // location of the menu in the dashboard where it should be displayed74 );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' function77 add_submenu_page(78 'adp-post-list', // menu slug79 esc_html__( 'All Post Type List', 'auto-delete-post' ), // title to show in the page80 esc_html__( 'All Post Type List', 'auto-delete-post' ), // title to show in the submenu page81 'manage_options', // capability of the user82 'adp-post-list' // mneu slug83 );84 85 // we will have to reuse the 'add_submenu_page' function to show the first submenu under the menu page86 add_submenu_page(87 'adp-post-list', // menu slug88 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 title89 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 title90 'manage_options', // capability91 'adp-post-list' // menu slug, in this case it is not doing. We are just using it for the sake of function parameters validity92 );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 <?php100 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 WP120 121 unset( $post_types['attachment'] ); // unsettings the builtin post type attachment from the post types list122 ?>123 <form action="<?php esc_url( admin_url( 'options.php' ) ); ?>" method="post">124 <?php125 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 <?php130 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 <?php139 }140 ?>141 <?php142 submit_button( esc_html__( 'Save', 'auto-delete-post' ), 'primary' );143 ?>144 </form>145 <?php146 ?>147 </ul>148 </div>149 <?php150 }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 post159 */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 type165 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 box171 public function adp_create_auto_delete_post_meta_box() {172 add_meta_box(173 'meta_box_for_auto_post_delete', // meta box id174 '<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 output176 $this->post_opt_result177 );178 }179 180 // callback function called in the add_meta_box function181 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 <?php190 }191 192 // function for saving the value of auto delete meta box value193 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 mechanism201 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 initialization227 228 // Class for creating a custom column on posts list showing the deletion time229 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 list234 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 list236 }237 238 // callback of custom column239 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 content245 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 time258 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 initialization264 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 post271 public function delete_auto_delte_post_meta( $post_id ) {272 // Specifying the meta key273 $meta_key_to_delete = 'auto_delete_post_time_key';274 275 // Delete the post meta276 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 initialization281 282 283 -
auto-delete-post/trunk/readme.txt
r3041524 r3132899 5 5 Requires PHP: 7.2 6 6 Requires at least: 5.2 7 Tested up to: 6. 4.38 Version: 1.1. 39 Stable tag: 1.1. 37 Tested up to: 6.6.1 8 Version: 1.1.4 9 Stable tag: 1.1.4 10 10 License: GPLv2 or later 11 11 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 35 35 1. Set the default time zone from the WordPress settings option to work correctly according to your timezone 36 36 2. 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 37 3. You can also select the time from the quick edit option, no need to go to the edit section of any post. 38 4. Select any main pages of WordPress from the checkbox options in the menu page where you want to add this functionality 38 39 39 40 == Changelog == 41 = 1.1.4 = 42 Added date time field in the quick edit section of post 40 43 41 44 = 1.1.3 = … … 44 47 == Upgrade Notice == 45 48 46 = 1.1. 3=49 = 1.1.4 = 47 50 There is a upgrade available.
Note: See TracChangeset
for help on using the changeset viewer.