PluginProbe
WPComplete / 1.4
WPComplete v1.4
2.9.5.7 2.9.5.6 trunk 1.0 1.1 1.2 1.4 1.4.6 2.3 2.9.1 2.9.2 2.9.5 2.9.5.1 2.9.5.3 2.9.5.4 2.9.5.5
wpcomplete / includes / class-wpcomplete.php

class-wpcomplete.php in WPComplete 1.4, at includes/class-wpcomplete.php

256 lines 8.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The file that defines the core plugin class
5 *
6 * A class definition that includes attributes and functions used across both the
7 * public-facing side of the site and the admin area.
8 *
9 * @link http://wpcomplete.co
10 * @since 1.0.0
11 *
12 * @package WPComplete
13 * @subpackage wpcomplete/includes
14 */
15
16 /**
17 * The core plugin class.
18 *
19 * This is used to define internationalization, admin-specific hooks, and
20 * public-facing site hooks.
21 *
22 * Also maintains the unique identifier of this plugin as well as the current
23 * version of the plugin.
24 *
25 * @since 1.0.0
26 * @package WPComplete
27 * @subpackage wpcomplete/includes
28 * @author Zack Gilbert <zack@zackgilbert.com>
29 */
30 class WPComplete {
31
32 /**
33 * The loader that's responsible for maintaining and registering all hooks that power
34 * the plugin.
35 *
36 * @since 1.0.0
37 * @access protected
38 * @var WPComplete_Loader $loader Maintains and registers all hooks for the plugin.
39 */
40 protected $loader;
41
42 /**
43 * The unique identifier of this plugin.
44 *
45 * @since 1.0.0
46 * @access protected
47 * @var string $plugin_name The string used to uniquely identify this plugin.
48 */
49 protected $plugin_name;
50
51 /**
52 * The current version of the plugin.
53 *
54 * @since 1.0.0
55 * @access protected
56 * @var string $version The current version of the plugin.
57 */
58 protected $version;
59
60 /**
61 * Define the core functionality of the plugin.
62 *
63 * Set the plugin name and the plugin version that can be used throughout the plugin.
64 * Load the dependencies, define the locale, and set the hooks for the admin area and
65 * the public-facing side of the site.
66 *
67 * @since 1.0.0
68 */
69 public function __construct() {
70
71 $this->plugin_name = WPCOMPLETE_PREFIX;
72 $this->version = '1.4.4';
73
74 $this->load_dependencies();
75 $this->set_locale();
76 $this->define_admin_hooks();
77 $this->define_public_hooks();
78
79 }
80
81 /**
82 * Load the required dependencies for this plugin.
83 *
84 * Include the following files that make up the plugin:
85 *
86 * - WPComplete_Loader. Orchestrates the hooks of the plugin.
87 * - WPComplete_i18n. Defines internationalization functionality.
88 * - WPComplete_Admin. Defines all hooks for the admin area.
89 * - WPComplete_Public. Defines all hooks for the public side of the site.
90 *
91 * Create an instance of the loader which will be used to register the hooks
92 * with WordPress.
93 *
94 * @since 1.0.0
95 * @access private
96 */
97 private function load_dependencies() {
98
99 /**
100 * The class responsible for orchestrating the actions and filters of the
101 * core plugin.
102 */
103 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpcomplete-loader.php';
104
105 /**
106 * The class responsible for defining internationalization functionality
107 * of the plugin.
108 */
109 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpcomplete-i18n.php';
110
111 /**
112 * The class responsible for defining all actions that occur in the admin area.
113 */
114 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpcomplete-admin.php';
115
116 /**
117 * The class responsible for defining all actions that occur in the public-facing
118 * side of the site.
119 */
120 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wpcomplete-public.php';
121
122 $this->loader = new WPComplete_Loader();
123
124 }
125
126 /**
127 * Define the locale for this plugin for internationalization.
128 *
129 * Uses the WPComplete_i18n class in order to set the domain and to register the hook
130 * with WordPress.
131 *
132 * @since 1.0.0
133 * @access private
134 */
135 private function set_locale() {
136
137 $plugin_i18n = new WPComplete_i18n();
138
139 $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
140
141 }
142
143 /**
144 * Register all of the hooks related to the admin area functionality
145 * of the plugin.
146 *
147 * @since 1.0.0
148 * @access private
149 */
150 private function define_admin_hooks() {
151
152 $plugin_admin = new WPComplete_Admin( $this->get_plugin_name(), $this->get_version() );
153
154 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
155 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
156 // adding settings page and metaboxes
157 $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_options_page' );
158 $this->loader->add_action( 'admin_init', $plugin_admin, 'register_settings' );
159 $this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'add_completable_metabox' );
160 $this->loader->add_action( 'save_post', $plugin_admin, 'save_completable' );
161 // adding bulk actions
162 $this->loader->add_action( 'admin_footer-edit.php', $plugin_admin, 'add_bulk_actions' );
163 $this->loader->add_action( 'load-edit.php', $plugin_admin, 'save_bulk_completable' );
164 $this->loader->add_action( 'admin_notices', $plugin_admin, 'show_bulk_action_notice' );
165 // adding custom edit column + quick edit
166 $this->loader->add_action( 'manage_pages_columns', $plugin_admin, 'add_custom_column_header' );
167 $this->loader->add_action( 'manage_posts_columns', $plugin_admin, 'add_custom_column_header' );
168 $this->loader->add_action( 'manage_pages_custom_column', $plugin_admin, 'add_custom_column_value', 10, 2 );
169 $this->loader->add_action( 'manage_posts_custom_column', $plugin_admin, 'add_custom_column_value', 10, 2 );
170 //$this->loader->add_action( 'manage_edit-page_sortable_columns', $plugin_admin, 'sort_custom_column' );
171 //$this->loader->add_action( 'manage_edit-post_sortable_columns', $plugin_admin, 'sort_custom_column' );
172 $this->loader->add_action( 'quick_edit_custom_box', $plugin_admin, 'add_custom_quick_edit', 10, 2 );
173 // adding custom completion column for users
174 $this->loader->add_action( 'manage_users_columns', $plugin_admin, 'add_user_column_header' );
175 $this->loader->add_action( 'manage_users_custom_column', $plugin_admin, 'add_user_column_value', 10, 3 );
176 //$this->loader->add_action( 'manage_users_sortable_columns', $plugin_admin, 'sort_custom_column' );
177 //$this->loader->add_action( 'pre_user_query', $plugin_admin, 'user_column_orderby' );
178
179 // PREMIUM: add specific pages to show completion
180 $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_post_completion_page' );
181 $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_user_completion_page' );
182 }
183
184 /**
185 * Register all of the hooks related to the public-facing functionality
186 * of the plugin.
187 *
188 * @since 1.0.0
189 * @access private
190 */
191 private function define_public_hooks() {
192
193 $plugin_public = new WPComplete_Public( $this->get_plugin_name(), $this->get_version() );
194
195 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
196 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
197
198 $this->loader->add_filter( 'the_content', $plugin_public, 'append_completion_code', 1 );
199
200 // Custom ajax functions:
201 $this->loader->add_action( 'wp_ajax_mark_completed', $plugin_public , 'mark_completed' );
202 $this->loader->add_action( 'wp_ajax_nopriv_mark_completed', $plugin_public , 'no_priv_mark_completed' );
203 $this->loader->add_action( 'wp_ajax_mark_uncompleted', $plugin_public , 'mark_uncompleted' );
204 $this->loader->add_action( 'wp_ajax_nopriv_mark_uncompleted', $plugin_public , 'no_priv_mark_uncompleted' );
205
206 // Add shortcodes:
207 $this->loader->add_shortcode( 'complete_button', $plugin_public, 'complete_button_cb' );
208 $this->loader->add_shortcode( 'wpc_complete_button', $plugin_public, 'complete_button_cb' );
209 $this->loader->add_shortcode( 'wpc_button', $plugin_public, 'complete_button_cb' );
210 $this->loader->add_shortcode( 'wpcomplete_button', $plugin_public, 'complete_button_cb' );
211
212 $this->loader->add_action( 'wp_head', $plugin_public, 'append_custom_styles' );
213 }
214
215 /**
216 * Run the loader to execute all of the hooks with WordPress.
217 *
218 * @since 1.0.0
219 */
220 public function run() {
221 $this->loader->run();
222 }
223
224 /**
225 * The name of the plugin used to uniquely identify it within the context of
226 * WordPress and to define internationalization functionality.
227 *
228 * @since 1.0.0
229 * @return string The name of the plugin.
230 */
231 public function get_plugin_name() {
232 return $this->plugin_name;
233 }
234
235 /**
236 * The reference to the class that orchestrates the hooks with the plugin.
237 *
238 * @since 1.0.0
239 * @return WPComplete_Loader Orchestrates the hooks of the plugin.
240 */
241 public function get_loader() {
242 return $this->loader;
243 }
244
245 /**
246 * Retrieve the version number of the plugin.
247 *
248 * @since 1.0.0
249 * @return string The version number of the plugin.
250 */
251 public function get_version() {
252 return $this->version;
253 }
254
255 }
256