Diverting WordPress login and register links to Joomla -


i have joomla plugin one-way single sign-on between joomla , wordpress.

it means registrations , logins handled joomla , every time registers in joomla replicates user's data wordpress user tables , everytime logs joomla writes user's status logged in wordpress cookie user automatically gets logged wordpress.

however not case wordpress. not these actions if logs wordpress or registers wordpress.

hence want divert users wordpress joomla pages login , registration activities.

example:

joomla login page: http://www.xyz.com/index.php?option=com_user&view=login&itemid=204  joomla registration page: http://www.xyz.com/index.php?option=com_user&view=login&itemid=205 

now want when user clicks on login link in default meta widget must take user above joomla page , when user clicks on register, must take user above registration page.

i looking solution preferably without hacking core files. please feel free suggest if there better solution looking above.

i use atom theme , has built-in login form widget, , code widget is:

please note: novice when comes programming hence requesting detailed reply.

/**  * login widget  * based on "login ajax" plugin - http://netweblogic.com/wordpress/plugins/login-with-ajax  *  * @since 1.0  * @todo add register form  */ class atom_widget_login extends wp_widget{    function atom_widget_login(){     $widget_ops = array('description' => __("login , lost password forms", atom));     $control_ops = array('width' => 500);     $this->wp_widget(false, __("login", atom), $widget_ops, $control_ops);     add_action('init', array(&$this, 'ajax'), 99);      // include in jquery(document).ready()     add_action('atom_jquery_init', array(&$this, 'js'));   }    function js(){     // need process instances because function gets run once.     $widget_settings = get_option($this->option_name);      foreach((array)$widget_settings $instance => $options):        // identify instance       $id = $this->id_base.'-'.$instance;       $block_id = 'instance-'.$id;        if (is_active_widget(false, $id, $this->id_base)): ?>        $('#<?php echo $id; ?>_login').submit(function(event){          // stop event         event.preventdefault();          $status = $("#<?php echo $block_id; ?> .status");         $status.removeclass("error").addclass("loading").text("<?php _e("checking...", atom); ?>");          // sort out url         url = $('#<?php echo $id; ?>_login').attr('action');         url += (url.match(/\?/) != null) ? '&callback=?' : '?callback=?' ;         url += "&log="+encodeuricomponent($("#<?php echo $id; ?>_user").val());         url += "&pwd="+encodeuricomponent($("#<?php echo $id; ?>_pass").val());         url += "&rememberme="+encodeuricomponent($("#<?php echo $id; ?>_login_remember").val());         url += "&login=login";          $.getjson(url, function(data, status){           if(data.result === true || data.result === false){             if(data.result === true){               $status.removeclass("loading error").addclass("success").html(data.message);               window.location.reload();             }else{               $status.removeclass("loading").addclass("error").html(data.error);                // assume link in status message points forgot pass form.               $status.find("a").click(function(event){                 event.preventdefault();                  if($("#<?php echo $id; ?>_forgot").is(":visible")){                   var origcolor = $("#<?php echo $id; ?>_forgot input.text").css("color");                   $("#<?php echo $id; ?>_forgot input.text").css({backgroundcolor: '#ffa799', color: '#333'}).animate({backgroundcolor: '#fff', color: origcolor}, 1000);                 }else{                   $("#<?php echo $block_id; ?> a.forgot_pass").remove(); // remove bottom forgot pass link                   $('#<?php echo $id; ?>_forgot').slidefade('toggle',333,'easeoutquart');                 }                });             }           }else{             $status.removeclass("loading").html("<?php _e("unkown error. please try again...", atom); ?>");           }         });       });        $('#<?php echo $id; ?>_forgot').submit(function(event){          // stop event         event.preventdefault();          $status = $("#<?php echo $block_id; ?> .status");         $status.removeclass("error").addclass("loading").text("<?php _e("checking...", atom); ?>");          // sort out url         url = $('#<?php echo $id; ?>_forgot').attr('action');         url += (url.match(/\?/) != null) ? '&callback=?' : '?callback=?' ;         url += "&user_login="+$("#<?php echo $id; ?>_user_or_email").val();         url += "&login=forgot_pass";          $.getjson(url, function(data, status){           if(data.result === true || data.result === false){             if(data.result == '1') $status.removeclass("loading error").addclass("success").html(data.message);             else $status.removeclass("loading").addclass("error").html(data.error);           }else{             $status.removeclass("loading").addclass("error").html("<?php _e("unkown error. please try again...", atom); ?>");           }         });       });        $("#<?php echo $block_id; ?> a.forgot_pass").click(function(event){         event.preventdefault();         $(this).remove();         $('#<?php echo $id; ?>_forgot').slidefade('toggle',333,'easeoutquart');       });        <?php endif;     endforeach;   }    function ajax(){      if(isset($_get["login"])):       switch($_get["login"]):         case 'login':           $_post['log'] = $_get['log'];           $_post['pwd'] = $_get['pwd'];           $_post['rememberme'] = $_get['rememberme'];            global $current_user;           $return = array(); //what send           $loginresult = wp_signon();            if(strtolower(get_class($loginresult)) == 'wp_user'):             //user login successful             $current_user = $loginresult;             /* @var $loginresult wp_user */             $return['result'] = true;             $return['message'] = __("login successful, redirecting...", atom);            elseif(strtolower(get_class($loginresult)) == 'wp_error'):             //user login failed             /* @var $loginresult wp_error */             $return['result'] = false;             $error = $loginresult->get_error_message();             $return['error'] = ($error ? $error : __("please type username , password", atom));            else:             //undefined error             $return['result'] = false;             $return['error'] = __('unknown error. sorry...', atom);            endif;           $return = json_encode($return);         break;          case 'forgot_pass':           $_post['user_login'] = $_get['user_login'];            // reads ajax login creds via post, calls login script , interprets result           $remember = array(); //what send           $result = retrieve_password();            if($result === true):             //password correctly remembered             $remember['result'] = true;             $remember['message'] = __("e-mail has been sent, check inbox.", atom);           elseif(strtolower(get_class($result)) == 'wp_error'):             //something went wrong             /* @var $result wp_error */             $remember['result'] = false;             $remember['error'] = $result->get_error_message();           else:             //undefined error             $remember['result'] = false;             $remember['error'] = __('unknown error. sorry...', atom);           endif;            $return = json_encode($remember);         break;          default:           $return = json_encode(array('result' => 0, 'error' => __('requested command invalid', atom)));         break;       endswitch;       if(isset($_get['callback'])) $return = $_get['callback']."($return)";       echo $return;       exit();     endif;   }    function widget($args, $instance){     extract($args);     $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);      // retrieve information current user.     global $current_user, $user_level;     get_currentuserinfo();      if(is_user_logged_in()) $title = sprintf(__('welcome %s', atom), $current_user->display_name);     echo $before_widget.($title ? $before_title.$title.$after_title : null);      echo '<div class="box login-block clear-block">';      // user logged in, display menu links     if(is_user_logged_in()):       echo '<div class="avatar">'.atom_get_avatar($current_user->user_email, 96, '', $current_user->display_name).'</div>';       echo '<ul class="menu">';        if($instance['dashboard']) echo '<li class="first"><a class="fadethis" href="'.admin_url().'">'.__('dashboard', atom).'</a></li>';        if($user_level >= 1): // need permissions         if($instance['write'])  echo '<li><a class="fadethis" href="'.admin_url('post-new.php').'">'.__('write', atom).'</a></li>';         if($instance['comments']) echo '<li><a class="fadethis" href="'.admin_url('edit-comments.php').'">'.__('comments', atom).'</a></li>';       endif;        if($instance['profile']) echo '<li><a class="fadethis" href="'.admin_url('profile.php').'">'.__('profile', atom).'</a></li>';       echo '<li><a class="fadethis last" id="wp-logout" href="'.wp_logout_url(atom_get_current_page_url()).'">'.__('log out', atom).'</a></li>';       echo '</ul>';      // user not logged in, display login form     else: ?>        <div class="status clear-block"><?php echo $instance['text']; ?></div>        <form id="<?php echo $this->id; ?>_login" action="<?php echo site_url('wp-login.php', 'login_post') ?>" method="post">          <div>           <input type="text" rel="<?php echo __("user", atom); ?>" name="log" id="<?php echo $this->id; ?>_user" class="text clearfield" value="" />           <input type="password" rel="<?php echo __("password", atom); ?>" name="pwd" id="<?php echo $this->id; ?>_pass" class="text clearfield" value="" />         </div>          <div class="clear-block">           <input type="submit" name="wp-submit" class="alignleft" value="<?php _e('log in', atom); ?>" tabindex="100" />            <input type="hidden" name="redirect_to" value="<?php echo atom_get_current_page_url(); ?>" />           <input type="hidden" name="testcookie" value="1" />           <input type="hidden" name="login" value="login" />            <label for="<?php echo $this->id; ?>_login_remember" class="remember alignleft">             <input name="rememberme" type="checkbox" id="<?php echo $this->id; ?>_login_remember" value="forever" />             <?php _e('remember me', atom); ?>           </label>         </div>       </form>        <form id="<?php echo $this->id; ?>_forgot" action="<?php echo site_url('wp-login.php?action=lostpassword', 'login_post') ?>" method="post" class="hidden">         <div>           <input type="text" name="user_login" size="20" id="<?php echo $this->id; ?>_user_or_email" class="text wide clearfield" value="<?php _e("enter username or email", atom); ?>" />           <input type="submit" value="<?php echo __("get new password", atom); ?>" />           <input type="hidden" name="login" value="forgot_pass" />         </div>       </form>        <?php       echo '<a class="forgot_pass" href="'.site_url('wp-login.php?action=lostpassword', 'login').'">'.__('lost password?', atom).'</a>';        if (get_option('users_can_register')):         if(function_exists('bp_get_signup_page')) $register_link = bp_get_signup_page(); // bp         elseif(file_exists(abspath."/wp-signup.php")) $register_link = site_url('wp-signup.php', 'login'); //mu + wp3         else $register_link = site_url('wp-login.php?action=register', 'login');         echo '<a class="register" href="'.$register_link.'">'.__('register', atom).'</a>';       endif;     endif;      echo '</div>';  echo $after_widget;   }    function update($new_instance, $old_instance){     $instance['title'] = esc_attr($new_instance['title']);     if (current_user_can('unfiltered_html')) $instance['text'] =  $new_instance['text'];     else $instance['text'] = stripslashes(wp_filter_post_kses(addslashes($new_instance['text']))); // wp_filter_post_kses() expects slashed     $instance['dashboard'] = isset($new_instance['dashboard']);     $instance['profile'] = isset($new_instance['profile']);     $instance['write'] = isset($new_instance['write']);     $instance['comments'] = isset($new_instance['comments']);     return $instance;   }    function form($instance){     $instance = wp_parse_args((array)$instance, apply_filters('atom_widget_login_defaults', array(       'title' => __('log in', atom),       'text' => __("hello guest. login below if have account", atom),       'dashboard' => 1,       'profile' => 1,       'write' => 1,       'comments' => 0)));     ?>      <p>       <label for="<?php echo $this->get_field_name('title'); ?>"><?php _e('title:', atom); ?>       <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php if (isset($instance['title'])) echo esc_attr($instance['title']); ?>" /></label>     </p>      <p>       <label for="<?php echo $this->get_field_name('text'); ?>"><?php _e('initial status text (or html):', atom); ?>       <textarea class="widefat code" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>" rows="6" cols="28"><?php if (isset($instance['text'])) echo format_to_edit($instance['text']); ?></textarea>       </label>     </p>      <p><strong><em><?php _e("welcome screen links (if enough permissions):", atom); ?></em></strong></p>     <p>      <label for="<?php echo $this->get_field_id('dashboard'); ?>">        <input id="<?php echo $this->get_field_id('dashboard'); ?>" name="<?php echo $this->get_field_name('dashboard'); ?>" type="checkbox" value="1" <?php checked(isset($instance['dashboard']) ? $instance['dashboard'] : 0); ?> />        <?php _e('dashboard', atom); ?>      </label>      <br />       <label for="<?php echo $this->get_field_id('profile'); ?>">        <input id="<?php echo $this->get_field_id('profile'); ?>" name="<?php echo $this->get_field_name('profile'); ?>" type="checkbox" value="1" <?php checked(isset($instance['profile']) ? $instance['profile'] : 0); ?> />        <?php _e('profile', atom); ?>      </label>      <br />       <label for="<?php echo $this->get_field_id('write'); ?>">        <input id="<?php echo $this->get_field_id('write'); ?>" name="<?php echo $this->get_field_name('write'); ?>" type="checkbox" value="1" <?php checked(isset($instance['write']) ? $instance['write'] : 0); ?> />        <?php _e('write', atom); ?>      </label>      <br />       <label for="<?php echo $this->get_field_id('comments'); ?>">        <input id="<?php echo $this->get_field_id('comments'); ?>" name="<?php echo $this->get_field_name('comments'); ?>" type="checkbox" value="1" <?php checked(isset($instance['comments']) ? $instance['comments'] : 0); ?> />        <?php _e('comments', atom); ?>      </label>      <br />       <label>        <input disabled="disabled" type="checkbox" value="1" checked="checked" />        <?php _e('log out', atom); ?>      </label>     </p>     <?php   } } 

replace

<form id="<?php echo $this->id; ?>_login" action="<?php echo site_url('wp-login.php', 'login_post') ?>" method="post"> 

with

<form id="<?php echo $this->id; ?>_login" action="<?php echo 'http://www.xyz.com/index.php?option=com_user&view=login&itemid=204' ?>" method="post"> 

for logging in , registering link replace

$register_link = site_url('wp-login.php?action=register', 'login'); 

with

$register_link = 'http://www.xyz.com/index.php?option=com_user&view=login&itemid=205'; 

p.s - didn't try myself


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -