Commit b4b826e8 authored by Dave Lane's avatar Dave Lane

fix out-of-place enqueuing requests

parent cddf6744
......@@ -34,6 +34,19 @@ class OREMain extends OREBase {
//$this->log('setting up scripts');
// jsquery validate script
add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
// add the ajax handlers
// this enables the register-enrol service for authenticated users...
add_action('wp_ajax_ore_submit', array($this, 'ajax_submit'));
add_action('wp_ajax_ore_email_check', array($this, 'ajax_email_check'));
add_action('wp_ajax_ore_username_check', array($this, 'ajax_username_check'));
// and, just as importantly, unauthenticated users...
add_action('wp_ajax_nopriv_ore_submit', array($this, 'ajax_submit'));
add_action('wp_ajax_nopriv_ore_email_check', array($this, 'ajax_email_check'));
add_action('wp_ajax_nopriv_ore_username_check', array($this, 'ajax_username_check'));
}
public function enqueue_scripts() {
wp_register_script(
'jquery-validate',
'https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.js',
......@@ -42,7 +55,6 @@ class OREMain extends OREBase {
);
wp_enqueue_script(ORE_SCRIPT, ORE_URL.'js/ore_script.js', array(
'jquery', 'jquery-form', 'jquery-validate'));
global $country_selector;
$this->country_selector = $country_selector;
$user_array = $this->get_user();
......@@ -71,15 +83,6 @@ class OREMain extends OREBase {
// our css
wp_register_style(ORE_STYLE, ORE_URL.'css/ore_style.css');
wp_enqueue_style(ORE_STYLE);
// add the ajax handlers
// this enables the register-enrol service for authenticated users...
add_action('wp_ajax_ore_submit', array($this, 'ajax_submit'));
add_action('wp_ajax_ore_email_check', array($this, 'ajax_email_check'));
add_action('wp_ajax_ore_username_check', array($this, 'ajax_username_check'));
// and, just as importantly, unauthenticated users...
add_action('wp_ajax_nopriv_ore_submit', array($this, 'ajax_submit'));
add_action('wp_ajax_nopriv_ore_email_check', array($this, 'ajax_email_check'));
add_action('wp_ajax_nopriv_ore_username_check', array($this, 'ajax_username_check'));
}
// give realtime info on whether or not an email is unique in the system
......@@ -279,6 +282,7 @@ class OREMain extends OREBase {
// apply the filter for password retrieval
$title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data );
$headers = array("From: OERu Course Admin <".$from.">");
if ($message && !wp_mail($user_email, wp_specialchars_decode($title), $message, $headers)) {
$this->log('sending email via wp_email failed with email '.$user_email.', title '.wp_specialchars_decode($title).', and message '.$message.'... and headers: '.print_r($headers, true));
$errors->add(ORE_ERROR_LABEL, 'The site failed to send an email. This is either because the email is invalid, or because this site is having difficulty sending email. To report this, you can <a href="https://oeru.org/contact-us">contact us</a>.');
......@@ -714,12 +718,17 @@ class OREMain extends OREBase {
// get the current user
if ($user_id === null) {
$current = wp_get_current_user();
$user_id = $current->data->ID;
if (isset($current->data) && isset($current->data->ID)) {
$user_id = $current->data->ID;
} else {
$this->log('no valid current user found!');
return false;
}
// for security's sake, don't even show the password hash...
unset($current->data->user_pass);
} else {
if (!($current = get_userdata($user_id))){
//$this->log('There is no user associated with user_id: '.$user_id);
$this->log('There is no user associated with user_id: '.$user_id);
return false;
}
}
......@@ -738,6 +747,7 @@ class OREMain extends OREBase {
//$this->log('user up to this point: '.print_r($user, true));
$user['country_name'] = $this->get_country_name($user['country']);
$user['profile_url'] = $this->get_profile_url($user_id);
$avatar_args = array();
$user['avatar_url'] = explode('?', get_avatar_url($user_id,
array('default'=>'identicon', 'processed_args'=>$avatar_args)))[0];
$user['log_out_url'] = wp_logout_url(get_permalink());
......@@ -837,7 +847,7 @@ class OREMain extends OREBase {
$markup .= $val['markup'];
}
$button_classes = 'button ore-button';
$both = (is_array($val['default']) && is_array($val['alternative'])) ? true : false;
$both = (is_array($val['default']) && isset($val['alternative']) && is_array($val['alternative'])) ? true : false;
if (is_array($val['default'])) {
$default = $val['default'];
$classes = $button_classes.' ore-default';
......@@ -863,7 +873,7 @@ class OREMain extends OREBase {
}
$markup .= '</div><!-- ore-default-wrapper -->';
$dialogs[$index]['default'] = $default;
if (is_array($val['alternative'])) {
if (isset($val['alternative']) && is_array($val['alternative'])) {
$alt = $val['alternative'];
$classes = $button_classes.' ore-alternative';
$div_classes = ($both) ? ' ore-right' : '';
......
......@@ -50,7 +50,6 @@ define('ORE_ID', 'register-enrol');
define('ORE_TITLE', 'Register Enrol');
define('ORE_MENU', 'Register Enrol');
define('ORE_TEMPLATES', 'register-enrol');
define('ORE_ID', 'register-enrol');
define('ORE_STYLE', 'ore-style');
define('ORE_SCRIPT', 'ore-script');
define('ORE_CLASS', 'ore-form');
......@@ -70,7 +69,9 @@ define('ORE_ADMIN_MENU', 'ORE Settings');*/
// turn on debugging with true, off with false
define('ORE_DEBUG', true);
// other stuff
define('LOG_STREAM', getenv('LOG_STREAM'));
if (!defined('LOG_STREAM')) {
define('LOG_STREAM', getenv('LOG_STREAM'));
}
define('ORE_MIN_PASSWORD_LENGTH', 8);
define('ORE_MIN_USERNAME_LENGTH', 4);
define('ORE_MIN_DISPLAY_NAME_LENGTH', 6);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment