Modify list row action
-
I’d like to add a link in my post table. It is very similar to the edit link (under the post title), I just need to link an anchor to the post editor page. Name of the link: “Prezzi”
I have found the code in internet but at the moment I only set the post type. The target address is https://test.sacconicase.com/wp-admin/post.php?post=9120&action=edit#prezzo_settimana , the post ID of course vary, in the post table each link gets the anchor for the corrispondent post ID
the code:
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 == "post" ) { // Build your links URL. $url = admin_url( '/wp-admin/post.php=' . $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="%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 = wp_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="%1$s">%2$s</a>', esc_url( $copy_link ), 'Duplicate' ) ) ); // Re-insert thrash link preserved from the default $actions. $actions['trash']=$trash; } } return $actions; }
The page I need help with: [log in to see the link]
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Modify list row action’ is closed to new replies.