| 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.0.0'; |
| 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( 'quick_edit_custom_box', $plugin_admin, 'add_custom_quick_edit', 10, 2 ); |
| 171 |
// adding custom completion column for users |
| 172 |
$this->loader->add_action( 'manage_users_columns', $plugin_admin, 'add_user_column_header' ); |
| 173 |
$this->loader->add_action( 'manage_users_custom_column', $plugin_admin, 'add_user_column_value', 10, 3 ); |
| 174 |
} |
| 175 |
|
| 176 |
/** |
| 177 |
* Register all of the hooks related to the public-facing functionality |
| 178 |
* of the plugin. |
| 179 |
* |
| 180 |
* @since 1.0.0 |
| 181 |
* @access private |
| 182 |
*/ |
| 183 |
private function define_public_hooks() { |
| 184 |
|
| 185 |
$plugin_public = new WPComplete_Public( $this->get_plugin_name(), $this->get_version() ); |
| 186 |
|
| 187 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
| 188 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
| 189 |
|
| 190 |
$this->loader->add_filter( 'the_content', $plugin_public, 'append_completion_code' ); |
| 191 |
|
| 192 |
// Custom ajax functions: |
| 193 |
$this->loader->add_action( 'wp_ajax_mark_completed', $plugin_public , 'mark_completed' ); |
| 194 |
$this->loader->add_action( 'wp_ajax_nopriv_mark_completed', $plugin_public , 'no_priv_mark_completed' ); |
| 195 |
$this->loader->add_action( 'wp_ajax_mark_uncompleted', $plugin_public , 'mark_uncompleted' ); |
| 196 |
$this->loader->add_action( 'wp_ajax_nopriv_mark_uncompleted', $plugin_public , 'no_priv_mark_uncompleted' ); |
| 197 |
|
| 198 |
// Add shortcodes: |
| 199 |
$this->loader->add_shortcode( 'complete_button', $plugin_public, 'complete_button_cb' ); |
| 200 |
} |
| 201 |
|
| 202 |
/** |
| 203 |
* Run the loader to execute all of the hooks with WordPress. |
| 204 |
* |
| 205 |
* @since 1.0.0 |
| 206 |
*/ |
| 207 |
public function run() { |
| 208 |
$this->loader->run(); |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* The name of the plugin used to uniquely identify it within the context of |
| 213 |
* WordPress and to define internationalization functionality. |
| 214 |
* |
| 215 |
* @since 1.0.0 |
| 216 |
* @return string The name of the plugin. |
| 217 |
*/ |
| 218 |
public function get_plugin_name() { |
| 219 |
return $this->plugin_name; |
| 220 |
} |
| 221 |
|
| 222 |
/** |
| 223 |
* The reference to the class that orchestrates the hooks with the plugin. |
| 224 |
* |
| 225 |
* @since 1.0.0 |
| 226 |
* @return WPComplete_Loader Orchestrates the hooks of the plugin. |
| 227 |
*/ |
| 228 |
public function get_loader() { |
| 229 |
return $this->loader; |
| 230 |
} |
| 231 |
|
| 232 |
/** |
| 233 |
* Retrieve the version number of the plugin. |
| 234 |
* |
| 235 |
* @since 1.0.0 |
| 236 |
* @return string The version number of the plugin. |
| 237 |
*/ |
| 238 |
public function get_version() { |
| 239 |
return $this->version; |
| 240 |
} |
| 241 |
|
| 242 |
} |
| 243 |
|