| 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.6.42 |
| 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 |
|
| 51 |
set_transient( 'charitable_install', 1, 0 ); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Finish the plugin installation. |
| 56 |
* |
| 57 |
* @since 1.3.4 |
| 58 |
* |
| 59 |
* @return void |
| 60 |
*/ |
| 61 |
public static function finish_installing() { |
| 62 |
Charitable_Cron::schedule_events(); |
| 63 |
|
| 64 |
add_action( 'init', 'flush_rewrite_rules' ); |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Create wp roles and assign capabilities |
| 69 |
* |
| 70 |
* @since 1.0.0 |
| 71 |
* |
| 72 |
* @return void |
| 73 |
*/ |
| 74 |
protected function setup_roles() { |
| 75 |
require_once( $this->includes_path . '/users/class-charitable-roles.php' ); |
| 76 |
$roles = new Charitable_Roles(); |
| 77 |
$roles->add_roles(); |
| 78 |
$roles->add_caps(); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Create database tables. |
| 83 |
* |
| 84 |
* @since 1.0.0 |
| 85 |
* |
| 86 |
* @return void |
| 87 |
*/ |
| 88 |
protected function create_tables() { |
| 89 |
require_once( $this->includes_path . 'abstracts/abstract-class-charitable-db.php' ); |
| 90 |
|
| 91 |
$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', |
| 95 |
); |
| 96 |
|
| 97 |
foreach ( $tables as $file => $class ) { |
| 98 |
require_once( $file ); |
| 99 |
$table = new $class; |
| 100 |
$table->create_table(); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Set up the upgrade log. |
| 106 |
* |
| 107 |
* @since 1.3.0 |
| 108 |
* |
| 109 |
* @return void |
| 110 |
*/ |
| 111 |
protected function setup_upgrade_log() { |
| 112 |
require_once( $this->includes_path . '/admin/upgrades/class-charitable-upgrade.php' ); |
| 113 |
Charitable_Upgrade::get_instance()->populate_upgrade_log_on_install(); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
endif; |
| 118 |
|