I made a lot of changes to my WP settings and now, when I approve and publish pending posts, authors have one hour to modify their articles. After the hour has gone the edit link disappear and they can't change anymore. I need to give them the opportunity to remove the post but the "trash" link has gone either. I've been thinking about adding a new text link under the post title to let the authors send me a message asking to delete the post. The text link should have the name of the post as subject in order to understand wich post need to be removed. Is this possible? Thanks
-
Add a link under the post title in backend, in single edit view or table list of posts or in frontend under the post title?– bueltgeMar 6, 2013 at 11:25
-
I meant that I need this code in the backend, in the page with the list of posts under the title of each post, nexxt to the "View" link...– user27309Mar 6, 2013 at 15:45
1 Answer
You can enhance, change the strings to each post title in the table view of backend on post via hook:
add_filter( 'post_row_actions', array( $this, 'add_archive_link' ), 10, 2 );
See the result in this screenshot:
Below you find my method to add a link
/**
* Add link on archive
*
* @uses get_post_type_object, get_archive_post_link, current_user_can, esc_attr
* @access public
* @since 0.0.1
* @param array string $actions
* @param integer $id
* @return array $actions
*/
public function add_archive_link( $actions, $id ) {
global $post, $current_screen, $mode;
$post_type_object = get_post_type_object( $post->post_type );
if ( is_array( $this->def_archive_screens ) && ! in_array( $current_screen->id, $this->def_archive_screens ) )
return $actions;
if ( ! current_user_can( $post_type_object->cap->delete_post, $post->ID ) )
return $actions;
$actions['archive'] = '<a href="' . $this->get_archive_post_link( $post->ID )
. '" title="'
. esc_attr( __( 'Move this item to the Archive', $this->textdomain ) )
. '">' . __( 'Archive', $this->textdomain ) . '</a>';
return $actions;
}
You must use the hook admin_action_{your_string}
for the callback, if the user click on the link. Also below a example for my string archive
:
add_action( 'admin_action_archive', array( $this, 'archive_post_type' ) );
Now the method for the hook:
/**
* Archive post type
*
* @uses wp_die, set_post_type, add_post_meta, wp_redirect, admin_url
* @access public
* @since 0.0.1
* @return void
*/
public function archive_post_type () {
if ( ! (
isset( $_GET['post']) ||
( isset( $_REQUEST['action']) && 'archive' == $_REQUEST['action'] )
) ) {
wp_die( __( 'No post to archive has been supplied!', $this->textdomain ) );
}
$id = (int) ( isset( $_GET['post']) ? $_GET['post'] : $_REQUEST['post']);
if ( $id ) {
$redirect_post_type = '';
$archived_post_type = get_post_type( $id );
if ( ! empty( $archived_post_type ) )
$redirect_post_type = 'post_type=' . $archived_post_type . '&';
// change post type
set_post_type( $id, $this->post_type_1 );
// add old post_type to post meta
add_post_meta( $id, $this->post_meta_key, $archived_post_type, TRUE );
wp_redirect( admin_url( 'edit.php?' . $redirect_post_type . 'archived=1&ids=' . $id ) );
exit;
} else {
wp_die( __( 'Sorry, i cant find the post-id', $this->textdomain ) );
}
}
You find a plugin, there use this on github.
-
-
-
Ok, I'll try to repost it... For every contributor (my default role for subscribers) I need to add a text link under the title of any published post in their backend. The text must be "ask for removal of title_of_the_post) and the link should open their emal account with the subject already filled (example: Mysite.com - Remove title_of_the_post). Hope I did clarify, thanks! Mar 15, 2013 at 16:25
-
Do you mean a link below the title in the list of all posts, there remove the title of the current post? Your contibutors (role) can remove the title. I don't understand the goal. What do it, if the user click this and remove the title? Can he change this or will you change the status of this current post to draft, or other status?– bueltgeMar 15, 2013 at 18:15
-
I don't want my contributors to edit their post when it's already published, I've added a function to disable editing and deleting but I still want to give them the chance to delete by clicking on a button available in the author.php page (this one is already active). The link text requested should bring to this page... Mar 18, 2013 at 22:12