includes/class-freemius.php
function _install_premium_version_ajax_action() {
            $this->_logger->entrance();

            $this->check_ajax_referer( 'install_premium_version' );

            if ( ! $this->is_registered() ) {
                // Not registered.
                self::shoot_ajax_failure( array(
                    'message' => $this->get_text_inline( 'Auto installation only works for opted-in users.', 'auto-install-error-not-opted-in' ),
                    'code'    => 'premium_installed',
                ) );
            }

            $plugin_id = fs_request_get( 'target_module_id', $this->get_id() );

            if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
                // Invalid ID.
                self::shoot_ajax_failure( array(
                    'message' => $this->get_text_inline( 'Invalid module ID.', 'auto-install-error-invalid-id' ),
                    'code'    => 'invalid_module_id',
                ) );
            }

            if ( $plugin_id == $this->get_id() ) {
                if ( $this->is_premium() ) {
                    // Already using the premium code version.
                    self::shoot_ajax_failure( array(
                        'message' => $this->get_text_inline( 'Premium version already active.', 'auto-install-error-premium-activated' ),
                        'code'    => 'premium_installed',
                    ) );
                }
                if ( ! $this->can_use_premium_code() ) {
                    // Don't have access to the premium code.
                    self::shoot_ajax_failure( array(
                        'message' => $this->get_text_inline( 'You do not have a valid license to access the premium version.', 'auto-install-error-invalid-license' ),
                        'code'    => 'invalid_license',
                    ) );
                }
                if ( ! $this->has_release_on_freemius() ) {
                    // Plugin is a serviceware, no premium code version.
                    self::shoot_ajax_failure( array(
                        'message' => $this->get_text_inline( 'Plugin is a "Serviceware" which means it does not have a premium code version.', 'auto-install-error-serviceware' ),
                        'code'    => 'premium_version_missing',
                    ) );
                }
            } else {
                $addon = $this->get_addon( $plugin_id );

                if ( ! is_object( $addon ) ) {
                    // Invalid add-on ID.
                    self::shoot_ajax_failure( array(
                        'message' => $this->get_text_inline( 'Invalid module ID.', 'auto-install-error-invalid-id' ),
                        'code'    => 'invalid_module_id',
                    ) );
                }

                if ( $this->is_addon_activated( $plugin_id, true ) ) {
                    // Premium add-on version is already activated.
                    self::shoot_ajax_failure( array(
                        'message' => $this->get_text_inline( 'Premium add-on version already installed.', 'auto-install-error-premium-addon-activated' ),
                        'code'    => 'premium_installed',
                    ) );
                }
            }

            $this->_isAutoInstall = true;

            // Try to install and activate.
            $updater = FS_Plugin_Updater::instance( $this );
            $result  = $updater->install_and_activate_plugin( $plugin_id );

            if ( is_array( $result ) && ! empty( $result['message'] ) ) {
                self::shoot_ajax_failure( array(
                    'message' => $result['message'],
                    'code'    => $result['code'],
                ) );
            }

            self::shoot_ajax_success( $result );
        }
function _install_premium_version_ajax_action() {
            $this->_logger->entrance();

            $this->check_ajax_referer( 'install_premium_version' );

            if ( ! $this->is_registered() ) {
                // Not registered.
                self::shoot_ajax_failure( array(
                    'message' => $this->get_text_inline( 'Auto installation only works for opted-in users.', 'auto-install-error-not-opted-in' ),
                    'code'    => 'premium_installed',
                ) );
            }

            $plugin_id = fs_request_get( 'target_module_id', $this->get_id() );

            if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
                // Invalid ID.
                self::shoot_ajax_failure( array(
                    'message' => $this->get_text_inline( 'Invalid module ID.', 'auto-install-error-invalid-id' ),
                    'code'    => 'invalid_module_id',
                ) );
            }

            if ( $plugin_id == $this->get_id() ) {
                if ( $this->is_premium() ) {
                    // Already using the premium code version.
                    self::shoot_ajax_failure( array(
                        'message' => $this->get_text_inline( 'Premium version already active.', 'auto-install-error-premium-activated' ),
                        'code'    => 'premium_installed',
                    ) );
                }
                if ( ! $this->can_use_premium_code() ) {
                    // Don't have access to the premium code.
                    self::shoot_ajax_failure( array(
                        'message' => $this->get_text_inline( 'You do not have a valid license to access the premium version.', 'auto-install-error-invalid-license' ),
                        'code'    => 'invalid_license',
                    ) );
                }
                if ( ! $this->has_release_on_freemius() ) {
                    // Plugin is a serviceware, no premium code version.
                    self::shoot_ajax_failure( array(
                        'message' => $this->get_text_inline( 'Plugin is a "Serviceware" which means it does not have a premium code version.', 'auto-install-error-serviceware' ),
                        'code'    => 'premium_version_missing',
                    ) );
                }
            } else {
                $addon = $this->get_addon( $plugin_id );

                if ( ! is_object( $addon ) ) {
                    // Invalid add-on ID.
                    self::shoot_ajax_failure( array(
                        'message' => $this->get_text_inline( 'Invalid module ID.', 'auto-install-error-invalid-id' ),
                        'code'    => 'invalid_module_id',
                    ) );
                }

                if ( $this->is_addon_activated( $plugin_id, true ) ) {
                    // Premium add-on version is already activated.
                    self::shoot_ajax_failure( array(
                        'message' => $this->get_text_inline( 'Premium add-on version already installed.', 'auto-install-error-premium-addon-activated' ),
                        'code'    => 'premium_installed',
                    ) );
                }
            }

            $this->_isAutoInstall = true;

            // Try to install and activate.
            $updater = FS_Plugin_Updater::instance( $this );
            $result  = $updater->install_and_activate_plugin( $plugin_id );

            if ( is_array( $result ) && ! empty( $result['message'] ) ) {
                self::shoot_ajax_failure( array(
                    'message' => $result['message'],
                    'code'    => $result['code'],
                ) );
            }

            self::shoot_ajax_success( $result );
        }
function _install_premium_version_ajax_action ( ) { $ this -> _logger -> entrance ( ) ; $ this -> check_ajax_referer ( 'install_premium_version' ) ; if ( ! $ this -> is_registered ( ) ) { // Not registered.
 self :: shoot_ajax_failure ( array ( 'message' => $ this -> get_text_inline ( 'Auto installation only works for opted-in users.' , 'auto-install-error-not-opted-in' ) , 'code' => 'premium_installed' , ) ) ; } $ plugin_id = fs_request_get ( 'target_module_id' , $ this -> get_id ( ) ) ; if ( ! FS_Plugin :: is_valid_id ( $ plugin_id ) ) { // Invalid ID.
 self :: shoot_ajax_failure ( array ( 'message' => $ this -> get_text_inline ( 'Invalid module ID.' , 'auto-install-error-invalid-id' ) , 'code' => 'invalid_module_id' , ) ) ; } if ( $ plugin_id == $ this -> get_id ( ) ) { if ( $ this -> is_premium ( ) ) { // Already using the premium code version.
 self :: shoot_ajax_failure ( array ( 'message' => $ this -> get_text_inline ( 'Premium version already active.' , 'auto-install-error-premium-activated' ) , 'code' => 'premium_installed' , ) ) ; } if ( ! $ this -> can_use_premium_code ( ) ) { // Don't have access to the premium code.
 self :: shoot_ajax_failure ( array ( 'message' => $ this -> get_text_inline ( 'You do not have a valid license to access the premium version.' , 'auto-install-error-invalid-license' ) , 'code' => 'invalid_license' , ) ) ; } if ( ! $ this -> has_release_on_freemius ( ) ) { // Plugin is a serviceware, no premium code version.
 self :: shoot_ajax_failure ( array ( 'message' => $ this -> get_text_inline ( 'Plugin is a "Serviceware" which means it does not have a premium code version.' , 'auto-install-error-serviceware' ) , 'code' => 'premium_version_missing' , ) ) ; } } else { $ addon = $ this -> get_addon ( $ plugin_id ) ; if ( ! is_object ( $ addon ) ) { // Invalid add-on ID.
 self :: shoot_ajax_failure ( array ( 'message' => $ this -> get_text_inline ( 'Invalid module ID.' , 'auto-install-error-invalid-id' ) , 'code' => 'invalid_module_id' , ) ) ; } if ( $ this -> is_addon_activated ( $ plugin_id , true ) ) { // Premium add-on version is already activated.
 self :: shoot_ajax_failure ( array ( 'message' => $ this -> get_text_inline ( 'Premium add-on version already installed.' , 'auto-install-error-premium-addon-activated' ) , 'code' => 'premium_installed' , ) ) ; } } $ this -> _isAutoInstall = true ; // Try to install and activate.
 $ updater = FS_Plugin_Updater :: instance ( $ this ) ; $ result = $ updater -> install_and_activate_plugin ( $ plugin_id ) ; if ( is_array ( $ result ) && ! empty ( $ result [ 'message' ] ) ) { self :: shoot_ajax_failure ( array ( 'message' => $ result [ 'message' ] , 'code' => $ result [ 'code' ] , ) ) ; } self :: shoot_ajax_success ( $ result ) ; }
After upgrade callback to install and auto activate a plugin.
This code will only be executed on explicit request from the user,
following the practice Jetpack are using with their theme installations.

@link   https://make.wordpress.org/plugins/2017/03/16/clarification-of-guideline-8-executable-code-and-installs/

@author Vova Feldman (@svovaf)
@since  1.2.1.7
After upgrade callback to install and auto activate a plugin . This code will only be executed on explicit request from the user following the practice Jetpack are using with their theme installations .