mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-14 04:06:36 +09:00
Update 1.2.92
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
class Array2XML {
|
||||
|
||||
private static $xml = null;
|
||||
private static $encoding = 'UTF-8';
|
||||
|
||||
/**
|
||||
* Initialize the root XML node [optional]
|
||||
* @param $version
|
||||
* @param $encoding
|
||||
* @param $format_output
|
||||
*/
|
||||
public static function init($version = '1.0', $encoding = 'UTF-8', $format_output = true) {
|
||||
self::$xml = new DomDocument($version, $encoding);
|
||||
self::$xml->formatOutput = $format_output;
|
||||
self::$encoding = $encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an Array to XML
|
||||
* @param string $node_name - name of the root node to be converted
|
||||
* @param array $arr - aray to be converterd
|
||||
* @return DomDocument
|
||||
*/
|
||||
public static function &createXML($node_name, $arr=array()) {
|
||||
$xml = self::getXMLRoot();
|
||||
$xml->appendChild(self::convert($node_name, $arr));
|
||||
|
||||
self::$xml = null; // clear the xml node in the class for 2nd time use.
|
||||
return $xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an Array to XML
|
||||
* @param string $node_name - name of the root node to be converted
|
||||
* @param array $arr - aray to be converterd
|
||||
* @return DOMNode
|
||||
*/
|
||||
private static function &convert($node_name, $arr=array()) {
|
||||
|
||||
//print_arr($node_name);
|
||||
$xml = self::getXMLRoot();
|
||||
$node = $xml->createElement($node_name);
|
||||
|
||||
if(is_array($arr)){
|
||||
// get the attributes first.;
|
||||
if(isset($arr['@attributes'])) {
|
||||
foreach($arr['@attributes'] as $key => $value) {
|
||||
if(!self::isValidTagName($key)) {
|
||||
throw new Exception('[Array2XML] Illegal character in attribute name. attribute: '.$key.' in node: '.$node_name);
|
||||
}
|
||||
$node->setAttribute($key, self::bool2str($value));
|
||||
}
|
||||
unset($arr['@attributes']); //remove the key from the array once done.
|
||||
}
|
||||
|
||||
// check if it has a value stored in @value, if yes store the value and return
|
||||
// else check if its directly stored as string
|
||||
if(isset($arr['@value'])) {
|
||||
$node->appendChild($xml->createTextNode(self::bool2str($arr['@value'])));
|
||||
unset($arr['@value']); //remove the key from the array once done.
|
||||
//return from recursion, as a note with value cannot have child nodes.
|
||||
return $node;
|
||||
} else if(isset($arr['@cdata'])) {
|
||||
$node->appendChild($xml->createCDATASection(self::bool2str($arr['@cdata'])));
|
||||
unset($arr['@cdata']); //remove the key from the array once done.
|
||||
//return from recursion, as a note with cdata cannot have child nodes.
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
|
||||
//create subnodes using recursion
|
||||
if(is_array($arr)){
|
||||
// recurse to get the node for that key
|
||||
foreach($arr as $key=>$value){
|
||||
if(!self::isValidTagName($key)) {
|
||||
throw new Exception('[Array2XML] Illegal character in tag name. tag: '.$key.' in node: '.$node_name);
|
||||
}
|
||||
if(is_array($value) && is_numeric(key($value))) {
|
||||
// MORE THAN ONE NODE OF ITS KIND;
|
||||
// if the new array is numeric index, means it is array of nodes of the same kind
|
||||
// it should follow the parent key name
|
||||
foreach($value as $k=>$v){
|
||||
$node->appendChild(self::convert($key, $v));
|
||||
}
|
||||
} else {
|
||||
// ONLY ONE NODE OF ITS KIND
|
||||
$node->appendChild(self::convert($key, $value));
|
||||
}
|
||||
unset($arr[$key]); //remove the key from the array once done.
|
||||
}
|
||||
}
|
||||
|
||||
// after we are done with all the keys in the array (if it is one)
|
||||
// we check if it has any text value, if yes, append it.
|
||||
if(!is_array($arr)) {
|
||||
$node->appendChild($xml->createTextNode(self::bool2str($arr)));
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the root XML node, if there isn't one, create it.
|
||||
*/
|
||||
private static function getXMLRoot(){
|
||||
if(empty(self::$xml)) {
|
||||
self::init();
|
||||
}
|
||||
return self::$xml;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get string representation of boolean value
|
||||
*/
|
||||
private static function bool2str($v){
|
||||
//convert boolean to text value.
|
||||
$v = $v === true ? 'true' : $v;
|
||||
$v = $v === false ? 'false' : $v;
|
||||
return $v;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the tag name or attribute name contains illegal characters
|
||||
* Ref: http://www.w3.org/TR/xml/#sec-common-syn
|
||||
*/
|
||||
private static function isValidTagName($tag){
|
||||
$pattern = '/^[a-z_]+[a-z0-9\:\-\.\_]*[^:]*$/i';
|
||||
return preg_match($pattern, $tag, $matches) && $matches[0] == $tag;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,6 +1,13 @@
|
||||
<?php
|
||||
|
||||
require_once("../../../../../../wp-load.php");
|
||||
$i = 0;
|
||||
$dirname = dirname( __FILE__ );
|
||||
do {
|
||||
$dirname = dirname( $dirname );
|
||||
$wp_load = "{$dirname}/wp-load.php";
|
||||
}
|
||||
while( ++$i < 10 && !file_exists( $wp_load ) );
|
||||
require_once( $wp_load );
|
||||
global $ultimatemember;
|
||||
|
||||
$id = $_POST['key'];
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
<?php
|
||||
|
||||
require_once("../../../../../../wp-load.php");
|
||||
$i = 0;
|
||||
$dirname = dirname( __FILE__ );
|
||||
do {
|
||||
$dirname = dirname( $dirname );
|
||||
$wp_load = "{$dirname}/wp-load.php";
|
||||
}
|
||||
while( ++$i < 10 && !file_exists( $wp_load ) );
|
||||
require_once( $wp_load );
|
||||
global $ultimatemember;
|
||||
|
||||
$id = $_POST['key'];
|
||||
|
||||
@@ -141,7 +141,7 @@
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @Error processing hook : standard
|
||||
***/
|
||||
@@ -159,12 +159,12 @@
|
||||
$ultimatemember->form->add_error($key, sprintf(__('%s is required.','ultimatemember'), $array['title'] ) );
|
||||
}
|
||||
|
||||
if ( isset( $array['type'] ) && $array['type'] == 'radio' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) ) {
|
||||
if ( isset( $array['type'] ) && $array['type'] == 'radio' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) && !in_array($key, array('role_radio','role_select') ) ) {
|
||||
$ultimatemember->form->add_error($key, sprintf(__('%s is required.','ultimatemember'), $array['title'] ) );
|
||||
}
|
||||
|
||||
if ( $key == 'role_select' || $key == 'role_radio' ) {
|
||||
if ( isset($args['role']) && empty($args['role']) && isset( $array['required'] ) && $array['required'] == 1 ) {
|
||||
if ( isset( $array['required'] ) && $array['required'] == 1 && ( !isset( $args['role'] ) || empty( $args['role'] ) ) ) {
|
||||
$ultimatemember->form->add_error('role', __('Please specify account type.','ultimatemember') );
|
||||
}
|
||||
}
|
||||
@@ -232,6 +232,11 @@
|
||||
|
||||
switch( $array['validate'] ) {
|
||||
|
||||
case 'custom':
|
||||
$custom = $array['custom_validate'];
|
||||
do_action("um_custom_field_validation_{$custom}", $key, $array );
|
||||
break;
|
||||
|
||||
case 'numeric':
|
||||
if ( $args[$key] && !is_numeric( $args[$key] ) ) {
|
||||
$ultimatemember->form->add_error($key, __('Please enter numbers only in this field','ultimatemember') );
|
||||
|
||||
@@ -171,18 +171,18 @@
|
||||
add_action('um_after_login_fields', 'um_add_submit_button_to_login', 1000);
|
||||
function um_add_submit_button_to_login($args){
|
||||
global $ultimatemember;
|
||||
|
||||
|
||||
// DO NOT add when reviewing user's details
|
||||
if ( $ultimatemember->user->preview == true && is_admin() ) return;
|
||||
|
||||
$primary_btn_word = $args['primary_btn_word'];
|
||||
$primary_btn_word = apply_filters('um_login_form_button_one', $primary_btn_word);
|
||||
$primary_btn_word = apply_filters('um_login_form_button_one', $primary_btn_word, $args );
|
||||
|
||||
$secondary_btn_word = $args['secondary_btn_word'];
|
||||
$secondary_btn_word = apply_filters('um_login_form_button_two', $secondary_btn_word);
|
||||
$secondary_btn_word = apply_filters('um_login_form_button_two', $secondary_btn_word, $args );
|
||||
|
||||
$secondary_btn_url = ( isset( $args['secondary_btn_url'] ) && $args['secondary_btn_url'] ) ? $args['secondary_btn_url'] : um_get_core_page('register');
|
||||
$secondary_btn_url = apply_filters('um_login_form_button_two_url', $secondary_btn_url);
|
||||
$secondary_btn_url = apply_filters('um_login_form_button_two_url', $secondary_btn_url, $args );
|
||||
|
||||
?>
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
function um_profile_content_main( $args ) {
|
||||
extract( $args );
|
||||
|
||||
if ( !um_get_option('profile_tab_main') && !isset( $_REQUEST['um_action'] ) )
|
||||
return;
|
||||
|
||||
$can_view = apply_filters('um_profile_can_view_main', -1, um_profile_id() );
|
||||
|
||||
if ( $can_view == -1 ) {
|
||||
@@ -374,8 +377,9 @@
|
||||
<div class="um-meta-text">
|
||||
<textarea placeholder="<?php _e('Tell us a bit about yourself...','ultimatemember'); ?>" name="<?php echo 'description-' . $args['form_id']; ?>" id="<?php echo 'description-' . $args['form_id']; ?>"><?php if ( um_user('description') ) { echo um_user('description'); } ?></textarea>
|
||||
|
||||
<?php if ( $ultimatemember->fields->is_error('description') )
|
||||
echo $ultimatemember->fields->field_error( $ultimatemember->fields->show_error('description') ); ?>
|
||||
<?php if ( $ultimatemember->fields->is_error('description') ) {
|
||||
echo $ultimatemember->fields->field_error( $ultimatemember->fields->show_error('description'), true ); }
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -581,7 +585,7 @@
|
||||
$tabs = $ultimatemember->profile->tabs_active();
|
||||
|
||||
$tabs = apply_filters('um_user_profile_tabs', $tabs );
|
||||
|
||||
|
||||
$ultimatemember->user->tabs = $tabs;
|
||||
|
||||
// need enough tabs to continue
|
||||
@@ -614,6 +618,8 @@
|
||||
|
||||
<i class="<?php echo $tab['icon']; ?>"></i>
|
||||
|
||||
<?php if ( isset( $tab['notifier'] ) && $tab['notifier'] > 0 ) { ?><span class="um-tab-notifier uimob500-show uimob340-show uimob800-show"><?php echo $tab['notifier']; ?></span><?php } ?>
|
||||
|
||||
<span class="uimob500-hide uimob340-hide uimob800-hide title"><?php echo $tab['name']; ?></span>
|
||||
|
||||
<?php if ( um_get_option('profile_menu_counts') && isset( $tab['count'] ) ) { ?>
|
||||
|
||||
@@ -99,6 +99,8 @@
|
||||
|
||||
$ultimatemember->user->set_plain_password( $args['user_password'] );
|
||||
|
||||
do_action('um_new_user_registration_plain');
|
||||
|
||||
do_action('um_post_registration_save', $user_id, $args);
|
||||
|
||||
do_action('um_post_registration_listener', $user_id, $args);
|
||||
@@ -237,13 +239,13 @@
|
||||
if ( isset( $ultimatemember->user->preview ) && $ultimatemember->user->preview == true && is_admin() ) return;
|
||||
|
||||
$primary_btn_word = $args['primary_btn_word'];
|
||||
$primary_btn_word = apply_filters('um_register_form_button_one', $primary_btn_word);
|
||||
$primary_btn_word = apply_filters('um_register_form_button_one', $primary_btn_word, $args );
|
||||
|
||||
$secondary_btn_word = $args['secondary_btn_word'];
|
||||
$secondary_btn_word = apply_filters('um_register_form_button_two', $secondary_btn_word);
|
||||
$secondary_btn_word = apply_filters('um_register_form_button_two', $secondary_btn_word, $args );
|
||||
|
||||
$secondary_btn_url = ( isset( $args['secondary_btn_url'] ) && $args['secondary_btn_url'] ) ? $args['secondary_btn_url'] : um_get_core_page('login');
|
||||
$secondary_btn_url = apply_filters('um_register_form_button_two_url', $secondary_btn_url);
|
||||
$secondary_btn_url = apply_filters('um_register_form_button_two_url', $secondary_btn_url, $args );
|
||||
|
||||
?>
|
||||
|
||||
|
||||
+727
@@ -0,0 +1,727 @@
|
||||
<?php
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
class UM_REST_API {
|
||||
|
||||
const VERSION = '1.0';
|
||||
|
||||
private $pretty_print = false;
|
||||
public $log_requests = true;
|
||||
private $is_valid_request = false;
|
||||
private $user_id = 0;
|
||||
private $stats;
|
||||
private $data = array();
|
||||
private $override = true;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
add_action( 'init', array( $this, 'add_endpoint' ) );
|
||||
add_action( 'template_redirect', array( $this, 'process_query' ), -1 );
|
||||
add_filter( 'query_vars', array( $this, 'query_vars' ) );
|
||||
add_action( 'show_user_profile', array( $this, 'user_key_field' ) );
|
||||
add_action( 'edit_user_profile', array( $this, 'user_key_field' ) );
|
||||
add_action( 'personal_options_update', array( $this, 'update_key' ) );
|
||||
add_action( 'edit_user_profile_update', array( $this, 'update_key' ) );
|
||||
|
||||
// Determine if JSON_PRETTY_PRINT is available
|
||||
$this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null;
|
||||
|
||||
// Allow API request logging to be turned off
|
||||
$this->log_requests = apply_filters( 'um_api_log_requests', $this->log_requests );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new rewrite endpoint for accessing the API
|
||||
*/
|
||||
public function add_endpoint( $rewrite_rules ) {
|
||||
add_rewrite_endpoint( 'um-api', EP_ALL );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers query vars for API access
|
||||
*/
|
||||
public function query_vars( $vars ) {
|
||||
|
||||
$vars[] = 'key';
|
||||
$vars[] = 'token';
|
||||
$vars[] = 'format';
|
||||
$vars[] = 'query';
|
||||
$vars[] = 'type';
|
||||
$vars[] = 'data';
|
||||
$vars[] = 'fields';
|
||||
$vars[] = 'number';
|
||||
$vars[] = 'id';
|
||||
$vars[] = 'email';
|
||||
$vars[] = 'orderby';
|
||||
$vars[] = 'order';
|
||||
$vars[] = 'include';
|
||||
$vars[] = 'exclude';
|
||||
|
||||
$this->vars = $vars;
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the API request
|
||||
*/
|
||||
private function validate_request() {
|
||||
global $wp_query;
|
||||
|
||||
$this->override = false;
|
||||
|
||||
// Make sure we have both user and api key
|
||||
if ( ! empty( $wp_query->query_vars['um-api'] ) ) {
|
||||
|
||||
if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) )
|
||||
$this->missing_auth();
|
||||
|
||||
// Retrieve the user by public API key and ensure they exist
|
||||
if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) :
|
||||
$this->invalid_key();
|
||||
else :
|
||||
$token = urldecode( $wp_query->query_vars['token'] );
|
||||
$secret = get_user_meta( $user, 'um_user_secret_key', true );
|
||||
$public = urldecode( $wp_query->query_vars['key'] );
|
||||
|
||||
if ( hash_equals( md5( $secret . $public ), $token ) )
|
||||
$this->is_valid_request = true;
|
||||
else
|
||||
$this->invalid_auth();
|
||||
endif;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the user ID based on the public key provided
|
||||
*/
|
||||
public function get_user( $key = '' ) {
|
||||
global $wpdb, $wp_query;
|
||||
|
||||
if( empty( $key ) )
|
||||
$key = urldecode( $wp_query->query_vars['key'] );
|
||||
|
||||
if ( empty( $key ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = get_transient( md5( 'um_api_user_' . $key ) );
|
||||
|
||||
if ( false === $user ) {
|
||||
$user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'um_user_public_key' AND meta_value = %s LIMIT 1", $key ) );
|
||||
set_transient( md5( 'um_api_user_' . $key ) , $user, DAY_IN_SECONDS );
|
||||
}
|
||||
|
||||
if ( $user != NULL ) {
|
||||
$this->user_id = $user;
|
||||
return $user;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a missing authentication error if all the parameters aren't
|
||||
* provided
|
||||
*/
|
||||
private function missing_auth() {
|
||||
$error = array();
|
||||
$error['error'] = __( 'You must specify both a token and API key!', 'ultimatemember' );
|
||||
|
||||
$this->data = $error;
|
||||
$this->output( 401 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an authentication failed error if the user failed to provide valid credentials
|
||||
*/
|
||||
private function invalid_auth() {
|
||||
$error = array();
|
||||
$error['error'] = __( 'Your request could not be authenticated', 'ultimatemember' );
|
||||
|
||||
$this->data = $error;
|
||||
$this->output( 401 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an invalid API key error if the API key provided couldn't be validated
|
||||
*/
|
||||
private function invalid_key() {
|
||||
$error = array();
|
||||
$error['error'] = __( 'Invalid API key', 'ultimatemember' );
|
||||
|
||||
$this->data = $error;
|
||||
$this->output( 401 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Listens for the API and then processes the API requests
|
||||
*/
|
||||
public function process_query() {
|
||||
global $wp_query;
|
||||
|
||||
// Check for um-api var. Get out if not present
|
||||
if ( ! isset( $wp_query->query_vars['um-api'] ) )
|
||||
return;
|
||||
|
||||
// Check for a valid user and set errors if necessary
|
||||
$this->validate_request();
|
||||
|
||||
// Only proceed if no errors have been noted
|
||||
if( ! $this->is_valid_request )
|
||||
return;
|
||||
|
||||
if( ! defined( 'UM_DOING_API' ) ) {
|
||||
define( 'UM_DOING_API', true );
|
||||
}
|
||||
|
||||
// Determine the kind of query
|
||||
$query_mode = $this->get_query_mode();
|
||||
foreach( $this->vars as $k ) {
|
||||
$args[ $k ] = isset( $wp_query->query_vars[ $k ] ) ? $wp_query->query_vars[ $k ] : null;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
switch( $query_mode ) :
|
||||
|
||||
case 'get.users':
|
||||
$data = $this->get_users( $args );
|
||||
break;
|
||||
|
||||
case 'get.user':
|
||||
$data = $this->get_auser( $args );
|
||||
break;
|
||||
|
||||
case 'get.following':
|
||||
$data = $this->get_following( $args );
|
||||
break;
|
||||
|
||||
case 'get.followers':
|
||||
$data = $this->get_followers( $args );
|
||||
break;
|
||||
|
||||
endswitch;
|
||||
|
||||
// Allow extensions to setup their own return data
|
||||
$this->data = apply_filters( 'um_api_output_data', $data, $query_mode, $this );
|
||||
|
||||
// Log this API request, if enabled. We log it here because we have access to errors.
|
||||
$this->log_request( $this->data );
|
||||
|
||||
// Send out data to the output function
|
||||
$this->output();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process Get followers users API Request
|
||||
*/
|
||||
public function get_followers( $args ) {
|
||||
global $ultimatemember;
|
||||
extract( $args );
|
||||
|
||||
$response = array();
|
||||
$error = array();
|
||||
|
||||
if ( !$id ) {
|
||||
$error['error'] = __('You must provide a user ID','ultimatemember');
|
||||
return $error;
|
||||
}
|
||||
|
||||
if ( class_exists( 'UM_Followers_API' ) ) {
|
||||
global $um_followers;
|
||||
$results = $um_followers->api->followers( $id );
|
||||
if ( !$results ) {
|
||||
$error['error'] = __('No users were found','ultimatemember');
|
||||
return $error;
|
||||
}
|
||||
$response['followers']['count'] = $um_followers->api->count_followers_plain( $id );
|
||||
foreach( $results as $k => $v ) {
|
||||
$user = get_userdata( $v['user_id2'] );
|
||||
$response['followers']['users'][$k]['ID'] = $v['user_id2'];
|
||||
$response['followers']['users'][$k]['username'] = $user->user_login;
|
||||
$response['followers']['users'][$k]['display_name'] = $user->display_name;
|
||||
}
|
||||
} else {
|
||||
$error['error'] = __('Invalid request','ultimatemember');
|
||||
return $error;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process Get following users API Request
|
||||
*/
|
||||
public function get_following( $args ) {
|
||||
global $ultimatemember;
|
||||
extract( $args );
|
||||
|
||||
$response = array();
|
||||
$error = array();
|
||||
|
||||
if ( !$id ) {
|
||||
$error['error'] = __('You must provide a user ID','ultimatemember');
|
||||
return $error;
|
||||
}
|
||||
|
||||
if ( class_exists( 'UM_Followers_API' ) ) {
|
||||
global $um_followers;
|
||||
$results = $um_followers->api->following( $id );
|
||||
if ( !$results ) {
|
||||
$error['error'] = __('No users were found','ultimatemember');
|
||||
return $error;
|
||||
}
|
||||
$response['following']['count'] = $um_followers->api->count_following_plain( $id );
|
||||
foreach( $results as $k => $v ) {
|
||||
$user = get_userdata( $v['user_id1'] );
|
||||
$response['following']['users'][$k]['ID'] = $v['user_id1'];
|
||||
$response['following']['users'][$k]['username'] = $user->user_login;
|
||||
$response['following']['users'][$k]['display_name'] = $user->display_name;
|
||||
}
|
||||
} else {
|
||||
$error['error'] = __('Invalid request','ultimatemember');
|
||||
return $error;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process Get users API Request
|
||||
*/
|
||||
public function get_users( $args ) {
|
||||
global $ultimatemember;
|
||||
extract( $args );
|
||||
|
||||
$response = array();
|
||||
$error = array();
|
||||
|
||||
if ( !$number )
|
||||
$number = 10;
|
||||
|
||||
if ( !$orderby )
|
||||
$orderby = 'user_registered';
|
||||
|
||||
if ( !$order )
|
||||
$order = 'desc';
|
||||
|
||||
$loop_a = array('number' => $number, 'orderby' => $orderby, 'order' => $order );
|
||||
|
||||
if ( $include ) {
|
||||
$include = explode(',', $include );
|
||||
$loop_a['include'] = $include;
|
||||
}
|
||||
|
||||
if ( $exclude ) {
|
||||
$exclude = explode(',', $exclude );
|
||||
$loop_a['exclude'] = $exclude;
|
||||
}
|
||||
|
||||
$loop = get_users( $loop_a );
|
||||
|
||||
foreach( $loop as $user ) {
|
||||
|
||||
unset( $user->data->user_status );
|
||||
unset( $user->data->user_activation_key );
|
||||
unset( $user->data->user_pass );
|
||||
|
||||
um_fetch_user( $user->ID );
|
||||
|
||||
foreach( $user as $key => $val ) {
|
||||
if ( $key != 'data' ) continue;
|
||||
if ( $key == 'data' ) {
|
||||
$key = 'profile';
|
||||
$val->roles = $user->roles;
|
||||
$val->first_name = um_user('first_name');
|
||||
$val->last_name = um_user('last_name');
|
||||
$val->community_role = um_user('role');
|
||||
$val->account_status = um_user('account_status');
|
||||
$val->profile_pic_original = $this->getsrc( um_user('profile_photo', 'original') );
|
||||
$val->profile_pic_normal = $this->getsrc( um_user('profile_photo', 200) );
|
||||
$val->profile_pic_small = $this->getsrc( um_user('profile_photo', 40) );
|
||||
$val->cover_photo = $this->getsrc( um_user('cover_photo', 1000) );
|
||||
|
||||
if ( class_exists('UM_Followers_API') ) {
|
||||
global $um_followers;
|
||||
$val->followers_count = $um_followers->api->count_followers_plain( $user->ID );
|
||||
$val->following_count = $um_followers->api->count_following_plain( $user->ID );
|
||||
}
|
||||
|
||||
}
|
||||
$response[ $user->ID ] = $val;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process Get user API Request
|
||||
*/
|
||||
public function get_auser( $args ) {
|
||||
global $ultimatemember;
|
||||
extract( $args );
|
||||
|
||||
$response = array();
|
||||
$error = array();
|
||||
|
||||
if ( !isset( $id ) ) {
|
||||
$error['error'] = __('You must provide a user ID','ultimatemember');
|
||||
return $error;
|
||||
}
|
||||
|
||||
$user = get_userdata( $id );
|
||||
if ( !$user ) {
|
||||
$error['error'] = __('Invalid user specified','ultimatemember');
|
||||
return $error;
|
||||
}
|
||||
|
||||
unset( $user->data->user_status );
|
||||
unset( $user->data->user_activation_key );
|
||||
unset( $user->data->user_pass );
|
||||
|
||||
um_fetch_user( $user->ID );
|
||||
|
||||
if ( isset( $fields ) && $fields ) {
|
||||
$fields = explode(',', $fields );
|
||||
$response['ID'] = $user->ID;
|
||||
$response['username'] = $user->user_login;
|
||||
foreach( $fields as $field ) {
|
||||
|
||||
switch( $field ) {
|
||||
|
||||
default:
|
||||
$response[$field] = ( um_profile( $field ) ) ? um_profile( $field ) : '';
|
||||
break;
|
||||
|
||||
case 'mycred_points':
|
||||
$response['mycred_points'] = number_format( (int)get_user_meta( $user->ID, 'mycred_default', true ), 2 );
|
||||
break;
|
||||
|
||||
case 'cover_photo':
|
||||
$response['cover_photo'] = $this->getsrc( um_user('cover_photo', 1000) );
|
||||
break;
|
||||
|
||||
case 'profile_pic':
|
||||
$response['profile_pic_original'] = $this->getsrc( um_user('profile_photo', 'original') );
|
||||
$response['profile_pic_normal'] = $this->getsrc( um_user('profile_photo', 200) );
|
||||
$response['profile_pic_small'] = $this->getsrc( um_user('profile_photo', 40) );
|
||||
break;
|
||||
|
||||
case 'status':
|
||||
$response['status'] = um_user('account_status');
|
||||
break;
|
||||
|
||||
case 'role':
|
||||
$response['role'] = um_user('role');
|
||||
break;
|
||||
|
||||
case 'email':
|
||||
case 'user_email':
|
||||
$response['email'] = um_user('user_email');
|
||||
break;
|
||||
|
||||
case 'followers':
|
||||
if ( class_exists('UM_Followers_API') ) {
|
||||
global $um_followers;
|
||||
$response['followers_count'] = $um_followers->api->count_followers_plain( $user->ID );
|
||||
$response['following_count'] = $um_followers->api->count_following_plain( $user->ID );
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
foreach( $user as $key => $val ) {
|
||||
if ( $key != 'data' ) continue;
|
||||
if ( $key == 'data' ) {
|
||||
$key = 'profile';
|
||||
$val->roles = $user->roles;
|
||||
$val->first_name = um_user('first_name');
|
||||
$val->last_name = um_user('last_name');
|
||||
$val->community_role = um_user('role');
|
||||
$val->account_status = um_user('account_status');
|
||||
$val->profile_pic_original = $this->getsrc( um_user('profile_photo', 'original') );
|
||||
$val->profile_pic_normal = $this->getsrc( um_user('profile_photo', 200) );
|
||||
$val->profile_pic_small = $this->getsrc( um_user('profile_photo', 40) );
|
||||
$val->cover_photo = $this->getsrc( um_user('cover_photo', 1000) );
|
||||
|
||||
if ( class_exists('UM_Followers_API') ) {
|
||||
global $um_followers;
|
||||
$val->followers_count = $um_followers->api->count_followers_plain( $user->ID );
|
||||
$val->following_count = $um_followers->api->count_following_plain( $user->ID );
|
||||
}
|
||||
|
||||
}
|
||||
$response = $val;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get source
|
||||
*/
|
||||
public function getsrc( $image ) {
|
||||
if (preg_match('/<img.+?src(?: )*=(?: )*[\'"](.*?)[\'"]/si', $image, $arrResult)) {
|
||||
return $arrResult[1];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the kind of query requested and also ensure it is a valid query
|
||||
*/
|
||||
public function get_query_mode() {
|
||||
global $wp_query;
|
||||
|
||||
// Whitelist our query options
|
||||
$accepted = apply_filters( 'um_api_valid_query_modes', array(
|
||||
'get.users',
|
||||
'get.user',
|
||||
'get.following',
|
||||
'get.followers',
|
||||
) );
|
||||
|
||||
$query = isset( $wp_query->query_vars['um-api'] ) ? $wp_query->query_vars['um-api'] : null;
|
||||
$error = array();
|
||||
// Make sure our query is valid
|
||||
if ( ! in_array( $query, $accepted ) ) {
|
||||
$error['error'] = __( 'Invalid query!', 'ultimatemember' );
|
||||
|
||||
$this->data = $error;
|
||||
$this->output();
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page number
|
||||
*/
|
||||
public function get_paged() {
|
||||
global $wp_query;
|
||||
|
||||
return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the output format
|
||||
*/
|
||||
public function get_output_format() {
|
||||
global $wp_query;
|
||||
|
||||
$format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json';
|
||||
|
||||
return apply_filters( 'um_api_output_format', $format );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log each API request, if enabled
|
||||
*/
|
||||
private function log_request( $data = array() ) {
|
||||
if ( ! $this->log_requests )
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the output data
|
||||
*/
|
||||
public function get_output() {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output Query in either JSON/XML. The query data is outputted as JSON
|
||||
* by default
|
||||
*/
|
||||
public function output( $status_code = 200 ) {
|
||||
global $wp_query;
|
||||
|
||||
$format = $this->get_output_format();
|
||||
|
||||
status_header( $status_code );
|
||||
|
||||
do_action( 'um_api_output_before', $this->data, $this, $format );
|
||||
|
||||
switch ( $format ) :
|
||||
|
||||
case 'xml' :
|
||||
|
||||
require_once um_path . 'core/lib/array2xml.php';
|
||||
$xml = Array2XML::createXML( 'um', $this->data );
|
||||
echo $xml->saveXML();
|
||||
|
||||
break;
|
||||
|
||||
case 'json' :
|
||||
case '' :
|
||||
|
||||
header( 'Content-Type: application/json' );
|
||||
if ( ! empty( $this->pretty_print ) )
|
||||
echo json_encode( $this->data, $this->pretty_print );
|
||||
else
|
||||
echo json_encode( $this->data );
|
||||
|
||||
break;
|
||||
|
||||
|
||||
default :
|
||||
|
||||
// Allow other formats to be added via extensions
|
||||
do_action( 'um_api_output_' . $format, $this->data, $this );
|
||||
|
||||
break;
|
||||
|
||||
endswitch;
|
||||
|
||||
do_action( 'um_api_output_after', $this->data, $this, $format );
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify User Profile
|
||||
*/
|
||||
function user_key_field( $user ) {
|
||||
if ( current_user_can( 'edit_users' ) && current_user_can( 'edit_user', $user->ID ) ) {
|
||||
$user = get_userdata( $user->ID );
|
||||
?>
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>
|
||||
<label for="um_set_api_key"><?php _e( 'Ultimate Member REST API', 'ultimatemember' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<?php if ( empty( $user->um_user_public_key ) ) { ?>
|
||||
<p><input name="um_set_api_key" type="checkbox" id="um_set_api_key" value="0" />
|
||||
<span class="description"><?php _e( 'Generate API Key', 'ultimatemember' ); ?></span></p>
|
||||
<?php } else { ?>
|
||||
<p>
|
||||
<strong><?php _e( 'Public key:', 'ultimatemember' ); ?> </strong><span id="publickey"><?php echo $user->um_user_public_key; ?></span><br/>
|
||||
<strong><?php _e( 'Secret key:', 'ultimatemember' ); ?> </strong><span id="privatekey"><?php echo $user->um_user_secret_key; ?></span><br/>
|
||||
<strong><?php _e( 'Token:', 'ultimatemember' ); ?> </strong><span id="token"><?php echo $this->get_token( $user->ID ); ?></span>
|
||||
</p>
|
||||
<p><input name="um_set_api_key" type="checkbox" id="um_set_api_key" value="0" />
|
||||
<span class="description"><?php _e( 'Revoke API Keys', 'ultimatemember' ); ?></span></p>
|
||||
<?php } ?>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php }
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate new API keys for a user
|
||||
*/
|
||||
public function generate_api_key( $user_id = 0, $regenerate = false ) {
|
||||
|
||||
if( empty( $user_id ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = get_userdata( $user_id );
|
||||
|
||||
if( ! $user ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $user->um_user_public_key ) ) {
|
||||
update_user_meta( $user_id, 'um_user_public_key', $this->generate_public_key( $user->user_email ) );
|
||||
update_user_meta( $user_id, 'um_user_secret_key', $this->generate_private_key( $user->ID ) );
|
||||
} elseif( $regenerate == true ) {
|
||||
$this->revoke_api_key( $user->ID );
|
||||
update_user_meta( $user_id, 'um_user_public_key', $this->generate_public_key( $user->user_email ) );
|
||||
update_user_meta( $user_id, 'um_user_secret_key', $this->generate_private_key( $user->ID ) );
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke a users API keys
|
||||
*/
|
||||
public function revoke_api_key( $user_id = 0 ) {
|
||||
|
||||
if( empty( $user_id ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = get_userdata( $user_id );
|
||||
|
||||
if( ! $user ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! empty( $user->um_user_public_key ) ) {
|
||||
delete_transient( md5( 'um_api_user_' . $user->um_user_public_key ) );
|
||||
delete_user_meta( $user_id, 'um_user_public_key' );
|
||||
delete_user_meta( $user_id, 'um_user_secret_key' );
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate and Save API key
|
||||
*/
|
||||
public function update_key( $user_id ) {
|
||||
if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['um_set_api_key'] ) ) {
|
||||
|
||||
$user = get_userdata( $user_id );
|
||||
|
||||
if ( empty( $user->um_user_public_key ) ) {
|
||||
update_user_meta( $user_id, 'um_user_public_key', $this->generate_public_key( $user->user_email ) );
|
||||
update_user_meta( $user_id, 'um_user_secret_key', $this->generate_private_key( $user->ID ) );
|
||||
} else {
|
||||
$this->revoke_api_key( $user_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the public key for a user
|
||||
*/
|
||||
private function generate_public_key( $user_email = '' ) {
|
||||
$auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
|
||||
$public = hash( 'md5', $user_email . $auth_key . date( 'U' ) );
|
||||
return $public;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the secret key for a user
|
||||
*/
|
||||
private function generate_private_key( $user_id = 0 ) {
|
||||
$auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
|
||||
$secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) );
|
||||
return $secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the user's token
|
||||
*/
|
||||
private function get_token( $user_id = 0 ) {
|
||||
$user = get_userdata( $user_id );
|
||||
return hash( 'md5', $user->um_user_secret_key . $user->um_user_public_key );
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -86,7 +86,7 @@ class UM_Enqueue {
|
||||
) );
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
wp_register_script('um_minified', um_url . 'assets/js/um.min.js', array('jquery'), ultimatemember_version, true );
|
||||
wp_enqueue_script('um_minified');
|
||||
|
||||
|
||||
+26
-35
@@ -245,8 +245,12 @@ class UM_Fields {
|
||||
/***
|
||||
*** @Print field error
|
||||
***/
|
||||
function field_error($text) {
|
||||
function field_error($text, $force_show = false ) {
|
||||
global $ultimatemember;
|
||||
if ( $force_show ) {
|
||||
$output = '<div class="um-field-error"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>'.$text.'</div>';
|
||||
return $output;
|
||||
}
|
||||
if ( isset( $this->set_id ) && $ultimatemember->form->processing == $this->set_id ) {
|
||||
$output = '<div class="um-field-error"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>'.$text.'</div>';
|
||||
} else {
|
||||
@@ -598,30 +602,18 @@ class UM_Fields {
|
||||
|
||||
$array['input'] = 'text';
|
||||
|
||||
if (!isset($array['autocomplete'])) $array['autocomplete'] = 'on';
|
||||
|
||||
if ( $key == 'user_login' ) $array['autocomplete'] = 'off';
|
||||
|
||||
break;
|
||||
|
||||
case 'password':
|
||||
|
||||
$array['input'] = 'password';
|
||||
|
||||
if (!isset($array['autocomplete'])) $array['autocomplete'] = 'on';
|
||||
|
||||
$array['autocomplete'] = 'off';
|
||||
|
||||
break;
|
||||
|
||||
case 'url':
|
||||
|
||||
$array['input'] = 'text';
|
||||
|
||||
if (!isset($array['autocomplete'])) $array['autocomplete'] = 'on';
|
||||
|
||||
if ( $key == 'user_login' ) $array['autocomplete'] = 'off';
|
||||
|
||||
break;
|
||||
|
||||
case 'date':
|
||||
@@ -697,9 +689,7 @@ class UM_Fields {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!isset($array['autocomplete'])) $array['autocomplete'] = 'on';
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case 'time':
|
||||
@@ -723,8 +713,6 @@ class UM_Fields {
|
||||
$array['js_format'] = $js_format;
|
||||
|
||||
if ( !isset( $array['intervals'] ) ) $array['intervals'] = 60;
|
||||
|
||||
if (!isset($array['autocomplete'])) $array['autocomplete'] = 'on';
|
||||
|
||||
break;
|
||||
|
||||
@@ -946,7 +934,7 @@ class UM_Fields {
|
||||
|
||||
}
|
||||
|
||||
$output .= '<input '.$disabled.' class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="'. $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" autocomplete="'.$autocomplete.'" />
|
||||
$output .= '<input '.$disabled.' class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="'. $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" />
|
||||
|
||||
</div>';
|
||||
|
||||
@@ -980,7 +968,7 @@ class UM_Fields {
|
||||
|
||||
}
|
||||
|
||||
$output .= '<input class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="'. $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" autocomplete="'.$autocomplete.'" />
|
||||
$output .= '<input class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="'. $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" />
|
||||
|
||||
</div>';
|
||||
|
||||
@@ -1009,7 +997,7 @@ class UM_Fields {
|
||||
|
||||
}
|
||||
|
||||
$output .= '<input class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="' . $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" autocomplete="'.$autocomplete.'" />
|
||||
$output .= '<input class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="' . $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" />
|
||||
|
||||
</div>';
|
||||
|
||||
@@ -1043,7 +1031,7 @@ class UM_Fields {
|
||||
|
||||
}
|
||||
|
||||
$output .= '<input class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="'. $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" autocomplete="'.$autocomplete.'" />
|
||||
$output .= '<input class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="'. $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" />
|
||||
|
||||
</div>';
|
||||
|
||||
@@ -1070,7 +1058,7 @@ class UM_Fields {
|
||||
|
||||
}
|
||||
|
||||
$output .= '<input class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="' . $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" autocomplete="'.$autocomplete.'" />
|
||||
$output .= '<input class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="' . $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" />
|
||||
|
||||
</div>';
|
||||
|
||||
@@ -1103,7 +1091,7 @@ class UM_Fields {
|
||||
|
||||
}
|
||||
|
||||
$output .= '<input class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="'. $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" autocomplete="'.$autocomplete.'" />
|
||||
$output .= '<input class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="'. $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" />
|
||||
|
||||
</div>';
|
||||
|
||||
@@ -1131,7 +1119,7 @@ class UM_Fields {
|
||||
|
||||
}
|
||||
|
||||
$output .= '<input class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="'. $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" autocomplete="'.$autocomplete.'" data-range="'.$range.'" data-years="'.$years.'" data-years_x="'.$years_x.'" data-disabled_weekdays="'.$disabled_weekdays.'" data-date_min="'.$date_min.'" data-date_max="'.$date_max.'" data-format="'.$js_format.'" data-value="'. $this->field_value( $key, $default, $data ) .'" />
|
||||
$output .= '<input class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="'. $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" data-range="'.$range.'" data-years="'.$years.'" data-years_x="'.$years_x.'" data-disabled_weekdays="'.$disabled_weekdays.'" data-date_min="'.$date_min.'" data-date_max="'.$date_max.'" data-format="'.$js_format.'" data-value="'. $this->field_value( $key, $default, $data ) .'" />
|
||||
|
||||
</div>';
|
||||
|
||||
@@ -1159,7 +1147,7 @@ class UM_Fields {
|
||||
|
||||
}
|
||||
|
||||
$output .= '<input class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="'. $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" autocomplete="'.$autocomplete.'" data-format="'.$js_format.'" data-intervals="'.$intervals.'" data-value="'. $this->field_value( $key, $default, $data ) .'" />
|
||||
$output .= '<input class="'.$this->get_class($key, $data).'" type="'.$input.'" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="'. $this->field_value( $key, $default, $data ) .'" placeholder="'.$placeholder.'" data-validate="'.$validate.'" data-key="'.$key.'" data-format="'.$js_format.'" data-intervals="'.$intervals.'" data-value="'. $this->field_value( $key, $default, $data ) .'" />
|
||||
|
||||
</div>';
|
||||
|
||||
@@ -1232,7 +1220,13 @@ class UM_Fields {
|
||||
case 'image':
|
||||
$output .= '<div class="um-field' . $classes . '"' . $conditional . ' data-key="'.$key.'">';
|
||||
|
||||
$output .= '<input type="hidden" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="'. $this->field_value( $key, $default, $data ) . '" />';
|
||||
if ( in_array( $key, array('profile_photo','cover_photo') ) ) {
|
||||
$field_value = '';
|
||||
} else {
|
||||
$field_value = $this->field_value( $key, $default, $data );
|
||||
}
|
||||
|
||||
$output .= '<input type="hidden" name="'.$key.$ultimatemember->form->form_suffix.'" id="'.$key.$ultimatemember->form->form_suffix.'" value="'. $field_value . '" />';
|
||||
|
||||
if ( isset( $data['label'] ) ) {
|
||||
$output .= $this->field_label($label, $key, $data);
|
||||
@@ -1244,17 +1238,14 @@ class UM_Fields {
|
||||
|
||||
if ( $this->field_value( $key, $default, $data ) ) {
|
||||
|
||||
$uri = um_user_uploads_uri() . $this->field_value( $key, $default, $data );
|
||||
|
||||
if ( isset( $ultimatemember->form->errors ) && !empty( $ultimatemember->form->errors ) ) {
|
||||
if ( isset( $this->set_mode ) && $this->set_mode == 'register' ) {
|
||||
$uri = $this->field_value( $key, $default, $data );
|
||||
}
|
||||
if ( !in_array( $key, array('profile_photo','cover_photo') ) ) {
|
||||
$img = '<img src="' . um_user_uploads_uri() . $this->field_value( $key, $default, $data ) . '" alt="" />';
|
||||
} else {
|
||||
$img = '';
|
||||
}
|
||||
|
||||
$output .= '<div class="um-single-image-preview show '. $crop_class .'" data-crop="'.$crop_data.'" data-key="'.$key.'">
|
||||
<a href="#" class="cancel"><i class="um-icon-close"></i></a>
|
||||
<img src="' . $uri . '" alt="" />
|
||||
<a href="#" class="cancel"><i class="um-icon-close"></i></a>' . $img . '
|
||||
</div><a href="#" data-modal="um_upload_single" data-modal-size="'.$modal_size.'" data-modal-copy="1" class="um-button um-btn-auto-width">'. __('Change photo') . '</a>';
|
||||
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ class UM_Form {
|
||||
if ( $form_timestamp == '' && um_get_option('enable_timebot') == 1 )
|
||||
wp_die( __('Hello, spam bot!') );
|
||||
|
||||
if ( $live_timestamp - $form_timestamp < 6 && um_get_option('enable_timebot') == 1 )
|
||||
if ( !current_user_can('manage_options') && $live_timestamp - $form_timestamp < 6 && um_get_option('enable_timebot') == 1 )
|
||||
wp_die( __('Whoa, slow down! You\'re seeing this message because you tried to submit a form too fast and we think you might be a spam bot. If you are a real human being please wait a few seconds before submitting the form. Thanks!') );
|
||||
|
||||
}
|
||||
|
||||
+17
-2
@@ -41,13 +41,28 @@ class UM_Profile {
|
||||
return $primary;
|
||||
}
|
||||
|
||||
/***
|
||||
*** @Activated tabs in backend
|
||||
***/
|
||||
function tabs_enabled(){
|
||||
$tabs = $this->tabs();
|
||||
foreach( $tabs as $id => $info ){
|
||||
if ( isset( $info['name'] ) ) {
|
||||
if ( um_get_option('profile_tab_'.$id) || isset( $info['_builtin'] ) ) {
|
||||
$primary[$id] = $info['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return ( isset( $primary ) ) ? $primary : '';
|
||||
}
|
||||
|
||||
/***
|
||||
*** @Get active_tab
|
||||
***/
|
||||
function active_tab() {
|
||||
|
||||
|
||||
$this->active_tab = um_get_option('profile_menu_default_tab');
|
||||
|
||||
|
||||
if ( get_query_var('profiletab') ) {
|
||||
$this->active_tab = get_query_var('profiletab');
|
||||
}
|
||||
|
||||
@@ -22,12 +22,18 @@
|
||||
*
|
||||
*/
|
||||
function um_user_ip() {
|
||||
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
|
||||
return $_SERVER['HTTP_CLIENT_IP'];
|
||||
} else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
return $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
$ip = '127.0.0.1';
|
||||
|
||||
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
|
||||
//check ip from share internet
|
||||
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
||||
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
|
||||
//to check ip is pass from proxy
|
||||
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
} elseif( ! empty( $_SERVER['REMOTE_ADDR'] ) ) {
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
return $_SERVER['REMOTE_ADDR'];
|
||||
return apply_filters( 'um_user_ip', $ip );
|
||||
}
|
||||
|
||||
/***
|
||||
@@ -490,6 +496,7 @@ function um_reset_user() {
|
||||
***/
|
||||
function um_edit_my_profile_cancel_uri() {
|
||||
$url = remove_query_arg( 'um_action' );
|
||||
$url = remove_query_arg( 'profiletab', $url );
|
||||
return $url;
|
||||
}
|
||||
|
||||
@@ -873,6 +880,10 @@ function um_fetch_user( $user_id ) {
|
||||
|
||||
}
|
||||
|
||||
if ( $attrs == 'original' ) {
|
||||
$uri = um_user_uploads_uri() . 'profile_photo.jpg?' . current_time( 'timestamp' );
|
||||
}
|
||||
|
||||
}
|
||||
return $uri;
|
||||
}
|
||||
|
||||
+20
-2
@@ -30,9 +30,21 @@ class UM_User {
|
||||
);
|
||||
|
||||
$this->target_id = null;
|
||||
|
||||
// When the cache should be cleared
|
||||
add_action('um_delete_user_hook', array(&$this, 'remove_cached_queue') );
|
||||
add_action('um_new_user_registration_plain', array(&$this, 'remove_cached_queue') );
|
||||
add_action('um_after_user_status_is_changed_hook', array(&$this, 'remove_cached_queue') );
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
*** @Remove cached queue from Users backend
|
||||
***/
|
||||
function remove_cached_queue() {
|
||||
delete_option('um_cached_users_queue');
|
||||
}
|
||||
|
||||
/***
|
||||
*** @Converts object to array
|
||||
***/
|
||||
@@ -305,7 +317,9 @@ class UM_User {
|
||||
|
||||
$this->update_usermeta_info('account_status');
|
||||
|
||||
do_action('um_after_user_status_is_changed', $status);
|
||||
do_action( 'um_after_user_status_is_changed_hook' );
|
||||
|
||||
do_action( 'um_after_user_status_is_changed', $status);
|
||||
|
||||
}
|
||||
|
||||
@@ -481,15 +495,19 @@ class UM_User {
|
||||
function delete( $send_mail = true ) {
|
||||
global $ultimatemember;
|
||||
|
||||
do_action( 'um_delete_user_hook' );
|
||||
do_action( 'um_delete_user', um_user('ID') );
|
||||
|
||||
// send email notifications
|
||||
if ( $send_mail ) {
|
||||
$ultimatemember->mail->send( um_user('user_email'), 'deletion_email' );
|
||||
$ultimatemember->mail->send( um_admin_email(), 'notification_deletion', array('admin' => true ) );
|
||||
}
|
||||
|
||||
// remove uploads
|
||||
$ultimatemember->files->remove_dir( um_user_uploads_dir() );
|
||||
|
||||
|
||||
// remove user
|
||||
if ( is_multisite() ) {
|
||||
|
||||
if ( !function_exists('wpmu_delete_user') ) {
|
||||
|
||||
Reference in New Issue
Block a user