/**
  * Outputs the content of the widget
  * 
  * Handles to show output of widget 
  * at front side sidebar
  * 
  * @package Easy Digital Downloads - Social Login
  * @since 1.1.0
  * 
  */
 function widget($args, $instance)
 {
     global $wpdb, $post, $edd_options;
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     if (!is_user_logged_in() && edd_slg_check_social_enable()) {
         echo $before_widget;
         // get redirect url from settings
         $defaulturl = isset($edd_options['edd_slg_redirect_url']) && !empty($edd_options['edd_slg_redirect_url']) ? $edd_options['edd_slg_redirect_url'] : edd_slg_get_current_page_url();
         //session create for redirect url
         EDD()->session->set('edd_slg_stcd_redirect_url_widget', $defaulturl);
         echo '<div class="edd-slg-social-container edd-slg-widget-content">';
         echo $before_title . $title . $after_title;
         $this->render->edd_slg_social_login_inner_buttons();
         //end container
         echo '</div><!--.edd-slg-widget-content-->';
         echo $after_widget;
     }
 }
 /**
  * Show All Social Login Buttons
  * 
  * Handles to show all social login buttons on the viewing page
  * whereever user put shortcode
  * 
  * @package Easy Digital Downloads - Social Login
  * @since 1.1.0
  */
 public function edd_slg_social_login($atts, $content)
 {
     global $edd_options, $post;
     extract(shortcode_atts(array('title' => '', 'redirect_url' => '', 'showonpage' => false), $atts));
     $showbuttons = true;
     // if show only on inners pages is set and current page is not inner page
     if (!empty($showonpage) && !is_singular()) {
         $showbuttons = false;
     }
     //check show social buttons or not
     if ($showbuttons) {
         //check user is logged in to site or not and any single social login button is enable or not
         if (!is_user_logged_in() && edd_slg_check_social_enable()) {
             // login heading from setting page
             $login_heading = isset($edd_options['edd_slg_login_heading']) ? $edd_options['edd_slg_login_heading'] : '';
             //  check title first from shortcode
             $login_heading = !empty($title) ? $title : $login_heading;
             // get redirect url from settings
             $defaulturl = isset($edd_options['edd_slg_redirect_url']) && !empty($edd_options['edd_slg_redirect_url']) ? $edd_options['edd_slg_redirect_url'] : edd_slg_get_current_page_url();
             //redirect url for shortcode
             $defaulturl = isset($redirect_url) && !empty($redirect_url) ? $redirect_url : $defaulturl;
             //session create for access token & secrets
             EDD()->session->set('edd_slg_stcd_redirect_url', $defaulturl);
             // get html for all social login buttons
             ob_start();
             echo '<fieldset id="edd_slg_social_login" class="edd-slg-social-container">';
             if (!empty($login_heading)) {
                 echo '<span><legend>' . $login_heading . '</legend></span>';
             }
             $this->render->edd_slg_social_login_inner_buttons($redirect_url);
             echo '</fieldset><!--#edd_slg_social_login-->';
             $content .= ob_get_clean();
         }
     }
     return $content;
 }
 /**
  * Add Social Login Buttons To 
  * Checkout page
  * 
  * Handles to add all social media login
  * buttons to edd checkout page
  * 
  * @package Easy Digital Downloads - Social Login
  * @since 1.0.0
  */
 public function edd_slg_social_login_buttons($title = '', $redirect_url = '')
 {
     global $edd_options, $post;
     //check user is logged in to site or not and any single social login button is enable or not
     if (!is_user_logged_in() && edd_slg_check_social_enable()) {
         // get title from settings
         $login_heading = isset($edd_options['edd_slg_login_heading']) ? $edd_options['edd_slg_login_heading'] : '';
         /*// get redirect url from settings 
         		$defaulturl = isset( $edd_options['edd_slg_redirect_url'] ) && !empty( $edd_options['edd_slg_redirect_url'] ) 
         							? $edd_options['edd_slg_redirect_url'] : edd_slg_get_current_page_url();*/
         $defaulturl = get_permalink($post->ID);
         //session create for redirect url
         EDD()->session->set('edd_slg_stcd_redirect_url', $defaulturl);
         echo '<fieldset id="edd_slg_social_login" class="edd-slg-social-container">';
         if (!empty($login_heading)) {
             echo '<span><legend>' . $login_heading . '</legend></span>';
         }
         $redirect_url = get_permalink($post->ID);
         $this->edd_slg_social_login_inner_buttons($redirect_url);
         echo '</fieldset><!--#edd_slg_social_login-->';
     }
 }
 /**
  * Adding Hooks
  *
  * Adding proper hoocks for the public pages.
  *
  * @package Easy Digital Downloads - Social Login
  * @since 1.0.0
  */
 public function add_hooks()
 {
     global $edd_options;
     //check is there any social media is enable or not
     if (edd_slg_check_social_enable()) {
         $edd_social_order = get_option('edd_social_order');
         //Initializes Google Plus API
         add_action('init', array($this->socialgoogle, 'edd_slg_initialize_google'));
         // add action for linkedin login
         add_action('init', array($this->sociallinkedin, 'edd_slg_initialize_linkedin'));
         // add action for twitter login
         add_action('init', array($this->socialtwitter, 'edd_slg_initialize_twitter'));
         // add action for yahoo login
         add_action('init', array($this->socialyahoo, 'edd_slg_initialize_yahoo'));
         // add action for foursquare login
         add_action('init', array($this->socialfoursquare, 'edd_slg_initialize_foursquare'));
         //add action for windows live login
         add_action('init', array($this->socialwindowslive, 'edd_slg_initialize_windowslive'));
         // add action for vk login
         add_action('init', array($this->socialvk, 'edd_slg_initialize_vk'));
         // add action for instagram login
         add_action('init', array($this->socialinstagram, 'edd_slg_initialize_instagram'));
         //add action to add social login button to before payment gateways
         add_action('edd_checkout_form_top', array($this->render, 'edd_slg_social_login_buttons'));
         // render login buttons on the myaccount page
         add_action('edd_profile_editor_before', array($this->render, 'edd_slg_myaccount_social_login_buttons'));
         // optional link buttons on thank you page
         add_action('edd_payment_receipt_after_table', array($this->render, 'edd_slg_maybe_render_social_link_buttons'));
         //add action to load login page
         add_action('login_init', array($this, 'edd_slg_social_login_redirect'));
         if (!empty($edd_social_order)) {
             $priority = 5;
             foreach ($edd_social_order as $social) {
                 add_action('edd_slg_checkout_social_login', array($this->render, 'edd_slg_login_' . $social), $priority);
                 $priority += 5;
             }
         }
     }
     // Filter to change the avatar image
     add_filter('get_avatar', array($this, 'edd_slg_get_avatar'), 10, 5);
     //AJAX Call to Login Via Social Media
     add_action('wp_ajax_edd_slg_social_login', array($this, 'edd_slg_social_login'));
     add_action('wp_ajax_nopriv_edd_slg_social_login', array($this, 'edd_slg_social_login'));
     //AJAX Call to unlink Via Social Media
     add_action('wp_ajax_edd_slg_social_unlink_profile', array($this, 'edd_slg_social_unlink_profile'));
     add_action('wp_ajax_nopriv_edd_slg_social_unlink_profile', array($this, 'edd_slg_social_unlink_profile'));
     if (isset($edd_options['edd_slg_enable_login_page']) && !empty($edd_options['edd_slg_enable_login_page'])) {
         //add social login buttons on wordpress login page
         add_action('login_footer', array($this->render, 'edd_slg_social_login_buttons_on_login'));
         //add action to add social login button on edd login page
         add_action('edd_login_fields_after', array($this->render, 'edd_slg_social_login_buttons'));
     }
 }
/**
 * Template Hooks
 * 
 * Handles to add all hooks of template
 * 
 * @package Easy Digital Downloads - Social Login
 * @since 1.4.1
 */
if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
global $edd_slg_render;
$user_id = get_current_user_id();
$render = $edd_slg_render;
//add action to load social button facebook, twitter, googleplus, linkedin
add_action('edd_slg_checkout_wrapper_social_login', array($render, 'edd_slg_checkout_wrapper_social_login_content'), 10);
//check is there any social media is enable or not
if (edd_slg_check_social_enable()) {
    $edd_social_order = get_option('edd_social_order');
    if (!empty($edd_social_order)) {
        $priority = 5;
        foreach ($edd_social_order as $social) {
            if (!empty($social)) {
                add_action('edd_slg_checkout_social_login', array($render, 'edd_slg_login_' . $social), $priority);
                add_action('edd_slg_checkout_social_login_link', array($render, 'edd_slg_login_link_' . $social), $priority);
                $priority += 5;
            }
        }
    }
}
 /**
  * Social Link button on thankyou page
  * 
  * Handles to display social link buttons on thankyou page
  * 
  * @package WooCommerce - Social Login
  * @since 1.5.6
  */
 public function edd_slg_maybe_render_social_link_buttons()
 {
     global $post;
     if (is_user_logged_in() && has_shortcode($post->post_content, 'edd_receipt') && edd_slg_check_social_enable() && edd_slg_link_display_on_thankyou_page()) {
         //display link buttons
         edd_slg_link_buttons();
     }
 }
 /**
  * Adding Hooks
  *
  * Adding proper hoocks for the public pages.
  *
  * @package Easy Digital Downloads - Social Login
  * @since 1.0.0
  */
 public function add_hooks()
 {
     //check is there any social media is enable or not
     if (edd_slg_check_social_enable()) {
         $edd_social_order = get_option('edd_social_order');
         //Initializes Google Plus API
         add_action('init', array($this->socialgoogle, 'edd_slg_initialize_google'));
         // add action for linkedin login
         add_action('init', array($this->sociallinkedin, 'edd_slg_initialize_linkedin'));
         // add action for twitter login
         add_action('init', array($this->socialtwitter, 'edd_slg_initialize_twitter'));
         // add action for yahoo login
         add_action('init', array($this->socialyahoo, 'edd_slg_initialize_yahoo'));
         // add action for foursquare login
         add_action('init', array($this->socialfoursquare, 'edd_slg_initialize_foursquare'));
         //add action for windows live login
         add_action('init', array($this->socialwindowslive, 'edd_slg_initialize_windowslive'));
         //add action to add social login button to before payment gateways
         add_action('edd_checkout_form_top', array($this->render, 'edd_slg_social_login_buttons'));
         //add action to load login page
         add_action('login_init', array($this, 'edd_slg_social_login_redirect'));
         if (!empty($edd_social_order)) {
             $priority = 5;
             foreach ($edd_social_order as $social) {
                 add_action('edd_slg_checkout_social_login', array($this->render, 'edd_slg_login_' . $social), $priority);
                 $priority += 5;
             }
         }
     }
     //AJAX Call to Login Via Social Media
     add_action('wp_ajax_edd_slg_social_login', array($this, 'edd_slg_social_login'));
     add_action('wp_ajax_nopriv_edd_slg_social_login', array($this, 'edd_slg_social_login'));
 }