From 2a76f0c19d3538e1234e1bea63bf0935263def64 Mon Sep 17 00:00:00 2001 From: Joshua Flowers Date: Mon, 12 Nov 2018 11:30:09 +0800 Subject: [PATCH] Add WC_Admin_Taxonomies instance method --- includes/admin/class-wc-admin-taxonomies.php | 139 +++++++++++-------- 1 file changed, 80 insertions(+), 59 deletions(-) diff --git a/includes/admin/class-wc-admin-taxonomies.php b/includes/admin/class-wc-admin-taxonomies.php index 8b4e3e8bf41..e28bd12ab23 100644 --- a/includes/admin/class-wc-admin-taxonomies.php +++ b/includes/admin/class-wc-admin-taxonomies.php @@ -5,12 +5,10 @@ * @class WC_Admin_Taxonomies * @version 2.3.10 * @package WooCommerce/Admin - * @category Class - * @author WooThemes */ if ( ! defined( 'ABSPATH' ) ) { - exit; // Exit if accessed directly + exit; // Exit if accessed directly. } /** @@ -18,6 +16,13 @@ if ( ! defined( 'ABSPATH' ) ) { */ class WC_Admin_Taxonomies { + /** + * Class instance. + * + * @var WC_Admin_Taxonomies instance + */ + protected static $instance = false; + /** * Default category ID. * @@ -25,6 +30,16 @@ class WC_Admin_Taxonomies { */ private $default_cat_id = 0; + /** + * Get class instance + */ + public static function get_instance() { + if ( ! self::$instance ) { + self::$instance = new self(); + } + return self::$instance; + } + /** * Constructor. */ @@ -32,17 +47,17 @@ class WC_Admin_Taxonomies { // Default category ID. $this->default_cat_id = get_option( 'default_product_cat', 0 ); - // Category/term ordering + // Category/term ordering. add_action( 'create_term', array( $this, 'create_term' ), 5, 3 ); add_action( 'delete_term', array( $this, 'delete_term' ), 5 ); - // Add form + // Add form. add_action( 'product_cat_add_form_fields', array( $this, 'add_category_fields' ) ); add_action( 'product_cat_edit_form_fields', array( $this, 'edit_category_fields' ), 10 ); add_action( 'created_term', array( $this, 'save_category_fields' ), 10, 3 ); add_action( 'edit_term', array( $this, 'save_category_fields' ), 10, 3 ); - // Add columns + // Add columns. add_filter( 'manage_edit-product_cat_columns', array( $this, 'product_cat_columns' ) ); add_filter( 'manage_product_cat_custom_column', array( $this, 'product_cat_column' ), 10, 3 ); @@ -50,7 +65,7 @@ class WC_Admin_Taxonomies { add_filter( 'product_cat_row_actions', array( $this, 'product_cat_row_actions' ), 10, 2 ); add_filter( 'admin_init', array( $this, 'handle_product_cat_row_actions' ) ); - // Taxonomy page descriptions + // Taxonomy page descriptions. add_action( 'product_cat_pre_add_form', array( $this, 'product_cat_description' ) ); add_action( 'after-product_cat-table', array( $this, 'product_cat_notes' ) ); @@ -62,19 +77,19 @@ class WC_Admin_Taxonomies { } } - // Maintain hierarchy of terms + // Maintain hierarchy of terms. add_filter( 'wp_terms_checklist_args', array( $this, 'disable_checked_ontop' ) ); - // Admin footer scripts for this product categories admin screen + // Admin footer scripts for this product categories admin screen. add_action( 'admin_footer', array( $this, 'scripts_at_product_cat_screen_footer' ) ); } /** * Order term when created (put in position 0). * - * @param mixed $term_id - * @param mixed $tt_id - * @param string $taxonomy + * @param mixed $term_id Term ID. + * @param mixed $tt_id Term taxonomy ID. + * @param string $taxonomy Taxonomy slug. */ public function create_term( $term_id, $tt_id = '', $taxonomy = '' ) { if ( 'product_cat' != $taxonomy && ! taxonomy_is_product_attribute( $taxonomy ) ) { @@ -89,7 +104,7 @@ class WC_Admin_Taxonomies { /** * When a term is deleted, delete its meta. * - * @param mixed $term_id + * @param mixed $term_id Term ID. */ public function delete_term( $term_id ) { global $wpdb; @@ -107,21 +122,21 @@ class WC_Admin_Taxonomies { public function add_category_fields() { ?>
- +
- +
- - + +