From dc1f6077aa2284702fffe4a795da08adbd162141 Mon Sep 17 00:00:00 2001 From: James Koster Date: Mon, 23 May 2016 12:06:41 +0100 Subject: [PATCH] coding standards tidy up --- cart-tab.php | 256 +++++++++++++++++++++++++++------------------------ 1 file changed, 138 insertions(+), 118 deletions(-) diff --git a/cart-tab.php b/cart-tab.php index bbde24f..6471f45 100755 --- a/cart-tab.php +++ b/cart-tab.php @@ -1,132 +1,146 @@ settings = array( array( 'name' => __( 'Cart Tab', 'woocommerce-cart-tab' ), 'type' => 'title', - 'id' => 'wc_ct_options' + 'id' => 'wc_ct_options', ), array( - 'name' => __( 'Cart Widget', 'woocommerce-cart-tab' ), - 'desc' => __( 'Display the cart widget on hover', 'woocommerce-cart-tab' ), - 'id' => 'wc_ct_cart_widget', - 'type' => 'checkbox' + 'name' => __( 'Cart Widget', 'woocommerce-cart-tab' ), + 'desc' => __( 'Display the cart widget on hover', 'woocommerce-cart-tab' ), + 'id' => 'wc_ct_cart_widget', + 'type' => 'checkbox', ), array( - 'name' => __( 'Hide Empty Cart', 'woocommerce-cart-tab' ), - 'desc' => __( 'Hide the cart tab if the cart is empty', 'woocommerce-cart-tab' ), - 'id' => 'wc_ct_hide_empty_cart', - 'type' => 'checkbox' + 'name' => __( 'Hide Empty Cart', 'woocommerce-cart-tab' ), + 'desc' => __( 'Hide the cart tab if the cart is empty', 'woocommerce-cart-tab' ), + 'id' => 'wc_ct_hide_empty_cart', + 'type' => 'checkbox', ), array( - 'name' => __( 'Use the light or dark skin', 'woocommerce-cart-tab' ), - 'id' => 'wc_ct_skin', - 'type' => 'select', - 'options' => array( - 'light' => __( 'Light', 'woocommerce-cart-tab' ) , - 'dark' => __( 'Dark', 'woocommerce-cart-tab' ) - ) + 'name' => __( 'Use the light or dark skin', 'woocommerce-cart-tab' ), + 'id' => 'wc_ct_skin', + 'type' => 'select', + 'options' => array( + 'light' => __( 'Light', 'woocommerce-cart-tab' ), + 'dark' => __( 'Dark', 'woocommerce-cart-tab' ), + ), ), array( - 'name' => __( 'Position the cart tab on the right or left', 'woocommerce-cart-tab' ), - 'id' => 'wc_ct_horizontal_position', - 'type' => 'select', - 'options' => array( - 'right' => __( 'Right', 'woocommerce-cart-tab' ) , - 'left' => __( 'Left', 'woocommerce-cart-tab' ) - ) + 'name' => __( 'Position the cart tab on the right or left', 'woocommerce-cart-tab' ), + 'id' => 'wc_ct_horizontal_position', + 'type' => 'select', + 'options' => array( + 'right' => __( 'Right', 'woocommerce-cart-tab' ), + 'left' => __( 'Left', 'woocommerce-cart-tab' ), + ), ), array( - 'name' => __( 'Cart link display total/subtotal', 'woocommerce-cart-tab' ), - 'id' => 'wc_ct_link_display_total', - 'type' => 'select', - 'options' => array( - 'total' => __( 'total', 'woocommerce-cart-tab' ) , - 'subtotal' => __( 'subtotal', 'woocommerce-cart-tab' ) - ) + 'name' => __( 'Cart link display total/subtotal', 'woocommerce-cart-tab' ), + 'id' => 'wc_ct_link_display_total', + 'type' => 'select', + 'options' => array( + 'total' => __( 'total', 'woocommerce-cart-tab' ), + 'subtotal' => __( 'subtotal', 'woocommerce-cart-tab' ), + ), ), - array( 'type' => 'sectionend', 'id' => 'wc_ct_options' ), - ); + array( + 'type' => 'sectionend', + 'id' => 'wc_ct_options', + ), + ); - // Default options - add_option( 'wc_ct_cart_widget', 'yes' ); - add_option( 'wc_ct_hide_empty_cart', 'no' ); - add_option( 'wc_ct_skin', 'light' ); + // Default options. + add_option( 'wc_ct_cart_widget', 'yes' ); + add_option( 'wc_ct_hide_empty_cart', 'no' ); + add_option( 'wc_ct_skin', 'light' ); add_option( 'wc_ct_horizontal_position', 'right' ); - add_option( 'wc_ct_link_display_total', 'total' ); - + add_option( 'wc_ct_link_display_total', 'total' ); - // Admin + // Admin. add_action( 'woocommerce_settings_image_options_after', array( $this, 'admin_settings' ), 20 ); - add_action( 'woocommerce_update_options_catalog', array( $this, 'save_admin_settings' ) ); - add_action( 'woocommerce_update_options_products', array( $this, 'save_admin_settings' ) ); + add_action( 'woocommerce_update_options_catalog', array( $this, 'save_admin_settings' ) ); + add_action( 'woocommerce_update_options_products', array( $this, 'save_admin_settings' ) ); } - - /*-----------------------------------------------------------------------------------*/ - /* Class Functions */ - /*-----------------------------------------------------------------------------------*/ - - // Load the settings + /** + * Load the settings + * + * @return void + */ function admin_settings() { woocommerce_admin_fields( $this->settings ); } - - // Save the settings + /** + * Save the settings + * + * @return void + */ function save_admin_settings() { woocommerce_update_options( $this->settings ); } - - // Setup styles + /** + * Styles + * + * @return void + */ function setup_styles() { if ( ! is_cart() && ! is_checkout() ) { wp_enqueue_style( 'ct-styles', plugins_url( '/assets/css/style.css', __FILE__ ) ); } } - - // The cart fragment (ensures the cart button updates via AJAX) + /** + * The cart fragment + * + * @param array $fragments elements that should be refreshed when items are added/removed from the cart. + */ function wcct_add_to_cart_fragment( $fragments ) { global $woocommerce; ob_start(); @@ -135,67 +149,73 @@ function wcct_add_to_cart_fragment( $fragments ) { return $fragments; } - - /*-----------------------------------------------------------------------------------*/ - /* Frontend Functions */ - /*-----------------------------------------------------------------------------------*/ - - // Display the cart tab and widget + /** + * Display the cart tab / widget + * + * @return void + */ function woocommerce_cart_tab() { global $woocommerce; - $skin = get_option( 'wc_ct_skin' ); - $position = get_option( 'wc_ct_horizontal_position' ); - $widget = get_option( 'wc_ct_cart_widget' ); - $hide_widget = get_option( 'wc_ct_hide_empty_cart' ); - if ( $woocommerce->cart->get_cart_contents_count() == 0 && $hide_widget == 'yes' ) { - // Hide empty cart - // Compatible with WP Super Cache as long as "late init" is enabled - $visibility = 'hidden'; + $skin = get_option( 'wc_ct_skin' ); + $position = get_option( 'wc_ct_horizontal_position' ); + $widget = get_option( 'wc_ct_cart_widget' ); + $hide_widget = get_option( 'wc_ct_hide_empty_cart' ); + + if ( 0 == $woocommerce->cart->get_cart_contents_count() && 'yes' == $hide_widget ) { + /** + * Hide empty cart + * Compatible with WP Super Cache as long as "late init" is enabled + */ + $visibility = 'hidden'; } else { - $visibility = 'visible'; + $visibility = 'visible'; } - if ( ! is_cart() && ! is_checkout() ) { - if ( $widget == 'yes' ) { - echo '
'; + if ( ! is_cart() && ! is_checkout() ) { + if ( 'yes' == $widget ) { + echo '
'; + } else { + echo '
'; + } + + wcct_cart_button(); + + // Display the widget if specified. + if ( 'yes' == $widget ) { + // Check for WooCommerce 2.0 and display the cart widget. + if ( version_compare( WOOCOMMERCE_VERSION, '2.0.0' ) >= 0 ) { + the_widget( 'WC_Widget_Cart', 'title=' ); } else { - echo '
'; + the_widget( 'WooCommerce_Widget_Cart', 'title=' ); } - wcct_cart_button(); - // Display the widget if specified - if ( $widget == 'yes' ) { - // Check for WooCommerce 2.0 and display the cart widget - if ( version_compare( WOOCOMMERCE_VERSION, "2.0.0" ) >= 0 ) { - the_widget( 'WC_Widget_Cart', 'title=' ); - } else { - the_widget( 'WooCommerce_Widget_Cart', 'title=' ); - } - } - echo '
'; } + echo '
'; } } + } - - // Displays the cart total and number of items as a link + /** + * Displays the cart total and number of items as a link + * + * @return void + */ function wcct_cart_button() { global $woocommerce; $link_total = get_option( 'wc_ct_link_display_total' ); ?> - + cart->get_cart_total() ); - } elseif ( $link_total == 'subtotal' ) { - echo wp_kses_post( $woocommerce->cart->get_cart_subtotal() ); - } - echo '' . sprintf( _n( '%d item', '%d items', intval( $woocommerce->cart->get_cart_contents_count() ), 'woocommerce-cart-tab' ), intval( $woocommerce->cart->get_cart_contents_count() ) ) . ''; + if ( 'total' == $link_total ) { + echo wp_kses_post( $woocommerce->cart->get_cart_total() ); + } elseif ( 'subtotal' == $link_total ) { + echo wp_kses_post( $woocommerce->cart->get_cart_subtotal() ); + } + echo '' . sprintf( _n( '%d item', '%d items', intval( $woocommerce->cart->get_cart_contents_count() ), 'woocommerce-cart-tab' ), intval( $woocommerce->cart->get_cart_contents_count() ) ) . ''; ?>