PluginProbe
Siteimprove / 2.1.4
Siteimprove v2.1.4
2.1.4 trunk 1.0.0 1.1.0 1.2.0 1.2.1 1.3.0 1.3.1 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.1.1 2.1.2 2.1.3
siteimprove / includes / class-siteimprove.php

class-siteimprove.php in Siteimprove 2.1.4, at includes/class-siteimprove.php

195 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The file that defines the core plugin class
4 *
5 * A class definition that includes attributes and functions used across both the
6 * public-facing side of the site and the admin area.
7 *
8 * @package Siteimprove
9 * @subpackage Siteimprove/includes
10 */
11
12 /**
13 * The core plugin class.
14 *
15 * This is used to define internationalization, admin-specific hooks, and
16 * public-facing site hooks.
17 *
18 * Also maintains the unique identifier of this plugin as well as the current
19 * version of the plugin.
20 *
21 * @package Siteimprove
22 * @subpackage Siteimprove/includes
23 */
24 class Siteimprove {
25
26 /**
27 * The loader that's responsible for maintaining and registering all hooks that power
28 * the plugin.
29 *
30 * @access protected
31 * @var Siteimprove_Loader $loader Maintains and registers all hooks for the plugin.
32 */
33 protected $loader;
34
35 /**
36 * The unique identifier of this plugin.
37 *
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 * @access protected
47 * @var string $version The current version of the plugin.
48 */
49 protected $version;
50
51 const JS_LIBRARY_URL = 'https://cdn.siteimprove.net/cms/';
52
53 /**
54 * Define the core functionality of the plugin.
55 *
56 * Set the plugin name and the plugin version that can be used throughout the plugin.
57 * Load the dependencies, define the locale, and set the hooks for the admin area and
58 * the public-facing side of the site.
59 */
60 public function __construct() {
61
62 $this->plugin_name = 'siteimprove';
63 $this->version = '2.1.4';
64
65 $this->load_dependencies();
66 $this->set_locale();
67 $this->define_admin_hooks();
68
69 }
70
71 /**
72 * Load the required dependencies for this plugin.
73 *
74 * Include the following files that make up the plugin:
75 *
76 * - Siteimprove_Loader. Orchestrates the hooks of the plugin.
77 * - Siteimprove_I18n. Defines internationalization functionality.
78 * - Siteimprove_Admin. Defines all hooks for the admin area.
79 * - Siteimprove_Public. Defines all hooks for the public side of the site.
80 *
81 * Create an instance of the loader which will be used to register the hooks
82 * with WordPress.
83 *
84 * @access private
85 */
86 private function load_dependencies() {
87
88 /**
89 * The class responsible for orchestrating the actions and filters of the
90 * core plugin.
91 */
92 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-siteimprove-loader.php';
93
94 /**
95 * The class responsible for defining internationalization functionality
96 * of the plugin.
97 */
98 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-siteimprove-i18n.php';
99
100 /**
101 * The class responsible for defining all actions that occur in the admin area.
102 */
103 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-siteimprove-admin.php';
104
105 $this->loader = new Siteimprove_Loader();
106
107 }
108
109 /**
110 * Define the locale for this plugin for internationalization.
111 *
112 * Uses the Siteimprove_I18n class in order to set the domain and to register the hook
113 * with WordPress.
114 *
115 * @access private
116 */
117 private function set_locale() {
118
119 $plugin_i18n = new Siteimprove_I18n();
120
121 $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
122
123 }
124
125 /**
126 * Register all of the hooks related to the admin area functionality
127 * of the plugin.
128 *
129 * @access private
130 */
131 private function define_admin_hooks() {
132
133 $plugin_admin = new Siteimprove_Admin( $this->get_plugin_name(), $this->get_version() );
134
135 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
136 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_admin, 'enqueue_preview_styles' );
137 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
138 $this->loader->add_action( 'enqueue_block_editor_assets', $plugin_admin, 'gutenberg_siteimprove_plugin' );
139
140 // Settings form.
141 $this->loader->add_action( 'admin_init', $plugin_admin, 'siteimprove_settings' );
142 $this->loader->add_action( 'admin_menu', $plugin_admin, 'siteimprove_settings_page' );
143 $this->loader->add_action( 'wp_ajax_siteimprove_request_token', $plugin_admin, 'siteimprove_request_token' );
144 $this->loader->add_action( 'wp_ajax_siteimprove_prepublish_activation', $plugin_admin, 'siteimprove_prepublish_manual_activation' );
145 $this->loader->add_action( 'wp_ajax_siteimprove_check_prepublish_activation', $plugin_admin, 'siteimprove_check_prepublish_activation' );
146 $this->loader->add_action( 'siteimprove_before_settings_form', $plugin_admin, 'siteimprove_before_settings_form' );
147
148 // Siteimprove Actions.
149 $this->loader->add_action( 'admin_init', $plugin_admin, 'siteimprove_init' );
150 $this->loader->add_action( 'publish_page', $plugin_admin, 'siteimprove_save_session_url_post' );
151 $this->loader->add_action( 'publish_post', $plugin_admin, 'siteimprove_save_session_url_post' );
152 $this->loader->add_action( 'edit_term', $plugin_admin, 'siteimprove_save_session_url_term', 10, 3 );
153 $this->loader->add_action( 'create_term', $plugin_admin, 'siteimprove_save_session_url_term', 10, 3 );
154 $this->loader->add_action( 'transition_post_status', $plugin_admin, 'siteimprove_save_session_url_product', 10, 3 );
155 $this->loader->add_action( 'wp_head', $plugin_admin, 'siteimprove_wp_head' );
156 $this->loader->add_action( 'admin_bar_menu', $plugin_admin, 'add_prepublish_toolbar_item', 500, 1 );
157 }
158
159 /**
160 * Run the loader to execute all of the hooks with WordPress.
161 */
162 public function run() {
163 $this->loader->run();
164 }
165
166 /**
167 * The name of the plugin used to uniquely identify it within the context of
168 * WordPress and to define internationalization functionality.
169 *
170 * @return string The name of the plugin.
171 */
172 public function get_plugin_name() {
173 return $this->plugin_name;
174 }
175
176 /**
177 * The reference to the class that orchestrates the hooks with the plugin.
178 *
179 * @return Siteimprove_Loader Orchestrates the hooks of the plugin.
180 */
181 public function get_loader() {
182 return $this->loader;
183 }
184
185 /**
186 * Retrieve the version number of the plugin.
187 *
188 * @return string The version number of the plugin.
189 */
190 public function get_version() {
191 return $this->version;
192 }
193
194 }
195