PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
1.8.13 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 All 211 releases
← All changes | includes/plugin/class-charitable-install.php +117 -10 1.7.0.11 → 1.8.13 View file →
@@ -5,12 +5,12 @@
5 5 * The responsibility of this class is to manage the events that need to happen
6 6 * when the plugin is activated.
7 7 *
8 8 * @package Charitable/Class/Charitable Install
9 - * @copyright Copyright (c) 2022, WP Charitable LLC
9 + * @copyright Copyright (c) 2023, WP Charitable LLC
10 10 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
11 11 * @since 1.0.0
12 - * @version 1.6.42
12 + * @version 1.8.1 added activity tables.
13 13 */
14 14
15 15 if ( ! defined( 'ABSPATH' ) ) {
16 16 exit;
@@ -46,8 +46,9 @@
46 46
47 47 $this->setup_roles();
48 48 $this->create_tables();
49 49 $this->setup_upgrade_log();
50 + $this->setup_initial_settings();
50 51
51 52 set_transient( 'charitable_install', 1, 0 );
52 53 }
53 54
@@ -71,9 +72,9 @@
71 72 *
72 73 * @return void
73 74 */
74 75 protected function setup_roles() {
75 - require_once( $this->includes_path . '/users/class-charitable-roles.php' );
76 + require_once( $this->includes_path . '/users/class-charitable-roles.php' ); //phpcs:ignore
76 77 $roles = new Charitable_Roles();
77 78 $roles->add_roles();
78 79 $roles->add_caps();
79 80 }
@@ -81,23 +82,27 @@
81 82 /**
82 83 * Create database tables.
83 84 *
84 85 * @since 1.0.0
86 + * @version 1.8.1
85 87 *
86 88 * @return void
87 89 */
88 90 protected function create_tables() {
89 - require_once( $this->includes_path . 'abstracts/abstract-class-charitable-db.php' );
91 + require_once( $this->includes_path . 'abstracts/abstract-class-charitable-db.php' ); //phpcs:ignore
90 92
91 93 $tables = array(
92 - $this->includes_path . 'data/class-charitable-donors-db.php' => 'Charitable_Donors_DB',
93 - $this->includes_path . 'data/class-charitable-donormeta-db.php' => 'Charitable_Donormeta_DB',
94 - $this->includes_path . 'data/class-charitable-campaign-donations-db.php' => 'Charitable_Campaign_Donations_DB',
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',
95 100 );
96 101
97 102 foreach ( $tables as $file => $class ) {
98 - require_once( $file );
99 - $table = new $class;
103 + require_once( $file ); //phpcs:ignore
104 + $table = new $class();
100 105 $table->create_table();
101 106 }
102 107 }
103 108
@@ -108,10 +113,112 @@
108 113 *
109 114 * @return void
110 115 */
111 116 protected function setup_upgrade_log() {
112 - require_once( $this->includes_path . '/admin/upgrades/class-charitable-upgrade.php' );
117 + require_once( $this->includes_path . '/admin/upgrades/class-charitable-upgrade.php' ); //phpcs:ignore
113 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 );
114 221 }
115 222 }
116 223
117 224 endif;