| 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 = '2.3.0'; |
| 73 |
$this->load_dependencies(); |
| 74 |
$this->set_locale(); |
| 75 |
$this->define_admin_hooks(); |
| 76 |
$this->define_public_hooks(); |
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Load the required dependencies for this plugin. |
| 82 |
* |
| 83 |
* Include the following files that make up the plugin: |
| 84 |
* |
| 85 |
* - WPComplete_Loader. Orchestrates the hooks of the plugin. |
| 86 |
* - WPComplete_i18n. Defines internationalization functionality. |
| 87 |
* - WPComplete_Admin. Defines all hooks for the admin area. |
| 88 |
* - WPComplete_Public. Defines all hooks for the public side of the site. |
| 89 |
* |
| 90 |
* Create an instance of the loader which will be used to register the hooks |
| 91 |
* with WordPress. |
| 92 |
* |
| 93 |
* @since 1.0.0 |
| 94 |
* @access private |
| 95 |
*/ |
| 96 |
private function load_dependencies() { |
| 97 |
|
| 98 |
/** |
| 99 |
* The class responsible for orchestrating the actions and filters of the |
| 100 |
* core plugin. |
| 101 |
*/ |
| 102 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpcomplete-loader.php'; |
| 103 |
|
| 104 |
/** |
| 105 |
* The class responsible for defining internationalization functionality |
| 106 |
* of the plugin. |
| 107 |
*/ |
| 108 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpcomplete-i18n.php'; |
| 109 |
|
| 110 |
/** |
| 111 |
* The class responsible for defining actions that are used in both admin and public sections |
| 112 |
*/ |
| 113 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpcomplete-common.php'; |
| 114 |
|
| 115 |
/** |
| 116 |
* The class responsible for defining all actions that occur in the admin area. |
| 117 |
*/ |
| 118 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpcomplete-admin.php'; |
| 119 |
|
| 120 |
/** |
| 121 |
* The class responsible for defining all actions that occur in the public-facing |
| 122 |
* side of the site. |
| 123 |
*/ |
| 124 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wpcomplete-public.php'; |
| 125 |
|
| 126 |
$this->loader = new WPComplete_Loader(); |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* Define the locale for this plugin for internationalization. |
| 131 |
* |
| 132 |
* Uses the WPComplete_i18n class in order to set the domain and to register the hook |
| 133 |
* with WordPress. |
| 134 |
* |
| 135 |
* @since 1.0.0 |
| 136 |
* @access private |
| 137 |
*/ |
| 138 |
private function set_locale() { |
| 139 |
|
| 140 |
$plugin_i18n = new WPComplete_i18n(); |
| 141 |
|
| 142 |
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
| 143 |
|
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Register all of the hooks related to the admin area functionality |
| 148 |
* of the plugin. |
| 149 |
* |
| 150 |
* @since 1.0.0 |
| 151 |
* @access private |
| 152 |
*/ |
| 153 |
private function define_admin_hooks() { |
| 154 |
|
| 155 |
$plugin_admin = new WPComplete_Admin( $this->get_plugin_name(), $this->get_version() ); |
| 156 |
|
| 157 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
| 158 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
| 159 |
// adding settings page and metaboxes |
| 160 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_options_page' ); |
| 161 |
$this->loader->add_action( 'admin_init', $plugin_admin, 'register_settings' ); |
| 162 |
$this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'add_completable_metabox' ); |
| 163 |
$this->loader->add_action( 'save_post', $plugin_admin, 'save_completable' ); |
| 164 |
// adding bulk actions |
| 165 |
$this->loader->add_action( 'admin_footer-edit.php', $plugin_admin, 'add_bulk_actions' ); |
| 166 |
$this->loader->add_action( 'load-edit.php', $plugin_admin, 'save_bulk_completable' ); |
| 167 |
$this->loader->add_action( 'admin_notices', $plugin_admin, 'show_bulk_action_notice' ); |
| 168 |
// adding custom edit column + quick edit |
| 169 |
$this->loader->add_action( 'manage_pages_columns', $plugin_admin, 'add_custom_column_header' ); |
| 170 |
$this->loader->add_action( 'manage_posts_columns', $plugin_admin, 'add_custom_column_header' ); |
| 171 |
$this->loader->add_action( 'manage_pages_custom_column', $plugin_admin, 'add_custom_column_value', 10, 2 ); |
| 172 |
$this->loader->add_action( 'manage_posts_custom_column', $plugin_admin, 'add_custom_column_value', 10, 2 ); |
| 173 |
$this->loader->add_action( 'quick_edit_custom_box', $plugin_admin, 'add_custom_quick_edit', 10, 2 ); |
| 174 |
// adding custom completion column for users |
| 175 |
$this->loader->add_action( 'manage_users_columns', $plugin_admin, 'add_user_column_header' ); |
| 176 |
$this->loader->add_action( 'manage_users_custom_column', $plugin_admin, 'add_user_column_value', 11, 3 ); |
| 177 |
$this->loader->add_action( 'admin_post_delete_user_data', $plugin_admin , 'delete_user_data' ); |
| 178 |
|
| 179 |
// PREMIUM: |
| 180 |
if (WPCOMPLETE_IS_ACTIVATED) { |
| 181 |
// PREMIUM: add specific pages to show completion |
| 182 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_course_completion_page' ); |
| 183 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_post_completion_page' ); |
| 184 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_button_completion_page' ); |
| 185 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_user_completion_page' ); |
| 186 |
|
| 187 |
// PREMIUM: Check for and validate license: |
| 188 |
$this->loader->add_action( 'admin_notices', $plugin_admin, 'show_license_notice' ); |
| 189 |
$this->loader->add_action( 'admin_init', $plugin_admin, 'activate_license' ); |
| 190 |
|
| 191 |
// PREMIUM: Add dashboard widget |
| 192 |
$this->loader->add_action( 'wp_dashboard_setup', $plugin_admin, 'add_dashboard_widget' ); |
| 193 |
|
| 194 |
// auto complete/suggest page/post title lookup |
| 195 |
$this->loader->add_action( 'wp_ajax_post_lookup', $plugin_admin, 'post_lookup'); |
| 196 |
$this->loader->add_action( 'wp_ajax_nopriv_post_lookup', $plugin_admin, 'post_lookup'); |
| 197 |
} |
| 198 |
// allow users to delete buttons: |
| 199 |
$this->loader->add_action( 'wp_ajax_wpc_delete_button', $plugin_admin, 'delete_button' ); |
| 200 |
$this->loader->add_action( 'wp_ajax_nopriv_wpc_delete_button', $plugin_admin, 'delete_button' ); |
| 201 |
|
| 202 |
// FIX OTHER PLUGINS: |
| 203 |
$this->loader->add_filter( 'manage_knowledgebase_posts_columns', $plugin_admin, 'add_custom_column_header' ); |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Register all of the hooks related to the public-facing functionality |
| 208 |
* of the plugin. |
| 209 |
* |
| 210 |
* @since 1.0.0 |
| 211 |
* @access private |
| 212 |
*/ |
| 213 |
private function define_public_hooks() { |
| 214 |
|
| 215 |
$plugin_public = new WPComplete_Public( $this->get_plugin_name(), $this->get_version() ); |
| 216 |
|
| 217 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
| 218 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
| 219 |
|
| 220 |
$this->loader->add_filter( 'the_content', $plugin_public, 'append_completion_code', 1 ); |
| 221 |
|
| 222 |
// Custom ajax functions: |
| 223 |
$this->loader->add_action( 'admin_post_mark_completed', $plugin_public , 'mark_completed' ); |
| 224 |
$this->loader->add_action( 'wp_ajax_mark_completed', $plugin_public , 'mark_completed' ); |
| 225 |
$this->loader->add_action( 'wp_ajax_nopriv_mark_completed', $plugin_public , 'nopriv_mark_completed' ); |
| 226 |
$this->loader->add_action( 'admin_post_mark_uncompleted', $plugin_public , 'mark_uncompleted' ); |
| 227 |
$this->loader->add_action( 'wp_ajax_mark_uncompleted', $plugin_public , 'mark_uncompleted' ); |
| 228 |
$this->loader->add_action( 'wp_ajax_nopriv_mark_uncompleted', $plugin_public , 'nopriv_mark_uncompleted' ); |
| 229 |
$this->loader->add_action( 'wp_ajax_get_button', $plugin_public , 'get_button' ); |
| 230 |
$this->loader->add_action( 'wp_ajax_nopriv_get_button', $plugin_public , 'get_button' ); |
| 231 |
$this->loader->add_action( 'wp_ajax_get_graphs', $plugin_public , 'get_graphs' ); |
| 232 |
$this->loader->add_action( 'wp_ajax_nopriv_get_graphs', $plugin_public , 'get_graphs' ); |
| 233 |
$this->loader->add_action( 'wp_ajax_get_content', $plugin_public , 'get_content' ); |
| 234 |
$this->loader->add_action( 'wp_ajax_nopriv_get_content', $plugin_public , 'get_cotent' ); |
| 235 |
|
| 236 |
// Add shortcodes: |
| 237 |
$this->loader->add_shortcode( 'complete_button', $plugin_public, 'complete_button_cb' ); |
| 238 |
$this->loader->add_shortcode( 'wpc_complete_button', $plugin_public, 'complete_button_cb' ); |
| 239 |
$this->loader->add_shortcode( 'wpc_button', $plugin_public, 'complete_button_cb' ); |
| 240 |
$this->loader->add_shortcode( 'wpcomplete_button', $plugin_public, 'complete_button_cb' ); |
| 241 |
|
| 242 |
// PREMIUM: |
| 243 |
if (WPCOMPLETE_IS_ACTIVATED) { |
| 244 |
$this->loader->add_shortcode( 'progress_percentage', $plugin_public, 'progress_percentage_cb' ); |
| 245 |
$this->loader->add_shortcode( 'progress_in_percentage', $plugin_public, 'progress_percentage_cb' ); |
| 246 |
$this->loader->add_shortcode( 'progress_ratio', $plugin_public, 'progress_ratio_cb' ); |
| 247 |
$this->loader->add_shortcode( 'progress_in_ratio', $plugin_public, 'progress_ratio_cb' ); |
| 248 |
$this->loader->add_shortcode( 'progress_graph', $plugin_public, 'progress_radial_graph_cb' ); |
| 249 |
$this->loader->add_shortcode( 'progress_bar', $plugin_public, 'progress_bar_graph_cb' ); |
| 250 |
$this->loader->add_shortcode( 'wpc_progress_percentage', $plugin_public, 'progress_percentage_cb' ); |
| 251 |
$this->loader->add_shortcode( 'wpc_progress_in_percentage', $plugin_public, 'progress_percentage_cb' ); |
| 252 |
$this->loader->add_shortcode( 'wpc_progress_ratio', $plugin_public, 'progress_ratio_cb' ); |
| 253 |
$this->loader->add_shortcode( 'wpc_progress_in_ratio', $plugin_public, 'progress_ratio_cb' ); |
| 254 |
$this->loader->add_shortcode( 'wpc_progress_graph', $plugin_public, 'progress_radial_graph_cb' ); |
| 255 |
$this->loader->add_shortcode( 'wpc_progress_bar', $plugin_public, 'progress_bar_graph_cb' ); |
| 256 |
$this->loader->add_shortcode( 'wpcomplete_progress_percentage', $plugin_public, 'progress_percentage_cb' ); |
| 257 |
$this->loader->add_shortcode( 'wpcomplete_progress_in_percentage', $plugin_public, 'progress_percentage_cb' ); |
| 258 |
$this->loader->add_shortcode( 'wpcomplete_progress_ratio', $plugin_public, 'progress_ratio_cb' ); |
| 259 |
$this->loader->add_shortcode( 'wpcomplete_progress_in_ratio', $plugin_public, 'progress_ratio_cb' ); |
| 260 |
$this->loader->add_shortcode( 'wpcomplete_progress_graph', $plugin_public, 'progress_radial_graph_cb' ); |
| 261 |
$this->loader->add_shortcode( 'wpcomplete_progress_bar', $plugin_public, 'progress_bar_graph_cb' ); |
| 262 |
|
| 263 |
add_filter( 'widget_text', 'do_shortcode' ); // allow text widgets to render shortcodes |
| 264 |
|
| 265 |
// conditional shortcodes |
| 266 |
$this->loader->add_shortcode( 'wpc_completed_content', $plugin_public, 'completed_content_cb' ); |
| 267 |
$this->loader->add_shortcode( 'wpc_incomplete_content', $plugin_public, 'incomplete_content_cb' ); |
| 268 |
$this->loader->add_shortcode( 'wpcomplete_completed_content', $plugin_public, 'completed_content_cb' ); |
| 269 |
$this->loader->add_shortcode( 'wpcomplete_incomplete_content', $plugin_public, 'incomplete_content_cb' ); |
| 270 |
$this->loader->add_shortcode( 'wpc_if_completed', $plugin_public, 'completed_content_cb' ); |
| 271 |
$this->loader->add_shortcode( 'wpc_if_incomplete', $plugin_public, 'incomplete_content_cb' ); |
| 272 |
$this->loader->add_shortcode( 'wpc_if_button_completed', $plugin_public, 'if_button_completed_cb' ); |
| 273 |
$this->loader->add_shortcode( 'wpc_if_button_incomplete', $plugin_public, 'if_button_incomplete_cb' ); |
| 274 |
$this->loader->add_shortcode( 'wpc_if_page_completed', $plugin_public, 'if_page_completed_cb' ); |
| 275 |
$this->loader->add_shortcode( 'wpc_if_page_incomplete', $plugin_public, 'if_page_incomplete_cb' ); |
| 276 |
$this->loader->add_shortcode( 'wpc_if_course_completed', $plugin_public, 'if_course_completed_cb' ); |
| 277 |
$this->loader->add_shortcode( 'wpc_if_course_incomplete', $plugin_public, 'if_course_incomplete_cb' ); |
| 278 |
|
| 279 |
// Mark links as completable and with their status if logged in: |
| 280 |
$this->loader->add_action( 'wp_ajax_get_completable_list', $plugin_public , 'get_completable_list' ); |
| 281 |
$this->loader->add_action( 'wp_ajax_nopriv_get_completable_list', $plugin_public , 'get_completable_list' ); |
| 282 |
|
| 283 |
// Shortode to build a list of course pages: |
| 284 |
$this->loader->add_shortcode('wpc_list_completable', $plugin_public, 'list_completable_shortcode'); |
| 285 |
$this->loader->add_shortcode('wpc_list_pages', $plugin_public, 'list_completable_shortcode'); |
| 286 |
|
| 287 |
// Peer Pressure shortcode: |
| 288 |
$this->loader->add_shortcode('wpc_peer_pressure', $plugin_public, 'peer_pressure_shortcode'); |
| 289 |
|
| 290 |
} |
| 291 |
$this->loader->add_action( 'wp_head', $plugin_public, 'append_custom_styles' ); |
| 292 |
} |
| 293 |
|
| 294 |
/** |
| 295 |
* Run the loader to execute all of the hooks with WordPress. |
| 296 |
* |
| 297 |
* @since 1.0.0 |
| 298 |
*/ |
| 299 |
public function run() { |
| 300 |
$this->loader->run(); |
| 301 |
} |
| 302 |
|
| 303 |
/** |
| 304 |
* The name of the plugin used to uniquely identify it within the context of |
| 305 |
* WordPress and to define internationalization functionality. |
| 306 |
* |
| 307 |
* @since 1.0.0 |
| 308 |
* @return string The name of the plugin. |
| 309 |
*/ |
| 310 |
public function get_plugin_name() { |
| 311 |
return $this->plugin_name; |
| 312 |
} |
| 313 |
|
| 314 |
/** |
| 315 |
* The reference to the class that orchestrates the hooks with the plugin. |
| 316 |
* |
| 317 |
* @since 1.0.0 |
| 318 |
* @return WPComplete_Loader Orchestrates the hooks of the plugin. |
| 319 |
*/ |
| 320 |
public function get_loader() { |
| 321 |
return $this->loader; |
| 322 |
} |
| 323 |
|
| 324 |
/** |
| 325 |
* Retrieve the version number of the plugin. |
| 326 |
* |
| 327 |
* @since 1.0.0 |
| 328 |
* @return string The version number of the plugin. |
| 329 |
*/ |
| 330 |
public function get_version() { |
| 331 |
return $this->version; |
| 332 |
} |
| 333 |
|
| 334 |
} |
| 335 |
|