function();
* $hmpl_usermeta->function()['array'];
*
*/
class HMPUserMeta {
protected $current_user = array();
public $userid;
public $displayname;
public $firstname;
public $lastname;
public $email;
public $website;
public $biography;
public $mainblog;
public $useriseditor;
public $userisadmin;
public $avatar_small;
public $avatar_big;
public $avatar_huge;
//* Filter hmpusermeta_hmpl_notavailable
public $hmpl_notavailable;
//* Filter hmplusermeta_hmpl_notspecified
public $hmpl_notspecified;
/**
* Constructor : Set up cacheable values.
*/
public function __construct() {
//* Parse vars
$this->current_user = wp_get_current_user();
$this->userid = $this->current_user->ID;
$this->displayname = $this->current_user->display_name;
$this->firstname = $this->current_user->user_firstname;
$this->lastname = $this->current_user->user_lastname;
$this->email = $this->current_user->user_email;
$this->regdate = $this->current_user->user_registered;
$this->website = $this->current_user->user_url;
$this->biography = $this->current_user->description;
$this->mainblog = get_user_meta($this->userid, 'primary_blog', true); //int
$this->avatar_small = get_avatar( $this->userid, 34 );
$this->avatar_big = get_avatar( $this->userid, 68 );
$this->avatar_huge = get_avatar( $this->userid, 120 );
//* Put functions in variables
// Example use: echo $hmpl_usermeta->hmpl_display_name;
//* user cap is called after theme setup
$this->useriseditor = $this->hmpl_user_is_editor(); //bool
$this->userisadmin = $this->hmpl_user_is_admin(); //bool
$this->hmpl_display_name = $this->hmpl_display_name(); //str
$this->hmpl_first_name = $this->hmpl_first_name(); //str
$this->hmpl_last_name = $this->hmpl_last_name(); //str
$this->hmpl_full_name = $this->hmpl_full_name(); //str
$this->hmpl_reg_date = $this->hmpl_reg_date(); //str
$this->hmpl_email_address = $this->hmpl_email_address(); //str
$this->hmpl_website = $this->hmpl_user_website(); //array
$this->hmpl_biography = $this->hmpl_biography(); //str
$this->hmpl_klantnummer = $this->hmpl_klantnummer(); //str
$this->hmpl_avatar = $this->hmpl_avatar(); //array
$this->hmpl_addressmeta = $this->hmpl_addressmeta(); //array
$this->hmpl_isbedrijf = $this->hmpl_isbedrijf(); //bool : duplicate
$this->hmpl_userbedrijfinfo = $this->hmpl_userbedrijfinfo(); //array
$this->hmpl_user_main_blog = $this->hmpl_user_main_blog(); //array
$this->hmpl_notavailable = $this->hmpl_notavailable(); //str filter : hmpusermeta_hmpl_notavailable
$this->hmpl_notspecified = $this->hmpl_notspecified(); //str filter : hmpusermeta_hmpl_notspecified
}
/**
* Returns boolean of editor role for main blog
*
* @param $user_is_editor
*
* @return bool
*/
public function hmpl_user_is_editor() {
$user_is_editor = current_user_can_for_blog($this->mainblog, 'edit_pages');
return $user_is_editor;
}
/**
* Returns boolean of admin role for main blog
*
* @param $user_is_admin
*
* @return bool
*/
public function hmpl_user_is_admin() {
$user_is_admin = current_user_can_for_blog($this->mainblog, 'edit_theme_options');
return $user_is_admin;
}
/**
* Returns string Not Available
*
* @param $output : output
*
* @filter hmpusermeta_hmpl_notavailable
*
* @return string
*/
public function hmpl_notavailable() {
$output = apply_filters( 'hmpusermeta_hmpl_notavailable', 'Niet beschikbaar' );
return $output;
}
/**
* Returns string Not Specified
*
* @param $output : output
*
* @filter hmpusermeta_hmpl_notspecified
*
* @return string
*/
public function hmpl_notspecified() {
$output = apply_filters( 'hmpusermeta_hmpl_notspecified', 'Niet opgegeven' );
return $output;
}
/**
* Returns string display name of user
*
* @return string : if not found, return not_specified
*/
public function hmpl_display_name() {
if ( !empty($this->displayname) ) {
return $this->displayname;
} else {
return $this->hmpl_notspecified();
}
}
/**
* Returns string first name of user
*
* @return string : if not found, return display name
*/
public function hmpl_first_name() {
if ( !empty($this->firstname) ) {
return $this->firstname;
} else {
return $this->hmpl_display_name;
}
}
/**
* Returns string last name of user
*
* @return string : if not found, return display name
*/
public function hmpl_last_name() {
if ( !empty($this->lastname) ) {
return $this->lastname;
} else {
return $this->hmpl_display_name;
}
}
/**
* Returns string full name of user
*
* @return string : if not found return not_specified
*/
public function hmpl_full_name() {
if ( !empty($this->firstname) || !empty($this->lastname) ) {
return $this->firstname . ' ' . $this->lastname;
} else {
return $this->hmpl_notspecified();
}
}
/**
* Returns string e-mail of user profile
*
* @return string plain : plain url
* @return string url : html wrapped url
*/
public function hmpl_email_address() {
if ( !empty($this->email ) ) {
return $this->email;
} else {
return $this->hmpl_notspecified();
}
}
/**
* Returns Array of user profile's Website
*
* @return string plain : plain url
* @return string url : html wrapped url
*/
public function hmpl_user_website() {
if ( !empty($this->website ) ) {
$url_plain = esc_url($this->website);
$goto = 'Ga naar ';
$url = sprintf( '%s', trailingslashit($url_plain), esc_attr($goto), trailingslashit(esc_attr($url_plain)), $url_plain );
return array(
'plain' => $plain,
'url' => $url,
);
} else {
return array(
'plain' => $this->hmpl_notspecified(),
'url' => $this->hmpl_notspecified(),
);
}
}
/**
* Returns biography of user
*
* @return string : biography
*/
public function hmpl_biography() {
if ( !empty($this->biography ) ) {
return esc_attr($this->biography);
} else {
return $this->hmpl_notspecified();
}
}
/**
* Returns date of user registration
*
* @return date_i18n : registration date
*/
public function hmpl_reg_date() {
return date_i18n('d F, Y', strtotime( $this->regdate )); // e.g. 03 June 1991
}
/**
* Returns Array of Gravatar avatars
*
* @requires: Genesis Framework
* @else: return bool false
*
* @param array $avatar
*
* @return array small
* @return array big
* @return array huge
* @return array else : Specify your own size in pixels
*/
public function hmpl_avatar() {
/**
* Filter the available sizes.
*/
$size = apply_filters( 'hmpusermeta_avatar', absint(50) ); // not working =(
$avatar = array(
'small' => $this->avatar_small,
'big' => $this->avatar_big,
'huge' => $this->avatar_huge,
'else' => get_avatar( $this->userid, $size ),
);
return $avatar;
}
/**
* Returns Array of User "Address" meta
*
* @requires: MU-Plugin useraddressmeta.php by Sybre Waaijer
* @else: returns "not_available" by default
*
* @return int klantnummer
*/
public function hmpl_klantnummer() {
if ( !empty( get_the_author_meta('user_klantnummer', $this->userid ) ) ) {
return esc_attr(get_the_author_meta( 'user_klantnummer', $this->userid ));
} else {
return $this->hmpl_notavailable();
}
}
/**
* Returns Array of User "Address" meta
*
* @requires: MU-Plugin useraddressmeta.php by Sybre Waaijer
* @else: return string $this->not_specified
*
* @return string straat
* @return string postcode
* @return string plaats
* @return string provincie
* @return string land
*/
public function hmpl_addressmeta() {
if ( !empty( get_the_author_meta( 'user_straat', $this->userid ) ) ) {
$straat = esc_attr(get_the_author_meta( 'user_straat', $this->userid ));
} else {
$straat = $this->hmpl_notspecified();
}
if ( !empty( get_the_author_meta( 'user_postcode', $this->userid ) ) ) {
$postcode = esc_attr(get_the_author_meta( 'user_postcode', $this->userid ));
} else {
$postcode = $this->hmpl_notspecified();
}
if ( !empty( get_the_author_meta( 'user_plaats', $this->userid ) ) ) {
$plaats = esc_attr(get_the_author_meta( 'user_plaats', $this->userid ));
} else {
$plaats = $this->hmpl_notspecified();
}
if ( !empty( get_the_author_meta( 'user_provincie', $this->userid ) ) ) {
$provincie = esc_attr(get_the_author_meta( 'user_provincie', $this->userid ));
} else {
$provincie = $this->hmpl_notspecified();
}
if ( !empty( get_the_author_meta( 'user_land', $this->userid ) ) ) {
$land = esc_attr(get_the_author_meta( 'user_land', $this->userid ));
} else {
$land = $this->hmpl_notspecified();
}
return array(
'straat' => $straat,
'postcode' => $postcode,
'plaats' => $plaats,
'provincie' => $provincie,
'land' => $land,
);
}
/**
* Returns boolean if company
*
* @requires: MU-Plugin useraddressmeta.php by Sybre Waaijer
* @else: return bool false
*
* @return bool hmpl_isbedrijf
*
* @duplicate of $this->hmpl_userbedrijfinfo['isbedrijf']
*/
public function hmpl_isbedrijf() {
if ( get_the_author_meta( 'user_isbedrijf', $this->userid ) == '1' ) {
$isbedrijf = true;
} else {
$isbedrijf = false;
}
return $isbedrijf;
}
/**
* Returns Array of User "Bedrijf" meta
*
* @requires: MU-Plugin useraddressmeta.php by Sybre Waaijer
* @else: return bool false, string NULL, string NULL, string NULL
*
* @return bool isbedrijf : User has checked "I'm working for as a company" in profile
* @return string bedrijf : Company Name
* @return string kvk : Company Security ID
* @return string btw : Tax number
*/
public function hmpl_userbedrijfinfo() {
if ( get_the_author_meta( 'user_isbedrijf', $this->userid ) == '1' ) {
$isbedrijf = true;
} else {
$isbedrijf = false;
}
$bedrijf = '';
$kvk = '';
$btw = '';
if ( $isbedrijf !== false) {
if ( !empty( get_the_author_meta( 'user_bedrijf', $this->userid ) ) ) {
$bedrijf = esc_attr(get_the_author_meta( 'user_bedrijf', $this->userid ));
} else {
$bedrijf = $this->hmpl_notspecified();
}
if ( !empty( get_the_author_meta( 'user_kvk', $this->userid ) ) ) {
$kvk = esc_attr(get_the_author_meta( 'user_kvk', $this->userid ));
} else {
$kvk = $this->hmpl_notspecified();
}
if ( !empty( get_the_author_meta( 'user_btw', $this->userid ) ) ) {
$btw = esc_attr(get_the_author_meta( 'user_btw', $this->userid ));
} else {
$btw = $this->hmpl_notspecified();
}
}
return array(
'isbedrijf' => $isbedrijf, //bool
'bedrijf' => $bedrijf, //str
'kvk' => $kvk, //str
'btw' => $btw, //str
);
}
/**
* Returns Array of Primary Blog values
*
* @param array $wpdb WordPress database
* @param array $psts Pro Sites
*
* @uses wp_cache : 14400
*
* @return bool useriseditor : user can edit posts
* @return int timezone : time zone in gmt offset
* @return string workdomainplain : work domain url
* @return string workdomaingoto : work domain html output
* @return string blogtitle : blog title of Primary blog
*
* @requires: Plugin Domain Mapping by WPMUDEV
*
* @return bool ismapped : domain is mapped
* @return string mappeddomainplain : mapped domain url
* @return string mappeddomaingoto : mapped domain html output
* @return string mainblogplain : either mapped or work domain plain
* @return string mainbloggoto : either mapped or work domain html output
*
* @requires: Plugin Pro Sites by WPMUDEV
*
* @return bool prositeactive : plugin active
* @return string levelname : name of pro site level
* @return time proexpire : pro site time expire in d F, Y
*/
public function hmpl_user_main_blog() {
global $psts,$wpdb;
$goto = 'Ga naar ';
$levelname = $this->hmpl_notavailable();
$mappeddomainplain = $this->hmpl_notavailable();
$mappeddomaingoto = $this->hmpl_notavailable();
$proexpire = $this->hmpl_notavailable();
$ismapped = false;
//* User is admin
// @Bool $useriseditor
$useriseditor = $this->useriseditor;
//* Time Zone of main blog, defaults to GMT+1 / UTC+1 (winter) / UTC+2 (summer)
$timezone = get_blog_option( $this->mainblog, 'gmt_offset' );
//* Blog Title of main blog, default
$blogtitle = get_blog_option( $this->mainblog, 'blogname' );
//* @string $workdomainplain
//* @string $workdomaingoto (html)
$workdomainpre = substr(get_blogaddress_by_id( $this->mainblog ), 7);
$workdomainplain = esc_url( 'https://' . $workdomainpre );
$workdomaingoto = sprintf( '%s', trailingslashit($workdomainplain), esc_attr($goto), trailingslashit(esc_attr($workdomainplain)), $workdomainplain );
//* @bool $prositeactive
if ( is_plugin_active( 'pro-sites/pro-sites.php' )) {
$prositeactive = true;
} else {
$prositesactive = false;
}
//* If plugin is active, else return not available for almost all values
if ( $prositeactive == true ) {
//* Level of main blog
$levelnamepre = $psts->get_level_setting( $psts->get_level( $this->mainblog ), 'name' );
if (!empty($levelnamepre) && $useriseditor !== false) {
$levelname = $levelnamepre;
} else {
$levelname = $this->hmpl_notavailable();
}
//* Mapped domain url + plain
$mappeddomainpre = wp_cache_get('hmpl_mappeddomainpre_' . $this->mainblog, 'hmpl_mainblog' );
if ( false === $mappeddomainpre ) {
$mappeddomainpre = $wpdb->get_var($wpdb->prepare("SELECT domain FROM {$wpdb->base_prefix}domain_mapping WHERE blog_id = %d", $this->mainblog));
wp_cache_set('hmpl_mappeddomainpre_' . $this->mainblog, $mappeddomainpre, 'hmpl_mainblog', 14400 );
}
if (!empty($mappeddomainpre)) {
$mappeddomain = $mappeddomainpre;
$mappeddomainplain = esc_url($mappeddomain);
$mappeddomaingoto = sprintf( '%s', trailingslashit($mappeddomainplain), esc_attr($goto), trailingslashit(esc_attr($mappeddomainplain)), $mappeddomainplain );
$ismapped = true;
$mainblogplain = $mappeddomainplain;
} else {
$mappeddomainplain = $this->hmpl_notspecified();
$mappeddomaingoto = $this->hmpl_notspecified();
$ismapped = false;
$mainblogplain = $workdomainplain;
}
//* Either mapped or work domain, depends on !empty(mappeddomainpre) bool
$mainbloggoto = sprintf( '%s', trailingslashit($mainblogplain), esc_attr($goto), trailingslashit(esc_attr($mainblogplain)), $mainblogplain );
//* Expire date Pro level
$protimesql = wp_cache_get('hmpl_pro_time_sql_' . $this->mainblog, 'hmpl_mainblog' );
if ( false === $protimesql ) {
$protimesql = $wpdb->get_var($wpdb->prepare("SELECT expire FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = %d", $this->mainblog));
wp_cache_set( 'hmpl_pro_time_sql_' . $this->mainblog, $protimesql, 'hmpl_mainblog', 14400 );
}
if ($protimesql == 9999999999 ) {
$proexpire = 'Onbepaald';
} else {
$proexpire = date_i18n('d F, Y', $protimesql);
}
}
return array(
'useriseditor' => $useriseditor, // bool
'ismapped' => $ismapped, //bool
'timezone' => $timezone, //int
'workdomain' => $workdomainplain, //str
'workdomaingoto' => $workdomaingoto, //str (html)
'proactive' => $prositeactive, //bool
'prolevel' => $levelname, //str
'proexpire' => $proexpire, //time
'mappeddomain' => $mappeddomainplain, //str
'mappeddomaingoto' => $mappeddomaingoto, //str (html)
'blogtitle' => $blogtitle, //str
'mainblogplain' => $mainblogplain, //str
'mainbloggoto' => $mainbloggoto, //str
);
}
}