PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.16
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.16
1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 All 172 releases
userswp / widgets / user-meta.php

user-meta.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.16, at widgets/user-meta.php

213 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 /**
7 * UsersWP user meta widget.
8 *
9 * @since 1.1.2
10 */
11 class UWP_User_Meta_Widget extends WP_Super_Duper {
12
13 /**
14 * Register the profile user title widget with WordPress.
15 *
16 */
17 public function __construct() {
18
19
20 $options = array(
21 'textdomain' => 'userswp',
22 'block-icon' => 'admin-site',
23 'block-category'=> 'widgets',
24 'block-keywords'=> "['userswp','usermeta']",
25 'class_name' => __CLASS__,
26 'base_id' => 'uwp_user_meta',
27 'name' => __('UWP > User Meta','userswp'),
28 'no_wrap' => true,
29 'widget_ops' => array(
30 'classname' => 'uwp-user-meta',
31 'description' => esc_html__('Displays user meta.','userswp'),
32 ),
33 'arguments' => array(
34 'key' => array(
35 'title' => __('Key:', 'userswp'),
36 'desc' => __('This is the custom field key.', 'userswp'),
37 'type' => 'select',
38 'options' => $this->get_custom_field_keys(),
39 'desc_tip' => true,
40 'default' => '',
41 'advanced' => false
42 ),
43 'user_id' => array(
44 'title' => __('User ID:', 'userswp'),
45 'desc' => __('Leave blank to use current user ID or use post_author for current post author ID. For profile page it will take displayed user ID. Input specific user ID for other pages.', 'userswp'),
46 'type' => 'text',
47 'desc_tip' => true,
48 'default' => '',
49 'advanced' => true
50 ),
51 'show' => array(
52 'title' => __('Show:', 'userswp'),
53 'desc' => __('What part of the post meta to show.', 'userswp'),
54 'type' => 'select',
55 'options' => array(
56 "" => __('Icon + Label + Value', 'userswp'),
57 "icon-value" => __('Icon + Value', 'userswp'),
58 "label-value" => __('Label + Value', 'userswp'),
59 "label" => __('Label', 'userswp'),
60 "value" => __('Value', 'userswp'),
61 "value-strip" => __('Value (strip_tags)', 'userswp'),
62 ),
63 'default' => '',
64 'desc_tip' => true,
65 'advanced' => true
66 ),
67 'css_class' => array(
68 'type' => 'text',
69 'title' => __('Extra class:', 'userswp'),
70 'desc' => __('Give the wrapper an extra class so you can style things as you want.', 'userswp'),
71 'placeholder' => '',
72 'default' => '',
73 'desc_tip' => true,
74 'advanced' => true,
75 ),
76 )
77
78 );
79
80
81 parent::__construct( $options );
82 }
83
84 /**
85 * Gets an array of custom field keys.
86 *
87 * @return array
88 */
89 public function get_custom_field_keys(){
90 global $wpdb;
91 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
92 $fields = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE form_type = 'account' ORDER BY sort_order ASC");
93
94 $keys = array();
95 $keys[] = __('Select Key','userswp');
96 if(!empty($fields)){
97 foreach($fields as $field){
98 $keys[ $field->htmlvar_name ] = $field->htmlvar_name . ' ( ' . __( $field->site_title, 'userswp' ) . ' )';
99 }
100 }
101
102 return apply_filters( 'uwp_meta_field_keys', $keys );
103
104 }
105
106 /**
107 * The Super block output function.
108 *
109 * @param array $args
110 * @param array $widget_args
111 * @param string $content
112 *
113 * @return mixed|string|bool
114 */
115 public function output( $args = array(), $widget_args = array(), $content = '' ) {
116
117 global $wpdb, $post;
118 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
119
120 $defaults = array(
121 'user_id' => '',
122 'key' => '',
123 'show' => '',
124 'css_class' => '',
125 );
126
127 $args = wp_parse_args( $args, $defaults );
128
129 $args = apply_filters( 'uwp_widget_user_meta_args', $args, $widget_args, $this );
130
131 if(isset($args['user_id']) && !empty($args['user_id'])){
132 if('post_author' == $args['user_id'] && $post instanceof WP_Post){
133 $user = get_userdata($post->post_author);
134 } else {
135 $user = get_userdata((int)$args['user_id']);
136 }
137 } else {
138 $user = uwp_get_displayed_user();
139 }
140
141 if(empty($args['key']) || empty($user)){
142 return '';
143 }
144
145 $key = str_replace('uwp_account_', '', $args['key']);
146 $form_id = uwp_get_register_form_id( $user->ID );
147 $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND htmlvar_name = %s AND form_id = %d", $key, $form_id));
148
149 if(!$fields){
150 return '';
151 }
152
153 $field = $fields[0];
154 $value = $output = $label = '';
155
156 if ($field->field_icon != '') {
157 $icon = uwp_get_field_icon($field->field_icon);
158 } else {
159 $field_icon = uwp_field_type_to_fa_icon($field->field_type);
160 if ($field_icon) {
161 $icon = '<i class="'.$field_icon.'"></i>';
162 } else {
163 $icon = '<i class="fas fa-user"></i>';
164 }
165 }
166
167 if(!empty($args['css_class']) && isset($field->css_class)){
168 $css_class = $field->css_class ." ". $args['css_class'];
169 } else {
170 $css_class = $args['css_class'];
171 }
172
173 $privacy = uwp_get_usermeta($user->ID, $key.'_privacy');
174
175 if (isset($privacy) && 'no' == $privacy) {
176 return $value;
177 }
178
179 $obj = new UsersWP_Profile();
180 $value = $obj->get_field_value($field, $user);
181
182 if(!$value){
183 return;
184 }
185
186 switch ($args['show']){
187 case 'icon-value':
188 $output = $icon.$value;
189 break;
190 case 'label-value':
191 $output = '<div class="uwp-user-meta-key">'. $field->site_title . '<span class="uwp-profile-extra-sep">:</span></div><div class="uwp-user-meta-value">'.$value.'</div>';
192 break;
193 case 'label':
194 return $field->site_title;
195 break;
196 case 'value':
197 return $value;
198 break;
199 case 'value-strip':
200 $output = '<div class="uwp-user-meta-value">'.strip_tags($value).'</div>';
201 break;
202 default:
203 $output = '<div class="uwp-user-meta-key">'. $icon . $field->site_title . '<span class="uwp-profile-extra-sep">:</span></div><div class="uwp-user-meta-value">'. $value. '</div>';
204 }
205
206 //wrap output in a div
207 $output = '<div class="uwp-user-meta-wrap '.$css_class.'">'.$output.'</div>';
208
209 return $output;
210
211 }
212
213 }