PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.73
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.73
1.2.73 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 All 173 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.73, at widgets/user-meta.php

216 lines 7.3 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 . ' ( ' . __( stripslashes( $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 global $wpdb, $post;
117
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 $user = array();
131
132 if ( ! empty( $args['user_id'] ) ) {
133 if ( 'post_author' == $args['user_id'] ) {
134 if ( ! empty( $post ) && is_object( $post ) && ! empty( $post->post_author ) ) {
135 $user = get_userdata( (int) $post->post_author );
136 }
137 } else {
138 $user = get_userdata( (int) $args['user_id'] );
139 }
140 } else {
141 $user = uwp_get_displayed_user();
142 }
143
144 if ( empty( $args['key'] ) || empty( $user ) ) {
145 return '';
146 }
147
148 $key = str_replace('uwp_account_', '', $args['key']);
149 $form_id = uwp_get_register_form_id( $user->ID );
150 $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));
151
152 if(!$fields){
153 return '';
154 }
155
156 $field = $fields[0];
157 $value = $output = $label = '';
158
159 if ($field->field_icon != '') {
160 $icon = uwp_get_field_icon($field->field_icon);
161 } else {
162 $field_icon = uwp_field_type_to_fa_icon($field->field_type);
163 if ($field_icon) {
164 $icon = '<i class="'.$field_icon.'"></i>';
165 } else {
166 $icon = '<i class="fas fa-user"></i>';
167 }
168 }
169
170 if(!empty($args['css_class']) && isset($field->css_class)){
171 $css_class = $field->css_class ." ". $args['css_class'];
172 } else {
173 $css_class = $args['css_class'];
174 }
175
176 $privacy = uwp_get_usermeta($user->ID, $key.'_privacy');
177
178 if (isset($privacy) && 'no' == $privacy) {
179 return $value;
180 }
181
182 $obj = new UsersWP_Profile();
183 $value = $obj->get_field_value($field, $user);
184
185 if(!$value){
186 return;
187 }
188
189 switch ($args['show']){
190 case 'icon-value':
191 $output = $icon.$value;
192 break;
193 case 'label-value':
194 $output = '<div class="uwp-user-meta-key">'. __( stripslashes( $field->site_title ), 'userswp' ) . '<span class="uwp-profile-extra-sep">:</span></div><div class="uwp-user-meta-value">'.$value.'</div>';
195 break;
196 case 'label':
197 return $field->site_title;
198 break;
199 case 'value':
200 return $value;
201 break;
202 case 'value-strip':
203 $output = '<div class="uwp-user-meta-value">'.strip_tags($value).'</div>';
204 break;
205 default:
206 $output = '<div class="uwp-user-meta-key">'. $icon . __( stripslashes( $field->site_title ), 'userswp' ) . '<span class="uwp-profile-extra-sep">:</span></div><div class="uwp-user-meta-value">'. $value. '</div>';
207 }
208
209 //wrap output in a div
210 $output = '<div class="uwp-user-meta-wrap '.$css_class.'">'.$output.'</div>';
211
212 return $output;
213
214 }
215
216 }