Improved the API Keys table list, added actions and fixed the links

This commit is contained in:
Claudio Sanches 2015-05-18 15:33:36 -03:00
parent 2f5df9c185
commit c4d4a623b5
3 changed files with 24 additions and 36 deletions

View File

@ -39,8 +39,7 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
'cb' => '<input type="checkbox" />',
'description' => __( 'Description', 'woocommerce' ),
'user' => __( 'User', 'woocommerce' ),
'permissions' => __( 'Permissions', 'woocommerce' ),
'actions' => __( 'Actions', 'woocommerce' ),
'permissions' => __( 'Permissions', 'woocommerce' )
);
}
@ -61,14 +60,33 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
* @return string
*/
public function column_description( $key ) {
$url = admin_url( 'admin.php?page=wc-settings&tab=api&section=keys&edit-key=' . $key['key_id'] );
$output = '<strong>';
$output .= '<a href="' . esc_url( $url ) . '">';
if ( empty( $key['description'] ) ) {
$output .= esc_html__( 'API Key', 'woocommerce' );
} else {
$output .= esc_html( $key['description'] );
}
$output .= '</a>';
$output .= '</strong>';
// Get actions
$actions = array(
'id' => sprintf( __( 'ID: %d', 'woocommerce' ), $key['key_id'] ),
'edit' => '<a href="' . esc_url( $url ) . '">' . __( 'View/Edit', 'woocommerce' ) . '</a>',
'trash' => '<a class="submitdelete" title="' . esc_attr__( 'Revoke API Key', 'woocommerce' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'revoke-key' => $key['key_id'] ), admin_url( 'admin.php?page=wc-settings&tab=api&section=keys' ) ), 'revoke' ) ) . '">' . __( 'Revoke', 'woocommerce' ) . '</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;
}
@ -115,36 +133,6 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
}
}
/**
* Return actions column
*
* @param array $key
* @return string
*/
public function column_actions( $key ) {
$actions = array();
$actions['revoke'] = array(
'url' => wp_nonce_url( add_query_arg( 'revoke', $key['key_id'] ), 'revoke' ),
'name' => __( 'Revoke API Key', 'woocommerce' ),
'action' => 'revoke'
);
$actions['edit'] = array(
'url' => admin_url( 'admin.php?page=wc-settings&tab=api&section=keys&edit-key=' . $key['key_id'] ),
'name' => __( 'View/Edit', 'woocommerce' ),
'action' => 'edit'
);
$output = '';
foreach ( $actions as $action ) {
$output .= sprintf( '<a class="button tips %1$s" href="%2$s" data-tip="%3$s">%3$s</a>', esc_attr( $action['action'] ), esc_url( $action['url'] ), esc_attr( $action['name'] ) );
}
return $output;
}
/**
* Get bulk actions
*

View File

@ -86,7 +86,7 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table {
if ( 'trash' == $post_status ) {
$output .= esc_html( $title );
} else {
$output .= '<a href="' . esc_attr( $edit_link ) . '">' . esc_html( $title ) . '</a>';
$output .= '<a href="' . esc_url( $edit_link ) . '">' . esc_html( $title ) . '</a>';
}
$output .= '</strong>';
@ -96,12 +96,12 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table {
);
if ( current_user_can( $post_type_object->cap->edit_post, $the_webhook->id ) && 'trash' !== $post_status ) {
$actions['edit'] = '<a href="' . esc_attr( $edit_link ) . '">' . __( 'Edit', 'woocommerce' ) . '</a>';
$actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'woocommerce' ) . '</a>';
}
if ( current_user_can( $post_type_object->cap->delete_post, $the_webhook->id ) ) {
if ( 'trash' == $post_status ) {
$actions['untrash'] = '<a title="' . esc_attr( __( 'Restore this item from the Trash', 'woocommerce' ) ) . '" href="' . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $the_webhook->id ) ), 'untrash-post_' . $the_webhook->id ) . '">' . __( 'Restore', 'woocommerce' ) . '</a>';
$actions['untrash'] = '<a title="' . esc_attr__( 'Restore this item from the Trash', 'woocommerce' ) . '" href="' . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $the_webhook->id ) ), 'untrash-post_' . $the_webhook->id ) . '">' . __( 'Restore', 'woocommerce' ) . '</a>';
} elseif ( EMPTY_TRASH_DAYS ) {
$actions['trash'] = '<a class="submitdelete" title="' . esc_attr( __( 'Move this item to the Trash', 'woocommerce' ) ) . '" href="' . get_delete_post_link( $the_webhook->id ) . '">' . __( 'Trash', 'woocommerce' ) . '</a>';
}

View File

@ -119,7 +119,7 @@ if ( ! defined( 'ABSPATH' ) ) {
?>
<p class="submit">
<?php submit_button( __( 'Save Changes', 'woocommerce' ), 'primary', 'update_api_key', false ); ?>
<a style="color: #a00; text-decoration: none; margin-left: 10px;" href="<?php echo esc_url( add_query_arg( array( 'revoke-key' => $key_id ), admin_url( 'admin.php?page=wc-settings&tab=api&section=keys' ) ) ); ?>"><?php _e( 'Revoke Key', 'woocommerce' ); ?></a>
<a style="color: #a00; text-decoration: none; margin-left: 10px;" href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'revoke-key' => $key_id ), admin_url( 'admin.php?page=wc-settings&tab=api&section=keys' ) ), 'revoke' ) ); ?>"><?php _e( 'Revoke Key', 'woocommerce' ); ?></a>
</p>
<?php
}