Tribe__Events__Integrations__Freemius::setup()

Performs setup for the Freemius integration singleton.


Source #

File: src/Tribe/Integrations/Freemius.php

	public function setup() {
		if ( ! is_admin() ) {
			return;
		}
		// Setup possible redirect.
		add_action( 'wp_loaded', [ $this, 'action_redirect_incorrect_page' ] );

		global $pagenow;

		$page = tribe_get_request_var( 'page' );

		$valid_page = [
			Tribe__Settings::$parent_slug          => true,
			Tribe__App_Shop::MENU_SLUG             => true,
			Tribe__Events__Aggregator__Page::$slug => true,
			'tribe-help'                           => true,
		];

		if ( isset( $valid_page[ $page ] ) ) {
			$this->page = $page;
		} elseif ( 'plugins.php' !== $pagenow && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
			return;
		}

		// If the common that loaded doesn't include Freemius, let's bail.
		if ( ! tribe()->offsetExists( 'freemius' ) ) {
			return;
		}

		$should_load = true;

		// Check if Freemius integration is disabled.
		if ( ( defined( 'TRIBE_NO_FREEMIUS' ) && true === TRIBE_NO_FREEMIUS ) || true === (bool) getenv( 'TRIBE_NO_FREEMIUS' ) ) {
			$should_load = false;
		}

		/**
		 * Allows third-party disabling of the integration.
		 *
		 * @since  4.9
		 *
		 * @param bool $should_load Whether the Freemius integration should load.
		 */
		$should_load = apply_filters( 'tribe_events_integrations_should_load_freemius', $should_load );

		if ( ! $should_load ) {
			return;
		}

		/** @var Tribe__Freemius $freemius */
		$freemius = tribe( 'freemius' );

		$this->instance = $freemius->initialize( $this->slug, $this->freemius_id, $this->public_key, [
			'menu'           => [
				'slug'       => $this->page,
				'first-path' => $this->get_settings_path(),
				'account'    => false,
				'contact'    => false,
				'support'    => false,
			],
			'is_premium'     => false,
			'has_addons'     => false,
			'has_paid_plans' => false,
		] );

		$this->instance->add_filter( 'connect_url', [ $this, 'get_connect_url' ], 10, 10 );
		$this->instance->add_filter( 'after_skip_url', [ $this, 'get_settings_url' ] );
		$this->instance->add_filter( 'after_connect_url', [ $this, 'get_settings_url' ] );
		$this->instance->add_filter( 'after_pending_connect_url', [ $this, 'get_settings_url' ] );
		$this->instance->add_filter( 'plugin_icon', [ $this, 'get_plugin_icon_url' ] );

		/*
		 * Freemius typically hooks this action–which bootstraps the deactivation dialog–during plugins_loaded, but we
		 * initialize our plugins AFTER plugins_loaded, so we'll register it on admin_init instead.
		 */
		add_action( 'admin_init', [ $this->instance, '_hook_action_links_and_register_account_hooks' ] );
		add_action( 'admin_init', [ $this, 'action_skip_activation' ] );

		$this->instance->add_filter( 'connect_message', [
			$this,
			'filter_connect_message_on_update',
		], 10, 6 );
		$this->instance->add_filter( 'connect_message_on_update', [
			$this,
			'filter_connect_message_on_update',
		], 10, 6 );

		add_action( 'admin_init', [ $this, 'maybe_remove_activation_complete_notice' ] );
	}

Top ↑

Changelog #

Changelog
Version Description
5.0.2 Introduced.