__( 'webhook', 'woocommerce' ),
'plural' => __( 'webhooks', 'woocommerce' ),
'ajax' => false
) );
}
/**
* Get list columns
*
* @return array
*/
public function get_columns() {
$columns = array(
'cb' => '',
'title' => __( 'Name', 'woocommerce' ),
'status' => __( 'Status', 'woocommerce' ),
'topic' => __( 'Topic', 'woocommerce' ),
'delivery_url' => __( 'Delivery URL', 'woocommerce' ),
);
return $columns;
}
/**
* Column cb.
*
* @param WC_Post $webhook
*
* @return string
*/
public function column_cb( $webhook ) {
return sprintf( '', $this->_args['singular'], $webhook->ID );
}
/**
* Webhook columns.
*
* @param WC_Post $webhook
* @param string $column_name
*
* @return string
*/
public function column_default( $webhook, $column_name ) {
global $the_webhook;
if ( empty( $the_webhook ) || $the_webhook->id != $webhook->ID ) {
$the_webhook = new WC_Webhook( $webhook->ID );
}
$output = '';
switch ( $column_name ) {
case 'title' :
$edit_link = admin_url( 'admin.php?page=wc-settings&tab=webhooks&edit-webhook=' . $the_webhook->id );
$title = _draft_or_post_title( $the_webhook->post_data );
$post_type_object = get_post_type_object( $the_webhook->post_data->post_type );
$post_status = $the_webhook->post_data->post_status;
// Title
$output = '';
if ( 'trash' == $post_status ) {
$output .= esc_html( $title );
} else {
$output .= '' . esc_html( $title ) . '';
}
$output .= '';
// Get actions
$actions = array();
$actions['id'] = sprintf( __( 'ID: %d', 'woocommerce' ), $the_webhook->id );
if ( current_user_can( $post_type_object->cap->edit_post, $the_webhook->id ) && 'trash' !== $post_status ) {
$actions['edit'] = '' . __( 'Edit', 'woocommerce' ) . '';
}
if ( current_user_can( $post_type_object->cap->delete_post, $the_webhook->id ) ) {
if ( 'trash' == $post_status ) {
$actions['untrash'] = '' . __( 'Restore', 'woocommerce' ) . '';
} elseif ( EMPTY_TRASH_DAYS ) {
$actions['trash'] = '' . __( 'Trash', 'woocommerce' ) . '';
}
if ( 'trash' == $post_status || ! EMPTY_TRASH_DAYS ) {
$actions['delete'] = '' . __( 'Delete Permanently', 'woocommerce' ) . '';
}
}
$actions = apply_filters( 'post_row_actions', $actions, $the_webhook->post_data );
$output .= '
';
$i = 0;
$action_count = sizeof( $actions );
foreach ( $actions as $action => $link ) {
++$i;
$sep = ( $i == $action_count ) ? '' : ' | ';
$output .= '' . $link . $sep . '';
}
$output .= '
';
break;
case 'status' :
$output = $the_webhook->get_i18n_status();
break;
case 'topic' :
$output = $the_webhook->get_topic();
break;
case 'delivery_url' :
$output = $the_webhook->get_delivery_url();
break;
default :
break;
}
return $output;
}
/**
* Get the status label for webhooks
*
* @param string $status_name
* @param stdClass $status
*
* @return array
*/
private function get_status_label( $status_name, $status ) {
switch ( $status_name ) {
case 'publish' :
$label = array(
'singular' => __( 'Actived (%s)', 'woocommerce' ),
'plural' => __( 'Actived (%s)', 'woocommerce' ),
'context' => '',
'domain' => 'woocommerce',
);
break;
case 'draft' :
$label = array(
'singular' => __( 'Paused (%s)', 'woocommerce' ),
'plural' => __( 'Paused (%s)', 'woocommerce' ),
'context' => '',
'domain' => 'woocommerce',
);
break;
case 'pending' :
$label = array(
'singular' => __( 'Disabled (%s)', 'woocommerce' ),
'plural' => __( 'Disabled (%s)', 'woocommerce' ),
'context' => '',
'domain' => 'woocommerce',
);
break;
default:
$label = $status->label_count;
break;
}
return $label;
}
/**
* Table list views
*
* @return array
*/
protected function get_views() {
$status_links = array();
$num_posts = wp_count_posts( 'shop_webhook', 'readable' );
$class = '';
$total_posts = array_sum( (array) $num_posts );
$current_user_id = get_current_user_id();
// Subtract post types that are not included in the admin all list.
foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
$total_posts -= $num_posts->$state;
}
$class = empty( $class ) && empty( $_REQUEST['status'] ) ? ' class="current"' : '';
$status_links['all'] = "" . sprintf( _nx( 'All (%s)', 'All (%s)', $total_posts, 'posts', 'woocommerce' ), number_format_i18n( $total_posts ) ) . '';
foreach ( get_post_stati( array( 'show_in_admin_status_list' => true ), 'objects' ) as $status ) {
$class = '';
$status_name = $status->name;
if ( ! in_array( $status_name, array( 'publish', 'draft', 'pending', 'trash', 'future', 'private', 'auto-draft' ) ) ) {
continue;
}
if ( empty( $num_posts->$status_name ) ) {
continue;
}
if ( isset( $_REQUEST['status'] ) && $status_name == $_REQUEST['status'] ) {
$class = ' class="current"';
}
$label = $this->get_status_label( $status_name, $status );
$status_links[ $status_name ] = "" . sprintf( translate_nooped_plural( $label, $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '';
}
return $status_links;
}
/**
* Get bulk actions
*
* @return array
*/
protected function get_bulk_actions() {
if ( isset( $_GET['status'] ) && 'trash' == $_GET['status'] ) {
return array(
'untrash' => __( 'Restore', 'woocommerce' ),
'delete' => __( 'Delete Permanently', 'woocommerce' )
);
}
return array(
'trash' => __( 'Move to Trash', 'woocommerce' )
);
}
/**
* Extra controls to be displayed between bulk actions and pagination
*
* @param string $which
*/
protected function extra_tablenav( $which ) {
if ( 'top' == $which && isset( $_GET['status'] ) && 'trash' == $_GET['status'] && current_user_can( 'delete_shop_webhooks' ) ) {
echo '';
}
}
/**
* Prepare table list items.
*/
public function prepare_items() {
$per_page = apply_filters( 'woocommerce_webhooks_settings_posts_per_page', 10 );
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
// Column headers
$this->_column_headers = array( $columns, $hidden, $sortable );
$current_page = $this->get_pagenum();
// Query args
$args = array(
'post_type' => 'shop_webhook',
'posts_per_page' => $per_page,
'ignore_sticky_posts' => true,
'paged' => $current_page
);
// Handle the status query
if ( ! empty( $_REQUEST['status'] ) ) {
$args['post_status'] = sanitize_text_field( $_REQUEST['status'] );
}
if ( ! empty( $_REQUEST['s'] ) ) {
$args['s'] = sanitize_text_field( $_REQUEST['s'] );
}
// Get the webhooks
$webhooks = new WP_Query( $args );
$this->items = $webhooks->posts;
// Set the pagination
$this->set_pagination_args( array(
'total_items' => $webhooks->found_posts,
'per_page' => $per_page,
'total_pages' => $webhooks->max_num_pages
) );
}
}