2017-07-26 14:57:52 +03:00
|
|
|
<?php
|
|
|
|
|
namespace um\core;
|
|
|
|
|
|
|
|
|
|
// Exit if accessed directly
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit;
|
|
|
|
|
|
2018-03-26 01:27:46 +03:00
|
|
|
if ( ! class_exists( 'um\core\Form' ) ) {
|
2017-07-26 14:57:52 +03:00
|
|
|
|
2018-03-20 13:24:38 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class Form
|
|
|
|
|
* @package um\core
|
|
|
|
|
*/
|
|
|
|
|
class Form {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var null
|
|
|
|
|
*/
|
|
|
|
|
public $form_suffix;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var
|
|
|
|
|
*/
|
|
|
|
|
var $form_id;
|
|
|
|
|
|
|
|
|
|
|
2019-08-23 20:22:42 +03:00
|
|
|
/**
|
|
|
|
|
* @var null
|
|
|
|
|
*/
|
|
|
|
|
var $post_form = null;
|
|
|
|
|
|
|
|
|
|
|
2021-08-19 12:58:13 +03:00
|
|
|
var $nonce = null;
|
|
|
|
|
|
|
|
|
|
|
2018-03-20 13:24:38 +02:00
|
|
|
/**
|
|
|
|
|
* Form constructor.
|
|
|
|
|
*/
|
|
|
|
|
function __construct() {
|
|
|
|
|
|
|
|
|
|
$this->form_suffix = null;
|
|
|
|
|
|
|
|
|
|
$this->errors = null;
|
|
|
|
|
|
|
|
|
|
$this->processing = null;
|
|
|
|
|
|
2019-08-23 20:22:42 +03:00
|
|
|
add_action( 'template_redirect', array( &$this, 'form_init' ), 2 );
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2019-08-23 20:22:42 +03:00
|
|
|
add_action( 'init', array( &$this, 'field_declare' ), 10 );
|
2018-03-20 13:24:38 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2021-06-29 02:51:54 +03:00
|
|
|
public function ajax_muted_action() {
|
2018-11-21 14:01:18 +02:00
|
|
|
UM()->check_ajax_nonce();
|
|
|
|
|
|
2021-06-29 02:51:54 +03:00
|
|
|
/**
|
|
|
|
|
* @var $user_id
|
|
|
|
|
* @var $hook
|
|
|
|
|
*/
|
2018-03-20 13:24:38 +02:00
|
|
|
extract( $_REQUEST );
|
|
|
|
|
|
2021-06-29 02:51:54 +03:00
|
|
|
if ( isset( $user_id ) ) {
|
|
|
|
|
$user_id = absint( $user_id );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isset( $hook ) ) {
|
|
|
|
|
$hook = sanitize_key( $hook );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( ! UM()->roles()->um_current_user_can( 'edit', $user_id ) ) {
|
|
|
|
|
die( esc_html__( 'You can not edit this user', 'ultimate-member' ) );
|
|
|
|
|
}
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2021-06-29 02:51:54 +03:00
|
|
|
switch ( $hook ) {
|
2018-03-20 13:24:38 +02:00
|
|
|
default:
|
|
|
|
|
/**
|
|
|
|
|
* UM hook
|
|
|
|
|
*
|
|
|
|
|
* @type action
|
|
|
|
|
* @title um_run_ajax_function__{$hook}
|
|
|
|
|
* @description Action on AJAX muted action
|
|
|
|
|
* @input_vars
|
|
|
|
|
* [{"var":"$request","type":"int","desc":"Request"}]
|
|
|
|
|
* @change_log
|
|
|
|
|
* ["Since: 2.0"]
|
|
|
|
|
* @usage add_action( 'um_run_ajax_function__{$hook}', 'function_name', 10, 1 );
|
|
|
|
|
* @example
|
|
|
|
|
* <?php
|
|
|
|
|
* add_action( 'um_run_ajax_function__{$hook}', 'my_run_ajax_function', 10, 1 );
|
|
|
|
|
* function my_run_ajax_function( $request ) {
|
|
|
|
|
* // your code here
|
|
|
|
|
* }
|
|
|
|
|
* ?>
|
|
|
|
|
*/
|
|
|
|
|
do_action( "um_run_ajax_function__{$hook}", $_REQUEST );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
public function ajax_select_options() {
|
2018-11-21 14:01:18 +02:00
|
|
|
UM()->check_ajax_nonce();
|
2018-07-13 13:33:28 +03:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
$arr_options = array();
|
2018-03-20 13:24:38 +02:00
|
|
|
$arr_options['status'] = 'success';
|
2021-06-29 21:15:48 +03:00
|
|
|
$arr_options['post'] = $_POST;
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2022-05-24 18:29:39 +03:00
|
|
|
// Callback validation
|
|
|
|
|
if ( empty( $_POST['child_callback'] ) ) {
|
|
|
|
|
$arr_options['status'] = 'error';
|
|
|
|
|
$arr_options['message'] = __( 'Wrong callback.', 'ultimate-member' );
|
|
|
|
|
|
|
|
|
|
wp_send_json( $arr_options );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$ajax_source_func = sanitize_text_field( $_POST['child_callback'] );
|
|
|
|
|
|
|
|
|
|
if ( ! function_exists( $ajax_source_func ) ) {
|
|
|
|
|
$arr_options['status'] = 'error';
|
|
|
|
|
$arr_options['message'] = __( 'Wrong callback.', 'ultimate-member' );
|
|
|
|
|
|
|
|
|
|
wp_send_json( $arr_options );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$allowed_callbacks = UM()->options()->get( 'allowed_choice_callbacks' );
|
2022-06-08 21:24:23 +03:00
|
|
|
|
2022-05-24 18:29:39 +03:00
|
|
|
if ( empty( $allowed_callbacks ) ) {
|
|
|
|
|
$arr_options['status'] = 'error';
|
|
|
|
|
$arr_options['message'] = __( 'This is not possible for security reasons.', 'ultimate-member' );
|
|
|
|
|
wp_send_json( $arr_options );
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-08 21:24:23 +03:00
|
|
|
$allowed_callbacks = array_map( 'rtrim', explode( "\n", wp_unslash( $allowed_callbacks ) ) );
|
2022-05-24 18:29:39 +03:00
|
|
|
|
|
|
|
|
if ( ! in_array( $ajax_source_func, $allowed_callbacks, true ) ) {
|
|
|
|
|
$arr_options['status'] = 'error';
|
|
|
|
|
$arr_options['message'] = __( 'This is not possible for security reasons.', 'ultimate-member' );
|
|
|
|
|
|
|
|
|
|
wp_send_json( $arr_options );
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-30 12:31:40 +03:00
|
|
|
if ( in_array( $ajax_source_func, UM()->fields()->dropdown_options_source_blacklist(), true ) ) {
|
|
|
|
|
$arr_options['status'] = 'error';
|
|
|
|
|
$arr_options['message'] = __( 'This is not possible for security reasons.', 'ultimate-member' );
|
|
|
|
|
|
|
|
|
|
wp_send_json( $arr_options );
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-15 02:46:47 +02:00
|
|
|
if ( isset( $_POST['form_id'] ) ) {
|
|
|
|
|
UM()->fields()->set_id = absint( $_POST['form_id'] );
|
|
|
|
|
}
|
2018-03-20 13:24:38 +02:00
|
|
|
UM()->fields()->set_mode = 'profile';
|
2021-06-29 21:15:48 +03:00
|
|
|
$form_fields = UM()->fields()->get_fields();
|
|
|
|
|
$arr_options['fields'] = $form_fields;
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
if ( isset( $arr_options['post']['members_directory'] ) && 'yes' === $arr_options['post']['members_directory'] ) {
|
2022-05-24 18:29:39 +03:00
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
|
|
$values_array = $wpdb->get_col(
|
|
|
|
|
$wpdb->prepare(
|
|
|
|
|
"SELECT DISTINCT meta_value
|
|
|
|
|
FROM $wpdb->usermeta
|
|
|
|
|
WHERE meta_key = %s AND
|
|
|
|
|
meta_value != ''",
|
|
|
|
|
$arr_options['post']['child_name']
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ( ! empty( $values_array ) ) {
|
|
|
|
|
$parent_dropdown = isset( $arr_options['field']['parent_dropdown_relationship'] ) ? $arr_options['field']['parent_dropdown_relationship'] : '';
|
|
|
|
|
$arr_options['items'] = call_user_func( $ajax_source_func, $parent_dropdown );
|
|
|
|
|
|
|
|
|
|
if ( array_keys( $arr_options['items'] ) !== range( 0, count( $arr_options['items'] ) - 1 ) ) {
|
|
|
|
|
// array with dropdown items is associative
|
|
|
|
|
$arr_options['items'] = array_intersect_key( array_map( 'trim', $arr_options['items'] ), array_flip( $values_array ) );
|
2019-11-22 11:55:21 +02:00
|
|
|
} else {
|
2022-05-24 18:29:39 +03:00
|
|
|
// array with dropdown items has sequential numeric keys, starting from 0 and there are intersected values with $values_array
|
|
|
|
|
$arr_options['items'] = array_intersect( $arr_options['items'], $values_array );
|
2019-11-22 11:55:21 +02:00
|
|
|
}
|
2022-05-24 18:29:39 +03:00
|
|
|
} else {
|
|
|
|
|
$arr_options['items'] = array();
|
2018-07-13 13:33:28 +03:00
|
|
|
}
|
2022-05-24 18:29:39 +03:00
|
|
|
|
|
|
|
|
wp_send_json( $arr_options );
|
2018-07-13 13:33:28 +03:00
|
|
|
} else {
|
|
|
|
|
/**
|
|
|
|
|
* UM hook
|
|
|
|
|
*
|
|
|
|
|
* @type filter
|
|
|
|
|
* @title um_ajax_select_options__debug_mode
|
|
|
|
|
* @description Activate debug mode for AJAX select options
|
|
|
|
|
* @input_vars
|
|
|
|
|
* [{"var":"$debug_mode","type":"bool","desc":"Enable Debug mode"}]
|
|
|
|
|
* @change_log
|
|
|
|
|
* ["Since: 2.0"]
|
|
|
|
|
* @usage
|
|
|
|
|
* <?php add_filter( 'um_ajax_select_options__debug_mode', 'function_name', 10, 1 ); ?>
|
|
|
|
|
* @example
|
|
|
|
|
* <?php
|
|
|
|
|
* add_filter( 'um_ajax_select_options__debug_mode', 'my_ajax_select_options__debug_mode', 10, 1 );
|
|
|
|
|
* function my_ajax_select_options__debug_mode( $debug_mode ) {
|
|
|
|
|
* // your code here
|
|
|
|
|
* return $debug_mode;
|
|
|
|
|
* }
|
|
|
|
|
* ?>
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
$debug = apply_filters( 'um_ajax_select_options__debug_mode', false );
|
|
|
|
|
if ( $debug ) {
|
2018-07-13 13:33:28 +03:00
|
|
|
$arr_options['debug'] = array(
|
|
|
|
|
$_POST,
|
|
|
|
|
$form_fields,
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2020-03-02 16:47:56 +02:00
|
|
|
if ( ! empty( $_POST['child_callback'] ) && isset( $form_fields[ $_POST['child_name'] ] ) ) {
|
2018-07-13 13:33:28 +03:00
|
|
|
// If the requested callback function is added in the form or added in the field option, execute it with call_user_func.
|
|
|
|
|
if ( isset( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) &&
|
|
|
|
|
! empty( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) &&
|
2021-06-29 21:15:48 +03:00
|
|
|
$form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] === $ajax_source_func ) {
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2018-07-13 13:33:28 +03:00
|
|
|
$arr_options['field'] = $form_fields[ $_POST['child_name'] ];
|
|
|
|
|
|
2022-05-24 18:29:39 +03:00
|
|
|
$arr_options['items'] = call_user_func( $ajax_source_func, $arr_options['field']['parent_dropdown_relationship'] );
|
2018-07-13 13:33:28 +03:00
|
|
|
} else {
|
2021-06-29 21:15:48 +03:00
|
|
|
$arr_options['status'] = 'error';
|
2020-03-02 16:47:56 +02:00
|
|
|
$arr_options['message'] = __( 'This is not possible for security reasons.', 'ultimate-member' );
|
2018-03-20 13:24:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-13 13:33:28 +03:00
|
|
|
wp_send_json( $arr_options );
|
2018-03-20 13:24:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Count the form errors.
|
|
|
|
|
* @return integer
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
public function count_errors() {
|
2018-03-20 13:24:38 +02:00
|
|
|
$errors = $this->errors;
|
|
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
if ( $errors && is_array( $errors ) ) {
|
2018-03-20 13:24:38 +02:00
|
|
|
return count( $errors );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Appends field errors
|
2021-06-29 21:15:48 +03:00
|
|
|
*
|
2018-03-20 13:24:38 +02:00
|
|
|
* @param string $key
|
|
|
|
|
* @param string $error
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
public function add_error( $key, $error ) {
|
|
|
|
|
if ( ! isset( $this->errors[ $key ] ) ) {
|
2018-03-20 13:24:38 +02:00
|
|
|
/**
|
|
|
|
|
* UM hook
|
|
|
|
|
*
|
|
|
|
|
* @type filter
|
|
|
|
|
* @title um_submit_form_error
|
|
|
|
|
* @description Change error text on submit form
|
|
|
|
|
* @input_vars
|
|
|
|
|
* [{"var":"$error","type":"string","desc":"Error String"},
|
|
|
|
|
* {"var":"$key","type":"string","desc":"Error Key"}]
|
|
|
|
|
* @change_log
|
|
|
|
|
* ["Since: 2.0"]
|
|
|
|
|
* @usage
|
|
|
|
|
* <?php add_filter( 'um_submit_form_error', 'function_name', 10, 2 ); ?>
|
|
|
|
|
* @example
|
|
|
|
|
* <?php
|
|
|
|
|
* add_filter( 'um_submit_form_error', 'my_submit_form_error', 10, 2 );
|
|
|
|
|
* function my_submit_form_error( $error, $key ) {
|
|
|
|
|
* // your code here
|
|
|
|
|
* return $error;
|
|
|
|
|
* }
|
|
|
|
|
* ?>
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
$this->errors[ $key ] = apply_filters( 'um_submit_form_error', $error, $key );
|
2018-03-20 13:24:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-08 17:51:23 +08:00
|
|
|
/**
|
|
|
|
|
* Appends field notices
|
|
|
|
|
* @param string $key
|
|
|
|
|
* @param string $notice
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
public function add_notice( $key, $notice ) {
|
|
|
|
|
if ( ! isset( $this->notices[ $key ] ) ) {
|
2020-01-08 17:51:23 +08:00
|
|
|
/**
|
|
|
|
|
* UM hook
|
|
|
|
|
*
|
|
|
|
|
* @type filter
|
|
|
|
|
* @title um_submit_form_notice
|
|
|
|
|
* @description Change notice text on submit form
|
|
|
|
|
* @input_vars
|
|
|
|
|
* [{"var":"$notice","type":"string","desc":"notice String"},
|
|
|
|
|
* {"var":"$key","type":"string","desc":"notice Key"}]
|
|
|
|
|
* @change_log
|
|
|
|
|
* ["Since: 2.0"]
|
|
|
|
|
* @usage
|
|
|
|
|
* <?php add_filter( 'um_submit_form_notice', 'function_name', 10, 2 ); ?>
|
|
|
|
|
* @example
|
|
|
|
|
* <?php
|
|
|
|
|
* add_filter( 'um_submit_form_notice', 'my_submit_form_notice', 10, 2 );
|
|
|
|
|
* function my_submit_form_notice( $notice, $key ) {
|
|
|
|
|
* // your code here
|
|
|
|
|
* return $notice;
|
|
|
|
|
* }
|
|
|
|
|
* ?>
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
$this->notices[ $key ] = apply_filters( 'um_submit_form_notice', $notice, $key );
|
2020-01-08 17:51:23 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-20 13:24:38 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If a form has errors
|
2021-06-29 21:15:48 +03:00
|
|
|
*
|
2018-03-20 13:24:38 +02:00
|
|
|
* @param string $key
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
public function has_error( $key ) {
|
2019-08-23 20:22:42 +03:00
|
|
|
if ( isset( $this->errors[ $key ] ) ) {
|
2018-03-20 13:24:38 +02:00
|
|
|
return true;
|
2019-08-23 20:22:42 +03:00
|
|
|
}
|
2018-03-20 13:24:38 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
|
2020-01-08 17:51:23 +08:00
|
|
|
/**
|
|
|
|
|
* If a form has notices/info
|
2021-06-29 21:15:48 +03:00
|
|
|
*
|
2020-01-08 17:51:23 +08:00
|
|
|
* @param string $key
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
public function has_notice( $key ) {
|
2020-01-08 17:51:23 +08:00
|
|
|
if ( isset( $this->notices[ $key ] ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2021-05-20 09:57:12 -05:00
|
|
|
/**
|
|
|
|
|
* Return the errors as a WordPress Error object
|
2021-08-23 17:13:39 +03:00
|
|
|
*
|
|
|
|
|
* @return \WP_Error
|
2021-05-20 09:57:12 -05:00
|
|
|
*/
|
|
|
|
|
function get_wp_error() {
|
|
|
|
|
$wp_error = new \WP_Error();
|
|
|
|
|
if ( $this->count_errors() > 0 ) {
|
|
|
|
|
foreach ( $this->errors as $key => $value ) {
|
|
|
|
|
$wp_error->add( $key, $value );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $wp_error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-03-20 13:24:38 +02:00
|
|
|
/**
|
|
|
|
|
* Declare all fields
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
public function field_declare() {
|
2018-03-20 13:24:38 +02:00
|
|
|
if ( isset( UM()->builtin()->custom_fields ) ) {
|
|
|
|
|
$this->all_fields = UM()->builtin()->custom_fields;
|
|
|
|
|
} else {
|
|
|
|
|
$this->all_fields = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-23 20:22:42 +03:00
|
|
|
* Validate form on submit
|
2018-03-20 13:24:38 +02:00
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
public function form_init() {
|
2018-03-20 13:24:38 +02:00
|
|
|
if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
|
2021-06-29 21:15:48 +03:00
|
|
|
$http_post = ( 'POST' === $_SERVER['REQUEST_METHOD'] );
|
2018-03-20 13:24:38 +02:00
|
|
|
} else {
|
|
|
|
|
$http_post = 'POST';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $http_post && ! is_admin() && isset( $_POST['form_id'] ) && is_numeric( $_POST['form_id'] ) ) {
|
|
|
|
|
|
2021-08-19 12:58:13 +03:00
|
|
|
$this->form_id = absint( $_POST['form_id'] );
|
|
|
|
|
if ( 'um_form' !== get_post_type( $this->form_id ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-29 21:15:48 +03:00
|
|
|
|
2021-08-19 12:58:13 +03:00
|
|
|
$this->form_status = get_post_status( $this->form_id );
|
2021-06-29 21:15:48 +03:00
|
|
|
if ( 'publish' !== $this->form_status ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 12:58:13 +03:00
|
|
|
$this->form_data = UM()->query()->post_data( $this->form_id );
|
|
|
|
|
|
2018-03-20 13:24:38 +02:00
|
|
|
/**
|
|
|
|
|
* UM hook
|
|
|
|
|
*
|
|
|
|
|
* @type action
|
|
|
|
|
* @title um_before_submit_form_post
|
|
|
|
|
* @description Before submit form
|
|
|
|
|
* @change_log
|
|
|
|
|
* ["Since: 2.0"]
|
|
|
|
|
* @usage add_action( 'um_before_submit_form_post', 'function_name', 10, 1 );
|
|
|
|
|
* @example
|
|
|
|
|
* <?php
|
|
|
|
|
* add_action( 'um_before_submit_form_post', 'my_before_submit_form_post', 10, 1 );
|
|
|
|
|
* function my_run_ajax_function( $post ) {
|
|
|
|
|
* // your code here
|
|
|
|
|
* }
|
|
|
|
|
* ?>
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
do_action( 'um_before_submit_form_post' );
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
/* save entire form as global */
|
|
|
|
|
/**
|
|
|
|
|
* UM hook
|
|
|
|
|
*
|
|
|
|
|
* @type filter
|
|
|
|
|
* @title um_submit_post_form
|
|
|
|
|
* @description Change submitted data on form submit
|
|
|
|
|
* @input_vars
|
|
|
|
|
* [{"var":"$data","type":"array","desc":"Submitted data"}]
|
|
|
|
|
* @change_log
|
|
|
|
|
* ["Since: 2.0"]
|
|
|
|
|
* @usage
|
|
|
|
|
* <?php add_filter( 'um_submit_post_form', 'function_name', 10, 1 ); ?>
|
|
|
|
|
* @example
|
|
|
|
|
* <?php
|
|
|
|
|
* add_filter( 'um_submit_post_form', 'my_submit_post_form', 10, 1 );
|
|
|
|
|
* function my_submit_post_form( $data ) {
|
|
|
|
|
* // your code here
|
|
|
|
|
* return $data;
|
|
|
|
|
* }
|
|
|
|
|
* ?>
|
|
|
|
|
*/
|
2022-10-24 16:22:04 +03:00
|
|
|
$this->post_form = apply_filters( 'um_submit_post_form', wp_unslash( $_POST ) );
|
2021-04-06 12:30:33 +03:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
if ( isset( $this->post_form[ UM()->honeypot ] ) && '' !== $this->post_form[ UM()->honeypot ] ) {
|
|
|
|
|
wp_die( esc_html__( 'Hello, spam bot!', 'ultimate-member' ) );
|
|
|
|
|
}
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
$this->post_form = $this->beautify( $this->post_form );
|
|
|
|
|
$this->post_form = $this->sanitize( $this->post_form );
|
|
|
|
|
$this->post_form['submitted'] = $this->post_form;
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
$this->post_form = array_merge( $this->form_data, $this->post_form );
|
2020-10-29 12:20:47 +02:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
// Remove role from post_form at first if role ! empty and there aren't custom fields with role name
|
|
|
|
|
if ( ! empty( $_POST['role'] ) ) {
|
|
|
|
|
if ( ! isset( $this->form_data['custom_fields'] ) || ! strstr( $this->form_data['custom_fields'], 'role_' ) ) {
|
|
|
|
|
unset( $this->post_form['role'] );
|
|
|
|
|
unset( $this->post_form['submitted']['role'] );
|
2020-10-29 12:20:47 +02:00
|
|
|
}
|
2021-06-29 21:15:48 +03:00
|
|
|
}
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
// Secure sanitize of the submitted data
|
|
|
|
|
if ( ! empty( $this->post_form ) ) {
|
|
|
|
|
$this->post_form = array_diff_key( $this->post_form, array_flip( UM()->user()->banned_keys ) );
|
|
|
|
|
}
|
|
|
|
|
if ( ! empty( $this->post_form['submitted'] ) ) {
|
|
|
|
|
$this->post_form['submitted'] = array_diff_key( $this->post_form['submitted'], array_flip( UM()->user()->banned_keys ) );
|
|
|
|
|
}
|
2020-10-29 12:20:47 +02:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
// set default role from settings on registration form
|
|
|
|
|
if ( isset( $this->post_form['mode'] ) && 'register' === $this->post_form['mode'] ) {
|
|
|
|
|
$role = $this->assigned_role( $this->form_id );
|
|
|
|
|
$this->post_form['role'] = $role;
|
|
|
|
|
}
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
if ( isset( $this->form_data['custom_fields'] ) && strstr( $this->form_data['custom_fields'], 'role_' ) ) { // Secure selected role
|
2020-10-29 12:20:47 +02:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
if ( ! empty( $_POST['role'] ) ) {
|
|
|
|
|
$custom_field_roles = $this->custom_field_roles( $this->form_data['custom_fields'] );
|
2020-10-29 12:20:47 +02:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
if ( ! empty( $custom_field_roles ) ) {
|
|
|
|
|
if ( is_array( $_POST['role'] ) ) {
|
|
|
|
|
$role = current( $_POST['role'] );
|
|
|
|
|
$role = sanitize_key( $role );
|
|
|
|
|
} else {
|
|
|
|
|
$role = sanitize_key( $_POST['role'] );
|
|
|
|
|
}
|
2020-10-01 12:03:56 +03:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
global $wp_roles;
|
|
|
|
|
$role_keys = array_map(
|
|
|
|
|
function( $item ) {
|
2020-10-01 12:03:56 +03:00
|
|
|
return 'um_' . $item;
|
2021-06-29 21:15:48 +03:00
|
|
|
},
|
|
|
|
|
get_option( 'um_roles', array() )
|
|
|
|
|
);
|
|
|
|
|
$exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) );
|
|
|
|
|
|
|
|
|
|
if ( ! empty( $role ) &&
|
|
|
|
|
( ! in_array( $role, $custom_field_roles, true ) || in_array( $role, $exclude_roles, true ) ) ) {
|
|
|
|
|
wp_die( esc_html__( 'This is not possible for security reasons.', 'ultimate-member' ) );
|
|
|
|
|
}
|
2020-10-01 12:03:56 +03:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
$this->post_form['role'] = $role;
|
|
|
|
|
$this->post_form['submitted']['role'] = $role;
|
|
|
|
|
} else {
|
|
|
|
|
unset( $this->post_form['role'] );
|
|
|
|
|
unset( $this->post_form['submitted']['role'] );
|
2020-10-01 12:03:56 +03:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
// set default role for registration form if custom field hasn't proper value
|
|
|
|
|
if ( isset( $this->post_form['mode'] ) && 'register' === $this->post_form['mode'] ) {
|
|
|
|
|
$role = $this->assigned_role( $this->form_id );
|
2020-10-01 12:03:56 +03:00
|
|
|
$this->post_form['role'] = $role;
|
2018-03-20 13:24:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-29 21:15:48 +03:00
|
|
|
}
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
/**
|
|
|
|
|
* UM hook
|
|
|
|
|
*
|
|
|
|
|
* @type filter
|
|
|
|
|
* @title um_submit_form_data
|
|
|
|
|
* @description Change submitted data on form submit
|
|
|
|
|
* @input_vars
|
|
|
|
|
* [{"var":"$data","type":"array","desc":"Submitted data"},
|
|
|
|
|
* {"var":"$mode","type":"string","desc":"Form mode"}]
|
|
|
|
|
* @change_log
|
|
|
|
|
* ["Since: 2.0"]
|
|
|
|
|
* @usage
|
|
|
|
|
* <?php add_filter( 'um_submit_form_data', 'function_name', 10, 2 ); ?>
|
|
|
|
|
* @example
|
|
|
|
|
* <?php
|
|
|
|
|
* add_filter( 'um_submit_form_data', 'my_submit_form_data', 10, 2 );
|
|
|
|
|
* function my_submit_form_data( $data ) {
|
|
|
|
|
* // your code here
|
|
|
|
|
* return $data;
|
|
|
|
|
* }
|
|
|
|
|
* ?>
|
|
|
|
|
*/
|
|
|
|
|
$this->post_form = apply_filters( 'um_submit_form_data', $this->post_form, $this->post_form['mode'] );
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
/* Continue based on form mode - pre-validation */
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
/**
|
|
|
|
|
* UM hook
|
|
|
|
|
*
|
|
|
|
|
* @type action
|
|
|
|
|
* @title um_submit_form_errors_hook
|
|
|
|
|
* @description Action on submit form
|
|
|
|
|
* @input_vars
|
|
|
|
|
* [{"var":"$post","type":"int","desc":"Post data"}]
|
|
|
|
|
* @change_log
|
|
|
|
|
* ["Since: 2.0"]
|
|
|
|
|
* @usage add_action( 'um_submit_form_errors_hook', 'function_name', 10, 1 );
|
|
|
|
|
* @example
|
|
|
|
|
* <?php
|
|
|
|
|
* add_action( 'um_submit_form_errors_hook', 'my_submit_form_errors', 10, 1 );
|
|
|
|
|
* function my_submit_form_errors( $post ) {
|
|
|
|
|
* // your code here
|
|
|
|
|
* }
|
|
|
|
|
* ?>
|
|
|
|
|
*/
|
|
|
|
|
do_action( 'um_submit_form_errors_hook', $this->post_form );
|
|
|
|
|
/**
|
|
|
|
|
* UM hook
|
|
|
|
|
*
|
|
|
|
|
* @type action
|
|
|
|
|
* @title um_submit_form_{$mode}
|
|
|
|
|
* @description Action on submit form
|
|
|
|
|
* @input_vars
|
|
|
|
|
* [{"var":"$post","type":"int","desc":"Post data"}]
|
|
|
|
|
* @change_log
|
|
|
|
|
* ["Since: 2.0"]
|
|
|
|
|
* @usage add_action( 'um_submit_form_{$mode}', 'function_name', 10, 1 );
|
|
|
|
|
* @example
|
|
|
|
|
* <?php
|
|
|
|
|
* add_action( 'um_submit_form_{$mode}', 'my_submit_form', 10, 1 );
|
|
|
|
|
* function my_submit_form( $post ) {
|
|
|
|
|
* // your code here
|
|
|
|
|
* }
|
|
|
|
|
* ?>
|
|
|
|
|
*/
|
|
|
|
|
do_action( "um_submit_form_{$this->post_form['mode']}", $this->post_form );
|
2018-03-20 13:24:38 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Beautify form data
|
2021-04-06 12:30:33 +03:00
|
|
|
*
|
2018-03-20 13:24:38 +02:00
|
|
|
* @param array $form
|
2021-06-29 21:15:48 +03:00
|
|
|
*
|
2018-03-20 13:24:38 +02:00
|
|
|
* @return array $form
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
public function beautify( $form ) {
|
2021-04-06 12:30:33 +03:00
|
|
|
if ( isset( $form['form_id'] ) ) {
|
2018-03-20 13:24:38 +02:00
|
|
|
$this->form_suffix = '-' . $form['form_id'];
|
2021-06-29 21:15:48 +03:00
|
|
|
$this->processing = $form['form_id'];
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2021-04-06 12:30:33 +03:00
|
|
|
foreach ( $form as $key => $value ) {
|
2018-03-20 13:24:38 +02:00
|
|
|
if ( strstr( $key, $this->form_suffix ) ) {
|
2021-06-29 21:15:48 +03:00
|
|
|
$a_key = str_replace( $this->form_suffix, '', $key );
|
2018-03-20 13:24:38 +02:00
|
|
|
$form[ $a_key ] = $value;
|
|
|
|
|
unset( $form[ $key ] );
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-29 21:15:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
|
}
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Beautify form data
|
|
|
|
|
*
|
|
|
|
|
* @param array $form
|
|
|
|
|
*
|
|
|
|
|
* @return array $form
|
|
|
|
|
*/
|
|
|
|
|
public function sanitize( $form ) {
|
2021-07-15 15:22:16 +03:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
if ( isset( $form['form_id'] ) ) {
|
|
|
|
|
if ( isset( $this->form_data['custom_fields'] ) ) {
|
|
|
|
|
$custom_fields = maybe_unserialize( $this->form_data['custom_fields'] );
|
|
|
|
|
|
|
|
|
|
if ( is_array( $custom_fields ) ) {
|
|
|
|
|
foreach ( $custom_fields as $k => $field ) {
|
2021-07-15 15:22:16 +03:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
if ( isset( $field['type'] ) ) {
|
|
|
|
|
if ( isset( $form[ $k ] ) ) {
|
|
|
|
|
|
|
|
|
|
switch ( $field['type'] ) {
|
|
|
|
|
default:
|
|
|
|
|
$form[ $k ] = apply_filters( 'um_sanitize_form_field', $form[ $k ], $field );
|
|
|
|
|
break;
|
|
|
|
|
case 'number':
|
|
|
|
|
$form[ $k ] = (int) $form[ $k ];
|
|
|
|
|
break;
|
|
|
|
|
case 'textarea':
|
2021-08-11 13:17:48 +03:00
|
|
|
if ( ! empty( $field['html'] ) || ( UM()->profile()->get_show_bio_key( $form ) === $k && UM()->options()->get( 'profile_show_html_bio' ) ) ) {
|
2021-07-15 15:22:16 +03:00
|
|
|
$form[ $k ] = wp_kses_post( $form[ $k ] );
|
|
|
|
|
} else {
|
|
|
|
|
$form[ $k ] = sanitize_textarea_field( $form[ $k ] );
|
|
|
|
|
}
|
2021-06-29 21:15:48 +03:00
|
|
|
break;
|
|
|
|
|
case 'url':
|
2021-08-06 01:13:02 +03:00
|
|
|
$f = UM()->builtin()->get_a_field( $k );
|
|
|
|
|
|
|
|
|
|
if ( array_key_exists( 'match', $f ) && array_key_exists( 'advanced', $f ) && 'social' === $f['advanced'] ) {
|
|
|
|
|
$v = sanitize_text_field( $form[ $k ] );
|
|
|
|
|
|
|
|
|
|
// Make a proper social link
|
|
|
|
|
if ( ! empty( $v ) && ! strstr( $v, $f['match'] ) ) {
|
|
|
|
|
$domain = trim( strtr( $f['match'], array(
|
|
|
|
|
'https://' => '',
|
|
|
|
|
'http://' => '',
|
|
|
|
|
) ), ' /' );
|
|
|
|
|
|
|
|
|
|
if ( ! strstr( $v, $domain ) ) {
|
|
|
|
|
$v = $f['match'] . $v;
|
|
|
|
|
} else {
|
|
|
|
|
$v = 'https://' . trim( strtr( $v, array(
|
|
|
|
|
'https://' => '',
|
|
|
|
|
'http://' => '',
|
|
|
|
|
) ), ' /' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$form[ $k ] = $v;
|
|
|
|
|
} else {
|
|
|
|
|
$form[ $k ] = esc_url_raw( $form[ $k ] );
|
|
|
|
|
}
|
2021-06-29 21:15:48 +03:00
|
|
|
break;
|
2022-06-10 01:53:35 +03:00
|
|
|
case 'password':
|
|
|
|
|
$form[ $k ] = trim( $form[ $k ] );
|
|
|
|
|
if ( array_key_exists( 'confirm_' . $k, $form ) ) {
|
|
|
|
|
$form[ 'confirm_' . $k ] = trim( $form[ 'confirm_' . $k ] );
|
|
|
|
|
}
|
|
|
|
|
break;
|
2021-06-29 21:15:48 +03:00
|
|
|
case 'text':
|
|
|
|
|
case 'select':
|
|
|
|
|
case 'image':
|
|
|
|
|
case 'file':
|
|
|
|
|
case 'date':
|
|
|
|
|
case 'time':
|
|
|
|
|
case 'rating':
|
|
|
|
|
case 'googlemap':
|
|
|
|
|
case 'youtube_video':
|
|
|
|
|
case 'vimeo_video':
|
|
|
|
|
case 'soundcloud_track':
|
|
|
|
|
$form[ $k ] = sanitize_text_field( $form[ $k ] );
|
|
|
|
|
break;
|
|
|
|
|
case 'multiselect':
|
|
|
|
|
case 'radio':
|
|
|
|
|
case 'checkbox':
|
2022-04-20 17:34:09 +03:00
|
|
|
$form[ $k ] = is_array( $form[ $k ] ) ? array_map( 'sanitize_text_field', $form[ $k ] ) : sanitize_text_field( $form[ $k ] );
|
2021-06-29 21:15:48 +03:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-20 13:24:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display form type as Title
|
|
|
|
|
* @param string $mode
|
|
|
|
|
* @param integer $post_id
|
|
|
|
|
* @return string $output
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
public function display_form_type( $mode, $post_id ) {
|
2018-03-20 13:24:38 +02:00
|
|
|
$output = null;
|
2021-06-29 21:15:48 +03:00
|
|
|
switch ( $mode ) {
|
2018-03-20 13:24:38 +02:00
|
|
|
case 'login':
|
2021-06-29 21:15:48 +03:00
|
|
|
$output = __( 'Login', 'ultimate-member' );
|
2018-03-20 13:24:38 +02:00
|
|
|
break;
|
|
|
|
|
case 'profile':
|
2021-06-29 21:15:48 +03:00
|
|
|
$output = __( 'Profile', 'ultimate-member' );
|
2018-03-20 13:24:38 +02:00
|
|
|
break;
|
|
|
|
|
case 'register':
|
2021-06-29 21:15:48 +03:00
|
|
|
$output = __( 'Register', 'ultimate-member' );
|
2018-03-20 13:24:38 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return $output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assigned roles to a form
|
|
|
|
|
* @param integer $post_id
|
|
|
|
|
* @return string $role
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
public function assigned_role( $post_id ) {
|
2018-03-20 13:24:38 +02:00
|
|
|
|
|
|
|
|
$global_role = get_option( 'default_role' ); // WP Global settings
|
|
|
|
|
|
|
|
|
|
$um_global_role = UM()->options()->get( 'register_role' ); // UM Settings Global settings
|
2018-05-25 18:22:38 +03:00
|
|
|
if ( ! empty( $um_global_role ) ) {
|
2018-03-20 13:24:38 +02:00
|
|
|
$global_role = $um_global_role; // Form Global settings
|
2018-05-25 18:22:38 +03:00
|
|
|
}
|
2018-03-20 13:24:38 +02:00
|
|
|
|
|
|
|
|
$mode = $this->form_type( $post_id );
|
2018-11-27 14:21:27 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @todo WPML integration to get role from original if it's empty
|
|
|
|
|
*/
|
2018-03-20 13:24:38 +02:00
|
|
|
$use_custom = get_post_meta( $post_id, "_um_{$mode}_use_custom_settings", true );
|
|
|
|
|
if ( $use_custom ) { // Custom Form settings
|
|
|
|
|
$role = get_post_meta( $post_id, "_um_{$mode}_role", true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( empty( $role ) ) { // custom role is default, return default role's slug
|
|
|
|
|
$role = $global_role;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $role;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get form type
|
|
|
|
|
* @param integer $post_id
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
public function form_type( $post_id ) {
|
2018-03-20 13:24:38 +02:00
|
|
|
$mode = get_post_meta( $post_id, '_um_mode', true );
|
|
|
|
|
return $mode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom field roles
|
2021-06-29 21:15:48 +03:00
|
|
|
*
|
2018-03-20 13:24:38 +02:00
|
|
|
* @param string $custom_fields serialized
|
|
|
|
|
* @return bool|array roles
|
|
|
|
|
*/
|
2021-06-29 21:15:48 +03:00
|
|
|
public function custom_field_roles( $custom_fields ) {
|
2018-03-20 13:24:38 +02:00
|
|
|
|
|
|
|
|
$fields = maybe_unserialize( $custom_fields );
|
2020-09-08 23:13:43 +03:00
|
|
|
if ( ! is_array( $fields ) ) {
|
2018-03-20 13:24:38 +02:00
|
|
|
return false;
|
2020-09-08 23:13:43 +03:00
|
|
|
}
|
2018-03-20 13:24:38 +02:00
|
|
|
|
2020-09-11 00:14:20 +03:00
|
|
|
// role field
|
|
|
|
|
global $wp_roles;
|
2021-06-29 21:15:48 +03:00
|
|
|
$role_keys = array_map(
|
|
|
|
|
function( $item ) {
|
|
|
|
|
return 'um_' . $item;
|
|
|
|
|
},
|
|
|
|
|
get_option( 'um_roles', array() )
|
|
|
|
|
);
|
2020-09-11 00:14:20 +03:00
|
|
|
$exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) );
|
|
|
|
|
|
|
|
|
|
$roles = UM()->roles()->get_roles( false, $exclude_roles );
|
2021-06-29 21:15:48 +03:00
|
|
|
$roles = array_map(
|
|
|
|
|
function( $item ) {
|
|
|
|
|
return html_entity_decode( $item, ENT_QUOTES );
|
|
|
|
|
},
|
|
|
|
|
$roles
|
|
|
|
|
);
|
2020-09-11 00:14:20 +03:00
|
|
|
|
2018-03-20 13:24:38 +02:00
|
|
|
foreach ( $fields as $field_key => $field_settings ) {
|
|
|
|
|
|
2020-09-22 14:30:25 +03:00
|
|
|
if ( strstr( $field_key, 'role_' ) && is_array( $field_settings['options'] ) ) {
|
2020-10-01 12:03:56 +03:00
|
|
|
|
2021-06-29 21:15:48 +03:00
|
|
|
if ( isset( $this->post_form['mode'] ) && 'profile' === $this->post_form['mode'] &&
|
2021-08-06 01:13:02 +03:00
|
|
|
isset( $field_settings['editable'] ) && $field_settings['editable'] == 0 ) {
|
2020-10-01 12:03:56 +03:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-05 23:21:40 +03:00
|
|
|
if ( ! um_can_view_field( $field_settings ) ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-22 14:30:25 +03:00
|
|
|
$intersected_options = array();
|
|
|
|
|
foreach ( $field_settings['options'] as $key => $title ) {
|
|
|
|
|
if ( false !== $search_key = array_search( $title, $roles ) ) {
|
|
|
|
|
$intersected_options[ $search_key ] = $title;
|
|
|
|
|
} elseif ( isset( $roles[ $key ] ) ) {
|
|
|
|
|
$intersected_options[ $key ] = $title;
|
2020-09-11 00:14:20 +03:00
|
|
|
}
|
2018-03-20 13:24:38 +02:00
|
|
|
}
|
2020-09-22 14:30:25 +03:00
|
|
|
|
|
|
|
|
// getting roles only from the first role fields
|
|
|
|
|
return array_keys( $intersected_options );
|
2018-03-20 13:24:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-29 02:51:54 +03:00
|
|
|
}
|