-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings-tester.php
120 lines (100 loc) · 2.69 KB
/
settings-tester.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* Plugin Name: Settings Tester
* Version: 0.1.0
* Author: The WordPress Contributors
* Author URI: https://woocommerce.com
* Text Domain: settings-tester
* Domain Path: /languages
*
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* @package extension
*/
defined( 'ABSPATH' ) || exit;
if ( ! defined( 'MAIN_PLUGIN_FILE' ) ) {
define( 'MAIN_PLUGIN_FILE', __FILE__ );
}
require_once plugin_dir_path( __FILE__ ) . '/vendor/autoload_packages.php';
use SettingsTester\Admin\Setup;
// phpcs:disable WordPress.Files.FileName
/**
* WooCommerce fallback notice.
*
* @since 0.1.0
*/
function settings_tester_missing_wc_notice() {
/* translators: %s WC download URL link. */
echo '<div class="error"><p><strong>' . sprintf( esc_html__( 'Settings Tester requires WooCommerce to be installed and active. You can download %s here.', 'settings_tester' ), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>' ) . '</strong></p></div>';
}
register_activation_hook( __FILE__, 'settings_tester_activate' );
/**
* Activation hook.
*
* @since 0.1.0
*/
function settings_tester_activate() {
if ( ! class_exists( 'WooCommerce' ) ) {
add_action( 'admin_notices', 'settings_tester_missing_wc_notice' );
return;
}
}
if ( ! class_exists( 'settings_tester' ) ) :
/**
* The settings_tester class.
*/
class settings_tester {
/**
* This class instance.
*
* @var \settings_tester single instance of this class.
*/
private static $instance;
/**
* Constructor.
*/
public function __construct() {
new Setup();
}
/**
* Cloning is forbidden.
*/
public function __clone() {
wc_doing_it_wrong( __FUNCTION__, __( 'Cloning is forbidden.', 'settings_tester' ), $this->version );
}
/**
* Unserializing instances of this class is forbidden.
*/
public function __wakeup() {
wc_doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'settings_tester' ), $this->version );
}
/**
* Gets the main instance.
*
* Ensures only one instance can be loaded.
*
* @return \settings_tester
*/
public static function instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
}
endif;
add_action( 'plugins_loaded', 'settings_tester_init', 10 );
/**
* Initialize the plugin.
*
* @since 0.1.0
*/
function settings_tester_init() {
load_plugin_textdomain( 'settings_tester', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
if ( ! class_exists( 'WooCommerce' ) ) {
add_action( 'admin_notices', 'settings_tester_missing_wc_notice' );
return;
}
settings_tester::instance();
}