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&section=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 '
' . __( 'Empty Trash', 'woocommerce' ) . '
'; + echo '
' . __( 'Empty Trash', 'woocommerce' ) . '
'; } } 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 '

' . __( 'Webhooks', 'woocommerce' ) . ' ' . __( 'Add Webhook', 'woocommerce' ) . '

'; + private function webhooks_table_list_output() { + echo '

' . __( 'Webhooks', 'woocommerce' ) . ' ' . __( 'Add Webhook', 'woocommerce' ) . '

'; $webhooks_table_list = new WC_Admin_Webhooks_Table_List(); $webhooks_table_list->prepare_items(); echo ''; - echo ''; + echo ''; + echo ''; $webhooks_table_list->views(); $webhooks_table_list->search_box( __( 'Search Webhooks', 'woocommerce' ), 'webhook' ); @@ -102,20 +161,20 @@ class WC_Settings_Webhooks extends WC_Settings_Page { } /** - * Edit webhook output + * Webhooks - Edit webhook output * * @param WC_Webhook $webhook */ - private function edit_output( $webhook ) { + private function webhooks_edit_output( $webhook ) { include_once( 'views/html-webhooks-edit.php' ); } /** - * Logs output + * Webhooks - Logs output * * @param WC_Webhook $webhook */ - private function logs_output( $webhook ) { + private function webhooks_logs_output( $webhook ) { $current = isset( $_GET['log_page'] ) ? absint( $_GET['log_page'] ) : 1; $args = array( 'post_id' => $webhook->id, @@ -142,33 +201,11 @@ class WC_Settings_Webhooks extends WC_Settings_Page { } /** - * 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 + * Webhooks - Get the webhook topic data * * @return array */ - private function get_topic_data( $webhook ) { + private function webhooks_get_topic_data( $webhook ) { $topic = $webhook->get_topic(); $event = ''; $resource = ''; @@ -191,13 +228,13 @@ class WC_Settings_Webhooks extends WC_Settings_Page { } /** - * Get the logs navigation. + * Webhooks - Get the logs navigation. * * @param int $total * * @return string */ - private function get_logs_navigation( $total, $webhook ) { + private function webhooks_get_logs_navigation( $total, $webhook ) { $pages = ceil( $total / 10 ); $current = isset( $_GET['log_page'] ) ? absint( $_GET['log_page'] ) : 1; @@ -212,13 +249,13 @@ class WC_Settings_Webhooks extends WC_Settings_Page { if ( 1 == $current ) { $html .= ' '; } else { - $html .= '' . __( '‹ Previous', 'woocommerce' ) . ' '; + $html .= '' . __( '‹ Previous', 'woocommerce' ) . ' '; } if ( $pages == $current ) { $html .= ''; } else { - $html .= '' . __( 'Next ›', 'woocommerce' ) . ''; + $html .= '' . __( 'Next ›', 'woocommerce' ) . ''; } $html .= '

'; } @@ -231,4 +268,4 @@ class WC_Settings_Webhooks extends WC_Settings_Page { endif; -return new WC_Settings_Webhooks(); +return new WC_Settings_Rest_API(); diff --git a/includes/admin/settings/views/html-webhook-log.php b/includes/admin/settings/views/html-webhook-log.php index 6ce71f52896..03e2465c8ca 100644 --- a/includes/admin/settings/views/html-webhook-log.php +++ b/includes/admin/settings/views/html-webhook-log.php @@ -1,7 +1,7 @@ diff --git a/includes/admin/settings/views/html-webhook-logs.php b/includes/admin/settings/views/html-webhook-logs.php index 7884c23843e..830e02d0f7e 100644 --- a/includes/admin/settings/views/html-webhook-logs.php +++ b/includes/admin/settings/views/html-webhook-logs.php @@ -1,7 +1,7 @@ id ); @@ -9,7 +9,7 @@ $total = $count_comments->approved; ?> -get_logs_navigation( $total, $webhook ); ?> +webhooks_get_logs_navigation( $total, $webhook ); ?> @@ -39,4 +39,4 @@ $total = $count_comments->approved;
-get_logs_navigation( $total, $webhook ); ?> +webhooks_get_logs_navigation( $total, $webhook ); ?> diff --git a/includes/admin/settings/views/html-webhooks-edit.php b/includes/admin/settings/views/html-webhooks-edit.php index f20a4da5c32..7d2057f6422 100644 --- a/includes/admin/settings/views/html-webhooks-edit.php +++ b/includes/admin/settings/views/html-webhooks-edit.php @@ -44,7 +44,7 @@ if ( ! defined( 'ABSPATH' ) ) {