label. * * @return array */ public static function order_statuses() { $statuses = array(); foreach ( wc_get_order_statuses() as $slug => $label ) { $key = preg_replace( '/^wc-/', '', $slug ); $statuses[ $key ] = $label; } return $statuses; } /** * Installed payment gateways as id => title. * * @return array */ public static function payment_gateways() { $gateways = array(); foreach ( WC()->payment_gateways()->payment_gateways() as $id => $gateway ) { $gateways[ $id ] = wp_strip_all_tags( $gateway->get_method_title() ); } return $gateways; } /** * Stops the request unless the user may manage WooCommerce and the nonce is valid. * * @param string $action Nonce action. * @return void */ private static function guard( $action ) { if ( ! current_user_can( Menu::CAPABILITY ) ) { wp_die( esc_html__( 'You do not have permission to do this.', 'abs-courier' ), '', array( 'response' => 403 ) ); } check_admin_referer( $action ); } /** * Allows one check of the same thing per user every few seconds. The subject is part of * the throttle key, so a merchant correcting a rejected API key can retry at once. * * @param string $subject What is being checked (e.g. the API key); stored only as a hash. * @return void */ private static function throttle( $subject = '' ) { $key = 'abs_courier_check_' . get_current_user_id() . '_' . substr( md5( (string) $subject ), 0, 12 ); if ( get_transient( $key ) ) { self::back( 'warning', __( 'Please wait a few seconds before checking the connection again.', 'abs-courier' ) ); } set_transient( $key, 1, self::CHECK_INTERVAL ); } /** * Redirects to the settings tab with a notice and ends the request. * * @param string $type Notice type. * @param string $message Notice text. * @return void */ private static function back( $type, $message ) { Notice::flash( $type, $message ); wp_safe_redirect( Menu::url( 'settings' ) ); exit; } }