latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

About: Realty Training

Sorry, I've not written a description yet. I'll get to it soon!


Topics I'm Subscribed To

Viewing 2 topics - 1 through 2 (of 2 total)
Topic Count Last Reply
Where's instructions for a login widget. 1 2

By:  Realty Training in: Community Forum

voices: 3
replies: 31

4 years, 3 months ago  Dan Martinez

Only the shortcode is showing.

By:  Realty Training in: Community Forum

voices: 2
replies: 3

4 years, 3 months ago  Eduan

Viewing 2 topics - 1 through 2 (of 2 total)

Topics I've Started

Viewing 2 topics - 1 through 2 (of 2 total)
Topic Count Last Reply
Where's instructions for a login widget. 1 2

By:  Realty Training in: Community Forum

voices: 3
replies: 31

4 years, 3 months ago  Dan Martinez

Only the shortcode is showing.

By:  Realty Training in: Community Forum

voices: 2
replies: 3

4 years, 3 months ago  Eduan

Viewing 2 topics - 1 through 2 (of 2 total)

My Latest Replies (From Various Topics)

Viewing 15 replies - 1 through 15 (of 15 total)
Author Replies
Author Replies
Posted: Sunday Sep 16th, 2012 at 5:46 pm #25517

That did the trick! Works perfect. You’re a genius Dan. Thanks SO much.

All the best,

Stephen

Posted: Sunday Sep 16th, 2012 at 2:20 pm #25509

It’s turned off. I even tried turning it on then off again just to be sure.

Posted: Sunday Sep 16th, 2012 at 1:20 pm #25500

@Eduan I’m not sure I understand you. It does no good to show the registration link if it’s not going to go to the Membership Options Page. Dan gave me a string of code but it didn’t cause it to redirect to the Membership Options Page as he hoped it would.

Posted: Sunday Sep 16th, 2012 at 6:38 am #25466

Registration link shows now but it still goes to the typical s3member login form and says at the top of the form. “user registration currently not allowed.” It’s not redirecting.

Posted: Saturday Sep 15th, 2012 at 6:16 pm #25445

I tried on their forums. No answer for two days. :(

Posted: Saturday Sep 15th, 2012 at 2:14 pm #25430

Yes Eduan I tried it and it didn’t work. I tried it in other parts of the script too.

Posted: Saturday Sep 15th, 2012 at 4:30 am #25398

When I turn off open registration it causes the registration links to disappear. :(

Posted: Thursday Sep 13th, 2012 at 7:30 pm #25220

The code for Sidebar Login might be less complicated. It doesn’t us a popup window for registration. What if I put a url instead of ‘sblogin’ at ‘theregister’=>__(‘Register’,’sblogin’),

'',
		'after_widget'=>'',
		'before_title'=>'',
		'after_title'=>''
	);
	$args = array_merge($defaults, $args);
	
	widget_wp_sidebarlogin($args);
}

/* The widget */
function widget_wp_sidebarlogin($args) {
	global $user_ID, $current_user;
	
	/* To add more extend i.e when terms came from themes - suggested by dev.xiligroup.com */
	$defaults = array(
		'thelogin'=>'',
		'thewelcome'=>'',
		'theusername'=>__('Username:','sblogin'),
		'thepassword'=>__('Password:','sblogin'),
		'theremember'=>__('Remember me','sblogin'),
		'theregister'=>__('Register','sblogin'),
		'thepasslostandfound'=>__('Password Lost and Found','sblogin'),
		'thelostpass'=>	__('Lost your password?','sblogin'),
		'thelogout'=> __('Logout','sblogin')
	);
	
	$args = array_merge($defaults, $args);
	extract($args);		
	
	get_currentuserinfo();

	if ($user_ID != '') {
	
		// User is logged in
		global $current_user;
  		get_currentuserinfo();
		
		if (empty($thewelcome)) $thewelcome = str_replace('%username%',ucwords($current_user->display_name),get_option('sidebarlogin_welcome_heading'));
		
		echo $before_widget . $before_title .$thewelcome. $after_title;
		
		if (get_option('sidebar_login_avatar')=='1') echo ''.get_avatar($user_ID, $size = '38').'';
		
		echo '<ul>';
		
		if(isset($current_user-&gt;user_level) &amp;&amp; $current_user-&gt;user_level) $level = $current_user-&gt;user_level;
				
		$links = do_shortcode(trim(get_option('sidebarlogin_logged_in_links')));
		
		$links = explode("\n", $links);
		if (sizeof($links)&gt;0)
		foreach ($links as $l) {
			$l = trim($l);
			if (!empty($l)) {
				$link = explode('|',$l);
				if (isset($link[1])) {
					$cap = strtolower(trim($link[1]));
					if ($cap=='true') {
						if (!current_user_can( 'manage_options' )) continue;
					} else {
						if (!current_user_can( $cap )) continue;
					}
				}
				// Parse %USERNAME%
				$link[0] = str_replace('%USERNAME%',sanitize_title($current_user-&gt;user_login),$link[0]);
				$link[0] = str_replace('%username%',sanitize_title($current_user-&gt;user_login),$link[0]);
				// Parse %USERID%
				$link[0] = str_replace('%USERID%',$current_user-&gt;ID,$link[0]);
				$link[0] = str_replace('%userid%',$current_user-&gt;ID,$link[0]);
				echo '<li>'.$link[0].'</li>';
			}
		}
		
		$redir = trim(stripslashes(get_option('sidebarlogin_logout_redirect')));
		if (!$redir || empty($redir)) $redir = sidebar_login_current_url('nologout');
		
		echo '<li><a href=" ' . wp_logout_url( $redir ) . '">' . $thelogout . '</a></li></ul>';
		
	} else {
	
		// User is NOT logged in!!!
		
		if (empty($thelogin)) $thelogin = get_option('sidebarlogin_heading');
		
		echo $before_widget . $before_title .''. $thelogin .'' . $after_title;

		global $login_errors;

		if ( is_wp_error($login_errors) &amp;&amp; $login_errors-&gt;get_error_code() ) {
			
			foreach ($login_errors-&gt;get_error_messages() as $error) {
				$error = apply_filters('sidebar_login_error', $error);
				echo '' . $error . "\n";
				break;
			}
				
		}
		
		// Get redirect URL
		$redirect_to = trim(stripslashes(get_option('sidebarlogin_login_redirect')));
		
		if ( empty( $redirect_to ) ) {
			if ( isset( $_REQUEST['redirect_to'] ) ) 
				$redirect_to = esc_url( $_REQUEST['redirect_to'] );
			else
				$redirect_to = sidebar_login_current_url('nologout');
		}
		
		if ( force_ssl_admin() ) 
			$redirect_to = str_replace( 'http:', 'https:', $redirect_to );
		
		// login form
		$sidebarlogin_post_url = ( force_ssl_login() || force_ssl_admin() ) ? str_replace('http://', 'https://', sidebar_login_current_url() ) : sidebar_login_current_url();
		
		$login_form_args = apply_filters( 'sidebar_login_form_args', array(
	        'echo' 				=&gt; true,
	        'redirect' 			=&gt; esc_attr( $redirect_to ), 
	        'label_username' 	=&gt; $theusername,
	        'label_password' 	=&gt; $thepassword,
	        'label_remember' 	=&gt; $theremember,
	        'label_log_in' 		=&gt; __('Login &raquo;', 'sblogin'),
	        'remember' 			=&gt; true,
	        'value_remember' 	=&gt; true 
	    ) );
		
		wp_login_form( $login_form_args );
			
		// Output other links
		$links = '';	
		if ( get_option('users_can_register') &amp;&amp; get_option('sidebarlogin_register_link') == '1' ) { 

			if ( ! is_multisite() ) {
			
				$links .= '<li><a href="' . apply_filters( 'sidebar_login_register_url', site_url('wp-login.php?action=register', 'login') ) . '">' . $theregister . '</a></li>';

			} else {
				
				$links .= '<li><a href="' . apply_filters( 'sidebar_login_register_url', site_url('wp-signup.php', 'login') ) . '">' . $theregister . '</a></li>';

			}
		}
		if ( get_option( 'sidebarlogin_forgotton_link' ) == '1' )
			$links .= '<li><a href="' . apply_filters( 'sidebar_login_lostpassword_url', wp_lostpassword_url() ) . '">' . $thelostpass . '</a></li>';

		if ($links)
			echo '<ul>' . $links . '</ul>';	
	}		
		
	// echo widget closing tag
	echo $after_widget;
}

/* Init widget/styles/scripts */
function widget_wp_sidebarlogin_init() {
	
	$plugin_url = (is_ssl()) ? str_replace('http://','https://', WP_PLUGIN_URL) : WP_PLUGIN_URL;
	
	// CSS
	$sidebar_login_css = $plugin_url . '/sidebar-login/style.css';
    wp_register_style('wp_sidebarlogin_css_styles', $sidebar_login_css);
    wp_enqueue_style('wp_sidebarlogin_css_styles');
    
	// Scripts
	$block_ui = $plugin_url . '/sidebar-login/js/blockui.js';
	$sidebar_login_script = $plugin_url . '/sidebar-login/js/sidebar-login.js';
	
	wp_register_script('blockui', $block_ui, array('jquery'), '1.0' );
	wp_register_script('sidebar-login', $sidebar_login_script, array('jquery', 'blockui'), '1.0' );
	wp_enqueue_script('jquery');
	wp_enqueue_script('blockui');
	wp_enqueue_script('sidebar-login');
	
	// Pass variables to script
	$sidebar_login_params = array(
		'ajax_url' 				=&gt; ( is_ssl() || force_ssl_admin() || force_ssl_login() ) ? str_replace('http:', 'https:', admin_url('admin-ajax.php')) : str_replace('https:', 'http:', admin_url('admin-ajax.php')),
		'login_nonce' 			=&gt; wp_create_nonce("sidebar-login-action")
	);
	wp_localize_script( 'sidebar-login', 'sidebar_login_params', $sidebar_login_params );
	
	// Register widget
	class SidebarLoginMultiWidget extends WP_Widget {
	    function SidebarLoginMultiWidget() {  
	        $widget_ops = array('description' =&gt; __( 'Sidebar Login.','sblogin') );
			$this-&gt;WP_Widget('wp_sidebarlogin', __('Sidebar Login','sblogin'), $widget_ops);  
	    }
	    function widget($args, $instance) {    
	        
	        widget_wp_sidebarlogin($args);
	
	    }
	} 
	register_widget('SidebarLoginMultiWidget');
	
}

add_action('init', 'widget_wp_sidebarlogin_init', 1);

/**
 * Process ajax login
 */
add_action('wp_ajax_sidebar_login_process', 'sidebar_login_ajax_process');
add_action('wp_ajax_nopriv_sidebar_login_process', 'sidebar_login_ajax_process');

function sidebar_login_ajax_process() {

	check_ajax_referer( 'sidebar-login-action', 'security' );
	
	// Get post data
	$creds = array();
	$creds['user_login'] 	= $_REQUEST['user_login'];
	$creds['user_password'] = $_REQUEST['user_password'];
	$creds['remember'] 		= esc_attr($_REQUEST['remember']);
	$redirect_to 			= esc_attr($_REQUEST['redirect_to']);
	
	// Check for Secure Cookie
	$secure_cookie = '';
	
	// If the user wants ssl but the session is not ssl, force a secure cookie.
	if ( ! force_ssl_admin() ) {
		$user_name = sanitize_user( $_REQUEST['user_login'] );
		if ( $user = get_user_by('login',  $user_name ) ) {
			if ( get_user_option('use_ssl', $user-&gt;ID) ) {
				$secure_cookie = true;
				force_ssl_admin(true);
			}
		}
	}
	
	if ( force_ssl_admin() ) $secure_cookie = true;
	if ( $secure_cookie=='' &amp;&amp; force_ssl_login() ) $secure_cookie = false;

	// Login
	$user = wp_signon($creds, $secure_cookie);
	
	// Redirect filter
	if ( $secure_cookie &amp;&amp; strstr($redirect_to, 'wp-admin') ) $redirect_to = str_replace('http:', 'https:', $redirect_to);

	// Result
	$result = array();
	
	if ( ! is_wp_error($user) ) :
		$result['success'] = 1;
		$result['redirect'] = $redirect_to;
	else :
		$result['success'] = 0;
		if ( $user-&gt;errors ) {
			foreach ($user-&gt;errors as $error) {
				$result['error'] = $error[0];
				break;
			}
		} else {
			$result['error'] = __('Please enter your username and password to login.', 'sblogin');
		}
	endif;
	
	header('content-type: application/json; charset=utf-8');

	echo $_GET['callback'] . '(' . json_encode($result) . ')';

	die();
}


/* Get Current URL */
if ( !function_exists('sidebar_login_current_url') ) {
	function sidebar_login_current_url( $url = '' ) {
	
		$pageURL  = force_ssl_admin() ? 'https://' : 'http://';
		$pageURL .= esc_attr( $_SERVER['HTTP_HOST'] );
		$pageURL .= esc_attr( $_SERVER['REQUEST_URI'] );
	
		if ($url != "nologout") {
			if (!strpos($pageURL,'_login=')) {
				$rand_string = md5(uniqid(rand(), true));
				$rand_string = substr($rand_string, 0, 10);
				$pageURL = add_query_arg('_login', $rand_string, $pageURL);
			}	
		}
		
		return strip_tags( $pageURL );
	}
}
  • This reply was modified 4 years, 3 months ago by  Eduan. Reason: Added the code tags
Posted: Thursday Sep 13th, 2012 at 7:23 pm #25219

Here’s the who shebang if you have the time. I see I need to learn coding.

<?php
/*
Plugin Name: Login With Ajax
Plugin URI: http://netweblogic.com/wordpress/plugins/login-with-ajax/
Description: Ajax driven login widget. Customisable from within your template folder, and advanced settings from the admin area.
Author: NetWebLogic
Version: 3.0.4.1
Author URI: http://netweblogic.com/
Tags: Login, Ajax, Redirect, BuddyPress, MU, WPMU, sidebar, admin, widget

Copyright (C) 2009 NetWebLogic LLC

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see .
*/
class LoginWithAjax {

	/**
	 * If logged in upon instantiation, it is a user object.
	 * @var WP_User
	 */
	var $current_user;
	/**
	 * List of templates available in the plugin dir and theme (populated in init())
	 * @var array
	 */
	var $templates = array();
	/**
	 * Name of selected template (if selected)
	 * @var string
	 */
	var $template;
	/**
	 * lwa_data option
	 * @var array
	 */
	var $data;
	/**
	 * Location of footer file if one is found when generating a widget, for use in loading template footers.
	 * @var string
	 */
	var $footer_loc;
	/**
	 * URL for the AJAX Login procedure in templates (including callback and template parameters)
	 * @var string
	 */
	var $url_login;
	/**
	 * URL for the AJAX Remember Password procedure in templates (including callback and template parameters)
	 * @var string
	 */
	var $url_remember;
	/**
	 * URL for the AJAX Registration procedure in templates (including callback and template parameters)
	 * @var string
	 */
	var $url_register;



	// Class initialization
	function LoginWithAjax() {
		//Set when to run the plugin
		add_action( 'widgets_init', array(&amp;$this,'init') );
	}

	// Actions to take upon initial action hook
	function init(){
		//Load LWA options
		$this-&gt;data = get_option('lwa_data');
		//Remember the current user, in case there is a logout
		$this-&gt;current_user = wp_get_current_user();

		//Get Templates from theme and default by checking for folders - we assume a template works if a folder exists!
		//Note that duplicate template names are overwritten in this order of precedence (highest to lowest) - Child Theme &gt; Parent Theme &gt; Plugin Defaults
		//First are the defaults in the plugin directory
		$this-&gt;find_templates( path_join( WP_PLUGIN_DIR , basename( dirname( __FILE__ ) ). "/widget/") );
		//Now, the parent theme (if exists)
		if( get_stylesheet_directory() != get_template_directory() ){
			$this-&gt;find_templates( get_template_directory().'/plugins/login-with-ajax/' );
		}
		//Finally, the child theme
		$this-&gt;find_templates( get_stylesheet_directory().'/plugins/login-with-ajax/' );

		//Generate URLs for login, remember, and register
		$this-&gt;url_login = $this-&gt;template_link(site_url('wp-login.php', 'login_post'));
		$this-&gt;url_register = $this-&gt;template_link(site_url('wp-login.php?action=register', 'login_post'));
		$this-&gt;url_remember = $this-&gt;template_link(site_url('wp-login.php?action=lostpassword', 'login_post'));

		//Make decision on what to display
		if ( isset($_REQUEST["login-with-ajax"]) ) { //AJAX Request
			$this-&gt;ajax();
		}elseif ( isset($_REQUEST["login-with-ajax-widget"]) ) { //Widget Request via AJAX
			$instance = ( !empty($_REQUEST["template"]) ) ? array('template' =&gt; $_REQUEST["template"]) : array();
			$instance['is_widget'] = false;
			$instance['profile_link'] = ( !empty($_REQUEST["lwa_profile_link"]) ) ? $_REQUEST['lwa_profile_link']:0;
			$this-&gt;widget( array(), $instance );
			exit();
		}elseif ( function_exists('register_widget') ){ //WP json_encode($this-&gt;login());
				break;
			case 'remember': //Remember the password
				$return = $this-&gt;json_encode($this-&gt;remember());
				break;
			default: //Don't know
				$return = $this-&gt;json_encode(array('result'=&gt;0, 'error'=&gt;'Unknown command requested'));
				break;
		}
		echo $return;
		exit();
	}

	// Reads ajax login creds via POSt, calls the login script and interprets the result
	function login(){
		$return = array(); //What we send back
		if( !empty($_REQUEST['log']) &amp;&amp; !empty($_REQUEST['pwd']) &amp;&amp; trim($_REQUEST['log']) != '' &amp;&amp; trim($_REQUEST['pwd'] != '') ){
			$loginResult = wp_signon();
			$user_role = 'null';
			if ( strtolower(get_class($loginResult)) == 'wp_user' ) {
				//User login successful
				$this-&gt;current_user = $loginResult;
				/* @var $loginResult WP_User */
				$return['result'] = true;
				$return['message'] = __("Login Successful, redirecting...",'login-with-ajax');
				//Do a redirect if necessary
				$redirect = $this-&gt;getLoginRedirect($this-&gt;current_user);
				if( $redirect != '' ){
					$return['redirect'] = $redirect;
				}
				//If the widget should just update with ajax, then supply the URL here.
				if( !empty($this-&gt;data['no_login_refresh']) &amp;&amp; $this-&gt;data['no_login_refresh'] == 1 ){
					//Is this coming from a template?
					$query_vars = ($_GET['template'] != '') ? "&amp;template={$_GET['template']}" : '';
					$query_vars .= ($_REQUEST['lwa_profile_link'] == '1') ? "&amp;lwa_profile_link=1" : '';
					$return['widget'] = get_bloginfo('wpurl')."?login-with-ajax-widget=1$query_vars";
					$return['message'] = __("Login successful, updating...",'login-with-ajax');
				}
			} elseif ( strtolower(get_class($loginResult)) == 'wp_error' ) {
				//User login failed
				/* @var WP_Error $loginResult */
				$return['result'] = false;
				$return['error'] = $loginResult-&gt;get_error_message();
			} else {
				//Undefined Error
				$return['result'] = false;
				$return['error'] = __('An undefined error has ocurred', 'login-with-ajax');
			}
		}else{
			$return['result'] = false;
			$return['error'] = __('Please supply your username and password.', 'login-with-ajax');
		}
		//Return the result array with errors etc.
		return $return;
	}

	/**
	 * Checks post data and registers user
	 * @return string
	 */
	function register(){
		if( !empty($_REQUEST['lwa']) ) {
			$return = array();
			if ('POST' == $_SERVER['REQUEST_METHOD']) {
				require_once( ABSPATH . WPINC . '/registration.php');
				$errors = register_new_user($_POST['user_login'], $_POST['user_email']);
				if ( !is_wp_error($errors) ) {
					//Success
					$return['result'] = true;
					$return['message'] = __('Registration complete. Please check your e-mail.');
				}else{
					//Something's wrong
					$return['result'] = false;
					$return['error'] = $errors-&gt;get_error_message();
				}
			}
			echo $this-&gt;json_encode($return);
			exit();
		}
	}

	// Reads ajax login creds via POSt, calls the login script and interprets the result
	function remember(){
		$return = array(); //What we send back
		$result = retrieve_password();

		if ( $result === true ) {
			//Password correctly remembered
			$return['result'] = true;
			$return['message'] = __("We have sent you an email", 'login-with-ajax');
		} elseif ( strtolower(get_class($result)) == 'wp_error' ) {
			//Something went wrong
			/* @var $result WP_Error */
			$return['result'] = false;
			$return['error'] = $result-&gt;get_error_message();
		} else {
			//Undefined Error
			$return['result'] = false;
			$return['error'] = __('An undefined error has ocurred', 'login-with-ajax');
		}
		//Return the result array with errors etc.
		return $return;
	}

	/*
	 * Redirect Functions
	 */

	function logoutRedirect(){
		$redirect = $this-&gt;getLogoutRedirect();
		if($redirect != ''){
			wp_redirect($redirect);
			exit();
		}
	}

	function getLogoutRedirect(){
		$data = $this-&gt;data;
		if( !empty($data['logout_redirect']) ){
			$redirect = $data['logout_redirect'];
		}
		if( strtolower(get_class($this-&gt;current_user)) == "wp_user" ){
			//Do a redirect if necessary
			$data = $this-&gt;data;
			$user_role = array_shift($this-&gt;current_user-&gt;roles); //Checking for role-based redirects
			if( !empty($data["role_logout"]) &amp;&amp; is_array($data["role_logout"]) &amp;&amp; isset($data["role_logout"][$user_role]) ){
				$redirect = $data["role_logout"][$user_role];
			}
		}
		$redirect = str_replace("%LASTURL%", $_SERVER['HTTP_REFERER'], $redirect);
		return $redirect;
	}

	function loginRedirect( $redirect, $redirect_notsurewhatthisis, $user ){
		$data = $this-&gt;data;
		if(is_user_logged_in()){
			$lwa_redirect = $this-&gt;getLoginRedirect($user);
			if( $lwa_redirect != '' ){
				wp_redirect($lwa_redirect);
				exit();
			}
		}
		return $redirect;
	}

	function getLoginRedirect($user){
		$data = $this-&gt;data;
		if($data['login_redirect'] != ''){
			$redirect = $data["login_redirect"];
		}
		if( strtolower(get_class($user)) == "wp_user" ){
			$user_role = array_shift($user-&gt;roles); //Checking for role-based redirects
			if( isset($data["role_login"][$user_role]) ){
				$redirect = $data["role_login"][$user_role];
			}
		}
		//Do string replacements
		$redirect = str_replace('%USERNAME%', $user-&gt;user_login, $redirect);
		$redirect = str_replace("%LASTURL%", $_SERVER['HTTP_REFERER'], $redirect);
		return $redirect;
	}

	/*
	 * WIDGET OPERATIONS
	 */

	function widget($args, $instance = array() ){
		//Extract widget arguments
		extract($args);
		//Merge instance options with global default options
		$lwa_data = $this-&gt;data;
		$lwa_data = wp_parse_args($instance, $lwa_data);
		//Deal with specific variables
		$lwa_data['profile_link'] = ( $lwa_data['profile_link'] != false &amp;&amp; $lwa_data['profile_link'] != "false" );
		$is_widget = ( isset($lwa_data['is_widget']) ) ? ($lwa_data['is_widget'] != false &amp;&amp; $lwa_data['is_widget'] != "false") : true ;
		//Add template logic
		$this-&gt;template = ( !empty($lwa_data['template']) &amp;&amp; array_key_exists($lwa_data['template'], $this-&gt;templates) ) ? $lwa_data['template']:'default';
		//Choose the widget content to display.
		if(is_user_logged_in()){
			//Firstly check for template in theme with no template folder (legacy)
			$template_loc = locate_template( array('plugins/login-with-ajax/widget_in.php') );
			//Then check for custom templates or theme template default
			$template_loc = ($template_loc == '' &amp;&amp; $this-&gt;template) ? $this-&gt;templates[$this-&gt;template].'/widget_in.php':$template_loc;
			include ( $template_loc != '' ) ? $template_loc : 'widget/default/widget_in.php';
		}else{
			//Firstly check for template in theme with no template folder (legacy)
			$template_loc = locate_template( array('plugins/login-with-ajax/widget_out.php') );
			//First check for custom templates or theme template default
			$template_loc = ($template_loc == '' &amp;&amp; $this-&gt;template) ? $this-&gt;templates[$this-&gt;template].'/widget_out.php' : $template_loc;
			include ( $template_loc != '' ) ? $template_loc : 'widget/default/widget_out.php';
		}
	}

	function shortcode($atts){
		$defaults = array( 'is_widget' =&gt; false, 'profile_link' =&gt; false, 'registration' =&gt; 1 );
		$atts = shortcode_atts($defaults, $atts);
		ob_start();
		$this-&gt;widget(array(), $atts );
		return ob_get_clean();
	}

	function new_user_notification($user_login, $plaintext_pass, $user_email, $blogname){
		//Copied out of /wp-includes/pluggable.php
		$message = $this-&gt;data['notification_message'];
		$message = str_replace('%USERNAME%', $user_login, $message);
		$message = str_replace('%PASSWORD%', $plaintext_pass, $message);
		$message = str_replace('%BLOGNAME%', $blogname, $message);
		$message = str_replace('%BLOGURL%', get_bloginfo('wpurl'), $message);

		$subject = $this-&gt;data['notification_subject'];
		$subject = str_replace('%BLOGNAME%', $blogname, $subject);
		$subject = str_replace('%BLOGURL%', get_bloginfo('wpurl'), $subject);

		wp_mail($user_email, $subject, $message);
	}

	/*
	 * Auxillary Functions
	 */

	//Checks a directory for folders and populates the template file
	function find_templates($dir){
		if (is_dir($dir)) {
		    if ($dh = opendir($dir)) {
		        while (($file = readdir($dh)) !== false) {
		            if(is_dir($dir . $file) &amp;&amp; $file != '.' &amp;&amp; $file != '..' &amp;&amp; $file != '.svn'){
		            	//Template dir found, add it to the template array
		            	$this-&gt;templates[$file] = path_join($dir, $file);
		            }
		        }
		        closedir($dh);
		    }
		}
	}

	//Add template link and JSON callback var to the URL
	function template_link( $content ){
		if(strstr($content, '?')){
			$content .= '&amp;callback=?&amp;template='.$this-&gt;template;
		}else{
			$content .= '?callback=?&amp;template='.$this-&gt;template;
		}
		return $content;
	}

	//PHP4 Safe JSON encoding
	function json_encode($array){
		if( !function_exists("json_encode") ){
			$return = json_encode($array);
		}else{
			$return = $this-&gt;array_to_json($array);
		}
		if( isset($_REQUEST['callback']) &amp;&amp; preg_match("/^jQuery[_a-zA-Z0-9]+$/", $_REQUEST['callback']) ){
			$return = $_GET['callback']."($return)";
		}
		return $return;
	}
	//PHP4 Compatible json encoder function
	function array_to_json($array){
		//PHP4 Comapatability - This encodes the array into JSON. Thanks go to Andy - http://www.php.net/manual/en/function.json-encode.php#89908
		if( !is_array( $array ) ){
	        return false;
	    }
	    $associative = count( array_diff( array_keys($array), array_keys( array_keys( $array )) ));
	    if( $associative ){
	        $construct = array();
	        foreach( $array as $key =&gt; $value ){
	            // We first copy each key/value pair into a staging array,
	            // formatting each key and value properly as we go.
	            // Format the key:
	            if( is_numeric($key) ){
	                $key = "key_$key";
	            }
	            $key = "'".addslashes($key)."'";
	            // Format the value:
	            if( is_array( $value )){
	                $value = $this-&gt;array_to_json( $value );
	            }else if( is_bool($value) ) {
	            	$value = ($value) ? "true" : "false";
	            }else if( !is_numeric( $value ) || is_string( $value ) ){
	                $value = "'".addslashes($value)."'";
	            }
	            // Add to staging array:
	            $construct[] = "$key: $value";
	        }
	        // Then we collapse the staging array into the JSON form:
	        $result = "{ " . implode( ", ", $construct ) . " }";
	    } else { // If the array is a vector (not associative):
	        $construct = array();
	        foreach( $array as $value ){
	            // Format the value:
	            if( is_array( $value )){
	                $value = $this-&gt;array_to_json( $value );
	            } else if( !is_numeric( $value ) || is_string( $value ) ){
	                $value = "'".addslashes($value)."'";
	            }
	            // Add to staging array:
	            $construct[] = $value;
	        }
	        // Then we collapse the staging array into the JSON form:
	        $result = "[ " . implode( ", ", $construct ) . " ]";
	    }
	    return $result;
	}
}
//Add translation
load_plugin_textdomain('login-with-ajax', false, "login-with-ajax/langs");

//Include admin file if needed
if(is_admin()){
	include_once('login-with-ajax-admin.php');
}
//Include widget
include_once('login-with-ajax-widget.php');

//Include pluggable functions file if user specifies in settings
$lwa_data = get_option('lwa_data');
if( !empty($lwa_data['notification_override']) &amp;&amp; $lwa_data['notification_override'] == '1' ){
	include_once('pluggable.php');
}

//Template Tag
function login_with_ajax($atts = ''){
	global $LoginWithAjax;
	$atts = shortcode_parse_atts($atts);
	echo $LoginWithAjax-&gt;shortcode($atts);
}

// Start plugin
global $LoginWithAjax;
$LoginWithAjax = new LoginWithAjax();

?>
  • This reply was modified 4 years, 3 months ago by  Eduan. Reason: Added the code tags
Posted: Thursday Sep 13th, 2012 at 11:09 am #25185

I’ll try that. Thanks so much for your help!

Posted: Thursday Sep 13th, 2012 at 10:34 am #25177

I don’t know how to do that but I suspect this is what I have to alter. Any idea what I should change?

//Register widget
register_widget(“LoginWithAjaxWidget”);

//Add logout/in redirection
add_action(‘login_form_register’, array(&$this, ‘register’));
add_action(‘wp_logout’, array(&$this, ‘logoutRedirect’));
add_action(‘login_redirect’, array(&$this, ‘loginRedirect’), 1, 3);
add_shortcode(‘login-with-ajax’, array(&$this, ‘shortcode’));
add_shortcode(‘lwa’, array(&$this, ‘shortcode’));

Posted: Wednesday Sep 12th, 2012 at 8:58 pm #25090

I guess I could put a registration link under the widget. I just want to make sure s2 is going to work for me better than the other ones out there before I get the pro version.

Posted: Wednesday Sep 12th, 2012 at 8:03 am #24991

The plugin you directed me to is called Sidebar Login. All it has is a checkbox to show the register link or not. But it doesn’t seem to have a place to put a redirect link. There’s a login redirect but nothing for registration.

I also tried a plugin called Login With Ajax. That plugin even accomodates different s2member login redirects according to membership level. So it must have been made with s2 in mind yet even that plugin doesn have a customizable registration redirect. I don’t get why?

Posted: Tuesday Sep 11th, 2012 at 7:27 pm #24939

I’m sorry. I figured out those pages were from another program I was trying out. I take it the only page that should be there is the Membership Options Page? Is this the page you use to get someone to signup with?

Sorry if I’m asking dumb questions. Everything hasn’t jelled yet.

Posted: Tuesday Sep 11th, 2012 at 7:04 pm #24937

Looks good. Thanks so much!

BTW, when I click on the register link it goes to a general registration form and doesn’t show any payment options. How do I change that?

Viewing 15 replies - 1 through 15 (of 15 total)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.