Update/install code + revised notices.
This commit is contained in:
parent
d91fb14b68
commit
aef75800c9
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
?>
|
||||
<div id="message" class="updated woocommerce-message wc-connect">
|
||||
<div class="squeezer">
|
||||
<h4><?php _e( '<strong>Welcome to WooCommerce</strong> – You\'re almost ready to start selling :)', 'woocommerce' ); ?></h4>
|
||||
<p class="submit"><a href="<?php echo add_query_arg('install_woocommerce_pages', 'true', admin_url('admin.php?page=woocommerce_settings') ); ?>" class="button-primary"><?php _e( 'Install WooCommerce Pages', 'woocommerce' ); ?></a> <a class="skip button-primary" href="<?php echo add_query_arg('skip_install_woocommerce_pages', 'true', admin_url('admin.php?page=woocommerce_settings') ); ?>"><?php _e( 'Skip setup', 'woocommerce' ); ?></a></p>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
?>
|
||||
<div id="message" class="updated woocommerce-message wc-connect">
|
||||
<div class="squeezer">
|
||||
<h4><?php _e( '<strong>WooCommerce has been installed</strong> – You\'re ready to start selling :)', 'woocommerce' ); ?></h4>
|
||||
|
||||
<p class="submit"><a href="<?php echo admin_url('admin.php?page=woocommerce_settings'); ?>" class="button-primary"><?php _e( 'Settings', 'woocommerce' ); ?></a> <a class="docs button-primary" href="http://www.woothemes.com/woocommerce-docs/"><?php _e( 'Docs', 'woocommerce' ); ?></a></p>
|
||||
|
||||
<p><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.woothemes.com/woocommerce/" data-text="A open-source (free) #ecommerce plugin for #WordPress that helps you sell anything. Beautifully." data-via="WooThemes" data-size="large" data-hashtags="WooCommerce">Tweet</a>
|
||||
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></p>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
?>
|
||||
<div id="message" class="updated woocommerce-message wc-connect">
|
||||
<div class="squeezer">
|
||||
<h4><?php _e( '<strong>Data Update Required</strong> – We just need to update your install to the latest version', 'woocommerce' ); ?></h4>
|
||||
<p class="submit"><a href="<?php echo add_query_arg( 'do_db_update', 'true', admin_url('admin.php?page=woocommerce_settings') ); ?>" class="button-primary"><?php _e( 'Run the updater', 'woocommerce' ); ?></a></p>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
?>
|
||||
<div id="message" class="updated woocommerce-message wc-connect">
|
||||
<div class="squeezer">
|
||||
<h4><?php _e( '<strong>WooCommerce has been updated</strong> – You\'re ready to continue selling :)', 'woocommerce' ); ?></h4>
|
||||
|
||||
<p class="submit"><a href="<?php echo admin_url('admin.php?page=woocommerce_settings'); ?>" class="button-primary"><?php _e( 'Settings', 'woocommerce' ); ?></a> <a class="docs button-primary" href="http://www.woothemes.com/woocommerce-docs/"><?php _e( 'Docs', 'woocommerce' ); ?></a></p>
|
||||
|
||||
<p><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.woothemes.com/woocommerce/" data-text="A open-source (free) #ecommerce plugin for #WordPress that helps you sell anything. Beautifully." data-via="WooThemes" data-size="large" data-hashtags="WooCommerce">Tweet</a>
|
||||
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></p>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/**
|
||||
* Update WC to 1.4
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Admin
|
||||
* @package WooCommerce/Admin/Updates
|
||||
* @version 1.7.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
global $wpdb, $woocommerce;
|
||||
|
||||
// Upgrade from old downloadable/virtual product types
|
||||
$downloadable_type = get_term_by( 'slug', 'downloadable', 'product_type' );
|
||||
if ( $downloadable_type ) {
|
||||
$products = get_objects_in_term( $downloadable_type->term_id, 'product_type' );
|
||||
foreach ( $products as $product ) {
|
||||
update_post_meta( $product, '_downloadable', 'yes' );
|
||||
update_post_meta( $product, '_virtual', 'yes' );
|
||||
wp_set_object_terms( $product, 'simple', 'product_type');
|
||||
}
|
||||
}
|
||||
|
||||
$virtual_type = get_term_by( 'slug', 'virtual', 'product_type' );
|
||||
if ( $virtual_type ) {
|
||||
$products = get_objects_in_term( $virtual_type->term_id, 'product_type' );
|
||||
foreach ( $products as $product ) {
|
||||
update_post_meta( $product, '_downloadable', 'no' );
|
||||
update_post_meta( $product, '_virtual', 'yes' );
|
||||
wp_set_object_terms( $product, 'simple', 'product_type');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* Update WC to 1.5
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Admin
|
||||
* @package WooCommerce/Admin/Updates
|
||||
* @version 1.7.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
global $wpdb, $woocommerce;
|
||||
|
||||
// Update woocommerce_downloadable_product_permissions table to include order ID's as well as keys
|
||||
$results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $wpdb->prefix . "woocommerce_downloadable_product_permissions WHERE order_id = 0;" ) );
|
||||
|
||||
if ( $results ) foreach ( $results as $result ) {
|
||||
|
||||
if ( ! $result->order_key )
|
||||
continue;
|
||||
|
||||
$order_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_order_key' AND meta_value = '%s' LIMIT 1;", $result->order_key ) );
|
||||
|
||||
if ( $order_id ) {
|
||||
|
||||
$wpdb->update( $wpdb->prefix . "woocommerce_downloadable_product_permissions", array(
|
||||
'order_id' => $order_id,
|
||||
), array(
|
||||
'product_id' => $result->product_id,
|
||||
'order_key' => $result->order_key
|
||||
), array( '%s' ), array( '%s', '%s' ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Upgrade old meta keys for product data
|
||||
$meta = array( 'sku', 'downloadable', 'virtual', 'price', 'visibility', 'stock', 'stock_status', 'backorders', 'manage_stock', 'sale_price', 'regular_price', 'weight', 'length', 'width', 'height', 'tax_status', 'tax_class', 'upsell_ids', 'crosssell_ids', 'sale_price_dates_from', 'sale_price_dates_to', 'min_variation_price', 'max_variation_price', 'featured', 'product_attributes', 'file_path', 'download_limit', 'product_url', 'min_variation_price', 'max_variation_price' );
|
||||
|
||||
$wpdb->query( $wpdb->prepare( "
|
||||
UPDATE {$wpdb->postmeta}
|
||||
LEFT JOIN {$wpdb->posts} ON ( {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID )
|
||||
SET meta_key = CONCAT( '_', meta_key )
|
||||
WHERE meta_key IN ( '" . implode( "', '", $meta ) . "' )
|
||||
AND {$wpdb->posts}.post_type IN ('product', 'product_variation')
|
||||
" ) );
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
/**
|
||||
* Update WC to 1.7
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Admin
|
||||
* @package WooCommerce/Admin/Updates
|
||||
* @version 1.7.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
global $wpdb, $woocommerce;
|
||||
|
||||
// Upgrade old style files paths to support multiple file paths
|
||||
$existing_file_paths = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM ". $wpdb->postmeta . " WHERE meta_key = '_file_path'" ) );
|
||||
|
||||
if ( $existing_file_paths ) {
|
||||
|
||||
foreach( $existing_file_paths as $existing_file_path ) {
|
||||
|
||||
$existing_file_path->meta_value = trim( $existing_file_path->meta_value );
|
||||
|
||||
if ( $existing_file_path->meta_value )
|
||||
$file_paths = maybe_serialize( array( md5( $existing_file_path->meta_value ) => $existing_file_path->meta_value ) );
|
||||
else
|
||||
$file_paths = '';
|
||||
|
||||
$wpdb->query( $wpdb->prepare( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_file_paths', meta_value = %s WHERE meta_id = %d", $file_paths, $existing_file_path->meta_id ) );
|
||||
|
||||
$wpdb->query( $wpdb->prepare( "UPDATE " . $wpdb->prefix . "woocommerce_downloadable_product_permissions SET download_id = %s WHERE product_id = %d", md5( $existing_file_path->meta_value ), $existing_file_path->post_id ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Update table primary keys
|
||||
$wpdb->query( $wpdb->prepare( "ALTER TABLE ". $wpdb->prefix . "woocommerce_downloadable_product_permissions DROP PRIMARY KEY" ) );
|
||||
|
||||
$wpdb->query( $wpdb->prepare( "ALTER TABLE ". $wpdb->prefix . "woocommerce_downloadable_product_permissions ADD PRIMARY KEY ( `product_id` , `order_id` , `order_key` , `download_id` )" ) );
|
||||
|
||||
// Setup default permalinks if shop page is defined
|
||||
$permalinks = get_option( 'woocommerce_permalinks' );
|
||||
$shop_page_id = woocommerce_get_page_id( 'shop' );
|
||||
|
||||
if ( empty( $permalinks ) && $shop_page_id > 0 ) {
|
||||
|
||||
$base_slug = $shop_page_id > 0 && get_page( $shop_page_id ) ? get_page_uri( $shop_page_id ) : 'shop';
|
||||
|
||||
$category_base = get_option('woocommerce_prepend_shop_page_to_urls') == "yes" ? trailingslashit( $base_slug ) : '';
|
||||
$category_slug = get_option('woocommerce_product_category_slug') ? get_option('woocommerce_product_category_slug') : _x( 'product-category', 'slug', 'woocommerce' );
|
||||
$tag_slug = get_option('woocommerce_product_tag_slug') ? get_option('woocommerce_product_tag_slug') : _x( 'product-tag', 'slug', 'woocommerce' );
|
||||
|
||||
if ( 'yes' == get_option('woocommerce_prepend_shop_page_to_products') ) {
|
||||
$product_base = trailingslashit( $base_slug );
|
||||
} else {
|
||||
if ( ( $product_slug = get_option('woocommerce_product_slug') ) !== false && ! empty( $product_slug ) ) {
|
||||
$product_base = trailingslashit( $product_slug );
|
||||
} else {
|
||||
$product_base = trailingslashit( _x('product', 'slug', 'woocommerce') );
|
||||
}
|
||||
}
|
||||
|
||||
if ( get_option('woocommerce_prepend_category_to_products') == 'yes' )
|
||||
$product_base .= trailingslashit('%product_cat%');
|
||||
|
||||
$permalinks = array(
|
||||
'product_base' => untrailingslashit( $product_base ),
|
||||
'category_base' => untrailingslashit( $category_base . $category_slug ),
|
||||
'attribute_base' => untrailingslashit( $category_base ),
|
||||
'tag_base' => untrailingslashit( $category_base . $tag_slug )
|
||||
);
|
||||
|
||||
update_option( 'woocommerce_permalinks', $permalinks );
|
||||
}
|
|
@ -140,57 +140,84 @@ add_action( 'admin_head', 'woocommerce_admin_menu_highlight' );
|
|||
|
||||
|
||||
/**
|
||||
* Show notices in admin.
|
||||
*
|
||||
* woocommerce_admin_notices_styles function.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function woocommerce_admin_install_notice() {
|
||||
?>
|
||||
<div id="message" class="updated woocommerce-message wc-connect">
|
||||
<div class="squeezer">
|
||||
<h4><?php _e( '<strong>Welcome to WooCommerce</strong> – You\'re almost ready to start selling :)', 'woocommerce' ); ?></h4>
|
||||
<p class="submit"><a href="<?php echo add_query_arg('install_woocommerce_pages', 'true', admin_url('admin.php?page=woocommerce_settings')); ?>" class="button-primary"><?php _e( 'Install WooCommerce Pages', 'woocommerce' ); ?></a> <a class="skip button-primary" href="<?php echo add_query_arg('skip_install_woocommerce_pages', 'true', admin_url('admin.php?page=woocommerce_settings')); ?>"><?php _e( 'Skip setup', 'woocommerce' ); ?></a></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
function woocommerce_admin_installed_notice() {
|
||||
?>
|
||||
<div id="message" class="updated woocommerce-message wc-connect">
|
||||
<div class="squeezer">
|
||||
<h4><?php _e( '<strong>WooCommerce has been installed</strong> – You\'re ready to start selling :)', 'woocommerce' ); ?></h4>
|
||||
|
||||
<p class="submit"><a href="<?php echo admin_url('admin.php?page=woocommerce_settings'); ?>" class="button-primary"><?php _e( 'Settings', 'woocommerce' ); ?></a> <a class="docs button-primary" href="http://www.woothemes.com/woocommerce-docs/"><?php _e( 'Documentation', 'woocommerce' ); ?></a></p>
|
||||
|
||||
<p><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.woothemes.com/woocommerce/" data-text="A open-source (free) #ecommerce plugin for #WordPress that helps you sell anything. Beautifully." data-via="WooThemes" data-size="large" data-hashtags="WooCommerce">Tweet</a>
|
||||
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
// Set installed option
|
||||
update_option('woocommerce_installed', 0);
|
||||
}
|
||||
function woocommerce_admin_notices_styles() {
|
||||
|
||||
// Installed notices
|
||||
if ( get_option('woocommerce_installed') == 1 ) {
|
||||
|
||||
if ( get_option( 'woocommerce_needs_update' ) == 1 || get_option( 'woocommerce_installed' ) == 1 ) {
|
||||
wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', dirname( __FILE__ ) ) );
|
||||
|
||||
if ( get_option('skip_install_woocommerce_pages') != 1 && woocommerce_get_page_id('shop') < 1 && ! isset( $_GET['install_woocommerce_pages'] ) && !isset( $_GET['skip_install_woocommerce_pages'] ) ) {
|
||||
add_action( 'admin_notices', 'woocommerce_admin_install_notice' );
|
||||
} elseif ( ! isset( $_GET['page'] ) || $_GET['page'] != 'woocommerce' ) {
|
||||
add_action( 'admin_notices', 'woocommerce_admin_installed_notice' );
|
||||
}
|
||||
|
||||
add_action( 'admin_notices', 'woocommerce_admin_install_notices' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
add_action( 'admin_print_styles', 'woocommerce_admin_notices_styles' );
|
||||
|
||||
|
||||
/**
|
||||
* woocommerce_admin_install_notices function.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function woocommerce_admin_install_notices() {
|
||||
global $woocommerce;
|
||||
|
||||
if ( get_option( 'woocommerce_needs_update' ) == 1 ) {
|
||||
|
||||
if ( ! isset( $_GET['do_db_update'] ) ) {
|
||||
|
||||
include( 'includes/notice-update.php' );
|
||||
|
||||
} elseif ( ! isset( $_GET['page'] ) || $_GET['page'] != 'woocommerce' ) {
|
||||
|
||||
// Do updates
|
||||
$current_db_version = get_option( 'woocommerce_db_version' );
|
||||
|
||||
if ( version_compare( $current_db_version, '1.4', '<' ) ) {
|
||||
include( 'includes/updates/woocommerce-update-1.4.php' );
|
||||
update_option( 'woocommerce_db_version', '1.4' );
|
||||
}
|
||||
|
||||
if ( version_compare( $current_db_version, '1.5', '<' ) ) {
|
||||
include( 'includes/updates/woocommerce-update-1.5.php' );
|
||||
update_option( 'woocommerce_db_version', '1.5' );
|
||||
}
|
||||
|
||||
if ( version_compare( $current_db_version, '1.7', '<' ) ) {
|
||||
include( 'includes/updates/woocommerce-update-1.7.php' );
|
||||
update_option( 'woocommerce_db_version', '1.7' );
|
||||
}
|
||||
|
||||
// Show notice
|
||||
include( 'includes/notice-updated.php' );
|
||||
|
||||
update_option( 'woocommerce_installed', 0 );
|
||||
update_option( 'woocommerce_needs_update', 0 );
|
||||
update_option( 'woocommerce_db_version', $woocommerce->version );
|
||||
}
|
||||
|
||||
} elseif ( get_option('woocommerce_installed') == 1 ) {
|
||||
|
||||
if ( get_option( 'skip_install_woocommerce_pages' ) != 1 && woocommerce_get_page_id( 'shop' ) < 1 && ! isset( $_GET['install_woocommerce_pages'] ) && !isset( $_GET['skip_install_woocommerce_pages'] ) ) {
|
||||
|
||||
include( 'includes/notice-install.php' );
|
||||
|
||||
} elseif ( ! isset( $_GET['page'] ) || $_GET['page'] != 'woocommerce' ) {
|
||||
|
||||
include( 'includes/notice-installed.php' );
|
||||
|
||||
update_option( 'woocommerce_installed', 0 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Include some admin files conditonally.
|
||||
*
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* @author WooThemes
|
||||
* @category Admin
|
||||
* @package WooCommerce/Admin/Install
|
||||
* @version 1.6.4
|
||||
* @version 1.7.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
@ -20,88 +20,50 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|||
*/
|
||||
function do_install_woocommerce() {
|
||||
global $woocommerce_settings, $woocommerce;
|
||||
|
||||
|
||||
// Do install
|
||||
woocommerce_default_options();
|
||||
woocommerce_tables_install();
|
||||
woocommerce_init_roles();
|
||||
|
||||
// Setup default permalinks
|
||||
$permalinks = get_option( 'woocommerce_permalinks' );
|
||||
$shop_page_id = woocommerce_get_page_id( 'shop' );
|
||||
if ( empty( $permalinks ) && $shop_page_id > 0 ) {
|
||||
|
||||
$base_slug = $shop_page_id > 0 && get_page( $shop_page_id ) ? get_page_uri( $shop_page_id ) : 'shop';
|
||||
|
||||
$category_base = get_option('woocommerce_prepend_shop_page_to_urls') == "yes" ? trailingslashit( $base_slug ) : '';
|
||||
$category_slug = get_option('woocommerce_product_category_slug') ? get_option('woocommerce_product_category_slug') : _x( 'product-category', 'slug', 'woocommerce' );
|
||||
$tag_slug = get_option('woocommerce_product_tag_slug') ? get_option('woocommerce_product_tag_slug') : _x( 'product-tag', 'slug', 'woocommerce' );
|
||||
|
||||
if ( 'yes' == get_option('woocommerce_prepend_shop_page_to_products') ) {
|
||||
$product_base = trailingslashit( $base_slug );
|
||||
} else {
|
||||
if ( ( $product_slug = get_option('woocommerce_product_slug') ) !== false && ! empty( $product_slug ) ) {
|
||||
$product_base = trailingslashit( $product_slug );
|
||||
} else {
|
||||
$product_base = trailingslashit( _x('product', 'slug', 'woocommerce') );
|
||||
}
|
||||
}
|
||||
|
||||
if ( get_option('woocommerce_prepend_category_to_products') == 'yes' )
|
||||
$product_base .= trailingslashit('%product_cat%');
|
||||
|
||||
$permalinks = array(
|
||||
'product_base' => untrailingslashit( $product_base ),
|
||||
'category_base' => untrailingslashit( $category_base . $category_slug ),
|
||||
'attribute_base' => untrailingslashit( $category_base ),
|
||||
'tag_base' => untrailingslashit( $category_base . $tag_slug )
|
||||
);
|
||||
|
||||
update_option( 'woocommerce_permalinks', $permalinks );
|
||||
}
|
||||
|
||||
// Register post types
|
||||
$woocommerce->init_taxonomy();
|
||||
|
||||
// Add default taxonomies
|
||||
woocommerce_default_taxonomies();
|
||||
|
||||
// Install folder for uploading files and prevent hotlinking
|
||||
// Install files and folders for uploading files and prevent hotlinking
|
||||
$upload_dir = wp_upload_dir();
|
||||
$downloads_url = $upload_dir['basedir'] . '/woocommerce_uploads';
|
||||
|
||||
// Deny access with htaccess
|
||||
if ( wp_mkdir_p( $downloads_url ) && ! file_exists( $downloads_url . '/.htaccess' ) ) {
|
||||
if ( $file_handle = @fopen( $downloads_url . '/.htaccess', 'w' ) ) {
|
||||
fwrite( $file_handle, 'deny from all' );
|
||||
fclose( $file_handle );
|
||||
}
|
||||
}
|
||||
$files = array(
|
||||
array(
|
||||
'base' => $upload_dir['basedir'] . '/woocommerce_uploads',
|
||||
'file' => '.htaccess',
|
||||
'content' => 'deny from all'
|
||||
),
|
||||
array(
|
||||
'base' => $upload_dir['basedir'] . '/woocommerce_uploads',
|
||||
'file' => 'index.html',
|
||||
'content' => ''
|
||||
),
|
||||
array(
|
||||
'base' => WP_PLUGIN_DIR . "/" . plugin_basename( dirname( dirname( __FILE__ ) ) ) . '/logs',
|
||||
'file' => '.htaccess',
|
||||
'content' => 'deny from all'
|
||||
),
|
||||
array(
|
||||
'base' => WP_PLUGIN_DIR . "/" . plugin_basename( dirname( dirname( __FILE__ ) ) ) . '/logs',
|
||||
'file' => 'index.html',
|
||||
'content' => ''
|
||||
)
|
||||
);
|
||||
|
||||
// Prevent directory listing with index.php
|
||||
if ( wp_mkdir_p( $downloads_url ) && ! file_exists( $downloads_url . '/index.html' ) ) {
|
||||
if ( $file_handle = @fopen( $downloads_url . '/index.html', 'w' ) ) {
|
||||
fwrite( $file_handle, '' );
|
||||
fclose( $file_handle );
|
||||
}
|
||||
}
|
||||
|
||||
// Install folder for logs
|
||||
$logs_url = WP_PLUGIN_DIR . "/" . plugin_basename( dirname( dirname( __FILE__ ) ) ) . '/logs';
|
||||
|
||||
// Deny access with htaccess
|
||||
if ( wp_mkdir_p( $logs_url ) && ! file_exists( $logs_url . '/.htaccess' ) ) {
|
||||
if ( $file_handle = @fopen( $logs_url . '/.htaccess', 'w' ) ) {
|
||||
fwrite( $file_handle, 'deny from all' );
|
||||
fclose( $file_handle );
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent directory listing with index.php
|
||||
if ( wp_mkdir_p( $logs_url ) && ! file_exists( $logs_url . '/index.html' ) ) {
|
||||
if ( $file_handle = @fopen( $logs_url . '/index.html', 'w' ) ) {
|
||||
fwrite( $file_handle, '' );
|
||||
fclose( $file_handle );
|
||||
foreach ( $files as $file ) {
|
||||
if ( wp_mkdir_p( $file['base'] ) && ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ) {
|
||||
if ( $file_handle = @fopen( trailingslashit( $file['base'] ) . $file['file'], 'w' ) ) {
|
||||
fwrite( $file_handle, $file['content'] );
|
||||
fclose( $file_handle );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,32 +73,24 @@ function do_install_woocommerce() {
|
|||
// Recompile LESS styles if they are custom
|
||||
if ( get_option( 'woocommerce_frontend_css' ) == 'yes' ) {
|
||||
|
||||
// Handle Colour Settings
|
||||
$colors = get_option( 'woocommerce_frontend_css_colors' );
|
||||
|
||||
if ( (
|
||||
! empty( $colors['primary'] ) &&
|
||||
! empty( $colors['secondary'] ) &&
|
||||
! empty( $colors['highlight'] ) &&
|
||||
! empty( $colors['content_bg'] ) &&
|
||||
! empty( $colors['subtext'] )
|
||||
) && (
|
||||
$colors['primary'] != '#ad74a2' ||
|
||||
$colors['secondary'] != '#f7f6f7' ||
|
||||
$colors['highlight'] != '#85ad74' ||
|
||||
$colors['content_bg'] != '#ffffff' ||
|
||||
$colors['subtext'] != '#777777'
|
||||
) ) {
|
||||
|
||||
// Write less file
|
||||
if ( ( ! empty( $colors['primary'] ) && ! empty( $colors['secondary'] ) && ! empty( $colors['highlight'] ) && ! empty( $colors['content_bg'] ) && ! empty( $colors['subtext'] ) ) && ( $colors['primary'] != '#ad74a2' || $colors['secondary'] != '#f7f6f7' || $colors['highlight'] != '#85ad74' || $colors['content_bg'] != '#ffffff' || $colors['subtext'] != '#777777' ) )
|
||||
woocommerce_compile_less_styles();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Update version
|
||||
update_option( 'woocommerce_db_version', $woocommerce->version );
|
||||
update_option( 'woocommerce_version', $woocommerce->version );
|
||||
|
||||
// Queue upgrades
|
||||
$current_db_version = get_option( 'woocommerce_db_version' );
|
||||
|
||||
if ( version_compare( $current_db_version, '1.7', '<' ) ) {
|
||||
update_option( 'woocommerce_needs_update', 1 );
|
||||
} else {
|
||||
update_option( 'woocommerce_db_version', $woocommerce->version );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -155,29 +109,17 @@ function woocommerce_default_options() {
|
|||
include_once( 'settings/settings-init.php' );
|
||||
|
||||
foreach ( $woocommerce_settings as $section ) {
|
||||
|
||||
foreach ( $section as $value ) {
|
||||
|
||||
if ( isset( $value['std'] ) && isset( $value['id'] ) ) {
|
||||
|
||||
if ( $value['type'] == 'image_width' ) {
|
||||
|
||||
add_option( $value['id'] . '_width', $value['std'] );
|
||||
add_option( $value['id'] . '_height', $value['std'] );
|
||||
|
||||
} else {
|
||||
|
||||
add_option( $value['id'], $value['std'] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
add_option( 'woocommerce_shop_slug', 'shop' );
|
||||
}
|
||||
|
||||
|
||||
|
@ -263,7 +205,6 @@ function woocommerce_create_pages() {
|
|||
|
||||
// Thanks page
|
||||
woocommerce_create_page( esc_sql( _x( 'order-received', 'page_slug', 'woocommerce' ) ), 'woocommerce_thanks_page_id', __( 'Order Received', 'woocommerce' ), '[woocommerce_thankyou]', woocommerce_get_page_id( 'checkout' ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -287,14 +228,6 @@ function woocommerce_tables_install() {
|
|||
}
|
||||
|
||||
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
||||
|
||||
/**
|
||||
* Data Upgrades - Prepare existing tables
|
||||
**/
|
||||
if ( version_compare( get_option('woocommerce_db_version'), '1.7', '<' ) ) {
|
||||
// remove the existing primary key so we can add the new download_id column
|
||||
$wpdb->query( $wpdb->prepare( "ALTER TABLE ". $wpdb->prefix . "woocommerce_downloadable_product_permissions DROP PRIMARY KEY" ) );
|
||||
}
|
||||
|
||||
// Table for storing attribute taxonomies - these are user defined
|
||||
$sql = "
|
||||
|
@ -307,7 +240,7 @@ CREATE TABLE ". $wpdb->prefix . "woocommerce_attribute_taxonomies (
|
|||
PRIMARY KEY (attribute_id)
|
||||
) $collate;
|
||||
";
|
||||
dbDelta($sql);
|
||||
dbDelta( $sql );
|
||||
|
||||
// Term meta table - sadly WordPress does not have termmeta so we need our own
|
||||
$sql = "
|
||||
|
@ -319,7 +252,7 @@ CREATE TABLE ". $wpdb->prefix . "woocommerce_termmeta (
|
|||
PRIMARY KEY (meta_id)
|
||||
) $collate;
|
||||
";
|
||||
dbDelta($sql);
|
||||
dbDelta( $sql );
|
||||
|
||||
// Table for storing user and guest download permissions
|
||||
// KEY(order_id, product_id, download_id) used for organizing downloads on the My Account page
|
||||
|
@ -339,64 +272,7 @@ CREATE TABLE ". $wpdb->prefix . "woocommerce_downloadable_product_permissions (
|
|||
KEY (order_id,product_id,download_id)
|
||||
) $collate;
|
||||
";
|
||||
dbDelta($sql);
|
||||
|
||||
/**
|
||||
* Data Upgrades
|
||||
**/
|
||||
if ( version_compare( get_option('woocommerce_db_version'), '1.7', '<' ) ) {
|
||||
|
||||
// upgrade existing meta data
|
||||
$existing_file_paths = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM ". $wpdb->postmeta . " WHERE meta_key = '_file_path'" ) );
|
||||
if ( $existing_file_paths ) {
|
||||
foreach( $existing_file_paths as $existing_file_path ) {
|
||||
$existing_file_path->meta_value = trim( $existing_file_path->meta_value );
|
||||
if ( $existing_file_path->meta_value )
|
||||
$file_paths = maybe_serialize( array( md5( $existing_file_path->meta_value ) => $existing_file_path->meta_value ) );
|
||||
else
|
||||
$file_paths = '';
|
||||
$wpdb->query( $wpdb->prepare( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_file_paths', meta_value = %s WHERE meta_id = %d", $file_paths, $existing_file_path->meta_id ) );
|
||||
$wpdb->query( $wpdb->prepare( "UPDATE " . $wpdb->prefix . "woocommerce_downloadable_product_permissions SET download_id = %s WHERE product_id = %d", md5( $existing_file_path->meta_value ), $existing_file_path->post_id ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( version_compare( get_option('woocommerce_db_version'), '1.0', '>' ) && version_compare( get_option('woocommerce_db_version'), '1.4', '<' ) ) {
|
||||
|
||||
// Update woocommerce_downloadable_product_permissions table to include order ID's as well as keys
|
||||
$results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $wpdb->prefix . "woocommerce_downloadable_product_permissions WHERE order_id = 0;" ) );
|
||||
|
||||
if ( $results ) foreach ( $results as $result ) {
|
||||
|
||||
if ( ! $result->order_key )
|
||||
continue;
|
||||
|
||||
$order_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_order_key' AND meta_value = '%s' LIMIT 1;", $result->order_key ) );
|
||||
|
||||
if ( $order_id ) {
|
||||
|
||||
$wpdb->update( $wpdb->prefix . "woocommerce_downloadable_product_permissions", array(
|
||||
'order_id' => $order_id,
|
||||
), array(
|
||||
'product_id' => $result->product_id,
|
||||
'order_key' => $result->order_key
|
||||
), array( '%s' ), array( '%s', '%s' ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Upgrade old meta keys for product data
|
||||
$meta = array('sku', 'downloadable', 'virtual', 'price', 'visibility', 'stock', 'stock_status', 'backorders', 'manage_stock', 'sale_price', 'regular_price', 'weight', 'length', 'width', 'height', 'tax_status', 'tax_class', 'upsell_ids', 'crosssell_ids', 'sale_price_dates_from', 'sale_price_dates_to', 'min_variation_price', 'max_variation_price', 'featured', 'product_attributes', 'file_path', 'download_limit', 'product_url', 'min_variation_price', 'max_variation_price');
|
||||
|
||||
$wpdb->query( $wpdb->prepare( "
|
||||
UPDATE {$wpdb->postmeta}
|
||||
LEFT JOIN {$wpdb->posts} ON ( {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID )
|
||||
SET meta_key = CONCAT( '_', meta_key )
|
||||
WHERE meta_key IN ( '" . implode( "', '", $meta ) . "' )
|
||||
AND {$wpdb->posts}.post_type IN ('product', 'product_variation')
|
||||
" ) );
|
||||
}
|
||||
dbDelta( $sql );
|
||||
}
|
||||
|
||||
|
||||
|
@ -408,53 +284,29 @@ CREATE TABLE ". $wpdb->prefix . "woocommerce_downloadable_product_permissions (
|
|||
*/
|
||||
function woocommerce_default_taxonomies() {
|
||||
|
||||
$product_types = array(
|
||||
'simple',
|
||||
'grouped',
|
||||
'variable',
|
||||
'external'
|
||||
$taxonomies = array(
|
||||
'product_type' => array(
|
||||
'simple',
|
||||
'grouped',
|
||||
'variable',
|
||||
'external'
|
||||
),
|
||||
'shop_order_status' => array(
|
||||
'pending',
|
||||
'failed',
|
||||
'on-hold',
|
||||
'processing',
|
||||
'completed',
|
||||
'refunded',
|
||||
'cancelled'
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( $product_types as $type ) {
|
||||
if ( ! get_term_by( 'slug', sanitize_title( $type ), 'product_type' ) ) {
|
||||
wp_insert_term( $type, 'product_type' );
|
||||
}
|
||||
}
|
||||
|
||||
$order_status = array(
|
||||
'pending',
|
||||
'failed',
|
||||
'on-hold',
|
||||
'processing',
|
||||
'completed',
|
||||
'refunded',
|
||||
'cancelled'
|
||||
);
|
||||
|
||||
foreach ( $order_status as $status ) {
|
||||
if ( ! get_term_by( 'slug', sanitize_title($status), 'shop_order_status' ) ) {
|
||||
wp_insert_term( $status, 'shop_order_status' );
|
||||
}
|
||||
}
|
||||
|
||||
// Upgrade from old downloadable/virtual product types
|
||||
$downloadable_type = get_term_by( 'slug', 'downloadable', 'product_type' );
|
||||
if ( $downloadable_type ) {
|
||||
$products = get_objects_in_term( $downloadable_type->term_id, 'product_type' );
|
||||
foreach ( $products as $product ) {
|
||||
update_post_meta( $product, '_downloadable', 'yes' );
|
||||
update_post_meta( $product, '_virtual', 'yes' );
|
||||
wp_set_object_terms( $product, 'simple', 'product_type');
|
||||
}
|
||||
}
|
||||
|
||||
$virtual_type = get_term_by( 'slug', 'virtual', 'product_type' );
|
||||
if ( $virtual_type ) {
|
||||
$products = get_objects_in_term( $virtual_type->term_id, 'product_type' );
|
||||
foreach ( $products as $product ) {
|
||||
update_post_meta( $product, '_downloadable', 'no' );
|
||||
update_post_meta( $product, '_virtual', 'yes' );
|
||||
wp_set_object_terms( $product, 'simple', 'product_type');
|
||||
foreach ( $taxonomies as $taxonomy => $terms ) {
|
||||
foreach ( $terms as $term ) {
|
||||
if ( ! get_term_by( 'slug', sanitize_title( $term ), $taxonomy ) ) {
|
||||
wp_insert_term( $term, $taxonomy );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -81,7 +81,11 @@ function woocommerce_status() {
|
|||
<tbody>
|
||||
<tr>
|
||||
<td><?php _e('WooCommerce version','woocommerce')?></td>
|
||||
<td><?php echo $woocommerce->version; ?></td>
|
||||
<td><?php echo esc_html( $woocommerce->version ); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php _e('WooCommerce DB version','woocommerce')?></td>
|
||||
<td><?php echo esc_html( get_option( 'woocommerce_db_version' ) ); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php _e('WordPress version','woocommerce')?></td>
|
||||
|
|
|
@ -180,6 +180,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
|
|||
* Templating - email-order-items.php change get_downloadable_file_url() to get_downloadable_file_urls() to support multiple files.
|
||||
* Templating - loop-end and start for product loops, allow changing the UL's used by default to something else.
|
||||
|
||||
* Tweak - Improved installation + upgrade process upon activation.
|
||||
* Tweak - Protect logs and uploads with a blank index.html
|
||||
* Tweak - Append unique hash to log file names
|
||||
* Tweak - get_order_number support for PayPal (thanks Justin)
|
||||
|
|
|
@ -83,7 +83,12 @@ if ( ( ! is_home() && ! is_front_page() && ! ( is_post_type_archive() && get_opt
|
|||
|
||||
} elseif ( is_post_type_archive('product') && get_option('page_on_front') !== woocommerce_get_page_id('shop') ) {
|
||||
|
||||
$_name = woocommerce_get_page_id( 'shop' ) ? get_the_title( woocommerce_get_page_id( 'shop' ) ) : ucwords( get_option( 'woocommerce_shop_slug' ) );
|
||||
$_name = woocommerce_get_page_id( 'shop' ) ? get_the_title( woocommerce_get_page_id( 'shop' ) ) : '';
|
||||
|
||||
if ( ! $_name ) {
|
||||
$product_post_type = get_post_type_object( 'product' );
|
||||
$_name = $product_post_type->labels->singular_name;
|
||||
}
|
||||
|
||||
if ( is_search() ) {
|
||||
|
||||
|
|
|
@ -265,7 +265,7 @@ class Woocommerce {
|
|||
function install() {
|
||||
register_activation_hook( __FILE__, 'activate_woocommerce' );
|
||||
register_activation_hook( __FILE__, 'flush_rewrite_rules' );
|
||||
if ( get_option('woocommerce_db_version') != $this->version )
|
||||
if ( get_option( 'woocommerce_version' ) != $this->version )
|
||||
add_action( 'init', 'install_woocommerce', 1 );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue