Hi
I’ve been trying to do this, and have got this far:
<?php
/*
Plugin Name: AAA test plugin
Plugin URI:
Description:
Version:
Author:
Author URI:
License:
License URI:
*/
/**
* Add Delete Link to Display Posts Shortcode plugin
* @author
*
* @param $output string, the original markup for an individual post
* @param $atts array, all the attributes passed to the shortcode
* @param $image string, the image part of the output
* @param $title string, the title part of the output
* @param $date string, the date part of the output
* @param $excerpt string, the excerpt part of the output
* @return $output string, the modified markup for an individual post
*/
add_filter( 'display_posts_shortcode_output', 'be_display_posts_delete', 10, 6 );
function be_display_posts_delete( $output, $atts, $image, $title, $date, $excerpt ) {
// Here's the delete code we'll be adding to the excerpt
$delete = '';
$url = get_bloginfo('url');
if (current_user_can('edit_post', $post->ID)){
$delete = '<a class="delete-post" href="' . wp_nonce_url("$url/wp-admin/post.php?action=trash&post=$id", 'delete-post_' . $post->ID) . '">Delete post</a>';
}
// First check if an excerpt is included by looking at the shortcode $atts
if ( $atts['include_delete'] )
// Now let's rebuild the excerpt with the facebook code at the end
$excerpt = ' - <span class="delete">' . $delete . '</span>';
else $excerpt = '';
// Now let's rebuild the output. Only the excerpt changed so we're using the original $image, $title, and $date
$output = '<li>' . $image . $title . $date . $excerpt . '</li>';
// Finally we'll return the modified output
return $output;
It now shows a delete text next to the post title. It’s messy and spaghetti code, because it is mixed it with the excerpt code. The problem is that the delete link doesn’t actually delete.
WP gives an white error box when the link is clicked, saying the link has expired.
Any clues?