Skip to content

Commit

Permalink
Adding email login, and needed filters, #126.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zane committed Sep 22, 2015
1 parent 35fd22f commit e40ddfa
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 13 deletions.
2 changes: 2 additions & 0 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
require ZM_ALR_PATH . 'src/ALRSocial/ALRSocialFacebook.php';
require ZM_ALR_PATH . 'src/ALRMisc/ALRMisc.php';
require ZM_ALR_PATH . 'src/ALRRedirect/ALRRedirect.php';
require ZM_ALR_PATH . 'src/ALREmailLogin/ALREmailLogin.php';


/**
Expand All @@ -59,6 +60,7 @@ function zm_alr_init(){
new ALRSocial();
new ALRSocialFacebook( new ZM_Dependency_Container( null ) );
new ALRUpgrade();
new ALREmailLogin();

global $zm_alr_settings_obj;
$zm_alr_settings_obj = new Quilt(
Expand Down
11 changes: 2 additions & 9 deletions src/ALRCore/ALRHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,9 @@ public function buildFormFieldsHtml( $fields=null, $prefix=null, $order=null ){
$new_fields = array();
foreach( $fields as $key => $value ){

$new_value = apply_filters( 'below_' . $key, null );
$new_fields[ $key ] = $value;

// Add the new value, using the key/
if ( $new_value ){
$new_fields[ $new_value['key'] ] = $new_value;

// no need to keep the key around, so we remove it, to avoid later confusion.
unset( $new_fields[ $new_value['key'] ]['key'] );
}
$new_fields = apply_filters( 'above_' . $key, $new_fields );
$new_fields = apply_filters( 'below_' . $key, $new_fields );

}

Expand Down
4 changes: 2 additions & 2 deletions src/ALRCore/ALRLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ public function loginSubmit( $user_login=null, $password=null, $is_ajax=true ) {
*/
if ( $is_ajax ) check_ajax_referer('login_submit','security');

$args = array(
$args = apply_filters( $this->prefix . '_form_params', array(
'user_login' => sanitize_user( $_POST['zm_alr_login_user_name'] ),
'password' => $_POST['zm_alr_login_password'],
'remember' => empty( $_POST['remember'] ) ? false : ture
);
) );

$pre_status = apply_filters( $this->prefix . '_submit_pre_status_error', $_POST );

Expand Down
105 changes: 105 additions & 0 deletions src/ALREmailLogin/ALREmailLogin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php


// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;


Class ALREmailLogin {

private $prefix;

public function __construct(){

$this->prefix = 'zm_alr_email_login';

add_filter( 'zm_alr_misc_settings_fields_tab', array( &$this, 'settings' ) );
add_filter( 'above_zm_alr_login_password', array( &$this, 'abovePassword' ) );
add_filter( 'zm_alr_login_form_fields', array( &$this, 'removeLoginField' ) );
add_filter( 'zm_alr_login_form_params', array( &$this, 'setUserName' ) );

}


/**
* Adds the Redirect settings as a tab.
*
* @since 2.0.0
*
* @param $current_settings
* @return
*/
public function settings( $current_fields ){

$fields = array( array(
'id' => $this->prefix . '_enable_email_login',
'title' => __( 'Enable Email Login', ZM_ALR_TEXT_DOMAIN ),
'type' => 'fancySelect',
'options' => array(
'yes' => 'Yes',
'no' => 'No'
),
'std' => 'no', // set to '' so it shows in settings as empty
'desc' =>
__('By enabling this setting users can login with their email. Note users MUST still <strong>register</strong> with a user name.',ZM_ALR_TEXT_DOMAIN )
) );

return array_merge( $current_fields, $fields );

}


public function abovePassword( $field ){

global $zm_alr_settings;

if ( $zm_alr_settings[ $this->prefix . '_enable_email_login' ] == 'no' )
return $field;

return array_merge( array(
$this->prefix . '_form_field' => array(
'title' => __( 'Email', ZM_ALR_TEXT_DOMAIN ),
'type' => 'email',
'placeholder' => 'your@email.com'
)
), $field );

}


public function removeLoginField( $fields ){

global $zm_alr_settings;

if ( $zm_alr_settings[ $this->prefix . '_enable_email_login' ] == 'yes' ){

unset( $fields['zm_alr_login_user_name'] );

}

return $fields;

}


public function setUserName( $args ){

global $zm_alr_settings;

if ( $zm_alr_settings[ $this->prefix . '_enable_email_login' ] == 'yes' ){

$user_obj = get_user_by( 'email', sanitize_email(
$_POST[ $this->prefix . '_form_field']
) );

if ( $user_obj ){
$args['user_login'] = $user_obj->user_login;
}

}

return $args;

}

}
4 changes: 2 additions & 2 deletions src/ALRMisc/ALRMisc.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function settings( $current_settings ){

$settings[ $this->prefix ] = array(
'title' => __('Misc.', ZM_ALR_TEXT_DOMAIN ),
'fields' => array(
'fields' => apply_filters( $this->prefix . '_settings_fields_tab', array(
array(
'id' => $this->prefix . '_login_handle',
'title' => __( 'Login Handle', ZM_ALR_TEXT_DOMAIN ),
Expand Down Expand Up @@ -80,7 +80,7 @@ public function settings( $current_settings ){
'desc' => __( 'Setting this option will pre-load the forms, allowing them to be loaded prior to being clicked on.', ZM_ALR_TEXT_DOMAIN )
)
)
);
) );

return array_merge( $current_settings, $settings );

Expand Down

0 comments on commit e40ddfa

Please sign in to comment.