| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* The file that defines the core plugin class |
| 5 |
* |
| 6 |
* This is used to define internationalization and admin-specific hooks. |
| 7 |
* Also maintains the unique identifier of this plugin as well as the current |
| 8 |
* version of the plugin. |
| 9 |
* |
| 10 |
* @link https://github.com/jamiebergen |
| 11 |
* @since 1.0.0 |
| 12 |
* |
| 13 |
* @package Plugin_Notes_Plus |
| 14 |
* @subpackage Plugin_Notes_Plus/includes |
| 15 |
* @author Jamie Bergen <jamie.bergen@gmail.com> |
| 16 |
*/ |
| 17 |
|
| 18 |
class Plugin_Notes_Plus { |
| 19 |
|
| 20 |
/** |
| 21 |
* The loader that's responsible for maintaining and registering all hooks that power |
| 22 |
* the plugin. |
| 23 |
* |
| 24 |
* @since 1.0.0 |
| 25 |
* @access protected |
| 26 |
* @var Plugin_Notes_Plus_Loader $loader Maintains and registers all hooks for the plugin. |
| 27 |
*/ |
| 28 |
protected $loader; |
| 29 |
|
| 30 |
/** |
| 31 |
* The unique identifier of this plugin. |
| 32 |
* |
| 33 |
* @since 1.0.0 |
| 34 |
* @access protected |
| 35 |
* @var string $plugin_name The string used to uniquely identify this plugin. |
| 36 |
*/ |
| 37 |
protected static $plugin_name = 'plugin-notes-plus'; |
| 38 |
|
| 39 |
/** |
| 40 |
* The current version of the plugin. |
| 41 |
* |
| 42 |
* @since 1.0.0 |
| 43 |
* @access protected |
| 44 |
* @var string $version The current version of the plugin. |
| 45 |
*/ |
| 46 |
protected $version; |
| 47 |
|
| 48 |
/** |
| 49 |
* The db table name. |
| 50 |
* |
| 51 |
* @since 1.1.0 |
| 52 |
* @access protected |
| 53 |
* @var string $version The db table name without the prefix. |
| 54 |
*/ |
| 55 |
protected static $table_name = 'plugin_notes_plus'; |
| 56 |
|
| 57 |
/** |
| 58 |
* Define the core functionality of the plugin. |
| 59 |
* |
| 60 |
* Set the plugin name and the plugin version that can be used throughout the plugin. |
| 61 |
* Load the dependencies, define the locale, and set the hooks for the admin area and |
| 62 |
* the public-facing side of the site. |
| 63 |
* |
| 64 |
* @since 1.0.0 |
| 65 |
*/ |
| 66 |
public function __construct() { |
| 67 |
if ( defined( 'PLUGIN_NOTES_PLUS_VERSION' ) ) { |
| 68 |
$this->version = PLUGIN_NOTES_PLUS_VERSION; |
| 69 |
} else { |
| 70 |
$this->version = '1.0.0'; |
| 71 |
} |
| 72 |
|
| 73 |
$this->load_dependencies(); |
| 74 |
$this->set_locale(); |
| 75 |
$this->define_admin_hooks(); |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Load the required dependencies for this plugin. |
| 81 |
* |
| 82 |
* Include the following files that make up the plugin: |
| 83 |
* |
| 84 |
* - Plugin_Notes_Plus_Loader. Orchestrates the hooks of the plugin. |
| 85 |
* - Plugin_Notes_Plus_i18n. Defines internationalization functionality. |
| 86 |
* - Plugin_Notes_Plus_Admin. Defines all hooks for the admin area. |
| 87 |
* |
| 88 |
* Create an instance of the loader which will be used to register the hooks |
| 89 |
* with WordPress. |
| 90 |
* |
| 91 |
* @since 1.0.0 |
| 92 |
* @access private |
| 93 |
*/ |
| 94 |
private function load_dependencies() { |
| 95 |
|
| 96 |
/** |
| 97 |
* The class responsible for orchestrating the actions and filters of the |
| 98 |
* core plugin. |
| 99 |
*/ |
| 100 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-plugin-notes-plus-loader.php'; |
| 101 |
|
| 102 |
/** |
| 103 |
* The class responsible for defining internationalization functionality |
| 104 |
* of the plugin. |
| 105 |
*/ |
| 106 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-plugin-notes-plus-i18n.php'; |
| 107 |
|
| 108 |
/** |
| 109 |
* The classes responsible for defining all actions that occur in the admin area. |
| 110 |
*/ |
| 111 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-plugin-notes-plus-admin.php'; |
| 112 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-plugin-notes-plus-the-note.php'; |
| 113 |
|
| 114 |
$this->loader = new Plugin_Notes_Plus_Loader(); |
| 115 |
|
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Define the locale for this plugin for internationalization. |
| 120 |
* |
| 121 |
* Uses the Plugin_Notes_Plus_i18n class in order to set the domain and to register the hook |
| 122 |
* with WordPress. |
| 123 |
* |
| 124 |
* @since 1.0.0 |
| 125 |
* @access private |
| 126 |
*/ |
| 127 |
private function set_locale() { |
| 128 |
|
| 129 |
$plugin_i18n = new Plugin_Notes_Plus_i18n(); |
| 130 |
|
| 131 |
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
| 132 |
|
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Register all of the hooks related to the admin area functionality |
| 137 |
* of the plugin. |
| 138 |
* |
| 139 |
* @since 1.0.0 |
| 140 |
* @access private |
| 141 |
*/ |
| 142 |
private function define_admin_hooks() { |
| 143 |
|
| 144 |
$plugin_admin = new Plugin_Notes_Plus_Admin( $this ); |
| 145 |
|
| 146 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
| 147 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
| 148 |
|
| 149 |
// Decision point for where to place notes |
| 150 |
$this->loader->add_action( 'after_setup_theme', $this, 'get_note_placement_option' ); |
| 151 |
|
| 152 |
$pnp_note_placement = get_option( 'plugin_notes_plus_note_placement' ); |
| 153 |
|
| 154 |
if ( 'description' === $pnp_note_placement ) { |
| 155 |
// Option to display plugin notes beneath description |
| 156 |
$this->loader->add_filter( 'plugin_row_meta', $plugin_admin, 'display_plugin_note_desc', 10, 4 ); |
| 157 |
} else { // 'column' by default |
| 158 |
// Custom column on plugins page in admin |
| 159 |
$this->loader->add_filter( 'manage_plugins_columns', $plugin_admin, 'add_plugin_notes_column' ); |
| 160 |
$this->loader->add_action( 'manage_plugins_custom_column', $plugin_admin, 'display_plugin_note', 10, 3 ); |
| 161 |
|
| 162 |
// Separate hook for multisite admin plugins page (only required for column option) |
| 163 |
$this->loader->add_filter( 'manage_plugins-network_columns', $plugin_admin, 'add_plugin_notes_column' ); |
| 164 |
} |
| 165 |
|
| 166 |
// Ajax responses for adding and deleting notes |
| 167 |
$this->loader->add_action( 'wp_ajax_pnp_add_response', $plugin_admin, 'pnp_add_response'); |
| 168 |
$this->loader->add_action( 'wp_ajax_pnp_delete_response', $plugin_admin, 'pnp_delete_response'); |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* Helper function to get and set the note placement option in the database |
| 173 |
* |
| 174 |
* @since 1.2.4 |
| 175 |
*/ |
| 176 |
public function get_note_placement_option() { |
| 177 |
|
| 178 |
$pnp_note_placement_options = array( 'column', 'description' ); |
| 179 |
|
| 180 |
$pnp_note_placement = 'column'; // set default |
| 181 |
|
| 182 |
$pnp_note_placement = apply_filters( 'plugin-notes-plus_note_placement', $pnp_note_placement ); |
| 183 |
|
| 184 |
// Protect against unexpected options |
| 185 |
if ( ! in_array( $pnp_note_placement, $pnp_note_placement_options ) ) { |
| 186 |
$pnp_note_placement = 'column'; |
| 187 |
} |
| 188 |
|
| 189 |
update_option( 'plugin_notes_plus_note_placement', $pnp_note_placement ); |
| 190 |
} |
| 191 |
|
| 192 |
/** |
| 193 |
* Run the loader to execute all of the hooks with WordPress. |
| 194 |
* |
| 195 |
* @since 1.0.0 |
| 196 |
*/ |
| 197 |
public function run() { |
| 198 |
$this->loader->run(); |
| 199 |
} |
| 200 |
|
| 201 |
/** |
| 202 |
* The name of the plugin used to uniquely identify it within the context of |
| 203 |
* WordPress and to define internationalization functionality. |
| 204 |
* |
| 205 |
* @since 1.0.0 |
| 206 |
* @return string The name of the plugin. |
| 207 |
*/ |
| 208 |
public static function get_plugin_name() { |
| 209 |
return self::$plugin_name; |
| 210 |
} |
| 211 |
|
| 212 |
/** |
| 213 |
* The reference to the class that orchestrates the hooks with the plugin. |
| 214 |
* |
| 215 |
* @since 1.0.0 |
| 216 |
* @return Plugin_Notes_Plus_Loader Orchestrates the hooks of the plugin. |
| 217 |
*/ |
| 218 |
public function get_loader() { |
| 219 |
return $this->loader; |
| 220 |
} |
| 221 |
|
| 222 |
/** |
| 223 |
* Retrieve the version number of the plugin. |
| 224 |
* |
| 225 |
* @since 1.0.0 |
| 226 |
* @return string The version number of the plugin. |
| 227 |
*/ |
| 228 |
public function get_version() { |
| 229 |
return $this->version; |
| 230 |
} |
| 231 |
|
| 232 |
/** |
| 233 |
* Retrieve the db table name. |
| 234 |
* |
| 235 |
* @since 1.1.0 |
| 236 |
* @return string The db table name without the prefix. |
| 237 |
*/ |
| 238 |
public static function get_table_name() { |
| 239 |
return self::$table_name; |
| 240 |
} |
| 241 |
|
| 242 |
} |
| 243 |
|