| @@ -1,18 +1,25 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 3 | +use Give\Form\Migrations\MoveOptionsToVisualAppearanceSection; | |
| 4 | +use Give\Framework\Migrations\Exceptions\DatabaseMigrationException; | |
| 5 | +use Give\Log\Migrations\MigrateExistingLogs; | |
| 6 | +use Give\MigrationLog\Migrations\CreateMigrationsTable; | |
| 7 | +use Give\Revenue\Migrations\AddPastDonationsToRevenueTable; | |
| 8 | + | |
| 2 | 9 | /** |
| 3 | 10 | * Install Function |
| 4 | 11 | * |
| 5 | 12 | * @package Give |
| 6 | - * @subpackage Functions/Install | |
| 13 | + * @since 1.0 | |
| 7 | 14 | * @copyright Copyright (c) 2016, GiveWP |
| 8 | 15 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 | - * @since 1.0 | |
| 16 | + * @subpackage Functions/Install | |
| 10 | 17 | */ |
| 11 | 18 | |
| 12 | 19 | // Exit if accessed directly. |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 14 | - exit; | |
| 20 | +if (!defined('ABSPATH')) { | |
| 21 | + exit; | |
| 15 | 22 | } |
| 16 | 23 | |
| 17 | 24 | /** |
| 18 | 25 | * Install |
| @@ -18,37 +25,30 @@ | ||
| 18 | 25 | * Install |
| 19 | 26 | * |
| 20 | 27 | * Runs on plugin install by setting up the post types, custom taxonomies, flushing rewrite rules to initiate the new |
| 21 | 28 | * 'donations' slug and also creates the plugin and populates the settings fields for those plugin pages. After |
| 22 | - * successful install, the user is redirected to the Give Welcome screen. | |
| 29 | + * successful install, the user is redirected to the Give Onboarding Wizard. | |
| 23 | 30 | * |
| 24 | 31 | * @since 1.0 |
| 25 | 32 | * |
| 26 | 33 | * @param bool $network_wide |
| 27 | 34 | * |
| 35 | + * @return void | |
| 28 | 36 | * @global $wpdb |
| 29 | - * @return void | |
| 30 | 37 | */ |
| 31 | -function give_install( $network_wide = false ) { | |
| 38 | +function give_install($network_wide = false) | |
| 39 | +{ | |
| 40 | + global $wpdb; | |
| 32 | 41 | |
| 33 | - global $wpdb; | |
| 34 | - | |
| 35 | - if ( is_multisite() && $network_wide ) { | |
| 36 | - | |
| 37 | - foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs LIMIT 100" ) as $blog_id ) { | |
| 38 | - | |
| 39 | - switch_to_blog( $blog_id ); | |
| 40 | - give_run_install(); | |
| 41 | - restore_current_blog(); | |
| 42 | - | |
| 43 | - } | |
| 44 | - | |
| 45 | - } else { | |
| 46 | - | |
| 47 | - give_run_install(); | |
| 48 | - | |
| 49 | - } | |
| 50 | - | |
| 42 | + if (is_multisite() && $network_wide) { | |
| 43 | + foreach ($wpdb->get_col("SELECT blog_id FROM $wpdb->blogs LIMIT 100") as $blog_id) { | |
| 44 | + switch_to_blog($blog_id); | |
| 45 | + give_run_install(); | |
| 46 | + restore_current_blog(); | |
| 47 | + } | |
| 48 | + } else { | |
| 49 | + give_run_install(); | |
| 50 | + } | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * Run the Give Install process. |
| @@ -55,115 +55,130 @@ | ||
| 55 | 55 | * |
| 56 | 56 | * @since 1.5 |
| 57 | 57 | * @return void |
| 58 | 58 | */ |
| 59 | -function give_run_install() { | |
| 60 | - $give_options = give_get_settings(); | |
| 59 | +function give_run_install() | |
| 60 | +{ | |
| 61 | + $give_options = give_get_settings(); | |
| 61 | 62 | |
| 62 | - // Setup the Give Custom Post Types. | |
| 63 | - give_setup_post_types(); | |
| 63 | + // Setup the Give Custom Post Types. | |
| 64 | + give_setup_post_types(); | |
| 64 | 65 | |
| 65 | - // Add Upgraded From Option. | |
| 66 | - $current_version = get_option( 'give_version' ); | |
| 67 | - if ( $current_version ) { | |
| 68 | - update_option( 'give_version_upgraded_from', $current_version, false ); | |
| 69 | - } | |
| 66 | + // Add Upgraded From Option. | |
| 67 | + $current_version = get_option('give_version'); | |
| 68 | + if ($current_version) { | |
| 69 | + update_option('give_version_upgraded_from', $current_version, false); | |
| 70 | + } | |
| 70 | 71 | |
| 71 | - // Setup some default options. | |
| 72 | - $options = array(); | |
| 72 | + // Setup some default options. | |
| 73 | + $options = []; | |
| 73 | 74 | |
| 74 | - //Fresh Install? Setup Test Mode, Base Country (US), Test Gateway, Currency. | |
| 75 | - if ( empty( $current_version ) ) { | |
| 76 | - $options = array_merge( $options, give_get_default_settings() ); | |
| 77 | - } | |
| 75 | + // Fresh Install? Setup Test Mode, Base Country (US), Test Gateway, Currency. | |
| 76 | + if (empty($current_version)) { | |
| 77 | + $options = array_merge($options, give_get_default_settings()); | |
| 78 | + } else { | |
| 79 | + // Otherwise, disable the Onboarding experience | |
| 80 | + $options = [ | |
| 81 | + 'setup_page_enabled' => 'disabled', | |
| 82 | + ]; | |
| 83 | + } | |
| 78 | 84 | |
| 79 | - // Populate the default values. | |
| 80 | - update_option( 'give_settings', array_merge( $give_options, $options ), false ); | |
| 85 | + // Populate the default values. | |
| 86 | + update_option('give_settings', array_merge($give_options, $options), false); | |
| 81 | 87 | |
| 82 | - /** | |
| 83 | - * Run plugin upgrades. | |
| 84 | - * | |
| 85 | - * @since 1.8 | |
| 86 | - */ | |
| 87 | - do_action( 'give_upgrades' ); | |
| 88 | + // Create Give roles. | |
| 89 | + $roles = new Give_Roles(); | |
| 90 | + $roles->add_roles(); | |
| 91 | + $roles->add_caps(); | |
| 88 | 92 | |
| 89 | - if ( GIVE_VERSION !== get_option( 'give_version' ) ) { | |
| 90 | - update_option( 'give_version', GIVE_VERSION, false ); | |
| 91 | - } | |
| 93 | + // Set api version, end point and refresh permalink. | |
| 94 | + $api = new Give_API(); | |
| 95 | + $api->add_endpoint(); | |
| 96 | + update_option('give_default_api_version', 'v' . $api->get_version(), false); | |
| 92 | 97 | |
| 93 | - // Create Give roles. | |
| 94 | - $roles = new Give_Roles(); | |
| 95 | - $roles->add_roles(); | |
| 96 | - $roles->add_caps(); | |
| 98 | + // Create databases. | |
| 99 | + __give_register_tables(); | |
| 97 | 100 | |
| 98 | - // Set api version, end point and refresh permalink. | |
| 99 | - $api = new Give_API(); | |
| 100 | - $api->add_endpoint(); | |
| 101 | - update_option( 'give_default_api_version', 'v' . $api->get_version(), false ); | |
| 101 | + // Add a temporary option to note that Give pages have been created. | |
| 102 | + Give_Cache::set('_give_installed', $options, 30, true); | |
| 102 | 103 | |
| 103 | - flush_rewrite_rules(); | |
| 104 | + /** | |
| 105 | + * Run plugin upgrades. | |
| 106 | + * | |
| 107 | + * @since 1.8 | |
| 108 | + */ | |
| 109 | + do_action('give_upgrades'); | |
| 104 | 110 | |
| 105 | - // Create databases. | |
| 106 | - __give_register_tables(); | |
| 111 | + if (GIVE_VERSION !== get_option('give_version')) { | |
| 112 | + update_option('give_version', GIVE_VERSION, false); | |
| 113 | + } | |
| 107 | 114 | |
| 108 | - // Add a temporary option to note that Give pages have been created. | |
| 109 | - Give_Cache::set( '_give_installed', $options, 30, true ); | |
| 115 | + if (!$current_version) { | |
| 116 | + require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php'; | |
| 110 | 117 | |
| 111 | - if ( ! $current_version ) { | |
| 118 | + // When new upgrade routines are added, mark them as complete on fresh install. | |
| 119 | + $upgrade_routines = [ | |
| 120 | + 'upgrade_give_user_caps_cleanup', | |
| 121 | + 'upgrade_give_payment_customer_id', | |
| 122 | + 'upgrade_give_offline_status', | |
| 123 | + 'v18_upgrades_core_setting', | |
| 124 | + 'v18_upgrades_form_metadata', | |
| 125 | + 'v189_upgrades_levels_post_meta', | |
| 126 | + 'v1812_update_amount_values', | |
| 127 | + 'v1812_update_donor_purchase_values', | |
| 128 | + 'v1813_update_user_roles', | |
| 129 | + 'v1813_update_donor_user_roles', | |
| 130 | + 'v1817_update_donation_iranian_currency_code', | |
| 131 | + 'v1817_cleanup_user_roles', | |
| 132 | + 'v1818_assign_custom_amount_set_donation', | |
| 133 | + 'v1818_give_worker_role_cleanup', | |
| 134 | + 'v20_upgrades_form_metadata', | |
| 135 | + 'v20_logs_upgrades', | |
| 136 | + 'v20_move_metadata_into_new_table', | |
| 137 | + 'v20_rename_donor_tables', | |
| 138 | + 'v20_upgrades_donor_name', | |
| 139 | + 'v20_upgrades_user_address', | |
| 140 | + 'v20_upgrades_payment_metadata', | |
| 141 | + 'v201_upgrades_payment_metadata', | |
| 142 | + 'v201_add_missing_donors', | |
| 143 | + 'v201_move_metadata_into_new_table', | |
| 144 | + 'v201_logs_upgrades', | |
| 145 | + 'v210_verify_form_status_upgrades', | |
| 146 | + 'v213_delete_donation_meta', | |
| 147 | + 'v215_update_donor_user_roles', | |
| 148 | + 'v220_rename_donation_meta_type', | |
| 149 | + 'v224_update_donor_meta', | |
| 150 | + 'v224_update_donor_meta_forms_id', | |
| 151 | + 'v230_move_donor_note', | |
| 152 | + 'v230_move_donation_note', | |
| 153 | + 'v230_delete_donor_wall_related_donor_data', | |
| 154 | + 'v230_delete_donor_wall_related_comment_data', | |
| 155 | + 'v240_update_form_goal_progress', | |
| 156 | + 'v241_remove_sale_logs', | |
| 157 | + 'v270_store_stripe_account_for_donation', | |
| 158 | + AddPastDonationsToRevenueTable::id(), | |
| 159 | + MigrateExistingLogs::id() | |
| 160 | + ]; | |
| 112 | 161 | |
| 113 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php'; | |
| 162 | + foreach ($upgrade_routines as $upgrade) { | |
| 163 | + give_set_upgrade_complete($upgrade); | |
| 164 | + } | |
| 165 | + } | |
| 114 | 166 | |
| 115 | - // When new upgrade routines are added, mark them as complete on fresh install. | |
| 116 | - $upgrade_routines = array( | |
| 117 | - 'upgrade_give_user_caps_cleanup', | |
| 118 | - 'upgrade_give_payment_customer_id', | |
| 119 | - 'upgrade_give_offline_status', | |
| 120 | - 'v18_upgrades_core_setting', | |
| 121 | - 'v18_upgrades_form_metadata', | |
| 122 | - 'v189_upgrades_levels_post_meta', | |
| 123 | - 'v1812_update_amount_values', | |
| 124 | - 'v1812_update_donor_purchase_values', | |
| 125 | - 'v1813_update_user_roles', | |
| 126 | - 'v1813_update_donor_user_roles', | |
| 127 | - 'v1817_update_donation_iranian_currency_code', | |
| 128 | - 'v1817_cleanup_user_roles', | |
| 129 | - 'v1818_assign_custom_amount_set_donation', | |
| 130 | - 'v1818_give_worker_role_cleanup', | |
| 131 | - 'v20_upgrades_form_metadata', | |
| 132 | - 'v20_logs_upgrades', | |
| 133 | - 'v20_move_metadata_into_new_table', | |
| 134 | - 'v20_rename_donor_tables', | |
| 135 | - 'v20_upgrades_donor_name', | |
| 136 | - 'v20_upgrades_user_address', | |
| 137 | - 'v20_upgrades_payment_metadata', | |
| 138 | - 'v201_upgrades_payment_metadata', | |
| 139 | - 'v201_add_missing_donors', | |
| 140 | - 'v201_move_metadata_into_new_table', | |
| 141 | - 'v201_logs_upgrades', | |
| 142 | - 'v210_verify_form_status_upgrades', | |
| 143 | - 'v213_delete_donation_meta', | |
| 144 | - 'v215_update_donor_user_roles', | |
| 145 | - 'v220_rename_donation_meta_type', | |
| 146 | - 'v224_update_donor_meta', | |
| 147 | - 'v224_update_donor_meta_forms_id', | |
| 148 | - 'v230_move_donor_note', | |
| 149 | - 'v230_move_donation_note', | |
| 150 | - 'v230_delete_donor_wall_related_donor_data', | |
| 151 | - 'v230_delete_donor_wall_related_comment_data' | |
| 152 | - ); | |
| 167 | + // Bail if activating from network, or bulk. | |
| 168 | + if (is_network_admin() || isset($_GET['activate-multi'])) { | |
| 169 | + return; | |
| 170 | + } | |
| 153 | 171 | |
| 154 | - foreach ( $upgrade_routines as $upgrade ) { | |
| 155 | - give_set_upgrade_complete( $upgrade ); | |
| 156 | - } | |
| 157 | - } | |
| 172 | + // Setup embed form route on fresh install or plugin activation. | |
| 173 | + Give()->routeForm->setBasePrefix(); | |
| 174 | + Give()->routeForm->addRule(); | |
| 158 | 175 | |
| 159 | - // Bail if activating from network, or bulk. | |
| 160 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { | |
| 161 | - return; | |
| 162 | - } | |
| 176 | + // Flush rewrite rules. | |
| 177 | + flush_rewrite_rules(); | |
| 163 | 178 | |
| 164 | - // Add the transient to redirect. | |
| 165 | - Give_Cache::set( '_give_activation_redirect', true, 30, true ); | |
| 179 | + // Add the transient to redirect. | |
| 180 | + Give_Cache::set('_give_activation_redirect', true, 30, true); | |
| 166 | 181 | } |
| 167 | 182 | |
| 168 | 183 | /** |
| 169 | 184 | * Network Activated New Site Setup. |
| @@ -172,59 +187,57 @@ | ||
| 172 | 187 | * up the site for Give. |
| 173 | 188 | * |
| 174 | 189 | * @since 1.3.5 |
| 175 | 190 | * |
| 176 | - * @param int $blog_id The Blog ID created. | |
| 177 | - * @param int $user_id The User ID set as the admin. | |
| 178 | - * @param string $domain The URL. | |
| 179 | - * @param string $path Site Path. | |
| 180 | - * @param int $site_id The Site ID. | |
| 181 | - * @param array $meta Blog Meta. | |
| 191 | + * @param int $blog_id The Blog ID created. | |
| 192 | + * @param int $user_id The User ID set as the admin. | |
| 193 | + * @param string $domain The URL. | |
| 194 | + * @param string $path Site Path. | |
| 195 | + * @param int $site_id The Site ID. | |
| 196 | + * @param array $meta Blog Meta. | |
| 182 | 197 | */ |
| 183 | -function give_on_create_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) { | |
| 184 | - | |
| 185 | - if ( is_plugin_active_for_network( GIVE_PLUGIN_BASENAME ) ) { | |
| 186 | - | |
| 187 | - switch_to_blog( $blog_id ); | |
| 188 | - give_install(); | |
| 189 | - restore_current_blog(); | |
| 190 | - | |
| 191 | - } | |
| 192 | - | |
| 198 | +function give_on_create_blog($blog_id, $user_id, $domain, $path, $site_id, $meta) | |
| 199 | +{ | |
| 200 | + if (is_plugin_active_for_network(GIVE_PLUGIN_BASENAME)) { | |
| 201 | + switch_to_blog($blog_id); | |
| 202 | + give_install(); | |
| 203 | + restore_current_blog(); | |
| 204 | + } | |
| 193 | 205 | } |
| 194 | 206 | |
| 195 | -add_action( 'wpmu_new_blog', 'give_on_create_blog', 10, 6 ); | |
| 207 | +add_action('wpmu_new_blog', 'give_on_create_blog', 10, 6); | |
| 196 | 208 | |
| 197 | 209 | |
| 198 | 210 | /** |
| 199 | 211 | * Drop Give's custom tables when a mu site is deleted. |
| 200 | 212 | * |
| 213 | + * @since 3.4.0 updated implementation to query all give_* tables | |
| 201 | 214 | * @since 1.4.3 |
| 202 | 215 | * |
| 203 | - * @param array $tables The tables to drop. | |
| 204 | - * @param int $blog_id The Blog ID being deleted. | |
| 216 | + * @param array $tables The tables to drop. | |
| 217 | + * @param int $blog_id The Blog ID being deleted. | |
| 205 | 218 | * |
| 206 | 219 | * @return array The tables to drop. |
| 207 | 220 | */ |
| 208 | -function give_wpmu_drop_tables( $tables, $blog_id ) { | |
| 221 | +function give_wpmu_drop_tables($tables, $blog_id) | |
| 222 | +{ | |
| 223 | + global $wpdb; | |
| 209 | 224 | |
| 210 | - switch_to_blog( $blog_id ); | |
| 211 | - $custom_tables = __give_get_tables(); | |
| 225 | + switch_to_blog($blog_id); | |
| 212 | 226 | |
| 213 | - /* @var Give_DB $table */ | |
| 214 | - foreach ( $custom_tables as $table ) { | |
| 215 | - if ( $table->installed() ) { | |
| 216 | - $tables[] = $table->table_name; | |
| 217 | - } | |
| 218 | - } | |
| 227 | + $prefix = $wpdb->prefix . 'give_%'; | |
| 228 | + $giveTables = $wpdb->get_col("SHOW TABLES LIKE '{$prefix}'"); | |
| 219 | 229 | |
| 220 | - restore_current_blog(); | |
| 230 | + foreach ($giveTables as $table) { | |
| 231 | + $tables[] = $table; | |
| 232 | + } | |
| 221 | 233 | |
| 222 | - return $tables; | |
| 234 | + restore_current_blog(); | |
| 223 | 235 | |
| 236 | + return array_unique($tables); | |
| 224 | 237 | } |
| 225 | 238 | |
| 226 | -add_filter( 'wpmu_drop_tables', 'give_wpmu_drop_tables', 10, 2 ); | |
| 239 | +add_filter('wpmu_drop_tables', 'give_wpmu_drop_tables', 10, 2); | |
| 227 | 240 | |
| 228 | 241 | /** |
| 229 | 242 | * Post-installation |
| 230 | 243 | * |
| @@ -232,55 +245,49 @@ | ||
| 232 | 245 | * |
| 233 | 246 | * @since 1.0 |
| 234 | 247 | * @return void |
| 235 | 248 | */ |
| 236 | -function give_after_install() { | |
| 249 | +function give_after_install() | |
| 250 | +{ | |
| 251 | + if (!is_admin()) { | |
| 252 | + return; | |
| 253 | + } | |
| 237 | 254 | |
| 238 | - if ( ! is_admin() ) { | |
| 239 | - return; | |
| 240 | - } | |
| 255 | + $give_options = Give_Cache::get('_give_installed', true); | |
| 256 | + $give_table_check = get_option('_give_table_check', false); | |
| 241 | 257 | |
| 242 | - $give_options = Give_Cache::get( '_give_installed', true ); | |
| 243 | - $give_table_check = get_option( '_give_table_check', false ); | |
| 258 | + if (false === $give_table_check || current_time('timestamp') > $give_table_check) { | |
| 259 | + if (!@Give()->donor_meta->installed()) { | |
| 260 | + // Create the donor meta database. | |
| 261 | + // (this ensures it creates it on multisite instances where it is network activated). | |
| 262 | + @Give()->donor_meta->create_table(); | |
| 263 | + } | |
| 244 | 264 | |
| 245 | - if ( false === $give_table_check || current_time( 'timestamp' ) > $give_table_check ) { | |
| 265 | + if (!@Give()->donors->installed()) { | |
| 266 | + // Create the donor database. | |
| 267 | + // (this ensures it creates it on multisite instances where it is network activated). | |
| 268 | + @Give()->donors->create_table(); | |
| 269 | + } | |
| 246 | 270 | |
| 247 | - if ( ! @Give()->donor_meta->installed() ) { | |
| 271 | + /** | |
| 272 | + * Fires after plugin installation. | |
| 273 | + * | |
| 274 | + * @since 1.0 | |
| 275 | + * | |
| 276 | + * @param array $give_options Give plugin options. | |
| 277 | + */ | |
| 278 | + do_action('give_after_install', $give_options); | |
| 248 | 279 | |
| 249 | - // Create the donor meta database. | |
| 250 | - // (this ensures it creates it on multisite instances where it is network activated). | |
| 251 | - @Give()->donor_meta->create_table(); | |
| 280 | + update_option('_give_table_check', (current_time('timestamp') + WEEK_IN_SECONDS), false); | |
| 281 | + } | |
| 252 | 282 | |
| 253 | - } | |
| 254 | - | |
| 255 | - if ( ! @Give()->donors->installed() ) { | |
| 256 | - // Create the donor database. | |
| 257 | - // (this ensures it creates it on multisite instances where it is network activated). | |
| 258 | - @Give()->donors->create_table(); | |
| 259 | - | |
| 260 | - /** | |
| 261 | - * Fires after plugin installation. | |
| 262 | - * | |
| 263 | - * @since 1.0 | |
| 264 | - * | |
| 265 | - * @param array $give_options Give plugin options. | |
| 266 | - */ | |
| 267 | - do_action( 'give_after_install', $give_options ); | |
| 268 | - } | |
| 269 | - | |
| 270 | - update_option( '_give_table_check', ( current_time( 'timestamp' ) + WEEK_IN_SECONDS ), false ); | |
| 271 | - | |
| 272 | - } | |
| 273 | - | |
| 274 | - // Delete the transient | |
| 275 | - if ( false !== $give_options ) { | |
| 276 | - Give_Cache::delete( Give_Cache::get_key( '_give_installed' ) ); | |
| 277 | - } | |
| 278 | - | |
| 279 | - | |
| 283 | + // Delete the transient | |
| 284 | + if (false !== $give_options) { | |
| 285 | + Give_Cache::delete(Give_Cache::get_key('_give_installed')); | |
| 286 | + } | |
| 280 | 287 | } |
| 281 | 288 | |
| 282 | -add_action( 'admin_init', 'give_after_install' ); | |
| 289 | +add_action('admin_init', 'give_after_install'); | |
| 283 | 290 | |
| 284 | 291 | |
| 285 | 292 | /** |
| 286 | 293 | * Install user roles on sub-sites of a network |
| @@ -289,28 +296,25 @@ | ||
| 289 | 296 | * |
| 290 | 297 | * @since 1.0 |
| 291 | 298 | * @return void |
| 292 | 299 | */ |
| 293 | -function give_install_roles_on_network() { | |
| 300 | +function give_install_roles_on_network() | |
| 301 | +{ | |
| 302 | + global $wp_roles; | |
| 294 | 303 | |
| 295 | - global $wp_roles; | |
| 304 | + if (!is_object($wp_roles)) { | |
| 305 | + return; | |
| 306 | + } | |
| 296 | 307 | |
| 297 | - if ( ! is_object( $wp_roles ) ) { | |
| 298 | - return; | |
| 299 | - } | |
| 300 | - | |
| 301 | - if ( ! array_key_exists( 'give_manager', $wp_roles->roles ) ) { | |
| 302 | - | |
| 303 | - // Create Give plugin roles | |
| 304 | - $roles = new Give_Roles(); | |
| 305 | - $roles->add_roles(); | |
| 306 | - $roles->add_caps(); | |
| 307 | - | |
| 308 | - } | |
| 309 | - | |
| 308 | + if (!array_key_exists('give_manager', $wp_roles->roles)) { | |
| 309 | + // Create Give plugin roles | |
| 310 | + $roles = new Give_Roles(); | |
| 311 | + $roles->add_roles(); | |
| 312 | + $roles->add_caps(); | |
| 313 | + } | |
| 310 | 314 | } |
| 311 | 315 | |
| 312 | -add_action( 'admin_init', 'give_install_roles_on_network' ); | |
| 316 | +add_action('admin_init', 'give_install_roles_on_network'); | |
| 313 | 317 | |
| 314 | 318 | /** |
| 315 | 319 | * Default core setting values. |
| 316 | 320 | * |
| @@ -316,82 +320,95 @@ | ||
| 316 | 320 | * |
| 317 | 321 | * @since 1.8 |
| 318 | 322 | * @return array |
| 319 | 323 | */ |
| 320 | -function give_get_default_settings() { | |
| 324 | +function give_get_default_settings() | |
| 325 | +{ | |
| 326 | + $options = [ | |
| 327 | + // General. | |
| 328 | + 'base_country' => 'US', | |
| 329 | + 'test_mode' => 'enabled', | |
| 330 | + 'currency' => 'USD', | |
| 331 | + 'currency_position' => 'before', | |
| 332 | + 'session_lifetime' => '604800', | |
| 333 | + 'email_access' => 'enabled', | |
| 334 | + 'thousands_separator' => ',', | |
| 335 | + 'decimal_separator' => '.', | |
| 336 | + 'number_decimals' => 2, | |
| 337 | + 'sequential-ordering_status' => 'enabled', | |
| 321 | 338 | |
| 322 | - $options = array( | |
| 323 | - // General. | |
| 324 | - 'base_country' => 'US', | |
| 325 | - 'test_mode' => 'enabled', | |
| 326 | - 'currency' => 'USD', | |
| 327 | - 'currency_position' => 'before', | |
| 328 | - 'session_lifetime' => '604800', | |
| 329 | - 'email_access' => 'enabled', | |
| 330 | - 'thousands_separator' => ',', | |
| 331 | - 'decimal_separator' => '.', | |
| 332 | - 'number_decimals' => 2, | |
| 333 | - 'sequential-ordering_status' => 'enabled', | |
| 339 | + // Display options. | |
| 340 | + 'css' => 'enabled', | |
| 341 | + 'floatlabels' => 'disabled', | |
| 342 | + 'company_field' => 'disabled', | |
| 343 | + 'name_title_prefix' => 'disabled', | |
| 344 | + 'forms_singular' => 'enabled', | |
| 345 | + 'forms_archives' => 'enabled', | |
| 346 | + 'forms_excerpt' => 'enabled', | |
| 347 | + 'form_featured_img' => 'enabled', | |
| 348 | + 'form_sidebar' => 'enabled', | |
| 349 | + 'categories' => 'disabled', | |
| 350 | + 'tags' => 'disabled', | |
| 351 | + 'terms' => 'disabled', | |
| 352 | + 'admin_notices' => 'enabled', | |
| 353 | + 'cache' => 'enabled', | |
| 354 | + 'uninstall_on_delete' => 'disabled', | |
| 355 | + 'the_content_filter' => 'enabled', | |
| 356 | + 'scripts_footer' => 'disabled', | |
| 357 | + 'agree_to_terms_label' => __('Agree to Terms?', 'give'), | |
| 358 | + 'agreement_text' => give_get_default_agreement_text(), | |
| 359 | + 'babel_polyfill_script' => 'enabled', | |
| 334 | 360 | |
| 335 | - // Display options. | |
| 336 | - 'css' => 'enabled', | |
| 337 | - 'floatlabels' => 'disabled', | |
| 338 | - 'welcome' => 'enabled', | |
| 339 | - 'company_field' => 'disabled', | |
| 340 | - 'name_title_prefix' => 'disabled', | |
| 341 | - 'forms_singular' => 'enabled', | |
| 342 | - 'forms_archives' => 'enabled', | |
| 343 | - 'forms_excerpt' => 'enabled', | |
| 344 | - 'form_featured_img' => 'enabled', | |
| 345 | - 'form_sidebar' => 'enabled', | |
| 346 | - 'categories' => 'disabled', | |
| 347 | - 'tags' => 'disabled', | |
| 348 | - 'terms' => 'disabled', | |
| 349 | - 'admin_notices' => 'enabled', | |
| 350 | - 'cache' => 'enabled', | |
| 351 | - 'uninstall_on_delete' => 'disabled', | |
| 352 | - 'the_content_filter' => 'enabled', | |
| 353 | - 'scripts_footer' => 'disabled', | |
| 354 | - 'agree_to_terms_label' => __( 'Agree to Terms?', 'give' ), | |
| 355 | - 'agreement_text' => give_get_default_agreement_text(), | |
| 356 | - 'babel_polyfill_script' => 'enabled', | |
| 361 | + // Default is manual gateway. | |
| 362 | + 'gateways' => [ | |
| 363 | + 'manual' => 1, | |
| 364 | + 'offline' => 1, | |
| 365 | + ], | |
| 366 | + 'gateways_v3' => [ | |
| 367 | + 'manual' => 1, | |
| 368 | + 'offline' => 1, | |
| 369 | + ], | |
| 370 | + 'default_gateway' => 'manual', | |
| 371 | + 'default_gateway_v3' => 'manual', | |
| 357 | 372 | |
| 358 | - // Paypal IPN verification. | |
| 359 | - 'paypal_verification' => 'enabled', | |
| 373 | + // Offline gateway setup. | |
| 374 | + 'global_offline_donation_content' => give_get_default_offline_donation_content(), | |
| 375 | + 'global_offline_donation_email' => give_get_default_offline_donation_content(), | |
| 360 | 376 | |
| 361 | - // Default is manual gateway. | |
| 362 | - 'gateways' => array( 'manual' => 1, 'offline' => 1 ), | |
| 363 | - 'default_gateway' => 'manual', | |
| 377 | + // Billing address. | |
| 378 | + 'give_offline_donation_enable_billing_fields' => 'disabled', | |
| 364 | 379 | |
| 365 | - // Offline gateway setup. | |
| 366 | - 'global_offline_donation_content' => give_get_default_offline_donation_content(), | |
| 367 | - 'global_offline_donation_email' => give_get_default_offline_donation_content(), | |
| 380 | + // Default donation notification email. | |
| 381 | + 'donation_notification' => give_get_default_donation_notification_email(), | |
| 368 | 382 | |
| 369 | - // Billing address. | |
| 370 | - 'give_offline_donation_enable_billing_fields' => 'disabled', | |
| 383 | + // Default email receipt message. | |
| 384 | + 'donation_receipt' => give_get_default_donation_receipt_email(), | |
| 371 | 385 | |
| 372 | - // Default donation notification email. | |
| 373 | - 'donation_notification' => give_get_default_donation_notification_email(), | |
| 386 | + 'donor_default_user_role' => 'give_donor', | |
| 387 | + Give()->routeForm->getOptionName() => 'give', | |
| 374 | 388 | |
| 375 | - // Default email receipt message. | |
| 376 | - 'donation_receipt' => give_get_default_donation_receipt_email(), | |
| 389 | + // Stripe accounts. | |
| 390 | + '_give_stripe_get_all_accounts' => [], | |
| 377 | 391 | |
| 378 | - 'donor_default_user_role' => 'give_donor', | |
| 392 | + // Onboarding | |
| 393 | + 'setup_page_enabled' => 'enabled', | |
| 379 | 394 | |
| 380 | - ); | |
| 395 | + // Advanced settings | |
| 396 | + 'usage_tracking' => 'disabled', | |
| 397 | + ]; | |
| 381 | 398 | |
| 382 | - return $options; | |
| 399 | + return $options; | |
| 383 | 400 | } |
| 384 | 401 | |
| 385 | 402 | /** |
| 386 | 403 | * Default terms and conditions. |
| 387 | 404 | */ |
| 388 | -function give_get_default_agreement_text() { | |
| 405 | +function give_get_default_agreement_text() | |
| 406 | +{ | |
| 407 | + $org_name = get_bloginfo('name'); | |
| 389 | 408 | |
| 390 | - $org_name = get_bloginfo( 'name' ); | |
| 391 | - | |
| 392 | - $agreement = sprintf( | |
| 393 | - '<p>Acceptance of any contribution, gift or grant is at the discretion of the %1$s. The %1$s will not accept any gift unless it can be used or expended consistently with the purpose and mission of the %1$s.</p> | |
| 409 | + $agreement = sprintf( | |
| 410 | + '<p>Acceptance of any contribution, gift or grant is at the discretion of the %1$s. The %1$s will not accept any gift unless it can be used or expended consistently with the purpose and mission of the %1$s.</p> | |
| 394 | 411 | <p>No irrevocable gift, whether outright or life-income in character, will be accepted if under any reasonable set of circumstances the gift would jeopardize the donor’s financial security.</p> |
| 395 | 412 | <p>The %1$s will refrain from providing advice about the tax or other treatment of gifts and will encourage donors to seek guidance from their own professional advisers to assist them in the process of making their donation.</p> |
| 396 | 413 | <p>The %1$s will accept donations of cash or publicly traded securities. Gifts of in-kind services will be accepted at the discretion of the %1$s.</p> |
| 397 | 414 | <p>Certain other gifts, real property, personal property, in-kind gifts, non-liquid securities, and contributions whose sources are not transparent or whose use is restricted in some manner, must be reviewed prior to acceptance due to the special obligations raised or liabilities they may pose for %1$s.</p> |
| @@ -397,12 +414,12 @@ | ||
| 397 | 414 | <p>Certain other gifts, real property, personal property, in-kind gifts, non-liquid securities, and contributions whose sources are not transparent or whose use is restricted in some manner, must be reviewed prior to acceptance due to the special obligations raised or liabilities they may pose for %1$s.</p> |
| 398 | 415 | <p>The %1$s will provide acknowledgments to donors meeting tax requirements for property received by the charity as a gift. However, except for gifts of cash and publicly traded securities, no value shall be ascribed to any receipt or other form of substantiation of a gift received by %1$s.</p> |
| 399 | 416 | <p>The %1$s will respect the intent of the donor relating to gifts for restricted purposes and those relating to the desire to remain anonymous. With respect to anonymous gifts, the %1$s will restrict information about the donor to only those staff members with a need to know.</p> |
| 400 | 417 | <p>The %1$s will not compensate, whether through commissions, finders\' fees, or other means, any third party for directing a gift or a donor to the %1$s.</p>', |
| 401 | - $org_name | |
| 402 | - ); | |
| 418 | + $org_name | |
| 419 | + ); | |
| 403 | 420 | |
| 404 | - return apply_filters( 'give_get_default_agreement_text', $agreement, $org_name ); | |
| 421 | + return apply_filters('give_get_default_agreement_text', $agreement, $org_name); | |
| 405 | 422 | } |
| 406 | 423 | |
| 407 | 424 | |
| 408 | 425 | /** |
| @@ -411,79 +428,82 @@ | ||
| 411 | 428 | * @since 1.8.11 |
| 412 | 429 | * |
| 413 | 430 | * @return void |
| 414 | 431 | */ |
| 415 | -function give_create_pages() { | |
| 432 | +function give_create_pages() | |
| 433 | +{ | |
| 434 | + // Bailout if pages already created. | |
| 435 | + if (Give_Cache_Setting::get_option('give_install_pages_created')) { | |
| 436 | + return; | |
| 437 | + } | |
| 416 | 438 | |
| 417 | - // Bailout if pages already created. | |
| 418 | - if ( get_option( 'give_install_pages_created' ) ) { | |
| 419 | - return false; | |
| 420 | - } | |
| 439 | + $options = []; | |
| 421 | 440 | |
| 422 | - $options = array(); | |
| 441 | + // Checks if the Success Page option exists AND that the page exists. | |
| 442 | + if (!get_post(give_get_option('success_page'))) { | |
| 443 | + // Donation Confirmation (Success) Page | |
| 444 | + $success = wp_insert_post( | |
| 445 | + [ | |
| 446 | + 'post_title' => esc_html__('Donation Confirmation', 'give'), | |
| 447 | + 'post_content' => '[give_receipt]', | |
| 448 | + 'post_status' => 'publish', | |
| 449 | + 'post_author' => 1, | |
| 450 | + 'post_type' => 'page', | |
| 451 | + 'comment_status' => 'closed', | |
| 452 | + ] | |
| 453 | + ); | |
| 423 | 454 | |
| 424 | - // Checks if the Success Page option exists AND that the page exists. | |
| 425 | - if ( ! get_post( give_get_option( 'success_page' ) ) ) { | |
| 455 | + // Store our page IDs | |
| 456 | + $options['success_page'] = $success; | |
| 457 | + } | |
| 426 | 458 | |
| 427 | - // Donation Confirmation (Success) Page | |
| 428 | - $success = wp_insert_post( | |
| 429 | - array( | |
| 430 | - 'post_title' => esc_html__( 'Donation Confirmation', 'give' ), | |
| 431 | - 'post_content' => '[give_receipt]', | |
| 432 | - 'post_status' => 'publish', | |
| 433 | - 'post_author' => 1, | |
| 434 | - 'post_type' => 'page', | |
| 435 | - 'comment_status' => 'closed' | |
| 436 | - ) | |
| 437 | - ); | |
| 459 | + // Checks if the Failure Page option exists AND that the page exists. | |
| 460 | + if (!get_post(give_get_option('failure_page'))) { | |
| 461 | + // Failed Donation Page | |
| 462 | + $failed = wp_insert_post( | |
| 463 | + [ | |
| 464 | + 'post_title' => esc_html__('Donation Failed', 'give'), | |
| 465 | + 'post_content' => esc_html__( | |
| 466 | + 'We\'re sorry, your donation failed to process. Please try again or contact site support.', | |
| 467 | + 'give' | |
| 468 | + ), | |
| 469 | + 'post_status' => 'publish', | |
| 470 | + 'post_author' => 1, | |
| 471 | + 'post_type' => 'page', | |
| 472 | + 'comment_status' => 'closed', | |
| 473 | + ] | |
| 474 | + ); | |
| 438 | 475 | |
| 439 | - // Store our page IDs | |
| 440 | - $options['success_page'] = $success; | |
| 441 | - } | |
| 476 | + $options['failure_page'] = $failed; | |
| 477 | + } | |
| 442 | 478 | |
| 443 | - // Checks if the Failure Page option exists AND that the page exists. | |
| 444 | - if ( ! get_post( give_get_option( 'failure_page' ) ) ) { | |
| 479 | + if (!empty($options)) { | |
| 480 | + update_option('give_settings', array_merge(give_get_settings(), $options), false); | |
| 481 | + } | |
| 445 | 482 | |
| 446 | - // Failed Donation Page | |
| 447 | - $failed = wp_insert_post( | |
| 448 | - array( | |
| 449 | - 'post_title' => esc_html__( 'Donation Failed', 'give' ), | |
| 450 | - 'post_content' => esc_html__( 'We\'re sorry, your donation failed to process. Please try again or contact site support.', 'give' ), | |
| 451 | - 'post_status' => 'publish', | |
| 452 | - 'post_author' => 1, | |
| 453 | - 'post_type' => 'page', | |
| 454 | - 'comment_status' => 'closed' | |
| 455 | - ) | |
| 456 | - ); | |
| 483 | + add_option('give_install_pages_created', 1, '', false); | |
| 484 | +} | |
| 457 | 485 | |
| 458 | - $options['failure_page'] = $failed; | |
| 459 | - } | |
| 486 | +// @TODO we can add this hook only when plugin activate instead of every admin page load. | |
| 487 | +// @see known issue https://github.com/impress-org/give/issues/1848 | |
| 488 | +add_action('admin_init', 'give_create_pages', -1); | |
| 460 | 489 | |
| 461 | - // Checks if the History Page option exists AND that the page exists. | |
| 462 | - if ( ! get_post( give_get_option( 'history_page' ) ) ) { | |
| 463 | - // Donation History Page | |
| 464 | - $history = wp_insert_post( | |
| 465 | - array( | |
| 466 | - 'post_title' => esc_html__( 'Donation History', 'give' ), | |
| 467 | - 'post_content' => '[donation_history]', | |
| 468 | - 'post_status' => 'publish', | |
| 469 | - 'post_author' => 1, | |
| 470 | - 'post_type' => 'page', | |
| 471 | - 'comment_status' => 'closed' | |
| 472 | - ) | |
| 473 | - ); | |
| 474 | 490 | |
| 475 | - $options['history_page'] = $history; | |
| 476 | - } | |
| 477 | - | |
| 478 | - if ( ! empty( $options ) ) { | |
| 479 | - update_option( 'give_settings', array_merge( give_get_settings(), $options ), false ); | |
| 480 | - } | |
| 481 | - | |
| 482 | - add_option( 'give_install_pages_created', 1, '', false ); | |
| 491 | +/** | |
| 492 | + * Install tables on plugin update if missing | |
| 493 | + * Note: only for internal use | |
| 494 | + * | |
| 495 | + * @since 2.4.1 | |
| 496 | + * | |
| 497 | + * @param string $old_version | |
| 498 | + */ | |
| 499 | +function give_install_tables_on_plugin_update($old_version) | |
| 500 | +{ | |
| 501 | + update_option('give_version_upgraded_from', $old_version, false); | |
| 502 | + __give_register_tables(); | |
| 483 | 503 | } |
| 484 | 504 | |
| 485 | -add_action( 'admin_init', 'give_create_pages', - 1 ); | |
| 505 | +add_action('update_option_give_version', 'give_install_tables_on_plugin_update', 0, 2); | |
| 486 | 506 | |
| 487 | 507 | |
| 488 | 508 | /** |
| 489 | 509 | * Get array of table class objects |
| @@ -490,25 +510,23 @@ | ||
| 490 | 510 | * |
| 491 | 511 | * Note: only for internal purpose use |
| 492 | 512 | * |
| 493 | 513 | * @sice 2.3.1 |
| 494 | - * | |
| 495 | 514 | */ |
| 496 | -function __give_get_tables() { | |
| 497 | - $tables = array( | |
| 498 | - 'donors_db' => new Give_DB_Donors(), | |
| 499 | - 'donor_meta_db' => new Give_DB_Donor_Meta(), | |
| 500 | - 'comment_db' => new Give_DB_Comments(), | |
| 501 | - 'comment_db_meta' => new Give_DB_Comment_Meta(), | |
| 502 | - 'give_session' => new Give_DB_Sessions(), | |
| 503 | - 'log_db' => new Give_DB_Logs(), | |
| 504 | - 'logmeta_db' => new Give_DB_Log_Meta(), | |
| 505 | - 'formmeta_db' => new Give_DB_Form_Meta(), | |
| 506 | - 'sequential_db' => new Give_DB_Sequential_Ordering(), | |
| 507 | - 'donation_meta' => new Give_DB_Payment_Meta(), | |
| 508 | - ); | |
| 515 | +function __give_get_tables() | |
| 516 | +{ | |
| 517 | + $tables = [ | |
| 518 | + 'donors_db' => new Give_DB_Donors(), | |
| 519 | + 'donor_meta_db' => new Give_DB_Donor_Meta(), | |
| 520 | + 'comment_db' => new Give_DB_Comments(), | |
| 521 | + 'comment_db_meta' => new Give_DB_Comment_Meta(), | |
| 522 | + 'give_session' => new Give_DB_Sessions(), | |
| 523 | + 'formmeta_db' => new Give_DB_Form_Meta(), | |
| 524 | + 'sequential_db' => new Give_DB_Sequential_Ordering(), | |
| 525 | + 'donation_meta' => new Give_DB_Payment_Meta(), | |
| 526 | + ]; | |
| 509 | 527 | |
| 510 | - return $tables; | |
| 528 | + return $tables; | |
| 511 | 529 | } |
| 512 | 530 | |
| 513 | 531 | /** |
| 514 | 532 | * Register classes |
| @@ -513,17 +531,21 @@ | ||
| 513 | 531 | /** |
| 514 | 532 | * Register classes |
| 515 | 533 | * Note: only for internal purpose use |
| 516 | 534 | * |
| 517 | - * @sice 2.3.1 | |
| 518 | - * | |
| 535 | + * @since 2.21.0 Install migration table on fresh install because this table is required to run migrations. | |
| 536 | + * @since 2.3.1 | |
| 537 | + * @throws DatabaseMigrationException | |
| 519 | 538 | */ |
| 520 | -function __give_register_tables() { | |
| 521 | - $tables = __give_get_tables(); | |
| 539 | +function __give_register_tables() | |
| 540 | +{ | |
| 541 | + $tables = __give_get_tables(); | |
| 522 | 542 | |
| 523 | - /* @var Give_DB $table */ | |
| 524 | - foreach ( $tables as $table ) { | |
| 525 | - if( ! $table->installed() ) { | |
| 526 | - $table->register_table(); | |
| 527 | - } | |
| 528 | - } | |
| 543 | + /* @var Give_DB $table */ | |
| 544 | + foreach ($tables as $table) { | |
| 545 | + if (!$table->installed()) { | |
| 546 | + $table->register_table(); | |
| 547 | + } | |
| 548 | + } | |
| 549 | + | |
| 550 | + give(CreateMigrationsTable::class)->run(); | |
| 529 | 551 | } |