コード例 #1
0
 /**
  * Loads Checkout Social Login Buttons Template
  * 
  * Handles to load checkout social login buttons
  * template
  * 
  * @package Social Deals Engine
  * @since 1.0.0
  */
 function wps_deals_cart_social_login()
 {
     global $wps_deals_options, $wps_deals_session;
     //check user is not logged in and social login is enable or not for any one service
     if (!is_user_logged_in() && wps_deals_enable_social_login()) {
         // get redirect url from settings
         $defaulturl = isset($wps_deals_options['login_redirect_url']) && !empty($wps_deals_options['login_redirect_url']) ? $wps_deals_options['login_redirect_url'] : wps_deals_get_current_page_url();
         //redirect url for shortcode
         $defaulturl = isset($redirect_url) && !empty($redirect_url) ? $redirect_url : $defaulturl;
         //session create for redirect url
         $wps_deals_session->set('wps_deals_stcd_redirect_url', $defaulturl);
         // get title from settings
         $login_heading = isset($wps_deals_options['login_heading']) ? $wps_deals_options['login_heading'] : __('Login with Social Media', 'wpsdeals');
         // get redirect url from settings
         $login_redirect_url = isset($wps_deals_options['login_redirect_url']) ? $wps_deals_options['login_redirect_url'] : '';
         //load social login buttons template
         wps_deals_get_template('checkout/content/social.php', array('title' => $login_heading, 'login_redirect_url' => $login_redirect_url));
         //enqueue social front script
         wp_enqueue_script('wps-deals-social-front-scripts');
     }
 }
コード例 #2
0
    /**
     * Load Login Page For Social
     * 
     * Handles to load login page for social
     * when no email address found
     * 
     * @package Social Deals Engine
     * @since 1.0.0
     */
    public function wps_deals_social_login_redirect()
    {
        global $wps_deals_options;
        $socialtype = isset($_GET['dealsnetwork']) ? $_GET['dealsnetwork'] : '';
        //get all social networks
        $allsocialtypes = wps_deals_social_networks();
        if (!is_user_logged_in() && isset($_GET['wps_deals_social_login']) && !empty($socialtype) && array_key_exists($socialtype, $allsocialtypes)) {
            //check if session is set and !empty then it will take get_permalink url
            $redirect_url = $this->session->get('wps_deals_stcd_redirect_url');
            $redirect_url = !empty($redirect_url) ? $redirect_url : wps_deals_get_current_page_url();
            //get cart details
            $cartdetails = $this->cart->get();
            $data = array();
            //wordpress error class
            $errors = new WP_Error();
            switch ($socialtype) {
                case 'twitter':
                    //get twitter user data
                    $tw_userdata = $this->twitter->wps_deals_social_get_twitter_user_data();
                    //check user id is set or not for twitter
                    if (!empty($tw_userdata) && isset($tw_userdata->id) && !empty($tw_userdata->id)) {
                        $data['first_name'] = $tw_userdata->name;
                        $data['last_name'] = '';
                        $data['name'] = $tw_userdata->screen_name;
                        //display name of user
                        $data['type'] = 'twitter';
                        $data['all'] = $tw_userdata;
                        $data['link'] = 'https://twitter.com/' . $tw_userdata->screen_name;
                        $data['id'] = $tw_userdata->id;
                    }
                    break;
            }
            //if cart is empty or user is not logged in social media
            //and accessing the url then send back user to checkout page
            if (!isset($data['id']) || empty($data['id'])) {
                $redirect_url = $this->session->get('wps_deals_stcd_redirect_url');
                if (!empty($redirect_url)) {
                    $this->session->remove('wps_deals_stcd_redirect_url');
                }
                wp_redirect($redirect_url);
                exit;
                //send user to checkout page
                //wps_deals_send_on_checkout_page();
            }
            //when user will click submit button of custom login
            //check user clicks submit button of registration page and get parameter should be valid param
            if (isset($_POST['wps-deals-submit']) && !empty($_POST['wps-deals-submit']) && $_POST['wps-deals-submit'] == __('Register', 'wpsdeals')) {
                $loginurl = wp_login_url();
                if (isset($_POST['wps_deals_social_email'])) {
                    //check email is set or not
                    $socialemail = $_POST['wps_deals_social_email'];
                    if (empty($socialemail)) {
                        //if email is empty
                        $errors->add('empty_email', __('<strong>ERROR :</strong> Enter your email address.', 'wpsdeals'));
                    } elseif (!is_email($socialemail)) {
                        //if email is not valid
                        $errors->add('invalid_email', __('<strong>ERROR :</strong> The email address did not validate.', 'wpsdeals'));
                        $socialemail = '';
                    } elseif (email_exists($socialemail)) {
                        //if email is exist or not
                        $errors->add('email_exists', __('<strong>ERROR :</strong> Email already exists, If you have an account login first.', 'wpsdeals'));
                    }
                    if ($errors->get_error_code() == '') {
                        //
                        if (!empty($data)) {
                            //check user data is not empty
                            $data['email'] = $socialemail;
                            //create user
                            $usercreated = $this->wps_deals_social_create_user($data);
                            //check shortcode redirect url is set and not empty then make it blank
                            $redirect_url = $this->session->get('wps_deals_stcd_redirect_url');
                            if (!empty($redirect_url)) {
                                $this->session->remove('wps_deals_stcd_redirect_url');
                            }
                            wp_redirect($redirect_url);
                            exit;
                            //send user to checkout page
                            //wps_deals_send_on_checkout_page();
                        }
                    }
                }
            }
            //redirect user to custom registration form
            if (isset($_GET['wps_deals_social_login']) && !empty($_GET['wps_deals_social_login'])) {
                $prefix = WPS_DEALS_META_PREFIX;
                //login call back url after registration
                /*$callbackurl = wp_login_url();
                		$callbackurl = add_query_arg('wps_deals_social_login_done', 1, $callbackurl);*/
                $socialemail = isset($_POST['wps_deals_social_email']) ? $_POST['wps_deals_social_email'] : '';
                //check the user who is going to connect with site
                //it is alreay exist with same data or not
                //if user is exist then simply make that user logged in
                $metaquery = array(array('key' => $prefix . 'social_user_connect_via', 'value' => $data['type']), array('key' => $prefix . 'social_identifier', 'value' => $data['id']));
                $getusers = get_users(array('meta_query' => $metaquery));
                $wpuser = array_shift($getusers);
                //getting users
                //check user is exist or not conected with same metabox
                if (!empty($wpuser)) {
                    //make user logged in
                    wp_set_auth_cookie($wpuser->ID, false);
                    //check shortcode redirect url is set and not empty then make it blank
                    $redirect_url = $this->session->get('wps_deals_stcd_redirect_url');
                    if (!empty($redirect_url)) {
                        $this->session->remove('wps_deals_stcd_redirect_url');
                    }
                    wp_redirect($redirect_url);
                    exit;
                    //send user to checkout page
                    //wps_deals_send_on_checkout_page();
                } else {
                    //if user is not exist then show register user form
                    login_header(__('Registration Form', 'wpsdeals'), '<p class="message register">' . __('Please enter your email address to compelete registeration.', 'wpsdeals') . '</p>', $errors);
                    ?>
						<form name="registerform" id="registerform" action="" method="post">
							  <p>
								  <label for="wcsl_email"><?php 
                    _e('E-mail', 'wpsdeals');
                    ?>
<br />
								  <input type="text" name="wps_deals_social_email" id="wps_deals_social_email" class="input" value="<?php 
                    echo $this->model->wps_deals_escape_attr($socialemail);
                    ?>
" size="25" tabindex="20" /></label>
							  </p>
							  <p id="reg_passmail">
							  	<?php 
                    _e('Username and Password will be sent to your email.', 'wpsdeals');
                    ?>
							  </p>
							  <br class="clear" />
							  <p class="submit"><input type="submit" name="wps-deals-submit" id="wps-deals-submit" class="button-primary" value="<?php 
                    _e('Register', 'wpsdeals');
                    ?>
" tabindex="100" /></p>
						</form>
					<?php 
                    login_footer('user_login');
                    exit;
                }
            }
        }
    }
コード例 #3
0
 /**
  * Show All Social Login Buttons
  * 
  * Handles to show all social login buttons on the viewing page
  * whereever user put shortcode
  * 
  * @package Social Deals Engine
  * @since 1.0.1
  */
 public function wps_deals_social_login($atts, $content)
 {
     global $wps_deals_options;
     extract(shortcode_atts(array('title' => '', 'redirect_url' => ''), $atts));
     if (!is_home() && is_singular()) {
         //check user is not logged in and social login is enable or not for any one service
         if (!is_user_logged_in() && wps_deals_enable_social_login()) {
             // get redirect url from settings
             $defaulturl = isset($wps_deals_options['login_redirect_url']) && !empty($wps_deals_options['login_redirect_url']) ? $wps_deals_options['login_redirect_url'] : wps_deals_get_current_page_url();
             //redirect url for shortcode
             $defaulturl = isset($redirect_url) && !empty($redirect_url) ? $redirect_url : $defaulturl;
             //session create for redirect url
             $this->session->set('wps_deals_stcd_redirect_url', $defaulturl);
             ob_start();
             //do action to add social login buttons
             do_action('wps_deals_social_login_shortcode', $title, $redirect_url);
             $content .= ob_get_clean();
         }
     }
     return $content;
 }
コード例 #4
0
ファイル: twitter.php プロジェクト: wppassion/deals-engine
 /**
  * Get auth url for twitter
  *
  * @param Social Deals Engine
  * @since 1.0.0
  */
 public function wps_deals_social_get_twitter_auth_url()
 {
     // Save temporary credentials to session.
     // Get temporary credentials.
     global $post;
     //load twitter class
     $twitter = $this->wps_deals_social_load_twitter();
     //check twitter class is loaded or not
     if (!$twitter) {
         return false;
     }
     $request_token = $this->twitter->getRequestToken(wps_deals_get_current_page_url());
     // get_permalink( $post->ID )
     // If last connection failed don't display authorization link.
     switch ($this->twitter->http_code) {
         //
         case 200:
             // Build authorize URL and redirect user to Twitter.
             // Save temporary credentials to session.
             $this->session->set('wps_deals_twt_oauth_token', $request_token['oauth_token']);
             $this->session->set('wps_deals_twt_oauth_token_secret', $request_token['oauth_token_secret']);
             $token = $request_token['oauth_token'];
             $url = $this->twitter->getAuthorizeURL($token);
             break;
         default:
             // Show notification if something went wrong.
             $url = '';
     }
     return $url;
 }