Admin
7 years ago
Integrations
7 years ago
Lite
7 years ago
Providers
7 years ago
WPForms.php
7 years ago
WPForms.php
341 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPForms { |
| 4 | |
| 5 | /** |
| 6 | * Main WPForms class. |
| 7 | * |
| 8 | * @since 1.0.0 |
| 9 | * |
| 10 | * @package WPForms |
| 11 | */ |
| 12 | final class WPForms { |
| 13 | |
| 14 | /** |
| 15 | * One is the loneliest number that you'll ever do. |
| 16 | * |
| 17 | * @since 1.0.0 |
| 18 | * |
| 19 | * @var \WPForms\WPForms |
| 20 | */ |
| 21 | private static $instance; |
| 22 | |
| 23 | /** |
| 24 | * Plugin version for enqueueing, etc. |
| 25 | * The value is got from WPFORMS_VERSION constant. |
| 26 | * |
| 27 | * @since 1.0.0 |
| 28 | * |
| 29 | * @var string |
| 30 | */ |
| 31 | public $version = ''; |
| 32 | |
| 33 | /** |
| 34 | * The form data handler instance. |
| 35 | * |
| 36 | * @since 1.0.0 |
| 37 | * |
| 38 | * @var \WPForms_Form_Handler |
| 39 | */ |
| 40 | public $form; |
| 41 | |
| 42 | /** |
| 43 | * The entry data handler instance (Pro). |
| 44 | * |
| 45 | * @since 1.0.0 |
| 46 | * |
| 47 | * @var \WPForms_Entry_Handler |
| 48 | */ |
| 49 | public $entry; |
| 50 | |
| 51 | /** |
| 52 | * The entry fields data handler instance (Pro). |
| 53 | * |
| 54 | * @since 1.4.3 |
| 55 | * |
| 56 | * @var \WPForms_Entry_Fields_Handler |
| 57 | */ |
| 58 | public $entry_fields; |
| 59 | |
| 60 | /** |
| 61 | * The entry meta data handler instance (Pro). |
| 62 | * |
| 63 | * @since 1.1.6 |
| 64 | * |
| 65 | * @var \WPForms_Entry_Meta_Handler |
| 66 | */ |
| 67 | public $entry_meta; |
| 68 | |
| 69 | /** |
| 70 | * The front-end instance. |
| 71 | * |
| 72 | * @since 1.0.0 |
| 73 | * |
| 74 | * @var \WPForms_Frontend |
| 75 | */ |
| 76 | public $frontend; |
| 77 | |
| 78 | /** |
| 79 | * The process instance. |
| 80 | * |
| 81 | * @since 1.0.0 |
| 82 | * |
| 83 | * @var \WPForms_Process |
| 84 | */ |
| 85 | public $process; |
| 86 | |
| 87 | /** |
| 88 | * The smart tags instance. |
| 89 | * |
| 90 | * @since 1.0.0 |
| 91 | * |
| 92 | * @var \WPForms_Smart_Tags |
| 93 | */ |
| 94 | public $smart_tags; |
| 95 | |
| 96 | /** |
| 97 | * The Logging instance. |
| 98 | * |
| 99 | * @since 1.0.0 |
| 100 | * |
| 101 | * @var \WPForms_Logging |
| 102 | */ |
| 103 | public $logs; |
| 104 | |
| 105 | /** |
| 106 | * The Preview instance. |
| 107 | * |
| 108 | * @since 1.1.9 |
| 109 | * |
| 110 | * @var \WPForms_Preview |
| 111 | */ |
| 112 | public $preview; |
| 113 | |
| 114 | /** |
| 115 | * The License class instance (Pro). |
| 116 | * |
| 117 | * @since 1.0.0 |
| 118 | * |
| 119 | * @var \WPForms_License |
| 120 | */ |
| 121 | public $license; |
| 122 | |
| 123 | /** |
| 124 | * Paid returns true, free (Lite) returns false. |
| 125 | * |
| 126 | * @since 1.3.9 |
| 127 | * |
| 128 | * @var boolean |
| 129 | */ |
| 130 | public $pro = false; |
| 131 | |
| 132 | /** |
| 133 | * Main WPForms Instance. |
| 134 | * |
| 135 | * Insures that only one instance of WPForms exists in memory at any one |
| 136 | * time. Also prevents needing to define globals all over the place. |
| 137 | * |
| 138 | * @since 1.0.0 |
| 139 | * |
| 140 | * @return WPForms |
| 141 | */ |
| 142 | public static function instance() { |
| 143 | |
| 144 | if ( |
| 145 | null === self::$instance || |
| 146 | ! self::$instance instanceof self |
| 147 | ) { |
| 148 | |
| 149 | self::$instance = new self(); |
| 150 | self::$instance->constants(); |
| 151 | self::$instance->conditional_logic_addon_check(); |
| 152 | self::$instance->includes(); |
| 153 | |
| 154 | // Load Pro or Lite specific files. |
| 155 | if ( self::$instance->pro ) { |
| 156 | require_once WPFORMS_PLUGIN_DIR . 'pro/wpforms-pro.php'; |
| 157 | } else { |
| 158 | require_once WPFORMS_PLUGIN_DIR . 'lite/wpforms-lite.php'; |
| 159 | } |
| 160 | |
| 161 | add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ), 10 ); |
| 162 | add_action( 'plugins_loaded', array( self::$instance, 'objects' ), 10 ); |
| 163 | } |
| 164 | |
| 165 | return self::$instance; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Setup plugin constants. |
| 170 | * All the path/URL related constants are defined in main plugin file. |
| 171 | * |
| 172 | * @since 1.0.0 |
| 173 | */ |
| 174 | private function constants() { |
| 175 | |
| 176 | $this->version = WPFORMS_VERSION; |
| 177 | |
| 178 | // Plugin Slug - Determine plugin type and set slug accordingly. |
| 179 | if ( apply_filters( 'wpforms_allow_pro_version', file_exists( WPFORMS_PLUGIN_DIR . 'pro/wpforms-pro.php' ) ) ) { |
| 180 | $this->pro = true; |
| 181 | define( 'WPFORMS_PLUGIN_SLUG', 'wpforms' ); |
| 182 | } else { |
| 183 | define( 'WPFORMS_PLUGIN_SLUG', 'wpforms-lite' ); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Loads the plugin language files. |
| 189 | * |
| 190 | * @since 1.0.0 |
| 191 | * @since 1.5.0 Load only the lite translation. |
| 192 | */ |
| 193 | public function load_textdomain() { |
| 194 | load_plugin_textdomain( 'wpforms-lite', false, dirname( plugin_basename( WPFORMS_PLUGIN_FILE ) ) . '/languages/' ); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Check to see if the conditional logic addon is running, if so then |
| 199 | * deactivate the plugin to prevent conflicts. |
| 200 | * |
| 201 | * @since 1.3.8 |
| 202 | */ |
| 203 | private function conditional_logic_addon_check() { |
| 204 | |
| 205 | if ( function_exists( 'wpforms_conditional_logic' ) ) { |
| 206 | |
| 207 | // Load core files needed to activate deactivate_plugins(). |
| 208 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 209 | require_once ABSPATH . 'wp-includes/pluggable.php'; |
| 210 | |
| 211 | // Deactivate Conditional Logic addon. |
| 212 | deactivate_plugins( 'wpforms-conditional-logic/wpforms-conditional-logic.php' ); |
| 213 | |
| 214 | // To avoid namespace collisions, reload current page. |
| 215 | $url = esc_url_raw( remove_query_arg( 'wpforms-test' ) ); |
| 216 | wp_redirect( $url ); |
| 217 | exit; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Include files. |
| 223 | * |
| 224 | * @since 1.0.0 |
| 225 | */ |
| 226 | private function includes() { |
| 227 | |
| 228 | $this->includes_magic(); |
| 229 | |
| 230 | // Global includes. |
| 231 | require_once WPFORMS_PLUGIN_DIR . 'includes/functions.php'; |
| 232 | require_once WPFORMS_PLUGIN_DIR . 'includes/class-install.php'; |
| 233 | require_once WPFORMS_PLUGIN_DIR . 'includes/class-form.php'; |
| 234 | require_once WPFORMS_PLUGIN_DIR . 'includes/class-fields.php'; |
| 235 | require_once WPFORMS_PLUGIN_DIR . 'includes/class-frontend.php'; |
| 236 | // TODO: class-templates.php should be loaded in admin area only. |
| 237 | require_once WPFORMS_PLUGIN_DIR . 'includes/class-templates.php'; |
| 238 | // TODO: class-providers.php should be loaded in admin area only. |
| 239 | require_once WPFORMS_PLUGIN_DIR . 'includes/class-providers.php'; |
| 240 | require_once WPFORMS_PLUGIN_DIR . 'includes/class-process.php'; |
| 241 | require_once WPFORMS_PLUGIN_DIR . 'includes/class-smart-tags.php'; |
| 242 | require_once WPFORMS_PLUGIN_DIR . 'includes/class-logging.php'; |
| 243 | require_once WPFORMS_PLUGIN_DIR . 'includes/class-widget.php'; |
| 244 | require_once WPFORMS_PLUGIN_DIR . 'includes/class-preview.php'; |
| 245 | require_once WPFORMS_PLUGIN_DIR . 'includes/class-conditional-logic-core.php'; |
| 246 | require_once WPFORMS_PLUGIN_DIR . 'includes/emails/class-emails.php'; |
| 247 | require_once WPFORMS_PLUGIN_DIR . 'includes/integrations.php'; |
| 248 | |
| 249 | // Admin/Dashboard only includes, also in ajax. |
| 250 | if ( is_admin() ) { |
| 251 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/admin.php'; |
| 252 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-notices.php'; |
| 253 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-menu.php'; |
| 254 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/overview/class-overview.php'; |
| 255 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/builder/class-builder.php'; |
| 256 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/builder/functions.php'; |
| 257 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-settings.php'; |
| 258 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-welcome.php'; |
| 259 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-tools.php'; |
| 260 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-editor.php'; |
| 261 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-review.php'; |
| 262 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-importers.php'; |
| 263 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-about.php'; |
| 264 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/ajax-actions.php'; |
| 265 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-am-notification.php'; |
| 266 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-am-deactivation-survey.php'; |
| 267 | require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-am-dashboard-widget-extend-feed.php'; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Including the new files with PHP 5.3 style. |
| 273 | * |
| 274 | * @since 1.4.7 |
| 275 | */ |
| 276 | private function includes_magic() { |
| 277 | |
| 278 | // Autoloader is put into its own file to save space here. |
| 279 | require_once WPFORMS_PLUGIN_DIR . 'autoloader.php'; |
| 280 | |
| 281 | /* |
| 282 | * Load admin components. |
| 283 | */ |
| 284 | add_action( 'wpforms_loaded', array( '\WPForms\Admin\Loader', 'get_instance' ) ); |
| 285 | |
| 286 | /* |
| 287 | * Properly init the providers loader, that will handle all the related logic and further loading. |
| 288 | */ |
| 289 | add_action( 'wpforms_loaded', array( '\WPForms\Providers\Loader', 'get_instance' ) ); |
| 290 | |
| 291 | /* |
| 292 | * Properly init the integrations loader, that will handle all the related logic and further loading. |
| 293 | */ |
| 294 | add_action( 'wpforms_loaded', array( '\WPForms\Integrations\Loader', 'get_instance' ) ); |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Setup objects. |
| 299 | * |
| 300 | * @since 1.0.0 |
| 301 | */ |
| 302 | public function objects() { |
| 303 | |
| 304 | // Global objects. |
| 305 | $this->form = new \WPForms_Form_Handler(); |
| 306 | $this->frontend = new \WPForms_Frontend(); |
| 307 | $this->process = new \WPForms_Process(); |
| 308 | $this->smart_tags = new \WPForms_Smart_Tags(); |
| 309 | $this->logs = new \WPForms_Logging(); |
| 310 | $this->preview = new \WPForms_Preview(); |
| 311 | |
| 312 | if ( is_admin() ) { |
| 313 | if ( ! wpforms_setting( 'hide-announcements', false ) ) { |
| 314 | new \AM_Notification( WPFORMS_PLUGIN_SLUG, $this->version ); |
| 315 | } |
| 316 | |
| 317 | if ( $this->pro || ( ! $this->pro && ! file_exists( WP_PLUGIN_DIR . '/wpforms/wpforms.php' ) ) ) { |
| 318 | new \AM_Deactivation_Survey( 'WPForms', basename( dirname( __DIR__ ) ) ); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | // Hook now that all of the WPForms stuff is loaded. |
| 323 | do_action( 'wpforms_loaded' ); |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | namespace { |
| 329 | |
| 330 | /** |
| 331 | * The function which returns the one WPForms instance. |
| 332 | * |
| 333 | * @since 1.0.0 |
| 334 | * |
| 335 | * @return WPForms\WPForms |
| 336 | */ |
| 337 | function wpforms() { |
| 338 | return WPForms\WPForms::instance(); |
| 339 | } |
| 340 | } |
| 341 |