PluginProbe
To Top / trunk
To Top vtrunk
trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.6 1.7 1.8 1.8.1 1.9 2.0 2.1 2.2 2.2.1 2.2.2 2.3 2.4 All 34 releases
to-top / includes / class-to-top.php

class-to-top.php in To Top trunk, at includes/class-to-top.php

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