AS_Boilerplate_Loader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
/**
3
 * @package   Awesome Support Addon Boilerplate
4
 * @author    Awesome Support <[email protected]>
5
 * @license   GPL-2.0+
6
 * @link      http://getawesomesupport.com
7
 * @copyright 2015-2018 Awesome Support
8
 * 
9
 * @boilerplate-version   2.0.0
10
 *
11
 * Plugin Name:       Awesome Support: Boilerplate (This name should be changed)
12
 * Plugin URI:        http://getawesomesupport.com/addons/?utm_source=internal&utm_medium=plugin_meta&utm_campaign=Addons_Boilerplate
13
 * Description:       A boilerplate for creating add-ons for Awesome Support.  Please see the readme.md file for how to use this.  If you see this message chances are you didn't read the file!
14
 * Version:           2.0.0
15
 * Author:            Awesome Support
16
 * Author URI:        http://getawesomesupport.com/?utm_source=internal&utm_medium=plugin_meta&utm_campaign=Addons_Boilerplate
17
 * Text Domain:       as-boilerplate
18
 * License:           GPL-2.0+
19
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
20
 * Domain Path:       /languages
21
 */
22
 
23
 /*
24
  * Instructions
25
  * 
26
  * 1. Rename this file - from boilerplate.php to something like awesome-support-your-function.php
27
  * 2. You should change the data in the header above.  In particular the name, description, uris, textdomain and versions.
28
  * 3. Change the main class name from AS_Boilerplate_Loader to something more representative of what you're building.
29
  * 4. In the constructor of the class, change the values passed to all the setXXX functions.  Right now there are 7 of those setXXX functions being called.
30
  * 5. The load() method at the end of the class is where you can hook into your own code, preferably by including your primary file.
31
  *
32
  */
33
34
// If this file is called directly, abort.
35
if ( ! defined( 'WPINC' ) ) {
36
	die;
37
}
38
39
// Include extension base class
40
if ( !class_exists( 'WPAS_Extension_Base' ) ) {
41
	
42
	$wpas_dir = defined( 'WPAS_ROOT' )  ? WPAS_ROOT : ( defined( 'WPAS_AS_FOLDER' ) ? WPAS_AS_FOLDER : 'awesome-support' );
43
	$wpas_eb_file = trailingslashit( WP_PLUGIN_DIR . '/' . $wpas_dir ) . 'includes/class-extension-base.php';
44
	
45
	if( file_exists( $wpas_eb_file ) ) {
46
		require_once ( $wpas_eb_file );
47
	} else {
48
		add_action( 'admin_notices', function() {
49
		?>	
50
		
51
		<div class="error">
52
			<p>
53
				<?php printf( __( 'You need Awesome Support to activate this Awesome Support addon. Please <a href="%s" target="_blank">install Awesome Support</a> before continuing.', 'as-boilerplate' ), esc_url( 'http://getawesomesupport.com/?utm_source=internal&utm_medium=addon_loader&utm_campaign=Addons' ) ); ?>
54
			</p>
55
		</div>
56
			
57
		<?php	
58
			
59
		});
60
		
61
		return;
62
	}
63
}
64
65
/*----------------------------------------------------------------------------*
66
 * Instantiate the plugin
67
 *----------------------------------------------------------------------------*/
68
69
/**
70
 * Register the activation hook
71
 */
72
register_activation_hook( __FILE__, array( 'AS_Boilerplate_Loader', 'activate' ) );
73
74
add_action( 'plugins_loaded', array( 'AS_Boilerplate_Loader', 'get_instance' ) );
75
/**
76
 * Instantiate the addon.
77
 *
78
 * This method runs a few checks to make sure that the addon
79
 * can indeed be used in the current context, after what it
80
 * registers the addon to the core plugin for it to be loaded
81
 * when the entire core is ready.
82
 *
83
 * @since  0.1.0
84
 * @return void
85
 */
86
class AS_Boilerplate_Loader  extends WPAS_Extension_Base {
87
	
88
	/**
89
	 * Instance of this loader class.
90
	 *
91
	 * @since    0.1.0
92
	 * @var      object
93
	 */
94
	protected static $instance = null;	
95
96
97
	public function __construct() {
98
		
99
		$this->setVersionRequired( '5.1.0' );			// Set required version of core
100
		$this->setPhpVersionRequired( '5.6' );			// Set required version of php
101
		$this->setSlug( 'wpas-boilerplate-addon' );		// Set addon slug
102
		$this->setUid( 'BPA' );							// Set short unique id
103
		$this->setTextDomain( 'as-boilderplate' );		// Set text domain for translation
104
		$this->setVersion( '1.0.0' );					// Set addon version
105
		$this->setItemId( 9999999 );					// Set addon item id if integrating with EDD licensing module
106
		
107
		parent::__construct();
108
		
109
	}
110
111
	/**
112
	 * Return an instance of this class.
113
	 *
114
	 * @since     3.0.0
115
	 * @return    object    A single instance of this class.
116
	 */
117
	public static function get_instance() {
118
119
		// If the single instance hasn't been set, set it now.
120
		if ( null == self::$instance ) {
121
			self::$instance = new self;
122
		}
123
124
		return self::$instance;
125
	}
126
127
	/**
128
	 * Activate the plugin.
129
	 *
130
	 * The activation method just checks if the main plugin
131
	 * Awesome Support is installed (active or inactive) on the site.
132
	 * If not, the addon installation is aborted and an error message is displayed.
133
	 *
134
	 * @since  0.1.0
135
	 * @return void
136
	 */
137
	public static function activate() {
138
139
		if ( ! class_exists( 'Awesome_Support' ) ) {
140
			deactivate_plugins( basename( __FILE__ ) );
141
			wp_die(
142
				sprintf( __( 'You need Awesome Support to activate this addon. Please <a href="%s" target="_blank">install Awesome Support</a> before continuing.', 'as-boilerplate' ), esc_url( 'http://getawesomesupport.com/?utm_source=internal&utm_medium=addon_loader&utm_campaign=Addons' ) )
143
			);
144
		}
145
146
	}
147
148
	/**
149
	 * Load the addon.
150
	 *
151
	 * Include all necessary files and instantiate the addon.
152
	 *
153
	 * @since  0.1.0
154
	 * @return void
155
	 */
156
	public function load() {
157
158
		// Load the addon here - i.e.: this is where you can put your own code, preferably by using include statements.		
159
160
	}
161
162
}