| @@ -61,89 +61,53 @@ | ||
| 61 | 61 | * @param array|bool $post_ids Post ids for post__in. Optional |
| 62 | 62 | * |
| 63 | 63 | * @return void |
| 64 | 64 | */ |
| 65 | -function uwp_generic_tab_content($user, $post_type = false, $title, $post_ids = false) { | |
| 66 | - ?> | |
| 67 | - <h3><?php echo $title; ?></h3> | |
| 68 | - <div class="uwp-profile-item-block"> | |
| 69 | - <?php | |
| 70 | - $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; | |
| 65 | +function uwp_generic_tab_content($user, $post_type = false, $title = '', $post_ids = false) { | |
| 71 | 66 | |
| 72 | - $args = array( | |
| 73 | - 'post_status' => 'publish', | |
| 74 | - 'posts_per_page' => uwp_get_option('profile_no_of_items', 10), | |
| 75 | - 'author' => $user->ID, | |
| 76 | - 'paged' => $paged, | |
| 77 | - ); | |
| 67 | + $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; | |
| 78 | 68 | |
| 79 | - if ($post_type) { | |
| 80 | - $args['post_type'] = $post_type; | |
| 81 | - } | |
| 69 | + $query_args = array( | |
| 70 | + 'post_status' => 'publish', | |
| 71 | + 'posts_per_page' => uwp_get_option('profile_no_of_items', 10), | |
| 72 | + 'author' => $user->ID, | |
| 73 | + 'paged' => $paged, | |
| 74 | + ); | |
| 82 | 75 | |
| 83 | - if (is_array($post_ids)) { | |
| 84 | - if (!empty($post_ids)) { | |
| 85 | - $args['post__in'] = $post_ids; | |
| 86 | - } else { | |
| 87 | - // no posts found | |
| 88 | - echo "<p>".__('No '.$title.' Found', 'userswp')."</p>"; | |
| 89 | - return; | |
| 90 | - } | |
| 91 | - } | |
| 92 | - // The Query | |
| 93 | - $the_query = new WP_Query($args); | |
| 76 | + if ($post_type) { | |
| 77 | + $query_args['post_type'] = $post_type; | |
| 78 | + } | |
| 94 | 79 | |
| 95 | - // The Loop | |
| 96 | - if ($the_query->have_posts()) { | |
| 97 | - echo '<ul class="uwp-profile-item-ul">'; | |
| 98 | - while ($the_query->have_posts()) { | |
| 99 | - $the_query->the_post(); | |
| 100 | - ?> | |
| 101 | - <li class="uwp-profile-item-li uwp-profile-item-clearfix"> | |
| 102 | - <div class="uwp_generic_thumb_wrap"> | |
| 103 | - <a class="uwp-profile-item-img" href="<?php echo get_the_permalink(); ?>"> | |
| 104 | - <?php | |
| 105 | - if ( has_post_thumbnail() ) { | |
| 106 | - $thumb_url = get_the_post_thumbnail_url(get_the_ID(), array(80, 80)); | |
| 107 | - } else { | |
| 108 | - $thumb_url = USERSWP_PLUGIN_URL."/public/assets/images/no_thumb.png"; | |
| 109 | - } | |
| 110 | - ?> | |
| 111 | - <img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo $thumb_url; ?>"> | |
| 112 | - </a> | |
| 113 | - </div> | |
| 80 | + if (is_array($post_ids)) { | |
| 81 | + if (!empty($post_ids)) { | |
| 82 | + $query_args['post__in'] = $post_ids; | |
| 83 | + } else { | |
| 84 | + // no posts found | |
| 85 | + echo aui()->alert( array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 86 | + 'type'=>'info', | |
| 87 | + 'content'=> esc_html( wp_sprintf( __( 'No %s found', 'userswp' ), strtolower( $title ) ) ) | |
| 88 | + ) ); | |
| 114 | 89 | |
| 115 | - <h3 class="uwp-profile-item-title"> | |
| 116 | - <a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a> | |
| 117 | - </h3> | |
| 118 | - <time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>"> | |
| 119 | - <?php echo get_the_date(); ?> | |
| 120 | - </time> | |
| 121 | - <div class="uwp-profile-item-summary"> | |
| 122 | - <?php | |
| 123 | - $excerpt = strip_shortcodes(wp_trim_words( get_the_excerpt(), 15, '...' )); | |
| 124 | - echo $excerpt; | |
| 125 | - if ($excerpt) { | |
| 126 | - ?> | |
| 127 | - <a href="<?php echo get_the_permalink(); ?>" class="more-link"><?php echo __( 'Read More »', 'userswp' ); ?></a> | |
| 128 | - <?php | |
| 129 | - } | |
| 130 | - ?> | |
| 131 | - </div> | |
| 132 | - </li> | |
| 133 | - <?php | |
| 134 | - } | |
| 135 | - echo '</ul>'; | |
| 136 | - /* Restore original Post Data */ | |
| 137 | - wp_reset_postdata(); | |
| 138 | - } else { | |
| 139 | - // no posts found | |
| 140 | - echo "<p>".__('No '.$title.' Found', 'userswp')."</p>"; | |
| 141 | - } | |
| 142 | - do_action('uwp_profile_pagination', $the_query->max_num_pages); | |
| 143 | - ?> | |
| 144 | - </div> | |
| 145 | - <?php | |
| 90 | + return; | |
| 91 | + } | |
| 92 | + } | |
| 93 | + | |
| 94 | + // The Query | |
| 95 | + $the_query = new WP_Query($query_args); | |
| 96 | + | |
| 97 | + $args = array(); | |
| 98 | + $args['template_args']= array( | |
| 99 | + 'the_query' => $the_query, | |
| 100 | + 'user' => $user, | |
| 101 | + 'post_type' => $post_type, | |
| 102 | + 'title' => $title, | |
| 103 | + 'post_ids' => $post_ids, | |
| 104 | + ); | |
| 105 | + | |
| 106 | + $design_style = !empty($args['design_style']) ? esc_attr($args['design_style']) : uwp_get_option("design_style",'bootstrap'); | |
| 107 | + $template = $design_style ? $design_style."/loop-posts.php" : "loop-posts.php"; | |
| 108 | + uwp_get_template($template, $args); | |
| 109 | + | |
| 146 | 110 | } |
| 147 | 111 | |
| 148 | 112 | |
| 149 | 113 | /** |
| @@ -155,71 +119,84 @@ | ||
| 155 | 119 | * @return array Account Tabs. |
| 156 | 120 | */ |
| 157 | 121 | function uwp_account_get_available_tabs() { |
| 158 | 122 | |
| 159 | - $tabs = array(); | |
| 160 | - $type = 'account'; | |
| 161 | - if (isset($_GET['type'])) { | |
| 162 | - $type = strip_tags(esc_sql($_GET['type'])); | |
| 163 | - } | |
| 164 | - | |
| 165 | - if('account' != $type){ | |
| 166 | - $tabs['account'] = array( | |
| 123 | + $tabs = array( | |
| 124 | + 'account' => array( | |
| 167 | 125 | 'title' => __( 'Edit Account', 'userswp' ), |
| 168 | 126 | 'icon' => 'fas fa-user', |
| 169 | - ); | |
| 170 | - } | |
| 127 | + ), | |
| 128 | + 'change-password' => array( | |
| 129 | + 'title' => __( 'Change Password', 'userswp' ), | |
| 130 | + 'icon' => 'fas fa-asterisk', | |
| 131 | + ), | |
| 132 | + 'notifications' => array( | |
| 133 | + 'title' => __( 'Notifications', 'userswp' ), | |
| 134 | + 'icon' => 'fas fa-envelope', | |
| 135 | + ), | |
| 136 | + 'privacy' => array( | |
| 137 | + 'title' => __('Privacy', 'userswp'), | |
| 138 | + 'icon' => 'fas fa-lock', | |
| 139 | + ), | |
| 140 | + ); | |
| 171 | 141 | |
| 172 | - if('notifications' != $type){ | |
| 173 | - $tabs['notifications'] = array( | |
| 174 | - 'title' => __( 'Notifications', 'userswp' ), | |
| 175 | - 'icon' => 'fas fa-bell', | |
| 176 | - ); | |
| 177 | - } | |
| 142 | + $tabs = apply_filters( 'uwp_account_available_tabs', $tabs ); | |
| 178 | 143 | |
| 179 | - if('privacy' != $type) { | |
| 180 | - $tabs['privacy'] = array( | |
| 181 | - 'title' => __('Privacy', 'userswp'), | |
| 182 | - 'icon' => 'fas fa-lock', | |
| 183 | - ); | |
| 184 | - } | |
| 144 | + if(class_exists('\WP2FA\WP2FA')){ | |
| 145 | + if(1 != uwp_get_option('disable_wp_2fa')) { | |
| 146 | + $tabs['wp2fa'] = array( | |
| 147 | + 'title' => __( 'WP - 2FA', 'userswp' ), | |
| 148 | + 'icon' => 'fas fa-user-lock', | |
| 149 | + ); | |
| 150 | + } | |
| 151 | + } | |
| 185 | 152 | |
| 186 | - return apply_filters( 'uwp_account_available_tabs', $tabs ); | |
| 153 | + // Keep delete account and logout last | |
| 154 | + if(1 != uwp_get_option('disable_account_delete') && !current_user_can('administrator')){ | |
| 155 | + $tabs['delete-account'] = array( | |
| 156 | + 'title' => __('Delete Account', 'userswp'), | |
| 157 | + 'icon' => 'fas fa-user-times', | |
| 158 | + ); | |
| 159 | + } | |
| 160 | + | |
| 161 | + $template = new UsersWP_Templates(); | |
| 162 | + $logout_url = $template->uwp_logout_url(); | |
| 163 | + | |
| 164 | + $tabs['logout'] = array( | |
| 165 | + 'title' => __('Logout', 'userswp'), | |
| 166 | + 'icon' => 'fas fa-sign-out-alt', | |
| 167 | + 'link' => $logout_url, | |
| 168 | + ); | |
| 169 | + | |
| 170 | + return apply_filters( 'uwp_account_all_tabs', $tabs ); | |
| 187 | 171 | } |
| 188 | 172 | |
| 189 | -/** | |
| 190 | - * Returns the setting page tab list for each page. | |
| 191 | - * | |
| 192 | - * @since 1.0.0 | |
| 193 | - * @package userswp | |
| 194 | - * | |
| 195 | - * @return array Tabs list. | |
| 196 | - */ | |
| 197 | -function uwp_get_settings_tabs() { | |
| 173 | +function uwp_profile_add_tabs($tab_data){ | |
| 198 | 174 | |
| 199 | - $tabs = array(); | |
| 175 | + $obj = new UsersWP_Settings_Profile_Tabs(); | |
| 176 | + $obj->tabs_field_save($tab_data); | |
| 200 | 177 | |
| 201 | - // wp-admin/admin.php?page=uwp | |
| 202 | - $tabs['userswp'] = array( | |
| 203 | - 'main' => __( 'General', 'userswp' ), | |
| 204 | - 'register' => __( 'Register', 'userswp' ), | |
| 205 | - 'login' => __( 'Login', 'userswp' ), | |
| 206 | - 'change' => __( 'Change Password', 'userswp' ), | |
| 207 | - 'profile' => __( 'Profile', 'userswp' ), | |
| 208 | - 'users' => __( 'Users', 'userswp' ), | |
| 209 | - 'import-export' => __( 'Import/Export', 'userswp' ), | |
| 210 | - 'uninstall' => __( 'Uninstall', 'userswp' ), | |
| 211 | - ); | |
| 178 | +} | |
| 212 | 179 | |
| 213 | - // wp-admin/admin.php?page=uwp_form_builder | |
| 214 | - $tabs['uwp_form_builder'] = array( | |
| 215 | - 'main' => __( 'Form Builder', 'userswp' ), | |
| 216 | - ); | |
| 180 | +function uwp_get_tabs_privacy_by_user($user){ | |
| 181 | + global $wpdb; | |
| 217 | 182 | |
| 218 | - // wp-admin/admin.php?page=uwp_notifications | |
| 219 | - $tabs['uwp_notifications'] = array( | |
| 220 | - 'main' => __( 'Users', 'userswp' ), | |
| 221 | - 'admin' => __( 'Admin', 'userswp' ) | |
| 222 | - ); | |
| 183 | + if(is_integer($user)){ | |
| 184 | + $user = get_userdata($user); | |
| 185 | + } | |
| 223 | 186 | |
| 224 | - return apply_filters( 'uwp_settings_tabs', $tabs ); | |
| 187 | + $tabs_privacy = array(); | |
| 188 | + $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta'; | |
| 189 | + $obj_key = $user->ID.'_tabs_privacy'; | |
| 190 | + $user_meta_info = wp_cache_get( $obj_key, 'uwp_usermeta_tabs_privacy' ); | |
| 191 | + | |
| 192 | + if ( ! $user_meta_info ) { | |
| 193 | + $user_meta_info = $wpdb->get_row($wpdb->prepare("SELECT tabs_privacy FROM {$meta_table} WHERE user_id = %d", $user->ID), ARRAY_A); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery | |
| 194 | + wp_cache_set( $obj_key, $user_meta_info, 'uwp_usermeta_tabs_privacy' ); | |
| 195 | + } | |
| 196 | + | |
| 197 | + if(isset($user_meta_info['tabs_privacy']) && !empty($user_meta_info['tabs_privacy'])){ | |
| 198 | + $tabs_privacy = maybe_unserialize($user_meta_info['tabs_privacy']); | |
| 199 | + } | |
| 200 | + | |
| 201 | + return $tabs_privacy; | |
| 225 | 202 | } |