2017-07-26 14:57:52 +03:00
< ? php
namespace um\core ;
2023-04-24 02:25:10 +03:00
if ( ! defined ( 'ABSPATH' ) ) {
exit ;
}
2017-07-26 14:57:52 +03:00
2018-03-26 01:27:46 +03:00
if ( ! class_exists ( 'um\core\Shortcodes' ) ) {
2018-03-20 13:24:38 +02:00
/**
* Class Shortcodes
* @package um\core
*/
class Shortcodes {
2023-07-12 11:46:03 +03:00
/**
* @var array
*/
public $forms_exist = array ();
2023-04-17 20:16:15 +03:00
/**
* @var string
*/
public $profile_role = '' ;
2018-03-20 13:24:38 +02:00
/**
2023-04-17 20:16:15 +03:00
* @var bool
2018-03-20 13:24:38 +02:00
*/
2023-04-17 20:16:15 +03:00
public $message_mode = false ;
2018-03-20 13:24:38 +02:00
2023-04-17 20:16:15 +03:00
/**
* @var string
*/
public $custom_message = '' ;
2018-03-20 13:24:38 +02:00
2023-04-17 20:16:15 +03:00
/**
* @var array
*/
public $loop = array ();
2018-03-20 13:24:38 +02:00
2023-04-17 20:16:15 +03:00
/**
* @var array
*/
public $emoji = array ();
2018-03-20 13:24:38 +02:00
2023-04-24 02:25:10 +03:00
/**
* @var null|int
*/
public $form_id = null ;
/**
* @var null|string
*/
public $form_status = null ;
/**
* @var array
*/
public $set_args = array ();
2023-04-17 20:16:15 +03:00
/**
* Shortcodes constructor.
*/
public function __construct () {
2018-03-20 13:24:38 +02:00
add_shortcode ( 'ultimatemember' , array ( & $this , 'ultimatemember' ) );
2018-10-22 21:53:43 +03:00
add_shortcode ( 'ultimatemember_login' , array ( & $this , 'ultimatemember_login' ) );
add_shortcode ( 'ultimatemember_register' , array ( & $this , 'ultimatemember_register' ) );
add_shortcode ( 'ultimatemember_profile' , array ( & $this , 'ultimatemember_profile' ) );
add_shortcode ( 'ultimatemember_directory' , array ( & $this , 'ultimatemember_directory' ) );
2018-03-20 13:24:38 +02:00
add_shortcode ( 'um_loggedin' , array ( & $this , 'um_loggedin' ) );
add_shortcode ( 'um_loggedout' , array ( & $this , 'um_loggedout' ) );
add_shortcode ( 'um_show_content' , array ( & $this , 'um_shortcode_show_content_for_role' ) );
add_shortcode ( 'ultimatemember_searchform' , array ( & $this , 'ultimatemember_searchform' ) );
2023-12-06 18:25:13 +02:00
if ( ! shortcode_exists ( 'um_profile_link' ) ) {
add_shortcode ( 'um_profile_link' , array ( & $this , 'um_profile_link' ) );
}
2018-03-20 13:24:38 +02:00
add_filter ( 'body_class' , array ( & $this , 'body_class' ), 0 );
add_filter ( 'um_shortcode_args_filter' , array ( & $this , 'display_logout_form' ), 99 );
add_filter ( 'um_shortcode_args_filter' , array ( & $this , 'parse_shortcode_args' ), 99 );
/**
* UM hook
*
* @type filter
* @title um_emoji_base_uri
* @description Change Emoji base URL
* @input_vars
* [{"var":"$url","type":"string","desc":"Base URL"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_emoji_base_uri', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_emoji_base_uri', 'my_emoji_base_uri', 10, 1 );
* function my_emoji_base_uri( $url ) {
* // your code here
* return $url;
* }
* ?>
*/
$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 ) {
2019-11-28 18:11:30 +02:00
if ( is_user_logged_in () && isset ( $args [ 'mode' ] ) && $args [ 'mode' ] == 'login' ) {
if ( isset ( UM () -> user () -> preview ) && UM () -> user () -> preview ) {
return $args ;
}
2018-03-20 13:24:38 +02:00
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' ;
2021-06-29 02:51:54 +03:00
$roleID = sanitize_key ( $_REQUEST [ 'um_role' ] );
2018-03-20 13:24:38 +02:00
$role = UM () -> roles () -> role_data ( $roleID );
2021-06-29 02:51:54 +03:00
if ( ! empty ( $role ) && ! empty ( $role [ 'status' ] ) ) {
$message_key = $role [ 'status' ] . '_message' ;
2023-09-05 02:04:03 +03:00
$this -> custom_message = ! empty ( $role [ $message_key ] ) ? $this -> convert_user_tags ( stripslashes ( $role [ $message_key ] ) ) : '' ;
2018-03-20 13:24:38 +02:00
}
}
}
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|$)/' , '<img src="' . $val . '" alt="' . $code . '" title="' . $code . '" class="emoji" />$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' );
}
}
/**
2023-11-03 17:31:18 +02:00
* Extend body classes.
2018-03-20 13:24:38 +02:00
*
2023-11-03 17:31:18 +02:00
* @param array $classes
2018-03-20 13:24:38 +02:00
*
* @return array
*/
2023-11-03 17:31:18 +02:00
public function body_class ( $classes ) {
2018-03-20 13:24:38 +02:00
$array = UM () -> config () -> permalinks ;
if ( ! $array ) {
return $classes ;
}
foreach ( $array as $slug => $info ) {
if ( um_is_core_page ( $slug ) ) {
2024-01-01 21:17:02 +02:00
$classes [] = 'um-page' ;
2018-03-20 13:24:38 +02:00
$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 ;
2018-10-15 10:46:50 +03:00
2023-06-28 20:56:09 +03:00
unset ( $args [ 'file' ], $args [ 'theme_file' ], $args [ 'tpl' ] );
2018-03-20 13:24:38 +02:00
2018-08-13 14:42:49 +03:00
$args = apply_filters ( 'um_template_load_args' , $args , $tpl );
2023-06-28 20:56:09 +03:00
/*
* 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 );
2018-03-20 13:24:38 +02:00
}
2023-06-28 20:56:09 +03:00
$file = UM_PATH . " templates/ { $tpl } .php " ;
2018-03-20 13:24:38 +02:00
$theme_file = get_stylesheet_directory () . " /ultimate-member/templates/ { $tpl } .php " ;
if ( file_exists ( $theme_file ) ) {
$file = $theme_file ;
}
if ( file_exists ( $file ) ) {
2022-09-27 15:13:35 +03:00
// Avoid Directory Traversal vulnerability by the checking the realpath.
// Templates can be situated only in the get_stylesheet_directory() or plugindir templates.
2022-10-10 15:29:30 +03:00
$real_file = wp_normalize_path ( realpath ( $file ) );
2023-09-13 22:56:32 +03:00
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 ) ) ) {
2022-09-27 15:13:35 +03:00
include $file ;
}
2018-03-20 13:24:38 +02:00
}
}
/**
* 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' ;
}
2023-08-15 03:49:13 +03:00
if ( true === UM () -> fields () -> editing ) {
2018-03-20 13:24:38 +02:00
$classes .= ' um-editing' ;
}
2023-08-15 03:49:13 +03:00
if ( true === UM () -> fields () -> viewing ) {
2018-03-20 13:24:38 +02:00
$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
* <?php add_filter( 'um_form_official_classes__hook', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_form_official_classes__hook', 'my_form_official_classes', 10, 1 );
* function my_form_official_classes( $classes ) {
* // your code here
* return $classes;
* }
* ?>
*/
$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 ();
2022-05-24 18:29:39 +03:00
$args = shortcode_atts (
array (
'lock_text' => __ ( 'This content has been restricted to logged in users only. Please <a href="{login_referrer}">login</a> to view this content.' , 'ultimate-member' ),
'show_lock' => 'yes' ,
),
$args ,
'um_loggedin'
2018-03-20 13:24:38 +02:00
);
if ( ! is_user_logged_in () ) {
2022-05-24 18:29:39 +03:00
if ( 'no' === $args [ 'show_lock' ] ) {
2018-03-20 13:24:38 +02:00
echo '' ;
} else {
2018-10-31 11:03:36 +02:00
$args [ 'lock_text' ] = $this -> convert_locker_tags ( $args [ 'lock_text' ] );
2019-10-17 18:05:44 +03:00
UM () -> get_template ( 'login-to-view.php' , '' , $args , true );
2018-03-20 13:24:38 +02:00
}
} else {
2020-04-03 11:21:35 +03:00
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 ) ) );
}
2018-03-20 13:24:38 +02:00
}
$output = ob_get_clean ();
2022-05-24 18:29:39 +03:00
2019-12-23 20:00:39 +08:00
return htmlspecialchars_decode ( $output , ENT_NOQUOTES );
2018-03-20 13:24:38 +02:00
}
2018-10-22 21:53:43 +03:00
/**
* Logged-out only content
*
* @param array $args
* @param string $content
*
* @return string
2018-03-20 13:24:38 +02:00
*/
2019-10-17 18:05:44 +03:00
function um_loggedout ( $args = array (), $content = '' ) {
2018-03-20 13:24:38 +02:00
ob_start ();
// Hide for logged in users
2018-09-28 17:14:50 +03:00
if ( is_user_logged_in () ) {
2018-03-20 13:24:38 +02:00
echo '' ;
} else {
2020-04-03 11:21:35 +03:00
if ( version_compare ( get_bloginfo ( 'version' ), '5.4' , '<' ) ) {
echo do_shortcode ( wpautop ( $content ) );
} else {
echo apply_shortcodes ( wpautop ( $content ) );
}
2018-03-20 13:24:38 +02:00
}
2018-09-28 17:14:50 +03:00
$output = ob_get_clean ();
2018-03-20 13:24:38 +02:00
return $output ;
}
2023-12-06 18:25:13 +02:00
/**
* Display profile link.
*
* @since 2.8.0
*
* Example 1: [um_profile_link]
* Example 2: [um_profile_link title="Go to profile" user_id="29"]
*
* @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.
* }
* @return string|void Profile link HTML or profile link URL if the link text is empty.
*/
public function um_profile_link ( $attr ) {
$defaults_atts = array (
'class' => 'um-link um-profile-link' ,
'title' => '' ,
'user_id' => is_singular () ? get_post () -> post_author : ( is_author () ? get_the_author_meta ( 'ID' ) : 0 ),
);
$atts = shortcode_atts ( $defaults_atts , $attr , 'um_profile_link' );
if ( empty ( $atts [ 'user_id' ] ) ) {
return ;
}
$url = um_user_profile_url ( $atts [ 'user_id' ] );
return empty ( $atts [ 'title' ] ) ? $url : '<a class="' . esc_attr ( $atts [ 'class' ] ) . '" href="' . esc_url ( $url ) . '">' . esc_html ( $atts [ 'title' ] ) . '</a>' ;
}
2018-10-22 21:53:43 +03:00
/**
* @param array $args
*
* @return string
*/
function ultimatemember_login ( $args = array () ) {
global $wpdb ;
$args = ! empty ( $args ) ? $args : array ();
$default_login = $wpdb -> get_var (
2023-03-29 14:38:11 +03:00
" SELECT pm.post_id
FROM { $wpdb -> postmeta } pm
2018-10-22 21:53:43 +03:00
LEFT JOIN { $wpdb -> postmeta } pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
2023-03-29 14:38:11 +03:00
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'login' AND
2018-10-22 21:53:43 +03:00
pm2.meta_value = '1' "
);
$args [ 'form_id' ] = $default_login ;
$shortcode_attrs = '' ;
foreach ( $args as $key => $value ) {
$shortcode_attrs .= " { $key } = \" { $value } \" " ;
}
2020-04-03 11:21:35 +03:00
if ( version_compare ( get_bloginfo ( 'version' ), '5.4' , '<' ) ) {
return do_shortcode ( " [ultimatemember { $shortcode_attrs } /] " );
} else {
return apply_shortcodes ( " [ultimatemember { $shortcode_attrs } /] " );
}
2018-10-22 21:53:43 +03:00
}
/**
* @param array $args
*
* @return string
*/
function ultimatemember_register ( $args = array () ) {
global $wpdb ;
$args = ! empty ( $args ) ? $args : array ();
$default_register = $wpdb -> get_var (
2023-03-29 14:38:11 +03:00
" SELECT pm.post_id
FROM { $wpdb -> postmeta } pm
2018-10-22 21:53:43 +03:00
LEFT JOIN { $wpdb -> postmeta } pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
2023-03-29 14:38:11 +03:00
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'register' AND
2018-10-22 21:53:43 +03:00
pm2.meta_value = '1' "
);
$args [ 'form_id' ] = $default_register ;
$shortcode_attrs = '' ;
foreach ( $args as $key => $value ) {
$shortcode_attrs .= " { $key } = \" { $value } \" " ;
}
2020-04-03 11:21:35 +03:00
if ( version_compare ( get_bloginfo ( 'version' ), '5.4' , '<' ) ) {
return do_shortcode ( " [ultimatemember { $shortcode_attrs } /] " );
} else {
return apply_shortcodes ( " [ultimatemember { $shortcode_attrs } /] " );
}
2018-10-22 21:53:43 +03:00
}
/**
* @param array $args
*
* @return string
*/
function ultimatemember_profile ( $args = array () ) {
global $wpdb ;
$args = ! empty ( $args ) ? $args : array ();
$default_profile = $wpdb -> get_var (
2023-03-29 14:38:11 +03:00
" SELECT pm.post_id
FROM { $wpdb -> postmeta } pm
2018-10-22 21:53:43 +03:00
LEFT JOIN { $wpdb -> postmeta } pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
2023-03-29 14:38:11 +03:00
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'profile' AND
2018-10-22 21:53:43 +03:00
pm2.meta_value = '1' "
);
$args [ 'form_id' ] = $default_profile ;
$shortcode_attrs = '' ;
foreach ( $args as $key => $value ) {
$shortcode_attrs .= " { $key } = \" { $value } \" " ;
}
2020-04-03 11:21:35 +03:00
if ( version_compare ( get_bloginfo ( 'version' ), '5.4' , '<' ) ) {
return do_shortcode ( " [ultimatemember { $shortcode_attrs } /] " );
} else {
return apply_shortcodes ( " [ultimatemember { $shortcode_attrs } /] " );
}
2018-10-22 21:53:43 +03:00
}
2018-10-23 00:36:27 +03:00
/**
* @param array $args
*
* @return string
*/
function ultimatemember_directory ( $args = array () ) {
global $wpdb ;
$args = ! empty ( $args ) ? $args : array ();
$default_directory = $wpdb -> get_var (
2023-03-29 14:38:11 +03:00
" SELECT pm.post_id
FROM { $wpdb -> postmeta } pm
2018-10-23 00:36:27 +03:00
LEFT JOIN { $wpdb -> postmeta } pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
2023-03-29 14:38:11 +03:00
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'directory' AND
2018-10-23 00:36:27 +03:00
pm2.meta_value = '1' "
);
$args [ 'form_id' ] = $default_directory ;
$shortcode_attrs = '' ;
foreach ( $args as $key => $value ) {
$shortcode_attrs .= " { $key } = \" { $value } \" " ;
}
2020-04-03 11:21:35 +03:00
if ( version_compare ( get_bloginfo ( 'version' ), '5.4' , '<' ) ) {
return do_shortcode ( " [ultimatemember { $shortcode_attrs } /] " );
} else {
return apply_shortcodes ( " [ultimatemember { $shortcode_attrs } /] " );
}
2018-10-23 00:36:27 +03:00
}
2018-03-20 13:24:38 +02:00
/**
* Shortcode
*
* @param array $args
*
* @return string
*/
2023-06-26 18:00:25 +03:00
public function ultimatemember ( $args = array () ) {
2023-08-31 11:27:11 +03:00
// There is possible to use 'shortcode_atts_ultimatemember' filter for getting customized `$args`.
$args = shortcode_atts (
array (
'form_id' => '' ,
2023-09-02 00:53:51 +03:00
'is_block' => false ,
2023-08-31 11:27:11 +03:00
),
$args ,
'ultimatemember'
);
2023-09-02 00:53:51 +03:00
// Sanitize shortcode arguments.
$args [ 'form_id' ] = ! empty ( $args [ 'form_id' ] ) ? absint ( $args [ 'form_id' ] ) : '' ;
$args [ 'is_block' ] = ( bool ) $args [ 'is_block' ];
2023-07-13 16:03:28 +03:00
/**
2023-07-21 15:47:01 +03:00
* 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.
2023-07-13 16:03:28 +03:00
*
* @since 2.6.8
2023-07-21 15:47:01 +03:00
* @since 2.6.9 $disable argument set to `true` by default
*
2023-07-13 16:03:28 +03:00
* @hook um_ultimatemember_shortcode_disable_singleton
*
2023-07-21 15:47:01 +03:00
* @param {bool} $disable Disabled singleton. By default, it's `true`.
2023-07-13 16:03:28 +03:00
* @param {array} $args Shortcode arguments.
*
* @return {bool} Disabled singleton or not.
*
2023-07-21 15:47:01 +03:00
* @example <caption>Turn off ability to use ultimatemember shortcode twice.</caption>
* add_filter( 'um_ultimatemember_shortcode_disable_singleton', '__return_false' );
2023-07-13 16:03:28 +03:00
*/
2023-07-21 15:47:01 +03:00
$disable_singleton_shortcode = apply_filters ( 'um_ultimatemember_shortcode_disable_singleton' , true , $args );
2023-07-13 16:03:28 +03:00
if ( false === $disable_singleton_shortcode ) {
if ( isset ( $args [ 'form_id' ] ) ) {
$id = $args [ 'form_id' ];
if ( isset ( $this -> forms_exist [ $id ] ) && true === $this -> forms_exist [ $id ] ) {
return '' ;
}
$this -> forms_exist [ $id ] = true ;
2023-07-12 11:46:03 +03:00
}
}
2018-03-20 13:24:38 +02:00
return $this -> load ( $args );
}
/**
* Load a module with global function
*
* @param $args
*
* @return string
*/
2023-06-22 14:40:44 +03:00
public function load ( $args ) {
2018-03-20 13:24:38 +02:00
$defaults = array ();
2023-06-22 14:40:44 +03:00
$args = wp_parse_args ( $args , $defaults );
2018-03-20 13:24:38 +02:00
2023-06-26 18:00:25 +03:00
// When to not continue.
if ( ! array_key_exists ( 'form_id' , $args ) ) {
return '' ;
2018-03-20 13:24:38 +02:00
}
2023-08-28 15:10:42 +03:00
2023-06-26 18:00:25 +03:00
$this -> form_id = $args [ 'form_id' ];
2023-08-28 15:10:42 +03:00
if ( empty ( $this -> form_id ) ) {
return '' ;
}
2018-03-20 13:24:38 +02:00
2019-09-30 01:27:01 +03:00
$this -> form_status = get_post_status ( $this -> form_id );
2023-06-22 14:40:44 +03:00
if ( 'publish' !== $this -> form_status ) {
2023-06-26 18:00:25 +03:00
return '' ;
2018-03-20 13:24:38 +02:00
}
2023-11-03 17:31:18 +02:00
UM () -> fields () -> set_id = absint ( $this -> form_id );
2018-03-20 13:24:38 +02:00
// get data into one global array
2018-11-27 14:21:27 +02:00
$post_data = UM () -> query () -> post_data ( $this -> form_id );
2023-06-22 14:40:44 +03:00
$args = array_merge ( $args , $post_data );
2018-03-20 13:24:38 +02:00
2018-09-28 17:14:50 +03:00
ob_start ();
2018-03-20 13:24:38 +02:00
/**
2023-06-26 18:00:25 +03:00
* Filters arguments for loading Ultimate Member shortcodes.
2018-03-20 13:24:38 +02:00
*
2023-06-26 18:00:25 +03:00
* @since 1.3.x
2023-06-22 14:40:44 +03:00
* @hook um_pre_args_setup
*
2023-06-26 18:00:25 +03:00
* @param {array} $args Data for loading shortcode.
2023-06-22 14:40:44 +03:00
*
2023-06-26 18:00:25 +03:00
* @return {array} Data for loading shortcode.
2023-06-22 14:40:44 +03:00
*
* @example <caption>Change arguments on load shortcode.</caption>
2023-06-26 18:00:25 +03:00
* function my_pre_args_setup( $args ) {
2018-03-20 13:24:38 +02:00
* // your code here
2023-06-26 18:00:25 +03:00
* return $args;
2018-03-20 13:24:38 +02:00
* }
2023-06-26 18:00:25 +03:00
* add_filter( 'um_pre_args_setup', 'my_pre_args_setup' );
2018-03-20 13:24:38 +02:00
*/
2019-09-30 01:27:01 +03:00
$args = apply_filters ( 'um_pre_args_setup' , $args );
2018-03-20 13:24:38 +02:00
2018-09-28 17:14:50 +03:00
if ( ! isset ( $args [ 'template' ] ) ) {
2018-03-20 13:24:38 +02:00
$args [ 'template' ] = '' ;
}
2023-06-22 14:40:44 +03:00
if ( isset ( $post_data [ 'template' ] ) && $post_data [ 'template' ] !== $args [ 'template' ] ) {
2018-03-20 13:24:38 +02:00
$args [ 'template' ] = $post_data [ 'template' ];
}
2018-11-27 14:21:27 +02:00
if ( ! $this -> template_exists ( $args [ 'template' ] ) ) {
2018-03-20 13:24:38 +02:00
$args [ 'template' ] = $post_data [ 'mode' ];
}
2018-11-27 14:21:27 +02:00
if ( ! isset ( $post_data [ 'template' ] ) ) {
2018-03-20 13:24:38 +02:00
$post_data [ 'template' ] = $post_data [ 'mode' ];
}
2023-06-22 14:40:44 +03:00
if ( 'directory' === $args [ 'mode' ] ) {
2020-02-12 12:36:47 +02:00
wp_enqueue_script ( 'um_members' );
2023-11-17 17:25:47 +02:00
wp_enqueue_style ( 'um_members' );
2020-02-12 12:36:47 +02:00
}
2023-06-22 14:40:44 +03:00
if ( 'directory' !== $args [ 'mode' ] ) {
2018-03-20 13:24:38 +02:00
$args = array_merge ( $post_data , $args );
2018-11-27 14:21:27 +02:00
if ( empty ( $args [ 'use_custom_settings' ] ) ) {
2018-03-20 13:24:38 +02:00
$args = array_merge ( $args , $this -> get_css_args ( $args ) );
} else {
$args = array_merge ( $this -> get_css_args ( $args ), $args );
}
}
/**
2023-06-26 18:00:25 +03:00
* Filters change arguments on load shortcode.
2018-03-20 13:24:38 +02:00
*
2023-06-26 18:00:25 +03:00
* @since 1.3.x
2023-06-22 14:40:44 +03:00
* @hook um_shortcode_args_filter
*
2023-06-26 18:00:25 +03:00
* @param {array} $args Shortcode arguments.
2023-06-22 14:40:44 +03:00
*
2023-06-26 18:00:25 +03:00
* @return {array} Shortcode arguments.
2023-06-22 14:40:44 +03:00
*
* @example <caption>Change arguments on load shortcode.</caption>
2018-03-20 13:24:38 +02:00
* function my_shortcode_args( $args ) {
* // your code here
* return $args;
* }
2023-06-26 18:00:25 +03:00
* add_filter( 'um_shortcode_args_filter', 'my_shortcode_args' );
2018-03-20 13:24:38 +02:00
*/
$args = apply_filters ( 'um_shortcode_args_filter' , $args );
2023-06-22 14:40:44 +03:00
if ( ! array_key_exists ( 'mode' , $args ) || ! array_key_exists ( 'template' , $args ) ) {
2023-06-26 18:00:25 +03:00
ob_get_clean ();
return '' ;
2023-06-22 14:40:44 +03:00
}
$mode = $args [ 'mode' ];
2018-03-20 13:24:38 +02:00
2023-06-26 18:00:25 +03:00
// Not display on admin preview.
2023-06-22 14:40:44 +03:00
if ( empty ( $_POST [ 'act_id' ] ) || 'um_admin_preview_form' !== sanitize_key ( $_POST [ 'act_id' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
2023-06-26 18:00:25 +03:00
/**
* Filters the ability to show registration form for the logged-in users.
* Set it to true for displaying registration form for the logged-in users.
*
* @since 2.1.20
* @hook um_registration_for_loggedin_users
*
* @param {bool} $show Show registration form for the logged-in users. By default, it's false
* @param {array} $args Shortcode arguments.
*
* @return {bool} Show registration form for the logged-in users.
*
* @example <caption>Show registration form for the logged-in users for all UM registration forms on your website.</caption>
* add_filter( 'um_registration_for_loggedin_users', '__return_true' );
*/
2021-04-27 00:21:32 +03:00
$enable_loggedin_registration = apply_filters ( 'um_registration_for_loggedin_users' , false , $args );
2023-06-26 18:00:25 +03:00
if ( ! $enable_loggedin_registration && 'register' === $mode && is_user_logged_in () ) {
2018-09-28 17:14:50 +03:00
ob_get_clean ();
2023-06-26 18:00:25 +03:00
return __ ( 'You are already registered.' , 'ultimate-member' );
2018-04-18 17:40:54 +03:00
}
2018-03-20 13:24:38 +02:00
}
2023-09-02 00:53:51 +03:00
if ( 'profile' === $mode && ! empty ( $args [ 'is_block' ] ) && ! is_user_logged_in () ) {
2023-06-26 18:00:25 +03:00
ob_get_clean ();
return '' ;
2023-05-09 13:30:39 +03:00
}
2023-06-26 18:00:25 +03:00
// For profiles only.
2023-06-22 14:40:44 +03:00
if ( 'profile' === $mode && um_profile_id () ) {
2023-06-26 18:00:25 +03:00
// Set requested user if it's not setup from permalinks (for not profile page in edit mode).
2019-05-16 00:21:43 +03:00
if ( ! um_get_requested_user () ) {
um_set_requested_user ( um_profile_id () );
}
2023-06-26 18:00:25 +03:00
if ( ! empty ( $args [ 'use_custom_settings' ] ) && ! empty ( $args [ 'role' ] ) ) {
// Option "Apply custom settings to this form". Option "Make this profile form role-specific".
// Show the first Profile Form with role selected, don't show profile forms below the page with other role-specific setting.
if ( empty ( $this -> profile_role ) ) {
$current_user_roles = UM () -> roles () -> get_all_user_roles ( um_profile_id () );
2020-09-11 00:14:20 +03:00
2023-06-26 18:00:25 +03:00
if ( empty ( $current_user_roles ) ) {
ob_get_clean ();
return '' ;
}
if ( is_array ( $args [ 'role' ] ) ) {
if ( ! count ( array_intersect ( $args [ 'role' ], $current_user_roles ) ) ) {
2020-09-11 00:14:20 +03:00
ob_get_clean ();
return '' ;
2020-05-25 17:37:20 +03:00
}
2023-06-26 18:00:25 +03:00
} elseif ( ! in_array ( $args [ 'role' ], $current_user_roles , true ) ) {
2020-04-24 14:54:04 +03:00
ob_get_clean ();
return '' ;
2018-06-03 20:02:55 +03:00
}
2023-06-26 18:00:25 +03:00
$this -> profile_role = $args [ 'role' ];
} elseif ( $this -> profile_role !== $args [ 'role' ] ) {
ob_get_clean ();
return '' ;
2018-04-13 15:08:00 +03:00
}
2018-03-20 13:24:38 +02:00
}
}
2023-08-24 17:37:41 +03:00
$content = apply_filters ( 'um_force_shortcode_render' , false , $args );
if ( false !== $content ) {
ob_get_clean ();
return $content ;
}
2018-03-20 13:24:38 +02:00
/**
2023-06-26 16:54:43 +03:00
* Fires before loading form shortcode.
2018-03-20 13:24:38 +02:00
*
2023-06-26 16:54:43 +03:00
* Note: $mode can be 'profile', 'login', 'register', 'account'.
*
* @since 1.3.x
2023-06-22 14:40:44 +03:00
* @hook um_pre_{$mode}_shortcode
*
2023-06-26 16:54:43 +03:00
* @param {array} $args Form shortcode arguments.
2023-06-22 14:40:44 +03:00
*
2023-06-26 16:54:43 +03:00
* @example <caption>Make any custom action before loading a registration form shortcode.</caption>
* function my_pre_register_shortcode( $args ) {
2018-03-20 13:24:38 +02:00
* // your code here
* }
2023-06-26 16:54:43 +03:00
* add_action( 'um_pre_register_shortcode', 'my_pre_register_shortcode' );
* @example <caption>Make any custom action before loading a login form shortcode.</caption>
* function my_pre_login_shortcode( $args ) {
* // your code here
* }
* add_action( 'um_pre_login_shortcode', 'my_pre_login_shortcode' );
* @example <caption>Make any custom action before loading a password reset form shortcode.</caption>
* function my_pre_password_shortcode( $args ) {
* // your code here
* }
* add_action( 'um_pre_password_shortcode', 'my_pre_password_shortcode' );
* @example <caption>Make any custom action before loading a profile form shortcode.</caption>
* function my_pre_profile_shortcode( $args ) {
* // your code here
* }
* add_action( 'um_pre_profile_shortcode', 'my_pre_profile_shortcode' );
* @example <caption>Make any custom action before loading an account form shortcode.</caption>
* function my_pre_account_shortcode( $args ) {
* // your code here
* }
* add_action( 'um_pre_account_shortcode', 'my_pre_account_shortcode' );
2018-03-20 13:24:38 +02:00
*/
do_action ( " um_pre_ { $mode } _shortcode " , $args );
/**
2023-06-26 16:54:43 +03:00
* Fires before loading form shortcode.
2018-03-20 13:24:38 +02:00
*
2023-06-26 16:54:43 +03:00
* @since 1.3.x
2023-06-22 14:40:44 +03:00
* @hook um_before_form_is_loaded
*
2023-06-26 16:54:43 +03:00
* @param {array} $args Form shortcode arguments.
2023-06-22 14:40:44 +03:00
*
2023-06-26 16:54:43 +03:00
* @example <caption>Make any custom action before loading UM form shortcode.</caption>
2018-03-20 13:24:38 +02:00
* function my_pre_shortcode( $args ) {
* // your code here
* }
2023-06-22 14:40:44 +03:00
* add_action( 'um_before_form_is_loaded', 'my_pre_shortcode', 10, 1 );
2018-03-20 13:24:38 +02:00
*/
2023-06-22 14:40:44 +03:00
do_action ( 'um_before_form_is_loaded' , $args );
2018-03-20 13:24:38 +02:00
/**
2023-06-26 16:54:43 +03:00
* Fires before loading a form shortcode.
2018-03-20 13:24:38 +02:00
*
2023-06-26 16:54:43 +03:00
* @since 1.3.x
* @todo Deprecate since 2.7.0. Use `um_pre_{$mode}_shortcode` or `um_before_form_is_loaded` instead.
2023-06-22 14:40:44 +03:00
* @hook um_before_{$mode}_form_is_loaded
*
2023-06-26 16:54:43 +03:00
* @param {array} $args Form shortcode arguments.
2018-03-20 13:24:38 +02:00
*/
do_action ( " um_before_ { $mode } _form_is_loaded " , $args );
2023-06-22 14:40:44 +03:00
$this -> template_load ( $args [ 'template' ], $args );
2018-03-20 13:24:38 +02:00
$this -> dynamic_css ( $args );
2023-06-26 16:54:43 +03:00
if ( 'logout' === $mode || um_get_requested_user () ) {
2018-03-20 13:24:38 +02:00
um_reset_user ();
}
/**
2023-06-22 14:40:44 +03:00
* Fires after load shortcode content.
2018-03-20 13:24:38 +02:00
*
2023-06-22 14:40:44 +03:00
* @since 2.0
* @hook um_after_everything_output
*
2023-06-26 18:00:25 +03:00
* @param {array} $args Form shortcode arguments.
2023-06-22 14:40:44 +03:00
*
* @example <caption>Make any custom action after load shortcode content.</caption>
* function my_pre_shortcode() {
2018-03-20 13:24:38 +02:00
* // your code here
* }
2023-06-22 14:40:44 +03:00
* add_action( 'um_after_everything_output', 'my_pre_shortcode', 10 );
2018-03-20 13:24:38 +02:00
*/
do_action ( 'um_after_everything_output' );
2017-10-19 16:28:30 +03:00
2023-06-26 16:54:43 +03:00
return ob_get_clean ();
2018-03-20 13:24:38 +02:00
}
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
/**
* Get dynamic CSS args
*
* @param $args
* @return array
*/
2023-06-26 20:46:23 +03:00
public function get_css_args ( $args ) {
2018-03-20 13:24:38 +02:00
$arr = um_styling_defaults ( $args [ 'mode' ] );
2023-06-26 20:46:23 +03:00
$arr = array_merge (
$arr ,
array (
'form_id' => $args [ 'form_id' ],
'mode' => $args [ 'mode' ],
)
);
2018-03-20 13:24:38 +02:00
return $arr ;
}
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
/**
2023-06-26 20:46:23 +03:00
* Load dynamic CSS.
2018-03-20 13:24:38 +02:00
*
* @param array $args
*
* @return string
*/
2023-06-22 14:49:40 +03:00
public function dynamic_css ( $args = array () ) {
2018-03-20 13:24:38 +02:00
/**
2023-06-26 20:46:23 +03:00
* Filters for disable global dynamic CSS. It's false by default, set it to true to disable.
2018-03-20 13:24:38 +02:00
*
2023-06-22 14:49:40 +03:00
* @since 2.0
* @hook um_disable_dynamic_global_css
*
2023-06-26 20:46:23 +03:00
* @param {bool} $disable Disable global CSS.
2023-06-22 14:49:40 +03:00
*
2023-06-26 20:46:23 +03:00
* @return {bool} Disable global CSS.
2023-06-22 14:49:40 +03:00
*
2023-06-26 20:46:23 +03:00
* @example <caption>Turn off enqueue of global dynamic CSS.</caption>
* add_filter( 'um_disable_dynamic_global_css', '__return_true' );
2018-03-20 13:24:38 +02:00
*/
$disable_css = apply_filters ( 'um_disable_dynamic_global_css' , false );
2023-06-22 14:49:40 +03:00
if ( $disable_css ) {
2018-03-20 13:24:38 +02:00
return '' ;
2023-06-22 14:49:40 +03:00
}
2017-07-26 14:57:52 +03:00
2023-06-26 20:46:23 +03:00
if ( empty ( $args [ 'form_id' ] ) ) {
return '' ;
}
2017-07-26 14:57:52 +03:00
2023-06-26 20:46:23 +03:00
include_once UM_PATH . 'assets/dynamic_css/dynamic-global.php' ;
if ( array_key_exists ( 'mode' , $args ) && in_array ( $args [ 'mode' ], array ( 'profile' , 'directory' ), true ) ) {
$file = UM_PATH . 'assets/dynamic_css/dynamic-' . $args [ 'mode' ] . '.php' ;
2017-08-11 14:21:42 +03:00
2023-06-22 14:49:40 +03:00
if ( file_exists ( $file ) ) {
2018-03-20 13:24:38 +02:00
include_once $file ;
2023-06-22 14:49:40 +03:00
}
2018-03-20 13:24:38 +02:00
}
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
return '' ;
}
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
/**
* Loads a template file
*
* @param $template
* @param array $args
*/
2023-06-26 20:46:23 +03:00
public function template_load ( $template , $args = array () ) {
2018-03-20 13:24:38 +02:00
if ( is_array ( $args ) ) {
$this -> set_args = $args ;
}
$this -> load_template ( $template );
}
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
/**
* Checks if a template file exists
*
* @param $template
*
* @return bool
*/
function template_exists ( $template ) {
2023-09-13 22:56:32 +03:00
$file = UM_PATH . 'templates/' . $template . '.php' ;
2018-03-20 13:24:38 +02:00
$theme_file = get_stylesheet_directory () . '/ultimate-member/templates/' . $template . '.php' ;
if ( file_exists ( $theme_file ) || file_exists ( $file )) {
return true ;
}
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
return false ;
}
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
/**
* Get File Name without path and extension
*
* @param $file
*
* @return mixed|string
*/
2020-09-22 14:30:25 +03:00
function get_template_name ( $file ) {
$file = basename ( $file );
$file = preg_replace ( '/\\.[^.\\s]{3,4}$/' , '' , $file );
2018-03-20 13:24:38 +02:00
return $file ;
}
/**
* Get Templates
*
* @param null $excluded
*
* @return mixed
*/
2020-09-22 14:30:25 +03:00
function get_templates ( $excluded = null ) {
2018-03-20 13:24:38 +02:00
2020-09-22 14:30:25 +03:00
if ( $excluded ) {
$array [ $excluded ] = __ ( 'Default Template' , 'ultimate-member' );
2018-03-20 13:24:38 +02:00
}
2023-09-13 22:56:32 +03:00
$paths [] = glob ( UM_PATH . 'templates/' . '*.php' );
2017-07-26 14:57:52 +03:00
2020-09-22 14:30:25 +03:00
if ( file_exists ( get_stylesheet_directory () . '/ultimate-member/templates/' ) ) {
$paths [] = glob ( get_stylesheet_directory () . '/ultimate-member/templates/' . '*.php' );
2018-03-20 13:24:38 +02:00
}
2017-07-26 14:57:52 +03:00
2020-09-22 14:30:25 +03:00
if ( isset ( $paths ) && ! empty ( $paths ) ) {
2017-07-26 14:57:52 +03:00
2020-09-22 14:30:25 +03:00
foreach ( $paths as $k => $files ) {
2017-07-26 14:57:52 +03:00
2020-09-22 14:30:25 +03:00
if ( isset ( $files ) && ! empty ( $files ) ) {
2017-07-26 14:57:52 +03:00
2020-09-22 14:30:25 +03:00
foreach ( $files as $file ) {
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
$clean_filename = $this -> get_template_name ( $file );
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
if ( 0 === strpos ( $clean_filename , $excluded ) ) {
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
$source = file_get_contents ( $file );
2020-09-22 14:30:25 +03:00
$tokens = @ \token_get_all ( $source );
2018-03-20 13:24:38 +02:00
$comment = array (
T_COMMENT , // All comments since PHP5
T_DOC_COMMENT , // PHPDoc comments
);
foreach ( $tokens as $token ) {
if ( in_array ( $token [ 0 ], $comment ) && strstr ( $token [ 1 ], '/* Template:' ) && $clean_filename != $excluded ) {
$txt = $token [ 1 ];
2020-09-22 14:30:25 +03:00
$txt = str_replace ( '/* Template: ' , '' , $txt );
$txt = str_replace ( ' */' , '' , $txt );
2018-03-20 13:24:38 +02:00
$array [ $clean_filename ] = $txt ;
}
}
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
}
}
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
}
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
}
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
}
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
return $array ;
}
2017-07-26 14:57:52 +03:00
2018-02-05 12:30:54 +02:00
/**
2018-03-20 13:24:38 +02:00
* Get Shortcode for given form ID
*
* @param $post_id
*
* @return string
*/
2018-02-05 12:30:54 +02:00
function get_shortcode ( $post_id ) {
2018-10-22 21:53:43 +03:00
$shortcode = '[ultimatemember form_id="' . $post_id . '"]' ;
return $shortcode ;
}
/**
* Get Shortcode for given form ID
*
* @param $post_id
*
* @return string
*/
function get_default_shortcode ( $post_id ) {
$mode = UM () -> query () -> get_attr ( 'mode' , $post_id );
switch ( $mode ) {
case 'login' :
$shortcode = '[ultimatemember_login]' ;
break ;
case 'profile' :
$shortcode = '[ultimatemember_profile]' ;
break ;
case 'register' :
$shortcode = '[ultimatemember_register]' ;
break ;
2018-10-23 00:36:27 +03:00
case 'directory' :
$shortcode = '[ultimatemember_directory]' ;
break ;
2018-10-22 21:53:43 +03:00
}
2018-02-05 12:30:54 +02:00
return $shortcode ;
}
2017-07-26 14:57:52 +03:00
2018-02-05 12:30:54 +02:00
/**
2018-03-20 13:24:38 +02:00
* Convert access lock tags
*
* @param $str
*
* @return mixed|string
*/
2018-02-05 12:30:54 +02:00
function convert_locker_tags ( $str ) {
2019-05-06 17:22:57 +03:00
add_filter ( 'um_template_tags_patterns_hook' , array ( & $this , 'add_placeholder' ), 10 , 1 );
add_filter ( 'um_template_tags_replaces_hook' , array ( & $this , 'add_replace_placeholder' ), 10 , 1 );
2018-02-05 12:30:54 +02:00
return um_convert_tags ( $str , array (), false );
}
2017-07-26 14:57:52 +03:00
2018-02-05 12:30:54 +02:00
/**
2018-03-20 13:24:38 +02:00
* Convert user tags in a string
*
2023-09-05 02:04:03 +03:00
* @param string $str
2018-03-20 13:24:38 +02:00
*
2023-09-05 02:04:03 +03:00
* @return string
2018-03-20 13:24:38 +02:00
*/
2023-09-05 02:04:03 +03:00
public function convert_user_tags ( $str ) {
2018-02-05 12:30:54 +02:00
$pattern_array = array (
'{first_name}' ,
'{last_name}' ,
'{display_name}' ,
'{user_avatar_small}' ,
'{username}' ,
2019-05-07 10:46:46 +03:00
'{nickname}' ,
2023-09-05 02:04:03 +03:00
'{user_email}' ,
2018-02-05 12:30:54 +02:00
);
2018-03-02 09:55:49 +02:00
/**
2023-09-05 02:04:03 +03:00
* Filters the user placeholders patterns.
2018-03-02 09:55:49 +02:00
*
2023-09-05 02:04:03 +03:00
* @since 1.3.x
* @hook um_allowed_user_tags_patterns
*
* @param {array} $patterns User Placeholders.
*
* @return {array} User Placeholders.
*
* @example <caption>Add the `{user_description}` placeholder.</caption>
2018-03-02 09:55:49 +02:00
* function my_allowed_user_tags( $patterns ) {
2023-09-05 02:04:03 +03:00
* $patterns[] = '{user_description}';
2018-03-02 09:55:49 +02:00
* return $patterns;
* }
2023-09-05 02:04:03 +03:00
* add_filter( 'um_allowed_user_tags_patterns', 'my_allowed_user_tags' );
2018-03-02 09:55:49 +02:00
*/
2018-02-05 12:30:54 +02:00
$pattern_array = apply_filters ( 'um_allowed_user_tags_patterns' , $pattern_array );
foreach ( $pattern_array as $pattern ) {
if ( preg_match ( $pattern , $str ) ) {
2017-07-26 14:57:52 +03:00
2023-09-05 02:04:03 +03:00
$value = '' ;
$usermeta = str_replace ( array ( '{' , '}' ), '' , $pattern );
2018-02-15 11:08:14 +02:00
if ( is_user_logged_in () ) {
2023-09-05 02:04:03 +03:00
if ( 'user_avatar_small' === $usermeta ) {
2018-02-15 11:08:14 +02:00
$value = get_avatar ( um_user ( 'ID' ), 40 );
} elseif ( um_user ( $usermeta ) ) {
$value = um_user ( $usermeta );
}
2017-07-26 14:57:52 +03:00
2023-09-05 02:04:03 +03:00
if ( 'username' === $usermeta ) {
2018-02-15 11:08:14 +02:00
$value = um_user ( 'user_login' );
}
2017-07-26 14:57:52 +03:00
2023-09-05 02:04:03 +03:00
if ( 'nickname' === $usermeta ) {
2019-05-07 10:46:46 +03:00
$value = um_profile ( 'nickname' );
}
2023-09-05 02:04:03 +03:00
if ( 'user_email' === $usermeta ) {
$value = um_user ( 'user_email' );
}
2018-03-02 09:55:49 +02:00
/**
2023-09-05 02:04:03 +03:00
* Filters the user placeholders value of pattern for logged-in user.
2018-03-02 09:55:49 +02:00
*
2023-09-05 02:04:03 +03:00
* @since 1.3.x
* @hook um_profile_tag_hook__{$usermeta}
*
* @param {string} $value User meta field value.
* @param {int} $id User ID.
*
* @return {string} User meta field value.
*
* @example <caption>Add the replacement value for `{user_description}` placeholder.</caption>
* function my_user_description( $value, $user_id ) {
* $value = get_user_meta( $user_id, 'user_description', true );
2018-03-02 09:55:49 +02:00
* return $value;
* }
2023-09-05 02:04:03 +03:00
* add_filter( 'um_profile_tag_hook__user_description', 'my_user_description', 10, 2 );
2018-03-02 09:55:49 +02:00
*/
2018-02-15 11:08:14 +02:00
$value = apply_filters ( " um_profile_tag_hook__ { $usermeta } " , $value , um_user ( 'ID' ) );
2023-09-05 02:04:03 +03:00
} else {
/**
* Filters the user placeholders value of pattern for not logged-in user.
*
* @since 2.6.11
* @hook um_profile_nopriv_tag_hook__{$usermeta}
*
* @param {string} $value User meta field value.
*
* @return {string} User meta field value.
*
* @example <caption>Add the replacement value for `{user_description}` placeholder for not logged-in user.</caption>
* function my_nopriv_user_description( $value ) {
* $value = ! empty( $_GET['user_description'] ) ? sanitize_text_field( $_GET['user_description'] ) : '';
* return $value;
* }
* add_filter( 'um_profile_nopriv_tag_hook__user_description', 'my_nopriv_user_description' );
*/
$value = apply_filters ( " um_profile_nopriv_tag_hook__ { $usermeta } " , $value );
2018-02-05 12:30:54 +02:00
}
2018-02-15 11:08:14 +02:00
$str = preg_replace ( '/' . $pattern . '/' , $value , $str );
2018-02-05 12:30:54 +02:00
}
}
return $str ;
}
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
/**
* Shortcode: Show custom content to specific role
*
* Show content to specific roles
* [um_show_content roles='member'] <!-- insert content here --> [/um_show_content]
* You can add multiple target roles, just use ',' e.g. [um_show_content roles='member,candidates,pets']
*
* Hide content from specific roles
* [um_show_content not='contributors'] <!-- insert content here --> [/um_show_content]
* You can add multiple target roles, just use ',' e.g. [um_show_content roles='member,candidates,pets']
*
* @param array $atts
* @param string $content
* @return string
*/
function um_shortcode_show_content_for_role ( $atts = array () , $content = '' ) {
global $user_ID ;
if ( ! is_user_logged_in () ) {
return ;
}
$a = shortcode_atts ( array (
'roles' => '' ,
'not' => '' ,
'is_profile' => false ,
), $atts );
if ( $a [ 'is_profile' ] ) {
um_fetch_user ( um_profile_id () );
} else {
um_fetch_user ( $user_ID );
}
$current_user_roles = um_user ( 'roles' );
if ( ! empty ( $a [ 'not' ] ) && ! empty ( $a [ 'roles' ] ) ) {
2020-04-03 11:21:35 +03:00
if ( version_compare ( get_bloginfo ( 'version' ), '5.4' , '<' ) ) {
return do_shortcode ( $this -> convert_locker_tags ( $content ) );
} else {
return apply_shortcodes ( $this -> convert_locker_tags ( $content ) );
}
2018-03-20 13:24:38 +02:00
}
if ( ! empty ( $a [ 'not' ] ) ) {
$not_in_roles = explode ( " , " , $a [ 'not' ] );
if ( is_array ( $not_in_roles ) && ( empty ( $current_user_roles ) || count ( array_intersect ( $current_user_roles , $not_in_roles ) ) <= 0 ) ) {
2020-04-03 11:21:35 +03:00
if ( version_compare ( get_bloginfo ( 'version' ), '5.4' , '<' ) ) {
return do_shortcode ( $this -> convert_locker_tags ( $content ) );
} else {
return apply_shortcodes ( $this -> convert_locker_tags ( $content ) );
}
2018-03-20 13:24:38 +02:00
}
} else {
$roles = explode ( " , " , $a [ 'roles' ] );
if ( ! empty ( $current_user_roles ) && is_array ( $roles ) && count ( array_intersect ( $current_user_roles , $roles ) ) > 0 ) {
2020-04-03 11:21:35 +03:00
if ( version_compare ( get_bloginfo ( 'version' ), '5.4' , '<' ) ) {
return do_shortcode ( $this -> convert_locker_tags ( $content ) );
} else {
return apply_shortcodes ( $this -> convert_locker_tags ( $content ) );
}
2018-03-20 13:24:38 +02:00
}
}
return '' ;
}
/**
* @param array $args
* @param string $content
*
* @return string
*/
2023-06-12 15:22:35 +03:00
public function ultimatemember_searchform ( $args = array (), $content = '' ) {
2019-10-18 13:01:40 +03:00
if ( ! UM () -> options () -> get ( 'members_page' ) ) {
return '' ;
}
$member_directory_ids = array ();
$page_id = UM () -> config () -> permalinks [ 'members' ];
if ( ! empty ( $page_id ) ) {
2023-06-12 15:22:35 +03:00
$member_directory_ids = UM () -> member_directory () -> get_member_directory_id ( $page_id );
2019-10-18 13:01:40 +03:00
}
if ( empty ( $member_directory_ids ) ) {
return '' ;
}
//current user priority role
$priority_user_role = false ;
if ( is_user_logged_in () ) {
$priority_user_role = UM () -> roles () -> get_priority_user_role ( get_current_user_id () );
}
$query = array ();
foreach ( $member_directory_ids as $directory_id ) {
$directory_data = UM () -> query () -> post_data ( $directory_id );
2019-11-12 15:25:35 +02:00
if ( isset ( $directory_data [ 'roles_can_search' ] ) ) {
$directory_data [ 'roles_can_search' ] = maybe_unserialize ( $directory_data [ 'roles_can_search' ] );
2019-11-12 13:47:57 +02:00
}
2019-10-18 13:01:40 +03:00
$show_search = empty ( $directory_data [ 'roles_can_search' ] ) || ( ! empty ( $priority_user_role ) && in_array ( $priority_user_role , $directory_data [ 'roles_can_search' ] ) );
if ( empty ( $directory_data [ 'search' ] ) || ! $show_search ) {
continue ;
}
$hash = UM () -> member_directory () -> get_directory_hash ( $directory_id );
2021-06-29 02:51:54 +03:00
$query [ 'search_' . $hash ] = ! empty ( $_GET [ 'search_' . $hash ] ) ? sanitize_text_field ( $_GET [ 'search_' . $hash ] ) : '' ;
2019-10-18 13:01:40 +03:00
}
if ( empty ( $query ) ) {
return '' ;
}
2018-03-20 13:24:38 +02:00
2019-10-18 13:01:40 +03:00
$search_value = array_values ( $query );
2018-03-20 13:24:38 +02:00
2019-10-18 13:01:40 +03:00
$template = UM () -> get_template ( 'searchform.php' , '' , array ( 'query' => $query , 'search_value' => $search_value [ 0 ], 'members_page' => um_get_core_page ( 'members' ) ) );
2018-03-20 13:24:38 +02:00
return $template ;
}
2019-05-06 17:22:57 +03:00
/**
* UM Placeholders for login referrer
*
* @param $placeholders
*
* @return array
*/
function add_placeholder ( $placeholders ) {
$placeholders [] = '{login_referrer}' ;
return $placeholders ;
}
/**
* UM Replace Placeholders for login referrer
*
* @param $replace_placeholders
*
* @return array
*/
function add_replace_placeholder ( $replace_placeholders ) {
$replace_placeholders [] = um_dynamic_login_page_redirect ();
return $replace_placeholders ;
}
2018-03-20 13:24:38 +02:00
}
2021-06-15 12:18:56 +03:00
}