<?php

if ( !defined( 'ABSPATH' ) ) {
    die( 'No direct access allowed' );
}

// to debug
//set_site_transient('update_themes',null);

/**
 * Check for theme updates
 */
function leap_themeforest_theme_update( $updates ) {
    if ( isset( $updates->checked ) ) {
        require get_template_directory() . '/functions/update/classes/class-leap-themes-updater.php';
        $tf_username = ot_get_option( 'tf_username', '' );
        $tf_api      = ot_get_option( 'tf_api', '' );
        $tf_pc       = ot_get_option( 'tf_pc', '' );

        if ( !empty( $tf_username ) && !empty( $tf_api ) && !empty( $tf_pc ) ) {
            $updater = new Leap_Themes_Updater( $tf_username, $tf_api );
            $updates = $updater->check( $updates );
        }
    }
    return $updates;
}

add_filter( "pre_set_site_transient_update_themes", "leap_themeforest_theme_update" );
