您可以通过钩子增强、更改post后端表视图中每个帖子标题的字符串:
add_filter( \'post_row_actions\', array( $this, \'add_archive_link\' ), 10, 2 );
请参见此屏幕截图中的结果:
下面是我添加链接的方法
/**
* 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;
}
你必须用钩子
admin_action_{your_string}
对于回调,如果用户单击链接。下面还有我的字符串示例
archive
:
add_action( \'admin_action_archive\', array( $this, \'archive_post_type\' ) );
现在,钩子的方法是:
/**
* 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 ) );
}
}
你找到一个插件,在上面使用这个
github.