PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.12.1
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.12.1
1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 1.8.0 All 210 releases
charitable / includes / plugin / class-charitable-install.php

class-charitable-install.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.12.1, at includes/plugin/class-charitable-install.php

225 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Install class.
4 *
5 * The responsibility of this class is to manage the events that need to happen
6 * when the plugin is activated.
7 *
8 * @package Charitable/Class/Charitable Install
9 * @copyright Copyright (c) 2023, WP Charitable LLC
10 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
11 * @since 1.0.0
12 * @version 1.8.1 added activity tables.
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 if ( ! class_exists( 'Charitable_Install' ) ) :
20
21 /**
22 * Charitable_Install
23 *
24 * @since 1.0.0
25 */
26 class Charitable_Install {
27
28 /**
29 * Includes directory path.
30 *
31 * @since 1.6.42
32 *
33 * @var string
34 */
35 private $includes_path;
36
37 /**
38 * Install the plugin.
39 *
40 * @since 1.0.0
41 *
42 * @param string $includes_path Path to the includes directory.
43 */
44 public function __construct( $includes_path ) {
45 $this->includes_path = $includes_path;
46
47 $this->setup_roles();
48 $this->create_tables();
49 $this->setup_upgrade_log();
50 $this->setup_initial_settings();
51
52 set_transient( 'charitable_install', 1, 0 );
53 }
54
55 /**
56 * Finish the plugin installation.
57 *
58 * @since 1.3.4
59 *
60 * @return void
61 */
62 public static function finish_installing() {
63 Charitable_Cron::schedule_events();
64
65 add_action( 'init', 'flush_rewrite_rules' );
66 }
67
68 /**
69 * Create wp roles and assign capabilities
70 *
71 * @since 1.0.0
72 *
73 * @return void
74 */
75 protected function setup_roles() {
76 require_once( $this->includes_path . '/users/class-charitable-roles.php' ); //phpcs:ignore
77 $roles = new Charitable_Roles();
78 $roles->add_roles();
79 $roles->add_caps();
80 }
81
82 /**
83 * Create database tables.
84 *
85 * @since 1.0.0
86 * @version 1.8.1
87 *
88 * @return void
89 */
90 protected function create_tables() {
91 require_once( $this->includes_path . 'abstracts/abstract-class-charitable-db.php' ); //phpcs:ignore
92
93 $tables = array(
94 $this->includes_path . 'data/class-charitable-donors-db.php' => 'Charitable_Donors_DB',
95 $this->includes_path . 'data/class-charitable-donormeta-db.php' => 'Charitable_Donormeta_DB',
96 $this->includes_path . 'data/class-charitable-campaign-donations-db.php' => 'Charitable_Campaign_Donations_DB',
97 $this->includes_path . 'data/class-charitable-donation-activities-db.php' => 'Charitable_Donation_Activities_DB',
98 $this->includes_path . 'data/class-charitable-campaign-activities-db.php' => 'Charitable_Campaign_Activities_DB',
99 $this->includes_path . 'logger/class-charitable-log-db.php' => 'Charitable_Log_DB',
100 );
101
102 foreach ( $tables as $file => $class ) {
103 require_once( $file ); //phpcs:ignore
104 $table = new $class();
105 $table->create_table();
106 }
107 }
108
109 /**
110 * Set up the upgrade log.
111 *
112 * @since 1.3.0
113 *
114 * @return void
115 */
116 protected function setup_upgrade_log() {
117 require_once( $this->includes_path . '/admin/upgrades/class-charitable-upgrade.php' ); //phpcs:ignore
118 Charitable_Upgrade::get_instance()->populate_upgrade_log_on_install();
119 }
120
121 /**
122 * Set up initial settings for install.
123 *
124 * @since 1.8.3.1
125 * @version 1.8.3.7 - Added general default settings.
126 *
127 * @return void
128 */
129 protected function setup_initial_settings() {
130
131 $activated = (array) get_option( 'charitable_activated', array() );
132
133 // If no activation date is set, assume it's a new install.
134 if ( false === $activated || empty( $activated ) ) {
135
136 // Default general settings.
137 $this->set_initial_charitable_option( 'donation_form_display', 'modal' );
138 $this->set_initial_charitable_option( 'country', 'US' );
139 $this->set_initial_charitable_option( 'currency', 'USD' );
140 $this->set_initial_charitable_option( 'currency_format', 'left' );
141 $this->set_initial_charitable_option( 'decimal_separator', '.' );
142 $this->set_initial_charitable_option( 'thousands_separator', ',' );
143 $this->set_initial_charitable_option( 'decimal_count', '2' );
144
145 // Default gateway settings.
146 $this->set_initial_charitable_option( 'test_mode', 1 );
147 $this->set_initial_charitable_option(
148 'active_gateways',
149 array(
150 0 => 'stripe',
151 'stripe' => 'Charitable_Gateway_Stripe_AM',
152 )
153 );
154 $this->set_initial_charitable_option( 'default_gateway', 'stripe' );
155
156 // Default advanced settings.
157 $this->set_initial_charitable_option( 'disable_campaign_legacy_mode', 1 );
158 }
159
160 // Clean up Square gateway settings if charitable-square plugin is not active.
161 $this->cleanup_square_gateway_settings();
162 }
163
164 /**
165 * Clean up Square gateway settings if charitable-square plugin is not active.
166 *
167 * @since 1.8.7
168 *
169 * @return void
170 */
171 private function cleanup_square_gateway_settings() {
172 // Check if charitable-square plugin is active.
173 if ( ! $this->is_square_addon_active() ) {
174 $settings = get_option( 'charitable_settings', array() );
175
176 // If 'square' gateway exists in active_gateways, remove it.
177 if ( isset( $settings['active_gateways']['square'] ) ) {
178 unset( $settings['active_gateways']['square'] );
179
180 // If 'square' was the default gateway, set a new default.
181 if ( isset( $settings['default_gateway'] ) && 'square' === $settings['default_gateway'] ) {
182 $settings['default_gateway'] = count( $settings['active_gateways'] ) ? key( $settings['active_gateways'] ) : '';
183 }
184
185 update_option( 'charitable_settings', $settings );
186 }
187 }
188 }
189
190 /**
191 * Check if charitable-square plugin is active.
192 *
193 * @since 1.8.7
194 *
195 * @return boolean
196 */
197 private function is_square_addon_active() {
198 return is_plugin_active( 'charitable-square/charitable-square.php' );
199 }
200
201 /**
202 * Set an initial Charitable option.
203 *
204 * @since 1.8.3.1
205 *
206 * @param string $setting The setting key.
207 * @param mixed $value The setting value.
208 * @return void
209 */
210 private function set_initial_charitable_option( $setting = '', $value = false ) {
211 $settings = get_option( 'charitable_settings', [] );
212
213 // if the setting somehow already exists, don't overwrite it.
214 if ( '' === $setting || isset( $settings[ $setting ] ) ) {
215 return;
216 }
217
218 $settings[ $setting ] = $value;
219
220 update_option( 'charitable_settings', $settings );
221 }
222 }
223
224 endif;
225