* @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 ] ) ? $this->convert_user_tags( 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 array $classes
*
* @return array
*/
public 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';
$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'], $args['theme_file'], $args['tpl'] );
$args = apply_filters( 'um_template_load_args', $args, $tpl );
/*
* This use of extract() cannot be removed. There are many possible ways that
* templates could depend on variables that it creates existing, and no way to
* detect and deprecate it.
*
* Passing the EXTR_SKIP flag is the safest option, ensuring globals and
* function variables cannot be overwritten.
*/
// phpcs:ignore WordPress.PHP.DontExtract.extract_extract
extract( $args, EXTR_SKIP );
}
$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 ( true === UM()->fields()->editing ) {
$classes .= ' um-editing';
}
if ( true === UM()->fields()->viewing ) {
$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;
}
/**
* Display post author's link to UM User Profile.
*
* @since 2.8.2
*
* Example 1: [um_author_profile_link] current post author User Profile URL
* Example 2: [um_author_profile_link title="User profile" user_id="29"]
* Example 3: [um_author_profile_link title="User profile" user_id="29"]Visit Author Profile[/um_author_profile_link]
* Example 4: [um_author_profile_link raw="1"] for result like http://localhost:8000/user/janedoe/
*
* @param array $attr {
* Attributes of the shortcode.
*
* @type string $class A link class.
* @type string $title A link text.
* @type int $user_id User ID. Author ID if empty.
* @type bool $raw Get raw URL or link layout. `false` by default.
* }
* @param string $content
* @return string Profile link HTML or profile link URL if the link text is empty.
*/
public function author_profile_link( $attr = array(), $content = '' ) {
$default_user_id = 0;
if ( is_singular() ) {
$default_user_id = get_post()->post_author;
} elseif ( is_author() ) {
$default_user_id = get_the_author_meta( 'ID' );
}
$defaults_atts = array(
'class' => 'um-link um-profile-link',
'title' => __( 'Go to profile', 'ultimate-member' ),
'user_id' => $default_user_id,
'raw' => false,
);
$atts = shortcode_atts( $defaults_atts, $attr, 'um_author_profile_link' );
if ( empty( $atts['user_id'] ) ) {
return '';
}
$user_id = absint( $atts['user_id'] );
$url = um_user_profile_url( $user_id );
if ( empty( $url ) ) {
return '';
}
if ( ! empty( $atts['raw'] ) ) {
return $url;
}
$title = ! empty( $atts['title'] ) ? $atts['title'] : __( 'Go to profile', 'ultimate-member' );
$link_html = empty( $content ) ? $title : $content;
return '' . wp_kses_post( $link_html ) . '';
}
/**
* @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
*/
public function ultimatemember( $args = array() ) {
// There is possible to use 'shortcode_atts_ultimatemember' filter for getting customized `$args`.
$args = shortcode_atts(
array(
'form_id' => '',
'is_block' => false,
),
$args,
'ultimatemember'
);
// Sanitize shortcode arguments.
$args['form_id'] = ! empty( $args['form_id'] ) ? absint( $args['form_id'] ) : '';
$args['is_block'] = (bool) $args['is_block'];
/**
* Filters variable for enable singleton shortcode loading on the same page.
* Note: Set it to `false` if you don't need to render the same form twice or more on the same page.
*
* @since 2.6.8
* @since 2.6.9 $disable argument set to `true` by default
*
* @hook um_ultimatemember_shortcode_disable_singleton
*
* @param {bool} $disable Disabled singleton. By default, it's `true`.
* @param {array} $args Shortcode arguments.
*
* @return {bool} Disabled singleton or not.
*
* @example