28
28
return ;
29
29
}
30
30
31
- /**
32
- * The WC_Seq_Order_Number global object
33
- * @name $wc_seq_order_number
34
- * @global WC_Seq_Order_Number $GLOBALS['wc_seq_order_number']
35
- */
36
- $ GLOBALS ['wc_seq_order_number ' ] = new WC_Seq_Order_Number ();
37
-
38
31
class WC_Seq_Order_Number {
39
32
40
33
41
34
/** version number */
42
35
const VERSION = '1.7.0 ' ;
43
36
37
+ /** @var \WC_Seq_Order_Number single instance of this plugin */
38
+ protected static $ instance ;
39
+
44
40
/** version option name */
45
41
const VERSION_OPTION_NAME = 'woocommerce_seq_order_number_db_version ' ;
46
42
@@ -60,6 +56,30 @@ public function __construct() {
60
56
}
61
57
62
58
59
+ /**
60
+ * Cloning instances is forbidden due to singleton pattern.
61
+ *
62
+ * @since 1.7.0
63
+ */
64
+ public function __clone () {
65
+
66
+ /* translators: Placeholders: %s - plugin name */
67
+ _doing_it_wrong ( __FUNCTION__ , sprintf ( esc_html__ ( 'You cannot clone instances of %s. ' , 'woocommerce-sequential-order-numbers ' ), $ this ->get_plugin_name () ), '1.7.0 ' );
68
+ }
69
+
70
+
71
+ /**
72
+ * Unserializing instances is forbidden due to singleton pattern.
73
+ *
74
+ * @since 1.7.0
75
+ */
76
+ public function __wakeup () {
77
+
78
+ /* translators: Placeholders: %s - plugin name */
79
+ _doing_it_wrong ( __FUNCTION__ , sprintf ( esc_html__ ( 'You cannot unserialize instances of %s. ' , 'woocommerce-sequential-order-numbers ' ), $ this ->get_plugin_name () ), '1.7.0 ' );
80
+ }
81
+
82
+
63
83
/**
64
84
* Initialize the plugin, bailing if any required conditions are not met,
65
85
* including minimum WooCommerce version
@@ -335,6 +355,21 @@ public function subscriptions_remove_renewal_order_meta( $order_meta_query ) {
335
355
/** Helper Methods ******************************************************/
336
356
337
357
358
+ /**
359
+ * Main Sequential Order Numbers Instance, ensures only one instance is/can be loaded
360
+ *
361
+ * @since 1.7.0
362
+ * @see wc_sequential_order_numbers()
363
+ * @return \WC_Seq_Order_Number
364
+ */
365
+ public static function instance () {
366
+ if ( is_null ( self ::$ instance ) ) {
367
+ self ::$ instance = new self ();
368
+ }
369
+ return self ::$ instance ;
370
+ }
371
+
372
+
338
373
/**
339
374
* Checks if WooCommerce is active
340
375
*
@@ -496,3 +531,39 @@ private function upgrade( $installed_version ) {
496
531
497
532
498
533
}
534
+
535
+
536
+ /**
537
+ * Returns the One True Instance of Sequential Order Numbers
538
+ *
539
+ * @since 1.7.0
540
+ * @return \WC_Seq_Order_Number
541
+ */
542
+ function wc_sequential_order_numbers () {
543
+ return WC_Seq_Order_Number::instance ();
544
+ }
545
+
546
+
547
+ /**
548
+ * Returns the One True Instance of Sequential Order Numbers after warning that
549
+ * the global has been deprecated
550
+ *
551
+ * @since 1.7.0
552
+ * @return \WC_Seq_Order_Number
553
+ */
554
+ function wc_sequential_order_numbers_deprecated_global () {
555
+
556
+ /* @deprecated since 1.7.0 */
557
+ _deprecated_function ( "\$GLOBALS['wc_seq_order_number'] " , '1.7.0 ' , 'wc_sequential_order_numbers() ' );
558
+
559
+ return wc_sequential_order_numbers ();
560
+ }
561
+
562
+
563
+ /**
564
+ * The WC_Seq_Order_Number global object
565
+ * @deprecated 1.7.0
566
+ * @name $wc_seq_order_number
567
+ * @global WC_Seq_Order_Number $GLOBALS['wc_seq_order_number']
568
+ */
569
+ $ GLOBALS ['wc_seq_order_number ' ] = wc_sequential_order_numbers_deprecated_global ();
0 commit comments