| 1 |
<?php |
| 2 |
/** |
| 3 |
* Core plugin bootstrap class. |
| 4 |
* |
| 5 |
* Defines Mlsimport, the orchestrator instantiated from mlsimport.php. It loads the |
| 6 |
* plugin's dependencies (loader, i18n, admin, custom post type, public), then registers |
| 7 |
* every WordPress hook — admin enqueues, option-save handlers, admin menu, AJAX handlers, |
| 8 |
* background-import actions, and the public-facing filters — through the Mlsimport_Loader. |
| 9 |
* Calling run() finally hands the collected hooks to WordPress. |
| 10 |
* |
| 11 |
* @package MLSImport |
| 12 |
*/ |
| 13 |
// Abort if the file is accessed directly outside of WordPress. |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; // Exit if accessed directly |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* The file that defines the core plugin class |
| 20 |
* |
| 21 |
* A class definition that includes attributes and functions used across both the |
| 22 |
* public-facing side of the site and the admin area. |
| 23 |
* |
| 24 |
* @link http://mlsimport.com/ |
| 25 |
* @since 1.0.0 |
| 26 |
* |
| 27 |
* @package Mlsimport |
| 28 |
* @subpackage Mlsimport/includes |
| 29 |
*/ |
| 30 |
|
| 31 |
/** |
| 32 |
* The core plugin class. |
| 33 |
* |
| 34 |
* This is used to define internationalization, admin-specific hooks, and |
| 35 |
* public-facing site hooks. |
| 36 |
* |
| 37 |
* Also maintains the unique identifier of this plugin as well as the current |
| 38 |
* version of the plugin. |
| 39 |
* |
| 40 |
* @since 1.0.0 |
| 41 |
* @package Mlsimport |
| 42 |
* @subpackage Mlsimport/includes |
| 43 |
* @author MlsImport <office@mlsimport.com> |
| 44 |
*/ |
| 45 |
class Mlsimport { |
| 46 |
|
| 47 |
/** |
| 48 |
* The loader that's responsible for maintaining and registering all hooks that power |
| 49 |
* the plugin. |
| 50 |
* |
| 51 |
* @since 1.0.0 |
| 52 |
* @access protected |
| 53 |
* @var Mlsimport_Loader $loader Maintains and registers all hooks for the plugin. |
| 54 |
*/ |
| 55 |
protected $loader; |
| 56 |
|
| 57 |
/** |
| 58 |
* The unique identifier of this plugin. |
| 59 |
* |
| 60 |
* @since 1.0.0 |
| 61 |
* @access protected |
| 62 |
* @var string $plugin_name The string used to uniquely identify this plugin. |
| 63 |
*/ |
| 64 |
protected $plugin_name; |
| 65 |
|
| 66 |
/** |
| 67 |
* The current version of the plugin. |
| 68 |
* |
| 69 |
* @since 1.0.0 |
| 70 |
* @access protected |
| 71 |
* @var string $version The current version of the plugin. |
| 72 |
*/ |
| 73 |
protected $version; |
| 74 |
|
| 75 |
/** |
| 76 |
* Define the core functionality of the plugin. |
| 77 |
* |
| 78 |
* Set the plugin name and the plugin version that can be used throughout the plugin. |
| 79 |
* Load the dependencies, define the locale, and set the hooks for the admin area and |
| 80 |
* the public-facing side of the site. |
| 81 |
* |
| 82 |
* @since 1.0.0 |
| 83 |
*/ |
| 84 |
|
| 85 |
/** |
| 86 |
* Store plugin admin class to allow public access. |
| 87 |
* |
| 88 |
* @since 20180622 |
| 89 |
* @var object The admin class. |
| 90 |
*/ |
| 91 |
public $admin; |
| 92 |
|
| 93 |
/** |
| 94 |
* Store plugin public class to allow public access. |
| 95 |
* |
| 96 |
* @since 20180622 |
| 97 |
* @var object The admin class. |
| 98 |
*/ |
| 99 |
public $public; |
| 100 |
|
| 101 |
/** |
| 102 |
* Set the plugin name/version and wire up all dependencies and hooks. |
| 103 |
*/ |
| 104 |
public function __construct() { |
| 105 |
// Use the defined plugin version constant, else fall back to 1.0.0. |
| 106 |
if ( defined( 'MLSIMPORT_VERSION' ) ) { |
| 107 |
$this->version = MLSIMPORT_VERSION; |
| 108 |
} else { |
| 109 |
$this->version = '1.0.0'; |
| 110 |
} |
| 111 |
// Unique plugin identifier used for option keys and hook names. |
| 112 |
$this->plugin_name = 'mlsimport'; |
| 113 |
|
| 114 |
// Load classes, set translations, then register admin + public hooks. |
| 115 |
$this->load_dependencies(); |
| 116 |
$this->set_locale(); |
| 117 |
$this->define_admin_hooks(); |
| 118 |
$this->define_public_hooks(); |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Load the required dependencies for this plugin. |
| 123 |
* |
| 124 |
* Include the following files that make up the plugin: |
| 125 |
* |
| 126 |
* - Mlsimport_Loader. Orchestrates the hooks of the plugin. |
| 127 |
* - Mlsimport_i18n. Defines internationalization functionality. |
| 128 |
* - Mlsimport_Admin. Defines all hooks for the admin area. |
| 129 |
* - Mlsimport_Public. Defines all hooks for the public side of the site. |
| 130 |
* |
| 131 |
* Create an instance of the loader which will be used to register the hooks |
| 132 |
* with WordPress. |
| 133 |
* |
| 134 |
* @since 1.0.0 |
| 135 |
* @access private |
| 136 |
*/ |
| 137 |
private function load_dependencies() { |
| 138 |
|
| 139 |
/** |
| 140 |
* The class responsible for orchestrating the actions and filters of the |
| 141 |
* core plugin. |
| 142 |
*/ |
| 143 |
// Hook loader/registry. |
| 144 |
require_once plugin_dir_path( __DIR__ ) . 'includes/class-mlsimport-loader.php'; |
| 145 |
|
| 146 |
/** |
| 147 |
* The class responsible for defining internationalization functionality |
| 148 |
* of the plugin. |
| 149 |
*/ |
| 150 |
// Translation loading. |
| 151 |
require_once plugin_dir_path( __DIR__ ) . 'includes/class-mlsimport-i18n.php'; |
| 152 |
|
| 153 |
/** |
| 154 |
* The class responsible for defining all actions that occur in the admin area. |
| 155 |
*/ |
| 156 |
// Admin monolith (settings, AJAX, imports). |
| 157 |
require_once plugin_dir_path( __DIR__ ) . 'admin/class-mlsimport-admin.php'; |
| 158 |
|
| 159 |
/** |
| 160 |
* The class responsible for custom post type |
| 161 |
*/ |
| 162 |
// mlsimport_item custom post type. |
| 163 |
require_once plugin_dir_path( __DIR__ ) . 'includes/class-mlsimport-item.php'; |
| 164 |
|
| 165 |
/** |
| 166 |
* The class responsible for defining all actions that occur in the public-facing |
| 167 |
* side of the site. |
| 168 |
*/ |
| 169 |
// Public-facing side of the plugin. |
| 170 |
require_once plugin_dir_path( __DIR__ ) . 'public/class-mlsimport-public.php'; |
| 171 |
|
| 172 |
// Instantiate the loader that collects all hook registrations. |
| 173 |
$this->loader = new Mlsimport_Loader(); |
| 174 |
} |
| 175 |
|
| 176 |
/** |
| 177 |
* Define the locale for this plugin for internationalization. |
| 178 |
* |
| 179 |
* Uses the Mlsimport_i18n class in order to set the domain and to register the hook |
| 180 |
* with WordPress. |
| 181 |
* |
| 182 |
* @since 1.0.0 |
| 183 |
* @access private |
| 184 |
*/ |
| 185 |
private function set_locale() { |
| 186 |
|
| 187 |
// The i18n helper that loads the plugin's text domain. |
| 188 |
$plugin_i18n = new Mlsimport_i18n(); |
| 189 |
|
| 190 |
// Load translations at `init` to ensure the locale is fully set. |
| 191 |
// Loading earlier can trigger WordPress notices starting WP 6.7. |
| 192 |
$this->loader->add_action( 'init', $plugin_i18n, 'load_plugin_textdomain' ); |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* Register all of the hooks related to the admin area functionality |
| 197 |
* of the plugin. |
| 198 |
* |
| 199 |
* @since 1.0.0 |
| 200 |
* @access private |
| 201 |
*/ |
| 202 |
private function define_admin_hooks() { |
| 203 |
|
| 204 |
// Instantiate the admin class (kept public via $this->admin) and configure it. |
| 205 |
$this->admin = $plugin_admin = new Mlsimport_Admin( $this->get_plugin_name(), $this->get_version() ); |
| 206 |
|
| 207 |
// Pass the current MLS provider and theme environment into the admin class. |
| 208 |
$this->admin->admin_setup( $this->get_plugin_name(), $this->get_plugin_data( 'mls_enviroment' ), $this->get_plugin_data( 'theme_enviroment' ) ); |
| 209 |
|
| 210 |
// Enqueue admin CSS/JS. |
| 211 |
$this->loader->add_action( 'admin_enqueue_scripts', $this->admin, 'enqueue_styles' ); |
| 212 |
$this->loader->add_action( 'admin_enqueue_scripts', $this->admin, 'enqueue_scripts' ); |
| 213 |
|
| 214 |
// Register the mlsimport_item custom post type late on init (priority 999). |
| 215 |
$plugin_post_types = new Mlsimport_Item(); |
| 216 |
$this->loader->add_action( 'init', $plugin_post_types, 'create_custom_post_type', 999 ); |
| 217 |
|
| 218 |
// save and render metaboxed |
| 219 |
// Import-task metaboxes: render on admin_init, persist on save_post. |
| 220 |
$this->loader->add_action( 'admin_init', $plugin_admin, 'mlsimport_item_product_metaboxes' ); |
| 221 |
$this->loader->add_action( 'save_post', $plugin_admin, 'mlsimport_item_product_save_metaboxes', 1, 2 ); |
| 222 |
|
| 223 |
// Save/Update our plugin options |
| 224 |
// Persist settings, and react to changes of the field-selection option. |
| 225 |
$this->loader->add_action( 'admin_init', $this->admin, 'options_update' ); |
| 226 |
$this->loader->add_action( 'update_option_' . $this->plugin_name . '_admin_fields_select', $this->admin, 'update_option_mlsimport_admin_fields_select' ); |
| 227 |
$this->loader->add_action( 'add_option_' . $this->plugin_name . '_admin_fields_select', $this->admin, 'update_option_mlsimport_admin_fields_select' ); |
| 228 |
|
| 229 |
// Add menu item |
| 230 |
$this->loader->add_action( 'admin_menu', $this->admin, 'add_plugin_admin_menu' ); |
| 231 |
|
| 232 |
// Add Settings link to the plugin list |
| 233 |
// Build this plugin's basename to target the plugin-row action links filter. |
| 234 |
$plugin_basename = plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_name . '.php' ); |
| 235 |
$this->loader->add_filter( 'plugin_action_links_' . $plugin_basename, $this->admin, 'add_action_links' ); |
| 236 |
|
| 237 |
// Register additional metabox options on admin_init. |
| 238 |
$this->loader->add_action( 'admin_init', $this->admin, 'mlsimport_meta_options' ); |
| 239 |
|
| 240 |
// AJAX: per-item move/stop/metadata handlers. |
| 241 |
$this->loader->add_action( 'wp_ajax_mlsimport_move_files_per_item', $this->admin, 'mlsimport_move_files_per_item' ); |
| 242 |
$this->loader->add_action( 'wp_ajax_mlsimport_stop_import_per_item', $this->admin, 'mlsimport_stop_import_per_item' ); |
| 243 |
$this->loader->add_action( 'wp_ajax_mlsimport_saas_get_metadata_function', $this->admin, 'mlsimport_saas_get_metadata_function' ); |
| 244 |
|
| 245 |
// Background import processing actions (full run and initial batch). |
| 246 |
$this->loader->add_action( 'mlsimport_background_process_per_item', $this->admin, 'mlsimport_background_process_per_item_function', 10, 1 ); |
| 247 |
$this->loader->add_action( 'mlsimport_background_process_per_item_inital_batch', $this->admin, 'mlsimport_background_process_per_item_inital_batch_function', 10, 1 ); |
| 248 |
|
| 249 |
// AJAX: logging and file-move handlers. |
| 250 |
$this->loader->add_action( 'wp_ajax_mlsimport_logger_per_item', $this->admin, 'mlsimport_logger_per_item' ); |
| 251 |
// AJAX: file-move and AWS log-move handlers. |
| 252 |
$this->loader->add_action( 'wp_ajax_mlsimport_move_files', $this->admin, 'mlsimport_move_files' ); |
| 253 |
$this->loader->add_action( 'wp_ajax_mlsimport_move_files_to_aws_logger', $this->admin, 'mlsimport_move_files_to_aws_logger' ); |
| 254 |
// AJAX: stop-move, cache clear, field reset, property delete, term lookup, exit survey. |
| 255 |
$this->loader->add_action( 'wp_ajax_mlsimport_stop_moving_files', $this->admin, 'mlsimport_stop_moving_files' ); |
| 256 |
$this->loader->add_action( 'wp_ajax_mlsimport_delete_cache', $this->admin, 'mlsimport_delete_cache' ); |
| 257 |
$this->loader->add_action( 'wp_ajax_mlsimport_clear_fields_data', $this->admin, 'mlsimport_clear_fields_data' ); |
| 258 |
$this->loader->add_action( 'wp_ajax_mlsimport_delete_properties', $this->admin, 'mlsimport_delete_properties' ); |
| 259 |
$this->loader->add_action( 'wp_ajax_mlsimport_get_taxonomy_terms', $this->admin, 'mlsimport_get_taxonomy_terms' ); |
| 260 |
$this->loader->add_action( 'wp_ajax_mlsimport_exit_survey_submit', $this->admin, 'mlsimport_exit_survey_submit' ); |
| 261 |
} |
| 262 |
|
| 263 |
/** |
| 264 |
* Register all of the hooks related to the public-facing functionality |
| 265 |
* of the plugin. |
| 266 |
* |
| 267 |
* @since 1.0.0 |
| 268 |
* @access private |
| 269 |
*/ |
| 270 |
private function define_public_hooks() { |
| 271 |
|
| 272 |
// Instantiate the public-facing class. |
| 273 |
$plugin_public = new Mlsimport_Public( $this->get_plugin_name(), $this->get_version() ); |
| 274 |
|
| 275 |
// Enqueue front-end CSS/JS. |
| 276 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
| 277 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
| 278 |
// Rewrite attachment URLs for remotely-hosted MLS images. |
| 279 |
$this->loader->add_filter( 'wp_get_attachment_url', $plugin_public, 'mlsimport_wp_get_attachment_url', 99, 2 ); |
| 280 |
|
| 281 |
|
| 282 |
} |
| 283 |
|
| 284 |
/** |
| 285 |
* Run the loader to execute all of the hooks with WordPress. |
| 286 |
* |
| 287 |
* @since 1.0.0 |
| 288 |
*/ |
| 289 |
public function run() { |
| 290 |
// Hand all collected hooks over to WordPress. |
| 291 |
$this->loader->run(); |
| 292 |
} |
| 293 |
|
| 294 |
/** |
| 295 |
* The name of the plugin used to uniquely identify it within the context of |
| 296 |
* WordPress and to define internationalization functionality. |
| 297 |
* |
| 298 |
* @since 1.0.0 |
| 299 |
* @return string The name of the plugin. |
| 300 |
*/ |
| 301 |
public function get_plugin_name() { |
| 302 |
// Return the stored plugin identifier. |
| 303 |
return $this->plugin_name; |
| 304 |
} |
| 305 |
|
| 306 |
/** |
| 307 |
* The reference to the class that orchestrates the hooks with the plugin. |
| 308 |
* |
| 309 |
* @since 1.0.0 |
| 310 |
* @return Mlsimport_Loader Orchestrates the hooks of the plugin. |
| 311 |
*/ |
| 312 |
public function get_loader() { |
| 313 |
// Return the hook loader instance. |
| 314 |
return $this->loader; |
| 315 |
} |
| 316 |
|
| 317 |
/** |
| 318 |
* Retrieve the version number of the plugin. |
| 319 |
* |
| 320 |
* @since 1.0.0 |
| 321 |
* @return string The version number of the plugin. |
| 322 |
*/ |
| 323 |
public function get_version() { |
| 324 |
// Return the resolved plugin version. |
| 325 |
return $this->version; |
| 326 |
} |
| 327 |
|
| 328 |
/** |
| 329 |
* return plugin shema |
| 330 |
* |
| 331 |
* Placeholder schema accessor; currently returns an empty string. |
| 332 |
* |
| 333 |
* @since 1.0.0 |
| 334 |
* @access protected |
| 335 |
* @var string $plugin_name |
| 336 |
* @return string Empty string (no schema). |
| 337 |
*/ |
| 338 |
public function return_plugin_schema() { |
| 339 |
|
| 340 |
// No schema defined at this level. |
| 341 |
return ''; |
| 342 |
} |
| 343 |
|
| 344 |
/** |
| 345 |
* return plugin data |
| 346 |
* |
| 347 |
* Reads a single value from the plugin schema. Provider behavior is resolved |
| 348 |
* by Mlsimport_Provider_Family and does not belong in this core accessor. |
| 349 |
* |
| 350 |
* @since 1.0.0 |
| 351 |
* @access protected |
| 352 |
* @var string $plugin_name |
| 353 |
* @param string $what The schema key to fetch (e.g. 'mls_enviroment'). |
| 354 |
* @return mixed The requested value, or '' when unavailable. |
| 355 |
*/ |
| 356 |
public function get_plugin_data( $what ) { |
| 357 |
// Pull the (currently empty) plugin schema. |
| 358 |
$plugin_data = $this->return_plugin_schema(); |
| 359 |
|
| 360 |
// Return the requested key when present, else empty string. |
| 361 |
if ( isset( $plugin_data[ $what ] ) ) { |
| 362 |
return $plugin_data[ $what ]; |
| 363 |
} else { |
| 364 |
return ''; |
| 365 |
} |
| 366 |
} |
| 367 |
} |
| 368 |
|