LLMS_Helper_Upgrader::install_addon( string|obj $addon_or_id, string $action = 'install' )

Install an add-on from LifterLMS.com


Parameters Parameters

$addon_or_id

(string|obj) (Required) ID for the add-on or an instance of the LLMS_Add_On.

$action

(string) (Optional) Installation type [install|update].

Default value: 'install'


Top ↑

Return Return

(WP_Error|true)


Top ↑

Source Source

File: libraries/lifterlms-helper/includes/class-llms-helper-upgrader.php

			return;
		}
		foreach ( (array) $products['items'] as $product ) {
			if ( isset( $product['slug'] ) && $product['slug'] ) {
				$addon = llms_get_add_on( $product );

				if ( ! $addon->is_installable() || ! $addon->is_installed() ) {
					continue;
				}

				Lifterlms\Lifterlms_Helper\Required\Traduttore_Registry\add_project(
					$product['type'],
					$product['slug'],
					'https://translate.lifterlms.com/translate/api/translations/' . $product['slug']
				);
			}
		}
	}

	/**
	 * Install an add-on from LifterLMS.com
	 *
	 * @since 3.0.0
	 * @since 3.2.0 Use strict comparison for `in_array()`.
	 * @since 3.4.0 Use core textdomain.
	 *
	 * @param string|obj $addon_or_id ID for the add-on or an instance of the LLMS_Add_On.
	 * @param string     $action      Installation type [install|update].
	 * @return WP_Error|true
	 */
	public function install_addon( $addon_or_id, $action = 'install' ) {

		// Setup the addon.
		$addon = is_a( $addon_or_id, 'LLMS_Add_On' ) ? $addon_or_id : llms_get_add_on( $addon_or_id );
		if ( ! $addon ) {
			return new WP_Error( 'invalid_addon', __( 'Invalid add-on ID.', 'lifterlms' ) );
		}

		if ( ! in_array( $action, array( 'install', 'update' ), true ) ) {
			return new WP_Error( 'invalid_action', __( 'Invalid action.', 'lifterlms' ) );
		}

		if ( ! $addon->is_installable() ) {
			return new WP_Error( 'not_installable', __( 'Add-on cannot be installable.', 'lifterlms' ) );
		}

		// Make sure it's not already installed.
		if ( 'install' === $action && $addon->is_installed() ) {
			// Translators: %s = Add-on name.
			return new WP_Error( 'installed', sprintf( __( '%s is already installed', 'lifterlms' ), $addon->get( 'title' ) ) );
		}

		// Get download info via llms.com api.
		$dl_info = $addon->get_download_info();
		if ( is_wp_error( $dl_info ) ) {
			return $dl_info;
		}
		if ( ! isset( $dl_info['data']['url'] ) ) {
			return new WP_Error( 'no_url', __( 'An error occured while attempting to retrieve add-on download information. Please try again.', 'lifterlms' ) );
		}

		require_once ABSPATH . 'wp-admin/includes/file.php';
		include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
		WP_Filesystem();

		$skin = new Automatic_Upgrader_Skin();

		if ( 'plugin' === $addon->get_type() ) {

			$upgrader = new Plugin_Upgrader( $skin );

Top ↑

Changelog Changelog

Changelog
Version Description
3.4.0 Use core textdomain.
3.2.0 Use strict comparison for in_array().
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.