diff --git a/includes/admin/class-wc-admin-settings.php b/includes/admin/class-wc-admin-settings.php index 7c8103c7050..9d16701c818 100644 --- a/includes/admin/class-wc-admin-settings.php +++ b/includes/admin/class-wc-admin-settings.php @@ -2,10 +2,10 @@ /** * WooCommerce Admin Settings Class. * - * @author WooThemes - * @category Admin - * @package WooCommerce/Admin - * @version 2.2.0 + * @author WooThemes + * @category Admin + * @package WooCommerce/Admin + * @version 2.4.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -40,7 +40,7 @@ class WC_Admin_Settings { $settings[] = include( 'settings/class-wc-settings-accounts.php' ); $settings[] = include( 'settings/class-wc-settings-emails.php' ); $settings[] = include( 'settings/class-wc-settings-integrations.php' ); - $settings[] = include( 'settings/class-wc-settings-webhooks.php' ); + $settings[] = include( 'settings/class-wc-settings-api.php' ); self::$settings = apply_filters( 'woocommerce_get_settings_pages', $settings ); } diff --git a/includes/admin/class-wc-admin-webhooks-table-list.php b/includes/admin/class-wc-admin-webhooks-table-list.php index d3d91d33786..15518563ba1 100644 --- a/includes/admin/class-wc-admin-webhooks-table-list.php +++ b/includes/admin/class-wc-admin-webhooks-table-list.php @@ -5,7 +5,7 @@ * @author WooThemes * @category Admin * @package WooCommerce/Admin - * @version 2.3.0 + * @version 2.4.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -76,7 +76,7 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table { */ public function column_title( $webhook ) { $the_webhook = $this->get_webbook_object( $webhook ); - $edit_link = admin_url( 'admin.php?page=wc-settings&tab=webhooks&edit-webhook=' . $the_webhook->id ); + $edit_link = admin_url( 'admin.php?page=wc-settings&tab=api§ion=webhooks&edit-webhook=' . $the_webhook->id ); $title = _draft_or_post_title( $the_webhook->get_post_data() ); $post_type_object = get_post_type_object( $the_webhook->get_post_data()->post_type ); $post_status = $the_webhook->get_post_data()->post_status; @@ -209,7 +209,7 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table { } $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 ) ) . ''; + $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 = ''; @@ -229,7 +229,7 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table { $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 ) ) . ''; + $status_links[ $status_name ] = "" . sprintf( translate_nooped_plural( $label, $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . ''; } return $status_links; @@ -260,7 +260,7 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table { */ protected function extra_tablenav( $which ) { if ( 'top' == $which && isset( $_GET['status'] ) && 'trash' == $_GET['status'] && current_user_can( 'delete_shop_webhooks' ) ) { - echo '
'; + echo ''; } } diff --git a/includes/admin/class-wc-admin-webhooks.php b/includes/admin/class-wc-admin-webhooks.php index 6a040b34075..60ca4590f76 100644 --- a/includes/admin/class-wc-admin-webhooks.php +++ b/includes/admin/class-wc-admin-webhooks.php @@ -5,7 +5,7 @@ * @author WooThemes * @category Admin * @package WooCommerce/Admin - * @version 2.3.0 + * @version 2.4.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -30,7 +30,12 @@ class WC_Admin_Webhooks { * @return bool */ private function is_webhook_settings_page() { - return isset( $_GET['page'] ) && 'wc-settings' == $_GET['page'] && isset( $_GET['tab'] ) && 'webhooks' == $_GET['tab']; + return isset( $_GET['page'] ) + && 'wc-settings' == $_GET['page'] + && isset( $_GET['tab'] ) + && 'api' == $_GET['tab'] + && isset( $_GET['section'] ) + && 'webhooks' == isset( $_GET['section'] ); } /** @@ -157,7 +162,7 @@ class WC_Admin_Webhooks { delete_transient( 'woocommerce_webhook_ids' ); // Redirect to webhook edit page to avoid settings save actions - wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=webhooks&edit-webhook=' . $webhook->id . '&updated=1' ) ); + wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=api§ion=webhooks&edit-webhook=' . $webhook->id . '&updated=1' ) ); exit(); } @@ -188,7 +193,7 @@ class WC_Admin_Webhooks { delete_transient( 'woocommerce_webhook_ids' ); // Redirect to edit page - wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=webhooks&edit-webhook=' . $webhook_id . '&created=1' ) ); + wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=api§ion=webhooks&edit-webhook=' . $webhook_id . '&created=1' ) ); exit(); } @@ -212,7 +217,7 @@ class WC_Admin_Webhooks { $status = isset( $_GET['status'] ) ? '&status=' . sanitize_text_field( $_GET['status'] ) : ''; // Redirect to webhooks page - wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=webhooks' . $status . '&' . $type . '=' . $qty ) ); + wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=api§ion=webhooks' . $status . '&' . $type . '=' . $qty ) ); exit(); } @@ -229,7 +234,7 @@ class WC_Admin_Webhooks { $qty = count( $webhooks ); // Redirect to webhooks page - wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=webhooks&status=trash&untrashed=' . $qty ) ); + wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=api§ion=webhooks&status=trash&untrashed=' . $qty ) ); exit(); } @@ -283,7 +288,7 @@ class WC_Admin_Webhooks { $qty = count( $webhooks ); // Redirect to webhooks page - wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=webhooks&deleted=' . $qty ) ); + wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=api§ion=webhooks&deleted=' . $qty ) ); exit(); } diff --git a/includes/admin/settings/class-wc-settings-webhooks.php b/includes/admin/settings/class-wc-settings-api.php similarity index 68% rename from includes/admin/settings/class-wc-settings-webhooks.php rename to includes/admin/settings/class-wc-settings-api.php index 56cdccde9fa..4f9de12ecd4 100644 --- a/includes/admin/settings/class-wc-settings-webhooks.php +++ b/includes/admin/settings/class-wc-settings-api.php @@ -1,38 +1,54 @@ id = 'webhooks'; - $this->label = __( 'Webhooks', 'woocommerce' ); + $this->id = 'api'; + $this->label = __( 'API', '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_sections_' . $this->id, array( $this, 'output_sections' ) ); add_action( 'woocommerce_settings_form_method_tab_' . $this->id, array( $this, 'form_method' ) ); $this->notices(); } + /** + * Get sections + * + * @return array + */ + public function get_sections() { + $sections = array( + '' => __( 'Settings', 'woocommerce' ), + 'keys' => __( 'Keys', 'woocommerce' ), + 'webhooks' => __( 'Webhooks', 'woocommerce' ), + ); + + return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections ); + } + /** * Form method * @@ -41,7 +57,9 @@ class WC_Settings_Webhooks extends WC_Settings_Page { * @return string */ public function form_method( $method ) { - if ( isset( $_GET['edit-webhook'] ) ) { + global $current_section; + + if ( 'webhooks' == $current_section && isset( $_GET['edit-webhook'] ) ) { $webhook_id = absint( $_GET['edit-webhook'] ); $webhook = new WC_Webhook( $webhook_id ); @@ -57,6 +75,46 @@ class WC_Settings_Webhooks extends WC_Settings_Page { * Notices. */ private function notices() { + if ( isset( $_GET['section'] ) && 'webhooks' == $_GET['section'] ) { + $this->webhook_notices(); + } + } + + /** + * Output the settings + */ + public function output() { + global $current_section; + + if ( 'webhooks' == $current_section ) { + $this->webhooks_output(); + } + } + + /** + * Webhooks output + */ + private function webhooks_output() { + // 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->webhooks_edit_output( $webhook ); + return; + } + } + + $this->webhooks_table_list_output(); + } + + /** + * Webhooks - Notices. + */ + private function webhook_notices() { if ( isset( $_GET['trashed'] ) ) { $trashed = absint( $_GET['trashed'] ); @@ -85,16 +143,17 @@ class WC_Settings_Webhooks extends WC_Settings_Page { } /** - * Table list output + * Webhooks - Table list output */ - private function table_list_output() { - echo '