| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809 |
- <?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
- //Make public functions without class creation
- /**
- * Trim string by char length
- *
- *
- * @param $s
- * @param int $length
- *
- * @return string
- */
- function um_trim_string( $s, $length = 20 ) {
- $s = mb_strlen( $s ) > $length ? substr( $s, 0, $length ) . "..." : $s;
- return $s;
- }
- /**
- * Get where user should be headed after logging
- *
- * @param string $redirect_to
- *
- * @return bool|false|mixed|string|void
- */
- function um_dynamic_login_page_redirect( $redirect_to = '' ) {
- $uri = um_get_core_page( 'login' );
- if ( ! $redirect_to ) {
- $redirect_to = UM()->permalinks()->get_current_url();
- }
- $redirect_key = urlencode_deep( $redirect_to );
- $uri = add_query_arg( 'redirect_to', $redirect_key, $uri );
- return $uri;
- }
- /**
- * Checks if session has been started
- *
- * @return bool
- */
- function um_is_session_started() {
- if ( php_sapi_name() !== 'cli' ) {
- if ( version_compare( phpversion(), '5.4.0', '>=' ) ) {
- return session_status() === PHP_SESSION_ACTIVE ? true : false;
- } else {
- return session_id() === '' ? false : true;
- }
- }
- return false;
- }
- /**
- * User clean basename
- *
- * @param $value
- *
- * @return mixed|void
- */
- function um_clean_user_basename( $value ) {
- $raw_value = $value;
- $value = str_replace( '.', ' ', $value );
- $value = str_replace( '-', ' ', $value );
- $value = str_replace( '+', ' ', $value );
- /**
- * UM hook
- *
- * @type filter
- * @title um_clean_user_basename_filter
- * @description Change clean user basename
- * @input_vars
- * [{"var":"$basename","type":"string","desc":"User basename"},
- * {"var":"$raw_basename","type":"string","desc":"RAW user basename"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_clean_user_basename_filter', 'function_name', 10, 2 );
- * @example
- * <?php
- * add_filter( 'um_clean_user_basename_filter', 'my_clean_user_basename', 10, 2 );
- * function my_clean_user_basename( $basename, $raw_basename ) {
- * // your code here
- * return $basename;
- * }
- * ?>
- */
- $value = apply_filters( 'um_clean_user_basename_filter', $value, $raw_value );
- return $value;
- }
- /**
- * Getting replace placeholders array
- *
- * @return array
- */
- function um_replace_placeholders() {
- $search = array(
- '{display_name}',
- '{first_name}',
- '{last_name}',
- '{gender}',
- '{username}',
- '{email}',
- '{site_name}',
- '{user_account_link}',
- );
- /**
- * UM hook
- *
- * @type filter
- * @title um_template_tags_patterns_hook
- * @description Extend UM placeholders
- * @input_vars
- * [{"var":"$placeholders","type":"array","desc":"UM Placeholders"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_template_tags_patterns_hook', 'function_name', 10, 1 );
- * @example
- * <?php
- * add_filter( 'um_template_tags_patterns_hook', 'my_template_tags_patterns', 10, 1 );
- * function my_template_tags_patterns( $placeholders ) {
- * // your code here
- * $placeholders[] = '{my_custom_placeholder}';
- * return $placeholders;
- * }
- * ?>
- */
- $search = apply_filters( 'um_template_tags_patterns_hook', $search );
- $replace = array(
- um_user( 'display_name' ),
- um_user( 'first_name' ),
- um_user( 'last_name' ),
- um_user( 'gender' ),
- um_user( 'user_login' ),
- um_user( 'user_email' ),
- UM()->options()->get( 'site_name' ),
- um_get_core_page( 'account' ),
- );
- /**
- * UM hook
- *
- * @type filter
- * @title um_template_tags_replaces_hook
- * @description Extend UM replace placeholders
- * @input_vars
- * [{"var":"$replace_placeholders","type":"array","desc":"UM Replace Placeholders"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_template_tags_replaces_hook', 'function_name', 10, 1 );
- * @example
- * <?php
- * add_filter( 'um_template_tags_replaces_hook', 'my_template_tags_replaces', 10, 1 );
- * function my_template_tags_replaces( $replace_placeholders ) {
- * // your code here
- * $replace_placeholders[] = 'my_replace_value';
- * return $replace_placeholders;
- * }
- * ?>
- */
- $replace = apply_filters( 'um_template_tags_replaces_hook', $replace );
- return array_combine( $search, $replace );
- }
- /**
- * Convert template tags
- *
- * @param $content
- * @param array $args
- * @param bool $with_kses
- *
- * @return mixed|string
- */
- function um_convert_tags( $content, $args = array(), $with_kses = true ) {
- $placeholders = um_replace_placeholders();
- $content = str_replace( array_keys( $placeholders ), array_values( $placeholders ), $content );
- if ( $with_kses ) {
- $content = wp_kses_decode_entities( $content );
- }
- if ( isset( $args['tags'] ) && isset( $args['tags_replace'] ) ) {
- $content = str_replace( $args['tags'], $args['tags_replace'], $content );
- }
- $regex = '~\{(usermeta:[^}]*)\}~';
- preg_match_all( $regex, $content, $matches );
- // Support for all usermeta keys
- if ( ! empty( $matches[1] ) && is_array( $matches[1] ) ) {
- foreach ( $matches[1] as $match ) {
- $key = str_replace( 'usermeta:', '', $match );
- $value = um_user( $key );
- if ( is_array( $value ) ) {
- $value = implode( ', ', $value );
- }
- $content = str_replace( '{' . $match . '}', apply_filters( 'um_convert_tags', $value, $key ), $content );
- }
- }
- return $content;
- }
- /**
- * UM Placeholders for activation link in email
- *
- * @param $placeholders
- *
- * @return array
- */
- function account_activation_link_tags_patterns( $placeholders ) {
- $placeholders[] = '{account_activation_link}';
- return $placeholders;
- }
- /**
- * UM Replace Placeholders for activation link in email
- *
- * @param $replace_placeholders
- *
- * @return array
- */
- function account_activation_link_tags_replaces( $replace_placeholders ) {
- $replace_placeholders[] = um_user( 'account_activation_link' );
- return $replace_placeholders;
- }
- /**
- * @function um_user_ip()
- *
- * @description This function returns the IP address of user.
- *
- * @usage <?php $user_ip = um_user_ip(); ?>
- *
- * @return string The user's IP address.
- *
- * @example The example below can retrieve the user's IP address
- *
- * <?php
- *
- * $user_ip = um_user_ip();
- * echo 'User IP address is: ' . $user_ip; // prints the user IP address e.g. 127.0.0.1
- *
- * ?>
- */
- function um_user_ip() {
- $ip = '127.0.0.1';
- if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
- //check ip from share internet
- $ip = $_SERVER['HTTP_CLIENT_IP'];
- } else if ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
- //to check ip is pass from proxy
- $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
- } else if ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) {
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- /**
- * UM hook
- *
- * @type filter
- * @title um_user_ip
- * @description Change User IP
- * @input_vars
- * [{"var":"$ip","type":"string","desc":"User IP"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_user_ip', 'function_name', 10, 1 );
- * @example
- * <?php
- * add_filter( 'um_user_ip', 'my_user_ip', 10, 1 );
- * function my_user_ip( $ip ) {
- * // your code here
- * return $ip;
- * }
- * ?>
- */
- return apply_filters( 'um_user_ip', $ip );
- }
- /**
- * If conditions are met return true;
- *
- * @param $data
- *
- * @return bool
- */
- function um_field_conditions_are_met( $data ) {
- if ( ! isset( $data['conditions'] ) ) {
- return true;
- }
- $state = ( isset( $data['conditional_action'] ) && $data['conditional_action'] == 'show' ) ? 1 : 0;
- $first_group = 0;
- $state_array = array();
- $count = count( $state_array );
- foreach ( $data['conditions'] as $k => $arr ) {
- $val = $arr[3];
- $op = $arr[2];
- if ( strstr( $arr[1], 'role_' ) ) {
- $arr[1] = 'role';
- }
- $field = um_profile( $arr[1] );
- if ( ! isset( $arr[5] ) || $arr[5] != $first_group ) {
- if ( $arr[0] == 'show' ) {
- switch ($op) {
- case 'equals to':
- $field = maybe_unserialize( $field );
- if (is_array( $field ))
- $state = in_array( $val, $field ) ? 'show' : 'hide';
- else
- $state = ( $field == $val ) ? 'show' : 'hide';
- break;
- case 'not equals':
- $field = maybe_unserialize( $field );
- if (is_array( $field ))
- $state = !in_array( $val, $field ) ? 'show' : 'hide';
- else
- $state = ( $field != $val ) ? 'show' : 'hide';
- break;
- case 'empty':
- $state = ( !$field ) ? 'show' : 'hide';
- break;
- case 'not empty':
- $state = ( $field ) ? 'show' : 'hide';
- break;
- case 'greater than':
- if ($field > $val) {
- $state = 'show';
- } else {
- $state = 'hide';
- }
- break;
- case 'less than':
- if ($field < $val) {
- $state = 'show';
- } else {
- $state = 'hide';
- }
- break;
- case 'contains':
- if (strstr( $field, $val )) {
- $state = 'show';
- } else {
- $state = 'hide';
- }
- break;
- }
- } elseif ( $arr[0] == 'hide' ) {
- switch ( $op ) {
- case 'equals to':
- $field = maybe_unserialize( $field );
- if ( is_array( $field ) ) {
- $state = in_array( $val, $field ) ? 'hide' : 'show';
- } else {
- $state = ( $field == $val ) ? 'hide' : 'show';
- }
- break;
- case 'not equals':
- $field = maybe_unserialize( $field );
- if ( is_array( $field ) ) {
- $state = ! in_array( $val, $field ) ? 'hide' : 'show';
- } else {
- $state = ( $field != $val ) ? 'hide' : 'show';
- }
- break;
- case 'empty':
- $state = ( ! $field ) ? 'hide' : 'show';
- break;
- case 'not empty':
- $state = ( $field ) ? 'hide' : 'show';
- break;
- case 'greater than':
- if ( $field <= $val ) {
- $state = 'hide';
- } else {
- $state = 'show';
- }
- break;
- case 'less than':
- if ( $field >= $val ) {
- $state = 'hide';
- } else {
- $state = 'show';
- }
- break;
- case 'contains':
- if ( strstr( $field, $val ) ) {
- $state = 'hide';
- } else {
- $state = 'show';
- }
- break;
- }
- }
- $first_group++;
- array_push( $state_array, $state );
- } else {
- if ( $arr[0] == 'show' ) {
- switch ( $op ) {
- case 'equals to':
- $field = maybe_unserialize( $field );
- if ( is_array( $field ) ) {
- $state = in_array( $val, $field ) ? 'show' : 'not_show';
- } else {
- $state = ( $field == $val ) ? 'show' : 'not_show';
- }
- break;
- case 'not equals':
- $field = maybe_unserialize( $field );
- if ( is_array( $field ) ) {
- $state = ! in_array( $val, $field ) ? 'show' : 'not_show';
- } else {
- $state = ( $field != $val ) ? 'show' : 'not_show';
- }
- break;
- case 'empty':
- $state = ( ! $field ) ? 'show' : 'not_show';
- break;
- case 'not empty':
- $state = ( $field ) ? 'show': 'not_show';
- break;
- case 'greater than':
- if ( $field > $val ) {
- $state = 'show';
- } else {
- $state = 'not_show';
- }
- break;
- case 'less than':
- if ( $field < $val ) {
- $state = 'show';
- } else {
- $state = 'not_show';
- }
- break;
- case 'contains':
- if ( strstr( $field, $val ) ) {
- $state = 'show';
- } else {
- $state = 'not_show';
- }
- break;
- }
- } elseif ( $arr[0] == 'hide' ) {
- switch ( $op ) {
- case 'equals to':
- $field = maybe_unserialize( $field );
- if ( is_array( $field ) ) {
- $state = in_array( $val, $field ) ? 'hide' : 'not_hide';
- } else {
- $state = ( $field == $val ) ? 'hide' : 'not_hide';
- }
- break;
- case 'not equals':
- $field = maybe_unserialize( $field );
- if ( is_array( $field ) ) {
- $state = ! in_array( $val, $field ) ? 'hide' : 'not_hide';
- } else {
- $state = ( $field != $val ) ? 'hide' : 'not_hide';
- }
- break;
- case 'empty':
- $state = ( ! $field ) ? 'hide' : 'not_hide';
- break;
- case 'not empty':
- $state = ( $field ) ? 'hide' : 'not_hide';
- break;
- case 'greater than':
- if ( $field <= $val ) {
- $state = 'hide';
- } else {
- $state = 'not_hide';
- }
- break;
- case 'less than':
- if ( $field >= $val ) {
- $state = 'hide';
- } else {
- $state = 'not_hide';
- }
- break;
- case 'contains':
- if ( strstr( $field, $val ) ) {
- $state = 'hide';
- } else {
- $state = 'not_hide';
- }
- break;
- }
- }
- if ( isset( $state_array[ $count ] ) ) {
- if ( $state_array[ $count ] == 'show' || $state_array[ $count ] == 'not_hide' ) {
- if ( $state == 'show' || $state == 'not_hide' ) {
- $state_array[ $count ] = 'show';
- } else {
- $state_array[ $count ] = 'hide';
- }
- } else {
- if ( $state == 'hide' || $state == 'not_show' ) {
- $state_array[ $count ] = 'hide';
- } else {
- $state_array[ $count ] = 'hide';
- }
- }
- } else {
- if ( $state == 'show' || $state == 'not_hide' ) {
- $state_array[ $count ] = 'show';
- } else {
- $state_array[ $count ] = 'hide';
- }
- }
- }
- }
- $result = array_unique( $state_array );
- if ( ! in_array( 'show', $result ) ) {
- return $state = false;
- } else {
- return $state = true;
- }
- }
- /**
- * Exit and redirect to home
- *
- * @param string $requested_user_id
- * @param string $is_my_profile
- */
- function um_redirect_home( $requested_user_id = '', $is_my_profile = '' ) {
- $url = apply_filters( 'um_redirect_home_custom_url', home_url(), $requested_user_id, $is_my_profile );
- exit( wp_redirect( $url ) );
- }
- /**
- * @param $url
- */
- function um_js_redirect( $url ) {
- if ( headers_sent() || empty( $url ) ) {
- //for blank redirects
- if ( '' == $url ) {
- $url = set_url_scheme( '//' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] );
- }
- register_shutdown_function( function( $url ) {
- echo '<script data-cfasync="false" type="text/javascript">window.location = "' . esc_js( $url ) . '"</script>';
- }, $url );
- if ( 1 < ob_get_level() ) {
- while ( ob_get_level() > 1 ) {
- ob_end_clean();
- }
- } ?>
- <script data-cfasync='false' type="text/javascript">
- window.location = '<?php echo esc_js( $url ); ?>';
- </script>
- <?php exit;
- } else {
- wp_redirect( $url );
- }
- exit;
- }
- /**
- * Get limit of words from sentence
- *
- * @param $str
- * @param int $wordCount
- *
- * @return string
- */
- function um_get_snippet( $str, $wordCount = 10 ) {
- if (str_word_count( $str, 0, "éèàôù" ) > $wordCount) {
- $str = implode(
- '',
- array_slice(
- preg_split(
- '/([\s,\.;\?\!]+)/',
- $str,
- $wordCount * 2 + 1,
- PREG_SPLIT_DELIM_CAPTURE
- ),
- 0,
- $wordCount * 2 - 1
- )
- );
- }
- return $str;
- }
- /**
- * Format submitted data for Info preview & Email template
- * @param boolean $style
- * @return string
- *
- * @since 2.1.4
- */
- function um_user_submitted_registration_formatted( $style = false ) {
- $output = null;
- $submitted_data = um_user( 'submitted' );
- if ( $style ) {
- $output .= '<div class="um-admin-infobox">';
- }
- // Timestamp
- $output .= um_user_submited_display( 'timestamp', __( 'Date Submitted', 'ultimate-member' ) );
- $output .= um_user_submited_display( 'form_id', __( 'Form', 'ultimate-member' ), $submitted_data );
- if ( isset( $submitted_data['use_gdpr_agreement'] ) ) {
- $output .= um_user_submited_display( 'use_gdpr_agreement', __( 'GDPR Applied', 'ultimate-member' ), $submitted_data );
- }
- if ( isset( $submitted_data ) && is_array( $submitted_data ) ) {
- if ( isset( $submitted_data['form_id'] ) ) {
- $fields = UM()->query()->get_attr( 'custom_fields', $submitted_data['form_id'] );
- $fields = maybe_unserialize( $fields );
- }
- if ( ! empty( $fields ) ) {
- $fields['form_id'] = array( 'title' => __( 'Form', 'ultimate-member' ) );
- $rows = array();
- UM()->fields()->get_fields = $fields;
- foreach ( $fields as $key => $array ) {
- if ( isset( $array['type'] ) && $array['type'] == 'row' ) {
- $rows[ $key ] = $array;
- unset( UM()->fields()->get_fields[ $key ] ); // not needed now
- }
- }
- if ( empty( $rows ) ) {
- $rows = array(
- '_um_row_1' => array(
- 'type' => 'row',
- 'id' => '_um_row_1',
- 'sub_rows' => 1,
- 'cols' => 1,
- ),
- );
- }
- foreach ( $rows as $row_id => $row_array ) {
- $row_fields = UM()->fields()->get_fields_by_row( $row_id );
- if ( $row_fields ) {
- $output .= UM()->fields()->new_row_output( $row_id, $row_array );
- $sub_rows = ( isset( $row_array['sub_rows'] ) ) ? $row_array['sub_rows'] : 1;
- for ( $c = 0; $c < $sub_rows; $c++ ) {
- // cols
- $cols = ( isset( $row_array['cols'] ) ) ? $row_array['cols'] : 1;
- if ( strstr( $cols, ':' ) ) {
- $col_split = explode( ':', $cols );
- } else {
- $col_split = array( $cols );
- }
- $cols_num = $col_split[ $c ];
- // sub row fields
- $subrow_fields = null;
- $subrow_fields = UM()->fields()->get_fields_in_subrow( $row_fields, $c );
- if ( is_array( $subrow_fields ) ) {
- if ( isset( $subrow_fields['form_id'] ) ) {
- unset( $subrow_fields['form_id'] );
- }
- $subrow_fields = UM()->fields()->array_sort_by_column( $subrow_fields, 'position' );
- if ( $cols_num == 1 ) {
- $col1_fields = UM()->fields()->get_fields_in_column( $subrow_fields, 1 );
- if ( $col1_fields ) {
- foreach ( $col1_fields as $key => $data ) {
- $output .= um_user_submited_display( $key, $data['title'] );
- }
- }
- } elseif ( $cols_num == 2 ) {
- $col1_fields = UM()->fields()->get_fields_in_column( $subrow_fields, 1 );
- if ( $col1_fields ) {
- foreach ( $col1_fields as $key => $data ) {
- $output .= um_user_submited_display( $key, $data['title'] );
- }
- }
- $col2_fields = UM()->fields()->get_fields_in_column( $subrow_fields, 2 );
- if ( $col2_fields ) {
- foreach ( $col2_fields as $key => $data ) {
- $output .= um_user_submited_display( $key, $data['title'] );
- }
- }
- } else {
- $col1_fields = UM()->fields()->get_fields_in_column( $subrow_fields, 1 );
- if ( $col1_fields ) {
- foreach ( $col1_fields as $key => $data ) {
- $output .= um_user_submited_display( $key, $data['title'] );
- }
- }
- $col2_fields = UM()->fields()->get_fields_in_column( $subrow_fields, 2 );
- if ( $col2_fields ) {
- foreach ( $col2_fields as $key => $data ) {
- $output .= um_user_submited_display( $key, $data['title'] );
- }
- }
- $col3_fields = UM()->fields()->get_fields_in_column( $subrow_fields, 3 );
- if ( $col3_fields ) {
- foreach ( $col3_fields as $key => $data ) {
- $output .= um_user_submited_display( $key, $data['title'] );
- }
- }
- }
- }
- }
- }
- } // endfor
- }
- }
- if ( $style ) {
- $output .= '</div>';
- }
- return $output;
- }
- /**
- * Prepare template
- *
- * @param string $k
- * @param string $title
- * @param array $data
- * @param boolean $style
- * @return string
- *
- * @since 2.1.4
- */
- function um_user_submited_display( $k, $title, $data = array(), $style = true ) {
- $output = '';
- if ( 'form_id' == $k && isset( $data['form_id'] ) && ! empty( $data['form_id'] ) ) {
- $v = sprintf( __( '%s - Form ID#: %s', 'ultimate-member' ), get_the_title( $data['form_id'] ), $data['form_id'] );
- } else {
- $v = um_user( $k );
- }
- if ( strstr( $k, 'user_pass' ) || in_array( $k, array( 'g-recaptcha-response', 'request', '_wpnonce', '_wp_http_referer' ) ) ) {
- return '';
- }
- $fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
- $type = UM()->fields()->get_field_type( $k );
- if ( in_array( $type, $fields_without_metakey ) ) {
- return '';
- }
- if ( ! $v ) {
- if ( $style ) {
- return "<p><label>$title: </label><span>" . __( '(empty)', 'ultimate-member' ) ."</span></p>";
- } else {
- return '';
- }
- }
- if ( $type == 'image' || $type == 'file' ) {
- $file = basename( $v );
- $filedata = get_user_meta( um_user( 'ID' ), $k . "_metadata", true );
- $baseurl = UM()->uploader()->get_upload_base_url();
- if ( ! file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . $file ) ) {
- if ( is_multisite() ) {
- //multisite fix for old customers
- $baseurl = str_replace( '/sites/' . get_current_blog_id() . '/', '/', $baseurl );
- }
- }
- if ( ! empty( $filedata['original_name'] ) ) {
- $v = '<a href="' . esc_attr( $baseurl . um_user( 'ID' ) . '/' . $file ) . '">' . esc_html( $filedata['original_name'] ) . '</a>';
- } else {
- $v = $baseurl . um_user( 'ID' ) . '/' . $file;
- }
- }
- if ( is_array( $v ) ) {
- $v = implode( ',', $v );
- }
- if ( $k == 'timestamp' ) {
- $v = date( "d M Y H:i", $v );
- } elseif ( $k == 'use_gdpr_agreement' ) {
- $v = date( "d M Y H:i", $v );
- }
- if ( $style ) {
- if ( ! $v ) {
- $v = __( '(empty)', 'ultimate-member' );
- }
- $output .= "<p><label>$title: </label><span>$v</span></p>";
- } else {
- $output .= "$title: $v" . "<br />";
- }
- return $output;
- }
- /**
- * Show filtered social link
- *
- * @param string $key
- * @param string $match
- *
- * @return string
- */
- function um_filtered_social_link( $key, $match ) {
- $value = um_profile( $key );
- $submatch = str_replace( 'https://', '', $match );
- $submatch = str_replace( 'http://', '', $submatch );
- if ( strstr( $value, $submatch ) ) {
- $value = 'https://' . $value;
- } elseif ( strpos( $value, 'http' ) !== 0 ) {
- $value = $match . $value;
- }
- $value = str_replace( 'https://https://', 'https://', $value );
- $value = str_replace( 'http://https://', 'https://', $value );
- $value = str_replace( 'https://http://', 'https://', $value );
- return $value;
- }
- /**
- * Get filtered meta value after applying hooks
- *
- * @param $key
- * @param bool $data
- * @return mixed|string|void
- */
- function um_filtered_value( $key, $data = false ) {
- $value = um_user( $key );
- if ( is_array( $value ) ) {
- $value = add_magic_quotes( $value );
- }
- if ( ! $data ) {
- $data = UM()->builtin()->get_specific_field( $key );
- }
- $type = ( isset( $data['type'] ) ) ? $data['type'] : '';
- /**
- * UM hook
- *
- * @type filter
- * @title um_profile_field_filter_hook__
- * @description Change or filter field value
- * @input_vars
- * [{"var":"$value","type":"string","desc":"Field Value"},
- * {"var":"$data","type":"array","desc":"Field Data"},
- * {"var":"$type","type":"string","desc":"Field Type"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_profile_field_filter_hook__', 'function_name', 10, 3 );
- * @example
- * <?php
- * add_filter( 'um_profile_field_filter_hook__', 'my_profile_field', 10, 3 );
- * function my_profile_field( $value, $data, $type ) {
- * // your code here
- * return $value;
- * }
- * ?>
- */
- $value = apply_filters( 'um_profile_field_filter_hook__', $value, $data, $type );
- /**
- * UM hook
- *
- * @type filter
- * @title um_profile_field_filter_hook__{$key}
- * @description Change or filter field value by field key ($key)
- * @input_vars
- * [{"var":"$value","type":"string","desc":"Field Value"},
- * {"var":"$data","type":"array","desc":"Field Data"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_profile_field_filter_hook__{$key}', 'function_name', 10, 2 );
- * @example
- * <?php
- * add_filter( 'um_profile_field_filter_hook__{$key}', 'my_profile_field', 10, 2 );
- * function my_profile_field( $value, $data ) {
- * // your code here
- * return $value;
- * }
- * ?>
- */
- $value = apply_filters( "um_profile_field_filter_hook__{$key}", $value, $data );
- /**
- * UM hook
- *
- * @type filter
- * @title um_profile_field_filter_hook__{$type}
- * @description Change or filter field value by field type ($type)
- * @input_vars
- * [{"var":"$value","type":"string","desc":"Field Value"},
- * {"var":"$data","type":"array","desc":"Field Data"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_profile_field_filter_hook__{$type}', 'function_name', 10, 2 );
- * @example
- * <?php
- * add_filter( 'um_profile_field_filter_hook__{$type}', 'my_profile_field', 10, 2 );
- * function my_profile_field( $value, $data ) {
- * // your code here
- * return $value;
- * }
- * ?>
- */
- $value = apply_filters( "um_profile_field_filter_hook__{$type}", $value, $data );
- $value = UM()->shortcodes()->emotize( $value );
- return $value;
- }
- /**
- * Returns requested User ID or current User ID
- *
- * @return int
- */
- function um_profile_id() {
- $requested_user = um_get_requested_user();
- if ( $requested_user ) {
- return um_get_requested_user();
- } elseif ( is_user_logged_in() && get_current_user_id() ) {
- return get_current_user_id();
- }
- return 0;
- }
- /**
- * Check that temp upload is valid
- *
- * @param string $url
- *
- * @return bool|string
- */
- function um_is_temp_upload( $url ) {
- if ( is_string( $url ) ) {
- $url = trim( $url );
- }
- if ( filter_var( $url, FILTER_VALIDATE_URL ) === false ) {
- $url = realpath( $url );
- }
- if ( ! $url ) {
- return false;
- }
- $url = explode( '/ultimatemember/temp/', $url );
- if ( isset( $url[1] ) ) {
- if ( strstr( $url[1], '../' ) || strstr( $url[1], '%' ) ) {
- return false;
- }
- $src = UM()->files()->upload_temp . $url[1];
- if ( ! file_exists( $src ) ) {
- return false;
- }
- return $src;
- }
- return false;
- }
- /**
- * Check that temp image is valid
- *
- * @param $url
- *
- * @return bool|string
- */
- function um_is_temp_image( $url ) {
- $url = explode( '/ultimatemember/temp/', $url );
- if (isset( $url[1] )) {
- $src = UM()->files()->upload_temp . $url[1];
- if (!file_exists( $src ))
- return false;
- list( $width, $height, $type, $attr ) = @getimagesize( $src );
- if (isset( $width ) && isset( $height ))
- return $src;
- }
- return false;
- }
- /**
- * Check user's file ownership
- * @param string $url
- * @param int|null $user_id
- * @param string|bool $image_path
- * @return bool
- */
- function um_is_file_owner( $url, $user_id = null, $image_path = false ) {
- if ( strpos( $url, UM()->uploader()->get_upload_base_url() . $user_id . '/' ) !== false && is_user_logged_in() ) {
- $user_basedir = UM()->uploader()->get_upload_user_base_dir( $user_id );
- } else {
- $user_basedir = UM()->uploader()->get_upload_user_base_dir( 'temp' );
- }
- $filename = wp_basename( parse_url( $url, PHP_URL_PATH ) );
- $file = $user_basedir . DIRECTORY_SEPARATOR . $filename;
- if ( file_exists( $file ) ) {
- if ( $image_path ) {
- return $file;
- }
- return true;
- }
- return false;
- }
- /**
- * Check if file is temporary
- * @param string $filename
- * @return bool
- */
- function um_is_temp_file( $filename ) {
- $user_basedir = UM()->uploader()->get_upload_user_base_dir( 'temp' );
- $file = $user_basedir . '/' . $filename;
- if ( file_exists( $file ) ) {
- return true;
- }
- return false;
- }
- /**
- * Get user's last login timestamp
- *
- * @param $user_id
- *
- * @return mixed|string
- */
- function um_user_last_login_timestamp( $user_id ) {
- $value = get_user_meta( $user_id, '_um_last_login', true );
- if ( $value ) {
- return $value;
- }
- return '';
- }
- /**
- * Get user's last login (time diff)
- *
- * @param int $user_id
- *
- * @return string
- */
- function um_user_last_login( $user_id ) {
- $value = get_user_meta( $user_id, '_um_last_login', true );
- return ! empty( $value ) ? UM()->datetime()->time_diff( $value, current_time( 'timestamp' ) ) : '';
- }
- /**
- * Get core page url
- *
- * @param $slug
- * @param bool $updated
- *
- * @return bool|false|mixed|string|void
- */
- function um_get_core_page( $slug, $updated = false ) {
- $url = '';
- if ( isset( UM()->config()->permalinks[ $slug ] ) ) {
- $url = get_permalink( UM()->config()->permalinks[ $slug ] );
- if ( $updated ) {
- $url = add_query_arg( 'updated', esc_attr( $updated ), $url );
- }
- }
- /**
- * UM hook
- *
- * @type filter
- * @title um_get_core_page_filter
- * @description Change UM core page URL
- * @input_vars
- * [{"var":"$url","type":"string","desc":"UM Page URL"},
- * {"var":"$slug","type":"string","desc":"UM Page slug"},
- * {"var":"$updated","type":"bool","desc":"Additional parameter"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_get_core_page_filter', 'function_name', 10, 3 );
- * @example
- * <?php
- * add_filter( 'um_get_core_page_filter', 'my_core_page_url', 10, 3 );
- * function my_core_page_url( $url, $slug, $updated ) {
- * // your code here
- * return $url;
- * }
- * ?>
- */
- return apply_filters( 'um_get_core_page_filter', $url, $slug, $updated );
- }
- /**
- * Check if we are on a UM Core Page or not
- *
- * Default um core pages slugs
- * 'user', 'login', 'register', 'members', 'logout', 'account', 'password-reset'
- *
- * @param string $page UM core page slug
- *
- * @return bool
- */
- function um_is_core_page( $page ) {
- global $post;
- if ( empty( $post ) ) {
- return false;
- }
- if ( isset( $post->ID ) && isset( UM()->config()->permalinks[ $page ] ) && $post->ID == UM()->config()->permalinks[ $page ] ) {
- return true;
- }
- if ( isset( $post->ID ) && get_post_meta( $post->ID, '_um_wpml_' . $page, true ) == 1 ) {
- return true;
- }
- if ( UM()->external_integrations()->is_wpml_active() ) {
- global $sitepress;
- if ( isset( UM()->config()->permalinks[ $page ] ) && UM()->config()->permalinks[ $page ] == wpml_object_id_filter( $post->ID, 'page', true, $sitepress->get_default_language() ) ) {
- return true;
- }
- }
- if ( isset( $post->ID ) ) {
- $_icl_lang_duplicate_of = get_post_meta( $post->ID, '_icl_lang_duplicate_of', true );
- if ( isset( UM()->config()->permalinks[ $page ] ) && ( ( $_icl_lang_duplicate_of == UM()->config()->permalinks[ $page ] && !empty( $_icl_lang_duplicate_of ) ) || UM()->config()->permalinks[ $page ] == $post->ID ) ) {
- return true;
- }
- }
- return false;
- }
- /**
- * @param $post
- * @param $core_page
- *
- * @return bool
- */
- function um_is_core_post( $post, $core_page ) {
- if ( isset( $post->ID ) && isset( UM()->config()->permalinks[ $core_page ] ) && $post->ID == UM()->config()->permalinks[ $core_page ] ) {
- return true;
- }
- if ( isset( $post->ID ) && get_post_meta( $post->ID, '_um_wpml_' . $core_page, true ) == 1 ) {
- return true;
- }
- if ( isset( $post->ID ) ) {
- $_icl_lang_duplicate_of = get_post_meta( $post->ID, '_icl_lang_duplicate_of', true );
- if ( isset( UM()->config()->permalinks[ $core_page ] ) && ( ( $_icl_lang_duplicate_of == UM()->config()->permalinks[ $core_page ] && ! empty( $_icl_lang_duplicate_of ) ) || UM()->config()->permalinks[ $core_page ] == $post->ID ) ) {
- return true;
- }
- }
- return false;
- }
- /**
- * Get styling defaults
- *
- * @param $mode
- *
- * @return array
- */
- function um_styling_defaults( $mode ) {
- $new_arr = array();
- $core_form_meta_all = UM()->config()->core_form_meta_all;
- $core_global_meta_all = UM()->config()->core_global_meta_all;
- foreach ( $core_form_meta_all as $k => $v ) {
- $s = str_replace( $mode . '_', '', $k );
- if (strstr( $k, '_um_' . $mode . '_' ) && !in_array( $s, $core_global_meta_all )) {
- $a = str_replace( '_um_' . $mode . '_', '', $k );
- $b = str_replace( '_um_', '', $k );
- $new_arr[$a] = UM()->options()->get( $b );
- } else if (in_array( $k, $core_global_meta_all )) {
- $a = str_replace( '_um_', '', $k );
- $new_arr[$a] = UM()->options()->get( $a );
- }
- }
- return $new_arr;
- }
- /**
- * Get meta option default
- *
- * @param $id
- *
- * @return string
- */
- function um_get_metadefault( $id ) {
- $core_form_meta_all = UM()->config()->core_form_meta_all;
- return isset( $core_form_meta_all[ '_um_' . $id ] ) ? $core_form_meta_all[ '_um_' . $id ] : '';
- }
- /**
- * boolean for account page editing
- *
- * @return bool
- */
- function um_submitting_account_page() {
- if ( isset( $_POST['_um_account'] ) && $_POST['_um_account'] == 1 && is_user_logged_in() ) {
- return true;
- }
- return false;
- }
- /**
- * Get a user's display name
- *
- * @param $user_id
- *
- * @return string
- */
- function um_get_display_name( $user_id ) {
- um_fetch_user( $user_id );
- $name = um_user( 'display_name' );
- um_reset_user();
- return $name;
- }
- /**
- * Clears the user data. You need to fetch a user manually after using this function.
- *
- * @function um_reset_user_clean()
- *
- * @description This function is similar to um_reset_user() with a difference that it will not use the logged-in
- * user data after resetting. It is a hard-reset function for all user data.
- *
- * @usage <?php um_reset_user_clean(); ?>
- *
- * @example You can reset user data by using the following line in your code
- *
- * <?php um_reset_user_clean(); ?>
- */
- function um_reset_user_clean() {
- UM()->user()->reset( true );
- }
- /**
- * Clears the user data. If a user is logged in, the user data will be reset to that user's data
- *
- * @function um_reset_user()
- *
- * @description This function resets the current user. You can use it to reset user data after
- * retrieving the details of a specific user.
- *
- * @usage <?php um_reset_user(); ?>
- *
- * @example You can reset user data by using the following line in your code
- *
- * <?php um_reset_user(); ?>
- */
- function um_reset_user() {
- UM()->user()->reset();
- }
- /**
- * Gets the queried user
- *
- * @return mixed
- */
- function um_queried_user() {
- return get_query_var( 'um_user' );
- }
- /**
- * Sets the requested user
- *
- * @param $user_id
- */
- function um_set_requested_user( $user_id ) {
- UM()->user()->target_id = $user_id;
- }
- /**
- * Gets the requested user
- *
- * @return bool|null
- */
- function um_get_requested_user() {
- if ( ! empty( UM()->user()->target_id ) ) {
- return UM()->user()->target_id;
- }
- return false;
- }
- /**
- * Remove edit profile args from url
- *
- * @param string $url
- *
- * @return mixed|string|void
- */
- function um_edit_my_profile_cancel_uri( $url = '' ) {
- if ( empty( $url ) ) {
- $url = remove_query_arg( 'um_action' );
- $url = remove_query_arg( 'profiletab', $url );
- $url = add_query_arg( 'profiletab', 'main', $url );
- }
- /**
- * UM hook
- *
- * @type filter
- * @title um_edit_profile_cancel_uri
- * @description Change Edit Profile Cancel URL
- * @input_vars
- * [{"var":"$url","type":"string","desc":"Cancel URL"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_edit_profile_cancel_uri', 'function_name', 10, 1 );
- * @example
- * <?php
- * add_filter( 'um_edit_profile_cancel_uri', 'my_edit_profile_cancel_uri', 10, 1 );
- * function my_edit_profile_cancel_uri( $url ) {
- * // your code here
- * return $url;
- * }
- * ?>
- */
- $url = apply_filters( 'um_edit_profile_cancel_uri', $url );
- return $url;
- }
- /**
- * boolean for profile edit page
- *
- * @return bool
- */
- function um_is_on_edit_profile() {
- if ( isset( $_REQUEST['um_action'] ) && sanitize_key( $_REQUEST['um_action'] ) == 'edit' ) {
- return true;
- }
- return false;
- }
- /**
- * Can view field
- *
- * @param $data
- *
- * @return bool
- */
- function um_can_view_field( $data ) {
- $can_view = true;
- if ( ! isset( UM()->fields()->set_mode ) ) {
- UM()->fields()->set_mode = '';
- }
- if ( isset( $data['public'] ) && UM()->fields()->set_mode != 'register' ) {
- $can_edit = false;
- $current_user_roles = [];
- if ( is_user_logged_in() ) {
- $can_edit = UM()->roles()->um_current_user_can( 'edit', um_user( 'ID' ) );
- $previous_user = um_user( 'ID' );
- um_fetch_user( get_current_user_id() );
- $current_user_roles = um_user( 'roles' );
- um_fetch_user( $previous_user );
- }
- switch ( $data['public'] ) {
- case '1': // Everyone
- break;
- case '2': // Members
- if ( ! is_user_logged_in() ) {
- $can_view = false;
- }
- break;
- case '-1': // Only visible to profile owner and users who can edit other member accounts
- if ( ! is_user_logged_in() ) {
- $can_view = false;
- } elseif ( ! um_is_user_himself() && ! $can_edit ) {
- $can_view = false;
- }
- break;
- case '-2': // Only specific member roles
- if ( ! is_user_logged_in() ) {
- $can_view = false;
- } elseif ( ! empty( $data['roles'] ) && count( array_intersect( $current_user_roles, $data['roles'] ) ) <= 0 ) {
- $can_view = false;
- }
- break;
- case '-3': // Only visible to profile owner and specific roles
- if ( ! is_user_logged_in() ) {
- $can_view = false;
- } elseif ( ! um_is_user_himself() && ! empty( $data['roles'] ) && count( array_intersect( $current_user_roles, $data['roles'] ) ) <= 0 ) {
- $can_view = false;
- }
- break;
- default:
- $can_view = apply_filters( 'um_can_view_field_custom', $can_view, $data );
- break;
- }
- }
- return apply_filters( 'um_can_view_field', $can_view, $data );
- }
- /**
- * Checks if user can view profile
- *
- * @param $user_id
- *
- * @return bool
- */
- function um_can_view_profile( $user_id ) {
- if ( ! is_user_logged_in() ) {
- return ! UM()->user()->is_private_profile( $user_id );
- }
- $temp_id = um_user('ID');
- um_fetch_user( get_current_user_id() );
- if ( ! um_user( 'can_view_all' ) && $user_id != get_current_user_id() && is_user_logged_in() ) {
- um_fetch_user( $temp_id );
- return false;
- }
- if ( ! um_user( 'can_access_private_profile' ) && UM()->user()->is_private_profile( $user_id ) ) {
- um_fetch_user( $temp_id );
- return false;
- }
- if ( um_user( 'can_view_roles' ) && $user_id != get_current_user_id() ) {
- $can_view_roles = um_user( 'can_view_roles' );
- if ( ! is_array( $can_view_roles ) ) {
- $can_view_roles = array();
- }
- if ( count( $can_view_roles ) && count( array_intersect( UM()->roles()->get_all_user_roles( $user_id ), $can_view_roles ) ) <= 0 ) {
- um_fetch_user( $temp_id );
- return false;
- }
- }
- um_fetch_user( $temp_id );
- return true;
- }
- /**
- * boolean check for not same user
- *
- * @return bool
- */
- function um_is_user_himself() {
- if (um_get_requested_user() && um_get_requested_user() != get_current_user_id())
- return false;
- return true;
- }
- /**
- * Can edit field
- *
- * @param $data
- *
- * @return bool
- */
- function um_can_edit_field( $data ) {
- $can_edit = true;
- if ( ! empty( UM()->fields()->editing ) && isset( UM()->fields()->set_mode ) && UM()->fields()->set_mode == 'profile' ) {
- if ( ! is_user_logged_in() ) {
- $can_edit = false;
- } else {
- if ( ! UM()->roles()->um_user_can( 'can_edit_everyone' ) ) {
- if ( isset( $data['editable'] ) && $data['editable'] == 0 ) {
- $can_edit = false;
- } else {
- if ( ! um_is_user_himself() ) {
- $can_edit = false;
- }
- }
- }
- }
- }
- return apply_filters( 'um_can_edit_field', $can_edit, $data );
- }
- /**
- * Check if user is in his profile
- *
- * @return bool
- */
- function um_is_myprofile() {
- if (get_current_user_id() && get_current_user_id() == um_get_requested_user()) return true;
- if (!um_get_requested_user() && um_is_core_page( 'user' ) && get_current_user_id()) return true;
- return false;
- }
- /**
- * Returns the edit profile link
- *
- * @param int $user_id
- *
- * @return string
- */
- function um_edit_profile_url( $user_id = null ) {
- if ( um_is_core_page( 'user' ) ) {
- $url = UM()->permalinks()->get_current_url();
- } else {
- $url = isset( $user_id ) ? um_user_profile_url( $user_id ) : um_user_profile_url();
- }
- $url = remove_query_arg( 'profiletab', $url );
- $url = remove_query_arg( 'subnav', $url );
- $url = add_query_arg( 'um_action', 'edit', $url );
- return $url;
- }
- /**
- * Checks if user can edit his profile
- *
- * @return bool
- */
- function um_can_edit_my_profile() {
- if ( ! is_user_logged_in() || ! um_user( 'can_edit_profile' ) ) {
- return false;
- }
- return true;
- }
- /**
- * Short for admin e-mail
- *
- * @return mixed|string|void
- */
- function um_admin_email() {
- return UM()->options()->get( 'admin_email' );
- }
- /**
- * Get admin e-mails
- *
- * @return array
- */
- function um_multi_admin_email() {
- $emails = UM()->options()->get( 'admin_email' );
- $emails_array = explode( ',', $emails );
- if ( ! empty( $emails_array ) ) {
- $emails_array = array_map( 'trim', $emails_array );
- }
- $emails_array = array_unique( $emails_array );
- return $emails_array;
- }
- /**
- * Display a link to profile page
- *
- * @param int|bool $user_id
- *
- * @return bool|string
- */
- function um_user_profile_url( $user_id = false ) {
- if ( ! $user_id ) {
- $user_id = um_user( 'ID' );
- }
- $url = UM()->user()->get_profile_link( $user_id );
- if ( empty( $url ) ) {
- //if empty profile slug - generate it and re-get profile URL
- UM()->user()->generate_profile_slug( $user_id );
- $url = UM()->user()->get_profile_link( $user_id );
- }
- return $url;
- }
- /**
- * Get all UM roles in array
- *
- * @return array
- */
- function um_get_roles() {
- return UM()->roles()->get_roles();
- }
- /**
- * Sets a specific user and prepares profile data and user permissions and makes them accessible.
- *
- * @function um_fetch_user()
- *
- * @description This function sets a user and allow you to retrieve any information for the retrieved user
- *
- * @usage <?php um_fetch_user( $user_id ); ?>
- *
- * @param $user_id (numeric) (required) A user ID is required. This is the user's ID that you wish to set/retrieve
- *
- *
- * @example The example below will set user ID 5 prior to retrieving his profile information.
- *
- * <?php
- *
- * um_fetch_user(5);
- * echo um_user('display_name'); // returns the display name of user ID 5
- *
- * ?>
- *
- * @example In the following example you can fetch the profile of a logged-in user dynamically.
- *
- * <?php
- *
- * um_fetch_user( get_current_user_id() );
- * echo um_user('display_name'); // returns the display name of logged-in user
- *
- * ?>
- *
- */
- function um_fetch_user( $user_id ) {
- UM()->user()->set( $user_id );
- }
- /**
- * Load profile key
- *
- * @param $key
- *
- * @return bool|string
- */
- function um_profile( $key ) {
- if ( ! empty( UM()->user()->profile[ $key ] ) ) {
- /**
- * UM hook
- *
- * @type filter
- * @title um_profile_{$key}__filter
- * @description Change not empty profile field value
- * @input_vars
- * [{"var":"$value","type":"mixed","desc":"Profile Value"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_profile_{$key}__filter', 'function_name', 10, 1 );
- * @example
- * <?php
- * add_filter( 'um_profile_{$key}__filter', 'my_profile_value', 10, 1 );
- * function my_profile_value( $value ) {
- * // your code here
- * return $value;
- * }
- * ?>
- */
- $value = apply_filters( "um_profile_{$key}__filter", UM()->user()->profile[ $key ] );
- } else {
- /**
- * UM hook
- *
- * @type filter
- * @title um_profile_{$key}_empty__filter
- * @description Change Profile field value if it's empty
- * @input_vars
- * [{"var":"$value","type":"mixed","desc":"Profile Value"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_profile_{$key}_empty__filter', 'function_name', 10, 1 );
- * @example
- * <?php
- * add_filter( 'um_profile_{$key}_empty__filter', 'my_profile_value', 10, 1 );
- * function my_profile_value( $value ) {
- * // your code here
- * return $value;
- * }
- * ?>
- */
- $value = apply_filters( "um_profile_{$key}_empty__filter", false );
- }
- return $value;
- }
- /**
- * Get youtube video ID from url
- *
- * @param $url
- *
- * @return bool
- */
- function um_youtube_id_from_url( $url ) {
- $pattern =
- '%^# Match any youtube URL
- (?:https?://)? # Optional scheme. Either http or https
- (?:www\.)? # Optional www subdomain
- (?: # Group host alternatives
- youtu\.be/ # Either youtu.be,
- | youtube\.com # or youtube.com
- (?: # Group path alternatives
- /embed/ # Either /embed/
- | /v/ # or /v/
- | /watch\?v= # or /watch\?v=
- ) # End path alternatives.
- ) # End host alternatives.
- ([\w-]{10,12}) # Allow 10-12 for 11 char youtube id.
- $%x';
- $result = preg_match( $pattern, $url, $matches );
- if ( false !== $result && isset( $matches[1] ) ) {
- return $matches[1];
- }
- return false;
- }
- /**
- * Find closest number in an array
- *
- * @param $array
- * @param $number
- *
- * @return mixed
- */
- function um_closest_num( $array, $number ) {
- sort( $array );
- foreach ( $array as $a ) {
- if ( $a >= $number ) return $a;
- }
- return end( $array );
- }
- /**
- * get cover uri
- *
- * @param $image
- * @param $attrs
- *
- * @return bool|string
- */
- function um_get_cover_uri( $image, $attrs ) {
- $uri = false;
- $uri_common = false;
- $ext = '.' . pathinfo( $image, PATHINFO_EXTENSION );
- $ratio = str_replace(':1','',UM()->options()->get( 'profile_cover_ratio' ) );
- $height = round( $attrs / $ratio );
- if ( is_multisite() ) {
- //multisite fix for old customers
- $multisite_fix_dir = UM()->uploader()->get_upload_base_dir();
- $multisite_fix_url = UM()->uploader()->get_upload_base_url();
- $multisite_fix_dir = str_replace( DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . get_current_blog_id() . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $multisite_fix_dir );
- $multisite_fix_url = str_replace( '/sites/' . get_current_blog_id() . '/', '/', $multisite_fix_url );
- if ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "cover_photo{$ext}" ) ) {
- $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/cover_photo{$ext}?" . current_time( 'timestamp' );
- }
- if ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "cover_photo-{$attrs}{$ext}" ) ) {
- $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/cover_photo-{$attrs}{$ext}?" . current_time( 'timestamp' );
- }elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "cover_photo-{$attrs}x{$height}{$ext}" ) ) {
- $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/cover_photo-{$attrs}x{$height}{$ext}?". current_time( 'timestamp' );
- }
- }
- if ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "cover_photo{$ext}" ) ) {
- $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/cover_photo{$ext}?" . current_time( 'timestamp' );
- }
- if ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "cover_photo-{$attrs}{$ext}" ) ) {
- $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/cover_photo-{$attrs}{$ext}?" . current_time( 'timestamp' );
- }elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "cover_photo-{$attrs}x{$height}{$ext}" ) ) {
- $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/cover_photo-{$attrs}x{$height}{$ext}?". current_time( 'timestamp' );
- }
- if ( ! empty( $uri_common ) && empty( $uri ) ) {
- $uri = $uri_common;
- }
- return $uri;
- }
- /**
- * get avatar URL instead of image
- *
- * @param $get_avatar
- *
- * @return mixed
- */
- function um_get_avatar_url( $get_avatar ) {
- preg_match( '/src="(.*?)"/i', $get_avatar, $matches );
- return isset( $matches[1] ) ? $matches[1] : '';
- }
- /**
- * get avatar uri
- *
- * @param $image
- * @param string|array $attrs
- *
- * @return bool|string
- */
- function um_get_avatar_uri( $image, $attrs ) {
- $uri = false;
- $uri_common = false;
- $find = false;
- $ext = '.' . pathinfo( $image, PATHINFO_EXTENSION );
- if ( is_multisite() ) {
- //multisite fix for old customers
- $multisite_fix_dir = UM()->uploader()->get_upload_base_dir();
- $multisite_fix_url = UM()->uploader()->get_upload_base_url();
- $multisite_fix_dir = str_replace( DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . get_current_blog_id() . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $multisite_fix_dir );
- $multisite_fix_url = str_replace( '/sites/' . get_current_blog_id() . '/', '/', $multisite_fix_url );
- if ( $attrs == 'original' && file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) {
- $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo{$ext}";
- } elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}x{$attrs}{$ext}" ) ) {
- $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$attrs}x{$attrs}{$ext}";
- } elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}{$ext}" ) ) {
- $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$attrs}{$ext}";
- } else {
- $sizes = UM()->options()->get( 'photo_thumb_sizes' );
- if ( is_array( $sizes ) ) {
- $find = um_closest_num( $sizes, $attrs );
- }
- if ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}x{$find}{$ext}" ) ) {
- $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$find}x{$find}{$ext}";
- } elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}{$ext}" ) ) {
- $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$find}{$ext}";
- } elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) {
- $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo{$ext}";
- }
- }
- }
- if ( $attrs == 'original' && file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) {
- $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo{$ext}";
- } elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}x{$attrs}{$ext}" ) ) {
- $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$attrs}x{$attrs}{$ext}";
- } elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}{$ext}" ) ) {
- $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$attrs}{$ext}";
- } else {
- $sizes = UM()->options()->get( 'photo_thumb_sizes' );
- if ( is_array( $sizes ) ) {
- $find = um_closest_num( $sizes, $attrs );
- }
- if ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}x{$find}{$ext}" ) ) {
- $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$find}x{$find}{$ext}";
- } elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}{$ext}" ) ) {
- $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$find}{$ext}";
- } elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) {
- $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo{$ext}";
- }
- }
- if ( ! empty( $uri_common ) && empty( $uri ) ) {
- $uri = $uri_common;
- }
- /**
- * UM hook
- *
- * @type filter
- * @title um_filter_avatar_cache_time
- * @description Change Profile field value if it's empty
- * @input_vars
- * [{"var":"$timestamp","type":"timestamp","desc":"Avatar cache time"},
- * {"var":"$user_id","type":"int","desc":"User ID"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_filter_avatar_cache_time', 'function_name', 10, 2 );
- * @example
- * <?php
- * add_filter( 'um_filter_avatar_cache_time', 'my_avatar_cache_time', 10, 2 );
- * function my_avatar_cache_time( $timestamp, $user_id ) {
- * // your code here
- * return $timestamp;
- * }
- * ?>
- */
- $cache_time = apply_filters( 'um_filter_avatar_cache_time', current_time( 'timestamp' ), um_user( 'ID' ) );
- if ( ! empty( $cache_time ) ) {
- $uri .= "?{$cache_time}";
- }
- return $uri;
- }
- /**
- * Default avatar URL
- *
- * @return string
- */
- function um_get_default_avatar_uri() {
- $uri = UM()->options()->get( 'default_avatar' );
- $uri = !empty( $uri['url'] ) ? $uri['url'] : '';
- if ( ! $uri ) {
- $uri = um_url . 'assets/img/default_avatar.jpg';
- }
- return set_url_scheme( $uri );
- }
- /**
- * get user avatar url
- *
- * @param $user_id
- * @param $size
- *
- * @return bool|string
- */
- function um_get_user_avatar_data( $user_id = '', $size = '96' ) {
- if( empty( $user_id ) ) {
- $user_id = um_user( 'ID' );
- } else {
- um_fetch_user( $user_id );
- }
- $data = array(
- 'user_id' => $user_id,
- 'default' => um_get_default_avatar_uri(),
- 'class' => 'gravatar avatar avatar-' . $size . ' um-avatar',
- 'size' => $size
- );
- if ( $profile_photo = um_profile( 'profile_photo' ) ) {
- $data['url'] = um_get_avatar_uri( $profile_photo, $size );
- $data['type'] = 'upload';
- $data['class'] .= ' um-avatar-uploaded';
- } elseif ( $synced_profile_photo = um_user( 'synced_profile_photo' ) ) {
- $data['url'] = $synced_profile_photo;
- $data['type'] = 'sync';
- $data['class'] .= ' um-avatar-default';
- } elseif ( UM()->options()->get( 'use_gravatars' ) ) {
- $avatar_hash_id = md5( um_user( 'user_email' ) );
- $data['url'] = set_url_scheme( '//gravatar.com/avatar/' . $avatar_hash_id );
- $data['url'] = add_query_arg( 's', 400, $data['url'] );
- $rating = get_option( 'avatar_rating' );
- if ( ! empty( $rating ) ) {
- $data['url'] = add_query_arg( 'r', $rating, $data['url'] );
- }
- $gravatar_type = UM()->options()->get( 'use_um_gravatar_default_builtin_image' );
- if ( $gravatar_type == 'default' ) {
- if ( UM()->options()->get( 'use_um_gravatar_default_image' ) ) {
- $data['url'] = add_query_arg( 'd', $data['default'], $data['url'] );
- } else {
- $default = get_option( 'avatar_default', 'mystery' );
- if ( $default == 'gravatar_default' ) {
- $default = '';
- }
- $data['url'] = add_query_arg( 'd', $default, $data['url'] );
- }
- } else {
- $data['url'] = add_query_arg( 'd', $gravatar_type, $data['url'] );
- }
- $data['type'] = 'gravatar';
- $data['class'] .= ' um-avatar-gravatar';
- } else {
- $data['url'] = $data['default'];
- $data['type'] = 'default';
- $data['class'] .= ' um-avatar-default';
- }
- /**
- * UM hook
- *
- * @type filter
- * @title um_user_avatar_url_filter
- * @description Change user avatar URL
- * @input_vars
- * [{"var":"$avatar_uri","type":"string","desc":"Avatar URL"},
- * {"var":"$user_id","type":"int","desc":"User ID"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_user_avatar_url_filter', 'function_name', 10, 2 );
- * @example
- * <?php
- * add_filter( 'um_user_avatar_url_filter', 'my_user_avatar_url', 10, 2 );
- * function my_user_avatar_url( $avatar_uri ) {
- * // your code here
- * return $avatar_uri;
- * }
- * ?>
- */
- $data['url'] = apply_filters( 'um_user_avatar_url_filter', $data['url'], $user_id, $data );
- /**
- * UM hook
- *
- * @type filter
- * @title um_avatar_image_alternate_text
- * @description Change user display name on um_user function profile photo
- * @input_vars
- * [{"var":"$display_name","type":"string","desc":"User Display Name"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_avatar_image_alternate_text', 'function_name', 10, 1 );
- * @example
- * <?php
- * add_filter( 'um_avatar_image_alternate_text', 'my_avatar_image_alternate_text', 10, 1 );
- * function my_avatar_image_alternate_text( $display_name ) {
- * // your code here
- * return $display_name;
- * }
- * ?>
- */
- $data['alt'] = apply_filters( "um_avatar_image_alternate_text", um_user( "display_name" ), $data );
- return $data;
- }
- /**
- * get user avatar url
- *
- * @param $user_id
- * @param $size
- *
- * @return bool|string
- */
- function um_get_user_avatar_url( $user_id = '', $size = '96' ) {
- $data = um_get_user_avatar_data( $user_id, $size );
- return $data['url'];
- }
- /**
- * default cover
- *
- * @return mixed|string|void
- */
- function um_get_default_cover_uri() {
- $uri = UM()->options()->get( 'default_cover' );
- $uri = ! empty( $uri['url'] ) ? $uri['url'] : '';
- if ( $uri ) {
- /**
- * UM hook
- *
- * @type filter
- * @title um_get_default_cover_uri_filter
- * @description Change Default Cover URL
- * @input_vars
- * [{"var":"$uri","type":"string","desc":"Default Cover URL"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_get_default_cover_uri_filter', 'function_name', 10, 1 );
- * @example
- * <?php
- * add_filter( 'um_get_default_cover_uri_filter', 'my_default_cover_uri', 10, 1 );
- * function my_default_cover_uri( $uri ) {
- * // your code here
- * return $uri;
- * }
- * ?>
- */
- return apply_filters( 'um_get_default_cover_uri_filter', $uri );
- }
- return '';
- }
- /**
- * @param $data
- * @param null $attrs
- *
- * @return string|array
- */
- function um_user( $data, $attrs = null ) {
- switch ($data) {
- default:
- $value = um_profile( $data );
- $value = maybe_unserialize( $value );
- if ( in_array( $data, array( 'role', 'gender' ) ) ) {
- if ( is_array( $value ) ) {
- $value = implode( ",", $value );
- }
- return $value;
- }
- return $value;
- break;
- case 'user_email':
- $user_email_in_meta = get_user_meta( um_user( 'ID' ), 'user_email', true );
- if ( $user_email_in_meta ) {
- delete_user_meta( um_user( 'ID' ), 'user_email' );
- }
- $value = um_profile( $data );
- return $value;
- break;
- case 'user_login':
- $user_login_in_meta = get_user_meta( um_user( 'ID' ), 'user_login', true );
- if ( $user_login_in_meta ) {
- delete_user_meta( um_user( 'ID' ), 'user_login' );
- }
- $value = um_profile( $data );
- return $value;
- break;
- case 'first_name':
- case 'last_name':
- $name = um_profile( $data );
- if ( UM()->options()->get( 'force_display_name_capitlized' ) ) {
- $name = implode( '-', array_map( 'ucfirst', explode( '-', $name ) ) );
- }
- /**
- * UM hook
- *
- * @type filter
- * @title um_user_{$data}_case
- * @description Change user name on um_user function
- * @input_vars
- * [{"var":"$name","type":"string","desc":"User Name"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_user_{$data}_case', 'function_name', 10, 1 );
- * @example
- * <?php
- * add_filter( 'um_user_{$data}_case', 'my_user_case', 10, 1 );
- * function my_user_case( $name ) {
- * // your code here
- * return $name;
- * }
- * ?>
- */
- $name = apply_filters( "um_user_{$data}_case", $name );
- return $name;
- break;
- case 'full_name':
- if ( um_user( 'first_name' ) && um_user( 'last_name' ) ) {
- $full_name = um_user( 'first_name' ) . ' ' . um_user( 'last_name' );
- } else {
- $full_name = um_user( 'display_name' );
- }
- $full_name = UM()->validation()->safe_name_in_url( $full_name );
- // update full_name changed
- if ( um_profile( $data ) !== $full_name ) {
- update_user_meta( um_user( 'ID' ), 'full_name', $full_name );
- }
- return $full_name;
- break;
- case 'first_and_last_name_initial':
- $f_and_l_initial = '';
- if ( um_user( 'first_name' ) && um_user( 'last_name' ) ) {
- $initial = um_user( 'last_name' );
- $f_and_l_initial = um_user( 'first_name' ) . ' ' . $initial[0];
- } else {
- $f_and_l_initial = um_profile( $data );
- }
- $f_and_l_initial = UM()->validation()->safe_name_in_url( $f_and_l_initial );
- if ( UM()->options()->get( 'force_display_name_capitlized' ) ) {
- $name = implode( '-', array_map( 'ucfirst', explode( '-', $f_and_l_initial ) ) );
- } else {
- $name = $f_and_l_initial;
- }
- return $name;
- break;
- case 'display_name':
- $op = UM()->options()->get( 'display_name' );
- $name = '';
- if ( $op == 'default' ) {
- $name = um_profile( 'display_name' );
- }
- if ( $op == 'nickname' ) {
- $name = um_profile( 'nickname' );
- }
- if ( $op == 'full_name' ) {
- if ( um_user( 'first_name' ) && um_user( 'last_name' ) ) {
- $name = um_user( 'first_name' ) . ' ' . um_user( 'last_name' );
- } else {
- $name = um_profile( $data );
- }
- if ( ! $name ) {
- $name = um_user( 'user_login' );
- }
- }
- if ( $op == 'sur_name' ) {
- if ( um_user( 'first_name' ) && um_user( 'last_name' ) ) {
- $name = um_user( 'last_name' ) . ' ' . um_user( 'first_name' );
- } else {
- $name = um_profile( $data );
- }
- }
- if ( $op == 'first_name' ) {
- if ( um_user( 'first_name' ) ) {
- $name = um_user( 'first_name' );
- } else {
- $name = um_profile( $data );
- }
- }
- if ( $op == 'username' ) {
- $name = um_user( 'user_login' );
- }
- if ( $op == 'initial_name' ) {
- if (um_user( 'first_name' ) && um_user( 'last_name' )) {
- $initial = um_user( 'last_name' );
- $name = um_user( 'first_name' ) . ' ' . $initial[0];
- } else {
- $name = um_profile( $data );
- }
- }
- if ( $op == 'initial_name_f' ) {
- if ( um_user( 'first_name' ) && um_user( 'last_name' ) ) {
- $initial = um_user( 'first_name' );
- $name = $initial[0] . ' ' . um_user( 'last_name' );
- } else {
- $name = um_profile( $data );
- }
- }
- if ( $op == 'field' && UM()->options()->get( 'display_name_field' ) != '' ) {
- $fields = array_filter( preg_split( '/[,\s]+/', UM()->options()->get( 'display_name_field' ) ) );
- $name = '';
- foreach ( $fields as $field ) {
- if ( um_profile( $field ) ) {
- $field_value = maybe_unserialize( um_profile( $field ) );
- $field_value = is_array( $field_value ) ? implode( ',', $field_value ) : $field_value;
- $name .= $field_value . ' ';
- } elseif ( um_user( $field ) && $field != 'display_name' && $field != 'full_name' ) {
- $name .= um_user( $field ) . ' ';
- }
- }
- }
- if ( UM()->options()->get( 'force_display_name_capitlized' ) ) {
- $name = implode( '-', array_map( 'ucfirst', explode( '-', $name ) ) );
- }
- /**
- * UM hook
- *
- * @type filter
- * @title um_user_display_name_filter
- * @description Change user display name on um_user function
- * @input_vars
- * [{"var":"$name","type":"string","desc":"User Name"},
- * {"var":"$user_id","type":"int","desc":"User ID"},
- * {"var":"$html","type":"bool","desc":"Is HTML"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_user_display_name_filter', 'function_name', 10, 3 );
- * @example
- * <?php
- * add_filter( 'um_user_display_name_filter', 'my_user_display_name', 10, 3 );
- * function my_user_display_name( $name, $user_id, $html ) {
- * // your code here
- * return $name;
- * }
- * ?>
- */
- return apply_filters( 'um_user_display_name_filter', $name, um_user( 'ID' ), ( $attrs == 'html' ) ? 1 : 0 );
- break;
- case 'role_select':
- case 'role_radio':
- return UM()->roles()->get_role_name( UM()->roles()->get_editable_priority_user_role( um_user( 'ID' ) ) );
- break;
- case 'submitted':
- $array = um_profile( $data );
- if ( empty( $array ) ) {
- return '';
- }
- $array = maybe_unserialize( $array );
- return $array;
- break;
- case 'password_reset_link':
- return UM()->password()->reset_url();
- break;
- case 'account_activation_link':
- return UM()->permalinks()->activate_url();
- break;
- case 'profile_photo':
- $data = um_get_user_avatar_data( um_user( 'ID' ), $attrs );
- return sprintf( '<img src="%s" class="%s" width="%s" height="%s" alt="%s" data-default="%s" onerror="%s" />',
- esc_attr( $data['url'] ),
- esc_attr( $data['class'] ),
- esc_attr( $data['size'] ),
- esc_attr( $data['size'] ),
- esc_attr( $data['alt'] ),
- esc_attr( $data['default'] ),
- 'if ( ! this.getAttribute(\'data-load-error\') ){ this.setAttribute(\'data-load-error\', \'1\');this.setAttribute(\'src\', this.getAttribute(\'data-default\'));}'
- );
- break;
- case 'cover_photo':
- $is_default = false;
- if ( um_profile( 'cover_photo' ) ) {
- $cover_uri = um_get_cover_uri( um_profile( 'cover_photo' ), $attrs );
- } elseif ( um_profile( 'synced_cover_photo' ) ) {
- $cover_uri = um_profile( 'synced_cover_photo' );
- } else {
- $cover_uri = um_get_default_cover_uri();
- $is_default = true;
- }
- /**
- * UM hook
- *
- * @type filter
- * @title um_user_cover_photo_uri__filter
- * @description Change user avatar URL
- * @input_vars
- * [{"var":"$cover_uri","type":"string","desc":"Cover URL"},
- * {"var":"$is_default","type":"bool","desc":"Default or not"},
- * {"var":"$attrs","type":"array","desc":"Attributes"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_user_cover_photo_uri__filter', 'function_name', 10, 3 );
- * @example
- * <?php
- * add_filter( 'um_user_cover_photo_uri__filter', 'my_user_cover_photo_uri', 10, 3 );
- * function my_user_cover_photo_uri( $cover_uri, $is_default, $attrs ) {
- * // your code here
- * return $cover_uri;
- * }
- * ?>
- */
- $cover_uri = apply_filters( 'um_user_cover_photo_uri__filter', $cover_uri, $is_default, $attrs );
- $alt = um_profile( 'nickname' );
- $cover_html = $cover_uri ? '<img src="' . esc_attr( $cover_uri ) . '" alt="' . esc_attr( $alt ) . '" />' : '';
- $cover_html = apply_filters( 'um_user_cover_photo_html__filter', $cover_html, $cover_uri, $alt, $is_default, $attrs );
- return $cover_html;
- break;
- case 'user_url':
- $value = um_profile( $data );
- return $value;
- break;
- }
- }
- /**
- * Get server protocol
- *
- * @return string
- */
- function um_get_domain_protocol() {
- if (is_ssl()) {
- $protocol = 'https://';
- } else {
- $protocol = 'http://';
- }
- return $protocol;
- }
- /**
- * Set SSL to media URI
- *
- * @param string $url
- *
- * @return string
- */
- function um_secure_media_uri( $url ) {
- if (is_ssl()) {
- $url = str_replace( 'http:', 'https:', $url );
- }
- return $url;
- }
- /**
- * Force strings to UTF-8 encoded
- *
- * @param mixed $value
- *
- * @return mixed
- */
- function um_force_utf8_string( $value ) {
- if ( is_array( $value ) ) {
- $arr_value = array();
- foreach ( $value as $key => $v ) {
- $utf8_decoded_value = utf8_decode( $v );
- if ( mb_check_encoding( $utf8_decoded_value, 'UTF-8' ) ) {
- array_push( $arr_value, $utf8_decoded_value );
- } else {
- array_push( $arr_value, $v );
- }
- }
- return $arr_value;
- } else {
- $utf8_decoded_value = utf8_decode( $value );
- if (mb_check_encoding( $utf8_decoded_value, 'UTF-8' )) {
- return $utf8_decoded_value;
- }
- }
- return $value;
- }
- /**
- * Get user host
- *
- * Returns the webhost this site is using if possible
- *
- * @since 1.3.68
- * @return mixed string $host if detected, false otherwise
- */
- function um_get_host() {
- $host = false;
- if (defined( 'WPE_APIKEY' )) {
- $host = 'WP Engine';
- } else if (defined( 'PAGELYBIN' )) {
- $host = 'Pagely';
- } else if (DB_HOST == 'localhost:/tmp/mysql5.sock') {
- $host = 'ICDSoft';
- } else if (DB_HOST == 'mysqlv5') {
- $host = 'NetworkSolutions';
- } else if (strpos( DB_HOST, 'ipagemysql.com' ) !== false) {
- $host = 'iPage';
- } else if (strpos( DB_HOST, 'ipowermysql.com' ) !== false) {
- $host = 'IPower';
- } else if (strpos( DB_HOST, '.gridserver.com' ) !== false) {
- $host = 'MediaTemple Grid';
- } else if (strpos( DB_HOST, '.pair.com' ) !== false) {
- $host = 'pair Networks';
- } else if (strpos( DB_HOST, '.stabletransit.com' ) !== false) {
- $host = 'Rackspace Cloud';
- } else if (strpos( DB_HOST, '.sysfix.eu' ) !== false) {
- $host = 'SysFix.eu Power Hosting';
- } else if (strpos( $_SERVER['SERVER_NAME'], 'Flywheel' ) !== false) {
- $host = 'Flywheel';
- } else {
- // Adding a general fallback for data gathering
- $host = 'DBH: ' . DB_HOST . ', SRV: ' . $_SERVER['SERVER_NAME'];
- }
- return $host;
- }
- /**
- * Let To Num
- *
- * Does Size Conversions
- *
- * @since 1.3.68
- * @author Chris Christoff
- *
- * @param string $v
- *
- * @return int|string
- */
- function um_let_to_num( $v ) {
- $l = substr( $v, -1 );
- $ret = substr( $v, 0, -1 );
- switch (strtoupper( $l )) {
- case 'P': // fall-through
- case 'T': // fall-through
- case 'G': // fall-through
- case 'M': // fall-through
- case 'K': // fall-through
- $ret *= 1024;
- break;
- default:
- break;
- }
- return $ret;
- }
- /**
- * Check if we are on UM page
- *
- * @return bool
- */
- function is_ultimatemember() {
- global $post;
- if ( isset( $post->ID ) && in_array( $post->ID, UM()->config()->permalinks ) )
- return true;
- return false;
- }
- /**
- * Maybe set empty time limit
- */
- function um_maybe_unset_time_limit() {
- @set_time_limit( 0 );
- }
- /*
- * Check if current user is owner of requested profile
- * @Returns Boolean
- */
- if ( ! function_exists( 'um_is_profile_owner' ) ) {
- /**
- * @param $user_id
- *
- * @return bool
- */
- function um_is_profile_owner( $user_id = false ) {
- if ( ! is_user_logged_in() ) {
- return false;
- }
- if ( empty( $user_id ) ) {
- $user_id = get_current_user_id();
- }
- return ( $user_id == um_profile_id() );
- }
- }
- /**
- * Check whether the current page is in AMP mode or not.
- * We need to check for specific functions, as there is no special AMP header.
- *
- * @since 2.1.11
- *
- * @param bool $check_theme_support Whether theme support should be checked. Defaults to true.
- *
- * @uses is_amp_endpoint() AMP by Automattic
- * @uses is_better_amp() Better AMP
- *
- * @return bool
- */
- function um_is_amp( $check_theme_support = true ) {
- $is_amp = false;
- if ( ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) ||
- ( function_exists( 'is_better_amp' ) && is_better_amp() ) ) {
- $is_amp = true;
- }
- if ( $is_amp && $check_theme_support ) {
- $is_amp = current_theme_supports( 'amp' );
- }
- return apply_filters( 'um_is_amp', $is_amp );
- }
|