Exceptions
3 years ago
GlobalStyles.php
3 years ago
LegacyServiceProvider.php
1 year ago
Onboarding.php
3 years ago
PaymentGateways.php
2 years ago
RequestType.php
3 years ago
RestAPI.php
3 years ago
Routes.php
4 years ago
ServiceProvider.php
4 years ago
LegacyServiceProvider.php
268 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\ServiceProviders; |
| 4 | |
| 5 | use Closure; |
| 6 | use Give\PaymentGateways\Gateways\Stripe\LegacyStripeAdapter; |
| 7 | use Give\Route\Form; |
| 8 | |
| 9 | /** |
| 10 | * Class LegacyServiceProvider |
| 11 | * |
| 12 | * This handles the loading of all of the legacy codebase included in the /includes directory. |
| 13 | * DO NOT EXTEND THIS WITH NEW CODE as it is intended to shrink over time as we migrate over |
| 14 | * to the new ways of doing things. |
| 15 | */ |
| 16 | class LegacyServiceProvider implements ServiceProvider |
| 17 | { |
| 18 | /** |
| 19 | * @inheritDoc |
| 20 | */ |
| 21 | public function register() |
| 22 | { |
| 23 | // TODO: move this |
| 24 | // this needs to load before the LegacyServiceProvider loads in GiveWP. |
| 25 | give(LegacyStripeAdapter::class)->addToStripeSupportedPaymentMethodsList(); |
| 26 | |
| 27 | $this->includeLegacyFiles(); |
| 28 | $this->bindClasses(); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @inheritDoc |
| 33 | */ |
| 34 | public function boot() |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Load all the legacy class files since they don't have auto-loading |
| 40 | * |
| 41 | * @since 3.1.2 remove WP_Background_Process & WP_Async_Request in favor of namespaced versions. |
| 42 | * @since 3.0.0 remove the manual (Test Donations) gateway from loading in favor of the new Test Donations gateway |
| 43 | * @since 2.8.0 |
| 44 | */ |
| 45 | private function includeLegacyFiles() |
| 46 | { |
| 47 | global $give_options; |
| 48 | |
| 49 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-cache-setting.php'; |
| 50 | |
| 51 | require_once GIVE_PLUGIN_DIR . 'includes/setting-functions.php'; |
| 52 | require_once GIVE_PLUGIN_DIR . 'includes/country-functions.php'; |
| 53 | require_once GIVE_PLUGIN_DIR . 'includes/template-functions.php'; |
| 54 | require_once GIVE_PLUGIN_DIR . 'includes/misc-functions.php'; |
| 55 | require_once GIVE_PLUGIN_DIR . 'includes/forms/functions.php'; |
| 56 | require_once GIVE_PLUGIN_DIR . 'includes/ajax-functions.php'; |
| 57 | require_once GIVE_PLUGIN_DIR . 'includes/currency-functions.php'; |
| 58 | require_once GIVE_PLUGIN_DIR . 'includes/price-functions.php'; |
| 59 | require_once GIVE_PLUGIN_DIR . 'includes/user-functions.php'; |
| 60 | require_once GIVE_PLUGIN_DIR . 'includes/donors/frontend-donor-functions.php'; |
| 61 | require_once GIVE_PLUGIN_DIR . 'includes/payments/functions.php'; |
| 62 | require_once GIVE_PLUGIN_DIR . 'includes/gateways/functions.php'; |
| 63 | |
| 64 | /** |
| 65 | * Load plugin files |
| 66 | */ |
| 67 | require_once GIVE_PLUGIN_DIR . 'includes/admin/class-admin-settings.php'; |
| 68 | $give_options = give_get_settings(); |
| 69 | |
| 70 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-cron.php'; |
| 71 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-async-process.php'; |
| 72 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-cache.php'; |
| 73 | require_once GIVE_PLUGIN_DIR . 'includes/post-types.php'; |
| 74 | require_once GIVE_PLUGIN_DIR . 'includes/filters.php'; |
| 75 | require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api-v2.php'; |
| 76 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-tooltips.php'; |
| 77 | require_once GIVE_PLUGIN_DIR . 'includes/class-notices.php'; |
| 78 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-translation.php'; |
| 79 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-license-handler.php'; |
| 80 | require_once GIVE_PLUGIN_DIR . 'includes/admin/class-give-html-elements.php'; |
| 81 | |
| 82 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-scripts.php'; |
| 83 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-roles.php'; |
| 84 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-donate-form.php'; |
| 85 | |
| 86 | require_once GIVE_PLUGIN_DIR . 'includes/database/class-give-db.php'; |
| 87 | require_once GIVE_PLUGIN_DIR . 'includes/database/class-give-db-meta.php'; |
| 88 | require_once GIVE_PLUGIN_DIR . 'includes/database/class-give-db-comments.php'; |
| 89 | require_once GIVE_PLUGIN_DIR . 'includes/database/class-give-db-comments-meta.php'; |
| 90 | require_once GIVE_PLUGIN_DIR . 'includes/database/class-give-db-donors.php'; |
| 91 | require_once GIVE_PLUGIN_DIR . 'includes/database/class-give-db-donor-meta.php'; |
| 92 | require_once GIVE_PLUGIN_DIR . 'includes/database/class-give-db-form-meta.php'; |
| 93 | require_once GIVE_PLUGIN_DIR . 'includes/database/class-give-db-sequential-ordering.php'; |
| 94 | require_once GIVE_PLUGIN_DIR . 'includes/database/class-give-db-sessions.php'; |
| 95 | require_once GIVE_PLUGIN_DIR . 'includes/database/class-give-db-payment-meta.php'; |
| 96 | |
| 97 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-donor.php'; |
| 98 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-stats.php'; |
| 99 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-session.php'; |
| 100 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-logging.php'; |
| 101 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-comment.php'; |
| 102 | |
| 103 | require_once GIVE_PLUGIN_DIR . 'includes/forms/widget.php'; |
| 104 | require_once GIVE_PLUGIN_DIR . 'includes/forms/class-give-forms-query.php'; |
| 105 | require_once GIVE_PLUGIN_DIR . 'includes/forms/template.php'; |
| 106 | require_once GIVE_PLUGIN_DIR . 'includes/shortcodes.php'; |
| 107 | require_once GIVE_PLUGIN_DIR . 'includes/formatting.php'; |
| 108 | require_once GIVE_PLUGIN_DIR . 'includes/error-tracking.php'; |
| 109 | require_once GIVE_PLUGIN_DIR . 'includes/login-register.php'; |
| 110 | require_once GIVE_PLUGIN_DIR . 'includes/plugin-compatibility.php'; |
| 111 | require_once GIVE_PLUGIN_DIR . 'includes/deprecated/deprecated-classes.php'; |
| 112 | require_once GIVE_PLUGIN_DIR . 'includes/deprecated/deprecated-functions.php'; |
| 113 | require_once GIVE_PLUGIN_DIR . 'includes/deprecated/deprecated-actions.php'; |
| 114 | require_once GIVE_PLUGIN_DIR . 'includes/deprecated/deprecated-filters.php'; |
| 115 | |
| 116 | require_once GIVE_PLUGIN_DIR . 'includes/process-donation.php'; |
| 117 | require_once GIVE_PLUGIN_DIR . 'includes/payments/backward-compatibility.php'; |
| 118 | require_once GIVE_PLUGIN_DIR . 'includes/payments/actions.php'; |
| 119 | require_once GIVE_PLUGIN_DIR . 'includes/payments/class-payment-stats.php'; |
| 120 | require_once GIVE_PLUGIN_DIR . 'includes/payments/class-payments-query.php'; |
| 121 | require_once GIVE_PLUGIN_DIR . 'includes/payments/class-give-payment.php'; |
| 122 | require_once GIVE_PLUGIN_DIR . 'includes/payments/class-give-sequential-donation-number.php'; |
| 123 | |
| 124 | require_once GIVE_PLUGIN_DIR . 'includes/gateways/actions.php'; |
| 125 | require_once GIVE_PLUGIN_DIR . 'includes/gateways/paypal/paypal-standard.php'; |
| 126 | require_once GIVE_PLUGIN_DIR . 'includes/gateways/offline-donations.php'; |
| 127 | require_once GIVE_PLUGIN_DIR . 'includes/emails/class-give-emails.php'; |
| 128 | require_once GIVE_PLUGIN_DIR . 'includes/emails/class-give-email-tags.php'; |
| 129 | require_once GIVE_PLUGIN_DIR . 'includes/admin/emails/class-email-notifications.php'; |
| 130 | require_once GIVE_PLUGIN_DIR . 'includes/emails/functions.php'; |
| 131 | require_once GIVE_PLUGIN_DIR . 'includes/emails/template.php'; |
| 132 | require_once GIVE_PLUGIN_DIR . 'includes/emails/actions.php'; |
| 133 | |
| 134 | require_once GIVE_PLUGIN_DIR . 'includes/donors/class-give-donors-query.php'; |
| 135 | require_once GIVE_PLUGIN_DIR . 'includes/donors/class-give-donor-wall.php'; |
| 136 | require_once GIVE_PLUGIN_DIR . 'includes/donors/class-give-donor-stats.php'; |
| 137 | require_once GIVE_PLUGIN_DIR . 'includes/donors/backward-compatibility.php'; |
| 138 | require_once GIVE_PLUGIN_DIR . 'includes/donors/actions.php'; |
| 139 | |
| 140 | require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/class-give-updates.php'; |
| 141 | |
| 142 | require_once GIVE_PLUGIN_DIR . 'blocks/load.php'; |
| 143 | |
| 144 | // Include Views |
| 145 | require_once GIVE_PLUGIN_DIR . 'src/Views/Views.php'; |
| 146 | |
| 147 | if (defined('WP_CLI') && WP_CLI) { |
| 148 | require_once GIVE_PLUGIN_DIR . 'includes/class-give-cli-commands.php'; |
| 149 | } |
| 150 | |
| 151 | // Load file for frontend |
| 152 | if ($this->is_request('frontend')) { |
| 153 | require_once GIVE_PLUGIN_DIR . 'includes/frontend/class-give-frontend.php'; |
| 154 | } |
| 155 | |
| 156 | if ($this->is_request('admin') || $this->is_request('wpcli')) { |
| 157 | require_once GIVE_PLUGIN_DIR . 'includes/admin/class-give-admin.php'; |
| 158 | }// End if(). |
| 159 | |
| 160 | require_once GIVE_PLUGIN_DIR . 'includes/actions.php'; |
| 161 | require_once GIVE_PLUGIN_DIR . 'includes/install.php'; |
| 162 | |
| 163 | // This conditional check will add backward compatibility to older Stripe versions (i.e. < 2.2.0) when used with Give 2.5.0. |
| 164 | if ( |
| 165 | !defined('GIVE_STRIPE_VERSION') || |
| 166 | ( |
| 167 | defined('GIVE_STRIPE_VERSION') && |
| 168 | version_compare(GIVE_STRIPE_VERSION, '2.2.0', '>=') |
| 169 | ) |
| 170 | ) { |
| 171 | require_once GIVE_PLUGIN_DIR . 'includes/gateways/stripe/class-give-stripe.php'; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Binds the legacy classes to the service provider |
| 177 | * |
| 178 | * @since 2.19.6 - remove donors in favor of DonorRepositoryProxy |
| 179 | * |
| 180 | * @since 2.8.0 |
| 181 | */ |
| 182 | private function bindClasses() |
| 183 | { |
| 184 | give()->singleton('routeForm', Form::class); |
| 185 | |
| 186 | $this->bindInstance('roles', 'Give_Roles', 'class-give-roles.php'); |
| 187 | $this->bindInstance('give_settings', 'Give_Admin_Settings', 'admin/class-admin-settings.php'); |
| 188 | $this->bindInstance('api', 'Give_API', 'api/class-give-api.php'); |
| 189 | $this->bindInstance('emails', 'Give_Emails', 'emails/class-give-emails.php'); |
| 190 | $this->bindInstance('email_tags', 'Give_Email_Template_Tags', 'emails/class-give-email-tags.php'); |
| 191 | $this->bindInstance('html', 'Give_HTML_Elements', 'admin/class-give-html-elements.php', true); |
| 192 | $this->bindInstance('donor_meta', 'Give_DB_Donor_Meta', 'database/class-give-db-donor-meta.php'); |
| 193 | $this->bindInstance('tooltips', 'Give_Tooltips', 'class-give-tooltips.php'); |
| 194 | $this->bindInstance('notices', 'Give_Notices', 'class-notices.php'); |
| 195 | $this->bindInstance('payment_meta', 'Give_DB_Payment_Meta', 'database/class-give-db-payment-meta.php'); |
| 196 | $this->bindInstance('logs', 'Give_Logging', 'class-give-logging.php'); |
| 197 | $this->bindInstance('form_meta', 'Give_DB_Form_Meta', 'database/class-give-db-form-meta.php'); |
| 198 | $this->bindInstance( |
| 199 | 'sequential_donation_db', |
| 200 | 'Give_DB_Sequential_Ordering', |
| 201 | 'database/class-give-db-sequential-ordering.php' |
| 202 | ); |
| 203 | $this->bindInstance('async_process', 'Give_Async_Process', 'class-give-async-process.php'); |
| 204 | $this->bindInstance('scripts', 'Give_Scripts', 'class-give-scripts.php'); |
| 205 | $this->bindInstance( |
| 206 | 'seq_donation_number', |
| 207 | 'Give_Sequential_Donation_Number', |
| 208 | 'payments/class-give-sequential-donation-number.php', |
| 209 | true |
| 210 | ); |
| 211 | $this->bindInstance('comment', 'Give_Comment', 'class-give-comment.php', true); |
| 212 | $this->bindInstance('session_db', 'Give_DB_Sessions', 'database/class-give-db-sessions.php'); |
| 213 | $this->bindInstance('session', 'Give_Session', 'class-give-session.php', true); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * A helper for loading legacy classes that do not use autoloading, then binding their instance |
| 218 | * to the container. |
| 219 | * |
| 220 | * @since 2.8.0 |
| 221 | * |
| 222 | * @param string $alias |
| 223 | * @param string|Closure $class |
| 224 | * @param string $includesPath |
| 225 | * @param bool $singleton |
| 226 | */ |
| 227 | private function bindInstance($alias, $class, $includesPath, $singleton = false) |
| 228 | { |
| 229 | require_once GIVE_PLUGIN_DIR . "includes/$includesPath"; |
| 230 | |
| 231 | if ($class instanceof Closure) { |
| 232 | give()->instance($alias, $class()); |
| 233 | } elseif ($singleton) { |
| 234 | give()->instance($alias, $class::get_instance()); |
| 235 | } else { |
| 236 | give()->instance($alias, new $class()); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * What type of request is this? |
| 242 | * |
| 243 | * @since 2.8.0 |
| 244 | * |
| 245 | * @param string $type admin, ajax, cron or frontend. |
| 246 | * |
| 247 | * @return bool |
| 248 | * @throws UnknownRequestTypeException |
| 249 | */ |
| 250 | private function is_request($type) |
| 251 | { |
| 252 | switch ($type) { |
| 253 | case RequestType::ADMIN: |
| 254 | return is_admin(); |
| 255 | case RequestType::AJAX: |
| 256 | return defined('DOING_AJAX'); |
| 257 | case RequestType::CRON: |
| 258 | return defined('DOING_CRON'); |
| 259 | case RequestType::FRONTEND: |
| 260 | return (!is_admin() || defined('DOING_AJAX')) && !defined('DOING_CRON') && !defined('REST_REQUEST'); |
| 261 | case RequestType::WPCLI: |
| 262 | return defined('WP_CLI') && WP_CLI; |
| 263 | default: |
| 264 | throw new UnknownRequestTypeException($type); |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 |