Use new code style
This commit is contained in:
@ -34,17 +34,18 @@ class Product_List_Table extends Base_List_Table {
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(array(
|
||||
'singular' => __('Product', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Products', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true, // does this table support ajax?
|
||||
'add_new' => array(
|
||||
'url' => wu_network_admin_url('wp-ultimo-edit-product'),
|
||||
'classes' => '',
|
||||
),
|
||||
));
|
||||
|
||||
} // end __construct;
|
||||
parent::__construct(
|
||||
array(
|
||||
'singular' => __('Product', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Products', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true, // does this table support ajax?
|
||||
'add_new' => array(
|
||||
'url' => wu_network_admin_url('wp-ultimo-edit-product'),
|
||||
'classes' => '',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the content of the product column.
|
||||
@ -58,7 +59,7 @@ class Product_List_Table extends Base_List_Table {
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_id(),
|
||||
'model' => 'product'
|
||||
'model' => 'product',
|
||||
);
|
||||
|
||||
$title = sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-product', $url_atts), $item->get_name());
|
||||
@ -68,13 +69,22 @@ class Product_List_Table extends Base_List_Table {
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-product', $url_atts), __('Edit', 'wp-ultimo')),
|
||||
'duplicate' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-products', array('action' => 'duplicate', 'id' => $item->get_id())), __('Duplicate', 'wp-ultimo')),
|
||||
'duplicate' => sprintf(
|
||||
'<a href="%s">%s</a>',
|
||||
wu_network_admin_url(
|
||||
'wp-ultimo-products',
|
||||
array(
|
||||
'action' => 'duplicate',
|
||||
'id' => $item->get_id(),
|
||||
)
|
||||
),
|
||||
__('Duplicate', 'wp-ultimo')
|
||||
),
|
||||
'delete' => sprintf('<a title="%s" class="wubox" href="%s">%s</a>', __('Delete', 'wp-ultimo'), wu_get_form_url('delete_modal', $url_atts), __('Delete', 'wp-ultimo')),
|
||||
);
|
||||
|
||||
return $title . $this->row_actions($actions);
|
||||
|
||||
} // end column_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the type of the product.
|
||||
@ -91,8 +101,7 @@ class Product_List_Table extends Base_List_Table {
|
||||
$class = $item->get_type_class();
|
||||
|
||||
return "<span class='wu-bg-gray-200 wu-text-gray-700 wu-leading-none wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono $class'>{$label}</span>";
|
||||
|
||||
} // end column_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the slug of the product.
|
||||
@ -107,8 +116,7 @@ class Product_List_Table extends Base_List_Table {
|
||||
$slug = $item->get_slug();
|
||||
|
||||
return "<span class='wu-bg-gray-200 wu-text-gray-700 wu-leading-none wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono'>{$slug}</span>";
|
||||
|
||||
} // end column_slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the price of the product.
|
||||
@ -121,21 +129,16 @@ class Product_List_Table extends Base_List_Table {
|
||||
public function column_amount($item) {
|
||||
|
||||
if ($item->get_pricing_type() === 'contact_us') {
|
||||
|
||||
return __('None', 'wp-ultimo') . sprintf('<br><small>%s</small>', __('Requires contact', 'wp-ultimo'));
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
if (empty($item->get_amount())) {
|
||||
|
||||
return __('Free', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$amount = wu_format_currency($item->get_amount(), $item->get_currency());
|
||||
|
||||
if ($item->is_recurring()) {
|
||||
|
||||
$duration = $item->get_duration();
|
||||
|
||||
$message = sprintf(
|
||||
@ -145,8 +148,7 @@ class Product_List_Table extends Base_List_Table {
|
||||
$item->get_duration_unit()
|
||||
);
|
||||
|
||||
if (!$item->is_forever_recurring()) {
|
||||
|
||||
if ( ! $item->is_forever_recurring()) {
|
||||
$billing_cycles_message = sprintf(
|
||||
// translators: %s is the number of billing cycles.
|
||||
_n('for %s cycle', 'for %s cycles', $item->get_billing_cycles(), 'wp-ultimo'),
|
||||
@ -154,18 +156,13 @@ class Product_List_Table extends Base_List_Table {
|
||||
);
|
||||
|
||||
$message .= ' ' . $billing_cycles_message;
|
||||
|
||||
} // end if;
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
$message = __('one time payment', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return sprintf('%s<br><small>%s</small>', $amount, $message);
|
||||
|
||||
} // end column_amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the setup fee of the product.
|
||||
@ -178,20 +175,15 @@ class Product_List_Table extends Base_List_Table {
|
||||
public function column_setup_fee($item) {
|
||||
|
||||
if ($item->get_pricing_type() === 'contact_us') {
|
||||
|
||||
return __('None', 'wp-ultimo') . sprintf('<br><small>%s</small>', __('Requires contact', 'wp-ultimo'));
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
if (!$item->has_setup_fee()) {
|
||||
|
||||
if ( ! $item->has_setup_fee()) {
|
||||
return __('No Setup Fee', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return wu_format_currency($item->get_setup_fee(), $item->get_currency());
|
||||
|
||||
} // end column_setup_fee;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the bulk processing adding duplication.
|
||||
@ -204,18 +196,15 @@ class Product_List_Table extends Base_List_Table {
|
||||
$bulk_action = $this->current_action();
|
||||
|
||||
if ($bulk_action === 'duplicate') {
|
||||
|
||||
$product = wu_request('id');
|
||||
|
||||
$product = wu_get_product($product);
|
||||
|
||||
if (!$product) {
|
||||
|
||||
if ( ! $product) {
|
||||
WP_Ultimo()->notices->add(__('Product not found.', 'wp-ultimo'), 'error', 'network-admin');
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$new_product = $product->duplicate();
|
||||
|
||||
@ -230,25 +219,24 @@ class Product_List_Table extends Base_List_Table {
|
||||
$result = $new_product->save();
|
||||
|
||||
if (is_wp_error($result)) {
|
||||
|
||||
WP_Ultimo()->notices->add($result->get_error_message(), 'error', 'network-admin');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
$redirect_url = wu_network_admin_url('wp-ultimo-edit-product', array(
|
||||
'id' => $new_product->get_id(),
|
||||
'updated' => 1,
|
||||
));
|
||||
$redirect_url = wu_network_admin_url(
|
||||
'wp-ultimo-edit-product',
|
||||
array(
|
||||
'id' => $new_product->get_id(),
|
||||
'updated' => 1,
|
||||
)
|
||||
);
|
||||
|
||||
wp_redirect($redirect_url);
|
||||
|
||||
exit;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end process_single_action;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
@ -270,8 +258,7 @@ class Product_List_Table extends Base_List_Table {
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the item display for grid mode.
|
||||
@ -283,12 +270,14 @@ class Product_List_Table extends Base_List_Table {
|
||||
*/
|
||||
public function single_row_grid($item) {
|
||||
|
||||
wu_get_template('base/products/grid-item', array(
|
||||
'item' => $item,
|
||||
'table' => $this,
|
||||
));
|
||||
|
||||
} // end single_row_grid;
|
||||
wu_get_template(
|
||||
'base/products/grid-item',
|
||||
array(
|
||||
'item' => $item,
|
||||
'table' => $this,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filters for this page.
|
||||
@ -300,8 +289,7 @@ class Product_List_Table extends Base_List_Table {
|
||||
return array(
|
||||
'filters' => array(),
|
||||
);
|
||||
|
||||
} // end get_filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pre-selected filters on the filter bar.
|
||||
@ -337,7 +325,5 @@ class Product_List_Table extends Base_List_Table {
|
||||
'count' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_views;
|
||||
|
||||
} // end class Product_List_Table;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user