Admin
1 week ago
Commands
2 years ago
Db
3 weeks ago
Ecommerce
1 week ago
Report
1 week ago
Site
1 week ago
TrackingCode
1 week ago
Updater
4 years ago
User
1 week ago
Workarounds
2 years ago
WpStatistics
1 week ago
views
1 week ago
AIBotTracking.php
1 week ago
API.php
3 weeks ago
Access.php
1 week ago
AjaxTracker.php
5 months ago
Annotations.php
1 week ago
Bootstrap.php
11 months ago
Capabilities.php
1 week ago
Compatibility.php
1 week ago
Email.php
1 week ago
ErrorNotice.php
1 week ago
Feature.php
3 months ago
Installer.php
1 week ago
Logger.php
1 year ago
MinimumRequirementsNotice.php
1 month ago
OptOut.php
2 months ago
Paths.php
1 week ago
PluginActionLinks.php
3 months ago
PluginAdminOverrides.php
1 week ago
PluginInit.php
1 week ago
PrivacyBadge.php
4 years ago
RedirectOnActivation.php
3 months ago
Referral.php
3 months ago
Roles.php
3 months ago
ScheduledTasks.php
1 week ago
Settings.php
1 week ago
Site.php
3 years ago
TrackingCode.php
1 week ago
Uninstaller.php
6 months ago
Updater.php
1 week ago
User.php
3 weeks ago
PluginInit.php
79 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 | } elseif ( matomo_is_app_request() ) { |
| 46 | // we can't install if matomo is requested... there's some circular reference |
| 47 | wp_safe_redirect( admin_url() ); |
| 48 | exit; |
| 49 | } elseif ( $installer->can_be_installed() ) { |
| 50 | $installer->install(); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // TODO: can this be moved out of here? try in a later release |
| 55 | $tracking_code = new TrackingCode( $this->settings ); |
| 56 | if ( $this->settings->is_tracking_enabled() |
| 57 | && $this->settings->get_global_option( 'track_ecommerce' ) |
| 58 | && ! $tracking_code->is_hidden_user() |
| 59 | ) { |
| 60 | $tracker = new AjaxTracker( $this->settings ); |
| 61 | |
| 62 | $sync_config = new SyncConfig( $this->settings ); |
| 63 | |
| 64 | if ( function_exists( 'WC' ) ) { |
| 65 | $woocommerce = new Woocommerce( $tracker, $this->settings, $sync_config ); |
| 66 | $woocommerce->register_hooks(); |
| 67 | } |
| 68 | |
| 69 | $easy_digital_downloads = new EasyDigitalDownloads( $tracker, $this->settings, $sync_config ); |
| 70 | $easy_digital_downloads->register_hooks(); |
| 71 | |
| 72 | $member_press = new MemberPress( $tracker, $this->settings, $sync_config ); |
| 73 | $member_press->register_hooks(); |
| 74 | |
| 75 | do_action( 'matomo_ecommerce_init', $tracker ); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 |