Advertisement
verygoodplugins

Untitled

Mar 6th, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. public function shortcode_user_meta_date( $atts, $content = null ) {
  2.  
  3.     $atts = shortcode_atts( array('field' => ''), $atts );
  4.  
  5.     if(empty($atts['field']))
  6.         return;
  7.  
  8.     if(!is_user_logged_in()) {
  9.         return do_shortcode($content);
  10.     }
  11.  
  12.     $user_data = get_userdata( get_current_user_id() );
  13.  
  14.     if( is_object($user_data) && property_exists( $user_data->data, $atts['field'] ) ) {
  15.  
  16.         $value = $user_data->data->{$atts['field']};
  17.  
  18.     } else {
  19.  
  20.         $value = get_user_meta( get_current_user_id(), $atts['field'], true );
  21.  
  22.     }
  23.  
  24.     if(empty($value)) {
  25.         return do_shortcode($content);
  26.     } else {
  27.  
  28.         if( is_numeric( $value ) ) {
  29.  
  30.             $value = date('F j, Y', $value);
  31.  
  32.         }
  33.  
  34.         return $value;
  35.  
  36.     }
  37.  
  38. }
  39.  
  40. add_shortcode( 'user_meta_date', 'shortcode_user_meta_date' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement