Admin
1 month ago
Commands
2 years ago
Db
1 year ago
Ecommerce
1 month ago
Report
2 months ago
Site
2 months ago
TrackingCode
4 months ago
Updater
4 years ago
User
2 months ago
Workarounds
2 years ago
WpStatistics
5 months ago
views
1 month ago
AIBotTracking.php
4 months ago
API.php
2 months ago
Access.php
4 years ago
AjaxTracker.php
4 months ago
Annotations.php
2 months ago
Bootstrap.php
10 months ago
Capabilities.php
2 months ago
Compatibility.php
2 months ago
Email.php
2 years ago
ErrorNotice.php
1 month ago
Feature.php
2 months ago
Installer.php
1 month ago
Logger.php
1 year ago
OptOut.php
1 month ago
Paths.php
5 months ago
PluginActionLinks.php
2 months ago
PluginAdminOverrides.php
2 months ago
PluginInit.php
2 months ago
PrivacyBadge.php
4 years ago
RedirectOnActivation.php
2 months ago
Referral.php
2 months ago
Roles.php
2 months ago
ScheduledTasks.php
2 months ago
Settings.php
4 months ago
Site.php
3 years ago
TrackingCode.php
2 months ago
Uninstaller.php
5 months ago
Updater.php
10 months ago
User.php
4 years ago
PluginInit.php
83 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Matomo - free/libre analytics platform |
| 4 | * |
| 5 | * @link https://matomo.org |
| 6 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 7 | * @package matomo |
| 8 | */ |
| 9 | |
| 10 | namespace WpMatomo; |
| 11 | |
| 12 | use WpMatomo\Ecommerce\EasyDigitalDownloads; |
| 13 | use WpMatomo\Ecommerce\MemberPress; |
| 14 | use WpMatomo\Ecommerce\Woocommerce; |
| 15 | use WpMatomo\Site\Sync\SyncConfig; |
| 16 | |
| 17 | if ( ! defined( 'ABSPATH' ) ) { |
| 18 | exit; // if accessed directly |
| 19 | } |
| 20 | |
| 21 | class PluginInit extends Feature { |
| 22 | |
| 23 | /** |
| 24 | * @var Settings |
| 25 | */ |
| 26 | private $settings; |
| 27 | |
| 28 | public function __construct( Settings $settings ) { |
| 29 | $this->settings = $settings; |
| 30 | } |
| 31 | |
| 32 | public function register_hooks() { |
| 33 | add_action( 'init', [ $this, 'init_plugin' ] ); |
| 34 | } |
| 35 | |
| 36 | public function init_plugin() { |
| 37 | if ( ( is_admin() || matomo_is_app_request() ) && ! wp_doing_ajax() ) { |
| 38 | $installer = new Installer( $this->settings ); |
| 39 | $installer->register_hooks(); |
| 40 | if ( $installer->looks_like_it_is_installed() ) { |
| 41 | if ( is_admin() && ( ! defined( 'MATOMO_ENABLE_AUTO_UPGRADE' ) || MATOMO_ENABLE_AUTO_UPGRADE ) ) { |
| 42 | $updater = new Updater( $this->settings ); |
| 43 | $updater->update_if_needed(); |
| 44 | } |
| 45 | } else { |
| 46 | if ( matomo_is_app_request() ) { |
| 47 | // we can't install if matomo is requested... there's some circular reference |
| 48 | wp_safe_redirect( admin_url() ); |
| 49 | exit; |
| 50 | } else { |
| 51 | if ( $installer->can_be_installed() ) { |
| 52 | $installer->install(); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // TODO: can this be moved out of here? try in a later release |
| 59 | $tracking_code = new TrackingCode( $this->settings ); |
| 60 | if ( $this->settings->is_tracking_enabled() |
| 61 | && $this->settings->get_global_option( 'track_ecommerce' ) |
| 62 | && ! $tracking_code->is_hidden_user() |
| 63 | ) { |
| 64 | $tracker = new AjaxTracker( $this->settings ); |
| 65 | |
| 66 | $sync_config = new SyncConfig( $this->settings ); |
| 67 | |
| 68 | if ( function_exists( 'WC' ) ) { |
| 69 | $woocommerce = new Woocommerce( $tracker, $this->settings, $sync_config ); |
| 70 | $woocommerce->register_hooks(); |
| 71 | } |
| 72 | |
| 73 | $easy_digital_downloads = new EasyDigitalDownloads( $tracker, $this->settings, $sync_config ); |
| 74 | $easy_digital_downloads->register_hooks(); |
| 75 | |
| 76 | $member_press = new MemberPress( $tracker, $this->settings, $sync_config ); |
| 77 | $member_press->register_hooks(); |
| 78 | |
| 79 | do_action( 'matomo_ecommerce_init', $tracker ); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 |