Created
January 16, 2021 09:19
-
-
Save gvgvgvijayan/3c3f0d9e285f56d4e2d7c5d3955d4d5e to your computer and use it in GitHub Desktop.
This gist is used in the tutorial https://www.vijayan.in/how-to-create-custom-table-list-in-wordpress-admin-page
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 | |
... | |
/** | |
* Return title column. | |
* | |
* @param array $item Item data. | |
* @return string | |
*/ | |
public function column_title( $item ) { | |
$edit_url = get_edit_post_link( $item['id'] ); | |
$post_link = get_permalink( $item['id'] ); | |
$delete_link = get_delete_post_link( $item['id'] ); | |
$output = '<strong>'; | |
/* translators: %s: Post Title */ | |
$output .= '<a class="row-title" href="' . esc_url( $edit_url ) . '" aria-label="' . sprintf( __( '%s (Edit)', 'admin-table-tut' ), $item['title'] ) . '">' . esc_html( $item['title'] ) . '</a>'; | |
$output .= _post_states( get_post( $item['id'] ), false ); | |
$output .= '</strong>'; | |
// Get actions. | |
$actions = array( | |
'edit' => '<a href="' . esc_url( $edit_url ) . '">' . __( 'Edit', 'admin-table-tut' ) . '</a>', | |
'trash' => '<a href="' . esc_url( $delete_link ) . '" class="submitdelete">' . __( 'Trash', 'admin-table-tut' ) . '</a>', | |
'view' => '<a href="' . esc_url( $post_link ) . '">' . __( 'View', 'admin-table-tut' ) . '</a>', | |
); | |
$row_actions = array(); | |
foreach ( $actions as $action => $link ) { | |
$row_actions[] = '<span class="' . esc_attr( $action ) . '">' . $link . '</span>'; | |
} | |
$output .= '<div class="row-actions">' . implode( ' | ', $row_actions ) . '</div>'; | |
return $output; | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment