Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. // do something every month
  2. global $wpdb;
  3. $evil_author = THE_ID_OF_THE_AUTHOR_WHOSE_POSTS_YOU_WANNA_BUZZIATE;
  4. $them_posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE AND post_author = $evil_author" AND post_type = "my_post_type"); // Replace my_post_type by the post type you want
  5.  
  6. foreach ( $them_posts as $post_die )
  7. {
  8. wp_delete_post( $post_die->ID, true ); // Bypasses Trash and deletes all the posts
  9. }
  10.  
  11. <?php
  12. /*
  13. Plugin Name:My Custom Plugin
  14. Description:My Custom Plugin
  15. Version:1.0
  16. */
  17.  
  18. register_activation_hook(__FILE__, 'my_activation');
  19.  
  20. function my_activation() {
  21. if (! wp_next_scheduled ( 'my_monthly_event' )) {
  22. wp_schedule_event(time(), 'monthly', 'my_monthly_event');
  23. }
  24. }
  25.  
  26. add_action('my_monthly_event', 'do_this_monthly');
  27.  
  28. function do_this_monthly() {
  29. // do something every month
  30. global $wpdb;
  31. $evil_author = THE_ID_OF_THE_AUTHOR_WHOSE_POSTS_YOU_WANNA_BUZZIATE;
  32. $them_posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE AND post_author = $evil_author" AND post_type = "my_post_type"); // Replace my_post_type by the post type you want
  33.  
  34. foreach ( $them_posts as $post_die )
  35. {
  36. wp_delete_post( $post_die->ID, true ); // Bypasses Trash and deletes all the posts
  37. }
  38. }
  39.  
  40.  
  41. // cleaning the scheduler on deactivation:
  42.  
  43. register_deactivation_hook(__FILE__, 'my_deactivation');
  44.  
  45. function my_deactivation() {
  46. wp_clear_scheduled_hook('my_monthly_event');
  47. }
  48.  
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement