diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php
index 2d75468bce3..b818ca080bd 100644
--- a/includes/abstracts/abstract-wc-order.php
+++ b/includes/abstracts/abstract-wc-order.php
@@ -135,7 +135,7 @@ abstract class WC_Abstract_Order {
public function remove_order_items( $type = null ) {
global $wpdb;
- if ( $type ) {
+ if ( ! empty( $type ) ) {
$wpdb->query( $wpdb->prepare( "DELETE FROM itemmeta USING {$wpdb->prefix}woocommerce_order_itemmeta itemmeta INNER JOIN {$wpdb->prefix}woocommerce_order_items items WHERE itemmeta.order_item_id = items.order_item_id AND items.order_id = %d AND items.order_item_type = %s", $this->id, $type ) );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d AND order_item_type = %s", $this->id, $type ) );
} else {
@@ -645,7 +645,7 @@ abstract class WC_Abstract_Order {
'tax_class' => ''
) );
- if ( $tax_rates ) {
+ if ( ! empty( $tax_rates ) ) {
foreach ( $tax_rates as $key => $rate ) {
if ( isset( $rate['shipping'] ) && 'yes' === $rate['shipping'] ) {
$matched_tax_rates[ $key ] = $rate;
@@ -1184,7 +1184,7 @@ abstract class WC_Abstract_Order {
$shipping_methods = $this->get_shipping_methods();
$has_method = false;
- if ( ! $shipping_methods ) {
+ if ( empty( $shipping_methods ) ) {
return false;
}
diff --git a/includes/abstracts/abstract-wc-product.php b/includes/abstracts/abstract-wc-product.php
index 45a961a5890..66c80f8559a 100644
--- a/includes/abstracts/abstract-wc-product.php
+++ b/includes/abstracts/abstract-wc-product.php
@@ -337,7 +337,7 @@ class WC_Product {
$downloadable_files = array_filter( isset( $this->downloadable_files ) ? (array) maybe_unserialize( $this->downloadable_files ) : array() );
- if ( $downloadable_files ) {
+ if ( ! empty( $downloadable_files ) ) {
foreach ( $downloadable_files as $key => $file ) {
@@ -1223,23 +1223,9 @@ class WC_Product {
public function get_related( $limit = 5 ) {
global $wpdb;
- $limit = absint( $limit );
-
// Related products are found from category and tag
- $tags_array = array(0);
- $cats_array = array(0);
-
- // Get tags
- $terms = apply_filters( 'woocommerce_get_related_product_tag_terms', wp_get_post_terms( $this->id, 'product_tag' ), $this->id );
- foreach ( $terms as $term ) {
- $tags_array[] = $term->term_id;
- }
-
- // Get categories
- $terms = apply_filters( 'woocommerce_get_related_product_cat_terms', wp_get_post_terms( $this->id, 'product_cat' ), $this->id );
- foreach ( $terms as $term ) {
- $cats_array[] = $term->term_id;
- }
+ $tags_array = $this->get_related_terms( 'product_tag' );
+ $cats_array = $this->get_related_terms( 'product_cat' );
// Don't bother if none are set
if ( sizeof( $cats_array ) == 1 && sizeof( $tags_array ) == 1 ) {
@@ -1247,60 +1233,10 @@ class WC_Product {
}
// Sanitize
- $cats_array = array_map( 'absint', $cats_array );
- $tags_array = array_map( 'absint', $tags_array );
$exclude_ids = array_map( 'absint', array_merge( array( 0, $this->id ), $this->get_upsells() ) );
// Generate query
- $query = array();
- $query['fields'] = "SELECT DISTINCT ID FROM {$wpdb->posts} p";
- $query['join'] = " INNER JOIN {$wpdb->postmeta} pm ON ( pm.post_id = p.ID AND pm.meta_key='_visibility' )";
- $query['join'] .= " INNER JOIN {$wpdb->term_relationships} tr ON (p.ID = tr.object_id)";
- $query['join'] .= " INNER JOIN {$wpdb->term_taxonomy} tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)";
- $query['join'] .= " INNER JOIN {$wpdb->terms} t ON (t.term_id = tt.term_id)";
-
- if ( get_option( 'woocommerce_hide_out_of_stock_items' ) === 'yes' ) {
- $query['join'] .= " INNER JOIN {$wpdb->postmeta} pm2 ON ( pm2.post_id = p.ID AND pm2.meta_key='_stock_status' )";
- }
-
- $query['where'] = " WHERE 1=1";
- $query['where'] .= " AND p.post_status = 'publish'";
- $query['where'] .= " AND p.post_type = 'product'";
- $query['where'] .= " AND p.ID NOT IN ( " . implode( ',', $exclude_ids ) . " )";
- $query['where'] .= " AND pm.meta_value IN ( 'visible', 'catalog' )";
-
- if ( get_option( 'woocommerce_hide_out_of_stock_items' ) === 'yes' ) {
- $query['where'] .= " AND pm2.meta_value = 'instock'";
- }
-
- if ( apply_filters( 'woocommerce_product_related_posts_relate_by_category', true, $this->id ) ) {
- $query['where'] .= " AND ( tt.taxonomy = 'product_cat' AND t.term_id IN ( " . implode( ',', $cats_array ) . " ) )";
- $andor = 'OR';
- } else {
- $andor = 'AND';
- }
-
- // when query is OR - need to check against excluded ids again
- if ( apply_filters( 'woocommerce_product_related_posts_relate_by_tag', true, $this->id ) ) {
- $query['where'] .= " {$andor} ( ( tt.taxonomy = 'product_tag' AND t.term_id IN ( " . implode( ',', $tags_array ) . " ) )";
- $query['where'] .= " AND p.ID NOT IN ( " . implode( ',', $exclude_ids ) . " ) )";
- }
-
- $query = apply_filters( 'woocommerce_product_related_posts_query', $query, $this->id );
-
- // How many rows total?
- $max_related_posts_transient_name = 'wc_max_related_' . $this->id . WC_Cache_Helper::get_transient_version( 'product' );
-
- if ( false === ( $max_related_posts = get_transient( $max_related_posts_transient_name ) ) ) {
- $max_related_posts_query = $query;
- $max_related_posts_query['fields'] = "SELECT COUNT(DISTINCT ID) FROM {$wpdb->posts} p";
- $max_related_posts = absint( $wpdb->get_var( implode( ' ', apply_filters( 'woocommerce_product_max_related_posts_query', $max_related_posts_query, $this->id ) ) ) );
- set_transient( $max_related_posts_transient_name, $max_related_posts, DAY_IN_SECONDS * 30 );
- }
-
- // Generate limit
- $offset = $max_related_posts < $limit ? 0 : absint( rand( 0, $max_related_posts - $limit ) );
- $query['limits'] = " LIMIT {$offset}, {$limit} ";
+ $query = $this->build_related_query( $cats_array, $tags_array, $exclude_ids, $limit );
// Get the posts
$related_posts = $wpdb->get_col( implode( ' ', $query ) );
@@ -1505,4 +1441,88 @@ class WC_Product {
return sprintf( __( '%s – %s', 'woocommerce' ), $identifier, $this->get_title() );
}
+
+ /**
+ * Retrieves related product terms
+ *
+ * @param string $term
+ * @return array
+ */
+ protected function get_related_terms( $term ) {
+ $terms_array = array(0);
+
+ $terms = apply_filters( 'woocommerce_get_related_' . $term . '_terms', wp_get_post_terms( $this->id, $term ), $this->id );
+ foreach ( $terms as $term ) {
+ $terms_array[] = $term->term_id;
+ }
+
+ return array_map( 'absint', $terms_array );
+ }
+
+ /**
+ * Builds the related posts query
+ *
+ * @param array $cats_array
+ * @param array $tags_array
+ * @param array $exclude_ids
+ * @param int $limit
+ * @return string
+ */
+ protected function build_related_query( $cats_array, $tags_array, $exclude_ids, $limit ) {
+ global $wpdb;
+
+ $limit = absint( $limit );
+
+ $query = array();
+ $query['fields'] = "SELECT DISTINCT ID FROM {$wpdb->posts} p";
+ $query['join'] = " INNER JOIN {$wpdb->postmeta} pm ON ( pm.post_id = p.ID AND pm.meta_key='_visibility' )";
+ $query['join'] .= " INNER JOIN {$wpdb->term_relationships} tr ON (p.ID = tr.object_id)";
+ $query['join'] .= " INNER JOIN {$wpdb->term_taxonomy} tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)";
+ $query['join'] .= " INNER JOIN {$wpdb->terms} t ON (t.term_id = tt.term_id)";
+
+ if ( get_option( 'woocommerce_hide_out_of_stock_items' ) === 'yes' ) {
+ $query['join'] .= " INNER JOIN {$wpdb->postmeta} pm2 ON ( pm2.post_id = p.ID AND pm2.meta_key='_stock_status' )";
+ }
+
+ $query['where'] = " WHERE 1=1";
+ $query['where'] .= " AND p.post_status = 'publish'";
+ $query['where'] .= " AND p.post_type = 'product'";
+ $query['where'] .= " AND p.ID NOT IN ( " . implode( ',', $exclude_ids ) . " )";
+ $query['where'] .= " AND pm.meta_value IN ( 'visible', 'catalog' )";
+
+ if ( get_option( 'woocommerce_hide_out_of_stock_items' ) === 'yes' ) {
+ $query['where'] .= " AND pm2.meta_value = 'instock'";
+ }
+
+ if ( apply_filters( 'woocommerce_product_related_posts_relate_by_category', true, $this->id ) ) {
+ $query['where'] .= " AND ( tt.taxonomy = 'product_cat' AND t.term_id IN ( " . implode( ',', $cats_array ) . " ) )";
+ $andor = 'OR';
+ } else {
+ $andor = 'AND';
+ }
+
+ // when query is OR - need to check against excluded ids again
+ if ( apply_filters( 'woocommerce_product_related_posts_relate_by_tag', true, $this->id ) ) {
+ $query['where'] .= " {$andor} ( ( tt.taxonomy = 'product_tag' AND t.term_id IN ( " . implode( ',', $tags_array ) . " ) )";
+ $query['where'] .= " AND p.ID NOT IN ( " . implode( ',', $exclude_ids ) . " ) )";
+ }
+
+ $query = apply_filters( 'woocommerce_product_related_posts_query', $query, $this->id );
+
+ // How many rows total?
+ $max_related_posts_transient_name = 'wc_max_related_' . $this->id . WC_Cache_Helper::get_transient_version( 'product' );
+
+ if ( false === ( $max_related_posts = get_transient( $max_related_posts_transient_name ) ) ) {
+ $max_related_posts_query = $query;
+ $max_related_posts_query['fields'] = "SELECT COUNT(DISTINCT ID) FROM {$wpdb->posts} p";
+ $max_related_posts = absint( $wpdb->get_var( implode( ' ', apply_filters( 'woocommerce_product_max_related_posts_query', $max_related_posts_query, $this->id ) ) ) );
+ set_transient( $max_related_posts_transient_name, $max_related_posts, DAY_IN_SECONDS * 30 );
+ }
+
+ // Generate limit
+ $offset = $max_related_posts < $limit ? 0 : absint( rand( 0, $max_related_posts - $limit ) );
+ $query['limits'] = " LIMIT {$offset}, {$limit} ";
+
+ return $query;
+ }
}
diff --git a/includes/abstracts/abstract-wc-settings-api.php b/includes/abstracts/abstract-wc-settings-api.php
index 773d7dc125a..cb93818c1ac 100644
--- a/includes/abstracts/abstract-wc-settings-api.php
+++ b/includes/abstracts/abstract-wc-settings-api.php
@@ -159,7 +159,7 @@ abstract class WC_Settings_API {
}
}
- if ( $this->settings && is_array( $this->settings ) ) {
+ if ( ! empty( $this->settings ) && is_array( $this->settings ) ) {
$this->settings = array_map( array( $this, 'format_settings' ), $this->settings );
$this->enabled = isset( $this->settings['enabled'] ) && $this->settings['enabled'] == 'yes' ? 'yes' : 'no';
}
@@ -215,7 +215,7 @@ abstract class WC_Settings_API {
*/
public function generate_settings_html( $form_fields = array() ) {
- if ( ! $form_fields ) {
+ if ( empty( $form_fields ) ) {
$form_fields = $this->get_form_fields();
}
@@ -726,7 +726,7 @@ abstract class WC_Settings_API {
*/
public function validate_settings_fields( $form_fields = array() ) {
- if ( ! $form_fields ) {
+ if ( empty( $form_fields ) ) {
$form_fields = $this->get_form_fields();
}
diff --git a/includes/abstracts/abstract-wc-widget.php b/includes/abstracts/abstract-wc-widget.php
index 918c155341f..de4f448e72d 100644
--- a/includes/abstracts/abstract-wc-widget.php
+++ b/includes/abstracts/abstract-wc-widget.php
@@ -139,7 +139,7 @@ abstract class WC_Widget extends WP_Widget {
$instance = $old_instance;
- if ( ! $this->settings ) {
+ if ( empty( $this->settings ) ) {
return $instance;
}
@@ -165,7 +165,7 @@ abstract class WC_Widget extends WP_Widget {
*/
public function form( $instance ) {
- if ( ! $this->settings ) {
+ if ( empty( $this->settings ) ) {
return;
}
diff --git a/includes/class-wc-checkout.php b/includes/class-wc-checkout.php
index 6a182957ee2..4d9ad073383 100644
--- a/includes/class-wc-checkout.php
+++ b/includes/class-wc-checkout.php
@@ -595,30 +595,30 @@ class WC_Checkout {
$password = ! empty( $this->posted['account_password'] ) ? $this->posted['account_password'] : '';
$new_customer = wc_create_new_customer( $this->posted['billing_email'], $username, $password );
- if ( is_wp_error( $new_customer ) ) {
- throw new Exception( $new_customer->get_error_message() );
- }
+ if ( is_wp_error( $new_customer ) ) {
+ throw new Exception( $new_customer->get_error_message() );
+ }
- $this->customer_id = $new_customer;
+ $this->customer_id = $new_customer;
- wc_set_customer_auth_cookie( $this->customer_id );
+ wc_set_customer_auth_cookie( $this->customer_id );
- // As we are now logged in, checkout will need to refresh to show logged in data
- WC()->session->set( 'reload_checkout', true );
+ // As we are now logged in, checkout will need to refresh to show logged in data
+ WC()->session->set( 'reload_checkout', true );
- // Also, recalculate cart totals to reveal any role-based discounts that were unavailable before registering
+ // Also, recalculate cart totals to reveal any role-based discounts that were unavailable before registering
WC()->cart->calculate_totals();
- // Add customer info from other billing fields
- if ( $this->posted['billing_first_name'] && apply_filters( 'woocommerce_checkout_update_customer_data', true, $this ) ) {
- $userdata = array(
+ // Add customer info from other billing fields
+ if ( $this->posted['billing_first_name'] && apply_filters( 'woocommerce_checkout_update_customer_data', true, $this ) ) {
+ $userdata = array(
'ID' => $this->customer_id,
'first_name' => $this->posted['billing_first_name'] ? $this->posted['billing_first_name'] : '',
'last_name' => $this->posted['billing_last_name'] ? $this->posted['billing_last_name'] : '',
'display_name' => $this->posted['billing_first_name'] ? $this->posted['billing_first_name'] : ''
- );
- wp_update_user( apply_filters( 'woocommerce_checkout_customer_userdata', $userdata, $this ) );
- }
+ );
+ wp_update_user( apply_filters( 'woocommerce_checkout_customer_userdata', $userdata, $this ) );
+ }
}
// Do a final stock check at this point
diff --git a/includes/class-wc-customer.php b/includes/class-wc-customer.php
index 8a5e3d63b17..ef6c3212cae 100644
--- a/includes/class-wc-customer.php
+++ b/includes/class-wc-customer.php
@@ -50,42 +50,7 @@ class WC_Customer {
if ( empty( $this->_data ) ) {
// Defaults
- $this->_data = array(
- 'postcode' => '',
- 'city' => '',
- 'address' => '',
- 'address_2' => '',
- 'state' => '',
- 'country' => '',
- 'shipping_postcode' => '',
- 'shipping_city' => '',
- 'shipping_address' => '',
- 'shipping_address_2' => '',
- 'shipping_state' => '',
- 'shipping_country' => '',
- 'is_vat_exempt' => false,
- 'calculated_shipping' => false
- );
-
- if ( is_user_logged_in() ) {
- foreach ( $this->_data as $key => $value ) {
- $meta_value = get_user_meta( get_current_user_id(), ( false === strstr( $key, 'shipping_' ) ? 'billing_' : '' ) . $key, true );
- $this->_data[ $key ] = $meta_value ? $meta_value : $this->_data[ $key ];
- }
- }
-
- if ( empty( $this->_data['country'] ) ) {
- $this->_data['country'] = $this->get_default_country();
- }
- if ( empty( $this->_data['shipping_country'] ) ) {
- $this->_data['shipping_country'] = $this->get_default_country();
- }
- if ( empty( $this->_data['state'] ) ) {
- $this->_data['state'] = $this->get_default_state();
- }
- if ( empty( $this->_data['shipping_state'] ) ) {
- $this->_data['shipping_state'] = $this->get_default_state();
- }
+ $this->set_default_data();
}
// When leaving or ending page load, store data
@@ -134,6 +99,7 @@ class WC_Customer {
/**
* Get default country for a customer
+ *
* @return string
*/
public function get_default_country() {
@@ -143,6 +109,7 @@ class WC_Customer {
/**
* Get default state for a customer
+ *
* @return string
*/
public function get_default_state() {
@@ -373,6 +340,51 @@ class WC_Customer {
return apply_filters( 'woocommerce_customer_taxable_address', array( $country, $state, $postcode, $city ) );
}
+ /**
+ * Set default data for a customer
+ */
+ public function set_default_data() {
+ $this->_data = array(
+ 'postcode' => '',
+ 'city' => '',
+ 'address' => '',
+ 'address_2' => '',
+ 'state' => '',
+ 'country' => '',
+ 'shipping_postcode' => '',
+ 'shipping_city' => '',
+ 'shipping_address' => '',
+ 'shipping_address_2' => '',
+ 'shipping_state' => '',
+ 'shipping_country' => '',
+ 'is_vat_exempt' => false,
+ 'calculated_shipping' => false
+ );
+
+ if ( is_user_logged_in() ) {
+ foreach ( $this->_data as $key => $value ) {
+ $meta_value = get_user_meta( get_current_user_id(), ( false === strstr( $key, 'shipping_' ) ? 'billing_' : '' ) . $key, true );
+ $this->_data[ $key ] = $meta_value ? $meta_value : $this->_data[ $key ];
+ }
+ }
+
+ if ( empty( $this->_data['country'] ) ) {
+ $this->_data['country'] = $this->get_default_country();
+ }
+
+ if ( empty( $this->_data['shipping_country'] ) ) {
+ $this->_data['shipping_country'] = $this->get_default_country();
+ }
+
+ if ( empty( $this->_data['state'] ) ) {
+ $this->_data['state'] = $this->get_default_state();
+ }
+
+ if ( empty( $this->_data['shipping_state'] ) ) {
+ $this->_data['shipping_state'] = $this->get_default_state();
+ }
+ }
+
/**
* Sets session data for the location.
diff --git a/includes/class-wc-form-handler.php b/includes/class-wc-form-handler.php
index 1c362375490..ec66a1564e3 100644
--- a/includes/class-wc-form-handler.php
+++ b/includes/class-wc-form-handler.php
@@ -650,10 +650,10 @@ class WC_Form_Handler {
$passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations );
if ( $passed_validation ) {
- if ( WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variations ) ) {
+ if ( WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variations ) !== false ) {
wc_add_to_cart_message( $product_id );
$was_added_to_cart = true;
- $added_to_cart[] = $product_id;
+ $added_to_cart[] = $product_id;
}
}
}
@@ -676,7 +676,7 @@ class WC_Form_Handler {
$passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $item, $quantity );
if ( $passed_validation ) {
- if ( WC()->cart->add_to_cart( $item, $quantity ) ) {
+ if ( WC()->cart->add_to_cart( $item, $quantity ) !== false ) {
$was_added_to_cart = true;
$added_to_cart[] = $item;
}
@@ -716,7 +716,7 @@ class WC_Form_Handler {
if ( $passed_validation ) {
// Add the product to the cart
- if ( WC()->cart->add_to_cart( $product_id, $quantity ) ) {
+ if ( WC()->cart->add_to_cart( $product_id, $quantity ) !== false ) {
wc_add_to_cart_message( $product_id );
$was_added_to_cart = true;
$added_to_cart[] = $product_id;
diff --git a/includes/class-wc-geo-ip.php b/includes/class-wc-geo-ip.php
index 0a025de3e72..8f0bc64d7c0 100644
--- a/includes/class-wc-geo-ip.php
+++ b/includes/class-wc-geo-ip.php
@@ -19,40 +19,40 @@ if ( ! defined( 'ABSPATH' ) ) {
*/
class WC_Geo_IP {
- const GEOIP_COUNTRY_BEGIN = 16776960;
- const GEOIP_STATE_BEGIN_REV0 = 16700000;
- const GEOIP_STATE_BEGIN_REV1 = 16000000;
- const GEOIP_MEMORY_CACHE = 1;
- const GEOIP_SHARED_MEMORY = 2;
- const STRUCTURE_INFO_MAX_SIZE = 20;
- const GEOIP_COUNTRY_EDITION = 1;
- const GEOIP_PROXY_EDITION = 8;
- const GEOIP_ASNUM_EDITION = 9;
- const GEOIP_NETSPEED_EDITION = 10;
- const GEOIP_REGION_EDITION_REV0 = 7;
- const GEOIP_REGION_EDITION_REV1 = 3;
- const GEOIP_CITY_EDITION_REV0 = 6;
- const GEOIP_CITY_EDITION_REV1 = 2;
- const GEOIP_ORG_EDITION = 5;
- const GEOIP_ISP_EDITION = 4;
- const SEGMENT_RECORD_LENGTH = 3;
- const STANDARD_RECORD_LENGTH = 3;
- const ORG_RECORD_LENGTH = 4;
- const GEOIP_SHM_KEY = 0x4f415401;
- const GEOIP_DOMAIN_EDITION = 11;
- const GEOIP_COUNTRY_EDITION_V6 = 12;
- const GEOIP_LOCATIONA_EDITION = 13;
- const GEOIP_ACCURACYRADIUS_EDITION = 14;
- const GEOIP_CITY_EDITION_REV1_V6 = 30;
- const GEOIP_CITY_EDITION_REV0_V6 = 31;
- const GEOIP_NETSPEED_EDITION_REV1 = 32;
+ const GEOIP_COUNTRY_BEGIN = 16776960;
+ const GEOIP_STATE_BEGIN_REV0 = 16700000;
+ const GEOIP_STATE_BEGIN_REV1 = 16000000;
+ const GEOIP_MEMORY_CACHE = 1;
+ const GEOIP_SHARED_MEMORY = 2;
+ const STRUCTURE_INFO_MAX_SIZE = 20;
+ const GEOIP_COUNTRY_EDITION = 1;
+ const GEOIP_PROXY_EDITION = 8;
+ const GEOIP_ASNUM_EDITION = 9;
+ const GEOIP_NETSPEED_EDITION = 10;
+ const GEOIP_REGION_EDITION_REV0 = 7;
+ const GEOIP_REGION_EDITION_REV1 = 3;
+ const GEOIP_CITY_EDITION_REV0 = 6;
+ const GEOIP_CITY_EDITION_REV1 = 2;
+ const GEOIP_ORG_EDITION = 5;
+ const GEOIP_ISP_EDITION = 4;
+ const SEGMENT_RECORD_LENGTH = 3;
+ const STANDARD_RECORD_LENGTH = 3;
+ const ORG_RECORD_LENGTH = 4;
+ const GEOIP_SHM_KEY = 0x4f415401;
+ const GEOIP_DOMAIN_EDITION = 11;
+ const GEOIP_COUNTRY_EDITION_V6 = 12;
+ const GEOIP_LOCATIONA_EDITION = 13;
+ const GEOIP_ACCURACYRADIUS_EDITION = 14;
+ const GEOIP_CITY_EDITION_REV1_V6 = 30;
+ const GEOIP_CITY_EDITION_REV0_V6 = 31;
+ const GEOIP_NETSPEED_EDITION_REV1 = 32;
const GEOIP_NETSPEED_EDITION_REV1_V6 = 33;
- const GEOIP_USERTYPE_EDITION = 28;
- const GEOIP_USERTYPE_EDITION_V6 = 29;
- const GEOIP_ASNUM_EDITION_V6 = 21;
- const GEOIP_ISP_EDITION_V6 = 22;
- const GEOIP_ORG_EDITION_V6 = 23;
- const GEOIP_DOMAIN_EDITION_V6 = 24;
+ const GEOIP_USERTYPE_EDITION = 28;
+ const GEOIP_USERTYPE_EDITION_V6 = 29;
+ const GEOIP_ASNUM_EDITION_V6 = 21;
+ const GEOIP_ISP_EDITION_V6 = 22;
+ const GEOIP_ORG_EDITION_V6 = 23;
+ const GEOIP_DOMAIN_EDITION_V6 = 24;
public $flags;
@@ -1120,133 +1120,150 @@ class WC_Geo_IP {
}
private function _setup_segments() {
- $this->databaseType = self::GEOIP_COUNTRY_EDITION;
+ $this->databaseType = self::GEOIP_COUNTRY_EDITION;
$this->record_length = self::STANDARD_RECORD_LENGTH;
- if ($this->flags & self::GEOIP_SHARED_MEMORY) {
- $offset = @shmop_size($this->shmid) - 3;
- for ($i = 0; $i < self::STRUCTURE_INFO_MAX_SIZE; $i++) {
- $delim = @shmop_read($this->shmid, $offset, 3);
+
+ if ( $this->flags & self::GEOIP_SHARED_MEMORY ) {
+ $offset = @shmop_size( $this->shmid ) - 3;
+
+ for ( $i = 0; $i < self::STRUCTURE_INFO_MAX_SIZE; $i++ ) {
+ $delim = @shmop_read( $this->shmid, $offset, 3 );
$offset += 3;
- if ($delim == (chr(255) . chr(255) . chr(255))) {
- $this->databaseType = ord(@shmop_read($this->shmid, $offset, 1));
- if ($this->databaseType >= 106) {
+
+ if ( $delim == ( chr( 255 ) . chr( 255 ) . chr( 255 ) ) ) {
+ $this->databaseType = ord( @shmop_read( $this->shmid, $offset, 1 ) );
+
+ if ( $this->databaseType >= 106 ) {
$this->databaseType -= 105;
}
+
$offset++;
- if ($this->databaseType == self::GEOIP_REGION_EDITION_REV0) {
+ if ( $this->databaseType == self::GEOIP_REGION_EDITION_REV0 ) {
$this->databaseSegments = self::GEOIP_STATE_BEGIN_REV0;
- } elseif ($this->databaseType == self::GEOIP_REGION_EDITION_REV1) {
+ } elseif ( $this->databaseType == self::GEOIP_REGION_EDITION_REV1 ) {
$this->databaseSegments = self::GEOIP_STATE_BEGIN_REV1;
- } elseif (($this->databaseType == self::GEOIP_CITY_EDITION_REV0)
- || ($this->databaseType == self::GEOIP_CITY_EDITION_REV1)
- || ($this->databaseType == self::GEOIP_ORG_EDITION)
- || ($this->databaseType == self::GEOIP_ORG_EDITION_V6)
- || ($this->databaseType == self::GEOIP_DOMAIN_EDITION)
- || ($this->databaseType == self::GEOIP_DOMAIN_EDITION_V6)
- || ($this->databaseType == self::GEOIP_ISP_EDITION)
- || ($this->databaseType == self::GEOIP_ISP_EDITION_V6)
- || ($this->databaseType == self::GEOIP_USERTYPE_EDITION)
- || ($this->databaseType == self::GEOIP_USERTYPE_EDITION_V6)
- || ($this->databaseType == self::GEOIP_LOCATIONA_EDITION)
- || ($this->databaseType == self::GEOIP_ACCURACYRADIUS_EDITION)
- || ($this->databaseType == self::GEOIP_CITY_EDITION_REV0_V6)
- || ($this->databaseType == self::GEOIP_CITY_EDITION_REV1_V6)
- || ($this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1)
- || ($this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1_V6)
- || ($this->databaseType == self::GEOIP_ASNUM_EDITION)
- || ($this->databaseType == self::GEOIP_ASNUM_EDITION_V6)
+ } elseif ( ( $this->databaseType == self::GEOIP_CITY_EDITION_REV0 )
+ || ( $this->databaseType == self::GEOIP_CITY_EDITION_REV1 )
+ || ( $this->databaseType == self::GEOIP_ORG_EDITION )
+ || ( $this->databaseType == self::GEOIP_ORG_EDITION_V6 )
+ || ( $this->databaseType == self::GEOIP_DOMAIN_EDITION )
+ || ( $this->databaseType == self::GEOIP_DOMAIN_EDITION_V6 )
+ || ( $this->databaseType == self::GEOIP_ISP_EDITION )
+ || ( $this->databaseType == self::GEOIP_ISP_EDITION_V6 )
+ || ( $this->databaseType == self::GEOIP_USERTYPE_EDITION )
+ || ( $this->databaseType == self::GEOIP_USERTYPE_EDITION_V6 )
+ || ( $this->databaseType == self::GEOIP_LOCATIONA_EDITION )
+ || ( $this->databaseType == self::GEOIP_ACCURACYRADIUS_EDITION )
+ || ( $this->databaseType == self::GEOIP_CITY_EDITION_REV0_V6 )
+ || ( $this->databaseType == self::GEOIP_CITY_EDITION_REV1_V6 )
+ || ( $this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1 )
+ || ( $this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1_V6 )
+ || ( $this->databaseType == self::GEOIP_ASNUM_EDITION )
+ || ( $this->databaseType == self::GEOIP_ASNUM_EDITION_V6 )
) {
$this->databaseSegments = 0;
- $buf = @shmop_read($this->shmid, $offset, self::SEGMENT_RECORD_LENGTH);
- for ($j = 0; $j < self::SEGMENT_RECORD_LENGTH; $j++) {
- $this->databaseSegments += (ord($buf[$j]) << ($j * 8));
+ $buf = @shmop_read( $this->shmid, $offset, self::SEGMENT_RECORD_LENGTH );
+
+ for ( $j = 0; $j < self::SEGMENT_RECORD_LENGTH; $j++ ) {
+ $this->databaseSegments += ( ord( $buf[ $j ] ) << ( $j * 8 ) );
}
- if (($this->databaseType == self::GEOIP_ORG_EDITION)
- || ($this->databaseType == self::GEOIP_ORG_EDITION_V6)
- || ($this->databaseType == self::GEOIP_DOMAIN_EDITION)
- || ($this->databaseType == self::GEOIP_DOMAIN_EDITION_V6)
- || ($this->databaseType == self::GEOIP_ISP_EDITION)
- || ($this->databaseType == self::GEOIP_ISP_EDITION_V6)
+
+ if ( ( $this->databaseType == self::GEOIP_ORG_EDITION )
+ || ( $this->databaseType == self::GEOIP_ORG_EDITION_V6 )
+ || ( $this->databaseType == self::GEOIP_DOMAIN_EDITION )
+ || ( $this->databaseType == self::GEOIP_DOMAIN_EDITION_V6 )
+ || ( $this->databaseType == self::GEOIP_ISP_EDITION )
+ || ( $this->databaseType == self::GEOIP_ISP_EDITION_V6 )
) {
$this->record_length = self::ORG_RECORD_LENGTH;
}
}
+
break;
} else {
$offset -= 4;
}
}
- if (($this->databaseType == self::GEOIP_COUNTRY_EDITION) ||
- ($this->databaseType == self::GEOIP_COUNTRY_EDITION_V6) ||
- ($this->databaseType == self::GEOIP_PROXY_EDITION) ||
- ($this->databaseType == self::GEOIP_NETSPEED_EDITION)
+ if ( ( $this->databaseType == self::GEOIP_COUNTRY_EDITION )
+ || ( $this->databaseType == self::GEOIP_COUNTRY_EDITION_V6 )
+ || ( $this->databaseType == self::GEOIP_PROXY_EDITION )
+ || ( $this->databaseType == self::GEOIP_NETSPEED_EDITION )
) {
$this->databaseSegments = self::GEOIP_COUNTRY_BEGIN;
}
} else {
- $filepos = ftell($this->filehandle);
- fseek($this->filehandle, -3, SEEK_END);
- for ($i = 0; $i < self::STRUCTURE_INFO_MAX_SIZE; $i++) {
- $delim = fread($this->filehandle, 3);
- if ($delim == (chr(255) . chr(255) . chr(255))) {
- $this->databaseType = ord(fread($this->filehandle, 1));
- if ($this->databaseType >= 106) {
+ $filepos = ftell( $this->filehandle );
+ fseek( $this->filehandle, -3, SEEK_END );
+
+ for ( $i = 0; $i < self::STRUCTURE_INFO_MAX_SIZE; $i++ ) {
+
+ $delim = fread( $this->filehandle, 3 );
+ if ( $delim == ( chr( 255 ) . chr( 255 ) . chr( 255 ) ) ) {
+
+ $this->databaseType = ord( fread( $this->filehandle, 1 ) );
+ if ( $this->databaseType >= 106 ) {
$this->databaseType -= 105;
}
- if ($this->databaseType == self::GEOIP_REGION_EDITION_REV0) {
+
+ if ( $this->databaseType == self::GEOIP_REGION_EDITION_REV0 ) {
$this->databaseSegments = self::GEOIP_STATE_BEGIN_REV0;
- } elseif ($this->databaseType == self::GEOIP_REGION_EDITION_REV1) {
+ } elseif ( $this->databaseType == self::GEOIP_REGION_EDITION_REV1 ) {
$this->databaseSegments = self::GEOIP_STATE_BEGIN_REV1;
- } elseif (($this->databaseType == self::GEOIP_CITY_EDITION_REV0)
- || ($this->databaseType == self::GEOIP_CITY_EDITION_REV1)
- || ($this->databaseType == self::GEOIP_CITY_EDITION_REV0_V6)
- || ($this->databaseType == self::GEOIP_CITY_EDITION_REV1_V6)
- || ($this->databaseType == self::GEOIP_ORG_EDITION)
- || ($this->databaseType == self::GEOIP_DOMAIN_EDITION)
- || ($this->databaseType == self::GEOIP_ISP_EDITION)
- || ($this->databaseType == self::GEOIP_ORG_EDITION_V6)
- || ($this->databaseType == self::GEOIP_DOMAIN_EDITION_V6)
- || ($this->databaseType == self::GEOIP_ISP_EDITION_V6)
- || ($this->databaseType == self::GEOIP_LOCATIONA_EDITION)
- || ($this->databaseType == self::GEOIP_ACCURACYRADIUS_EDITION)
- || ($this->databaseType == self::GEOIP_CITY_EDITION_REV0_V6)
- || ($this->databaseType == self::GEOIP_CITY_EDITION_REV1_V6)
- || ($this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1)
- || ($this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1_V6)
- || ($this->databaseType == self::GEOIP_USERTYPE_EDITION)
- || ($this->databaseType == self::GEOIP_USERTYPE_EDITION_V6)
- || ($this->databaseType == self::GEOIP_ASNUM_EDITION)
- || ($this->databaseType == self::GEOIP_ASNUM_EDITION_V6)
+ } elseif ( ( $this->databaseType == self::GEOIP_CITY_EDITION_REV0 )
+ || ( $this->databaseType == self::GEOIP_CITY_EDITION_REV1 )
+ || ( $this->databaseType == self::GEOIP_CITY_EDITION_REV0_V6 )
+ || ( $this->databaseType == self::GEOIP_CITY_EDITION_REV1_V6 )
+ || ( $this->databaseType == self::GEOIP_ORG_EDITION )
+ || ( $this->databaseType == self::GEOIP_DOMAIN_EDITION )
+ || ( $this->databaseType == self::GEOIP_ISP_EDITION )
+ || ( $this->databaseType == self::GEOIP_ORG_EDITION_V6 )
+ || ( $this->databaseType == self::GEOIP_DOMAIN_EDITION_V6 )
+ || ( $this->databaseType == self::GEOIP_ISP_EDITION_V6 )
+ || ( $this->databaseType == self::GEOIP_LOCATIONA_EDITION )
+ || ( $this->databaseType == self::GEOIP_ACCURACYRADIUS_EDITION )
+ || ( $this->databaseType == self::GEOIP_CITY_EDITION_REV0_V6 )
+ || ( $this->databaseType == self::GEOIP_CITY_EDITION_REV1_V6 )
+ || ( $this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1 )
+ || ( $this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1_V6 )
+ || ( $this->databaseType == self::GEOIP_USERTYPE_EDITION )
+ || ( $this->databaseType == self::GEOIP_USERTYPE_EDITION_V6 )
+ || ( $this->databaseType == self::GEOIP_ASNUM_EDITION )
+ || ( $this->databaseType == self::GEOIP_ASNUM_EDITION_V6 )
) {
$this->databaseSegments = 0;
- $buf = fread($this->filehandle, self::SEGMENT_RECORD_LENGTH);
- for ($j = 0; $j < self::SEGMENT_RECORD_LENGTH; $j++) {
- $this->databaseSegments += (ord($buf[$j]) << ($j * 8));
+ $buf = fread( $this->filehandle, self::SEGMENT_RECORD_LENGTH );
+
+ for ( $j = 0; $j < self::SEGMENT_RECORD_LENGTH; $j++ ) {
+ $this->databaseSegments += ( ord( $buf[ $j ] ) << ( $j * 8 ) );
}
- if (($this->databaseType == self::GEOIP_ORG_EDITION)
- || ($this->databaseType == self::GEOIP_DOMAIN_EDITION)
- || ($this->databaseType == self::GEOIP_ISP_EDITION)
- || ($this->databaseType == self::GEOIP_ORG_EDITION_V6)
- || ($this->databaseType == self::GEOIP_DOMAIN_EDITION_V6)
- || ($this->databaseType == self::GEOIP_ISP_EDITION_V6)
+
+ if ( ( $this->databaseType == self::GEOIP_ORG_EDITION )
+ || ( $this->databaseType == self::GEOIP_DOMAIN_EDITION )
+ || ( $this->databaseType == self::GEOIP_ISP_EDITION )
+ || ( $this->databaseType == self::GEOIP_ORG_EDITION_V6 )
+ || ( $this->databaseType == self::GEOIP_DOMAIN_EDITION_V6 )
+ || ( $this->databaseType == self::GEOIP_ISP_EDITION_V6 )
) {
$this->record_length = self::ORG_RECORD_LENGTH;
}
}
+
break;
} else {
- fseek($this->filehandle, -4, SEEK_CUR);
+ fseek( $this->filehandle, -4, SEEK_CUR );
}
}
- if (($this->databaseType == self::GEOIP_COUNTRY_EDITION) ||
- ($this->databaseType == self::GEOIP_COUNTRY_EDITION_V6) ||
- ($this->databaseType == self::GEOIP_PROXY_EDITION) ||
- ($this->databaseType == self::GEOIP_NETSPEED_EDITION)
+
+ if ( ( $this->databaseType == self::GEOIP_COUNTRY_EDITION )
+ || ( $this->databaseType == self::GEOIP_COUNTRY_EDITION_V6 )
+ || ( $this->databaseType == self::GEOIP_PROXY_EDITION )
+ || ( $this->databaseType == self::GEOIP_NETSPEED_EDITION )
) {
$this->databaseSegments = self::GEOIP_COUNTRY_BEGIN;
}
- fseek($this->filehandle, $filepos, SEEK_SET);
+
+ fseek( $this->filehandle, $filepos, SEEK_SET );
}
return $this;
@@ -1263,92 +1280,109 @@ class WC_Geo_IP {
private function _common_get_record( $seek_country ) {
// workaround php's broken substr, strpos, etc handling with
// mbstring.func_overload and mbstring.internal_encoding
- $mbExists = extension_loaded('mbstring');
- if ($mbExists) {
+ $mbExists = extension_loaded( 'mbstring' );
+ if ( $mbExists ) {
$enc = mb_internal_encoding();
- mb_internal_encoding('ISO-8859-1');
+ mb_internal_encoding( 'ISO-8859-1' );
}
- $record_pointer = $seek_country + (2 * $this->record_length - 1) * $this->databaseSegments;
+ $record_pointer = $seek_country + ( 2 * $this->record_length - 1 ) * $this->databaseSegments;
- if ($this->flags & self::GEOIP_MEMORY_CACHE) {
- $record_buf = substr($this->memory_buffer, $record_pointer, FULL_RECORD_LENGTH);
- } elseif ($this->flags & self::GEOIP_SHARED_MEMORY) {
- $record_buf = @shmop_read($this->shmid, $record_pointer, FULL_RECORD_LENGTH);
+ if ( $this->flags & self::GEOIP_MEMORY_CACHE ) {
+ $record_buf = substr( $this->memory_buffer, $record_pointer, FULL_RECORD_LENGTH );
+ } elseif ( $this->flags & self::GEOIP_SHARED_MEMORY ) {
+ $record_buf = @shmop_read( $this->shmid, $record_pointer, FULL_RECORD_LENGTH );
} else {
- fseek($this->filehandle, $record_pointer, SEEK_SET);
- $record_buf = fread($this->filehandle, FULL_RECORD_LENGTH);
+ fseek( $this->filehandle, $record_pointer, SEEK_SET );
+ $record_buf = fread( $this->filehandle, FULL_RECORD_LENGTH );
}
- $record = new WC_Geo_IP_Record();
- $record_buf_pos = 0;
- $char = ord(substr($record_buf, $record_buf_pos, 1));
- $record->country_code = $this->GEOIP_COUNTRY_CODES[$char];
- $record->country_code3 = $this->GEOIP_COUNTRY_CODES3[$char];
- $record->country_name = $this->GEOIP_COUNTRY_NAMES[$char];
- $record->continent_code = $this->GEOIP_CONTINENT_CODES[$char];
+
+ $record = new WC_Geo_IP_Record();
+ $record_buf_pos = 0;
+ $char = ord( substr( $record_buf, $record_buf_pos, 1 ) );
+ $record->country_code = $this->GEOIP_COUNTRY_CODES[ $char ];
+ $record->country_code3 = $this->GEOIP_COUNTRY_CODES3[ $char ];
+ $record->country_name = $this->GEOIP_COUNTRY_NAMES[ $char ];
+ $record->continent_code = $this->GEOIP_CONTINENT_CODES[ $char ];
+ $str_length = 0;
+
$record_buf_pos++;
- $str_length = 0;
// Get region
- $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1));
- while ($char != 0) {
+ $char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
+ while ( $char != 0 ) {
$str_length++;
- $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1));
+ $char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
}
- if ($str_length > 0) {
- $record->region = substr($record_buf, $record_buf_pos, $str_length);
+
+ if ( $str_length > 0 ) {
+ $record->region = substr( $record_buf, $record_buf_pos, $str_length );
}
+
$record_buf_pos += $str_length + 1;
- $str_length = 0;
+ $str_length = 0;
+
// Get city
- $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1));
- while ($char != 0) {
+ $char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
+ while ( $char != 0 ) {
$str_length++;
- $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1));
+ $char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
}
- if ($str_length > 0) {
- $record->city = substr($record_buf, $record_buf_pos, $str_length);
+
+ if ( $str_length > 0 ) {
+ $record->city = substr( $record_buf, $record_buf_pos, $str_length );
}
+
$record_buf_pos += $str_length + 1;
- $str_length = 0;
+ $str_length = 0;
+
// Get postal code
- $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1));
- while ($char != 0) {
+ $char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
+ while ( $char != 0 ) {
$str_length++;
- $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1));
+ $char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
}
- if ($str_length > 0) {
- $record->postal_code = substr($record_buf, $record_buf_pos, $str_length);
+
+ if ( $str_length > 0 ) {
+ $record->postal_code = substr( $record_buf, $record_buf_pos, $str_length );
}
+
$record_buf_pos += $str_length + 1;
- $str_length = 0;
+
// Get latitude and longitude
- $latitude = 0;
+ $latitude = 0;
$longitude = 0;
- for ($j = 0; $j < 3; ++$j) {
- $char = ord(substr($record_buf, $record_buf_pos++, 1));
- $latitude += ($char << ($j * 8));
+ for ( $j = 0; $j < 3; ++$j ) {
+ $char = ord( substr( $record_buf, $record_buf_pos++, 1 ) );
+ $latitude += ( $char << ( $j * 8 ) );
}
- $record->latitude = ($latitude / 10000) - 180;
- for ($j = 0; $j < 3; ++$j) {
- $char = ord(substr($record_buf, $record_buf_pos++, 1));
- $longitude += ($char << ($j * 8));
+
+ $record->latitude = ( $latitude / 10000 ) - 180;
+
+ for ( $j = 0; $j < 3; ++$j ) {
+ $char = ord( substr( $record_buf, $record_buf_pos++, 1 ) );
+ $longitude += ( $char << ( $j * 8 ) );
}
- $record->longitude = ($longitude / 10000) - 180;
- if (self::GEOIP_CITY_EDITION_REV1 == $this->databaseType) {
+
+ $record->longitude = ( $longitude / 10000 ) - 180;
+
+ if ( self::GEOIP_CITY_EDITION_REV1 == $this->databaseType ) {
$metroarea_combo = 0;
- if ($record->country_code == "US") {
- for ($j = 0; $j < 3; ++$j) {
- $char = ord(substr($record_buf, $record_buf_pos++, 1));
- $metroarea_combo += ($char << ($j * 8));
+ if ( $record->country_code == "US" ) {
+ for ( $j = 0; $j < 3; ++$j ) {
+ $char = ord( substr( $record_buf, $record_buf_pos++, 1 ) );
+ $metroarea_combo += ( $char << ( $j * 8 ) );
}
- $record->metro_code = $record->dma_code = floor($metroarea_combo / 1000);
- $record->area_code = $metroarea_combo % 1000;
+
+ $record->metro_code = $record->dma_code = floor( $metroarea_combo / 1000 );
+ $record->area_code = $metroarea_combo % 1000;
}
}
- if ($mbExists) {
- mb_internal_encoding($enc);
+
+ if ( $mbExists ) {
+ mb_internal_encoding( $enc );
}
+
return $record;
}
@@ -1357,48 +1391,55 @@ class WC_Geo_IP {
if ( $seek_country == $this->databaseSegments ) {
return null;
}
+
return $this->_common_get_record( $seek_country );
}
private function _geoip_seek_country( $ipnum ) {
$offset = 0;
- for ($depth = 31; $depth >= 0; --$depth) {
- if ($this->flags & self::GEOIP_MEMORY_CACHE) {
+ for ( $depth = 31; $depth >= 0; --$depth ) {
+ if ( $this->flags & self::GEOIP_MEMORY_CACHE ) {
$buf = $this->_safe_substr(
$this->memory_buffer,
2 * $this->record_length * $offset,
2 * $this->record_length
);
- } elseif ($this->flags & self::GEOIP_SHARED_MEMORY) {
+ } elseif ( $this->flags & self::GEOIP_SHARED_MEMORY ) {
$buf = @shmop_read(
$this->shmid,
2 * $this->record_length * $offset,
2 * $this->record_length
);
} else {
- fseek($this->filehandle, 2 * $this->record_length * $offset, SEEK_SET) == 0
- or trigger_error("GeoIP API: fseek failed", E_USER_ERROR);
- $buf = fread($this->filehandle, 2 * $this->record_length);
+ fseek( $this->filehandle, 2 * $this->record_length * $offset, SEEK_SET ) == 0
+ or trigger_error( "GeoIP API: fseek failed", E_USER_ERROR );
+
+ $buf = fread( $this->filehandle, 2 * $this->record_length );
}
- $x = array(0, 0);
- for ($i = 0; $i < 2; ++$i) {
- for ($j = 0; $j < $this->record_length; ++$j) {
- $x[$i] += ord($buf[$this->record_length * $i + $j]) << ($j * 8);
+
+ $x = array( 0, 0 );
+ for ( $i = 0; $i < 2; ++$i ) {
+ for ( $j = 0; $j < $this->record_length; ++$j ) {
+ $x[ $i ] += ord( $buf[ $this->record_length * $i + $j ] ) << ( $j * 8 );
}
}
- if ($ipnum & (1 << $depth)) {
- if ($x[1] >= $this->databaseSegments) {
+ if ( $ipnum & ( 1 << $depth ) ) {
+ if ( $x[1] >= $this->databaseSegments ) {
return $x[1];
}
+
$offset = $x[1];
} else {
- if ($x[0] >= $this->databaseSegments) {
+ if ( $x[0] >= $this->databaseSegments ) {
return $x[0];
}
+
$offset = $x[0];
}
}
- trigger_error("GeoIP API: Error traversing database - perhaps it is corrupt?", E_USER_ERROR);
+
+ trigger_error( "GeoIP API: Error traversing database - perhaps it is corrupt?", E_USER_ERROR );
+
return false;
}
@@ -1406,6 +1447,7 @@ class WC_Geo_IP {
if ( $addr == null ) {
return 0;
}
+
$ipnum = ip2long( $addr );
return $this->_get_record( $ipnum );
}
@@ -1427,6 +1469,7 @@ class WC_Geo_IP {
return $this->GEOIP_COUNTRY_CODES[ $country_id ];
}
}
+
return false;
}
diff --git a/includes/class-wc-product-factory.php b/includes/class-wc-product-factory.php
index 62d11021279..9709aaf82c7 100644
--- a/includes/class-wc-product-factory.php
+++ b/includes/class-wc-product-factory.php
@@ -75,7 +75,7 @@ class WC_Product_Factory {
/**
* Get the product object
* @param mixed $the_product
- * @uses WP_POST
+ * @uses WP_Post
* @return WP_Post|bool false on failure
*/
private function get_product_object( $the_product ) {
diff --git a/includes/class-wc-product-variable.php b/includes/class-wc-product-variable.php
index a08ddb8d8da..28970b23c81 100644
--- a/includes/class-wc-product-variable.php
+++ b/includes/class-wc-product-variable.php
@@ -43,20 +43,20 @@ class WC_Product_Variable extends WC_Product {
return apply_filters( 'woocommerce_product_add_to_cart_text', __( 'Select options', 'woocommerce' ), $this );
}
- /**
- * Get total stock.
- *
- * This is the stock of parent and children combined.
- *
- * @access public
- * @return int
- */
- public function get_total_stock() {
- if ( empty( $this->total_stock ) ) {
- $transient_name = 'wc_product_total_stock_' . $this->id . WC_Cache_Helper::get_transient_version( 'product' );
+ /**
+ * Get total stock.
+ *
+ * This is the stock of parent and children combined.
+ *
+ * @access public
+ * @return int
+ */
+ public function get_total_stock() {
+ if ( empty( $this->total_stock ) ) {
+ $transient_name = 'wc_product_total_stock_' . $this->id . WC_Cache_Helper::get_transient_version( 'product' );
- if ( false === ( $this->total_stock = get_transient( $transient_name ) ) ) {
- $this->total_stock = max( 0, wc_stock_amount( $this->stock ) );
+ if ( false === ( $this->total_stock = get_transient( $transient_name ) ) ) {
+ $this->total_stock = max( 0, wc_stock_amount( $this->stock ) );
if ( sizeof( $this->get_children() ) > 0 ) {
foreach ( $this->get_children() as $child_id ) {
@@ -70,7 +70,7 @@ class WC_Product_Variable extends WC_Product {
}
}
return wc_stock_amount( $this->total_stock );
- }
+ }
/**
* Set stock level of the product.
@@ -134,8 +134,8 @@ class WC_Product_Variable extends WC_Product {
$transient_name = 'wc_product_children_ids_' . $this->id . WC_Cache_Helper::get_transient_version( 'product' );
$this->children = get_transient( $transient_name );
- if ( empty( $this->children ) ) {
- $args = array(
+ if ( empty( $this->children ) ) {
+ $args = array(
'post_parent' => $this->id,
'post_type' => 'product_variation',
'orderby' => 'menu_order',
@@ -143,7 +143,7 @@ class WC_Product_Variable extends WC_Product {
'fields' => 'ids',
'post_status' => 'publish',
'numberposts' => -1
- );
+ );
$this->children = get_posts( $args );
@@ -330,32 +330,32 @@ class WC_Product_Variable extends WC_Product {
return apply_filters( 'woocommerce_get_price_html', $price, $this );
}
- /**
- * Return an array of attributes used for variations, as well as their possible values.
- *
- * @access public
- * @return array of attributes and their available values
- */
- public function get_variation_attributes() {
- $variation_attributes = array();
+ /**
+ * Return an array of attributes used for variations, as well as their possible values.
+ *
+ * @access public
+ * @return array of attributes and their available values
+ */
+ public function get_variation_attributes() {
+ $variation_attributes = array();
- if ( ! $this->has_child() ) {
- return $variation_attributes;
- }
+ if ( ! $this->has_child() ) {
+ return $variation_attributes;
+ }
- $attributes = $this->get_attributes();
+ $attributes = $this->get_attributes();
- foreach ( $attributes as $attribute ) {
- if ( ! $attribute['is_variation'] ) {
- continue;
- }
+ foreach ( $attributes as $attribute ) {
+ if ( ! $attribute['is_variation'] ) {
+ continue;
+ }
- $values = array();
- $attribute_field_name = 'attribute_' . sanitize_title( $attribute['name'] );
+ $values = array();
+ $attribute_field_name = 'attribute_' . sanitize_title( $attribute['name'] );
- foreach ( $this->get_children() as $child_id ) {
+ foreach ( $this->get_children() as $child_id ) {
- $variation = $this->get_child( $child_id );
+ $variation = $this->get_child( $child_id );
if ( ! empty( $variation->variation_id ) ) {
@@ -365,22 +365,22 @@ class WC_Product_Variable extends WC_Product {
$child_variation_attributes = $variation->get_variation_attributes();
- foreach ( $child_variation_attributes as $name => $value ) {
- if ( $name == $attribute_field_name ) {
- $values[] = sanitize_title( $value );
- }
- }
- }
- }
+ foreach ( $child_variation_attributes as $name => $value ) {
+ if ( $name == $attribute_field_name ) {
+ $values[] = sanitize_title( $value );
+ }
+ }
+ }
+ }
- // empty value indicates that all options for given attribute are available
- if ( in_array( '', $values ) ) {
+ // empty value indicates that all options for given attribute are available
+ if ( in_array( '', $values ) ) {
- $values = array();
+ $values = array();
- // Get all options
- if ( $attribute['is_taxonomy'] ) {
- $post_terms = wp_get_post_terms( $this->id, $attribute['name'] );
+ // Get all options
+ if ( $attribute['is_taxonomy'] ) {
+ $post_terms = wp_get_post_terms( $this->id, $attribute['name'] );
foreach ( $post_terms as $term )
$values[] = $term->slug;
} else {
@@ -390,46 +390,46 @@ class WC_Product_Variable extends WC_Product {
$values = array_unique( $values );
// Order custom attributes (non taxonomy) as defined
- } elseif ( ! $attribute['is_taxonomy'] ) {
+ } elseif ( ! $attribute['is_taxonomy'] ) {
- $option_names = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
- $option_slugs = $values;
- $values = array();
+ $option_names = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
+ $option_slugs = $values;
+ $values = array();
- foreach ( $option_names as $option_name ) {
- if ( in_array( sanitize_title( $option_name ), $option_slugs ) )
- $values[] = $option_name;
- }
- }
+ foreach ( $option_names as $option_name ) {
+ if ( in_array( sanitize_title( $option_name ), $option_slugs ) )
+ $values[] = $option_name;
+ }
+ }
- $variation_attributes[ $attribute['name'] ] = array_unique( $values );
- }
+ $variation_attributes[ $attribute['name'] ] = array_unique( $values );
+ }
- return $variation_attributes;
- }
+ return $variation_attributes;
+ }
- /**
- * If set, get the default attributes for a variable product.
- *
- * @access public
- * @return array
- */
- public function get_variation_default_attributes() {
+ /**
+ * If set, get the default attributes for a variable product.
+ *
+ * @access public
+ * @return array
+ */
+ public function get_variation_default_attributes() {
- $default = isset( $this->default_attributes ) ? $this->default_attributes : '';
+ $default = isset( $this->default_attributes ) ? $this->default_attributes : '';
- return apply_filters( 'woocommerce_product_default_attributes', (array) maybe_unserialize( $default ), $this );
- }
+ return apply_filters( 'woocommerce_product_default_attributes', (array) maybe_unserialize( $default ), $this );
+ }
- /**
- * Get an array of available variations for the current product.
- *
- * @access public
- * @return array
- */
- public function get_available_variations() {
+ /**
+ * Get an array of available variations for the current product.
+ *
+ * @access public
+ * @return array
+ */
+ public function get_available_variations() {
- $available_variations = array();
+ $available_variations = array();
foreach ( $this->get_children() as $child_id ) {
@@ -493,7 +493,7 @@ class WC_Product_Variable extends WC_Product {
}
return $available_variations;
- }
+ }
/**
* Sync variable product prices with the children lowest/highest prices.
diff --git a/includes/class-wc-query.php b/includes/class-wc-query.php
index 867f5779f16..e9f687e81c1 100644
--- a/includes/class-wc-query.php
+++ b/includes/class-wc-query.php
@@ -35,7 +35,7 @@ class WC_Query {
/** @public array Product IDs that match the layered nav + price filter */
public $post__in = array();
- /** @public array The meta query for the page */
+ /** @public array|string The meta query for the page */
public $meta_query = '';
/** @public array Post IDs matching layered nav only */
diff --git a/includes/class-wc-tracker.php b/includes/class-wc-tracker.php
index 38705b5b0f5..ffb2d4bbe19 100644
--- a/includes/class-wc-tracker.php
+++ b/includes/class-wc-tracker.php
@@ -244,8 +244,8 @@ class WC_Tracker {
* @return array
*/
private static function get_user_counts() {
- $user_count = array();
- $user_count_data = count_users();
+ $user_count = array();
+ $user_count_data = count_users();
$user_count['total'] = $user_count_data['total_users'];
// Get user count based on user role
@@ -261,14 +261,15 @@ class WC_Tracker {
* @return array
*/
private static function get_product_counts() {
- $product_count = array();
- $product_count_data = wp_count_posts( 'product' );
+ $product_count = array();
+ $product_count_data = wp_count_posts( 'product' );
$product_count['total'] = $product_count_data->publish;
$product_statuses = get_terms( 'product_type', array( 'hide_empty' => 0 ) );
foreach ( $product_statuses as $product_status ) {
$product_count[ $product_status->name ] = $product_status->count;
}
+
return $product_count;
}
@@ -277,12 +278,13 @@ class WC_Tracker {
* @return array
*/
private static function get_order_counts() {
- $order_count = array();
+ $order_count = array();
$order_count_data = wp_count_posts( 'shop_order' );
foreach ( wc_get_order_statuses() as $status_slug => $status_name ) {
$order_count[ $status_slug ] = $order_count_data->{ $status_slug };
}
+
return $order_count;
}
@@ -292,12 +294,13 @@ class WC_Tracker {
*/
private static function get_active_payment_gateways() {
$active_gateways = array();
- $gateways = WC()->payment_gateways->payment_gateways();
+ $gateways = WC()->payment_gateways->payment_gateways();
foreach ( $gateways as $id => $gateway ) {
if ( isset( $gateway->enabled ) && $gateway->enabled == 'yes' ) {
$active_gateways[ $id ] = array( 'title' => $gateway->title, 'supports' => $gateway->supports );
}
}
+
return $active_gateways;
}
@@ -306,13 +309,14 @@ class WC_Tracker {
* @return array
*/
private static function get_active_shipping_methods() {
- $active_methods = array();
+ $active_methods = array();
$shipping_methods = WC()->shipping->get_shipping_methods();
foreach ( $shipping_methods as $id => $shipping_method ) {
if ( isset( $shipping_method->enabled ) && $shipping_method->enabled == 'yes' ) {
$active_methods[ $id ] = array( 'title' => $shipping_method->title, 'tax_status' => $shipping_method->tax_status );
}
}
+
return $active_methods;
}
@@ -322,23 +326,23 @@ class WC_Tracker {
*/
private static function get_all_woocommerce_options_values() {
return array(
- 'version' => WC()->version,
- 'currency' => get_woocommerce_currency(),
- 'base_location' => WC()->countries->get_base_country(),
- 'selling_locations' => WC()->countries->get_allowed_countries(),
- 'api_enabled' => get_option( 'woocommerce_api_enabled' ),
- 'weight_unit' => get_option( 'woocommerce_weight_unit' ),
- 'dimension_unit' => get_option( 'woocommerce_dimension_unit' ),
- 'download_method' => get_option( 'woocommerce_file_download_method' ),
- 'download_require_login' => get_option( 'woocommerce_downloads_require_login' ),
- 'calc_taxes' => get_option( 'woocommerce_calc_taxes' ),
- 'coupons_enabled' => get_option( 'woocommerce_enable_coupons' ),
- 'guest_checkout' => get_option( 'woocommerce_enable_guest_checkout'),
- 'secure_checkout' => get_option( 'woocommerce_force_ssl_checkout' ),
- 'enable_signup_and_login_from_checkout' => get_option( 'woocommerce_enable_signup_and_login_from_checkout' ),
- 'enable_myaccount_registration' => get_option( 'woocommerce_enable_myaccount_registration' ),
- 'registration_generate_username' => get_option( 'woocommerce_registration_generate_username' ),
- 'registration_generate_password' => get_option( 'woocommerce_registration_generate_password' ),
+ 'version' => WC()->version,
+ 'currency' => get_woocommerce_currency(),
+ 'base_location' => WC()->countries->get_base_country(),
+ 'selling_locations' => WC()->countries->get_allowed_countries(),
+ 'api_enabled' => get_option( 'woocommerce_api_enabled' ),
+ 'weight_unit' => get_option( 'woocommerce_weight_unit' ),
+ 'dimension_unit' => get_option( 'woocommerce_dimension_unit' ),
+ 'download_method' => get_option( 'woocommerce_file_download_method' ),
+ 'download_require_login' => get_option( 'woocommerce_downloads_require_login' ),
+ 'calc_taxes' => get_option( 'woocommerce_calc_taxes' ),
+ 'coupons_enabled' => get_option( 'woocommerce_enable_coupons' ),
+ 'guest_checkout' => get_option( 'woocommerce_enable_guest_checkout'),
+ 'secure_checkout' => get_option( 'woocommerce_force_ssl_checkout' ),
+ 'enable_signup_and_login_from_checkout' => get_option( 'woocommerce_enable_signup_and_login_from_checkout' ),
+ 'enable_myaccount_registration' => get_option( 'woocommerce_enable_myaccount_registration' ),
+ 'registration_generate_username' => get_option( 'woocommerce_registration_generate_username' ),
+ 'registration_generate_password' => get_option( 'woocommerce_registration_generate_password' ),
);
}
@@ -370,7 +374,8 @@ class WC_Tracker {
} else {
$theme_file = false;
}
- if ( $theme_file ) {
+
+ if ( $theme_file !== false ) {
$override_data[] = basename( $theme_file );
}
}
diff --git a/includes/emails/class-wc-email-customer-completed-order.php b/includes/emails/class-wc-email-customer-completed-order.php
index 0ab8a9696a9..b0c20444dea 100644
--- a/includes/emails/class-wc-email-customer-completed-order.php
+++ b/includes/emails/class-wc-email-customer-completed-order.php
@@ -11,11 +11,11 @@ if ( ! class_exists( 'WC_Email_Customer_Completed_Order' ) ) :
*
* Order complete emails are sent to the customer when the order is marked complete and usual indicates that the order has been shipped.
*
- * @class WC_Email_Customer_Completed_Order
- * @version 2.0.0
- * @package WooCommerce/Classes/Emails
- * @author WooThemes
- * @extends WC_Email
+ * @class WC_Email_Customer_Completed_Order
+ * @version 2.0.0
+ * @package WooCommerce/Classes/Emails
+ * @author WooThemes
+ * @extends WC_Email
*/
class WC_Email_Customer_Completed_Order extends WC_Email {
@@ -24,15 +24,15 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
*/
function __construct() {
- $this->id = 'customer_completed_order';
- $this->title = __( 'Completed order', 'woocommerce' );
- $this->description = __( 'Order complete emails are sent to customers when their orders are marked completed and usually indicate that their orders have been shipped.', 'woocommerce' );
+ $this->id = 'customer_completed_order';
+ $this->title = __( 'Completed order', 'woocommerce' );
+ $this->description = __( 'Order complete emails are sent to customers when their orders are marked completed and usually indicate that their orders have been shipped.', 'woocommerce' );
- $this->heading = __( 'Your order is complete', 'woocommerce' );
- $this->subject = __( 'Your {site_title} order from {order_date} is complete', 'woocommerce' );
+ $this->heading = __( 'Your order is complete', 'woocommerce' );
+ $this->subject = __( 'Your {site_title} order from {order_date} is complete', 'woocommerce' );
- $this->template_html = 'emails/customer-completed-order.php';
- $this->template_plain = 'emails/plain/customer-completed-order.php';
+ $this->template_html = 'emails/customer-completed-order.php';
+ $this->template_plain = 'emails/plain/customer-completed-order.php';
// Triggers for this email
add_action( 'woocommerce_order_status_completed_notification', array( $this, 'trigger' ) );
@@ -54,8 +54,8 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
function trigger( $order_id ) {
if ( $order_id ) {
- $this->object = wc_get_order( $order_id );
- $this->recipient = $this->object->billing_email;
+ $this->object = wc_get_order( $order_id );
+ $this->recipient = $this->object->billing_email;
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
@@ -78,10 +78,11 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
* @return string
*/
function get_subject() {
- if ( ! empty( $this->object ) && $this->object->has_downloadable_item() )
+ if ( ! empty( $this->object ) && $this->object->has_downloadable_item() ) {
return apply_filters( 'woocommerce_email_subject_customer_completed_order', $this->format_string( $this->subject_downloadable ), $this->object );
- else
+ } else {
return apply_filters( 'woocommerce_email_subject_customer_completed_order', $this->format_string( $this->subject ), $this->object );
+ }
}
/**
@@ -91,10 +92,11 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
* @return string
*/
function get_heading() {
- if ( ! empty( $this->object ) && $this->object->has_downloadable_item() )
+ if ( ! empty( $this->object ) && $this->object->has_downloadable_item() ) {
return apply_filters( 'woocommerce_email_heading_customer_completed_order', $this->format_string( $this->heading_downloadable ), $this->object );
- else
+ } else {
return apply_filters( 'woocommerce_email_heading_customer_completed_order', $this->format_string( $this->heading ), $this->object );
+ }
}
/**
@@ -106,7 +108,7 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
function get_content_html() {
ob_start();
wc_get_template( $this->template_html, array(
- 'order' => $this->object,
+ 'order' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'plain_text' => false
@@ -123,7 +125,7 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
function get_content_plain() {
ob_start();
wc_get_template( $this->template_plain, array(
- 'order' => $this->object,
+ 'order' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'plain_text' => true
@@ -140,46 +142,46 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
- 'title' => __( 'Enable/Disable', 'woocommerce' ),
- 'type' => 'checkbox',
- 'label' => __( 'Enable this email notification', 'woocommerce' ),
- 'default' => 'yes'
+ 'title' => __( 'Enable/Disable', 'woocommerce' ),
+ 'type' => 'checkbox',
+ 'label' => __( 'Enable this email notification', 'woocommerce' ),
+ 'default' => 'yes'
),
'subject' => array(
- 'title' => __( 'Subject', 'woocommerce' ),
- 'type' => 'text',
- 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->subject ),
- 'placeholder' => '',
- 'default' => ''
+ 'title' => __( 'Subject', 'woocommerce' ),
+ 'type' => 'text',
+ 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->subject ),
+ 'placeholder' => '',
+ 'default' => ''
),
'heading' => array(
- 'title' => __( 'Email Heading', 'woocommerce' ),
- 'type' => 'text',
- 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->heading ),
- 'placeholder' => '',
- 'default' => ''
+ 'title' => __( 'Email Heading', 'woocommerce' ),
+ 'type' => 'text',
+ 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->heading ),
+ 'placeholder' => '',
+ 'default' => ''
),
'subject_downloadable' => array(
- 'title' => __( 'Subject (downloadable)', 'woocommerce' ),
- 'type' => 'text',
- 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->subject_downloadable ),
- 'placeholder' => '',
- 'default' => ''
+ 'title' => __( 'Subject (downloadable)', 'woocommerce' ),
+ 'type' => 'text',
+ 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->subject_downloadable ),
+ 'placeholder' => '',
+ 'default' => ''
),
'heading_downloadable' => array(
- 'title' => __( 'Email Heading (downloadable)', 'woocommerce' ),
- 'type' => 'text',
- 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->heading_downloadable ),
- 'placeholder' => '',
- 'default' => ''
+ 'title' => __( 'Email Heading (downloadable)', 'woocommerce' ),
+ 'type' => 'text',
+ 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->heading_downloadable ),
+ 'placeholder' => '',
+ 'default' => ''
),
'email_type' => array(
- 'title' => __( 'Email type', 'woocommerce' ),
- 'type' => 'select',
- 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
- 'default' => 'html',
- 'class' => 'email_type wc-enhanced-select',
- 'options' => $this->get_email_type_options()
+ 'title' => __( 'Email type', 'woocommerce' ),
+ 'type' => 'select',
+ 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
+ 'default' => 'html',
+ 'class' => 'email_type wc-enhanced-select',
+ 'options' => $this->get_email_type_options()
)
);
}
diff --git a/includes/emails/class-wc-email-customer-invoice.php b/includes/emails/class-wc-email-customer-invoice.php
index c8a9d077e99..c686381fb16 100644
--- a/includes/emails/class-wc-email-customer-invoice.php
+++ b/includes/emails/class-wc-email-customer-invoice.php
@@ -11,11 +11,11 @@ if ( ! class_exists( 'WC_Email_Customer_Invoice' ) ) :
*
* An email sent to the customer via admin.
*
- * @class WC_Email_Customer_Invoice
- * @version 2.3.0
- * @package WooCommerce/Classes/Emails
- * @author WooThemes
- * @extends WC_Email
+ * @class WC_Email_Customer_Invoice
+ * @version 2.3.0
+ * @package WooCommerce/Classes/Emails
+ * @author WooThemes
+ * @extends WC_Email
*/
class WC_Email_Customer_Invoice extends WC_Email {
@@ -60,8 +60,8 @@ class WC_Email_Customer_Invoice extends WC_Email {
}
if ( $order ) {
- $this->object = $order;
- $this->recipient = $this->object->billing_email;
+ $this->object = $order;
+ $this->recipient = $this->object->billing_email;
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
@@ -114,7 +114,7 @@ class WC_Email_Customer_Invoice extends WC_Email {
function get_content_html() {
ob_start();
wc_get_template( $this->template_html, array(
- 'order' => $this->object,
+ 'order' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'plain_text' => false
@@ -131,7 +131,7 @@ class WC_Email_Customer_Invoice extends WC_Email {
function get_content_plain() {
ob_start();
wc_get_template( $this->template_plain, array(
- 'order' => $this->object,
+ 'order' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'plain_text' => true
@@ -148,40 +148,40 @@ class WC_Email_Customer_Invoice extends WC_Email {
function init_form_fields() {
$this->form_fields = array(
'subject' => array(
- 'title' => __( 'Email subject', 'woocommerce' ),
- 'type' => 'text',
- 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->subject ),
- 'placeholder' => '',
- 'default' => ''
+ 'title' => __( 'Email subject', 'woocommerce' ),
+ 'type' => 'text',
+ 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->subject ),
+ 'placeholder' => '',
+ 'default' => ''
),
'heading' => array(
- 'title' => __( 'Email heading', 'woocommerce' ),
- 'type' => 'text',
- 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->heading ),
- 'placeholder' => '',
- 'default' => ''
+ 'title' => __( 'Email heading', 'woocommerce' ),
+ 'type' => 'text',
+ 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->heading ),
+ 'placeholder' => '',
+ 'default' => ''
),
'subject_paid' => array(
- 'title' => __( 'Email subject (paid)', 'woocommerce' ),
- 'type' => 'text',
- 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->subject_paid ),
- 'placeholder' => '',
- 'default' => ''
+ 'title' => __( 'Email subject (paid)', 'woocommerce' ),
+ 'type' => 'text',
+ 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->subject_paid ),
+ 'placeholder' => '',
+ 'default' => ''
),
'heading_paid' => array(
- 'title' => __( 'Email heading (paid)', 'woocommerce' ),
- 'type' => 'text',
- 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->heading_paid ),
- 'placeholder' => '',
- 'default' => ''
+ 'title' => __( 'Email heading (paid)', 'woocommerce' ),
+ 'type' => 'text',
+ 'description' => sprintf( __( 'Defaults to %s
', 'woocommerce' ), $this->heading_paid ),
+ 'placeholder' => '',
+ 'default' => ''
),
'email_type' => array(
- 'title' => __( 'Email type', 'woocommerce' ),
- 'type' => 'select',
- 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
- 'default' => 'html',
- 'class' => 'email_type wc-enhanced-select',
- 'options' => $this->get_email_type_options()
+ 'title' => __( 'Email type', 'woocommerce' ),
+ 'type' => 'select',
+ 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
+ 'default' => 'html',
+ 'class' => 'email_type wc-enhanced-select',
+ 'options' => $this->get_email_type_options()
)
);
}
diff --git a/includes/emails/class-wc-email-customer-new-account.php b/includes/emails/class-wc-email-customer-new-account.php
index bb04d066081..e0a19f13f5d 100644
--- a/includes/emails/class-wc-email-customer-new-account.php
+++ b/includes/emails/class-wc-email-customer-new-account.php
@@ -11,11 +11,11 @@ if ( ! class_exists( 'WC_Email_Customer_New_Account' ) ) :
*
* An email sent to the customer when they create an account.
*
- * @class WC_Email_Customer_New_Account
- * @version 2.3.0
- * @package WooCommerce/Classes/Emails
- * @author WooThemes
- * @extends WC_Email
+ * @class WC_Email_Customer_New_Account
+ * @version 2.3.0
+ * @package WooCommerce/Classes/Emails
+ * @author WooThemes
+ * @extends WC_Email
*/
class WC_Email_Customer_New_Account extends WC_Email {
@@ -31,15 +31,15 @@ class WC_Email_Customer_New_Account extends WC_Email {
*/
function __construct() {
- $this->id = 'customer_new_account';
- $this->title = __( 'New account', 'woocommerce' );
- $this->description = __( 'Customer "new account" emails are sent to the customer when a customer signs up via checkout or account pages.', 'woocommerce' );
+ $this->id = 'customer_new_account';
+ $this->title = __( 'New account', 'woocommerce' );
+ $this->description = __( 'Customer "new account" emails are sent to the customer when a customer signs up via checkout or account pages.', 'woocommerce' );
- $this->template_html = 'emails/customer-new-account.php';
- $this->template_plain = 'emails/plain/customer-new-account.php';
+ $this->template_html = 'emails/customer-new-account.php';
+ $this->template_plain = 'emails/plain/customer-new-account.php';
- $this->subject = __( 'Your account on {site_title}', 'woocommerce');
- $this->heading = __( 'Welcome to {site_title}', 'woocommerce');
+ $this->subject = __( 'Your account on {site_title}', 'woocommerce');
+ $this->heading = __( 'Welcome to {site_title}', 'woocommerce');
// Call parent constuctor
parent::__construct();
@@ -54,7 +54,7 @@ class WC_Email_Customer_New_Account extends WC_Email {
function trigger( $user_id, $user_pass = '', $password_generated = false ) {
if ( $user_id ) {
- $this->object = new WP_User( $user_id );
+ $this->object = new WP_User( $user_id );
$this->user_pass = $user_pass;
$this->user_login = stripslashes( $this->object->user_login );
@@ -63,8 +63,9 @@ class WC_Email_Customer_New_Account extends WC_Email {
$this->password_generated = $password_generated;
}
- if ( ! $this->is_enabled() || ! $this->get_recipient() )
+ if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
return;
+ }
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}
@@ -83,8 +84,8 @@ class WC_Email_Customer_New_Account extends WC_Email {
'user_pass' => $this->user_pass,
'blogname' => $this->get_blogname(),
'password_generated' => $this->password_generated,
- 'sent_to_admin' => false,
- 'plain_text' => false
+ 'sent_to_admin' => false,
+ 'plain_text' => false
) );
return ob_get_clean();
}
@@ -103,8 +104,8 @@ class WC_Email_Customer_New_Account extends WC_Email {
'user_pass' => $this->user_pass,
'blogname' => $this->get_blogname(),
'password_generated' => $this->password_generated,
- 'sent_to_admin' => false,
- 'plain_text' => true
+ 'sent_to_admin' => false,
+ 'plain_text' => true
) );
return ob_get_clean();
}
diff --git a/includes/emails/class-wc-email-customer-note.php b/includes/emails/class-wc-email-customer-note.php
index 1f1a8486564..e024785a9a8 100644
--- a/includes/emails/class-wc-email-customer-note.php
+++ b/includes/emails/class-wc-email-customer-note.php
@@ -11,11 +11,11 @@ if ( ! class_exists( 'WC_Email_Customer_Note' ) ) :
*
* Customer note emails are sent when you add a note to an order.
*
- * @class WC_Email_Customer_Note
- * @version 2.3.0
- * @package WooCommerce/Classes/Emails
- * @author WooThemes
- * @extends WC_Email
+ * @class WC_Email_Customer_Note
+ * @version 2.3.0
+ * @package WooCommerce/Classes/Emails
+ * @author WooThemes
+ * @extends WC_Email
*/
class WC_Email_Customer_Note extends WC_Email {
@@ -29,15 +29,15 @@ class WC_Email_Customer_Note extends WC_Email {
*/
function __construct() {
- $this->id = 'customer_note';
- $this->title = __( 'Customer note', 'woocommerce' );
- $this->description = __( 'Customer note emails are sent when you add a note to an order.', 'woocommerce' );
+ $this->id = 'customer_note';
+ $this->title = __( 'Customer note', 'woocommerce' );
+ $this->description = __( 'Customer note emails are sent when you add a note to an order.', 'woocommerce' );
- $this->template_html = 'emails/customer-note.php';
- $this->template_plain = 'emails/plain/customer-note.php';
+ $this->template_html = 'emails/customer-note.php';
+ $this->template_plain = 'emails/plain/customer-note.php';
- $this->subject = __( 'Note added to your {site_title} order from {order_date}', 'woocommerce');
- $this->heading = __( 'A note has been added to your order', 'woocommerce');
+ $this->subject = __( 'Note added to your {site_title} order from {order_date}', 'woocommerce');
+ $this->heading = __( 'A note has been added to your order', 'woocommerce');
// Triggers
add_action( 'woocommerce_new_customer_note_notification', array( $this, 'trigger' ) );
@@ -57,8 +57,8 @@ class WC_Email_Customer_Note extends WC_Email {
if ( $args ) {
$defaults = array(
- 'order_id' => '',
- 'customer_note' => ''
+ 'order_id' => '',
+ 'customer_note' => ''
);
$args = wp_parse_args( $args, $defaults );
@@ -66,8 +66,8 @@ class WC_Email_Customer_Note extends WC_Email {
extract( $args );
if ( $order_id && ( $this->object = wc_get_order( $order_id ) ) ) {
- $this->recipient = $this->object->billing_email;
- $this->customer_note = $customer_note;
+ $this->recipient = $this->object->billing_email;
+ $this->customer_note = $customer_note;
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
@@ -95,7 +95,7 @@ class WC_Email_Customer_Note extends WC_Email {
function get_content_html() {
ob_start();
wc_get_template( $this->template_html, array(
- 'order' => $this->object,
+ 'order' => $this->object,
'email_heading' => $this->get_heading(),
'customer_note' => $this->customer_note,
'sent_to_admin' => false,
@@ -113,7 +113,7 @@ class WC_Email_Customer_Note extends WC_Email {
function get_content_plain() {
ob_start();
wc_get_template( $this->template_plain, array(
- 'order' => $this->object,
+ 'order' => $this->object,
'email_heading' => $this->get_heading(),
'customer_note' => $this->customer_note,
'sent_to_admin' => false,
diff --git a/includes/emails/class-wc-email-customer-processing-order.php b/includes/emails/class-wc-email-customer-processing-order.php
index 19735a96f87..cfcfe6b3407 100644
--- a/includes/emails/class-wc-email-customer-processing-order.php
+++ b/includes/emails/class-wc-email-customer-processing-order.php
@@ -11,11 +11,11 @@ if ( ! class_exists( 'WC_Email_Customer_Processing_Order' ) ) :
*
* An email sent to the customer when a new order is received/paid for.
*
- * @class WC_Email_Customer_Processing_Order
- * @version 2.0.0
- * @package WooCommerce/Classes/Emails
- * @author WooThemes
- * @extends WC_Email
+ * @class WC_Email_Customer_Processing_Order
+ * @version 2.0.0
+ * @package WooCommerce/Classes/Emails
+ * @author WooThemes
+ * @extends WC_Email
*/
class WC_Email_Customer_Processing_Order extends WC_Email {
@@ -24,15 +24,15 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
*/
function __construct() {
- $this->id = 'customer_processing_order';
- $this->title = __( 'Processing order', 'woocommerce' );
- $this->description = __( 'This is an order notification sent to customers containing their order details after payment.', 'woocommerce' );
+ $this->id = 'customer_processing_order';
+ $this->title = __( 'Processing order', 'woocommerce' );
+ $this->description = __( 'This is an order notification sent to customers containing their order details after payment.', 'woocommerce' );
- $this->heading = __( 'Thank you for your order', 'woocommerce' );
- $this->subject = __( 'Your {site_title} order receipt from {order_date}', 'woocommerce' );
+ $this->heading = __( 'Thank you for your order', 'woocommerce' );
+ $this->subject = __( 'Your {site_title} order receipt from {order_date}', 'woocommerce' );
- $this->template_html = 'emails/customer-processing-order.php';
- $this->template_plain = 'emails/plain/customer-processing-order.php';
+ $this->template_html = 'emails/customer-processing-order.php';
+ $this->template_plain = 'emails/plain/customer-processing-order.php';
// Triggers for this email
add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ) );
@@ -51,8 +51,8 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
function trigger( $order_id ) {
if ( $order_id ) {
- $this->object = wc_get_order( $order_id );
- $this->recipient = $this->object->billing_email;
+ $this->object = wc_get_order( $order_id );
+ $this->recipient = $this->object->billing_email;
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
@@ -77,7 +77,7 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
function get_content_html() {
ob_start();
wc_get_template( $this->template_html, array(
- 'order' => $this->object,
+ 'order' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'plain_text' => false
diff --git a/includes/emails/class-wc-email-customer-reset-password.php b/includes/emails/class-wc-email-customer-reset-password.php
index edd8f50a4b5..9e40998905c 100644
--- a/includes/emails/class-wc-email-customer-reset-password.php
+++ b/includes/emails/class-wc-email-customer-reset-password.php
@@ -11,11 +11,11 @@ if ( ! class_exists( 'WC_Email_Customer_Reset_Password' ) ) :
*
* An email sent to the customer when they reset their password.
*
- * @class WC_Email_Customer_Reset_Password
- * @version 2.3.0
- * @package WooCommerce/Classes/Emails
- * @author WooThemes
- * @extends WC_Email
+ * @class WC_Email_Customer_Reset_Password
+ * @version 2.3.0
+ * @package WooCommerce/Classes/Emails
+ * @author WooThemes
+ * @extends WC_Email
*/
class WC_Email_Customer_Reset_Password extends WC_Email {
@@ -36,15 +36,15 @@ class WC_Email_Customer_Reset_Password extends WC_Email {
*/
function __construct() {
- $this->id = 'customer_reset_password';
- $this->title = __( 'Reset password', 'woocommerce' );
- $this->description = __( 'Customer "reset password" emails are sent when customers reset their passwords.', 'woocommerce' );
+ $this->id = 'customer_reset_password';
+ $this->title = __( 'Reset password', 'woocommerce' );
+ $this->description = __( 'Customer "reset password" emails are sent when customers reset their passwords.', 'woocommerce' );
- $this->template_html = 'emails/customer-reset-password.php';
- $this->template_plain = 'emails/plain/customer-reset-password.php';
+ $this->template_html = 'emails/customer-reset-password.php';
+ $this->template_plain = 'emails/plain/customer-reset-password.php';
- $this->subject = __( 'Password Reset for {site_title}', 'woocommerce');
- $this->heading = __( 'Password Reset Instructions', 'woocommerce');
+ $this->subject = __( 'Password Reset for {site_title}', 'woocommerce');
+ $this->heading = __( 'Password Reset Instructions', 'woocommerce');
// Trigger
add_action( 'woocommerce_reset_password_notification', array( $this, 'trigger' ), 10, 2 );
@@ -87,9 +87,9 @@ class WC_Email_Customer_Reset_Password extends WC_Email {
ob_start();
wc_get_template( $this->template_html, array(
'email_heading' => $this->get_heading(),
- 'user_login' => $this->user_login,
- 'reset_key' => $this->reset_key,
- 'blogname' => $this->get_blogname(),
+ 'user_login' => $this->user_login,
+ 'reset_key' => $this->reset_key,
+ 'blogname' => $this->get_blogname(),
'sent_to_admin' => false,
'plain_text' => false
) );
@@ -106,9 +106,9 @@ class WC_Email_Customer_Reset_Password extends WC_Email {
ob_start();
wc_get_template( $this->template_plain, array(
'email_heading' => $this->get_heading(),
- 'user_login' => $this->user_login,
- 'reset_key' => $this->reset_key,
- 'blogname' => $this->get_blogname(),
+ 'user_login' => $this->user_login,
+ 'reset_key' => $this->reset_key,
+ 'blogname' => $this->get_blogname(),
'sent_to_admin' => false,
'plain_text' => true
) );
diff --git a/includes/emails/class-wc-email-new-order.php b/includes/emails/class-wc-email-new-order.php
index 7cdac6bb4d3..d9d81f43d07 100644
--- a/includes/emails/class-wc-email-new-order.php
+++ b/includes/emails/class-wc-email-new-order.php
@@ -11,11 +11,11 @@ if ( ! class_exists( 'WC_Email_New_Order' ) ) :
*
* An email sent to the admin when a new order is received/paid for.
*
- * @class WC_Email_New_Order
- * @version 2.0.0
- * @package WooCommerce/Classes/Emails
- * @author WooThemes
- * @extends WC_Email
+ * @class WC_Email_New_Order
+ * @version 2.0.0
+ * @package WooCommerce/Classes/Emails
+ * @author WooThemes
+ * @extends WC_Email
*/
class WC_Email_New_Order extends WC_Email {
@@ -24,15 +24,15 @@ class WC_Email_New_Order extends WC_Email {
*/
function __construct() {
- $this->id = 'new_order';
- $this->title = __( 'New order', 'woocommerce' );
- $this->description = __( 'New order emails are sent when an order is received.', 'woocommerce' );
+ $this->id = 'new_order';
+ $this->title = __( 'New order', 'woocommerce' );
+ $this->description = __( 'New order emails are sent when an order is received.', 'woocommerce' );
- $this->heading = __( 'New customer order', 'woocommerce' );
- $this->subject = __( '[{site_title}] New customer order ({order_number}) - {order_date}', 'woocommerce' );
+ $this->heading = __( 'New customer order', 'woocommerce' );
+ $this->subject = __( '[{site_title}] New customer order ({order_number}) - {order_date}', 'woocommerce' );
- $this->template_html = 'emails/admin-new-order.php';
- $this->template_plain = 'emails/plain/admin-new-order.php';
+ $this->template_html = 'emails/admin-new-order.php';
+ $this->template_plain = 'emails/plain/admin-new-order.php';
// Triggers for this email
add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ) );
@@ -61,7 +61,7 @@ class WC_Email_New_Order extends WC_Email {
function trigger( $order_id ) {
if ( $order_id ) {
- $this->object = wc_get_order( $order_id );
+ $this->object = wc_get_order( $order_id );
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
@@ -86,7 +86,7 @@ class WC_Email_New_Order extends WC_Email {
function get_content_html() {
ob_start();
wc_get_template( $this->template_html, array(
- 'order' => $this->object,
+ 'order' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => true,
'plain_text' => false
@@ -103,7 +103,7 @@ class WC_Email_New_Order extends WC_Email {
function get_content_plain() {
ob_start();
wc_get_template( $this->template_plain, array(
- 'order' => $this->object,
+ 'order' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => true,
'plain_text' => true
@@ -120,39 +120,39 @@ class WC_Email_New_Order extends WC_Email {
function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
- 'title' => __( 'Enable/Disable', 'woocommerce' ),
- 'type' => 'checkbox',
- 'label' => __( 'Enable this email notification', 'woocommerce' ),
- 'default' => 'yes'
+ 'title' => __( 'Enable/Disable', 'woocommerce' ),
+ 'type' => 'checkbox',
+ 'label' => __( 'Enable this email notification', 'woocommerce' ),
+ 'default' => 'yes'
),
'recipient' => array(
- 'title' => __( 'Recipient(s)', 'woocommerce' ),
- 'type' => 'text',
- 'description' => sprintf( __( 'Enter recipients (comma separated) for this email. Defaults to %s
.', 'woocommerce' ), esc_attr( get_option('admin_email') ) ),
- 'placeholder' => '',
- 'default' => ''
+ 'title' => __( 'Recipient(s)', 'woocommerce' ),
+ 'type' => 'text',
+ 'description' => sprintf( __( 'Enter recipients (comma separated) for this email. Defaults to %s
.', 'woocommerce' ), esc_attr( get_option('admin_email') ) ),
+ 'placeholder' => '',
+ 'default' => ''
),
'subject' => array(
- 'title' => __( 'Subject', 'woocommerce' ),
- 'type' => 'text',
- 'description' => sprintf( __( 'This controls the email subject line. Leave blank to use the default subject: %s
.', 'woocommerce' ), $this->subject ),
- 'placeholder' => '',
- 'default' => ''
+ 'title' => __( 'Subject', 'woocommerce' ),
+ 'type' => 'text',
+ 'description' => sprintf( __( 'This controls the email subject line. Leave blank to use the default subject: %s
.', 'woocommerce' ), $this->subject ),
+ 'placeholder' => '',
+ 'default' => ''
),
'heading' => array(
- 'title' => __( 'Email Heading', 'woocommerce' ),
- 'type' => 'text',
- 'description' => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: %s
.', 'woocommerce' ), $this->heading ),
- 'placeholder' => '',
- 'default' => ''
+ 'title' => __( 'Email Heading', 'woocommerce' ),
+ 'type' => 'text',
+ 'description' => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: %s
.', 'woocommerce' ), $this->heading ),
+ 'placeholder' => '',
+ 'default' => ''
),
'email_type' => array(
- 'title' => __( 'Email type', 'woocommerce' ),
- 'type' => 'select',
- 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
- 'default' => 'html',
- 'class' => 'email_type wc-enhanced-select',
- 'options' => $this->get_email_type_options()
+ 'title' => __( 'Email type', 'woocommerce' ),
+ 'type' => 'select',
+ 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
+ 'default' => 'html',
+ 'class' => 'email_type wc-enhanced-select',
+ 'options' => $this->get_email_type_options()
)
);
}
diff --git a/includes/emails/class-wc-email.php b/includes/emails/class-wc-email.php
index 09b6f40283d..732de38cc8c 100644
--- a/includes/emails/class-wc-email.php
+++ b/includes/emails/class-wc-email.php
@@ -402,7 +402,6 @@ class WC_Email extends WC_Settings_API {
} catch ( Exception $e ) {
$logger = new WC_Logger();
-
$logger->add( 'emogrifier', $e->getMessage() );
}
}
@@ -535,53 +534,8 @@ class WC_Email extends WC_Settings_API {
parent::process_admin_options();
// Save templates
- if ( ! empty( $_POST['template_html_code'] ) && ! empty( $this->template_html ) ) {
-
- $saved = false;
- $file = get_stylesheet_directory() . '/woocommerce/' . $this->template_html;
- $code = stripslashes( $_POST['template_html_code'] );
-
- if ( is_writeable( $file ) ) {
-
- $f = fopen( $file, 'w+' );
-
- if ( $f !== false ) {
- fwrite( $f, $code );
- fclose( $f );
- $saved = true;
- }
- }
-
- if ( ! $saved ) {
- $redirect = add_query_arg( 'wc_error', urlencode( __( 'Could not write to template file.', 'woocommerce' ) ) );
- wp_redirect( $redirect );
- exit;
- }
- }
-
- if ( ! empty( $_POST['template_plain_code'] ) && ! empty( $this->template_plain ) ) {
-
- $saved = false;
- $file = get_stylesheet_directory() . '/woocommerce/' . $this->template_plain;
- $code = stripslashes( $_POST['template_plain_code'] );
-
- if ( is_writeable( $file ) ) {
-
- $f = fopen( $file, 'w+' );
-
- if ( $f !== false ) {
- fwrite( $f, $code );
- fclose( $f );
- $saved = true;
- }
- }
-
- if ( ! $saved ) {
- $redirect = add_query_arg( 'wc_error', __( 'Could not write to template file.', 'woocommerce' ) );
- wp_redirect( $redirect );
- exit;
- }
- }
+ $this->save_template( $_POST['template_html_code'], $this->template_html );
+ $this->save_template( $_POST['template_plain_code'], $this->template_plain );
}
/**
@@ -603,6 +557,38 @@ class WC_Email extends WC_Settings_API {
return '';
}
+ /**
+ * Save the email templates
+ *
+ * @param string $template_code
+ * @param string $template_path
+ * @return void
+ */
+ protected function save_template( $template_code, $template_path ) {
+ if ( ! empty( $template_code ) && ! empty( $template_path ) ) {
+ $saved = false;
+ $file = get_stylesheet_directory() . '/woocommerce/' . $template_path;
+ $code = stripslashes( $template_code );
+
+ if ( is_writeable( $file ) ) {
+
+ $f = fopen( $file, 'w+' );
+
+ if ( $f !== false ) {
+ fwrite( $f, $code );
+ fclose( $f );
+ $saved = true;
+ }
+ }
+
+ if ( ! $saved ) {
+ $redirect = add_query_arg( 'wc_error', urlencode( __( 'Could not write to template file.', 'woocommerce' ) ) );
+ wp_redirect( $redirect );
+ exit;
+ }
+ }
+ }
+
/**
* Get the template file in the current theme.
*
@@ -698,13 +684,13 @@ class WC_Email extends WC_Settings_API {
/**
* Admin Options
*
- * Setup the gateway settings screen.
- * Override this in your gateway.
+ * Setup the email settings screen.
+ * Override this in your email.
*
* @since 1.0.0
*/
public function admin_options() {
- // Do admin acations.
+ // Do admin actions.
$this->admin_actions();
?>
diff --git a/includes/gateways/simplify-commerce/class-wc-addons-gateway-simplify-commerce.php b/includes/gateways/simplify-commerce/class-wc-addons-gateway-simplify-commerce.php
index e9a3ca6633a..6f12e5c7b1d 100644
--- a/includes/gateways/simplify-commerce/class-wc-addons-gateway-simplify-commerce.php
+++ b/includes/gateways/simplify-commerce/class-wc-addons-gateway-simplify-commerce.php
@@ -41,7 +41,6 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
*
* @param array $args
* @param int $order_id
- *
* @return array
*/
public function hosted_payment_args( $args, $order_id ) {
@@ -58,7 +57,6 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
* Check if order contains subscriptions.
*
* @param int $order_id
- *
* @return bool
*/
protected function order_contains_subscription( $order_id ) {
@@ -69,7 +67,6 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
* Check if order contains pre-orders.
*
* @param int $order_id
- *
* @return bool
*/
protected function order_contains_pre_order( $order_id ) {
@@ -81,7 +78,8 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
*
* @param WC_Order $order
* @param string $cart_token
- *
+ * @uses Simplify_ApiException
+ * @uses Simplify_BadRequestException
* @return array
*/
protected function process_subscription( $order, $cart_token = '' ) {
@@ -157,7 +155,8 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
*
* @param WC_Order $order
* @param string $cart_token
- *
+ * @uses Simplify_ApiException
+ * @uses Simplify_BadRequestException
* @return array
*/
protected function process_pre_order( $order, $cart_token = '' ) {
@@ -263,9 +262,10 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
*
* @param WC_order $order
* @param integer $amount (default: 0)
+ * @uses Simplify_BadRequestException
* @return bool|WP_Error
*/
- public function process_subscription_payment( $order = '', $amount = 0 ) {
+ public function process_subscription_payment( $order, $amount = 0 ) {
$order_items = $order->get_items();
$order_item = array_shift( $order_items );
$subscription_name = sprintf( __( '%s - Subscription for "%s"', 'woocommerce' ), esc_html( get_bloginfo( 'name', 'display' ) ), $order_item['name'] ) . ' ' . sprintf( __( '(Order #%s)', 'woocommerce' ), $order->get_order_number() );
diff --git a/includes/gateways/simplify-commerce/class-wc-gateway-simplify-commerce.php b/includes/gateways/simplify-commerce/class-wc-gateway-simplify-commerce.php
index 7a062e587aa..99896f6f94b 100644
--- a/includes/gateways/simplify-commerce/class-wc-gateway-simplify-commerce.php
+++ b/includes/gateways/simplify-commerce/class-wc-gateway-simplify-commerce.php
@@ -307,7 +307,8 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway {
*
* @param WC_Order $order
* @param string $cart_token
- *
+ * @uses Simplify_ApiException
+ * @uses Simplify_BadRequestException
* @return array
*/
protected function process_standard_payments( $order, $cart_token = '' ) {
@@ -501,6 +502,8 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway {
* @param int $order_id
* @param float $amount
* @param string $reason
+ * @uses Simplify_ApiException
+ * @uses Simplify_BadRequestException
* @return bool|WP_Error
*/
public function process_refund( $order_id, $amount = null, $reason = '' ) {
diff --git a/includes/wc-conditional-functions.php b/includes/wc-conditional-functions.php
index e144340923f..f71220f0327 100644
--- a/includes/wc-conditional-functions.php
+++ b/includes/wc-conditional-functions.php
@@ -126,7 +126,7 @@ if ( ! function_exists( 'is_wc_endpoint_url' ) ) {
$wc_endpoints = WC()->query->get_query_vars();
- if ( $endpoint ) {
+ if ( $endpoint !== false ) {
if ( ! isset( $wc_endpoints[ $endpoint ] ) ) {
return false;
} else {
@@ -140,6 +140,7 @@ if ( ! function_exists( 'is_wc_endpoint_url' ) ) {
return true;
}
}
+
return false;
}
}