PluginProbe
Essential Widgets / 3.2
Essential Widgets v3.2
3.2.1 3.3 3.2 trunk 1.0.0 1.0.1 1.1 1.2 1.2.1 1.2.2 1.3 1.4 1.4.1 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8 1.9 2.0 2.1 2.2 All 31 releases
essential-widgets / includes / class-essential-widgets.php

class-essential-widgets.php in Essential Widgets 3.2, at includes/class-essential-widgets.php

231 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 /**
8 * The file that defines the core plugin class
9 *
10 * A class definition that includes attributes and functions used across both the
11 * public-facing side of the site and the admin area.
12 *
13 * @link https://catchplugins.com
14 * @since 1.0.0
15 *
16 * @package Essential_Widgets
17 * @subpackage Essential_Widgets/includes
18 */
19
20 /**
21 * The core plugin class.
22 *
23 * This is used to define internationalization, admin-specific hooks, and
24 * public-facing site hooks.
25 *
26 * Also maintains the unique identifier of this plugin as well as the current
27 * version of the plugin.
28 *
29 * @since 1.0.0
30 * @package Essential_Widgets
31 * @subpackage Essential_Widgets/includes
32 * @author Catch Plugins <info@catchplugins.com>
33 */
34 class Essential_Widgets {
35
36 /**
37 * The loader that's responsible for maintaining and registering all hooks that power
38 * the plugin.
39 *
40 * @since 1.0.0
41 * @access protected
42 * @var Essential_Widgets_Loader $loader Maintains and registers all hooks for the plugin.
43 */
44 protected $loader;
45
46 /**
47 * The unique identifier of this plugin.
48 *
49 * @since 1.0.0
50 * @access protected
51 * @var string $plugin_name The string used to uniquely identify this plugin.
52 */
53 protected $plugin_name;
54
55 /**
56 * The current version of the plugin.
57 *
58 * @since 1.0.0
59 * @access protected
60 * @var string $version The current version of the plugin.
61 */
62 protected $version;
63
64 /**
65 * Define the core functionality of the plugin.
66 *
67 * Set the plugin name and the plugin version that can be used throughout the plugin.
68 * Load the dependencies, define the locale, and set the hooks for the admin area and
69 * the public-facing side of the site.
70 *
71 * @since 1.0.0
72 */
73 public function __construct() {
74
75 $this->version = ESSENTIAL_WIDGETS_VERSION;
76
77 $this->plugin_name = 'essential-widgets';
78
79 $this->load_dependencies();
80 $this->set_locale();
81 $this->define_admin_hooks();
82 $this->define_public_hooks();
83
84 }
85
86 /**
87 * Load the required dependencies for this plugin.
88 *
89 * Include the following files that make up the plugin:
90 *
91 * - Essential_Widgets_Loader. Orchestrates the hooks of the plugin.
92 * - Essential_Widgets_i18n. Defines internationalization functionality.
93 * - Essential_Widgets_Admin. Defines all hooks for the admin area.
94 * - Essential_Widgets_Public. Defines all hooks for the public side of the site.
95 *
96 * Create an instance of the loader which will be used to register the hooks
97 * with WordPress.
98 *
99 * @since 1.0.0
100 * @access private
101 */
102 private function load_dependencies() {
103
104 /**
105 * The class responsible for orchestrating the actions and filters of the
106 * core plugin.
107 */
108 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-essential-widgets-loader.php';
109
110 /**
111 * The class responsible for defining internationalization functionality
112 * of the plugin.
113 */
114 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-essential-widgets-i18n.php';
115
116 /**
117 * The class responsible for defining all actions that occur in the admin area.
118 */
119 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-essential-widgets-admin.php';
120
121 /**
122 * The class responsible for defining all actions that occur in the public-facing
123 * side of the site.
124 */
125 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-essential-widgets-public.php';
126
127 /* widgets include */
128 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/widgets/widgets.php';
129
130 $this->loader = new Essential_Widgets_Loader();
131
132 }
133
134 /**
135 * Define the locale for this plugin for internationalization.
136 *
137 * Uses the Essential_Widgets_i18n class in order to set the domain and to register the hook
138 * with WordPress.
139 *
140 * @since 1.0.0
141 * @access private
142 */
143 private function set_locale() {
144
145 $plugin_i18n = new Essential_Widgets_i18n();
146
147 $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
148
149 }
150
151 /**
152 * Register all of the hooks related to the admin area functionality
153 * of the plugin.
154 *
155 * @since 1.0.0
156 * @access private
157 */
158 private function define_admin_hooks() {
159
160 $plugin_admin = new Essential_Widgets_Admin( $this->get_plugin_name(), $this->get_version() );
161
162 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
163 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
164
165 $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_settings_menu' );
166
167 $this->loader->add_action( 'admin_init', $plugin_admin, 'register_settings' );
168 $this->loader->add_filter( 'plugin_action_links_' . ESSENTIAL_WIDGETS_BASENAME, $plugin_admin, 'action_links', 10, 1 );
169 $this->loader->add_action( 'wp_ajax_ew_switch', $plugin_admin, 'ew_switch' );
170 $this->loader->add_filter( 'plugin_row_meta', $plugin_admin, 'add_plugin_meta_links', 10, 2 );
171
172 }
173
174 /**
175 * Register all of the hooks related to the public-facing functionality
176 * of the plugin.
177 *
178 * @since 1.0.0
179 * @access private
180 */
181 private function define_public_hooks() {
182
183 $plugin_public = new Essential_Widgets_Public( $this->get_plugin_name(), $this->get_version() );
184
185 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
186 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
187
188 }
189
190 /**
191 * Run the loader to execute all of the hooks with WordPress.
192 *
193 * @since 1.0.0
194 */
195 public function run() {
196 $this->loader->run();
197 }
198
199 /**
200 * The name of the plugin used to uniquely identify it within the context of
201 * WordPress and to define internationalization functionality.
202 *
203 * @since 1.0.0
204 * @return string The name of the plugin.
205 */
206 public function get_plugin_name() {
207 return $this->plugin_name;
208 }
209
210 /**
211 * The reference to the class that orchestrates the hooks with the plugin.
212 *
213 * @since 1.0.0
214 * @return Essential_Widgets_Loader Orchestrates the hooks of the plugin.
215 */
216 public function get_loader() {
217 return $this->loader;
218 }
219
220 /**
221 * Retrieve the version number of the plugin.
222 *
223 * @since 1.0.0
224 * @return string The version number of the plugin.
225 */
226 public function get_version() {
227 return $this->version;
228 }
229
230 }
231