Skip to content

Instantly share code, notes, and snippets.

@nikitasinelnikov
Created October 31, 2023 08:52
Show Gist options
  • Save nikitasinelnikov/2806dcedc58c5a86c0a8af262fa3df08 to your computer and use it in GitHub Desktop.
Save nikitasinelnikov/2806dcedc58c5a86c0a8af262fa3df08 to your computer and use it in GitHub Desktop.
Probably fix by singleton
<?php
namespace um\core;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'um\core\Form' ) ) {
/**
* Class Form
* @package um\core
*/
class Form {
/**
* @var
*/
public $form_data;
public $form_suffix = null;
/**
* @var
*/
public $form_id;
/**
* @var
*/
public $form_status;
/**
* @var null
*/
public $post_form = null;
/**
* @var null
*/
public $nonce = null;
/**
* @var null|array
*/
public $errors = null;
/**
* @var null
*/
public $processing = null;
/**
* @var array
*/
public $all_fields = array();
/**
* Whitelisted usermeta that can be stored when UM Form is submitted.
*
* @since 2.6.7
*
* @var array
*/
public $usermeta_whitelist = array();
public function hooks() {
add_action( 'template_redirect', array( &$this, 'form_init' ), 2 );
add_action( 'init', array( &$this, 'field_declare' ), 10 );
}
/**
*
*/
public function ajax_muted_action() {
UM()->check_ajax_nonce();
// phpcs:disable WordPress.Security.NonceVerification
if ( ! isset( $_REQUEST['hook'] ) ) {
die( esc_html__( 'Invalid hook', 'ultimate-member' ) );
}
if ( isset( $_REQUEST['user_id'] ) ) {
$user_id = absint( $_REQUEST['user_id'] );
}
if ( ! isset( $user_id ) || ! UM()->roles()->um_current_user_can( 'edit', $user_id ) ) {
die( esc_html__( 'You can not edit this user.', 'ultimate-member' ) );
}
$hook = sanitize_key( $_REQUEST['hook'] );
/**
* Fires on AJAX muted action.
*
* @since 1.3.x
* @hook um_run_ajax_function__{$hook}
*
* @param {array} $request Request.
*
* @example <caption>Make any custom action on AJAX muted action.</caption>
* function my_run_ajax_function( $request ) {
* // your code here
* }
* add_action( 'um_run_ajax_function__{$hook}', 'my_run_ajax_function', 10, 1 );
*/
do_action( "um_run_ajax_function__{$hook}", $_REQUEST );
// phpcs:enable WordPress.Security.NonceVerification
}
/**
*
*/
public function ajax_select_options() {
UM()->check_ajax_nonce();
$arr_options = array();
$arr_options['status'] = 'success';
$arr_options['post'] = $_POST;
// 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' );
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 );
}
$allowed_callbacks = array_map( 'rtrim', explode( "\n", wp_unslash( $allowed_callbacks ) ) );
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 );
}
if ( UM()->fields()->is_source_blacklisted( $ajax_source_func ) ) {
$arr_options['status'] = 'error';
$arr_options['message'] = __( 'This is not possible for security reasons.', 'ultimate-member' );
wp_send_json( $arr_options );
}
if ( isset( $_POST['form_id'] ) ) {
UM()->fields()->set_id = absint( $_POST['form_id'] );
}
UM()->fields()->set_mode = 'profile';
$form_fields = UM()->fields()->get_fields();
$arr_options['fields'] = $form_fields;
if ( isset( $arr_options['post']['members_directory'] ) && 'yes' === $arr_options['post']['members_directory'] ) {
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 ) );
} else {
// 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 );
}
} else {
$arr_options['items'] = array();
}
wp_send_json( $arr_options );
} 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;
* }
* ?>
*/
$debug = apply_filters( 'um_ajax_select_options__debug_mode', false );
if ( $debug ) {
$arr_options['debug'] = array(
$_POST,
$form_fields,
);
}
if ( ! empty( $_POST['child_callback'] ) && isset( $form_fields[ $_POST['child_name'] ] ) ) {
// 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'] ) &&
$form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] === $ajax_source_func ) {
$arr_options['field'] = $form_fields[ $_POST['child_name'] ];
$arr_options['items'] = call_user_func( $ajax_source_func, $arr_options['field']['parent_dropdown_relationship'] );
} else {
$arr_options['status'] = 'error';
$arr_options['message'] = __( 'This is not possible for security reasons.', 'ultimate-member' );
}
}
wp_send_json( $arr_options );
}
}
/**
* Count the form errors.
* @return integer
*/
public function count_errors() {
$errors = $this->errors;
if ( $errors && is_array( $errors ) ) {
return count( $errors );
}
return 0;
}
/**
* Appends field errors
*
* @param string $key
* @param string $error
*/
public function add_error( $key, $error ) {
if ( ! isset( $this->errors[ $key ] ) ) {
/**
* 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;
* }
* ?>
*/
$this->errors[ $key ] = apply_filters( 'um_submit_form_error', $error, $key );
}
}
/**
* Appends field notices
* @param string $key
* @param string $notice
*/
public function add_notice( $key, $notice ) {
if ( ! isset( $this->notices[ $key ] ) ) {
/**
* 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;
* }
* ?>
*/
$this->notices[ $key ] = apply_filters( 'um_submit_form_notice', $notice, $key );
}
}
/**
* If a form has errors
*
* @param string $key
* @return boolean
*/
public function has_error( $key ) {
if ( isset( $this->errors[ $key ] ) ) {
return true;
}
return false;
}
/**
* If a form has notices/info
*
* @param string $key
* @return boolean
*/
public function has_notice( $key ) {
if ( isset( $this->notices[ $key ] ) ) {
return true;
}
return false;
}
/**
* Return the errors as a WordPress Error object
*
* @return \WP_Error
*/
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;
}
/**
* Declare all fields
*/
public function field_declare() {
if ( isset( UM()->builtin()->custom_fields ) ) {
$this->all_fields = UM()->builtin()->custom_fields;
} else {
$this->all_fields = null;
}
}
/**
* Remove banned wp_usermeta keys from submitted data.
*
* @since 2.6.5
* @param array $submitted
* @return array
*/
public function clean_submitted_data( $submitted ) {
foreach ( $submitted as $metakey => $value ) {
if ( UM()->user()->is_metakey_banned( $metakey/*, 'submission'*/ ) ) {
unset( $submitted[ $metakey ] );
}
}
return $submitted;
}
/**
* Validate form on submit
*/
public function form_init() {
if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
$http_post = ( 'POST' === $_SERVER['REQUEST_METHOD'] );
} else {
$http_post = 'POST';
}
// Handles Register, Profile and Login forms.
if ( $http_post && ! is_admin() && isset( $_POST['form_id'] ) && is_numeric( $_POST['form_id'] ) ) {
$this->form_id = absint( $_POST['form_id'] );
if ( 'um_form' !== get_post_type( $this->form_id ) ) {
return;
}
$this->form_status = get_post_status( $this->form_id );
if ( 'publish' !== $this->form_status ) {
return;
}
// Verified that form_id is right and UM form is published. Then get form data.
$this->form_data = UM()->query()->post_data( $this->form_id );
// Checking the form custom fields. Form without custom fields is invalid.
if ( ! array_key_exists( 'mode', $this->form_data ) ) {
return;
}
// Checking the form custom fields. Form without custom fields is invalid.
if ( ! array_key_exists( 'custom_fields', $this->form_data ) ) {
return;
}
$custom_fields = maybe_unserialize( $this->form_data['custom_fields'] );
if ( ! is_array( $custom_fields ) || empty( $custom_fields ) ) {
return;
}
$ignore_keys = array();
$field_types_without_metakey = UM()->builtin()->get_fields_without_metakey();
foreach ( $custom_fields as $cf_k => $cf_data ) {
if ( ! array_key_exists( 'type', $cf_data ) || in_array( $cf_data['type'], $field_types_without_metakey, true ) ) {
unset( $custom_fields[ $cf_k ] );
}
if ( array_key_exists( 'type', $cf_data ) && 'password' === $cf_data['type'] ) {
$ignore_keys[] = $cf_k;
$ignore_keys[] = 'confirm_' . $cf_k;
}
if ( 'profile' === $this->form_data['mode'] ) {
if ( ! empty( $cf_data['edit_forbidden'] ) ) {
$ignore_keys[] = $cf_k;
}
if ( ! um_can_edit_field( $cf_data ) || ! um_can_view_field( $cf_data ) ) {
$ignore_keys[] = $cf_k;
}
}
if ( ! array_key_exists( 'metakey', $cf_data ) || empty( $cf_data['metakey'] ) ) {
unset( $custom_fields[ $cf_k ] );
}
if ( isset( $cf_data['required_opt'] ) ) {
$opt = $cf_data['required_opt'];
if ( UM()->options()->get( $opt[0] ) !== $opt[1] ) {
$ignore_keys[] = $cf_k;
}
}
}
$cf_metakeys = array_column( $custom_fields, 'metakey' );
$all_cf_metakeys = $cf_metakeys;
// The '_um_last_login' cannot be updated through UM form.
$cf_metakeys = array_values( array_diff( $cf_metakeys, array( 'role_select', 'role_radio', 'role', '_um_last_login', 'user_pass', 'user_password', 'confirm_user_password' ) ) );
if ( ! empty( $ignore_keys ) ) {
$cf_metakeys = array_values( array_diff( $cf_metakeys, $ignore_keys ) );
}
// Remove restricted fields when edit profile.
if ( 'profile' === $this->form_data['mode'] ) {
// Column names from wp_users table.
$cf_metakeys = array_values( array_diff( $cf_metakeys, array( 'user_login' ) ) );
// Hidden for edit fields
$cf_metakeys = array_values( array_diff( $cf_metakeys, UM()->fields()->get_restricted_fields_for_edit() ) );
$cf_metakeys[] = 'profile_photo';
$cf_metakeys[] = 'cover_photo';
if ( ! empty( $this->form_data['use_custom_settings'] ) && ! empty( $this->form_data['show_bio'] ) ) {
$cf_metakeys[] = UM()->profile()->get_show_bio_key( $this->form_data );
} else {
if ( UM()->options()->get( 'profile_show_bio' ) ) {
$cf_metakeys[] = UM()->profile()->get_show_bio_key( $this->form_data );
}
}
}
// Add required usermeta for register.
if ( 'register' === $this->form_data['mode'] ) {
$cf_metakeys[] = 'form_id';
$cf_metakeys[] = 'timestamp';
}
/**
* Filters whitelisted usermeta keys that can be stored inside DB after UM Form submission.
*
* @param {array} $whitelisted_metakeys Whitelisted usermeta keys.
* @param {array} $form_data UM form data.
*
* @return {array} Whitelisted usermeta keys.
*
* @since 2.6.7
* @hook um_whitelisted_metakeys
*
* @example <caption>Extends whitelisted usermeta keys.</caption>
* function my_um_whitelisted_metakeys( $metakeys, $form_data ) {
* $metakeys[] = 'some_key';
* return $metakeys;
* }
* add_filter( 'um_whitelisted_metakeys', 'my_um_whitelisted_metakeys', 10, 2 );
*/
$cf_metakeys = apply_filters( 'um_whitelisted_metakeys', $cf_metakeys, $this->form_data );
// Important variable to prevent save unnecessary data to wp_usermeta.
$this->usermeta_whitelist = $cf_metakeys;
/**
* Fires before UM login, registration or profile form submission.
*
* @since 1.3.x
* @hook um_before_submit_form_post
*
* @param {array} $post $_POST submission array. Deprecated since 2.0.
* @param {object} $this UM()->form() class instance. Since 2.6.7
*
* @example <caption>Make any custom action before UM login, registration or profile form submission.</caption>
* function my_custom_before_submit_form_post( $um_form_obj ) {
* // your code here
* }
* add_action( 'um_before_submit_form_post', 'my_custom_before_submit_form_post' );
*/
do_action( 'um_before_submit_form_post', $this );
/* save entire form as global */
/**
* Filters $_POST submitted data by the UM login, registration or profile form.
*
* @param {array} $_post Submitted data. Already un-slashed by `wp_unslash()`.
*
* @return {array} Submitted data.
*
* @since 1.3.x
* @hook um_submit_post_form
*
* @example <caption>Extends $_POST data.</caption>
* function my_submit_post_form( $_post ) {
* $_post['some_key'] = 'some value';
* return $_post;
* }
* add_filter( 'um_submit_post_form', 'my_submit_post_form' );
*/
$this->post_form = apply_filters( 'um_submit_post_form', wp_unslash( $_POST ) );
// Validate form submission by honeypot.
if ( isset( $this->post_form[ UM()->honeypot ] ) && '' !== $this->post_form[ UM()->honeypot ] ) {
// High level escape if hacking.
wp_die( esc_html__( 'Hello, spam bot!', 'ultimate-member' ) );
}
$this->post_form = $this->beautify( $this->post_form );
// Validate and filter 'role' submitted data to avoid handling roles with admin privileges.
// Remove role from post_form at first if role ! empty and there aren't custom fields with role name
$maybe_set_default_role = true;
if ( array_key_exists( 'role', $this->post_form ) ) {
if ( 'login' === $this->form_data['mode'] ) {
unset( $this->post_form['role'] );
} else {
$form_has_role_field = count( array_intersect( $all_cf_metakeys, array( 'role_select', 'role_radio' ) ) ) > 0;
if ( ! $form_has_role_field ) {
unset( $this->post_form['role'] );
} else {
$custom_field_roles = $this->custom_field_roles( $this->form_data['custom_fields'] );
if ( ! empty( $custom_field_roles ) && ! empty( $this->post_form['role'] ) ) {
if ( is_array( $this->post_form['role'] ) ) {
$role = current( $this->post_form['role'] );
$role = sanitize_key( $role );
} else {
$role = sanitize_key( $this->post_form['role'] );
}
global $wp_roles;
$exclude_roles = array_diff( array_keys( $wp_roles->roles ), UM()->roles()->get_editable_user_roles() );
if ( ! empty( $role ) &&
( ! in_array( $role, $custom_field_roles, true ) || in_array( $role, $exclude_roles, true ) ) ) {
// High level escape if hacking.
wp_die( esc_html__( 'This is not possible for security reasons.', 'ultimate-member' ) );
}
$this->post_form['role'] = $role;
$maybe_set_default_role = false;
}
}
}
}
$this->post_form = $this->sanitize( $this->post_form );
$this->post_form['submitted'] = $this->post_form;
// Set default role from settings on registration form. It has been made after defined 'submitted' because predefined role isn't a submitted field.
if ( $maybe_set_default_role && 'register' === $this->form_data['mode'] ) {
$role = $this->assigned_role( $this->form_id );
$this->post_form['role'] = $role;
}
/**
* Filters $_POST submitted data by the UM login, registration or profile form.
* It's un-slashed by `wp_unslash()`, beautified and sanitized. `role` attribute is filtered by possible role.
* `submitted` key is added by code and contains summary of submission.
*
* Internal Ultimate Member callbacks (Priority -> Callback name -> Excerpt):
* 9 - `um_submit_form_data_trim_fields()` maybe over-functionality and can be removed.
* 10 - `um_submit_form_data_role_fields()` important for conditional logic based on role fields in form.
*
* @param {array} $_post Submitted data.
* @param {string} $mode Form mode. login||register||profile
* @param {array} $all_cf_metakeys Form's metakeys. Since 2.6.7.
*
* @return {array} Submitted data.
*
* @since 1.3.x
* @hook um_submit_form_data
*
* @example <caption>Extends UM form submitted data.</caption>
* function my_submit_form_data( $_post, $mode, $all_cf_metakeys ) {
* $_post['some_key'] = 'some value';
* return $_post;
* }
* add_filter( 'um_submit_form_data', 'my_submit_form_data', 10, 3 );
*/
$this->post_form = apply_filters( 'um_submit_form_data', $this->post_form, $this->form_data['mode'], $all_cf_metakeys );
/* Continue based on form mode - pre-validation */
/**
* Fires for validation UM login, registration or profile form submission.
*
* Internal Ultimate Member callbacks (Priority -> Callback name -> Excerpt):
* 10 - `um_submit_form_errors_hook()` All form validation handlers.
* 20 - `um_recaptcha_validate()` reCAPTCHA form validation handlers. um-recaptcha extension.
*
* @since 1.3.x
* @hook um_submit_form_errors_hook
*
* @param {array} $post $_POST Submission array.
* @param {array} $form_data UM form data. Since 2.6.7
*
* @example <caption>Make any common validation action here.</caption>
* function my_custom_before_submit_form_post( $post, $form_data ) {
* // your code here
* }
* add_action( 'um_submit_form_errors_hook', 'my_custom_submit_form_errors_hook', 10, 2 );
*/
do_action( 'um_submit_form_errors_hook', $this->post_form, $this->form_data );
/* Continue based on form mode - store data. */
/**
* Fires for make main actions on UM login, registration or profile form submission.
*
* Internal Ultimate Member callbacks (Priority -> Callback name -> Excerpt):
* ### um_submit_form_login:
* * 1 - `UM()->login()->verify_nonce()` Verify nonce.
* * 10 - `um_submit_form_login()` Login form main handler.
* ### um_submit_form_register:
* * 1 - `UM()->register()->verify_nonce()` Verify nonce.
* * 9 - `UM()->agreement_validation()` GDPR Agreement.
* * 9 - `UM()->terms_conditions()->agreement_validation()` Terms & Conditions Agreement.
* * 10 - `um_submit_form_register()` Register form main handler.
* ### um_submit_form_profile:
* * 10 - `um_submit_form_profile()` Profile form main handler.
*
* @since 1.3.x
* @hook um_submit_form_errors_hook
*
* @param {array} $post $_POST Submission array.
* @param {array} $form_data UM form data. Since 2.6.7
*
* @example <caption>Make any custom action.</caption>
* function my_custom_before_submit_form_post( $post, $form_data ) {
* // your code here
* }
* add_action( 'um_submit_form_errors_hook', 'my_custom_submit_form_errors_hook', 10, 2 );
*/
do_action( "um_submit_form_{$this->form_data['mode']}", $this->post_form, $this->form_data );
}
}
/**
* Beautify form data
*
* @param array $form
*
* @return array $form
*/
public function beautify( $form ) {
if ( isset( $form['form_id'] ) ) {
$this->form_suffix = '-' . $form['form_id'];
$this->processing = absint( $form['form_id'] );
foreach ( $form as $key => $value ) {
if ( strstr( $key, $this->form_suffix ) ) {
$a_key = str_replace( $this->form_suffix, '', $key );
$form[ $a_key ] = $value;
unset( $form[ $key ] );
}
}
}
return $form;
}
/**
* Beautify form data
*
* @param array $form
*
* @return array $form
*/
public function sanitize( $form ) {
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 ) {
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':
if ( ! empty( $field['html'] ) || ( UM()->profile()->get_show_bio_key( $form ) === $k && UM()->options()->get( 'profile_show_html_bio' ) ) ) {
$allowed_html = UM()->get_allowed_html( 'templates' );
if ( empty( $allowed_html['iframe'] ) ) {
$allowed_html['iframe'] = array(
'allow' => true,
'frameborder' => true,
'loading' => true,
'name' => true,
'referrerpolicy' => true,
'sandbox' => true,
'src' => true,
'srcdoc' => true,
'title' => true,
'width' => true,
'height' => true,
'allowfullscreen' => true,
);
}
$form[ $k ] = wp_kses( $form[ $k ], $allowed_html );
add_filter( 'wp_kses_allowed_html', array( &$this, 'wp_kses_user_desc' ), 10, 2 );
} else {
$form[ $k ] = sanitize_textarea_field( $form[ $k ] );
}
break;
case 'oembed':
case 'url':
$f = UM()->builtin()->get_a_field( $k );
if ( is_array( $f ) && 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 ) ) {
$replace_match = is_array( $f['match'] ) ? $f['match'][0] : $f['match'];
$need_replace = false;
if ( is_array( $f['match'] ) ) {
$need_replace = true;
foreach ( $f['match'] as $arr_match ) {
if ( strstr( $v, $arr_match ) ) {
$need_replace = false;
}
}
}
if ( ! is_array( $f['match'] ) || $need_replace ) {
if ( ! strstr( $v, $replace_match ) ) {
$domain = trim(
strtr(
$replace_match,
array(
'https://' => '',
'http://' => '',
)
),
' /'
);
if ( ! strstr( $v, $domain ) ) {
$v = $replace_match . $v;
} else {
$v = 'https://' . trim(
strtr(
$v,
array(
'https://' => '',
'http://' => '',
)
),
' /'
);
}
}
}
}
$form[ $k ] = $v;
} else {
$form[ $k ] = esc_url_raw( $form[ $k ] );
}
break;
case 'password':
$form[ $k ] = trim( $form[ $k ] );
if ( array_key_exists( 'confirm_' . $k, $form ) ) {
$form[ 'confirm_' . $k ] = trim( $form[ 'confirm_' . $k ] );
}
break;
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':
case 'spotify':
$form[ $k ] = sanitize_text_field( $form[ $k ] );
break;
case 'multiselect':
case 'radio':
case 'checkbox':
$form[ $k ] = is_array( $form[ $k ] ) ? array_map( 'sanitize_text_field', $form[ $k ] ) : sanitize_text_field( $form[ $k ] );
break;
}
}
}
}
}
}
$show_bio = false;
$bio_html = false;
$global_setting = UM()->options()->get( 'profile_show_html_bio' );
if ( ! empty( $form_data['use_custom_settings'] ) ) {
if ( ! empty( $form_data['show_bio'] ) ) {
$show_bio = true;
$bio_html = ! empty( $global_setting );
}
} else {
$global_show_bio = UM()->options()->get( 'profile_show_bio' );
if ( ! empty( $global_show_bio ) ) {
$show_bio = true;
$bio_html = ! empty( $global_setting );
}
}
$description_key = UM()->profile()->get_show_bio_key( $this->form_data );
if ( $show_bio && ! empty( $form[ $description_key ] ) ) {
$field_exists = false;
if ( ! empty( $this->form_data['custom_fields'] ) ) {
$custom_fields = maybe_unserialize( $this->form_data['custom_fields'] );
if ( array_key_exists( $description_key, $custom_fields ) ) {
$field_exists = true;
if ( ! empty( $custom_fields[ $description_key ]['html'] ) && $bio_html ) {
$allowed_html = UM()->get_allowed_html( 'templates' );
if ( empty( $allowed_html['iframe'] ) ) {
$allowed_html['iframe'] = array(
'allow' => true,
'frameborder' => true,
'loading' => true,
'name' => true,
'referrerpolicy' => true,
'sandbox' => true,
'src' => true,
'srcdoc' => true,
'title' => true,
'width' => true,
'height' => true,
'allowfullscreen' => true,
);
}
$form[ $description_key ] = wp_kses( $form[ $description_key ], $allowed_html );
add_filter( 'wp_kses_allowed_html', array( &$this, 'wp_kses_user_desc' ), 10, 2 );
} else {
$form[ $description_key ] = sanitize_textarea_field( $form[ $description_key ] );
}
}
}
if ( ! $field_exists ) {
if ( $bio_html ) {
$allowed_html = UM()->get_allowed_html( 'templates' );
if ( empty( $allowed_html['iframe'] ) ) {
$allowed_html['iframe'] = array(
'allow' => true,
'frameborder' => true,
'loading' => true,
'name' => true,
'referrerpolicy' => true,
'sandbox' => true,
'src' => true,
'srcdoc' => true,
'title' => true,
'width' => true,
'height' => true,
'allowfullscreen' => true,
);
}
$form[ $description_key ] = wp_kses( $form[ $description_key ], $allowed_html );
add_filter( 'wp_kses_allowed_html', array( &$this, 'wp_kses_user_desc' ), 10, 2 );
} else {
$form[ $description_key ] = sanitize_textarea_field( $form[ $description_key ] );
}
}
}
}
return $form;
}
public function wp_kses_user_desc( $tags, $context ) {
if ( 'user_description' === $context || 'pre_user_description' === $context ) {
$allowed_html = UM()->get_allowed_html( 'templates' );
if ( empty( $allowed_html['iframe'] ) ) {
$allowed_html['iframe'] = array(
'allow' => true,
'frameborder' => true,
'loading' => true,
'name' => true,
'referrerpolicy' => true,
'sandbox' => true,
'src' => true,
'srcdoc' => true,
'title' => true,
'width' => true,
'height' => true,
'allowfullscreen' => true,
);
}
$tags = $allowed_html;
}
return $tags;
}
/**
* Display form type as Title
* @param string $mode
* @param integer $post_id
* @return string $output
*/
public function display_form_type( $mode, $post_id ) {
$output = null;
switch ( $mode ) {
case 'login':
$output = __( 'Login', 'ultimate-member' );
break;
case 'profile':
$output = __( 'Profile', 'ultimate-member' );
break;
case 'register':
$output = __( 'Register', 'ultimate-member' );
break;
}
return $output;
}
/**
* Assigned roles to a form
* @param integer $post_id
* @return string $role
*/
public function assigned_role( $post_id ) {
$global_role = get_option( 'default_role' ); // WP Global settings
$um_global_role = UM()->options()->get( 'register_role' ); // UM Settings Global settings
if ( ! empty( $um_global_role ) ) {
$global_role = $um_global_role; // Form Global settings
}
$mode = $this->form_type( $post_id );
/**
* @todo WPML integration to get role from original if it's empty
*/
$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
*/
public function form_type( $post_id ) {
$mode = get_post_meta( $post_id, '_um_mode', true );
return $mode;
}
/**
* Get custom field roles
*
* @param string $custom_fields serialized
* @return bool|array roles
*/
public function custom_field_roles( $custom_fields ) {
$fields = maybe_unserialize( $custom_fields );
if ( ! is_array( $fields ) ) {
return false;
}
// role field
global $wp_roles;
$exclude_roles = array_diff( array_keys( $wp_roles->roles ), UM()->roles()->get_editable_user_roles() );
$roles = UM()->roles()->get_roles( false, $exclude_roles );
$roles = array_map(
function( $item ) {
return html_entity_decode( $item, ENT_QUOTES );
},
$roles
);
foreach ( $fields as $field_key => $field_settings ) {
if ( strstr( $field_key, 'role_' ) && array_key_exists( 'options', $field_settings ) && is_array( $field_settings['options'] ) ) {
if ( isset( $this->post_form['mode'] ) && 'profile' === $this->post_form['mode'] ) {
// It's for a legacy case `array_key_exists( 'editable', $field_settings )`.
if ( ( array_key_exists( 'editable', $field_settings ) && empty( $field_settings['editable'] ) ) || ! um_can_edit_field( $field_settings ) ) {
continue;
}
}
if ( ! um_can_view_field( $field_settings ) ) {
continue;
}
$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;
}
}
// getting roles only from the first role fields
return array_keys( $intersected_options );
}
}
return false;
}
}
}
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'UM' ) ) {
/**
* Main UM Class
*
* @class UM
* @version 2.0
*
* @method UM_bbPress_API bbPress_API()
* @method UM_Followers_API Followers_API()
* @method UM_Friends_API Friends_API()
* @method UM_Instagram_API Instagram_API()
* @method UM_Mailchimp Mailchimp()
* @method UM_Messaging_API Messaging_API()
* @method UM_myCRED myCRED()
* @method UM_Notices Notices()
* @method UM_Notifications_API Notifications_API()
* @method UM_Online Online()
* @method UM_Profile_Completeness_API Profile_Completeness_API()
* @method UM_reCAPTCHA reCAPTCHA()
* @method UM_Reviews Reviews()
* @method UM_Activity_API Activity_API()
* @method UM_Social_Login_API Social_Login_API()
* @method UM_User_Tags User_Tags()
* @method UM_Verified_Users_API Verified_Users_API()
* @method UM_WooCommerce_API WooCommerce_API()
* @method UM_Terms_Conditions Terms_Conditions()
* @method UM_Private_Content Private_Content()
* @method UM_User_Locations User_Locations()
* @method UM_Photos_API Photos_API()
* @method UM_Groups Groups()
* @method UM_Frontend_Posting Frontend_Posting()
* @method UM_Notes Notes()
* @method UM_User_Bookmarks User_Bookmarks()
* @method UM_Unsplash Unsplash()
* @method UM_ForumWP ForumWP()
* @method UM_Profile_Tabs Profile_Tabs()
* @method UM_JobBoardWP JobBoardWP()
* @method UM_Google_Authenticator Google_Authenticator()
*/
final class UM extends UM_Functions {
/**
* @var UM the single instance of the class
*/
protected static $instance;
/**
* @var array all plugin's classes
*/
public $classes = array();
/**
* @var bool Old variable
*
* @todo deprecate this variable
*/
public $is_filtering;
/**
* WP Native permalinks turned on?
*
* @var
*/
public $is_permalinks = false;
/**
* @var null|string
*/
public $honeypot = null;
/**
* Main UM Instance
*
* Ensures only one instance of UM is loaded or can be loaded.
*
* @since 1.0
* @static
* @see UM()
* @return UM - Main instance
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
self::$instance->_um_construct();
}
return self::$instance;
}
/**
* Create plugin classes - not sure if it needs!!!!!!!!!!!!!!!
*
* @since 1.0
* @see UM()
*
* @param $name
* @param array $params
* @return mixed
*/
public function __call( $name, array $params ) {
if ( empty( $this->classes[ $name ] ) ) {
/**
* UM hook
*
* @type filter
* @title um_call_object_{$class_name}
* @description Extend call classes of Extensions for use UM()->class_name()->method|function
* @input_vars
* [{"var":"$class","type":"object","desc":"Class Instance"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_call_object_{$class_name}', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_call_object_{$class_name}', 'my_extension_class', 10, 1 );
* function my_extension_class( $class ) {
* // your code here
* return $class;
* }
* ?>
*/
$this->classes[ $name ] = apply_filters( 'um_call_object_' . $name, false );
}
return $this->classes[ $name ];
}
/**
* Function for add classes to $this->classes
* for run using UM()
*
* @since 2.0
*
* @param string $class_name
* @param bool $instance
*/
public function set_class( $class_name, $instance = false ) {
if ( empty( $this->classes[ $class_name ] ) ) {
$class = 'UM_' . $class_name;
$this->classes[ $class_name ] = $instance ? $class::instance() : new $class;
}
}
/**
* Cloning is forbidden.
* @since 1.0
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'ultimate-member' ), '1.0' );
}
/**
* Unserializing instances of this class is forbidden.
* @since 1.0
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'ultimate-member' ), '1.0' );
}
/**
* UM constructor.
*
* @since 1.0
*/
function __construct() {
parent::__construct();
}
/**
* UM pseudo-constructor.
*
* @since 2.0.18
*/
function _um_construct() {
//register autoloader for include UM classes
spl_autoload_register( array( $this, 'um__autoloader' ) );
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
if ( get_option( 'permalink_structure' ) ) {
$this->is_permalinks = true;
}
$this->is_filtering = 0;
$this->honeypot = 'um_request';
// textdomain loading
add_action( 'init', array( &$this, 'localize' ), 0 );
// include UM classes
$this->includes();
// include hook files
add_action( 'plugins_loaded', array( &$this, 'init' ), 0 );
//run hook for extensions init
add_action( 'plugins_loaded', array( &$this, 'extensions_init' ), -19 );
add_action( 'init', array( &$this, 'old_update_patch' ), 0 );
//run activation
register_activation_hook( UM_PLUGIN, array( &$this, 'activation' ) );
register_deactivation_hook( UM_PLUGIN, array( &$this, 'deactivation' ) );
if ( is_multisite() && ! defined( 'DOING_AJAX' ) ) {
add_action( 'wp_loaded', array( $this, 'maybe_network_activation' ) );
}
// init widgets
add_action( 'widgets_init', array( &$this, 'widgets_init' ) );
//include short non class functions
require_once 'um-short-functions.php';
require_once 'um-deprecated-functions.php';
}
}
/**
* Loading UM textdomain
*
* 'ultimate-member' by default
*/
public function localize() {
// The function `get_user_locale()` will return `get_locale()` result by default if user or its locale is empty.
$language_locale = get_user_locale();
/**
* UM hook
*
* @type filter
* @title um_language_locale
* @description Change UM language locale
* @input_vars
* [{"var":"$locale","type":"string","desc":"UM language locale"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_language_locale', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_language_locale', 'my_language_locale', 10, 1 );
* function my_language_locale( $locale ) {
* // your code here
* return $locale;
* }
* ?>
*/
$language_locale = apply_filters( 'um_language_locale', $language_locale );
/**
* UM hook
*
* @type filter
* @title um_language_textdomain
* @description Change UM textdomain
* @input_vars
* [{"var":"$domain","type":"string","desc":"UM Textdomain"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_language_textdomain', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_language_textdomain', 'my_textdomain', 10, 1 );
* function my_textdomain( $domain ) {
* // your code here
* return $domain;
* }
* ?>
*/
$language_domain = apply_filters( 'um_language_textdomain', 'ultimate-member' );
$language_file = WP_LANG_DIR . '/plugins/' . $language_domain . '-' . $language_locale . '.mo';
/**
* UM hook
*
* @type filter
* @title um_language_file
* @description Change UM language file path
* @input_vars
* [{"var":"$language_file","type":"string","desc":"UM language file path"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_language_file', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_language_file', 'my_language_file', 10, 1 );
* function my_language_file( $language_file ) {
* // your code here
* return $language_file;
* }
* ?>
*/
$language_file = apply_filters( 'um_language_file', $language_file );
// Unload textdomain if it has already loaded.
if ( is_textdomain_loaded( $language_domain ) ) {
unload_textdomain( $language_domain, true );
}
load_textdomain( $language_domain, $language_file );
}
/**
* 1.3.x active extensions deactivate for properly running 2.0.x AJAX upgrades
*/
function old_update_patch() {
global $um_woocommerce, $um_bbpress, $um_followers, $um_friends, $um_mailchimp, $um_messaging, $um_mycred, $um_notices, $um_notifications, $um_online, $um_private_content, $um_profile_completeness, $um_recaptcha, $um_reviews, $um_activity, $um_social_login, $um_user_tags, $um_verified;
if ( is_object( $um_woocommerce ) ) {
remove_action( 'init', array( $um_woocommerce, 'plugin_check' ), 1 );
$um_woocommerce->plugin_inactive = true;
}
if ( is_object( $um_bbpress ) ) {
remove_action( 'init', array( $um_bbpress, 'plugin_check' ), 4 );
$um_bbpress->plugin_inactive = true;
}
if ( is_object( $um_followers ) ) {
remove_action( 'init', array( $um_followers, 'plugin_check' ), 1 );
$um_followers->plugin_inactive = true;
}
if ( is_object( $um_friends ) ) {
remove_action( 'init', array( $um_friends, 'plugin_check' ), 1 );
$um_friends->plugin_inactive = true;
}
if ( is_object( $um_mailchimp ) ) {
remove_action( 'init', array( $um_mailchimp, 'plugin_check' ), 1 );
$um_mailchimp->plugin_inactive = true;
}
if ( is_object( $um_messaging ) ) {
remove_action( 'init', array( $um_messaging, 'plugin_check' ), 1 );
$um_messaging->plugin_inactive = true;
}
if ( is_object( $um_mycred ) ) {
remove_action( 'init', array( $um_mycred, 'plugin_check' ), 1 );
$um_mycred->plugin_inactive = true;
}
if ( is_object( $um_notices ) ) {
remove_action( 'init', array( $um_notices, 'plugin_check' ), 1 );
$um_notices->plugin_inactive = true;
}
if ( is_object( $um_notifications ) ) {
remove_action( 'init', array( $um_notifications, 'plugin_check' ), 1 );
$um_notifications->plugin_inactive = true;
}
if ( is_object( $um_online ) ) {
remove_action( 'init', array( $um_online, 'plugin_check' ), 1 );
$um_online->plugin_inactive = true;
}
if ( is_object( $um_private_content ) ) {
remove_action( 'init', array( $um_private_content, 'plugin_check' ), 1 );
$um_private_content->plugin_inactive = true;
}
if ( is_object( $um_profile_completeness ) ) {
remove_action( 'init', array( $um_profile_completeness, 'plugin_check' ), 1 );
$um_profile_completeness->plugin_inactive = true;
}
if ( is_object( $um_recaptcha ) ) {
remove_action( 'init', array( $um_recaptcha, 'plugin_check' ), 1 );
$um_recaptcha->plugin_inactive = true;
}
if ( is_object( $um_reviews ) ) {
remove_action( 'init', array( $um_reviews, 'plugin_check' ), 1 );
$um_reviews->plugin_inactive = true;
}
if ( is_object( $um_activity ) ) {
remove_action( 'init', array( $um_activity, 'plugin_check' ), 1 );
$um_activity->plugin_inactive = true;
}
if ( is_object( $um_social_login ) ) {
remove_action( 'init', array( $um_social_login, 'plugin_check' ), 1 );
$um_social_login->plugin_inactive = true;
}
if ( is_object( $um_user_tags ) ) {
remove_action( 'init', array( $um_user_tags, 'plugin_check' ), 1 );
$um_user_tags->plugin_inactive = true;
}
if ( is_object( $um_verified ) ) {
remove_action( 'init', array( $um_verified, 'plugin_check' ), 1 );
$um_verified->plugin_inactive = true;
}
}
/**
* Autoload UM classes handler
*
* @since 2.0
*
* @param $class
*/
function um__autoloader( $class ) {
if ( strpos( $class, 'um' ) === 0 ) {
$array = explode( '\\', strtolower( $class ) );
$array[ count( $array ) - 1 ] = 'class-'. end( $array );
if ( strpos( $class, 'um_ext' ) === 0 ) {
$full_path = str_replace( 'ultimate-member', '', untrailingslashit( UM_PATH ) ) . str_replace( '_', '-', $array[1] ) . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR;
unset( $array[0], $array[1] );
$path = implode( DIRECTORY_SEPARATOR, $array );
$path = str_replace( '_', '-', $path );
$full_path .= $path . '.php';
} else if ( strpos( $class, 'um\\' ) === 0 ) {
$class = implode( '\\', $array );
$slash = DIRECTORY_SEPARATOR;
$path = str_replace(
array( 'um\\', '_', '\\' ),
array( $slash, '-', $slash ),
$class );
$full_path = UM_PATH . 'includes' . $path . '.php';
}
if( isset( $full_path ) && file_exists( $full_path ) ) {
include_once $full_path;
}
}
}
/**
* Plugin Activation
*
* @since 2.0
*/
function activation() {
$this->single_site_activation();
if ( is_multisite() ) {
update_network_option( get_current_network_id(), 'um_maybe_network_wide_activation', 1 );
}
}
/**
* Plugin Deactivation
*
* @since 2.3
*/
function deactivation() {
$this->cron()->unschedule_events();
}
/**
* Maybe need multisite activation process
*
* @since 2.1.7
*/
function maybe_network_activation() {
$maybe_activation = get_network_option( get_current_network_id(), 'um_maybe_network_wide_activation' );
if ( $maybe_activation ) {
delete_network_option( get_current_network_id(), 'um_maybe_network_wide_activation' );
if ( is_plugin_active_for_network( UM_PLUGIN ) ) {
// get all blogs
$blogs = get_sites();
if ( ! empty( $blogs ) ) {
foreach( $blogs as $blog ) {
switch_to_blog( $blog->blog_id );
//make activation script for each sites blog
$this->single_site_activation();
restore_current_blog();
}
}
}
}
}
/**
* Single site plugin activation handler
*/
function single_site_activation() {
//first install
$version = get_option( 'um_version' );
if ( ! $version ) {
update_option( 'um_last_version_upgrade', UM_VERSION );
add_option( 'um_first_activation_date', time() );
//show avatars on first install
if ( ! get_option( 'show_avatars' ) ) {
update_option( 'show_avatars', 1 );
}
} else {
UM()->options()->update( 'rest_api_version', '1.0' );
}
if ( $version != UM_VERSION ) {
update_option( 'um_version', UM_VERSION );
}
//run setup
$this->common()->cpt()->create_post_types();
$this->setup()->run_setup();
$this->cron()->schedule_events();
}
/**
*
*/
function extensions_init() {
do_action( 'um_core_loaded' );
}
/**
* Include required core files used in admin and on the frontend.
*
* @since 2.0
*
* @return void
*/
public function includes() {
$this->common()->includes();
$this->access();
if ( $this->is_request( 'ajax' ) ) {
$this->ajax()->includes();
$this->admin();
$this->ajax_init();
$this->admin_ajax_hooks();
$this->metabox();
$this->admin_upgrade()->init_packages_ajax_handlers();
$this->admin_gdpr();
$this->columns();
$this->admin()->notices();
$this->admin_navmenu();
$this->plugin_updater();
$this->theme_updater();
} elseif ( $this->is_request( 'admin' ) ) {
$this->admin()->includes();
$this->admin();
$this->admin_menu();
$this->admin_upgrade();
$this->admin_settings();
$this->columns();
$this->metabox();
$this->users();
$this->dragdrop();
$this->admin_gdpr();
$this->admin_navmenu();
$this->plugin_updater();
$this->theme_updater();
} elseif ( $this->is_request( 'frontend' ) ) {
$this->frontend()->includes();
$this->account();
$this->password();
$this->login();
$this->register();
$this->user_posts();
$this->logout();
}
//common includes
$this->rewrite();
$this->mail();
$this->rest_api();
$this->shortcodes();
$this->roles();
$this->user();
$this->profile();
$this->builtin();
$this->form()->hooks();
$this->permalinks();
$this->modal();
$this->cron();
$this->mobile();
$this->external_integrations();
$this->gdpr();
$this->member_directory();
$this->blocks();
$this->secure();
//if multisite networks active
if ( is_multisite() ) {
$this->multisite();
}
}
/**
* @since 2.1.0
*
* @return um\core\Member_Directory()
*/
function member_directory() {
if ( empty( $this->classes['member_directory'] ) ) {
$search_in_table = $this->options()->get( 'member_directory_own_table' );
if ( ! empty( $search_in_table ) ) {
$this->classes['member_directory'] = new um\core\Member_Directory_Meta();
} else {
$this->classes['member_directory'] = new um\core\Member_Directory();
}
}
return $this->classes['member_directory'];
}
/**
* @since 2.6.1
*
* @return um\core\Blocks()
*/
public function blocks() {
if ( empty( $this->classes['blocks'] ) ) {
$this->classes['blocks'] = new um\core\Blocks();
}
return $this->classes['blocks'];
}
/**
* Get extension API
*
* @since 2.0.34
*
* @param $slug
*
* @return um_ext\um_bbpress\Init
*/
function extension( $slug ) {
if ( empty( $this->classes[ $slug ] ) ) {
$class = "um_ext\um_{$slug}\Init";
/**
* @var $class um_ext\um_bbpress\Init
*/
$this->classes[ $slug ] = $class::instance();
}
return $this->classes[ $slug ];
}
/**
* @param $class
*
* @return mixed
*/
function call_class( $class ) {
$key = strtolower( $class );
if ( empty( $this->classes[ $key ] ) ) {
$this->classes[ $key ] = new $class;
}
return $this->classes[ $key ];
}
/**
* @since 2.6.8
*
* @return um\ajax\Init
*/
public function ajax() {
if ( empty( $this->classes['um\ajax\init'] ) ) {
$this->classes['um\ajax\init'] = new um\ajax\Init();
}
return $this->classes['um\ajax\init'];
}
/**
* @since 2.0
* @since 2.6.8 changed namespace and class content.
*
* @return um\common\Init
*/
public function common() {
if ( empty( $this->classes['um\common\init'] ) ) {
$this->classes['um\common\init'] = new um\common\Init();
}
return $this->classes['um\common\init'];
}
/**
* @since 2.6.8
*
* @return um\frontend\Init
*/
public function frontend() {
if ( empty( $this->classes['um\frontend\init'] ) ) {
$this->classes['um\frontend\init'] = new um\frontend\Init();
}
return $this->classes['um\frontend\init'];
}
/**
* @since 2.0
*
* @return um\core\External_Integrations()
*/
function external_integrations() {
if ( empty( $this->classes['external_integrations'] ) ) {
$this->classes['external_integrations'] = new um\core\External_Integrations();
}
return $this->classes['external_integrations'];
}
/**
* @since 2.0
*
* @return um\core\Options()
*/
function options() {
if ( empty( $this->classes['options'] ) ) {
$this->classes['options'] = new um\core\Options();
}
return $this->classes['options'];
}
/**
* @since 2.0
*
* @return um\core\Plugin_Updater()
*/
function plugin_updater() {
if ( empty( $this->classes['plugin_updater'] ) ) {
$this->classes['plugin_updater'] = new um\core\Plugin_Updater();
}
return $this->classes['plugin_updater'];
}
/**
* @since 2.0.45
* @return um\admin\core\Admin_Theme_Updater()
*/
function theme_updater() {
if ( empty( $this->classes['theme_updater'] ) ) {
$this->classes['theme_updater'] = new um\admin\core\Admin_Theme_Updater();
}
return $this->classes['theme_updater'];
}
/**
* @since 2.0
*/
function ajax_init() {
new um\core\AJAX_Common();
}
/**
* @since 2.0.30
*/
function admin_ajax_hooks() {
if ( empty( $this->classes['admin_ajax_hooks'] ) ) {
$this->classes['admin_ajax_hooks'] = new um\admin\core\Admin_Ajax_Hooks();
}
return $this->classes['admin_ajax_hooks'];
}
/**
* @since 2.0
*
* @return um\admin\Admin
*/
public function admin() {
if ( empty( $this->classes['admin'] ) ) {
$this->classes['admin'] = new um\admin\Admin();
}
return $this->classes['admin'];
}
/**
* @since 2.0
*
* @return um\admin\core\Admin_Menu()
*/
function admin_menu() {
if ( empty( $this->classes['admin_menu'] ) ) {
$this->classes['admin_menu'] = new um\admin\core\Admin_Menu();
}
return $this->classes['admin_menu'];
}
/**
* @since 2.0.26
*
* @return um\admin\core\Admin_Navmenu()
*/
function admin_navmenu() {
if ( empty( $this->classes['admin_navmenu'] ) ) {
$this->classes['admin_navmenu'] = new um\admin\core\Admin_Navmenu();
}
return $this->classes['admin_navmenu'];
}
/**
* @since 2.0
*
* @return um\admin\core\Admin_Settings()
*/
function admin_settings() {
if ( empty( $this->classes['admin_settings'] ) ) {
$this->classes['admin_settings'] = new um\admin\core\Admin_Settings();
}
return $this->classes['admin_settings'];
}
/**
* @since 2.0
*
* @return um\admin\core\Admin_Upgrade()
*/
function admin_upgrade() {
if ( empty( $this->classes['admin_upgrade'] ) ) {
$this->classes['admin_upgrade'] = um\admin\core\Admin_Upgrade::instance();
//$this->classes['admin_upgrade'] = new um\admin\core\Admin_Upgrade();
}
return $this->classes['admin_upgrade'];
}
/**
* GDPR privacy policy
*
* @since 2.0.14
*
* @return bool|um\admin\core\Admin_GDPR()
*/
function admin_gdpr() {
global $wp_version;
if ( version_compare( $wp_version, '4.9.6', '<' ) ) {
return false;
}
if ( empty( $this->classes['admin_gdpr'] ) ) {
$this->classes['admin_gdpr'] = new um\admin\core\Admin_GDPR();
}
return $this->classes['admin_gdpr'];
}
/**
* GDPR privacy policy
*
* @since 2.0.14
*
* @return bool|um\core\GDPR()
*/
function gdpr() {
global $wp_version;
if ( version_compare( $wp_version, '4.9.6', '<' ) ) {
return false;
}
if ( empty( $this->classes['gdpr'] ) ) {
$this->classes['gdpr'] = new um\core\GDPR();
}
return $this->classes['gdpr'];
}
/**
* @since 2.0
*
* @return um\admin\core\Admin_Columns()
*/
function columns() {
if ( empty( $this->classes['admin_columns'] ) ) {
$this->classes['admin_columns'] = new um\admin\core\Admin_Columns();
}
return $this->classes['admin_columns'];
}
/**
* @since 2.0
* @depecated 2.7.0
*
* @return um\admin\Enqueue
*/
public function admin_enqueue() {
_deprecated_function( __METHOD__, '2.7.0', 'UM()->admin()->enqueue()' );
return $this->admin()->enqueue();
}
/**
* @since 2.0
*
* @return um\admin\core\Admin_Metabox()
*/
function metabox() {
if ( empty( $this->classes['admin_metabox'] ) ) {
$this->classes['admin_metabox'] = new um\admin\core\Admin_Metabox();
}
return $this->classes['admin_metabox'];
}
/**
* @since 2.0
*
* @return um\admin\core\Admin_Users()
*/
function users() {
if ( empty( $this->classes['admin_users'] ) ) {
$this->classes['admin_users'] = new um\admin\core\Admin_Users();
}
return $this->classes['admin_users'];
}
/**
* @since 2.0
*
* @return um\admin\core\Admin_Builder()
*/
function builder() {
if ( empty( $this->classes['admin_builder'] ) ) {
$this->classes['admin_builder'] = new um\admin\core\Admin_Builder();
}
return $this->classes['admin_builder'];
}
/**
* @since 2.0
*
* @return um\admin\core\Admin_DragDrop()
*/
function dragdrop() {
if ( empty( $this->classes['admin_dragdrop'] ) ) {
$this->classes['admin_dragdrop'] = new um\admin\core\Admin_DragDrop();
}
return $this->classes['admin_dragdrop'];
}
/**
* @since 2.0
*
* @param bool|array $data
* @return um\admin\core\Admin_Forms()
*/
function admin_forms( $data = false ) {
if ( ! isset( $this->classes[ 'admin_forms_' . $data['class'] ] ) || empty( $this->classes[ 'admin_forms_' . $data['class'] ] ) ) {
$this->classes[ 'admin_forms_' . $data['class'] ] = new um\admin\core\Admin_Forms( $data );
}
return $this->classes[ 'admin_forms_' . $data['class'] ];
}
/**
* @since 2.0
*
* @param bool|array $data
* @return um\admin\core\Admin_Forms_Settings()
*/
function admin_forms_settings( $data = false ) {
if ( ! isset( $this->classes[ 'admin_forms_settings_' . $data['class'] ] ) || empty( $this->classes[ 'admin_forms_settings_' . $data['class'] ] ) ) {
$this->classes[ 'admin_forms_settings_' . $data['class'] ] = new um\admin\core\Admin_Forms_Settings( $data );
}
return $this->classes[ 'admin_forms_settings_' . $data['class'] ];
}
/**
* @since 2.0.34
*
* @return um\Extensions
*/
function extensions() {
if ( empty( $this->classes['extensions'] ) ) {
$this->classes['extensions'] = new um\Extensions();
}
return $this->classes['extensions'];
}
/**
* @since 2.0
*
* @return um\Dependencies
*/
function dependencies() {
if ( empty( $this->classes['dependencies'] ) ) {
$this->classes['dependencies'] = new um\Dependencies();
}
return $this->classes['dependencies'];
}
/**
* @since 2.0
*
* @return um\Config
*/
function config() {
if ( empty( $this->classes['config'] ) ) {
$this->classes['config'] = new um\Config();
}
return $this->classes['config'];
}
/**
* @since 2.0
*
* @return um\core\rest\API_v1|um\core\rest\API_v2
*/
function rest_api() {
$api_version = $this->options()->get( 'rest_api_version' );
if ( empty( $this->classes['rest_api'] ) ) {
if ( '1.0' === $api_version ) {
$this->classes['rest_api'] = new um\core\rest\API_v1();
} elseif ( '2.0' === $api_version ) {
$this->classes['rest_api'] = new um\core\rest\API_v2();
} else {
$this->classes['rest_api'] = new um\core\rest\API_v1();
}
}
return $this->classes['rest_api'];
}
/**
* @since 2.0
*
* @return um\core\Rewrite
*/
function rewrite() {
if ( empty( $this->classes['rewrite'] ) ) {
$this->classes['rewrite'] = new um\core\Rewrite();
}
return $this->classes['rewrite'];
}
/**
* @since 2.0
*
* @return um\core\Setup
*/
function setup() {
if ( empty( $this->classes['setup'] ) ) {
$this->classes['setup'] = new um\core\Setup();
}
return $this->classes['setup'];
}
/**
* @since 2.0
*
* @return um\core\FontIcons
*/
function fonticons() {
if ( empty( $this->classes['fonticons'] ) ) {
$this->classes['fonticons'] = new um\core\FontIcons();
}
return $this->classes['fonticons'];
}
/**
* @since 2.0
*
* @return um\core\Login
*/
function login() {
if ( empty( $this->classes['login'] ) ) {
$this->classes['login'] = new um\core\Login();
}
return $this->classes['login'];
}
/**
* @since 2.0
*
* @return um\core\Register
*/
function register() {
if ( empty( $this->classes['register'] ) ) {
$this->classes['register'] = new um\core\Register();
}
return $this->classes['register'];
}
/**
* @since 2.0
* @todo Make it deprecated and review extensions.
*
* @return um\frontend\Enqueue
*/
public function enqueue() {
_deprecated_function( __METHOD__, '2.7.0', 'UM()->frontend()->enqueue()' );
return $this->frontend()->enqueue();
}
/**
* @since 2.0
*
* @return um\core\Shortcodes
*/
function shortcodes() {
if ( empty( $this->classes['shortcodes'] ) ) {
$this->classes['shortcodes'] = new um\core\Shortcodes();
}
return $this->classes['shortcodes'];
}
/**
* @since 2.0
*
* @return um\core\Account
*/
function account() {
if ( empty( $this->classes['account'] ) ) {
$this->classes['account'] = new um\core\Account();
}
return $this->classes['account'];
}
/**
* @since 2.0
*
* @return um\core\Password
*/
function password() {
if ( empty( $this->classes['password'] ) ) {
$this->classes['password'] = new um\core\Password();
}
return $this->classes['password'];
}
/**
* @since 2.0
*
* @return um\core\Form
*/
function form() {
if ( empty( $this->classes['form'] ) ) {
$this->classes['form'] = new um\core\Form();
}
return $this->classes['form'];
}
/**
* @since 2.0
*
* @return um\core\Fields
*/
function fields() {
if ( empty( $this->classes['fields'] ) ) {
$this->classes['fields'] = new um\core\Fields();
}
return $this->classes['fields'];
}
/**
* @since 2.0
*
* @return um\core\User
*/
function user() {
if ( empty( $this->classes['user'] ) ) {
$this->classes['user'] = new um\core\User();
}
return $this->classes['user'];
}
/**
* @since 2.0
*
* @return um\core\Roles_Capabilities
*/
function roles() {
if ( empty( $this->classes['roles'] ) ) {
$this->classes['roles'] = new um\core\Roles_Capabilities();
}
return $this->classes['roles'];
}
/**
* @since 2.0
*
* @return um\core\User_posts
*/
function user_posts() {
if ( empty( $this->classes['user_posts'] ) ) {
$this->classes['user_posts'] = new um\core\User_posts();
}
return $this->classes['user_posts'];
}
/**
* @since 2.0
*
* @return um\core\Profile
*/
function profile() {
if ( empty( $this->classes['profile'] ) ) {
$this->classes['profile'] = new um\core\Profile();
}
return $this->classes['profile'];
}
/**
* @since 2.0
*
* @return um\core\Query
*/
function query() {
if ( empty( $this->classes['query'] ) ) {
$this->classes['query'] = new um\core\Query();
}
return $this->classes['query'];
}
/**
* @since 2.0
*
* @return um\core\Date_Time
*/
function datetime() {
if ( empty( $this->classes['datetime'] ) ) {
$this->classes['datetime'] = new um\core\Date_Time();
}
return $this->classes['datetime'];
}
/**
* @since 2.0
*
* @return um\core\Builtin
*/
function builtin() {
if ( empty( $this->classes['builtin'] ) ) {
$this->classes['builtin'] = new um\core\Builtin();
}
return $this->classes['builtin'];
}
/**
* @since 2.0
*
* @return um\core\Files
*/
function files() {
if ( empty( $this->classes['files'] ) ) {
$this->classes['files'] = new um\core\Files();
}
return $this->classes['files'];
}
/**
* @since 2.0.21
*
* @return um\core\Uploader
*/
function uploader() {
if ( empty( $this->classes['uploader'] ) ) {
$this->classes['uploader'] = new um\core\Uploader();
}
return $this->classes['uploader'];
}
/**
* @since 2.0
*
* @return um\core\Validation
*/
function validation() {
if ( empty( $this->classes['validation'] ) ) {
$this->classes['validation'] = new um\core\Validation();
}
return $this->classes['validation'];
}
/**
* @since 2.0
*
* @return um\core\Access
*/
function access() {
if ( empty( $this->classes['access'] ) ) {
$this->classes['access'] = new um\core\Access();
}
return $this->classes['access'];
}
/**
* @since 2.0
*
* @return um\core\Permalinks
*/
function permalinks() {
if ( empty( $this->classes['permalinks'] ) ) {
$this->classes['permalinks'] = new um\core\Permalinks();
}
return $this->classes['permalinks'];
}
/**
* @since 2.0
*
* @return um\core\Mail
*/
function mail() {
if ( empty( $this->classes['mail'] ) ) {
$this->classes['mail'] = new um\core\Mail();
}
return $this->classes['mail'];
}
/**
* @deprecated 2.1.0
*
* @since 2.0
*
* @return um\core\Members
*/
function members() {
um_deprecated_function( 'UM()->members()', '2.1.0', 'UM()->member_directory()' );
if ( empty( $this->classes['members'] ) ) {
$this->classes['members'] = new um\core\Members();
}
return $this->classes['members'];
}
/**
* @since 2.0
*
* @return um\core\Logout
*/
function logout() {
if ( empty( $this->classes['logout'] ) ) {
$this->classes['logout'] = new um\core\Logout();
}
return $this->classes['logout'];
}
/**
* @since 2.0
*
* @return um\core\Modal
*/
function modal() {
if ( empty( $this->classes['modal'] ) ) {
$this->classes['modal'] = new um\core\Modal();
}
return $this->classes['modal'];
}
/**
* @since 2.0
*
* @return um\core\Cron
*/
function cron() {
if ( empty( $this->classes['cron'] ) ) {
$this->classes['cron'] = new um\core\Cron();
}
return $this->classes['cron'];
}
/**
* @since 2.0
*
* @return um\core\Templates
*/
function templates() {
if ( empty( $this->classes['templates'] ) ) {
$this->classes['templates'] = new um\core\Templates();
}
return $this->classes['templates'];
}
/**
* @since 2.0
*
* @return um\lib\mobiledetect\Um_Mobile_Detect
*/
function mobile() {
if ( empty( $this->classes['mobile'] ) ) {
$this->classes['mobile'] = new um\lib\mobiledetect\Um_Mobile_Detect();
}
return $this->classes['mobile'];
}
/**
* @since 2.0.44
*
* @return um\core\Multisite
*/
function multisite() {
if ( empty( $this->classes['multisite'] ) ) {
$this->classes['multisite'] = new um\core\Multisite();
}
return $this->classes['multisite'];
}
/**
* Include files with hooked filters/actions
*
* @since 2.0
*/
function init() {
ob_start();
require_once 'core/um-actions-form.php';
require_once 'core/um-actions-access.php';
require_once 'core/um-actions-wpadmin.php';
require_once 'core/um-actions-core.php';
require_once 'core/um-actions-ajax.php';
require_once 'core/um-actions-login.php';
require_once 'core/um-actions-register.php';
require_once 'core/um-actions-profile.php';
require_once 'core/um-actions-account.php';
require_once 'core/um-actions-global.php';
require_once 'core/um-actions-user.php';
require_once 'core/um-actions-save-profile.php';
require_once 'core/um-actions-misc.php';
require_once 'core/um-filters-login.php';
require_once 'core/um-filters-fields.php';
require_once 'core/um-filters-files.php';
require_once 'core/um-filters-navmenu.php';
require_once 'core/um-filters-avatars.php';
require_once 'core/um-filters-user.php';
require_once 'core/um-filters-profile.php';
require_once 'core/um-filters-account.php';
require_once 'core/um-filters-misc.php';
require_once 'core/um-filters-commenting.php';
}
/**
* Init UM widgets
*
* @since 2.0
*/
function widgets_init() {
register_widget( 'um\widgets\UM_Search_Widget' );
}
}
}
/**
* Function for calling UM methods and variables
*
* @since 2.0
*
* @return UM
*/
function UM() {
return UM::instance();
}
// Global for backwards compatibility.
$GLOBALS['ultimatemember'] = UM();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment