ap_activate_addon( string $addon_name )

Description #

Activate an addon and trigger addon activation hook.

Parameters #

  • $addon_name
    string (Required) Addon file name.

Changelog #

VersionDescription
4.1.8Introduced.

Source #

File: includes/functions.php

function ap_activate_addon( $addon_name ) {
	if ( ap_is_addon_active( $addon_name ) ) {
		return false;
	}

	global $ap_addons_activation;

	$opt        = get_option( 'anspress_addons', array() );
	$all_addons = ap_get_addons();
	$addon_name = wp_normalize_path( $addon_name );

	if ( isset( $all_addons[ $addon_name ] ) ) {
		$opt[ $addon_name ] = true;
		update_option( 'anspress_addons', $opt );

		$file = $all_addons[ $addon_name ]['path'];

		// Check file exists before requiring.
		if ( ! file_exists( $file ) ) {
			return false;
		}

		require_once $file;

		if ( isset( $ap_addons_activation[ $addon_name ] ) ) {
			call_user_func( $ap_addons_activation[ $addon_name ] );
		}

		do_action( 'ap_addon_activated', $addon_name );

		// Fix to drop wpengine cache.
		if ( class_exists( 'WpeCommon' ) ) {
			WpeCommon::purge_memcached();
			WpeCommon::clear_maxcdn_cache();
			WpeCommon::purge_varnish_cache();
		}

		// Delete cache.
		wp_cache_delete( 'addons', 'anspress' );

		// Flush rewrite rules.
		ap_opt( 'ap_flush', 'true' );

		return true;
	}

	return false;
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment