Zurück   WordPress Deutschland Forum > Support > Plugins und Widgets

Antwort
 
Themen-Optionen Ansicht
Alt 27.11.2005, 16:24   #1 (permalink)
PostRank: 6
 
Registriert seit: 27.12.2004
Beiträge: 657
auto delete posts

Hallo,
ich möchte dieses http://ashwinbihari.com/archives/200...-delete-posts/
plugin benutzen
Code:
<?php
/*
Plugin Name: Auto Delete Posts
Plugin URI: http://ashwinbihari.com/plugins
Description: Auto delete or move posts after a pre-determined time.
Author: Ashwin Bihari
Author URI: http://ashwinbihari.com
Version: 0.3
*/ 

/* Main program */
add_action('admin_menu', 'wpadp_menu');

global $wp_filter;

/* Look for immediate action hooks and perform the actions */
if (isset($_POST['performdelete'])) {
    wpadp_check_and_delete_posts();
} 
if (isset($_POST['performmove'])) {
    wpadp_check_and_move_posts();
}

/* If deletion enabled, add the appropriate action hooks */if (($adp = get_option('wpadp_options')) && ('1' == $adp['wpadp_enable'])) {
  add_action('edit_post', 'wpadp_check_and_delete_posts');
  add_action('publish_post', 'wpadp_check_and_delete_posts');
}
else if (($adp = get_option('wpadp_options')) && ('2' == $adp['wpadp_enable'])) {
  add_action('edit_post', 'wpadp_check_and_move_posts');
  add_action('publish_post', 'wpadp_check_and_move_posts');
}

/* Add menu page */
function wpadp_menu()
{
  add_options_page('Auto Delete Posts Options', 'Auto Delete Posts', 9, 
           basename(__FILE__), 'wpadp_manage');
}


/* Load defaults or update it */
function wpadp_defaults($action = '', $enable = '0', $expire = '14') 
{
  if ((FALSE == get_option('wpadp_options'))) {
    $adp_options = array('wpadp_enable' => $enable,
             'wpadp_expire' => $expire);
    update_option('wpadp_options', $adp_options);
  } elseif ('update' == $action) {
    $adp_options = array('wpadp_enable' => $enable,
             'wpadp_expire' => $expire);
    update_option('wpadp_options', $adp_options);
  }
}

/* Load Move defaults or update it */
function wpadp_move_defaults($action = '', $category = '')
{
  if ((FALSE == get_option('wpadp_move_options'))) { 
    $adp_move_options = array('wpadp_category' => $category);
    update_option('wpadp_move_options', $adp_move_options);
  } elseif ('update' == $action) {
    $adp_move_options = array('wpadp_category' => $category);
    update_option('wpadp_move_options', $adp_move_options);
  }    
}

/* Manage options in admin menu */
function wpadp_manage()
{
  global $wpdb;
  
  if (isset($_POST['wpadp_options']) && ('update' == $_POST['wpadp_options'])) {
    wpadp_defaults('update', $_POST['enable'], $_POST['expire']);
  }
  else if (isset($_POST['wpadp_move_options']) && ('update' == $_POST['wpadp_move_options'])) {
    wpadp_move_defaults('update', $_POST['category']);
  }
  
  // Load defaults
  wpadp_defaults();
  wpadp_move_defaults();
  
  // Grab the options
  $adp_options = get_option('wpadp_options');
  $adp_move_options = get_option('wpadp_move_options');

  echo "<div class='wrap'>";
  echo "<h2>Auto Delete Posts Options</h2>\r\n";
  echo "<fieldset class='options'>";
  echo "<table width='100%' cellspacing='2' cellpadding='5' class='editform'><tr>";
  echo "<form method='POST'>";
  echo "<input type='hidden' name='wpadp_options' value='update'>";
  echo "<td>Plugin Action? ";
  echo "<input type='radio' name='enable' value='1'";
  if ('1' == $adp_options['wpadp_enable']) {
    echo " checked='checked'";
  }
  echo ">Delete &nbsp;<input type='radio' name='enable' value='2'";
  if ('2' == $adp_options['wpadp_enable']) {
    echo " checked='checked'";
  }
  echo "> Move &nbsp;<input type='radio' name='enable' value='0'";
  if ('0' == $adp_options['wpadp_enable']) {
    echo " checked='checked'";
  }
  echo "> Preview</td></tr><tr>";
  echo "<td>How long (in days) to keep posts: <input type='text' size='10' name='expire' value='" . $adp_options['wpadp_expire'] . "' /></td>";
  echo "<tr'><td align='right' colspan='2'><input type='submit' name='submit' value='Update Options'></td>\r\n";
  echo "</td></tr>\r\n</table></form></fieldset>\r\n";
  echo "<div style='clear: both;'>&nbsp;</div>";

  /* Choose which category to move posts to */
  if ('2' == $adp_options['wpadp_enable']) {
    echo "<h2>Post Move Options</h2>\r\n";
    $query = "SELECT cat_name,cat_ID FROM $wpdb->categories ORDER BY cat_name ASC";
    $cats = $wpdb->get_results($query);
    if (!$cats) {
      echo "<p align='center'><strong>No Categories Found</strong></p>";
      die;
    }
    echo "<fieldset class='move_options'>";
    echo '<table width="100%" cellpadding="3" cellspacing="3" style="text-align: left; vertical-align: top;">';
    echo '<tr class="alternate"><th width="75%">Category</th><th width="25%">Destination</th></tr>';
    echo "<form method='POST'>";
    echo "<input type='hidden' name='wpadp_move_options' value='update'>";
    foreach ($cats as $cat) {
      if (('' == $cat->cat_ID) || ('' == $cat->cat_name)) { continue; }
      echo "<tr>";
      echo "<td>$cat->cat_name</td>";
      echo "<td><input type='radio' name='category' value='$cat->cat_ID'";
      if ($cat->cat_ID == $adp_move_options['wpadp_category']) {
    echo " checked='checked'";
      }
      echo "></td>";
      echo "</tr>";
    }
    echo "<tr'><td align='right' colspan='2'><input type='submit' name='submit' value='Update Options'></td></tr>";
    echo "</table></form></fieldset>";
  }
  /* Preview what posts would be deleted. */
  else if ('0' == $adp_options['wpadp_enable']) {
    echo "<h2>Preview Of Post Deletion/Move</h2>\r\n";
    $expiration  = $adp_options['wpadp_expire'];
    $query = "SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_date < NOW() - INTERVAL " . $expiration . " DAY ORDER BY ID ASC";
    $ids = $wpdb->get_results($query);
    if (!$ids) { 
      echo "<p align='center'><strong>No Posts Found</strong></p>";
      die;
    }
    echo '<table width="100%" cellpadding="3" cellspacing="3" style="text-align: left; vertical-align: top;">';
    echo '<tr class="alternate"><th width="25%">Post ID</th><th width="25%">Post Title</th><th width="25%">Post Category</th><th width="25%">No. of Comments</th></tr>';
    foreach ($ids as $id) {
      if ('' == $id->ID) { continue; }
      $query = "SELECT DISTINCT post_title FROM $wpdb->posts WHERE ID=". $id->ID;
      $title = $wpdb->get_var($query);
      $commentCount = get_comments_number($id->ID);
      $catnames = get_the_category($id->ID);
      echo "<tr>";
      echo "<td>$id->ID</td> <td>$title</td>";
      echo "<td>";
      $count = 0;
      foreach ($catnames as $catname) {
    if ($count > 0) {
      echo ", ";
    }
    echo "$catname->cat_name";
    $count++;
      }
      echo "</td>";
      if ($commentCount) {
    echo "<td>$commentCount</td>\r\n";
      } else {
    echo "<td></td>\r\n";
      }
      echo "</tr>";
    }
    echo "<tr>\r\n";
    echo "<td>\r\n";
    
    $adp_move_options = get_option('wpadp_move_options');
    $adp_categoryid = $adp_move_options['wpadp_category'];
    $adp_category = get_the_category_by_ID($adp_categoryid);
    
    echo "<form method=\"post\" />\r\n";
    echo "<input name=\"performdelete\" class=\"button\" type=\"submit\" id=\"performdelete\" tabindex=\"10\" value=\"Delete These Posts Now!\" onclick=\"return confirm('You are about to delete all these posts  \'Cancel\' to stop, \'OK\' to delete.') \" />\r\n";
    if (!("" == $adp_category)) {
        echo "<input name=\"performmove\" class=\"button\" type=\"submit\" id=\"performmove\" tabindex=\"10\" value=\"Move These Posts to '".$adp_category."' Now!\" onclick=\"return confirm('You are about to move all these posts  \'Cancel\' to stop, \'OK\' to move.') \" />\r\n";
    }
    echo "</form>\r\n";
    echo "</td>\r\n";
    echo "</tr>\r\n";
    echo '</table>';
  }


  echo "</div>";
}

/* Check posts that need to be deleted. */
function wpadp_check_and_delete_posts()
{
  global $wpdb;
  
  $adp_options = get_option('wpadp_options');

  $expiration = $adp_options['wpadp_expire'];
  
  /* 
   * Create a query that will give us all the post ID's that predate the 
   * interval we are given, that is, NOW - expiration date.
   */
  $query = "SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_date < NOW() - INTERVAL " . $expiration . " DAY";
  
  $ids = $wpdb->get_results($query);
  foreach ($ids as $id) {
    if ('' == $id->ID) { continue; }
    wp_delete_post($id->ID);
  }
}

/* Check posts that need to be moved. */
function wpadp_check_and_move_posts()
{
  global $wpdb;
  $adp_options = get_option('wpadp_options');
  $adp_move_options = get_option('wpadp_move_options');
  $expiration = $adp_options['wpadp_expire'];
  $category = array($adp_move_options['wpadp_category']);
  
  /*
   * Create a query that will give us all the post ID's that predate the
   * interval we are given, that is, NOW - expiration date.
   */
  $query = "SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_date < NOW() - INTERVAL " . $expiration . " DAY";
  $ids = $wpdb->get_results($query);
  foreach ($ids as $id) {
    if ('' == $id->ID) { continue; }
    wp_set_post_cats('', $id->ID, $category);
  }

}
?>
ich möchte dieses plugin aber so einsetzen, dass nur die Beiträge aus einer ganz bestimmten Kategorie - sagen wir mal zum Beispiel der Kategorie ID=2 - gelöscht werden.

Hier gibt es doch sicher jemanden, der mir helfen kann, den code entsprechend anzupassen.
Wäre wirklich cool.
__________________
tschüß nepf
nepf ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist aus.
HTML-Code ist aus.
Trackbacks are aus
Pingbacks are aus
Refbacks are aus


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:52 Uhr.


Powered by vBulletin® Version 3.7.4 (Deutsch)
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 | Impressum | Ein Inpsyde.com Projekt