post_row_actions
最后更新于:2021-11-27 17:17:25
apply_filters( ‘post_row_actions’, string[] $actions, GC_Post $post )
Filters the array of row action links on the Posts list table.
参数
- $actions
-
(string[])
An array of row action links. Defaults are ‘Edit’, ‘Quick Edit’, ‘Restore’, ‘Trash’, ‘Delete Permanently’, ‘Preview’, and ‘View’. - $post
-
(GC_Post)
The post object.
源文件
文件: gc-admin/includes/class-gc-posts-list-table.php
add_filter( 'post_row_actions', 'modify_list_row_actions', 10, 2 ); function modify_list_row_actions( $actions, $post ) { // Check for your post type. if ( $post->post_type == "my_custom_post_type" ) { // Build your links URL. $url = admin_url( 'admin.php?page=mycpt_page&post=' . $post->ID ); // Maybe put in some extra arguments based on the post status. $edit_link = add_query_arg( array( 'action' => 'edit' ), $url ); // The default $actions passed has the Edit, Quick-edit and Trash links. $trash = $actions['trash']; /* * You can reset the default $actions with your own array, or simply merge them * here I want to rewrite my Edit link, remove the Quick-link, and introduce a * new link 'Copy' */ $actions = array( 'edit' => sprintf( '<a href="https://docs.gechiui.com/hooks/post_row_actions/%1$s">%2$s</a>', esc_url( $edit_link ), esc_html( __( 'Edit', 'contact-form-7' ) ) ) ); // You can check if the current user has some custom rights. if ( current_user_can( 'edit_my_cpt', $post->ID ) ) { // Include a nonce in this link $copy_link = gc_nonce_url( add_query_arg( array( 'action' => 'copy' ), $url ), 'edit_my_cpt_nonce' ); // Add the new Copy quick link. $actions = array_merge( $actions, array( 'copy' => sprintf( '<a href="https://docs.gechiui.com/hooks/post_row_actions/%1$s">%2$s</a>', esc_url( $copy_link ), 'Duplicate' ) ) ); // Re-insert thrash link preserved from the default $actions. $actions['trash']=$trash; } } return $actions; }