pmpro_member_shortcode

Shortcode to show a specific user field for current user or specified user ID.

Description

pmpro_member_shortcode( $atts, (constant) $content = null, (string) $code = '' ); 

Parameters (3)

0. $atts
The atts.
1. $content — Optional. (constant) => null
The content.
2. $code — Optional. (string) => ''
The code.

Usage

  1. if ( !function_exists( 'pmpro_member_shortcode' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/shortcodes/pmpro_member.php'; 
  3.  
  4. // The atts. 
  5. $atts = null; 
  6.  
  7. // The content. 
  8. $content = null; 
  9.  
  10. // The code. 
  11. $code = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = pmpro_member_shortcode($atts, $content, $code); 
  15.  

Defined (1)

The function is defined in the following location(s).

/shortcodes/pmpro_member.php  
  1. function pmpro_member_shortcode($atts, $content=null, $code='') 
  2. // $atts ::= array of attributes 
  3. // $content ::= text within enclosing form of shortcode element 
  4. // $code ::= the shortcode found, when == callback name 
  5. // examples: [pmpro_member field='last_name'] 
  6. global $current_user; 
  7.  
  8. extract(shortcode_atts(array( 
  9. 'user_id' => $current_user->ID,  
  10. 'field' => NULL 
  11. ), $atts)); 
  12.  
  13. /** 
  14. -  
  15. */ 
  16.  
  17. //membership level fields 
  18. $pmpro_level_fields = array( 
  19. 'membership_id',  
  20. 'membership_name',  
  21. 'membership_code_id',  
  22. 'membership_code',  
  23. 'membership_initial_payment',  
  24. 'membership_billing_amount',  
  25. 'membership_cycle_number',  
  26. 'membership_cycle_period',  
  27. 'membership_billing_limit',  
  28. 'membership_trial_amount',  
  29. 'membership_trial_limit',  
  30. 'membership_startdate',  
  31. 'membership_enddate',  
  32. ); 
  33.  
  34. //pmpro-related fields stored in user meta 
  35. $pmpro_user_meta_fields = array( 
  36. 'bfirstname',  
  37. 'blastname',  
  38. 'baddress1',  
  39. 'baddress2',  
  40. 'bcity',  
  41. 'bstate',  
  42. 'bzipcode',  
  43. 'bcountry',  
  44. 'bphone',  
  45. 'bemail',  
  46. 'CardType',  
  47. 'AccountNumber',  
  48. 'ExpirationMonth',  
  49. 'ExpirationYear',  
  50. ); 
  51.  
  52. //fields stored in wp_users column 
  53. $user_column_fields = array( 
  54. 'user_login',  
  55. 'user_email',  
  56. 'user_url',  
  57. 'user_registered',  
  58. 'display_name',  
  59. ); 
  60.  
  61. //date fields 
  62. $date_fields = array( 
  63. 'startdate',  
  64. 'enddate',  
  65. 'modified',  
  66. 'user_registered',  
  67. 'next_payment_date',  
  68. ); 
  69.  
  70. //price fields 
  71. $price_fields = array( 
  72. 'initial_payment',  
  73. 'billing_amount',  
  74. 'trial_amount',  
  75. ); 
  76.  
  77. if($field == 'level_cost') { 
  78. $membership_level = pmpro_getMembershipLevelForUser($user_id); 
  79. if( !empty($membership_level ) ) 
  80. $r = pmpro_getLevelCost($membership_level, false, true); 
  81. else 
  82. $r = ''; 
  83. } elseif($field == 'next_payment_date') { 
  84. //next_payment_date 
  85. $r = pmpro_next_payment($user_id); 
  86. } elseif(in_array( $field, $pmpro_level_fields )) { 
  87. //membership level fields 
  88. $field = str_replace('membership_', '', $field); 
  89. $membership_level = pmpro_getMembershipLevelForUser($user_id); 
  90. if(!empty($membership_level)) 
  91. $r = $membership_level->$field; 
  92. else 
  93. $r = ''; 
  94. } elseif(in_array( $field, $pmpro_user_meta_fields )) { 
  95. //pmpro-related fields stored in user meta 
  96. $field = 'pmpro_' . $field; 
  97. $r = get_user_meta($user_id, $field, true); 
  98. } elseif(in_array( $field, $user_column_fields )) { 
  99. //wp_users column 
  100. $user = get_userdata($user_id); 
  101. $r = $user->$field; 
  102. } else { 
  103. //assume user meta 
  104. $r = get_user_meta($user_id, $field, true); 
  105.  
  106. //Check for dates to reformat them. 
  107. if(in_array( $field, $date_fields )) { 
  108. if(empty($r) || $r == '0000-00-00 00:00:00') 
  109. $r = ''; 
  110. elseif(is_numeric($r)) 
  111. $r = date_i18n(get_option('date_format'), $r); //timestamp 
  112. else 
  113. $r = date_i18n(get_option('date_format'), strtotime($r, current_time('timestamp'))); //YYYY-MM-DD/etc format 
  114.  
  115. //Check for prices to reformat them. 
  116. if(in_array( $field, $price_fields )) { 
  117. if(empty($r) || $r == '0.00') 
  118. $r = ''; 
  119. else 
  120. $r = pmpro_formatPrice($r); 
  121.  
  122. /**  
  123. * Filter 
  124. */ 
  125. $r = apply_filters('pmpro_member_shortcode_field', $r, $user_id, $field); 
  126.  
  127. return $r;