* @example
*
*/
$base_uri = apply_filters( 'um_emoji_base_uri', 'https://s.w.org/images/core/emoji/' );
$this->emoji[':)'] = $base_uri . '72x72/1f604.png';
$this->emoji[':smiley:'] = $base_uri . '72x72/1f603.png';
$this->emoji[':D'] = $base_uri . '72x72/1f600.png';
$this->emoji[':$'] = $base_uri . '72x72/1f60a.png';
$this->emoji[':relaxed:'] = $base_uri . '72x72/263a.png';
$this->emoji[';)'] = $base_uri . '72x72/1f609.png';
$this->emoji[':heart_eyes:'] = $base_uri . '72x72/1f60d.png';
$this->emoji[':kissing_heart:'] = $base_uri . '72x72/1f618.png';
$this->emoji[':kissing_closed_eyes:'] = $base_uri . '72x72/1f61a.png';
$this->emoji[':kissing:'] = $base_uri . '72x72/1f617.png';
$this->emoji[':kissing_smiling_eyes:'] = $base_uri . '72x72/1f619.png';
$this->emoji[';P'] = $base_uri . '72x72/1f61c.png';
$this->emoji[':P'] = $base_uri . '72x72/1f61b.png';
$this->emoji[':stuck_out_tongue_closed_eyes:'] = $base_uri . '72x72/1f61d.png';
$this->emoji[':flushed:'] = $base_uri . '72x72/1f633.png';
$this->emoji[':grin:'] = $base_uri . '72x72/1f601.png';
$this->emoji[':pensive:'] = $base_uri . '72x72/1f614.png';
$this->emoji[':relieved:'] = $base_uri . '72x72/1f60c.png';
$this->emoji[':unamused'] = $base_uri . '72x72/1f612.png';
$this->emoji[':('] = $base_uri . '72x72/1f61e.png';
$this->emoji[':persevere:'] = $base_uri . '72x72/1f623.png';
$this->emoji[":'("] = $base_uri . '72x72/1f622.png';
$this->emoji[':joy:'] = $base_uri . '72x72/1f602.png';
$this->emoji[':sob:'] = $base_uri . '72x72/1f62d.png';
$this->emoji[':sleepy:'] = $base_uri . '72x72/1f62a.png';
$this->emoji[':disappointed_relieved:'] = $base_uri . '72x72/1f625.png';
$this->emoji[':cold_sweat:'] = $base_uri . '72x72/1f630.png';
$this->emoji[':sweat_smile:'] = $base_uri . '72x72/1f605.png';
$this->emoji[':sweat:'] = $base_uri . '72x72/1f613.png';
$this->emoji[':weary:'] = $base_uri . '72x72/1f629.png';
$this->emoji[':tired_face:'] = $base_uri . '72x72/1f62b.png';
$this->emoji[':fearful:'] = $base_uri . '72x72/1f628.png';
$this->emoji[':scream:'] = $base_uri . '72x72/1f631.png';
$this->emoji[':angry:'] = $base_uri . '72x72/1f620.png';
$this->emoji[':rage:'] = $base_uri . '72x72/1f621.png';
$this->emoji[':triumph'] = $base_uri . '72x72/1f624.png';
$this->emoji[':confounded:'] = $base_uri . '72x72/1f616.png';
$this->emoji[':laughing:'] = $base_uri . '72x72/1f606.png';
$this->emoji[':yum:'] = $base_uri . '72x72/1f60b.png';
$this->emoji[':mask:'] = $base_uri . '72x72/1f637.png';
$this->emoji[':cool:'] = $base_uri . '72x72/1f60e.png';
$this->emoji[':sleeping:'] = $base_uri . '72x72/1f634.png';
$this->emoji[':dizzy_face:'] = $base_uri . '72x72/1f635.png';
$this->emoji[':astonished:'] = $base_uri . '72x72/1f632.png';
$this->emoji[':worried:'] = $base_uri . '72x72/1f61f.png';
$this->emoji[':frowning:'] = $base_uri . '72x72/1f626.png';
$this->emoji[':anguished:'] = $base_uri . '72x72/1f627.png';
$this->emoji[':smiling_imp:'] = $base_uri . '72x72/1f608.png';
$this->emoji[':imp:'] = $base_uri . '72x72/1f47f.png';
$this->emoji[':open_mouth:'] = $base_uri . '72x72/1f62e.png';
$this->emoji[':grimacing:'] = $base_uri . '72x72/1f62c.png';
$this->emoji[':neutral_face:'] = $base_uri . '72x72/1f610.png';
$this->emoji[':confused:'] = $base_uri . '72x72/1f615.png';
$this->emoji[':hushed:'] = $base_uri . '72x72/1f62f.png';
$this->emoji[':no_mouth:'] = $base_uri . '72x72/1f636.png';
$this->emoji[':innocent:'] = $base_uri . '72x72/1f607.png';
$this->emoji[':smirk:'] = $base_uri . '72x72/1f60f.png';
$this->emoji[':expressionless:'] = $base_uri . '72x72/1f611.png';
}
/**
* Conditional logout form
*
* @param array $args
*
* @return array
*/
function display_logout_form( $args ) {
if ( is_user_logged_in() && isset( $args['mode'] ) && $args['mode'] == 'login' ) {
if ( isset( UM()->user()->preview ) && UM()->user()->preview ) {
return $args;
}
if ( get_current_user_id() != um_user( 'ID' ) ) {
um_fetch_user( get_current_user_id() );
}
$args['template'] = 'logout';
}
return $args;
}
/**
* Filter shortcode args
*
* @param array $args
*
* @return array
*/
function parse_shortcode_args( $args ) {
if ( $this->message_mode == true ) {
if ( ! empty( $_REQUEST['um_role'] ) ) {
$args['template'] = 'message';
$roleID = sanitize_key( $_REQUEST['um_role'] );
$role = UM()->roles()->role_data( $roleID );
if ( ! empty( $role ) && ! empty( $role['status'] ) ) {
$message_key = $role['status'] . '_message';
$this->custom_message = ! empty( $role[ $message_key ] ) ? stripslashes( $role[ $message_key ] ) : '';
}
}
}
foreach ( $args as $k => $v ) {
$args[ $k ] = maybe_unserialize( $args[ $k ] );
}
return $args;
}
/**
* Emoji support
*
* @param $content
*
* @return mixed|string
*/
function emotize( $content ) {
$content = stripslashes( $content );
foreach ( $this->emoji as $code => $val ) {
$regex = str_replace(array('(', ')'), array("\\" . '(', "\\" . ')'), $code);
$content = preg_replace('/(' . $regex . ')(\s|$)/', '$2', $content);
}
return $content;
}
/**
* Remove wpautop filter for post content if it's UM core page
*/
function is_um_page() {
if ( is_ultimatemember() ) {
remove_filter( 'the_content', 'wpautop' );
}
}
/**
* Extend body classes
*
* @param $classes
*
* @return array
*/
function body_class( $classes ) {
$array = UM()->config()->permalinks;
if ( ! $array ) {
return $classes;
}
foreach ( $array as $slug => $info ) {
if ( um_is_core_page( $slug ) ) {
$classes[] = 'um-page-' . $slug;
if ( is_user_logged_in() ) {
$classes[] = 'um-page-loggedin';
} else {
$classes[] = 'um-page-loggedout';
}
}
}
if ( um_is_core_page( 'user' ) && um_is_user_himself() ) {
$classes[] = 'um-own-profile';
}
return $classes;
}
/**
* Retrieve core login form
*
* @return int
*/
function core_login_form() {
$forms = get_posts(array('post_type' => 'um_form', 'posts_per_page' => 1, 'meta_key' => '_um_core', 'meta_value' => 'login'));
$form_id = isset( $forms[0]->ID ) ? $forms[0]->ID: 0;
return $form_id;
}
/**
* Load a compatible template
*
* @param $tpl
*/
function load_template( $tpl ) {
$loop = ( $this->loop ) ? $this->loop : array();
if ( isset( $this->set_args ) && is_array( $this->set_args ) ) {
$args = $this->set_args;
unset( $args['file'] );
unset( $args['theme_file'] );
unset( $args['tpl'] );
$args = apply_filters( 'um_template_load_args', $args, $tpl );
extract( $args );
}
$file = um_path . "templates/{$tpl}.php";
$theme_file = get_stylesheet_directory() . "/ultimate-member/templates/{$tpl}.php";
if ( file_exists( $theme_file ) ) {
$file = $theme_file;
}
if ( file_exists( $file ) ) {
// Avoid Directory Traversal vulnerability by the checking the realpath.
// Templates can be situated only in the get_stylesheet_directory() or plugindir templates.
$real_file = wp_normalize_path( realpath( $file ) );
if ( 0 === strpos( $real_file, wp_normalize_path( um_path . "templates" . DIRECTORY_SEPARATOR ) ) || 0 === strpos( $real_file, wp_normalize_path( get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'ultimate-member' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR ) ) ) {
include $file;
}
}
}
/**
* Add class based on shortcode
*
* @param $mode
* @param array $args
*
* @return mixed|string|void
*/
function get_class($mode, $args = array()) {
$classes = 'um-' . $mode;
if (is_admin()) {
$classes .= ' um-in-admin';
}
if (isset(UM()->form()->errors) && UM()->form()->errors) {
$classes .= ' um-err';
}
if (UM()->fields()->editing == true) {
$classes .= ' um-editing';
}
if (UM()->fields()->viewing == true) {
$classes .= ' um-viewing';
}
if (isset($args['template']) && $args['template'] != $args['mode']) {
$classes .= ' um-' . $args['template'];
}
/**
* UM hook
*
* @type filter
* @title um_form_official_classes__hook
* @description Change official form classes
* @input_vars
* [{"var":"$classes","type":"string","desc":"Classes string"}]
* @change_log
* ["Since: 2.0"]
* @usage
*
* @example
*
*/
$classes = apply_filters( 'um_form_official_classes__hook', $classes );
return $classes;
}
/**
* Logged-in only content
*
* @param array $args
* @param string $content
*
* @return string
*/
function um_loggedin( $args = array(), $content = "" ) {
ob_start();
$args = shortcode_atts(
array(
'lock_text' => __( 'This content has been restricted to logged in users only. Please login to view this content.', 'ultimate-member' ),
'show_lock' => 'yes',
),
$args,
'um_loggedin'
);
if ( ! is_user_logged_in() ) {
if ( 'no' === $args['show_lock'] ) {
echo '';
} else {
$args['lock_text'] = $this->convert_locker_tags( $args['lock_text'] );
UM()->get_template( 'login-to-view.php', '', $args, true );
}
} else {
if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
echo do_shortcode( $this->convert_locker_tags( wpautop( $content ) ) );
} else {
echo apply_shortcodes( $this->convert_locker_tags( wpautop( $content ) ) );
}
}
$output = ob_get_clean();
return htmlspecialchars_decode( $output, ENT_NOQUOTES );
}
/**
* Logged-out only content
*
* @param array $args
* @param string $content
*
* @return string
*/
function um_loggedout( $args = array(), $content = '' ) {
ob_start();
// Hide for logged in users
if ( is_user_logged_in() ) {
echo '';
} else {
if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
echo do_shortcode( wpautop( $content ) );
} else {
echo apply_shortcodes( wpautop( $content ) );
}
}
$output = ob_get_clean();
return $output;
}
/**
* @param array $args
*
* @return string
*/
function ultimatemember_login( $args = array() ) {
global $wpdb;
$args = ! empty( $args ) ? $args : array();
$default_login = $wpdb->get_var(
"SELECT pm.post_id
FROM {$wpdb->postmeta} pm
LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'login' AND
pm2.meta_value = '1'"
);
$args['form_id'] = $default_login;
$shortcode_attrs = '';
foreach ( $args as $key => $value ) {
$shortcode_attrs .= " {$key}=\"{$value}\"";
}
if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
return do_shortcode( "[ultimatemember {$shortcode_attrs} /]" );
} else {
return apply_shortcodes( "[ultimatemember {$shortcode_attrs} /]" );
}
}
/**
* @param array $args
*
* @return string
*/
function ultimatemember_register( $args = array() ) {
global $wpdb;
$args = ! empty( $args ) ? $args : array();
$default_register = $wpdb->get_var(
"SELECT pm.post_id
FROM {$wpdb->postmeta} pm
LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'register' AND
pm2.meta_value = '1'"
);
$args['form_id'] = $default_register;
$shortcode_attrs = '';
foreach ( $args as $key => $value ) {
$shortcode_attrs .= " {$key}=\"{$value}\"";
}
if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
return do_shortcode( "[ultimatemember {$shortcode_attrs} /]" );
} else {
return apply_shortcodes( "[ultimatemember {$shortcode_attrs} /]" );
}
}
/**
* @param array $args
*
* @return string
*/
function ultimatemember_profile( $args = array() ) {
global $wpdb;
$args = ! empty( $args ) ? $args : array();
$default_profile = $wpdb->get_var(
"SELECT pm.post_id
FROM {$wpdb->postmeta} pm
LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'profile' AND
pm2.meta_value = '1'"
);
$args['form_id'] = $default_profile;
$shortcode_attrs = '';
foreach ( $args as $key => $value ) {
$shortcode_attrs .= " {$key}=\"{$value}\"";
}
if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
return do_shortcode( "[ultimatemember {$shortcode_attrs} /]" );
} else {
return apply_shortcodes( "[ultimatemember {$shortcode_attrs} /]" );
}
}
/**
* @param array $args
*
* @return string
*/
function ultimatemember_directory( $args = array() ) {
global $wpdb;
$args = ! empty( $args ) ? $args : array();
$default_directory = $wpdb->get_var(
"SELECT pm.post_id
FROM {$wpdb->postmeta} pm
LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'directory' AND
pm2.meta_value = '1'"
);
$args['form_id'] = $default_directory;
$shortcode_attrs = '';
foreach ( $args as $key => $value ) {
$shortcode_attrs .= " {$key}=\"{$value}\"";
}
if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
return do_shortcode( "[ultimatemember {$shortcode_attrs} /]" );
} else {
return apply_shortcodes( "[ultimatemember {$shortcode_attrs} /]" );
}
}
/**
* Shortcode
*
* @param array $args
*
* @return string
*/
function ultimatemember( $args = array() ) {
return $this->load( $args );
}
/**
* Load a module with global function
*
* @param $args
*
* @return string
*/
public function load( $args ) {
$defaults = array();
$args = wp_parse_args( $args, $defaults );
// when to not continue
$this->form_id = isset( $args['form_id'] ) ? $args['form_id'] : null;
if ( ! $this->form_id ) {
return;
}
$this->form_status = get_post_status( $this->form_id );
if ( 'publish' !== $this->form_status ) {
return;
}
// get data into one global array
$post_data = UM()->query()->post_data( $this->form_id );
$args = array_merge( $args, $post_data );
ob_start();
/**
* Filters change arguments on load shortcode
*
* @since 2.0
* @hook um_pre_args_setup
*
* @param {array} $post_data $_POST data.
*
* @return {array} $post_data data.
*
* @example