PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.46
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.46
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 / button-group.php

button-group.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.46, at widgets/button-group.php

158 lines 5.4 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 Button_Group widget.
8 *
9 * @since 1.2.0
10 */
11 class UWP_Button_Group_Widget extends WP_Super_Duper {
12
13 /**
14 * Register the profile social 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','button']",
25 'class_name' => __CLASS__,
26 'base_id' => 'uwp_button_group',
27 'name' => __('UWP > Button Group','userswp'),
28 'widget_ops' => array(
29 'classname' => 'uwp-button-group bsui',
30 'description' => esc_html__('Displays a group of buttons from the custom fields.','userswp'),
31 ),
32 'arguments' => array(
33 'fields' => array(
34 'title' => __( 'Fields', 'userswp' ),
35 'desc' => __( 'Enter a comma separated list of field keys. (leave empty for default social fields)', 'userswp' ),
36 'placeholder' => 'facebook,twitter,instagram,linkedin,flickr,github,youtube,wordpress,tiktok,user_url',
37 'type' => 'text',
38 'desc_tip' => true,
39 'default' => '',
40 'advanced' => false
41 ),
42 'user_id' => array(
43 'title' => __('User ID:', 'userswp'),
44 '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'),
45 'type' => 'text',
46 'desc_tip' => true,
47 'default' => '',
48 'advanced' => true
49 ),
50 'css_class' => array(
51 'type' => 'text',
52 'title' => __('Extra class:', 'userswp'),
53 'desc' => __('Give the wrapper an extra class so you can style things as you want.', 'userswp'),
54 'placeholder' => 'btn-sm btn-circle',
55 'default' => '',
56 'desc_tip' => true,
57 'advanced' => true,
58 ),
59 )
60
61 );
62
63
64 parent::__construct( $options );
65 }
66
67 /**
68 * The Super block output function.
69 *
70 * @param array $args
71 * @param array $widget_args
72 * @param string $content
73 *
74 * @return mixed|string|bool
75 */
76 public function output( $args = array(), $widget_args = array(), $content = '' ) {
77
78 global $wpdb, $post;
79
80 if('post_author' == $args['user_id'] && $post instanceof WP_Post){
81 $user = get_userdata($post->post_author);
82 $args['user_id'] = $post->post_author;
83 } else if(isset($args['user_id']) && (int)$args['user_id'] > 0){
84 $user = get_userdata($args['user_id']);
85 } else {
86 $user = uwp_get_displayed_user();
87 }
88
89 if(empty($args['user_id']) && !empty($user->ID)){
90 $args['user_id'] = $user->ID;
91 }
92
93 if(empty($user)){
94 return '';
95 }
96
97 $defaults = array(
98 'fields' => 'facebook,twitter,instagram,linkedin,flickr,github,youtube,wordpress,tiktok,user_url',
99 'css_class' => 'btn-sm btn-circle'
100 );
101
102 $args = wp_parse_args( $args, $defaults );
103
104 if(empty($args['fields'])){$args['fields'] = $defaults['fields'];}
105 if(empty($args['css_class'])){$args['css_class'] = $defaults['css_class'];}
106
107 $args = apply_filters( 'uwp_widget_button_group_args', $args, $widget_args, $this );
108
109 // prepare the field names
110 $fields = explode(",",$args['fields']);
111 $fields = array_map('trim',$fields);
112 $prepare_fields = implode(",",array_fill(0, count($fields), '%s'));
113
114 // get the field settings
115 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
116 $db_fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE ( form_type = 'register' OR form_type = 'account' ) AND field_type = 'url' AND htmlvar_name IN($prepare_fields)",$fields));
117 $field_info = array();
118 if(!empty($db_fields)){
119 foreach($db_fields as $db_field){
120 $field_info[$db_field->htmlvar_name] = $db_field;
121 }
122 }
123
124 // get the user meta
125 $user_meta = uwp_get_usermeta_row($user->ID);
126 $privacy = isset( $user_meta ) && ! empty( $user_meta->user_privacy ) ? explode( ',', $user_meta->user_privacy ) : array();
127
128 $buttons = array();
129 foreach($fields as $field){
130 if(!empty($user_meta->{$field}) && isset($field_info[$field]) && ! in_array( $field . '_privacy', $privacy )){
131 $buttons[$field] = $field_info[$field];
132 $buttons[$field]->url = esc_url($user_meta->{$field});
133 }
134 }
135
136 // set the button global or die
137 if(empty($buttons)){
138 return '';
139 }else{
140 $args['buttons'] = $buttons;
141 }
142
143 $design_style = !empty($args['design_style']) ? esc_attr($args['design_style']) : uwp_get_option("design_style",'bootstrap');
144 $template = $design_style ? $design_style."/button-group.php" : "";
145
146 ob_start();
147
148 if($template){
149 uwp_get_template($template, $args);
150 }
151
152 $output = ob_get_clean();
153
154 return $output;
155
156 }
157
158 }