includes/class-freemius.php
private function _sync_addon_license( $addon_id, $background ) {
            $this->_logger->entrance();

            if ( $this->is_addon_activated( $addon_id ) ) {
                // If already installed, use add-on sync.
                $fs_addon = self::get_instance_by_id( $addon_id );
                $fs_addon->_sync_license( $background );

                return;
            }

            // Validate add-on exists.
            $addon = $this->get_addon( $addon_id );

            if ( ! is_object( $addon ) ) {
                return;
            }

            // Add add-on into account add-ons.
            $account_addons = $this->get_account_addons();
            if ( ! is_array( $account_addons ) ) {
                $account_addons = array();
            }
            $account_addons[] = $addon->id;
            $account_addons   = array_unique( $account_addons );
            $this->_store_account_addons( $account_addons );

            // Load add-on licenses.
            $licenses = $this->_fetch_licenses( $addon->id );

            // Sync add-on licenses.
            if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
                $this->_update_licenses( $licenses, $addon->id );

                if ( ! $this->is_addon_installed( $addon->id ) && FS_License_Manager::has_premium_license( $licenses ) ) {
                    $plans_result = $this->get_api_site_or_plugin_scope()->get( $this->add_show_pending( "/addons/{$addon_id}/plans.json" ) );

                    if ( ! isset( $plans_result->error ) ) {
                        $plans = array();
                        foreach ( $plans_result->plans as $plan ) {
                            $plans[] = new FS_Plugin_Plan( $plan );
                        }

                        $this->_admin_notices->add_sticky(
                            sprintf(
                                ( FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
                                    $this->get_text_inline( 'Your %s Add-on plan was successfully upgraded.', 'addon-successfully-upgraded-message' ) :
                                    /* translators: %s:product name, e.g. Facebook add-on was successfully... */
                                    $this->get_text_inline( '%s Add-on was successfully purchased.', 'addon-successfully-purchased-message' ) ),
                                $addon->title
                            ) . ' ' . $this->get_latest_download_link(
                                $this->get_text_inline( 'Download the latest version', 'download-latest-version' ),
                                $addon_id
                            ),
                            'addon_plan_upgraded_' . $addon->slug,
                            $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
                        );
                    }
                }
            }
        }
private function _sync_addon_license( $addon_id, $background ) {
            $this->_logger->entrance();

            if ( $this->is_addon_activated( $addon_id ) ) {
                // If already installed, use add-on sync.
                $fs_addon = self::get_instance_by_id( $addon_id );
                $fs_addon->_sync_license( $background );

                return;
            }

            // Validate add-on exists.
            $addon = $this->get_addon( $addon_id );

            if ( ! is_object( $addon ) ) {
                return;
            }

            // Add add-on into account add-ons.
            $account_addons = $this->get_account_addons();
            if ( ! is_array( $account_addons ) ) {
                $account_addons = array();
            }
            $account_addons[] = $addon->id;
            $account_addons   = array_unique( $account_addons );
            $this->_store_account_addons( $account_addons );

            // Load add-on licenses.
            $licenses = $this->_fetch_licenses( $addon->id );

            // Sync add-on licenses.
            if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
                $this->_update_licenses( $licenses, $addon->id );

                if ( ! $this->is_addon_installed( $addon->id ) && FS_License_Manager::has_premium_license( $licenses ) ) {
                    $plans_result = $this->get_api_site_or_plugin_scope()->get( $this->add_show_pending( "/addons/{$addon_id}/plans.json" ) );

                    if ( ! isset( $plans_result->error ) ) {
                        $plans = array();
                        foreach ( $plans_result->plans as $plan ) {
                            $plans[] = new FS_Plugin_Plan( $plan );
                        }

                        $this->_admin_notices->add_sticky(
                            sprintf(
                                ( FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
                                    $this->get_text_inline( 'Your %s Add-on plan was successfully upgraded.', 'addon-successfully-upgraded-message' ) :
                                    /* translators: %s:product name, e.g. Facebook add-on was successfully... */
                                    $this->get_text_inline( '%s Add-on was successfully purchased.', 'addon-successfully-purchased-message' ) ),
                                $addon->title
                            ) . ' ' . $this->get_latest_download_link(
                                $this->get_text_inline( 'Download the latest version', 'download-latest-version' ),
                                $addon_id
                            ),
                            'addon_plan_upgraded_' . $addon->slug,
                            $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
                        );
                    }
                }
            }
        }
private function _sync_addon_license ( $ addon_id , $ background ) { $ this -> _logger -> entrance ( ) ; if ( $ this -> is_addon_activated ( $ addon_id ) ) { // If already installed, use add-on sync.
 $ fs_addon = self :: get_instance_by_id ( $ addon_id ) ; $ fs_addon -> _sync_license ( $ background ) ; return ; } // Validate add-on exists.
 $ addon = $ this -> get_addon ( $ addon_id ) ; if ( ! is_object ( $ addon ) ) { return ; } // Add add-on into account add-ons.
 $ account_addons = $ this -> get_account_addons ( ) ; if ( ! is_array ( $ account_addons ) ) { $ account_addons = array ( ) ; } $ account_addons [ ] = $ addon -> id ; $ account_addons = array_unique ( $ account_addons ) ; $ this -> _store_account_addons ( $ account_addons ) ; // Load add-on licenses.
 $ licenses = $ this -> _fetch_licenses ( $ addon -> id ) ; // Sync add-on licenses.
 if ( $ this -> is_array_instanceof ( $ licenses , 'FS_Plugin_License' ) ) { $ this -> _update_licenses ( $ licenses , $ addon -> id ) ; if ( ! $ this -> is_addon_installed ( $ addon -> id ) && FS_License_Manager :: has_premium_license ( $ licenses ) ) { $ plans_result = $ this -> get_api_site_or_plugin_scope ( ) -> get ( $ this -> add_show_pending ( "/addons/{$addon_id}/plans.json" ) ) ; if ( ! isset ( $ plans_result -> error ) ) { $ plans = array ( ) ; foreach ( $ plans_result -> plans as $ plan ) { $ plans [ ] = new FS_Plugin_Plan ( $ plan ) ; } $ this -> _admin_notices -> add_sticky ( sprintf ( ( FS_Plan_Manager :: instance ( ) -> has_free_plan ( $ plans ) ? $ this -> get_text_inline ( 'Your %s Add-on plan was successfully upgraded.' , 'addon-successfully-upgraded-message' ) : /* translators: %s:product name, e.g. Facebook add-on was successfully... */ $ this -> get_text_inline ( '%s Add-on was successfully purchased.' , 'addon-successfully-purchased-message' ) ) , $ addon -> title ) . ' ' . $ this -> get_latest_download_link ( $ this -> get_text_inline ( 'Download the latest version' , 'download-latest-version' ) , $ addon_id ) , 'addon_plan_upgraded_' . $ addon -> slug , $ this -> get_text_x_inline ( 'Yee-haw' , 'interjection expressing joy or exuberance' , 'yee-haw' ) . '!' ) ; } } } }
Sync plugin's add-on license.

@author Vova Feldman (@svovaf)
@since  1.0.6
@uses   FS_Api

@param number $addon_id
@param bool   $background
Sync plugin s add - on license .