Skip to content

Commit

Permalink
Overhauled classes and removed singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Sep 6, 2011
1 parent b3d7b8e commit c18f533
Show file tree
Hide file tree
Showing 58 changed files with 1,038 additions and 964 deletions.
15 changes: 8 additions & 7 deletions admin/admin-attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
*/
function woocommerce_attributes() {

global $wpdb;
global $wpdb, $woocommerce;

if (isset($_POST['add_new_attribute']) && $_POST['add_new_attribute']) :

$attribute_name = (string) sanitize_title($_POST['attribute_name']);
$attribute_type = (string) $_POST['attribute_type'];
$attribute_label = (string) $_POST['attribute_label'];

if ($attribute_name && strlen($attribute_name)<30 && $attribute_type && !taxonomy_exists( woocommerce::attribute_name($attribute_name) )) :
if ($attribute_name && strlen($attribute_name)<30 && $attribute_type && !taxonomy_exists( $woocommerce->attribute_name($attribute_name) )) :

$wpdb->insert( $wpdb->prefix . "woocommerce_attribute_taxonomies", array( 'attribute_name' => $attribute_name, 'attribute_label' => $attribute_label, 'attribute_type' => $attribute_type ), array( '%s', '%s' ) );

Expand Down Expand Up @@ -62,7 +62,7 @@ function woocommerce_attributes() {

if ($att_name && $wpdb->query("DELETE FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_id = '$delete'")) :

$taxonomy = woocommerce::attribute_name($att_name);
$taxonomy = $woocommerce->attribute_name($att_name);

if (taxonomy_exists($taxonomy)) :

Expand Down Expand Up @@ -147,6 +147,7 @@ function woocommerce_edit_attribute() {
* Shows the interface for adding new attributes
*/
function woocommerce_add_attribute() {
global $woocommerce;
?>
<div class="wrap woocommerce">
<div class="icon32 icon32-attributes" id="icon-woocommerce"><br/></div>
Expand All @@ -166,21 +167,21 @@ function woocommerce_add_attribute() {
</thead>
<tbody>
<?php
$attribute_taxonomies = woocommerce::get_attribute_taxonomies();
$attribute_taxonomies = $woocommerce->get_attribute_taxonomies();
if ( $attribute_taxonomies ) :
foreach ($attribute_taxonomies as $tax) :
?><tr>

<td><a href="edit-tags.php?taxonomy=<?php echo woocommerce::attribute_name($tax->attribute_name); ?>&amp;post_type=product"><?php echo $tax->attribute_name; ?></a>
<td><a href="edit-tags.php?taxonomy=<?php echo $woocommerce->attribute_name($tax->attribute_name); ?>&amp;post_type=product"><?php echo $tax->attribute_name; ?></a>

<div class="row-actions"><span class="edit"><a href="<?php echo add_query_arg('edit', $tax->attribute_id, 'admin.php?page=attributes') ?>"><?php _e('Edit', 'woothemes'); ?></a> | </span><span class="delete"><a class="delete" href="<?php echo add_query_arg('delete', $tax->attribute_id, 'admin.php?page=attributes') ?>"><?php _e('Delete', 'woothemes'); ?></a></span></div>
</td>
<td><?php echo ucwords($tax->attribute_label); ?></td>
<td><?php echo ucwords($tax->attribute_type); ?></td>
<td><?php
if (taxonomy_exists(woocommerce::attribute_name($tax->attribute_name))) :
if (taxonomy_exists($woocommerce->attribute_name($tax->attribute_name))) :
$terms_array = array();
$terms = get_terms( woocommerce::attribute_name($tax->attribute_name), 'orderby=name&hide_empty=0' );
$terms = get_terms( $woocommerce->attribute_name($tax->attribute_name), 'orderby=name&hide_empty=0' );
if ($terms) :
foreach ($terms as $term) :
$terms_array[] = $term->name;
Expand Down
8 changes: 5 additions & 3 deletions admin/admin-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

function woocommerce_content_right_now() {

global $lowinstock, $outofstock;
global $lowinstock, $outofstock, $woocommerce;

$lowstockamount = get_option('woocommerce_notify_low_stock_amount');
if (!is_numeric($lowstockamount)) $lowstockamount = 1;
Expand Down Expand Up @@ -92,7 +92,7 @@ function woocommerce_content_right_now() {
</tr>
<tr>
<td class="first b"><a href="admin.php?page=attributes"><?php
echo sizeof(woocommerce::get_attribute_taxonomies());
echo sizeof($woocommerce->get_attribute_taxonomies());
?></a></td>
<td class="t"><a href="admin.php?page=attributes"><?php _e('Attribute taxonomies', 'woothemes'); ?></a></td>
</tr>
Expand Down Expand Up @@ -263,6 +263,8 @@ function woocommmerce_dashboard_sales() {
*/
function woocommmerce_dashboard_sales_js() {

global $woocommerce;

$screen = get_current_screen();

if (!$screen || $screen->id!=='dashboard') return;
Expand Down Expand Up @@ -355,7 +357,7 @@ function woocommmerce_dashboard_sales_js() {
$params['order_data'] = json_encode($order_data);

// Queue
wp_register_script( 'woocommerce_dashboard_sales', woocommerce::plugin_url() . '/assets/js/woocommerce_dashboard_sales.js', 'jquery', '1.0' );
wp_register_script( 'woocommerce_dashboard_sales', $woocommerce->plugin_url() . '/assets/js/woocommerce_dashboard_sales.js', 'jquery', '1.0' );
wp_localize_script( 'woocommerce_dashboard_sales', 'params', $params );
wp_print_scripts('woocommerce_dashboard_sales');

Expand Down
10 changes: 6 additions & 4 deletions admin/admin-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function woocommerce_admin_init() {
* Admin Scripts
*/
function woocommerce_admin_scripts() {
wp_register_script( 'woocommerce_admin', woocommerce::plugin_url() . '/assets/js/woocommerce_admin.js', array('jquery', 'jquery-ui-widget'), '1.0' );
global $woocommerce;
wp_register_script( 'woocommerce_admin', $woocommerce->plugin_url() . '/assets/js/woocommerce_admin.js', array('jquery', 'jquery-ui-widget'), '1.0' );
wp_enqueue_script('woocommerce_admin');
}
add_action('admin_print_scripts', 'woocommerce_admin_scripts');
Expand All @@ -36,11 +37,11 @@ function woocommerce_admin_scripts() {
* Sets up the admin menus in wordpress.
*/
function woocommerce_admin_menu() {
global $menu;
global $menu, $woocommerce;

$menu[] = array( '', 'read', 'separator-woocommerce', '', 'wp-menu-separator' );

add_menu_page(__('WooCommerce'), __('WooCommerce'), 'manage_woocommerce', 'woocommerce' , 'woocommerce_settings', woocommerce::plugin_url() . '/assets/images/icons/menu_icons.png', 56);
add_menu_page(__('WooCommerce'), __('WooCommerce'), 'manage_woocommerce', 'woocommerce' , 'woocommerce_settings', $woocommerce->plugin_url() . '/assets/images/icons/menu_icons.png', 56);
add_submenu_page('woocommerce', __('General Settings', 'woothemes'), __('Settings', 'woothemes') , 'manage_woocommerce', 'woocommerce', 'woocommerce_settings');
add_submenu_page('edit.php?post_type=product', __('Attributes', 'woothemes'), __('Attributes', 'woothemes'), 'manage_woocommerce', 'attributes', 'woocommerce_attributes');
}
Expand Down Expand Up @@ -159,10 +160,11 @@ function woocommerce_get_current_post_type() {
* Categories ordering scripts
*/
function woocommerce_categories_scripts () {
global $woocommerce;

if( !isset($_GET['taxonomy']) || $_GET['taxonomy'] !== 'product_cat') return;

wp_register_script('woocommerce-categories-ordering', woocommerce::plugin_url() . '/assets/js/categories-ordering.js', array('jquery-ui-sortable'));
wp_register_script('woocommerce-categories-ordering', $woocommerce->plugin_url() . '/assets/js/categories-ordering.js', array('jquery-ui-sortable'));
wp_print_scripts('woocommerce-categories-ordering');

}
Expand Down
8 changes: 4 additions & 4 deletions admin/admin-post-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function woocommerce_edit_product_columns($columns){
add_action('manage_product_posts_custom_column', 'woocommerce_custom_product_columns', 2);

function woocommerce_custom_product_columns($column) {
global $post;
global $post, $woocommerce;
$product = &new woocommerce_product($post->ID);

switch ($column) {
Expand Down Expand Up @@ -180,8 +180,8 @@ function woocommerce_custom_product_columns($column) {
case "featured" :
$url = wp_nonce_url( admin_url('admin-ajax.php?action=woocommerce-feature-product&product_id=' . $post->ID) );
echo '<a href="'.$url.'" title="'.__('Change', 'woothemes') .'">';
if ($product->is_featured()) echo '<a href="'.$url.'"><img src="'.woocommerce::plugin_url().'/assets/images/success.gif" alt="yes" />';
else echo '<img src="'.woocommerce::plugin_url().'/assets/images/success-off.gif" alt="no" />';
if ($product->is_featured()) echo '<a href="'.$url.'"><img src="'.$woocommerce->plugin_url().'/assets/images/success.gif" alt="yes" />';
else echo '<img src="'.$woocommerce->plugin_url().'/assets/images/success-off.gif" alt="no" />';
echo '</a>';
break;
case "visibility" :
Expand All @@ -192,7 +192,7 @@ function woocommerce_custom_product_columns($column) {
endif;
break;
case "is_in_stock" :
if ( !$product->is_type( 'grouped' ) && $product->is_in_stock() ) echo '<img src="'.woocommerce::plugin_url().'/assets/images/success.gif" alt="yes" />';
if ( !$product->is_type( 'grouped' ) && $product->is_in_stock() ) echo '<img src="'.$woocommerce->plugin_url().'/assets/images/success.gif" alt="yes" />';
else echo '<span class="na">&ndash;</span>';
break;
case "inventory" :
Expand Down
19 changes: 10 additions & 9 deletions admin/admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ function woocommerce_update_options($options) {
* Loops though the woocommerce options array and outputs each field.
*/
function woocommerce_admin_fields($options) {
global $woocommerce;
?>
<div class="icon32 icon32-woocommerce-settings" id="icon-woocommerce"><br></div><h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
<?php
Expand Down Expand Up @@ -781,7 +782,7 @@ function woocommerce_admin_fields($options) {
</tr><?php
break;
case 'single_select_country' :
$countries = woocommerce_countries::$countries;
$countries = $woocommerce->countries->countries;
$country_setting = (string) get_option($value['id']);
if (strstr($country_setting, ':')) :
$country = current(explode(':', $country_setting));
Expand All @@ -793,13 +794,13 @@ function woocommerce_admin_fields($options) {
?><tr valign="top" class="multi_select_countries">
<th scope="rpw" class="titledesc"><?php echo $value['name'] ?></th>
<td class="forminp"><select name="<?php echo $value['id'] ?>" title="Country" style="width: 175px;">
<?php echo woocommerce_countries::country_dropdown_options($country, $state); ?>
<?php echo $woocommerce->countries->country_dropdown_options($country, $state); ?>
</select> <span class="description"><?php echo $value['desc'] ?></span>
</td>
</tr><?php
break;
case 'multi_select_countries' :
$countries = woocommerce_countries::$countries;
$countries = $woocommerce->countries->countries;
asort($countries);
$selections = (array) get_option($value['id']);
?><tr valign="top" class="multi_select_countries">
Expand Down Expand Up @@ -830,7 +831,7 @@ function woocommerce_admin_fields($options) {
<?php $i = -1; if ($tax_rates && is_array($tax_rates) && sizeof($tax_rates)>0) foreach( $tax_rates as $rate ) : $i++; ?>
<div class="taxrow">
<select name="tax_country[<?php echo $i; ?>][]" title="Country" class="country_multiselect" size="10" multiple="multiple">
<?php echo woocommerce_countries::country_multiselect_options( $rate['countries'] ); ?>
<?php echo $woocommerce->countries->country_multiselect_options( $rate['countries'] ); ?>
</select>
<select name="tax_class[<?php echo $i; ?>]" title="Tax Class">
<option value=""><?php _e('Standard Rate', 'woothemes'); ?></option>
Expand All @@ -857,7 +858,7 @@ function woocommerce_admin_fields($options) {

$links = array();

foreach (woocommerce_shipping::$shipping_methods as $method) :
foreach ($woocommerce->shipping->shipping_methods as $method) :

$title = ($method->method_title) ? ucwords($method->method_title) : ucwords($method->id);

Expand All @@ -867,7 +868,7 @@ function woocommerce_admin_fields($options) {

echo '<div class="subsubsub_section"><ul class="subsubsub"><li>' . implode(' | </li><li>', $links) . '</li></ul><br class="clear" />';

foreach (woocommerce_shipping::$shipping_methods as $method) :
foreach ($woocommerce->shipping->shipping_methods as $method) :

echo '<div class="section" id="shipping-'.$method->id.'">';
$method->admin_options();
Expand All @@ -882,7 +883,7 @@ function woocommerce_admin_fields($options) {

$links = array();

foreach (woocommerce_payment_gateways::payment_gateways() as $gateway) :
foreach ($woocommerce->payment_gateways->payment_gateways() as $gateway) :

$title = ($gateway->title) ? ucwords($gateway->title) : ucwords($gateway->id);

Expand All @@ -892,7 +893,7 @@ function woocommerce_admin_fields($options) {

echo '<div class="subsubsub_section"><ul class="subsubsub"><li>' . implode(' | </li><li>', $links) . '</li></ul><br class="clear" />';

foreach (woocommerce_payment_gateways::payment_gateways() as $gateway) :
foreach ($woocommerce->payment_gateways->payment_gateways() as $gateway) :

echo '<div class="section" id="gateway-'.$gateway->id.'">';
$gateway->admin_options();
Expand Down Expand Up @@ -972,7 +973,7 @@ function woocommerce_admin_fields($options) {

// Add the row
jQuery('<div class="taxrow">\
<select name="tax_country[' + size + '][]" title="Country" class="country_multiselect" size="10" multiple="multiple"><?php echo woocommerce_countries::country_multiselect_options('',true); ?></select>\
<select name="tax_country[' + size + '][]" title="Country" class="country_multiselect" size="10" multiple="multiple"><?php echo $woocommerce->countries->country_multiselect_options('',true); ?></select>\
<select name="tax_class[' + size + ']" title="Tax Class"><option value=""><?php _e('Standard Rate', 'woothemes'); ?></option><?php
if ($tax_classes) foreach ($tax_classes as $class) :
echo '<option value="'.sanitize_title($class).'">'.$class.'</option>';
Expand Down
4 changes: 2 additions & 2 deletions admin/writepanels/writepanel-order_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function woocommerce_order_data_meta_box($post) {
* Displays the order items meta box - for showing individual items in the order
*/
function woocommerce_order_items_meta_box($post) {

global $woocommerce;
$order_items = (array) maybe_unserialize( get_post_meta($post->ID, '_order_items', true) );
?>
<div class="woocommerce_order_items_wrapper">
Expand Down Expand Up @@ -152,7 +152,7 @@ function woocommerce_order_items_meta_box($post) {
echo '<strong>'.__('Product ID:', 'woothemes').'</strong> '. $item['id'];
echo '<br/><strong>'.__('Variation ID:', 'woothemes').'</strong> '; if ($item['variation_id']) echo $item['variation_id']; else echo '-';
echo '<br/><strong>'.__('Product SKU:', 'woothemes').'</strong> '; if ($_product->sku) echo $_product->sku; else echo '-';
?>" src="<?php echo woocommerce::plugin_url(); ?>/assets/images/tip.png" />
?>" src="<?php echo $woocommerce->plugin_url(); ?>/assets/images/tip.png" />
</td>
<td class="name">
<a href="<?php echo admin_url('post.php?post='. $_product->id .'&action=edit'); ?>"><?php echo $item['name']; ?></a>
Expand Down
14 changes: 7 additions & 7 deletions admin/writepanels/writepanel-product-type-variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Product Options for the variable product type
*/
function variable_product_type_options() {
global $post;
global $post, $woocommerce;

$attributes = maybe_unserialize( get_post_meta($post->ID, 'product_attributes', true) );
if (!isset($attributes)) $attributes = array();
Expand All @@ -42,7 +42,7 @@ function variable_product_type_options() {
$image = wp_get_attachment_url( $variation_data['_thumbnail_id'][0] );
endif;

if (!$image) $image = woocommerce::plugin_url().'/assets/images/placeholder.png';
if (!$image) $image = $woocommerce->plugin_url().'/assets/images/placeholder.png';
?>
<div class="woocommerce_variation">
<p>
Expand Down Expand Up @@ -114,7 +114,7 @@ function variable_product_type_options() {
* Javascript for the variable product type
*/
function variable_product_write_panel_js() {
global $post;
global $post, $woocommerce;

$attributes = maybe_unserialize( get_post_meta($post->ID, 'product_attributes', true) );
if (!isset($attributes)) $attributes = array();
Expand All @@ -135,7 +135,7 @@ function variable_product_write_panel_js() {

jQuery('button.add_variation').live('click', function(){

jQuery('.woocommerce_variations').block({ message: null, overlayCSS: { background: '#fff url(<?php echo woocommerce::plugin_url(); ?>/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
jQuery('.woocommerce_variations').block({ message: null, overlayCSS: { background: '#fff url(<?php echo $woocommerce->plugin_url(); ?>/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });

var data = {
action: 'woocommerce_add_variation',
Expand Down Expand Up @@ -174,7 +174,7 @@ function variable_product_write_panel_js() {
<table cellpadding="0" cellspacing="0" class="woocommerce_variable_attributes">\
<tbody>\
<tr>\
<td class="upload_image"><img src="<?php echo woocommerce::plugin_url().'/assets/images/placeholder.png' ?>" width="60px" height="60px" /><input type="hidden" name="upload_image_id[' + loop + ']" class="upload_image_id" /><input type="button" class="upload_image_button button" rel="" value="<?php _e('Product Image', 'woothemes'); ?>" /></td>\
<td class="upload_image"><img src="<?php echo $woocommerce->plugin_url().'/assets/images/placeholder.png' ?>" width="60px" height="60px" /><input type="hidden" name="upload_image_id[' + loop + ']" class="upload_image_id" /><input type="button" class="upload_image_button button" rel="" value="<?php _e('Product Image', 'woothemes'); ?>" /></td>\
<td><label><?php _e('SKU:', 'woothemes'); ?></label><input type="text" size="5" name="variable_sku[' + loop + ']" /></td>\
<td><label><?php _e('Weight', 'woothemes').' ('.get_option('woocommerce_weight_unit').'):'; ?></label><input type="text" size="5" name="variable_weight[' + loop + ']" /></td>\
<td><label><?php _e('Stock Qty:', 'woothemes'); ?></label><input type="text" size="5" name="variable_stock[' + loop + ']" /></td>\
Expand All @@ -198,7 +198,7 @@ function variable_product_write_panel_js() {
var answer = confirm('<?php _e('Are you sure you want to link all variations? This will create a new variation for each and every possible combination of variation attributes.', 'woothemes'); ?>');
if (answer){

jQuery('.woocommerce_variations').block({ message: null, overlayCSS: { background: '#fff url(<?php echo woocommerce::plugin_url(); ?>/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
jQuery('.woocommerce_variations').block({ message: null, overlayCSS: { background: '#fff url(<?php echo $woocommerce->plugin_url(); ?>/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });

var data = {
action: 'woocommerce_link_all_variations',
Expand Down Expand Up @@ -228,7 +228,7 @@ function variable_product_write_panel_js() {

if (variation>0) {

jQuery(el).block({ message: null, overlayCSS: { background: '#fff url(<?php echo woocommerce::plugin_url(); ?>/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
jQuery(el).block({ message: null, overlayCSS: { background: '#fff url(<?php echo $woocommerce->plugin_url(); ?>/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });

var data = {
action: 'woocommerce_remove_variation',
Expand Down
Loading

0 comments on commit c18f533

Please sign in to comment.