-
-
Save billerickson/4db5125401af9143c843debeae27e765 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add Delete Link to Display Posts Shortcode plugin | |
* @see https://displayposts.com/2019/01/19/add-delete-post-link-if-user-has-permission-to-edit-content/ | |
*/ | |
function be_dps_delete_link( $output, $atts, $image, $title, $date, $excerpt, $inner_wrapper, $content, $class, $author, $category_display_text ) { | |
if( empty( $atts['include_delete'] ) || true !== filter_var( $atts['include_delete'], FILTER_VALIDATE_BOOLEAN ) ) | |
return $output; | |
if( ! current_user_can( 'edit_post', get_the_ID() ) ) | |
return $output; | |
$delete_button = ' <a class="delete-post" href="' . get_delete_post_link( get_the_ID() ) . '">Delete</a>'; | |
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $author . $category_display_text . $excerpt . $content . $delete_button . '</' . $inner_wrapper . '>'; | |
return $output; | |
} | |
add_filter( 'display_posts_shortcode_output', 'be_dps_delete_link', 10, 11 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment