Merge branch 'master' of github.com:woothemes/woocommerce
This commit is contained in:
commit
b76fc7c68a
|
@ -10,6 +10,9 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
?>
|
||||
|
||||
<div id="message" class="updated woocommerce-message wc-connect">
|
||||
<p><?php _e( '<strong>Your theme does not declare WooCommerce support</strong> – if you encounter layout issues please read our integration guide or choose a WooCommerce theme :)', 'woocommerce' ); ?></p>
|
||||
<p class="submit"><a href="<?php echo esc_url( apply_filters( 'woocommerce_docs_url', 'http://docs.woothemes.com/document/third-party-custom-theme-compatibility/', 'theme-compatibility' ) ); ?>" class="button-primary"><?php _e( 'Theme Integration Guide', 'woocommerce' ); ?></a> <a class="skip button-primary" href="<?php echo esc_url( add_query_arg( 'hide_theme_support_notice', 'true' ) ); ?>"><?php _e( 'Hide this notice', 'woocommerce' ); ?></a></p>
|
||||
<p><?php echo sprintf( __( '<strong>Your theme does not declare WooCommerce support</strong> – Please read our integration guide or check out our %sStorefront%s theme which is totally free to download and designed specifically for use with WooCommerce :)', 'woocommerce' ), '<a href="' . esc_url( admin_url( 'theme-install.php?theme=highwind">' ) ) . '', '</a>' ); ?></p>
|
||||
<p class="submit">
|
||||
<a href="http://woothemes.com/storefront" class="button-primary" target="_blank"><?php _e( 'Find out more about Storefront', 'woocommerce' ); ?></a>
|
||||
<a href="<?php echo esc_url( apply_filters( 'woocommerce_docs_url', 'http://docs.woothemes.com/document/third-party-custom-theme-compatibility/', 'theme-compatibility' ) ); ?>" class="button"><?php _e( 'Theme integration guide', 'woocommerce' ); ?></a>
|
||||
<a class="skip button" href="<?php echo esc_url( add_query_arg( 'hide_theme_support_notice', 'true' ) ); ?>"><?php _e( 'Hide this notice', 'woocommerce' ); ?></a></p>
|
||||
</div>
|
|
@ -54,6 +54,22 @@ class WC_Cache_Helper {
|
|||
return $transient_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the page name/id for a WC page
|
||||
* @param string $wc_page
|
||||
* @return array
|
||||
*/
|
||||
private static function get_page_uris( $wc_page ) {
|
||||
$wc_page_uris = array();
|
||||
|
||||
if ( ( $page_id = wc_get_page_id( $wc_page ) ) && $page_id > 0 && ( $page = get_post( $page_id ) ) ) {
|
||||
$wc_page_uris[] = 'p=' . $page_id;
|
||||
$wc_page_uris[] = '/' . $page->post_name;
|
||||
}
|
||||
|
||||
return $wc_page_uris;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent caching on dynamic pages.
|
||||
*
|
||||
|
@ -62,34 +78,7 @@ class WC_Cache_Helper {
|
|||
*/
|
||||
public static function prevent_caching() {
|
||||
if ( false === ( $wc_page_uris = get_transient( 'woocommerce_cache_excluded_uris' ) ) ) {
|
||||
$wc_page_uris = array();
|
||||
|
||||
// Exclude querystring when using page ID and permalinks
|
||||
if ( ( $cart_page_id = wc_get_page_id( 'cart' ) ) && $cart_page_id > 0 ) {
|
||||
$wc_page_uris[] = 'p=' . $cart_page_id;
|
||||
$page = get_post( $cart_page_id );
|
||||
|
||||
if ( ! is_null( $page ) ) {
|
||||
$wc_page_uris[] = '/' . $page->post_name;
|
||||
}
|
||||
}
|
||||
if ( ( $checkout_page_id = wc_get_page_id( 'checkout' ) ) && $checkout_page_id > 0 ) {
|
||||
$wc_page_uris[] = 'p=' . $checkout_page_id;
|
||||
$page = get_post( $checkout_page_id );
|
||||
|
||||
if ( ! is_null( $page ) ) {
|
||||
$wc_page_uris[] = '/' . $page->post_name;
|
||||
}
|
||||
}
|
||||
if ( ( $myaccount_page_id = wc_get_page_id( 'myaccount' ) ) && $myaccount_page_id > 0 ) {
|
||||
$wc_page_uris[] = 'p=' . $myaccount_page_id;
|
||||
$page = get_post( $myaccount_page_id );
|
||||
|
||||
if ( ! is_null( $page ) ) {
|
||||
$wc_page_uris[] = '/' . $page->post_name;
|
||||
}
|
||||
}
|
||||
|
||||
$wc_page_uris = array_filter( array_merge( self::get_page_uris( 'cart' ), self::get_page_uris( 'checkout' ), self::get_page_uris( 'myaccount' ) ) );
|
||||
set_transient( 'woocommerce_cache_excluded_uris', $wc_page_uris );
|
||||
}
|
||||
|
||||
|
|
|
@ -379,6 +379,7 @@ class WC_Countries {
|
|||
'FR' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city_upper}\n{country}",
|
||||
'HK' => "{company}\n{first_name} {last_name_upper}\n{address_1}\n{address_2}\n{city_upper}\n{state_upper}\n{country}",
|
||||
'HU' => "{name}\n{company}\n{city}\n{address_1}\n{address_2}\n{postcode}\n{country}",
|
||||
'IN' => "{company}\n{name}\n{address_1}\n{address_2}\n{city} - {postcode}\n{state}, {country}",
|
||||
'IS' => $postcode_before_city,
|
||||
'IT' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode}\n{city}\n{state_upper}\n{country}",
|
||||
'JP' => "{postcode}\n{state}{city}{address_1}\n{address_2}\n{company}\n{last_name} {first_name}\n {country}",
|
||||
|
|
|
@ -128,11 +128,13 @@ class WC_Download_Handler {
|
|||
*/
|
||||
private static function check_download_login_required( $download_data ) {
|
||||
if ( $download_data->user_id && 'yes' === get_option( 'woocommerce_downloads_require_login' ) ) {
|
||||
if ( ! is_user_logged_in() && wc_get_page_id( 'myaccount' ) ) {
|
||||
wp_safe_redirect( add_query_arg( 'wc_error', urlencode( __( 'You must be logged in to download files.', 'woocommerce' ) ), get_permalink( wc_get_page_id( 'myaccount' ) ) ) );
|
||||
exit;
|
||||
} elseif ( ! is_user_logged_in() ) {
|
||||
self::download_error( __( 'You must be logged in to download files.', 'woocommerce' ) . ' <a href="' . esc_url( wp_login_url( get_permalink( wc_get_page_id( 'myaccount' ) ) ) ) . '" class="wc-forward">' . __( 'Login', 'woocommerce' ) . '</a>', __( 'Log in to Download Files', 'woocommerce' ), 403 );
|
||||
if ( ! is_user_logged_in() ) {
|
||||
if ( wc_get_page_id( 'myaccount' ) ) {
|
||||
wp_safe_redirect( add_query_arg( 'wc_error', urlencode( __( 'You must be logged in to download files.', 'woocommerce' ) ), get_permalink( wc_get_page_id( 'myaccount' ) ) ) );
|
||||
exit;
|
||||
} else {
|
||||
self::download_error( __( 'You must be logged in to download files.', 'woocommerce' ) . ' <a href="' . esc_url( wp_login_url( get_permalink( wc_get_page_id( 'myaccount' ) ) ) ) . '" class="wc-forward">' . __( 'Login', 'woocommerce' ) . '</a>', __( 'Log in to Download Files', 'woocommerce' ), 403 );
|
||||
}
|
||||
} elseif ( ! current_user_can( 'download_file', $download_data ) ) {
|
||||
self::download_error( __( 'This is not your download link.', 'woocommerce' ), '', 403 );
|
||||
}
|
||||
|
@ -156,7 +158,7 @@ class WC_Download_Handler {
|
|||
array(
|
||||
'permission_id' => absint( $download_data->permission_id ),
|
||||
),
|
||||
array( '%d' ),
|
||||
array( '%d', '%s' ),
|
||||
array( '%d' )
|
||||
);
|
||||
}
|
||||
|
@ -203,43 +205,32 @@ class WC_Download_Handler {
|
|||
* @return array
|
||||
*/
|
||||
public static function parse_file_path( $file_path ) {
|
||||
$remote_file = true;
|
||||
$wp_uploads = wp_upload_dir();
|
||||
$wp_uploads_dir = $wp_uploads['basedir'];
|
||||
$wp_uploads_url = $wp_uploads['baseurl'];
|
||||
|
||||
// Replace uploads dir, site url etc with absolute counterparts if we can
|
||||
$replacements = array(
|
||||
$wp_uploads_url => $wp_uploads_dir,
|
||||
network_site_url( '/', 'https' ) => ABSPATH,
|
||||
network_site_url( '/', 'http' ) => ABSPATH,
|
||||
site_url( '/', 'https' ) => ABSPATH,
|
||||
site_url( '/', 'http' ) => ABSPATH
|
||||
);
|
||||
|
||||
$file_path = str_replace( array_keys( $replacements ), array_values( $replacements ), $file_path );
|
||||
$parsed_file_path = parse_url( $file_path );
|
||||
$remote_file = true;
|
||||
|
||||
$wp_uploads = wp_upload_dir();
|
||||
$wp_uploads_dir = $wp_uploads['basedir'];
|
||||
$wp_uploads_url = $wp_uploads['baseurl'];
|
||||
|
||||
if ( ( ! isset( $parsed_file_path['scheme'] ) || ! in_array( $parsed_file_path['scheme'], array( 'http', 'https', 'ftp' ) ) ) && isset( $parsed_file_path['path'] ) && file_exists( $parsed_file_path['path'] ) ) {
|
||||
|
||||
/// This is an absolute path
|
||||
$remote_file = false;
|
||||
|
||||
} elseif ( strpos( $file_path, $wp_uploads_url ) !== false ) {
|
||||
|
||||
// This is a local file given by URL so we need to figure out the path
|
||||
$remote_file = false;
|
||||
$file_path = str_replace( $wp_uploads_url, $wp_uploads_dir, $file_path );
|
||||
|
||||
} elseif ( is_multisite() && ( strpos( $file_path, network_site_url( '/', 'http' ) ) !== false || strpos( $file_path, network_site_url( '/', 'https' ) ) !== false ) ) {
|
||||
|
||||
// This is a local file outside of wp-content so figure out the path
|
||||
$remote_file = false;
|
||||
// Try to replace network url and upload URL
|
||||
$file_path = str_replace( array( network_site_url( '/', 'https' ), network_site_url( '/', 'http' ) ), ABSPATH, $file_path );
|
||||
$file_path = str_replace( $wp_uploads_url, $wp_uploads_dir, $file_path );
|
||||
|
||||
} elseif ( strpos( $file_path, site_url( '/', 'http' ) ) !== false || strpos( $file_path, site_url( '/', 'https' ) ) !== false ) {
|
||||
|
||||
// This is a local file outside of wp-content so figure out the path
|
||||
$remote_file = false;
|
||||
$file_path = str_replace( array( site_url( '/', 'https' ), site_url( '/', 'http' ) ), ABSPATH, $file_path );
|
||||
|
||||
} elseif ( file_exists( ABSPATH . $file_path ) ) {
|
||||
|
||||
// Path needs an abspath to work
|
||||
// See if path needs an abspath prepended to work
|
||||
if ( file_exists( ABSPATH . $file_path ) ) {
|
||||
$remote_file = false;
|
||||
$file_path = ABSPATH . $file_path;
|
||||
|
||||
// Check if we have an absolute path
|
||||
} elseif ( ( ! isset( $parsed_file_path['scheme'] ) || ! in_array( $parsed_file_path['scheme'], array( 'http', 'https', 'ftp' ) ) ) && isset( $parsed_file_path['path'] ) && file_exists( $parsed_file_path['path'] ) ) {
|
||||
$remote_file = false;
|
||||
$file_path = $parsed_file_path['path'];
|
||||
}
|
||||
|
||||
return array(
|
||||
|
@ -258,24 +249,17 @@ class WC_Download_Handler {
|
|||
|
||||
extract( $parsed_file_path );
|
||||
|
||||
// Path fix - kudos to Jason Judge
|
||||
if ( getcwd() ) {
|
||||
$xsendfile_path = trim( preg_replace( '`^' . str_replace( '\\', '/', getcwd() ) . '`' , '', $file_path ), '/' );
|
||||
}
|
||||
|
||||
if ( function_exists( 'apache_get_modules' ) && in_array( 'mod_xsendfile', apache_get_modules() ) ) {
|
||||
self::download_headers( $file_path, $filename );
|
||||
header( "Content-Disposition: attachment; filename=\"" . $filename . "\";" );
|
||||
header( "X-Sendfile: $xsendfile_path" );
|
||||
header( "X-Sendfile: $file_path" );
|
||||
exit;
|
||||
} elseif ( stristr( getenv( 'SERVER_SOFTWARE' ), 'lighttpd' ) ) {
|
||||
self::download_headers( $file_path, $filename );
|
||||
header( "Content-Disposition: attachment; filename=\"" . $filename . "\";" );
|
||||
header( "X-Lighttpd-Sendfile: $xsendfile_path" );
|
||||
header( "X-Lighttpd-Sendfile: $file_path" );
|
||||
exit;
|
||||
} elseif ( stristr( getenv( 'SERVER_SOFTWARE' ), 'nginx' ) || stristr( getenv( 'SERVER_SOFTWARE' ), 'cherokee' ) ) {
|
||||
self::download_headers( $file_path, $filename );
|
||||
header( "Content-Disposition: attachment; filename=\"" . $filename . "\";" );
|
||||
$xsendfile_path = trim( preg_replace( '`^' . str_replace( '\\', '/', getcwd() ) . '`', '', $file_path ), '/' );
|
||||
header( "X-Accel-Redirect: /$xsendfile_path" );
|
||||
exit;
|
||||
}
|
||||
|
@ -423,7 +407,7 @@ class WC_Download_Handler {
|
|||
* @param array $headers
|
||||
* @return array
|
||||
*/
|
||||
public function ie_nocache_headers_fix( $headers ) {
|
||||
public static function ie_nocache_headers_fix( $headers ) {
|
||||
if ( is_ssl() && ! empty( $GLOBALS['is_IE'] ) ) {
|
||||
$headers['Cache-Control'] = 'private';
|
||||
unset( $headers['Pragma'] );
|
||||
|
|
|
@ -44,11 +44,7 @@ class WC_Form_Handler {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( empty( $_POST[ 'action' ] ) || ( 'edit_address' !== $_POST[ 'action' ] ) || empty( $_POST['_wpnonce'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'woocommerce-edit_address' ) ) {
|
||||
if ( empty( $_POST[ 'action' ] ) || 'edit_address' !== $_POST[ 'action' ] || empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'woocommerce-edit_address' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -145,7 +141,7 @@ class WC_Form_Handler {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( empty( $_POST[ 'action' ] ) || ( 'save_account_details' !== $_POST[ 'action' ] ) || empty( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'save_account_details' ) ) {
|
||||
if ( empty( $_POST[ 'action' ] ) || 'save_account_details' !== $_POST[ 'action' ] || empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'save_account_details' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -813,7 +809,7 @@ class WC_Form_Handler {
|
|||
}
|
||||
|
||||
// process reset password form
|
||||
if ( isset( $_POST['password_1'] ) && isset( $_POST['password_2'] ) && isset( $_POST['reset_key'] ) && isset( $_POST['reset_login'] ) && isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'reset_password' ) ) {
|
||||
if ( isset( $_POST['password_1'] ) && isset( $_POST['password_2'] ) && isset( $_POST['reset_key'] ) && isset( $_POST['reset_login'] ) && isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'reset_password' ) ) {
|
||||
|
||||
// verify reset key again
|
||||
$user = WC_Shortcode_My_Account::check_password_reset_key( $_POST['reset_key'], $_POST['reset_login'] );
|
||||
|
|
|
@ -453,13 +453,27 @@ final class WooCommerce {
|
|||
define( 'WC_TEMPLATE_PATH', $this->template_path() );
|
||||
}
|
||||
|
||||
// Post thumbnail support
|
||||
$this->add_thumbnail_support();
|
||||
$this->add_image_sizes();
|
||||
$this->fix_server_vars();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure post thumbnail support is turned on
|
||||
*/
|
||||
private function add_thumbnail_support() {
|
||||
if ( ! current_theme_supports( 'post-thumbnails' ) ) {
|
||||
add_theme_support( 'post-thumbnails' );
|
||||
}
|
||||
add_post_type_support( 'product', 'thumbnail' );
|
||||
}
|
||||
|
||||
// Add image sizes
|
||||
/**
|
||||
* Add WC Image sizes to WP
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
private function add_image_sizes() {
|
||||
$shop_thumbnail = wc_get_image_size( 'shop_thumbnail' );
|
||||
$shop_catalog = wc_get_image_size( 'shop_catalog' );
|
||||
$shop_single = wc_get_image_size( 'shop_single' );
|
||||
|
@ -467,16 +481,16 @@ final class WooCommerce {
|
|||
add_image_size( 'shop_thumbnail', $shop_thumbnail['width'], $shop_thumbnail['height'], $shop_thumbnail['crop'] );
|
||||
add_image_size( 'shop_catalog', $shop_catalog['width'], $shop_catalog['height'], $shop_catalog['crop'] );
|
||||
add_image_size( 'shop_single', $shop_single['width'], $shop_single['height'], $shop_single['crop'] );
|
||||
}
|
||||
|
||||
// IIS
|
||||
if ( ! isset($_SERVER['REQUEST_URI'] ) ) {
|
||||
$_SERVER['REQUEST_URI'] = substr( $_SERVER['PHP_SELF'], 1 );
|
||||
|
||||
if ( isset( $_SERVER['QUERY_STRING'] ) ) {
|
||||
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix `$_SERVER` variables for various setups.
|
||||
*
|
||||
* Note: Removed IIS handling due to wp_fix_server_vars()
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
private function fix_server_vars() {
|
||||
// NGINX Proxy
|
||||
if ( ! isset( $_SERVER['REMOTE_ADDR'] ) && isset( $_SERVER['HTTP_REMOTE_ADDR'] ) ) {
|
||||
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_REMOTE_ADDR'];
|
||||
|
|
Loading…
Reference in New Issue