2014-12-15 22:38:07 +02:00
< ? php
class UM_Shortcodes {
function __construct () {
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
$this -> message_mode = false ;
2015-12-15 15:45:03 -08:00
2015-02-04 20:31:39 +02:00
$this -> loop = '' ;
2014-12-15 22:38:07 +02:00
add_shortcode ( 'ultimatemember' , array ( & $this , 'ultimatemember' ), 1 );
2016-01-10 07:23:29 -08:00
2016-02-11 12:05:59 +08:00
add_shortcode ( 'um_loggedin' , array ( & $this , 'um_loggedin' ));
add_shortcode ( 'um_loggedout' , array ( & $this , 'um_loggedout' ));
2016-02-26 18:35:09 +08:00
add_shortcode ( 'um_show_content' , array ( & $this , 'um_shortcode_show_content_for_role' ) );
2016-03-06 09:36:56 -08:00
2016-02-11 12:05:59 +08:00
add_filter ( 'body_class' , array ( & $this , 'body_class' ), 0 );
$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' ;
2015-03-14 23:39:33 +02:00
}
2015-12-15 15:45:03 -08:00
2015-05-05 18:06:39 +03:00
/***
2016-02-11 12:05:59 +08:00
*** @emoji support
*/
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 );
2015-05-05 18:06:39 +03:00
}
return $content ;
}
2015-12-15 15:45:03 -08:00
2015-03-14 23:39:33 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @extend body classes
*/
function body_class ( $classes ) {
2015-03-14 23:39:33 +02:00
global $ultimatemember ;
2015-11-05 19:51:31 +08:00
2015-03-14 23:39:33 +02:00
$array = $ultimatemember -> permalinks -> core ;
2016-02-11 12:05:59 +08:00
if ( ! $array ) {
return $classes ;
}
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
foreach ( $array as $slug => $info ) {
if ( um_is_core_page ( $slug )) {
2015-12-15 15:45:03 -08:00
2015-03-14 23:39:33 +02:00
$classes [] = 'um-page-' . $slug ;
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ( is_user_logged_in ()) {
2015-11-05 19:51:31 +08:00
$classes [] = 'um-page-loggedin' ;
} else {
$classes [] = 'um-page-loggedout' ;
}
2015-12-15 15:45:03 -08:00
2015-11-05 19:51:31 +08:00
}
2015-03-14 23:39:33 +02:00
}
2015-12-15 15:45:03 -08:00
2015-03-14 23:39:33 +02:00
return $classes ;
2014-12-15 22:38:07 +02:00
}
2015-12-15 15:45:03 -08:00
2015-05-05 18:06:39 +03:00
/***
2016-02-11 12:05:59 +08:00
*** @Retrieve core login form
*/
2015-05-05 18:06:39 +03:00
function core_login_form () {
2016-02-11 12:05:59 +08:00
$forms = get_posts ( array ( 'post_type' => 'um_form' , 'posts_per_page' => 1 , 'meta_key' => '_um_core' , 'meta_value' => 'login' ));
2016-02-23 16:21:52 +08:00
$form_id = isset ( $forms [ 0 ] -> ID ) ? $forms [ 0 ] -> ID : 0 ;
return $form_id ;
2015-05-05 18:06:39 +03:00
}
2015-12-15 15:45:03 -08:00
2015-02-04 20:31:39 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @load a compatible template
*/
function load_template ( $tpl ) {
2015-02-04 20:31:39 +02:00
global $ultimatemember ;
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
$loop = ( $this -> loop ) ? $this -> loop : '' ;
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ( isset ( $this -> set_args ) && is_array ( $this -> set_args )) {
2015-02-04 20:31:39 +02:00
$args = $this -> set_args ;
2016-02-11 12:05:59 +08:00
extract ( $args );
2015-02-04 20:31:39 +02:00
}
$file = um_path . 'templates/' . $tpl . '.php' ;
$theme_file = get_stylesheet_directory () . '/ultimate-member/templates/' . $tpl . '.php' ;
2016-02-11 12:05:59 +08:00
if ( file_exists ( $theme_file )) {
2015-02-04 20:31:39 +02:00
$file = $theme_file ;
2016-02-11 12:05:59 +08:00
}
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ( file_exists ( $file )) {
2015-02-04 20:31:39 +02:00
include $file ;
2016-02-11 12:05:59 +08:00
}
2015-02-04 20:31:39 +02:00
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @Add class based on shortcode
*/
function get_class ( $mode , $args = array ()) {
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
global $ultimatemember ;
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
$classes = 'um-' . $mode ;
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ( is_admin ()) {
2014-12-15 22:38:07 +02:00
$classes .= ' um-in-admin' ;
}
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ( isset ( $ultimatemember -> form -> errors ) && $ultimatemember -> form -> errors ) {
2015-11-05 19:51:31 +08:00
$classes .= ' um-err' ;
}
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ( $ultimatemember -> fields -> editing == true ) {
2014-12-15 22:38:07 +02:00
$classes .= ' um-editing' ;
}
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ( $ultimatemember -> fields -> viewing == true ) {
2014-12-15 22:38:07 +02:00
$classes .= ' um-viewing' ;
}
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ( isset ( $args [ 'template' ]) && $args [ 'template' ] != $args [ 'mode' ]) {
2015-03-12 18:22:29 +02:00
$classes .= ' um-' . $args [ 'template' ];
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
$classes = apply_filters ( 'um_form_official_classes__hook' , $classes );
return $classes ;
}
2015-12-15 15:45:03 -08:00
2016-01-02 01:36:11 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @Logged-in only content
*/
function um_loggedin ( $args = array (), $content = " " ) {
2016-01-02 01:36:11 +02:00
global $ultimatemember ;
ob_start ();
$defaults = array (
2016-02-11 12:05:59 +08:00
'lock_text' => __ ( 'This content has been restricted to logged in users only. Please <a href="{login_referrer}">login</a> to view this content.' , 'ultimatemember' ),
'show_lock' => 'yes' ,
2016-01-02 01:36:11 +02:00
);
2016-01-10 07:23:29 -08:00
2016-02-11 12:05:59 +08:00
$args = wp_parse_args ( $args , $defaults );
2016-01-10 07:23:29 -08:00
2016-02-11 12:05:59 +08:00
$args [ 'lock_text' ] = $this -> convert_locker_tags ( $args [ 'lock_text' ]);
2016-01-02 01:36:11 +02:00
2016-02-11 12:05:59 +08:00
if ( ! is_user_logged_in ()) {
if ( $args [ 'show_lock' ] == 'no' ) {
2016-01-02 01:36:11 +02:00
echo '' ;
} else {
$ultimatemember -> shortcodes -> set_args = $args ;
2016-02-11 12:05:59 +08:00
$ultimatemember -> shortcodes -> load_template ( 'login-to-view' );
2016-01-02 01:36:11 +02:00
}
} else {
2016-02-11 12:05:59 +08:00
echo do_shortcode ( $this -> convert_locker_tags ( wpautop ( $content )));
2016-01-02 01:36:11 +02:00
}
2016-01-10 07:23:29 -08:00
2016-01-02 01:36:11 +02:00
$output = ob_get_contents ();
ob_end_clean ();
return $output ;
}
2016-01-10 07:23:29 -08:00
2016-01-02 18:25:44 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @Logged-out only content
*/
function um_loggedout ( $args = array (), $content = " " ) {
2016-01-02 18:25:44 +02:00
global $ultimatemember ;
ob_start ();
// Hide for logged in users
2016-02-11 12:05:59 +08:00
if ( is_user_logged_in ()) {
2016-01-02 18:25:44 +02:00
echo '' ;
} else {
2016-02-11 12:05:59 +08:00
echo do_shortcode ( wpautop ( $content ));
2016-01-02 18:25:44 +02:00
}
2016-01-10 07:23:29 -08:00
2016-01-02 18:25:44 +02:00
$output = ob_get_contents ();
ob_end_clean ();
return $output ;
}
2016-01-10 07:23:29 -08:00
2014-12-15 22:38:07 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @Shortcode
*/
function ultimatemember ( $args = array ()) {
return $this -> load ( $args );
2014-12-15 22:38:07 +02:00
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @Load a module with global function
*/
function load ( $args ) {
2014-12-15 22:38:07 +02:00
global $ultimatemember ;
ob_start ();
$defaults = array ();
2016-02-11 12:05:59 +08:00
$args = wp_parse_args ( $args , $defaults );
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
// when to not continue
$this -> form_id = ( isset ( $args [ 'form_id' ])) ? $args [ 'form_id' ] : null ;
2016-02-11 12:05:59 +08:00
if ( ! $this -> form_id ) {
return ;
}
$this -> form_status = get_post_status ( $this -> form_id );
if ( $this -> form_status != 'publish' ) {
return ;
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
// get data into one global array
2016-02-11 12:05:59 +08:00
$post_data = $ultimatemember -> query -> post_data ( $this -> form_id );
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
$args = apply_filters ( 'um_pre_args_setup' , $post_data );
2015-04-07 20:10:23 +02:00
2016-02-11 12:05:59 +08:00
if ( ! isset ( $args [ 'template' ])) {
$args [ 'template' ] = '' ;
}
if ( isset ( $post_data [ 'template' ]) && $post_data [ 'template' ] != $args [ 'template' ]) {
$args [ 'template' ] = $post_data [ 'template' ];
}
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ( ! $this -> template_exists ( $args [ 'template' ])) {
$args [ 'template' ] = $post_data [ 'mode' ];
}
if ( ! isset ( $post_data [ 'template' ])) {
$post_data [ 'template' ] = $post_data [ 'mode' ];
}
$args = array_merge ( $post_data , $args );
if ( isset ( $args [ 'use_globals' ]) && $args [ 'use_globals' ] == 1 ) {
$args = array_merge ( $args , $this -> get_css_args ( $args ));
2014-12-15 22:38:07 +02:00
} else {
2016-02-11 12:05:59 +08:00
$args = array_merge ( $this -> get_css_args ( $args ), $args );
2014-12-15 22:38:07 +02:00
}
2015-03-12 18:22:29 +02:00
// filter for arguments
2016-02-11 12:05:59 +08:00
$args = apply_filters ( 'um_shortcode_args_filter' , $args );
2014-12-15 22:38:07 +02:00
2016-02-11 12:05:59 +08:00
extract ( $args , EXTR_SKIP );
2015-04-25 21:41:47 +02:00
2015-02-10 02:05:27 +02:00
// for profiles only
2016-02-11 12:05:59 +08:00
if ( $mode == 'profile' && um_profile_id () && isset ( $args [ 'role' ]) && $args [ 'role' ] &&
$args [ 'role' ] != $ultimatemember -> query -> get_role_by_userid ( um_profile_id ())) {
2015-02-10 02:05:27 +02:00
return ;
2016-02-11 12:05:59 +08:00
}
2015-02-10 02:05:27 +02:00
2015-03-12 18:22:29 +02:00
// start loading the template here
2014-12-15 22:38:07 +02:00
do_action ( " um_pre_ { $mode } _shortcode " , $args );
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
do_action ( " um_before_form_is_loaded " , $args );
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
do_action ( " um_before_ { $mode } _form_is_loaded " , $args );
2015-02-23 01:43:11 +02:00
2016-02-11 12:05:59 +08:00
$this -> template_load ( $template , $args );
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
$this -> dynamic_css ( $args );
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ( um_get_requested_user () || $mode == 'logout' ) {
2014-12-15 22:38:07 +02:00
um_reset_user ();
}
2015-12-15 15:45:03 -08:00
2015-04-07 20:10:23 +02:00
do_action ( 'um_after_everything_output' );
2014-12-15 22:38:07 +02:00
$output = ob_get_contents ();
ob_end_clean ();
return $output ;
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @Get dynamic css args
*/
function get_css_args ( $args ) {
$arr = um_styling_defaults ( $args [ 'mode' ]);
$arr = array_merge ( $arr , array ( 'form_id' => $args [ 'form_id' ], 'mode' => $args [ 'mode' ]));
2014-12-15 22:38:07 +02:00
return $arr ;
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @Load dynamic css
*/
function dynamic_css ( $args = array ()) {
2015-01-28 17:16:04 +02:00
global $ultimatemember ;
2014-12-15 22:38:07 +02:00
extract ( $args );
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
$global = um_path . 'assets/dynamic_css/dynamic_global.php' ;
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ( isset ( $mode )) {
$file = um_path . 'assets/dynamic_css/dynamic_' . $mode . '.php' ;
2015-11-05 19:51:31 +08:00
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
include $global ;
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ( isset ( $file ) && file_exists ( $file )) {
2014-12-15 22:38:07 +02:00
include $file ;
2016-02-11 12:05:59 +08:00
}
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ( isset ( $args [ 'custom_css' ])) {
2015-01-28 17:16:04 +02:00
$css = $args [ 'custom_css' ];
2016-02-11 12:05:59 +08:00
?> <!-- ULTIMATE MEMBER FORM INLINE CSS BEGIN --><style type="text/css"><?php print $ultimatemember->styles->minify($css);?></style><!-- ULTIMATE MEMBER FORM INLINE CSS END --><?php
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @Loads a template file
*/
function template_load($template, $args = array()) {
2014-12-15 22:38:07 +02:00
global $ultimatemember;
2016-02-11 12:05:59 +08:00
if (is_array($args)) {
2015-02-04 20:31:39 +02:00
$ultimatemember->shortcodes->set_args = $args;
}
2016-02-11 12:05:59 +08:00
$ultimatemember->shortcodes->load_template($template);
2014-12-15 22:38:07 +02:00
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @Checks if a template file exists
*/
function template_exists($template) {
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
$file = um_path . 'templates/' . $template . '.php';
2015-02-04 20:31:39 +02:00
$theme_file = get_stylesheet_directory() . '/ultimate-member/templates/' . $template . '.php';
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if (file_exists($theme_file) || file_exists($file)) {
2014-12-15 22:38:07 +02:00
return true;
2016-02-11 12:05:59 +08:00
}
2014-12-15 22:38:07 +02:00
return false;
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @Get File Name without path and extension
*/
function get_template_name($file) {
2014-12-15 22:38:07 +02:00
$file = basename($file);
$file = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file);
return $file;
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @Get Templates
*/
function get_templates($excluded = null) {
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
if ($excluded) {
2016-02-11 12:05:59 +08:00
$array[$excluded] = __('Default Template', 'ultimatemember');
2014-12-15 22:38:07 +02:00
}
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
$paths[] = glob(um_path . 'templates/' . '*.php');
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if (file_exists(get_stylesheet_directory() . '/ultimate-member/templates/')) {
$paths[] = glob(get_stylesheet_directory() . '/ultimate-member/templates/' . '*.php');
2015-02-21 01:39:02 +02:00
}
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
foreach ($paths as $k => $files) {
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
foreach ($files as $file) {
2015-12-15 15:45:03 -08:00
2015-02-21 01:39:02 +02:00
$clean_filename = $this->get_template_name($file);
2015-12-15 15:45:03 -08:00
2015-02-21 01:39:02 +02:00
if (0 === strpos($clean_filename, $excluded)) {
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
$source = file_get_contents($file);
$tokens = token_get_all($source);
2015-02-21 01:39:02 +02:00
$comment = array(
2016-02-11 12:05:59 +08:00
T_COMMENT, // All comments since PHP5
T_DOC_COMMENT, // PHPDoc comments
2015-02-21 01:39:02 +02:00
);
2016-02-11 12:05:59 +08:00
foreach ($tokens as $token) {
if (in_array($token[0], $comment) && strstr($token[1], '/* Template:') && $clean_filename != $excluded) {
2015-02-21 01:39:02 +02:00
$txt = $token[1];
2016-02-11 12:05:59 +08:00
$txt = str_replace('/* Template: ', '', $txt);
$txt = str_replace(' */', '', $txt);
$array[$clean_filename] = $txt;
2015-02-21 01:39:02 +02:00
}
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
}
return $array;
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
}
2015-12-15 15:45:03 -08:00
2014-12-15 22:38:07 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @Get Shortcode for given form ID
*/
function get_shortcode($post_id) {
$shortcode = '[ultimatemember form_id=' . $post_id . ']';
2014-12-15 22:38:07 +02:00
return $shortcode;
}
2016-01-10 07:23:29 -08:00
2016-01-02 01:36:11 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @convert access lock tags
*/
function convert_locker_tags($str) {
$str = um_convert_tags($str);
2016-01-02 01:36:11 +02:00
return $str;
}
2015-12-15 15:45:03 -08:00
2015-01-28 17:16:04 +02:00
/***
2016-02-11 12:05:59 +08:00
*** @convert user tags in a string
*/
function convert_user_tags($str) {
2015-12-15 15:45:03 -08:00
2015-03-10 14:27:56 +02:00
$value = '';
2015-12-15 15:45:03 -08:00
2015-01-28 17:16:04 +02:00
$pattern_array = array(
'{first_name}',
'{last_name}',
2015-03-07 13:07:49 +02:00
'{display_name}',
'{user_avatar_small}',
2015-04-07 20:10:23 +02:00
'{username}',
2015-01-28 17:16:04 +02:00
);
2015-12-15 15:45:03 -08:00
2015-01-28 17:16:04 +02:00
$pattern_array = apply_filters('um_allowed_user_tags_patterns', $pattern_array);
2015-12-15 15:45:03 -08:00
2015-01-28 17:16:04 +02:00
$matches = false;
2016-02-11 12:05:59 +08:00
foreach ($pattern_array as $pattern) {
2015-12-15 15:45:03 -08:00
2015-02-01 01:30:04 +02:00
if (preg_match($pattern, $str)) {
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
$usermeta = str_replace('{', '', $pattern);
$usermeta = str_replace('}', '', $usermeta);
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ($usermeta == 'user_avatar_small') {
$value = get_avatar(um_user('ID'), 40);
} elseif (um_user($usermeta)) {
$value = um_user($usermeta);
2015-03-07 13:07:49 +02:00
}
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ($usermeta == 'username') {
2015-04-07 20:10:23 +02:00
$value = um_user('user_login');
}
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
$value = apply_filters("um_profile_tag_hook__{$usermeta}", $value, um_user('ID'));
2015-12-15 15:45:03 -08:00
2016-02-11 12:05:59 +08:00
if ($value) {
$str = preg_replace('/' . $pattern . '/', $value, $str);
2015-01-28 17:16:04 +02:00
}
2015-12-15 15:45:03 -08:00
2015-02-01 01:30:04 +02:00
}
2015-12-15 15:45:03 -08:00
2015-01-28 17:16:04 +02:00
}
2015-12-15 15:45:03 -08:00
2015-01-28 17:16:04 +02:00
return $str;
}
2014-12-15 22:38:07 +02:00
2016-02-26 18:35:09 +08:00
/**
* Shortcode: Show custom content to specific role
2016-03-06 09:36:56 -08:00
*
2016-03-02 01:04:45 +08:00
* Show content to specific roles
2016-02-26 18:35:09 +08:00
* [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']
2016-03-06 09:36:56 -08:00
*
2016-03-02 01:04:45 +08:00
* 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']
2016-03-06 09:36:56 -08:00
*
* @param array $atts
2016-02-26 18:35:09 +08:00
* @param string $content
* @return string
*/
function um_shortcode_show_content_for_role( $atts = array() , $content = '' ) {
2016-03-02 01:04:45 +08:00
global $user_ID;
2016-03-06 09:36:56 -08:00
2016-03-02 01:04:45 +08:00
if( ! is_user_logged_in() ) {
return;
2016-03-06 09:36:56 -08:00
}
2016-03-02 01:04:45 +08:00
2016-02-26 18:35:09 +08:00
$a = shortcode_atts( array(
2016-03-02 01:04:45 +08:00
'roles' => '',
'not' => '',
2016-02-26 18:35:09 +08:00
), $atts );
2016-03-06 09:36:56 -08:00
2016-03-02 01:04:45 +08:00
um_fetch_user( $user_ID );
2016-02-26 18:35:09 +08:00
2016-03-02 01:04:45 +08:00
$current_user_role = um_user('role');
if( isset( $a['not'] ) && ! empty( $a['not'] ) && isset( $a['roles'] ) && ! empty( $a['roles'] ) ){
2016-03-06 09:36:56 -08:00
return do_shortcode( $content );
2016-02-26 18:35:09 +08:00
}
2016-03-02 01:04:45 +08:00
if( isset( $a['not'] ) && ! empty( $a['not'] ) ){
$not_in_roles = explode(",", $a['not'] );
if( is_array( $not_in_roles ) && ! in_array( $current_user_role, $not_in_roles ) ){
2016-03-06 09:36:56 -08:00
return do_shortcode( $content );
2016-03-02 01:04:45 +08:00
}
}else{
$roles = explode(",", $a['roles'] );
2016-03-06 09:36:56 -08:00
2016-03-02 01:04:45 +08:00
if(is_array( $roles ) && in_array( $current_user_role, $roles ) ){
2016-03-06 09:36:56 -08:00
return do_shortcode( $content );
2016-03-02 01:04:45 +08:00
}
2016-03-06 09:36:56 -08:00
2016-03-02 01:04:45 +08:00
}
2016-02-26 18:35:09 +08:00
return '';
}
2016-03-06 09:36:56 -08:00
2015-12-15 15:45:03 -08:00
}