id = 'webhooks'; $this->label = __( 'Webhooks', 'woocommerce' ); add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) ); add_action( 'woocommerce_settings_form_method_tab_' . $this->id, array( $this, 'form_method' ) ); $this->notices(); } /** * Form method * * @param string $method * * @return string */ public function form_method( $method ) { if ( isset( $_GET['edit-webhook'] ) ) { $webhook_id = absint( $_GET['edit-webhook'] ); $webhook = new WC_Webhook( $webhook_id ); if ( 'trash' != $webhook->post_data->post_status ) { return 'post'; } } return 'get'; } /** * Notices. */ private function notices() { if ( isset( $_GET['trashed'] ) ) { $trashed = absint( $_GET['trashed'] ); WC_Admin_Settings::add_message( sprintf( _n( '1 webhook moved to the Trash.', '%d webhooks moved to the Trash.', $trashed, 'woocommerce' ), $trashed ) ); } if ( isset( $_GET['untrashed'] ) ) { $untrashed = absint( $_GET['untrashed'] ); WC_Admin_Settings::add_message( sprintf( _n( '1 webhook restored from the Trash.', '%d webhooks restored from the Trash.', $untrashed, 'woocommerce' ), $untrashed ) ); } if ( isset( $_GET['deleted'] ) ) { $deleted = absint( $_GET['deleted'] ); WC_Admin_Settings::add_message( sprintf( _n( '1 webhook permanently deleted.', '%d webhooks permanently deleted.', $deleted, 'woocommerce' ), $deleted ) ); } if ( isset( $_GET['updated'] ) ) { WC_Admin_Settings::add_message( __( 'Webhook updated successfully.', 'woocommerce' ) ); } if ( isset( $_GET['created'] ) ) { WC_Admin_Settings::add_message( __( 'Webhook created successfully.', 'woocommerce' ) ); } } /** * Table list output */ private function table_list_output() { echo '
' . __( 'This Webhook has no log yet.', 'woocommerce' ) . '
'; } } /** * Output the settings */ public function output() { global $current_section; // Hide the save button $GLOBALS['hide_save_button'] = true; if ( isset( $_GET['edit-webhook'] ) ) { $webhook_id = absint( $_GET['edit-webhook'] ); $webhook = new WC_Webhook( $webhook_id ); if ( 'trash' != $webhook->post_data->post_status ) { $this->edit_output( $webhook ); return; } } $this->table_list_output(); } /** * Get the webhook topic data * * @return array */ private function get_topic_data( $webhook ) { $topic = $webhook->get_topic(); $event = ''; $resource = ''; if ( $topic ) { list( $resource, $event ) = explode( '.', $topic ); if ( 'action' === $resource ) { $topic = 'action'; } else if ( ! in_array( $resource, array( 'coupon', 'customer', 'order', 'product' ) ) ) { $topic = 'custom'; } } return array( 'topic' => $topic, 'event' => $event, 'resource' => $resource ); } /** * Get the logs navigation. * * @param int $total * * @return string */ private function get_logs_navigation( $total, $webhook ) { $pages = ceil( $total / 10 ); $current = isset( $_GET['log_page'] ) ? absint( $_GET['log_page'] ) : 1; $html = ' '; return $html; } } endif; return new WC_Settings_Webhooks();