| 1 |
<?php |
| 2 |
/** |
| 3 |
* The WP_Members Shortcodes Class. |
| 4 |
* |
| 5 |
* This class contains functions |
| 6 |
* for the shortcodes used by the plugin. |
| 7 |
* |
| 8 |
* This file is part of the WP-Members plugin by Chad Butler |
| 9 |
* You can find out more about this plugin at https://rocketgeek.com |
| 10 |
* Copyright (c) 2006-2026 Chad Butler |
| 11 |
* WP-Members(tm) is a trademark of butlerblog.com |
| 12 |
* |
| 13 |
* @package WP-Members |
| 14 |
* @subpackage WP_Members_Shortcodes |
| 15 |
* @author Chad Butler |
| 16 |
* @copyright 2006-2026 |
| 17 |
*/ |
| 18 |
|
| 19 |
// Exit if accessed directly. |
| 20 |
if ( ! defined( 'ABSPATH' ) ) { |
| 21 |
exit(); |
| 22 |
} |
| 23 |
|
| 24 |
class WP_Members_Shortcodes { |
| 25 |
|
| 26 |
public $enable_field = 0; |
| 27 |
|
| 28 |
function __construct( $settings ) { |
| 29 |
|
| 30 |
$this->enable_field = ( isset( $settings['shortcodes']['enable_field'] ) ) ? $settings['shortcodes']['enable_field'] : 0; |
| 31 |
|
| 32 |
/** |
| 33 |
* Fires before shortcodes load. |
| 34 |
* |
| 35 |
* @since 3.0.0 |
| 36 |
* @since 3.1.6 Fires before shortcodes load. |
| 37 |
*/ |
| 38 |
do_action( 'wpmem_load_shortcodes' ); |
| 39 |
|
| 40 |
add_shortcode( 'wpmem_logged_in', array( $this, 'logged_in' ) ); |
| 41 |
add_shortcode( 'wpmem_logged_out', array( $this, 'logged_out' ) ); |
| 42 |
add_shortcode( 'wpmem_logout', array( $this, 'logout' ) ); |
| 43 |
add_shortcode( 'wpmem_form', array( $this, 'forms' ) ); |
| 44 |
add_shortcode( 'wpmem_login', array( $this, 'forms_login' ) ); |
| 45 |
add_shortcode( 'wpmem_reg', array( $this, 'forms_reg' ) ); |
| 46 |
add_shortcode( 'wpmem_profile', array( $this, 'user_profile' ) ); |
| 47 |
add_shortcode( 'wpmem_loginout', array( $this, 'loginout' ) ); |
| 48 |
add_shortcode( 'wpmem_login_link', array( $this, 'login_link' ) ); |
| 49 |
add_shortcode( 'wpmem_login_button', array( $this, 'login_button' ) ); |
| 50 |
add_shortcode( 'wpmem_reg_link', array( $this, 'login_link' ) ); |
| 51 |
add_shortcode( 'wpmem_tos', array( $this, 'tos' ) ); |
| 52 |
add_shortcode( 'wpmem_avatar', array( $this, 'avatar' ) ); |
| 53 |
add_shortcode( 'wpmem_show_count', array( $this, 'user_count' ) ); |
| 54 |
add_shortcode( 'wpmem_form_nonce', array( $this, 'form_nonce' ) ); |
| 55 |
|
| 56 |
/** |
| 57 |
* Filters the capability required for partial [wpmem_field]. |
| 58 |
* |
| 59 |
* @since 3.5.0 |
| 60 |
* |
| 61 |
* @param string $required_capability |
| 62 |
*/ |
| 63 |
$required_capability = apply_filters( 'wpmem_field_sc_required_capability', 'list_users' ); |
| 64 |
|
| 65 |
if ( 1 == $this->enable_field && current_user_can( $required_capability ) ) { |
| 66 |
add_shortcode( 'wpmem_field', array( $this, 'fields' ) ); |
| 67 |
} |
| 68 |
if ( 2 == $this->enable_field ) { |
| 69 |
add_shortcode( 'wpmem_field', array( $this, 'fields' ) ); |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Fires after shortcodes load. |
| 74 |
* |
| 75 |
* @since 3.0.0 |
| 76 |
* @since 3.1.6 Was wpmem_load_shortcodes, now wpmem_shortcodes_loaded. |
| 77 |
*/ |
| 78 |
do_action( 'wpmem_shortcodes_loaded' ); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Alias for [wpmem_form login] shortcode. |
| 83 |
* |
| 84 |
* @since 3.5.0 |
| 85 |
* |
| 86 |
* @param array $atts |
| 87 |
* @param string $content |
| 88 |
* @param string $tag |
| 89 |
* @param return $content |
| 90 |
*/ |
| 91 |
public function forms_login( $atts, $content, $tag ) { |
| 92 |
$atts[0] = 'login'; |
| 93 |
return $this->forms( $atts, $content, 'wpmem_form' ); |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Alias for [wpmem_form reg] shortcode. |
| 98 |
* |
| 99 |
* @since 3.5.0 |
| 100 |
* |
| 101 |
* @param array $atts |
| 102 |
* @param string $content |
| 103 |
* @param string $tag |
| 104 |
* @param return $content |
| 105 |
*/ |
| 106 |
public function forms_reg( $atts, $content, $tag ) { |
| 107 |
$atts[0] = 'register'; |
| 108 |
return $this->forms( $atts, $content, 'wpmem_form' ); |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Renders forms called by [wpmem_form] shortcode. |
| 113 |
* |
| 114 |
* @since 3.0.0 |
| 115 |
* @since 3.1.3 Added forgot_username shortcode. |
| 116 |
* @since 3.2.0 Moved to WP_Members_Shortcodes::forms(). |
| 117 |
* @since 3.2.0 Added id, exclude_fields, include_fields, and product attributes. |
| 118 |
* @since 3.3.2 Added WP default login form. |
| 119 |
* |
| 120 |
* @todo Complete support for id, exlude_fields, include_fields, and product attributes |
| 121 |
* May require updates to core functions. |
| 122 |
* |
| 123 |
* @global object $wpmem The WP_Members object. |
| 124 |
* @global string $wpmem_themsg The WP-Members message container. |
| 125 |
* |
| 126 |
* @param array $atts { |
| 127 |
* Possible shortcode attributes (some vary by form). |
| 128 |
* |
| 129 |
* @type string $id An ID for the form. |
| 130 |
* @type string $login Renders a login form. |
| 131 |
* @type string $password Renders a reset/change password form (login state dependent). |
| 132 |
* @type string $user_edit Renders a user profile edit form. |
| 133 |
* @type string $forgot_username Renders a forgot username form. |
| 134 |
* @type string $register Renders a register form. |
| 135 |
* @type string $wp_login Renders the WP login form. |
| 136 |
* @type string $redirect_to URL to redirect to on form submit (used for login and register forms). |
| 137 |
* @type string $texturize Add/fix texturization for the from HTML (usually not necessary). |
| 138 |
* @type string $exclude_fields Fields to exclude as comma separated meta keys (register/user_edit forms only). |
| 139 |
* @type string $include_fields Fields to include as comma separated meta keys (register/user_edit forms only). |
| 140 |
* @type string $product Register for specific product (if products are enabled). |
| 141 |
* } |
| 142 |
* @param string $content Nested content displayed if the shortcode is in the logged in state (optional). |
| 143 |
* @param string $tag The shortcode's tag (wpmem_form). |
| 144 |
* @return string The form HTML (or nested content, if used and the user is logged in). |
| 145 |
*/ |
| 146 |
function forms( $atts, $content, $tag ) { |
| 147 |
|
| 148 |
if ( is_admin() ) { |
| 149 |
return; |
| 150 |
} |
| 151 |
|
| 152 |
global $wpmem, $wpmem_themsg; |
| 153 |
|
| 154 |
// Sanitize the user input. |
| 155 |
$sanitized_atts = wpmem_sanitize_array( $atts ); |
| 156 |
|
| 157 |
// Defaults. |
| 158 |
$defaults = array( |
| 159 |
'form' => '', |
| 160 |
'redirect_to' => null, |
| 161 |
'texturize' => false, |
| 162 |
'form_id' => false, |
| 163 |
); |
| 164 |
$args = wp_parse_args( $sanitized_atts, $defaults ); |
| 165 |
|
| 166 |
$args['form'] = ( isset( $args[0] ) ) ? $args[0] : 'login'; |
| 167 |
unset( $args[0] ); |
| 168 |
|
| 169 |
$customizer = ( is_customize_preview() ) ? get_theme_mod( 'wpmem_show_logged_out_state', false ) : false; |
| 170 |
|
| 171 |
// If $args is an array, get the tag from the array so we know what form to render. |
| 172 |
switch ( $args['form'] ) { |
| 173 |
|
| 174 |
case 'wp_login': |
| 175 |
if ( is_user_logged_in() && '1' != $customizer ) { |
| 176 |
// If the user is logged in, return any nested content (if any) or the default bullet links if no nested content. |
| 177 |
$content = ( $content ) ? $content : $this->render_links( 'login' ); |
| 178 |
} else { |
| 179 |
$args['echo'] = false; |
| 180 |
$args['redirect'] = ( isset( $args['redirect'] ) ) ? $args['redirect'] : ( ( isset( $args['redirect_to'] ) ) ? $args['redirect_to'] : wpmem_current_url() ); |
| 181 |
$content = wpmem_wp_login_form( $args ); |
| 182 |
} |
| 183 |
break; |
| 184 |
|
| 185 |
case 'register': |
| 186 |
|
| 187 |
// Set up register form args. |
| 188 |
$reg_form_args = array( 'tag' => 'new' ); |
| 189 |
if ( isset( $redirect_to ) ) { |
| 190 |
$reg_form_args['redirect_to'] = $redirect_to; |
| 191 |
} |
| 192 |
|
| 193 |
if ( is_user_logged_in() && '1' != $customizer ) { |
| 194 |
/* |
| 195 |
* If the user is logged in, return any nested content (if any) |
| 196 |
* or the default bullet links if no nested content. |
| 197 |
*/ |
| 198 |
$content = ( $content ) ? $content : $this->render_links( 'register' ); |
| 199 |
} elseif ( is_user_logged_in() && is_customize_preview() && get_theme_mod( 'wpmem_show_form_message_dialog', false ) ) { |
| 200 |
$wpmem_themsg = wpmem_get_text( 'customizer_generic_msg' ); |
| 201 |
$content = wpmem_get_display_message( $wpmem->regchk, $wpmem_themsg ); |
| 202 |
$content .= wpmem_register_form( $reg_form_args ); |
| 203 |
} else { |
| 204 |
if ( $wpmem->regchk == 'loginfailed' ) { |
| 205 |
$content = $wpmem->dialogs->login_failed() . wpmem_login_form(); |
| 206 |
break; |
| 207 |
} |
| 208 |
// @todo Can this be moved into another function? Should $wpmem get an error message handler? |
| 209 |
if ( $wpmem->regchk == 'captcha' ) { |
| 210 |
global $wpmem_captcha_err; |
| 211 |
$wpmem_themsg = wpmem_get_text( 'reg_captcha_err' ) . '<br /><br />' . $wpmem_captcha_err; |
| 212 |
} |
| 213 |
$content = ( $wpmem_themsg || $wpmem->regchk == 'success' ) ? wpmem_get_display_message( $wpmem->regchk, $wpmem_themsg ) : ''; |
| 214 |
$content .= ( $wpmem->regchk == 'success' ) ? wpmem_login_form() : wpmem_register_form( $reg_form_args ); |
| 215 |
} |
| 216 |
break; |
| 217 |
|
| 218 |
case 'password': |
| 219 |
$content = $this->render_pwd_reset( $wpmem->regchk, $content ); |
| 220 |
break; |
| 221 |
|
| 222 |
case 'user_edit': |
| 223 |
$content = $this->render_user_edit( $wpmem->regchk, $content, $args ); |
| 224 |
break; |
| 225 |
|
| 226 |
case 'forgot_username': |
| 227 |
$content = $this->render_forgot_username( $wpmem->regchk, $content ); |
| 228 |
break; |
| 229 |
|
| 230 |
// @todo Review - is this actually ever triggered? |
| 231 |
case 'customizer_login': |
| 232 |
$content = wpmem_login_form(); |
| 233 |
break; |
| 234 |
|
| 235 |
// @todo Review - is this actually ever triggered? |
| 236 |
case 'customizer_register': |
| 237 |
$content = wpmem_register_form( 'new' ); |
| 238 |
break; |
| 239 |
|
| 240 |
case 'login': |
| 241 |
default: |
| 242 |
if ( is_user_logged_in() && '1' != $customizer ) { |
| 243 |
// If the user is logged in, return any nested content (if any) or the default bullet links if no nested content. |
| 244 |
$content = ( $content ) ? $content : $this->render_links( 'login' ); |
| 245 |
} else { |
| 246 |
$content = ''; |
| 247 |
if ( $wpmem->regchk == 'loginfailed' || ( is_customize_preview() && get_theme_mod( 'wpmem_show_form_message_dialog', false ) ) ) { |
| 248 |
$content = wpmem_get_display_message( 'loginfailed' ); |
| 249 |
} |
| 250 |
$form_id = ( $args['form_id'] ) ? $args['form_id'] : 'wpmem_login_form'; |
| 251 |
$content .= wpmem_login_form( array( 'redirect_to'=>$args['redirect_to'], 'form_id'=>$form_id ) ); |
| 252 |
} |
| 253 |
break; |
| 254 |
|
| 255 |
} |
| 256 |
|
| 257 |
return do_shortcode( $content ); |
| 258 |
} |
| 259 |
|
| 260 |
/** |
| 261 |
* Restricts content to logged in users using the shortcode [wpmem_logged_in]. |
| 262 |
* |
| 263 |
* There are several attributes that can be used with the shortcode: |
| 264 |
* in|out, sub for subscription only info, id, and role. IDs and roles |
| 265 |
* can be comma separated values for multiple users and roles. |
| 266 |
* |
| 267 |
* @since 3.0.0 |
| 268 |
* @since 3.2.0 Moved to WP_Members_Shortcodes::logged_in(). |
| 269 |
* @since 3.2.0 Added attributes for meta key/value pairs. |
| 270 |
* @since 3.2.3 Added product attribute. |
| 271 |
* @since 3.3.0 Added compare attribute for meta key/value compare (=|!=). |
| 272 |
* @since 3.5.5 Added attribute for display on various states of [wpmem_profile]. |
| 273 |
* |
| 274 |
* @global object $wpmem The WP_Members object. |
| 275 |
* |
| 276 |
* @param array $atts { |
| 277 |
* Attributes of the wpmem_logged_in shortcode. |
| 278 |
* |
| 279 |
* @type string $status User status to check (in|out) (optional). |
| 280 |
* @type int $id The user's ID. Restricts to a specified user by ID (optional). |
| 281 |
* @type string $role The user's role. Restrictes to a specific role (optional). |
| 282 |
* @type string $sub If the user is a current subscriber (for use with the PayPal extension) (optional). |
| 283 |
* @type string $meta_key If the user has a specified meta key (use with meta_value) (optional). |
| 284 |
* @type string $meta_value If the user has a specific meta key value (use with meta_key) (optional). |
| 285 |
* @tryp string $compare Can specify a comparison operator when using meta_key/meta_value (optional). |
| 286 |
* @type string $product If the user has a specific product/membership (optional). |
| 287 |
* @type string $membership If the user has a specific product/membership (optional). |
| 288 |
* @type string $wrap_id Adds a div wrapper with specified id. |
| 289 |
* @type string $wrap_class Adds a div wrapper with specified class. |
| 290 |
* @type string $wrap_tag Specifies wrapper tag (default: div) |
| 291 |
* } |
| 292 |
* @param string $content Shortcode content. |
| 293 |
* @param string $tag The shortcode's tag (wpmem_logged_in). |
| 294 |
* @return string|void The restricted content to display if the user meets the criteria. |
| 295 |
*/ |
| 296 |
function logged_in( $atts, $content, $tag ) { |
| 297 |
|
| 298 |
global $wpmem; |
| 299 |
|
| 300 |
// Sanitize the user input. |
| 301 |
$sanitized_atts = wpmem_sanitize_array( $atts ); |
| 302 |
|
| 303 |
// Handles the 'status' attribute. |
| 304 |
if ( ( isset( $sanitized_atts['status'] ) ) || $tag == 'wpmem_logged_in' ) { |
| 305 |
|
| 306 |
$do_return = false; |
| 307 |
|
| 308 |
// If there is a status attribute of "out" and the user is not logged in. |
| 309 |
$do_return = ( isset( $sanitized_atts['status'] ) && $sanitized_atts['status'] == 'out' && ! is_user_logged_in() ) ? true : $do_return; |
| 310 |
|
| 311 |
if ( is_user_logged_in() ) { |
| 312 |
|
| 313 |
// In case $current_user is not already global |
| 314 |
$current_user = wp_get_current_user(); |
| 315 |
|
| 316 |
// If there is a status attribute of "in" and the user is logged in. |
| 317 |
$do_return = ( isset( $sanitized_atts['status'] ) && $sanitized_atts['status'] == 'in' ) ? true : $do_return; |
| 318 |
|
| 319 |
// If using the wpmem_logged_in tag with no attributes & the user is logged in. |
| 320 |
$do_return = ( $tag == 'wpmem_logged_in' && ( ! $sanitized_atts ) ) ? true : $do_return; |
| 321 |
|
| 322 |
// If there is an "id" attribute and the user ID is in it. |
| 323 |
if ( isset( $sanitized_atts['id'] ) ) { |
| 324 |
$ids = explode( ',', $sanitized_atts['id'] ); |
| 325 |
foreach ( $ids as $id ) { |
| 326 |
if ( trim( $id ) == $current_user->ID ) { |
| 327 |
$do_return = true; |
| 328 |
} |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
// If there is a "role" attribute and the user has a matching role. |
| 333 |
if ( isset( $sanitized_atts['role'] ) ) { |
| 334 |
$roles = explode( ',', $sanitized_atts['role'] ); |
| 335 |
if ( wpmem_user_has_role( $roles ) ) { |
| 336 |
$do_return = true; |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
// If there is a status attribute of "sub" and the user is logged in. |
| 341 |
if ( ( isset( $sanitized_atts['status'] ) ) && $sanitized_atts['status'] == 'sub' ) { |
| 342 |
if ( wpmem_is_exp_enabled() && $wpmem->use_exp == 1 ) { |
| 343 |
if ( ! wpmem_is_user_current() ) { |
| 344 |
$do_return = true; |
| 345 |
} elseif ( $sanitized_atts['msg'] == "true" ) { |
| 346 |
$do_return = true; |
| 347 |
$content = wpmem_sc_expmessage(); |
| 348 |
} |
| 349 |
} |
| 350 |
} |
| 351 |
|
| 352 |
// If there is a meta key attribute. |
| 353 |
if ( isset( $sanitized_atts['meta_key'] ) ) { |
| 354 |
$do_return = false; |
| 355 |
$value = ( isset( $sanitized_atts['meta_value'] ) ) ? $sanitized_atts['meta_value'] : false; |
| 356 |
if ( ! isset( $sanitized_atts['compare'] ) || "=" == $sanitized_atts['compare'] ) { |
| 357 |
if ( wpmem_user_has_meta( $sanitized_atts['meta_key'], $value ) ) { |
| 358 |
$do_return = true; |
| 359 |
} |
| 360 |
} |
| 361 |
if ( isset( $sanitized_atts['compare'] ) && "!=" == $sanitized_atts['compare'] ) { |
| 362 |
if ( ! wpmem_user_has_meta( $sanitized_atts['meta_key'], $value ) ) { |
| 363 |
$do_return = true; |
| 364 |
} |
| 365 |
} |
| 366 |
} |
| 367 |
|
| 368 |
// If there is a product attribute. |
| 369 |
if ( isset( $sanitized_atts['product'] ) || isset( $sanitized_atts['membership'] ) ) { |
| 370 |
// @todo What if attribute is comma separated/multiple? |
| 371 |
$membership = ( isset( $sanitized_atts['membership'] ) ) ? $sanitized_atts['membership'] : $sanitized_atts['product']; |
| 372 |
$message = ( isset( $sanitized_atts['msg'] ) && ( true === $sanitized_atts['msg'] || "true" === strtolower( $sanitized_atts['msg'] ) ) ) ? true : false; |
| 373 |
$not_in = ( isset( $sanitized_atts['not_in'] ) && "true" == $sanitized_atts['not_in'] ) ? true : false; |
| 374 |
if ( $not_in ) { |
| 375 |
$do_return = ( wpmem_user_has_access( $membership ) || ! is_user_logged_in() ) ? false : true; |
| 376 |
} else { |
| 377 |
if ( wpmem_user_has_access( $membership ) ) { |
| 378 |
$do_return = true; |
| 379 |
} elseif ( true == $message ) { |
| 380 |
$do_return = true; |
| 381 |
$settings = array( |
| 382 |
'wrapper_before' => '<div class="product_restricted_msg">', |
| 383 |
'msg' => sprintf( wpmem_get_text( 'product_restricted' ), wpmem_get_membership_name( $membership ) ), |
| 384 |
'wrapper_after' => '</div>', |
| 385 |
); |
| 386 |
/** |
| 387 |
* Filter the access failed message. |
| 388 |
* |
| 389 |
* @since 3.3.0 |
| 390 |
* @since 3.3.3 Changed from 'wpmem_sc_product_access_denied' |
| 391 |
* @deprecated 3.5.0 Use wpmem_sc_membership_restricted instead. |
| 392 |
* |
| 393 |
* @param array $settings. |
| 394 |
*/ |
| 395 |
$settings = apply_filters_deprecated( 'wpmem_sc_product_restricted', array( $settings ), '3.5.0', 'wpmem_sc_membership_restricted' ); |
| 396 |
$settings = apply_filters( 'wpmem_sc_membership_restricted', $settings ); |
| 397 |
$content = $settings['wrapper_before'] . $settings['msg'] . $settings['wrapper_after']; |
| 398 |
} |
| 399 |
} |
| 400 |
} |
| 401 |
|
| 402 |
// Prevents display if the current page is the user profile and an action is being handled. |
| 403 |
if ( ( wpmem_current_url( true, false ) == wpmem_profile_url() ) ) { |
| 404 |
|
| 405 |
if ( isset( $_GET['a'] ) ) { |
| 406 |
$do_return = false; |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
// Adds optional wrapper. |
| 411 |
if ( isset( $sanitized_atts['wrap_id'] ) || isset( $sanitized_atts['wrap_class'] ) || isset( $sanitized_atts['wrap_tag'] ) ) { |
| 412 |
$tag = ( isset( $sanitized_atts['wrap_tag'] ) ) ? $sanitized_atts['wrap_tag'] : 'div'; |
| 413 |
$wrapper = '<' . esc_attr( $tag ); |
| 414 |
$wrapper .= ( isset( $sanitized_atts['wrap_id'] ) ) ? ' id="' . esc_attr( $sanitized_atts['wrap_id'] ) . '"' : ''; |
| 415 |
$wrapper .= ( isset( $sanitized_atts['wrap_class'] ) ) ? ' class="' . esc_attr( $sanitized_atts['wrap_class'] ) . '"' : ''; |
| 416 |
$wrapper .= '>'; |
| 417 |
$content = $wrapper . $content . '</' . esc_attr( $tag ) . '>'; |
| 418 |
$content = wp_kses_post( $content ); |
| 419 |
} |
| 420 |
|
| 421 |
} |
| 422 |
|
| 423 |
// Return content (or empty content) depending on the result of the above logic. |
| 424 |
return ( $do_return ) ? do_shortcode( $content ) : ''; |
| 425 |
} |
| 426 |
} |
| 427 |
|
| 428 |
/** |
| 429 |
* Renders the [wpmem_logged_out] shortcode. |
| 430 |
* |
| 431 |
* @since 3.0.0 |
| 432 |
* @since 3.2.0 Moved to WP_Members_Shortcodes::logged_out(). |
| 433 |
* |
| 434 |
* @param array $atts There are no attributes for this shortcode. |
| 435 |
* @param string $content Conent to display if user is logged out. |
| 436 |
* @param string $tag The shortcode tab (wpmem_logged_out). |
| 437 |
* @return string $content The content, if the user is logged out, otherwise an empty string. |
| 438 |
*/ |
| 439 |
function logged_out( $atts, $content, $tag ) { |
| 440 |
return ( ! is_user_logged_in() ) ? do_shortcode( $content ) : ''; |
| 441 |
} |
| 442 |
|
| 443 |
/** |
| 444 |
* Displays the user count shortcode [wpmem_show_count]. |
| 445 |
* |
| 446 |
* User count displays a total user count or a count of users by specific |
| 447 |
* role (role="some_role"). It also accepts attributes for counting users |
| 448 |
* by a meta field (key="meta_key" value="meta_value"). A label can be |
| 449 |
* displayed using the attribute label (label="Some label:"). |
| 450 |
* |
| 451 |
* @since 3.0.0 |
| 452 |
* @since 3.1.5 Added total user count features. |
| 453 |
* @since 3.2.0 Moved to WP_Members_Shortcodes::user_count(). |
| 454 |
* |
| 455 |
* @global object $wpdb The WordPress database object. |
| 456 |
* @param array $atts { |
| 457 |
* The shortcode attributes. |
| 458 |
* |
| 459 |
* @type string $key The user meta key, if displaying count by meta key. |
| 460 |
* @type string $value The user meta value, if displaying count by meta key. |
| 461 |
* @type string $role The user role, if displaying count by role. |
| 462 |
* @type string $label Label to display with the count (optional). |
| 463 |
* } |
| 464 |
* @param string $content Does not accept nested content. |
| 465 |
* @param string $tag The shortcode's tag (wpmem_show_count). |
| 466 |
* @return string $content The user count. |
| 467 |
*/ |
| 468 |
function user_count( $atts, $content, $tag ) { |
| 469 |
|
| 470 |
// Sanitize the user input. |
| 471 |
$sanitized_args = wpmem_sanitize_array( $atts ); |
| 472 |
|
| 473 |
if ( isset( $sanitized_args['key'] ) && isset( $sanitized_args['value'] ) ) { |
| 474 |
// If by meta key. |
| 475 |
$user_count = wpmem_get_user_count_by_meta( $sanitized_args['key'], $sanitized_args['value'] ); |
| 476 |
} else { |
| 477 |
// If no meta, it's a total count. |
| 478 |
$user_count = ( isset( $sanitized_args['role'] ) ) ? wpmem_get_user_count_by_role( $sanitized_args['role'] ) : wpmem_get_user_count_by_role( 'all' ); |
| 479 |
} |
| 480 |
|
| 481 |
// Assemble the output and return. |
| 482 |
$content = ( isset( $sanitized_args['label'] ) ) ? $sanitized_args['label'] . ' ' . intval( $user_count ) : wp_kses_post( $content ) . ' ' . intval( $user_count ); |
| 483 |
return do_shortcode( $content ); |
| 484 |
} |
| 485 |
|
| 486 |
/** |
| 487 |
* Creates the user profile dashboard area [wpmem_profile]. |
| 488 |
* |
| 489 |
* @since 3.1.0 |
| 490 |
* @since 3.1.2 Added function arguments. |
| 491 |
* @since 3.2.0 Moved to WP_Members_Shortcodes::user_profile(). |
| 492 |
* |
| 493 |
* @global object $wpmem The WP_Members object. |
| 494 |
* @global string $wpmem_themsg The WP-Members message container. |
| 495 |
* @param string $atts { |
| 496 |
* The shortcode attributes (filter with 'shortcode_atts_wpmem_profile'). |
| 497 |
* |
| 498 |
* @type string $redirect_to |
| 499 |
* @type string $register "hide" removes registration form, any other value is false. |
| 500 |
* } |
| 501 |
* @param string $content |
| 502 |
* @param string $tag |
| 503 |
* @return string $content |
| 504 |
*/ |
| 505 |
function user_profile( $atts, $content, $tag ) { |
| 506 |
|
| 507 |
global $wpmem, $wpmem_themsg; |
| 508 |
|
| 509 |
// Sanitize the user input. |
| 510 |
$sanitized_atts = wpmem_sanitize_array( $atts ); |
| 511 |
|
| 512 |
$pairs = array( |
| 513 |
'register' => 'show', |
| 514 |
'redirect_to' => '', |
| 515 |
); |
| 516 |
|
| 517 |
$args = shortcode_atts( $pairs, $sanitized_atts, $tag ); |
| 518 |
|
| 519 |
// @todo $redirect_to is not currently used in the user profile. |
| 520 |
$redirect_to = $args['redirect_to']; |
| 521 |
$hide_register = ( isset( $args['register'] ) && 'hide' == $args['register'] ) ? true : false; |
| 522 |
|
| 523 |
$content = ''; |
| 524 |
|
| 525 |
if ( $wpmem->regchk == "captcha" ) { |
| 526 |
global $wpmem_captcha_err; |
| 527 |
$wpmem_themsg = wpmem_get_text( 'reg_captcha_err' ) . '<br /><br />' . $wpmem_captcha_err; |
| 528 |
} |
| 529 |
|
| 530 |
if ( is_user_logged_in() ) { |
| 531 |
|
| 532 |
switch( $wpmem->action ) { |
| 533 |
|
| 534 |
case "edit": |
| 535 |
$content = $content . wpmem_register_form( 'edit' ); |
| 536 |
break; |
| 537 |
|
| 538 |
case "update": |
| 539 |
// Determine if there are any errors/empty fields. |
| 540 |
if ( $wpmem->regchk == "updaterr" || $wpmem->regchk == "email" ) { |
| 541 |
$content = $content . wpmem_get_display_message( $wpmem->regchk, $wpmem_themsg ); |
| 542 |
$content = $content . wpmem_register_form( 'edit' ); |
| 543 |
} else { |
| 544 |
//Case "editsuccess". |
| 545 |
$content = $content . wpmem_get_display_message( $wpmem->regchk, $wpmem_themsg ); |
| 546 |
$content = $content . $this->render_links(); |
| 547 |
} |
| 548 |
break; |
| 549 |
|
| 550 |
case "pwdchange": |
| 551 |
$content = $this->render_pwd_reset( $wpmem->regchk, $content ); |
| 552 |
$content = ( 'pwdchangesuccess' == $wpmem->regchk ) ? $content . $this->render_links() : $content; |
| 553 |
break; |
| 554 |
|
| 555 |
case "renew": |
| 556 |
if ( function_exists( 'wpmem_renew' ) ) { |
| 557 |
$content = wpmem_renew(); |
| 558 |
} else { |
| 559 |
$content = ''; |
| 560 |
} |
| 561 |
break; |
| 562 |
|
| 563 |
default: |
| 564 |
$content = $this->render_links(); |
| 565 |
break; |
| 566 |
} |
| 567 |
|
| 568 |
} else { |
| 569 |
|
| 570 |
if ( ( 'login' == $wpmem->action ) || ( 'register' == $wpmem->action && ! $hide_register ) ) { |
| 571 |
|
| 572 |
$content = wpmem_get_display_message( $wpmem->regchk, $wpmem_themsg ); |
| 573 |
$content.= ( 'loginfailed' == $wpmem->regchk || 'success' == $wpmem->regchk ) ? wpmem_login_form() : wpmem_register_form(); |
| 574 |
|
| 575 |
} elseif ( 'pwdreset' == $wpmem->action ) { |
| 576 |
|
| 577 |
$content = $this->render_pwd_reset( $wpmem->regchk, $content ); |
| 578 |
|
| 579 |
} elseif ( 'set_password_from_key' == $wpmem->action ) { |
| 580 |
|
| 581 |
$content = ( false != $wpmem->user->pwd_reset->content ) ? $wpmem->user->pwd_reset->content : $content; |
| 582 |
|
| 583 |
} elseif ( 'getusername' == $wpmem->action ) { |
| 584 |
|
| 585 |
$content = $this->render_forgot_username( $wpmem->regchk, $content ); |
| 586 |
|
| 587 |
} elseif ( 'reconfirm' == $wpmem->action ) { |
| 588 |
|
| 589 |
$content = $this->render_resend_confirm( $wpmem->regchk, $content ); |
| 590 |
|
| 591 |
} else { |
| 592 |
|
| 593 |
$content = $content . wpmem_login_form( 'profile' ); |
| 594 |
$content = ( ! $hide_register ) ? $content . wpmem_register_form() : $content; |
| 595 |
} |
| 596 |
} |
| 597 |
|
| 598 |
return $content; |
| 599 |
} |
| 600 |
|
| 601 |
/** |
| 602 |
* Log in/out shortcode [wpmem_loginout]. |
| 603 |
* |
| 604 |
* @since 3.1.1 |
| 605 |
* @since 3.1.6 Uses wpmem_loginout(). |
| 606 |
* @since 3.2.0 Moved to WP_Members_Shortcodes::loginout(). |
| 607 |
* |
| 608 |
* @param array $atts { |
| 609 |
* The shortcode attributes. |
| 610 |
* |
| 611 |
* @type string $login_redirect_to The url to redirect to after login (optional). |
| 612 |
* @type string $logout_redirect_to The url to redirect to after logout (optional). |
| 613 |
* @type string $login_text Text for the login link (optional). |
| 614 |
* @type string $logout_text Text for the logout link (optional). |
| 615 |
* } |
| 616 |
* @param string $content |
| 617 |
* @param string $tag |
| 618 |
* @return string $content |
| 619 |
*/ |
| 620 |
function loginout( $atts, $content, $tag ) { |
| 621 |
$sanitized_atts = wpmem_sanitize_array( $atts ); |
| 622 |
$link = wpmem_loginout( $sanitized_atts ); |
| 623 |
return do_shortcode( $link ); |
| 624 |
} |
| 625 |
|
| 626 |
/** |
| 627 |
* Function to handle field shortcodes [wpmem_field]. |
| 628 |
* |
| 629 |
* Shortcode to display the data for a given user field. Requires |
| 630 |
* that a field meta key be passed as an attribute. Can either of |
| 631 |
* the following: |
| 632 |
* - [wpmem_field field="meta_key"] |
| 633 |
* - [wpmem_field meta_key] |
| 634 |
* |
| 635 |
* Other attributes: |
| 636 |
* |
| 637 |
* - id (numeric user ID or "get" to retrieve uid from query string. |
| 638 |
* - underscores="true" strips underscores from the displayed value. |
| 639 |
* - display="raw" displays the stored value for dropdowns, radios, files. |
| 640 |
* - size(thumbnail|medium|large|full|w,h): image field only. |
| 641 |
* - clickable |
| 642 |
* - label |
| 643 |
* |
| 644 |
* Filter the end result with `wpmem_field_shortcode`. |
| 645 |
* |
| 646 |
* User input is sanitized with wpmem_sanitize_array(). |
| 647 |
* |
| 648 |
* @since 3.1.2 |
| 649 |
* @since 3.1.4 Changed to display value rather than stored value for dropdown/multicheck/radio. |
| 650 |
* @since 3.1.5 Added display attribute, meta key as a direct attribute, and image/file display. |
| 651 |
* @since 3.2.0 Moved to WP_Members_Shortcodes::fields(). |
| 652 |
* @since 3.2.0 Added clickable attribute. |
| 653 |
* @since 3.2.5 Added label attribute. |
| 654 |
* |
| 655 |
* @global object $wpmem The WP_Members object. |
| 656 |
* @param array $atts { |
| 657 |
* The shortcode attributes. |
| 658 |
* |
| 659 |
* @type string {meta_key} |
| 660 |
* @type string $field |
| 661 |
* @type int $id |
| 662 |
* @type string $underscores |
| 663 |
* @type string $display default:raw |
| 664 |
* @type string $size |
| 665 |
* @type string $clickable default:false |
| 666 |
* @type string $label default:false |
| 667 |
* } |
| 668 |
* @param string $content Any content passed with the shortcode (default:null). |
| 669 |
* @param string $tag The shortcode tag (wpmem_form). |
| 670 |
* @return string $content Content to return. |
| 671 |
*/ |
| 672 |
function fields( $atts, $content, $tag ) { |
| 673 |
|
| 674 |
if ( is_admin() ) { |
| 675 |
return; |
| 676 |
} |
| 677 |
|
| 678 |
// Sanitize the user input. |
| 679 |
$sanitized_atts = wpmem_sanitize_array( $atts ); |
| 680 |
|
| 681 |
// What field? |
| 682 |
if ( isset( $sanitized_atts[0] ) ) { |
| 683 |
$field = $sanitized_atts[0]; |
| 684 |
} elseif ( isset( $sanitized_atts['field'] ) ) { |
| 685 |
$field = $sanitized_atts['field']; |
| 686 |
} else { |
| 687 |
return; // If the field is not directly set in the attributes array, or keyed as "field", then it's not used correctly so return void. |
| 688 |
} |
| 689 |
|
| 690 |
// Exit if it's an excluded field, just return. |
| 691 |
if ( in_array( $field, array( 'user_pass', 'user_activation_key', 'user_status', 'cap_key', 'filter', 'password', 'confirm_password', 'confirm_email' ) ) ) { |
| 692 |
return; |
| 693 |
} |
| 694 |
|
| 695 |
// What user? |
| 696 |
if ( isset( $sanitized_atts['id'] ) ) { |
| 697 |
if ( 'author' == $sanitized_atts['id'] ) { |
| 698 |
global $post; |
| 699 |
$field_user_id = get_post_field( 'post_author', $post->ID ); |
| 700 |
|
| 701 |
// Alternate method: |
| 702 |
// $field_user_id = get_the_author_meta( 'ID' ); |
| 703 |
} else { |
| 704 |
$field_user_id = ( $sanitized_atts['id'] == 'get' ) ? wpmem_get( 'uid', '', 'get' ) : $sanitized_atts['id']; |
| 705 |
} |
| 706 |
} else { |
| 707 |
$field_user_id = get_current_user_id(); |
| 708 |
} |
| 709 |
|
| 710 |
// Sanitize the result. |
| 711 |
$sanitized_user_id = intval( $field_user_id ); |
| 712 |
|
| 713 |
// Get the user data. |
| 714 |
$user_info = get_userdata( $sanitized_user_id ); |
| 715 |
|
| 716 |
// Get the meta keys in WP-Members. |
| 717 |
$fields = wpmem_fields(); |
| 718 |
|
| 719 |
// Additional fields from $user_info that are allowed by default. |
| 720 |
$allowed_fields = array_merge( array( 'ID', 'user_login', 'user_email', 'user_registered', 'user_url', 'description', 'display_name', 'expires' ), array_keys( $fields ) ); |
| 721 |
|
| 722 |
// Remove some (it won't ever get here for these, but just so they don't show up in the filter array to confuse someone). |
| 723 |
unset( $allowed_fields['password'] ); |
| 724 |
unset( $allowed_fields['confirm_password'] ); |
| 725 |
unset( $allowed_fields['confirm_email'] ); |
| 726 |
|
| 727 |
/** |
| 728 |
* Filter meta keys allowed to be displayed. |
| 729 |
* |
| 730 |
* @since 3.4.9 |
| 731 |
* |
| 732 |
* @param array $fields |
| 733 |
*/ |
| 734 |
$allowed_fields = apply_filters( 'wpmem_field_sc_meta_keys', $allowed_fields ); |
| 735 |
|
| 736 |
// If there is userdata. |
| 737 |
if ( in_array( $field, $allowed_fields ) && $user_info && isset( $user_info->{$field} ) && ! is_object( $user_info->{$field} ) && ! is_array( $user_info->{$field} ) ) { |
| 738 |
|
| 739 |
$field_type = ( 'user_login' == $field || ! isset( $fields[ $field ] ) ) ? 'text' : $fields[ $field ]['type']; |
| 740 |
$user_info_field = ( isset( $field ) && is_object( $user_info ) ) ? $user_info->{$field} : ''; |
| 741 |
$result = false; |
| 742 |
|
| 743 |
// Handle each field type. |
| 744 |
switch ( $field_type ) { |
| 745 |
|
| 746 |
// Select and radio groups have single selections. |
| 747 |
case 'select': |
| 748 |
case 'radio': |
| 749 |
$result = ( isset( $sanitized_atts['display'] ) && 'raw' == $sanitized_atts['display'] ) ? $user_info_field : wpmem_select_field_display( $field, $user_info_field ); |
| 750 |
break; |
| 751 |
|
| 752 |
// Multiple select and multiple checkbox have multiple selections. |
| 753 |
case 'multiselect': |
| 754 |
case 'multicheckbox': |
| 755 |
case 'membership': |
| 756 |
if ( ! isset( $sanitized_atts['display'] ) ) { |
| 757 |
$sanitized_atts['display'] = ''; |
| 758 |
} |
| 759 |
if ( isset( $sanitized_atts['display'] ) && 'raw' == $sanitized_atts['display'] ) { |
| 760 |
$result = $user_info_field; |
| 761 |
} else { |
| 762 |
$saved_vals = explode( $fields[ $field ]['delimiter'], $user_info_field ); |
| 763 |
$result = ''; $x = 1; |
| 764 |
if ( 'list' == $sanitized_atts['display'] ) { |
| 765 |
/** |
| 766 |
* Filter list multi field list display HTML parts. |
| 767 |
* |
| 768 |
* @since 3.5.0 |
| 769 |
* |
| 770 |
* @param array { |
| 771 |
* The HTML parts (defaults as a bulleted list) |
| 772 |
* |
| 773 |
* @type string $wrapper_before |
| 774 |
* @type string $item_before |
| 775 |
* @type string $item_after |
| 776 |
* @type string $wrapper_after |
| 777 |
* } |
| 778 |
* @param string $field |
| 779 |
*/ |
| 780 |
$multi_args = apply_filters( 'wpmem_field_shortcode_multi_args', array( |
| 781 |
'wrapper_before' => '<ul id="wpmem_sc_field_' . $field . '">', |
| 782 |
'item_id' => 'wpmem-sc-multi-' . $field, |
| 783 |
'item_class' => 'wpmem-sc-multi', |
| 784 |
'item_before' => '<li id="%s" class="%s">', |
| 785 |
'item_after' => '</li>', |
| 786 |
'wrapper_after' => '</ul>', |
| 787 |
), $field ); |
| 788 |
|
| 789 |
foreach ( $saved_vals as $value ) { |
| 790 |
$rows[ $value ] = array( |
| 791 |
'item_before' => $multi_args['item_before'], |
| 792 |
'id' => $multi_args['item_id'] . '-' . $value, |
| 793 |
'class' => $multi_args['item_class'], |
| 794 |
'value' => $value, |
| 795 |
'title' => $value, |
| 796 |
'item_after' => $multi_args['item_after'], |
| 797 |
); |
| 798 |
} |
| 799 |
/** |
| 800 |
* Filter the row parts |
| 801 |
* |
| 802 |
* @since 3.5.0 |
| 803 |
* |
| 804 |
* @param array $rows |
| 805 |
* @param string $field |
| 806 |
*/ |
| 807 |
$rows = apply_filters( 'wpmem_field_shortcode_multi_rows', $rows, $field ); |
| 808 |
$row_items = ''; |
| 809 |
foreach ( $rows as $value => $row ) { |
| 810 |
$row_items .= sprintf( $row['item_before'], esc_attr( $row['id'] . '-' . $row['value'] ), esc_attr( $row['class'] ) ) . esc_attr( $row['title'] ) . $row['item_after']; |
| 811 |
} |
| 812 |
|
| 813 |
$result = $multi_args['wrapper_before'] . $row_items . $multi_args['wrapper_after']; |
| 814 |
|
| 815 |
$args = array( |
| 816 |
'wrapper' => array( |
| 817 |
'tag' => ( isset( $sanitized_atts['wrapper_tag'] ) ) ? $sanitized_atts['wrapper_tag'] : 'ul', |
| 818 |
'atts' => array( |
| 819 |
'id' => ( isset( $sanitized_atts['wrapper_id'] ) ) ? $sanitized_atts['wrapper_id'] : 'wpmem_field_' . $field, |
| 820 |
'class' => ( isset( $sanitized_atts['wrapper_class'] ) ) ? $sanitized_atts['wrapper_class'] : 'wpmem-field-multi-list', |
| 821 |
), |
| 822 |
), |
| 823 |
); |
| 824 |
foreach ( $saved_vals as $value ) { |
| 825 |
$args['item'][ $value ] = array( |
| 826 |
'tag' => ( isset( $sanitized_atts['item_tag'] ) ) ? $sanitized_atts['item_tag'] : 'li', |
| 827 |
'atts' => array( |
| 828 |
'id' => 'wpmem_field_' . $field . '_' . $value, |
| 829 |
'class' => 'wpmem-field-' . $field . '-item-' . $value, |
| 830 |
), |
| 831 |
'content' => $value |
| 832 |
); |
| 833 |
} |
| 834 |
/** |
| 835 |
* Filter list multi field list display HTML parts. |
| 836 |
* |
| 837 |
* @since 3.5.0 |
| 838 |
* |
| 839 |
* @param array { |
| 840 |
* The HTML parts (defaults as a bulleted list) |
| 841 |
* |
| 842 |
* @type array $wrapper { |
| 843 |
* The wrapper parts. |
| 844 |
* |
| 845 |
* @type string $tag The HTML tag (default: ul) |
| 846 |
* @type array $sanitized_atts The HTML tag attributes |
| 847 |
* @type string $content The content wrapped by the tag (default: list items) |
| 848 |
* } |
| 849 |
* @type array $item { |
| 850 |
* An item for each list item. |
| 851 |
* |
| 852 |
* @type string $tag The HTML tag (default: li) |
| 853 |
* @type array $sanitized_atts The HTML tag attributes |
| 854 |
* @type string $content The list item value |
| 855 |
* } |
| 856 |
* } |
| 857 |
* @param string $field |
| 858 |
*/ |
| 859 |
$multi_args = apply_filters( 'wpmem_field_sc_multi_html', $args, $field ); |
| 860 |
|
| 861 |
$list = ''; |
| 862 |
foreach ( $multi_args['item'] as $item ) { |
| 863 |
$list .= rktgk_build_html_tag( $item ); |
| 864 |
} |
| 865 |
$multi_args['wrapper']['content'] = $list; |
| 866 |
$result = rktgk_build_html_tag( $multi_args['wrapper'] ); |
| 867 |
|
| 868 |
} else { |
| 869 |
foreach ( $saved_vals as $value ) { |
| 870 |
$result.= ( $x > 1 ) ? ', ' : ''; $x++; |
| 871 |
$result.= wpmem_select_field_display( $field, $value );; |
| 872 |
} |
| 873 |
} |
| 874 |
} |
| 875 |
break; |
| 876 |
|
| 877 |
case 'file': |
| 878 |
case 'image': |
| 879 |
if ( isset( $sanitized_atts['display'] ) ) { |
| 880 |
switch ( $sanitized_atts['display'] ) { |
| 881 |
case "url": |
| 882 |
$result = wp_get_attachment_url( $user_info_field ); |
| 883 |
break; |
| 884 |
case "raw": |
| 885 |
default: |
| 886 |
$result = $user_info_field; |
| 887 |
break; |
| 888 |
} |
| 889 |
|
| 890 |
} else { |
| 891 |
if ( 'file' == $field_type ) { |
| 892 |
$attachment_url = wp_get_attachment_url( $user_info_field ); |
| 893 |
/** |
| 894 |
* Filter the file html tag parts. |
| 895 |
* |
| 896 |
* @since 3.4.5 |
| 897 |
* |
| 898 |
* @param array $args |
| 899 |
* @param string $field |
| 900 |
*/ |
| 901 |
$html_args = apply_filters( 'wpmem_field_sc_file_html', array( |
| 902 |
'tag' => 'a', |
| 903 |
'atts' => array( |
| 904 |
'href' => esc_url( $attachment_url ), |
| 905 |
'id' => ( isset( $sanitized_atts['id'] ) ) ? esc_attr( $sanitized_atts['id'] ) : esc_attr( 'wpmem_field_file_' . $field ), |
| 906 |
'class' => ( isset( $sanitized_atts['class'] ) ) ? esc_attr( $sanitized_atts['class'] ) : esc_attr( 'wpmem-field-file-' . $field ), |
| 907 |
), |
| 908 |
'content' => get_the_title( $user_info_field ), |
| 909 |
), $field ); |
| 910 |
$result = ( $attachment_url ) ? rktgk_build_html_tag( $html_args ) : ''; |
| 911 |
} else { |
| 912 |
$size = 'thumbnail'; |
| 913 |
if ( isset( $sanitized_atts['size'] ) ) { |
| 914 |
$sizes = array( 'thumbnail', 'medium', 'large', 'full' ); |
| 915 |
$size = ( ! in_array( $sanitized_atts['size'], $sizes ) ) ? explode( ",", $sanitized_atts['size'] ) : $sanitized_atts['size']; |
| 916 |
} |
| 917 |
$image = wp_get_attachment_image_src( $user_info_field, $size ); |
| 918 |
/** |
| 919 |
* Filter the image html tag parts. |
| 920 |
* |
| 921 |
* @since 3.4.5 |
| 922 |
* |
| 923 |
* @param array $args |
| 924 |
* @param string $field |
| 925 |
*/ |
| 926 |
$html_args = apply_filters( 'wpmem_field_sc_image_html', array( |
| 927 |
'tag' => 'img', |
| 928 |
'atts' => array( |
| 929 |
'src' => esc_url( $image[0] ), |
| 930 |
'width' => esc_attr( $image[1] ), |
| 931 |
'height' => esc_attr( $image[2] ), |
| 932 |
'id' => ( isset( $sanitized_atts['id'] ) ) ? esc_attr( $sanitized_atts['id'] ) : esc_attr( 'wpmem_field_img_' . $field ), |
| 933 |
'class' => ( isset( $sanitized_atts['class'] ) ) ? esc_attr( $sanitized_atts['class'] ) : esc_attr( 'wpmem-field-img-' . $field ) |
| 934 |
), |
| 935 |
), $field ); |
| 936 |
$result = ( $image ) ? rktgk_build_html_tag( $html_args ) : ''; |
| 937 |
} |
| 938 |
} |
| 939 |
break; |
| 940 |
|
| 941 |
case 'textarea': |
| 942 |
// Handle line breaks for textarea fields |
| 943 |
$result = ( isset( $sanitized_atts['display'] ) && 'raw' == $sanitized_atts['display'] ) ? $user_info_field : nl2br( $user_info_field ); |
| 944 |
break; |
| 945 |
|
| 946 |
case 'date': |
| 947 |
if ( isset( $sanitized_atts['format'] ) ) { |
| 948 |
// Formats date: https://secure.php.net/manual/en/function.date.php |
| 949 |
$result = ( '' != $user_info_field ) ? date( $sanitized_atts['format'], strtotime( $user_info_field ) ) : ''; |
| 950 |
} else { |
| 951 |
// Formats date to whatever the WP setting is. |
| 952 |
$result = ( '' != $user_info_field ) ? date_i18n( get_option( 'date_format' ), strtotime( $user_info_field ) ) : ''; |
| 953 |
} |
| 954 |
break; |
| 955 |
|
| 956 |
// Handle all other fields. |
| 957 |
default: |
| 958 |
$result = ( ! $result ) ? $user_info_field : $result; |
| 959 |
break; |
| 960 |
} |
| 961 |
|
| 962 |
// Remove underscores from value if requested (default: on). |
| 963 |
if ( isset( $sanitized_atts['underscores'] ) && 'off' == $sanitized_atts['underscores'] && $user_info ) { |
| 964 |
$result = str_replace( '_', ' ', $result ); |
| 965 |
} |
| 966 |
|
| 967 |
$content = ( $content ) ? $result . $content : $result; |
| 968 |
|
| 969 |
// Make it clickable? |
| 970 |
$content = ( isset( $sanitized_atts['clickable'] ) && ( true == $sanitized_atts['clickable'] || 'true' == $sanitized_atts['clickable'] ) ) ? make_clickable( $content ) : $content; |
| 971 |
|
| 972 |
// Display field label? |
| 973 |
$content = ( isset( $fields[ $field ] ) && isset( $sanitized_atts['label'] ) && ( true == $sanitized_atts['label'] ) ) ? wpmem_get_field_label( $field ) . ": " . $content : $content; |
| 974 |
} |
| 975 |
|
| 976 |
/** |
| 977 |
* Filters the field shortcode before returning value. |
| 978 |
* |
| 979 |
* @since 3.2.5 |
| 980 |
* @since 3.4.5 Added $field |
| 981 |
* |
| 982 |
* @param string $content |
| 983 |
* @param array $sanitized_atts |
| 984 |
* @param string $field |
| 985 |
*/ |
| 986 |
$content = apply_filters( 'wpmem_field_shortcode', $content, $sanitized_atts, $field ); |
| 987 |
|
| 988 |
return $content; |
| 989 |
} |
| 990 |
|
| 991 |
/** |
| 992 |
* Logout link shortcode [wpmem_logout]. |
| 993 |
* |
| 994 |
* @since 3.1.2 |
| 995 |
* @since 3.2.0 Moved to WP_Members_Shortcodes::logout(). |
| 996 |
* |
| 997 |
* @param array $atts { |
| 998 |
* The shortcode attributes. |
| 999 |
* |
| 1000 |
* @type string $url |
| 1001 |
* } |
| 1002 |
* @param string $content |
| 1003 |
* @param string $tag |
| 1004 |
* @retrun string $content |
| 1005 |
*/ |
| 1006 |
function logout( $atts, $content, $tag ) { |
| 1007 |
|
| 1008 |
// Sanitize the user input. |
| 1009 |
$sanitized_atts = wpmem_sanitize_array( $atts ); |
| 1010 |
|
| 1011 |
// Logout link shortcode. |
| 1012 |
if ( is_user_logged_in() && $tag == 'wpmem_logout' ) { |
| 1013 |
$link = ( isset( $sanitized_atts['url'] ) ) ? add_query_arg( array( 'a'=>'logout', 'redirect_to'=>$sanitized_atts['url'] ) ) : add_query_arg( 'a', 'logout' ); |
| 1014 |
$text = ( $content ) ? $content : wpmem_get_text( 'logout_sc_text' ); // "Click here to log out." |
| 1015 |
return do_shortcode( '<a href="' . esc_url( $link ) . '">' . esc_html( $text ) . '</a>' ); |
| 1016 |
} |
| 1017 |
} |
| 1018 |
|
| 1019 |
/** |
| 1020 |
* TOS shortcode [wpmem_tos]. |
| 1021 |
* |
| 1022 |
* @since 3.1.2 |
| 1023 |
* @since 3.2.0 Moved to WP_Members_Shortcodes::tos(). |
| 1024 |
* @since 3.2.5 Now can use page slug (without full url). |
| 1025 |
* |
| 1026 |
* @param array $atts { |
| 1027 |
* The shortcode attributes. |
| 1028 |
* |
| 1029 |
* @type string $url |
| 1030 |
* } |
| 1031 |
* @param string $content |
| 1032 |
* @param string $tag |
| 1033 |
* @return string $content |
| 1034 |
*/ |
| 1035 |
function tos( $atts, $content, $tag ) { |
| 1036 |
|
| 1037 |
// Sanitize the user input. |
| 1038 |
$sanitized_atts = wpmem_sanitize_array( $atts ); |
| 1039 |
|
| 1040 |
$url = ''; |
| 1041 |
if ( isset( $sanitized_atts['url'] ) ) { |
| 1042 |
$url = ( strpos( $sanitized_atts['url'], 'http://' ) || strpos( $sanitized_atts['url'], 'https://' ) ) ? $sanitized_atts['url'] : home_url( $sanitized_atts['url'] ); |
| 1043 |
return esc_url( $url ); |
| 1044 |
} else { |
| 1045 |
return; |
| 1046 |
} |
| 1047 |
} |
| 1048 |
|
| 1049 |
/** |
| 1050 |
* Display user avatar. |
| 1051 |
* |
| 1052 |
* @since 3.1.7 |
| 1053 |
* @since 3.2.0 Moved to WP_Members_Shortcodes::avatar(). |
| 1054 |
* |
| 1055 |
* @param array $atts { |
| 1056 |
* The shortcode attributes. |
| 1057 |
* |
| 1058 |
* @type string $id The user email or id. |
| 1059 |
* @type int $size Avatar size (square) in pixels. |
| 1060 |
* } |
| 1061 |
* @param string $content |
| 1062 |
* @param string $tag |
| 1063 |
* @retrun string $content |
| 1064 |
*/ |
| 1065 |
function avatar( $atts, $content, $tag ) { |
| 1066 |
|
| 1067 |
// Sanitize the user input. |
| 1068 |
$sanitized_atts = wpmem_sanitize_array( $atts ); |
| 1069 |
|
| 1070 |
$content = ''; |
| 1071 |
$size = ( isset( $sanitized_atts['size'] ) ) ? $sanitized_atts['size'] : ''; |
| 1072 |
if ( isset( $sanitized_atts['id'] ) ) { |
| 1073 |
$content = get_avatar( $sanitized_atts['id'], $size ); |
| 1074 |
} elseif ( is_user_logged_in() ) { |
| 1075 |
// If the user is logged in and this isn't specifying a user ID, return the current user avatar. |
| 1076 |
global $current_user; |
| 1077 |
wp_get_current_user(); |
| 1078 |
$content = get_avatar( $current_user->ID, $size ); |
| 1079 |
} |
| 1080 |
return do_shortcode( $content ); |
| 1081 |
} |
| 1082 |
|
| 1083 |
/** |
| 1084 |
* Generates a login link with a return url. |
| 1085 |
* |
| 1086 |
* @since 3.1.7 |
| 1087 |
* @since 3.2.0 Moved to WP_Members_Shortcodes::login_link(). |
| 1088 |
* @since 3.4.6 Using wpmem_get_login_link() and wpmem_get_reg_link() adds id and class attributes to HTML tag. |
| 1089 |
* @since 3.5.5 Only allow specific HTML tag attributes in the shortcode. |
| 1090 |
* |
| 1091 |
* @param array $atts { |
| 1092 |
* The shortcode attributes. |
| 1093 |
* } |
| 1094 |
* @param string $content |
| 1095 |
* @param string $tag |
| 1096 |
* @return string $content |
| 1097 |
*/ |
| 1098 |
function login_link( $atts, $content, $tag ) { |
| 1099 |
|
| 1100 |
// Sanitize the user input. |
| 1101 |
$sanitized_atts = wpmem_sanitize_array( $atts ); |
| 1102 |
|
| 1103 |
// Only allow specific HTML tag attributes to be included in the shortcode. |
| 1104 |
if ( isset( $sanitized_atts ) && ! empty( $sanitized_atts ) ) { |
| 1105 |
$allowed_atts = array( 'id', 'class', 'href' ); |
| 1106 |
foreach ( $sanitized_atts as $key => $value ) { |
| 1107 |
if ( ! array_key_exists( $key, $allowed_atts ) ) { |
| 1108 |
unset( $sanitized_atts[ $key ] ); |
| 1109 |
} |
| 1110 |
} |
| 1111 |
$args['attributes'] = $sanitized_atts; |
| 1112 |
} |
| 1113 |
|
| 1114 |
if ( 'wpmem_reg_link' == $tag ) { |
| 1115 |
$args['content'] = ( isset( $content ) && '' != $content ) ? $content : esc_html__( 'Register' ); |
| 1116 |
return do_shortcode( wpmem_get_reg_link( $args ) ); |
| 1117 |
} else { |
| 1118 |
$args['content'] = ( isset( $content ) && '' != $content ) ? $content : esc_html__( 'Log In' ); |
| 1119 |
return do_shortcode( wpmem_get_login_link( $args ) ); |
| 1120 |
} |
| 1121 |
} |
| 1122 |
|
| 1123 |
/** |
| 1124 |
* Generages a login link formatted as a button. |
| 1125 |
* |
| 1126 |
* @since 3.3.5 |
| 1127 |
* |
| 1128 |
* @param array $atts { |
| 1129 |
* The shortcode attributes. |
| 1130 |
* } |
| 1131 |
* @param string $content |
| 1132 |
* @param string $tag |
| 1133 |
* @return string $content |
| 1134 |
*/ |
| 1135 |
function login_button( $atts, $content, $tag ) { |
| 1136 |
$content = wpmem_loginout( array( 'format'=>'button' ) ); |
| 1137 |
return do_shortcode( $content ); |
| 1138 |
} |
| 1139 |
|
| 1140 |
/** |
| 1141 |
* Generate a nonce for a WP-Members form. |
| 1142 |
* |
| 1143 |
* For situations where a hardcoded form may exist, this shortcode |
| 1144 |
* can output the appropriate nonce. |
| 1145 |
* |
| 1146 |
* @since 3.3.0 |
| 1147 |
* |
| 1148 |
* @param array $atts { |
| 1149 |
* The shortcode attributes. |
| 1150 |
* |
| 1151 |
* $form string The form to generate the nonce for (register|update|login) |
| 1152 |
* } |
| 1153 |
* $param string $content |
| 1154 |
* @param string $tag |
| 1155 |
* @return string $content |
| 1156 |
*/ |
| 1157 |
function form_nonce( $atts, $content, $tag ) { |
| 1158 |
// Sanitize the user input. |
| 1159 |
$sanitized_atts = wpmem_sanitize_array( $atts ); |
| 1160 |
$nonce = ( isset( $sanitized_atts['form'] ) ) ? esc_attr( $sanitized_atts['form'] ) : 'register'; |
| 1161 |
$content = wpmem_form_nonce( $nonce, false ); |
| 1162 |
return do_shortcode( $content ); |
| 1163 |
} |
| 1164 |
|
| 1165 |
/** |
| 1166 |
* Password reset forms. |
| 1167 |
* |
| 1168 |
* This function creates both password reset and forgotten |
| 1169 |
* password forms for page=password shortcode. |
| 1170 |
* |
| 1171 |
* @since 2.7.6 |
| 1172 |
* @since 3.2.6 Added nonce validation. |
| 1173 |
* @since 3.4.0 Moved to shortcodes as private function, renamed from wpmem_page_pwd_reset(). |
| 1174 |
* |
| 1175 |
* @global object $wpmem |
| 1176 |
* @param string $wpmem_regchk |
| 1177 |
* @param string $content |
| 1178 |
* @return string $content |
| 1179 |
*/ |
| 1180 |
function render_pwd_reset( $wpmem_regchk, $content ) { |
| 1181 |
|
| 1182 |
global $wpmem; |
| 1183 |
|
| 1184 |
if ( is_user_logged_in() ) { |
| 1185 |
|
| 1186 |
switch ( $wpmem_regchk ) { |
| 1187 |
|
| 1188 |
case "pwdchangesuccess": |
| 1189 |
$content = $content . wpmem_get_display_message( $wpmem_regchk ); |
| 1190 |
break; |
| 1191 |
|
| 1192 |
default: |
| 1193 |
if ( isset( $wpmem_regchk ) && '' != $wpmem_regchk ) { |
| 1194 |
$content .= wpmem_get_display_message( $wpmem_regchk, wpmem_get_text( $wpmem_regchk ) ); |
| 1195 |
} |
| 1196 |
$content = $content . wpmem_change_password_form(); |
| 1197 |
break; |
| 1198 |
} |
| 1199 |
|
| 1200 |
} else { |
| 1201 |
|
| 1202 |
// If the password shortcode page is set as User Profile page. |
| 1203 |
if ( 'getusername' == $wpmem->action ) { |
| 1204 |
|
| 1205 |
return $this->render_forgot_username( $wpmem_regchk, $content ); |
| 1206 |
|
| 1207 |
} elseif ( 'set_password_from_key' == $wpmem->action ) { |
| 1208 |
|
| 1209 |
return ( false != $wpmem->user->pwd_reset->content ) ? $wpmem->user->pwd_reset->content : $content; |
| 1210 |
|
| 1211 |
} else { |
| 1212 |
|
| 1213 |
switch( $wpmem_regchk ) { |
| 1214 |
|
| 1215 |
case "pwdresetsuccess": |
| 1216 |
$content = $content . wpmem_get_display_message( $wpmem_regchk ); |
| 1217 |
$wpmem_regchk = ''; // Clear regchk. |
| 1218 |
break; |
| 1219 |
|
| 1220 |
default: |
| 1221 |
if ( $wpmem->has_errors() ) { |
| 1222 |
$errors = $wpmem->error->get_error_messages(); |
| 1223 |
if ( sizeof( $errors ) > 1 ) { |
| 1224 |
$error_string = ""; |
| 1225 |
foreach ( $errors as $error ) { |
| 1226 |
$error_string .= $error . '<br />'; |
| 1227 |
} |
| 1228 |
} else { |
| 1229 |
$error_string = $errors[0]; |
| 1230 |
} |
| 1231 |
$content = wpmem_get_display_message( $error_string ); |
| 1232 |
} elseif ( isset( $wpmem_regchk ) && '' != $wpmem_regchk ) { |
| 1233 |
$content = wpmem_get_display_message( $wpmem_regchk, wpmem_get_text( $wpmem_regchk ) ); |
| 1234 |
} |
| 1235 |
$content = $content . wpmem_reset_password_form(); |
| 1236 |
break; |
| 1237 |
} |
| 1238 |
|
| 1239 |
} |
| 1240 |
|
| 1241 |
} |
| 1242 |
|
| 1243 |
return $content; |
| 1244 |
|
| 1245 |
} |
| 1246 |
|
| 1247 |
/** |
| 1248 |
* Creates a user edit page. |
| 1249 |
* |
| 1250 |
* @since 2.7.6 |
| 1251 |
* @since 3.3.9 Added $atts |
| 1252 |
* @since 3.4.0 Moved to shortcodes as private function, renamed from wpmem_page_user_edit |
| 1253 |
* |
| 1254 |
* @global object $wpmem |
| 1255 |
* @global string $wpmem_a |
| 1256 |
* @global string $wpmem_themsg |
| 1257 |
* @param string $wpmem_regchk |
| 1258 |
* @param string $content |
| 1259 |
* @return string $content |
| 1260 |
*/ |
| 1261 |
function render_user_edit( $wpmem_regchk, $content, $atts = false ) { |
| 1262 |
|
| 1263 |
global $wpmem_a, $wpmem_themsg; |
| 1264 |
/** |
| 1265 |
* Filter the default User Edit heading for shortcode. |
| 1266 |
* |
| 1267 |
* @since 2.7.6 |
| 1268 |
* |
| 1269 |
* @param string The default edit mode heading. |
| 1270 |
*/ |
| 1271 |
$heading = apply_filters( 'wpmem_user_edit_heading', wpmem_get_text( 'profile_heading' ) ); |
| 1272 |
|
| 1273 |
if ( $wpmem_a == "update") { |
| 1274 |
$content.= wpmem_get_display_message( $wpmem_regchk, $wpmem_themsg ); |
| 1275 |
} |
| 1276 |
|
| 1277 |
$args['tag'] = 'edit'; |
| 1278 |
$args['heading'] = $heading; |
| 1279 |
if ( false !== $atts && isset( $atts['fields'] ) ) { |
| 1280 |
$args['fields'] = $atts['fields']; |
| 1281 |
} |
| 1282 |
|
| 1283 |
$content = $content . wpmem_register_form( $args ); |
| 1284 |
|
| 1285 |
return $content; |
| 1286 |
} |
| 1287 |
|
| 1288 |
/** |
| 1289 |
* Forgot username form. |
| 1290 |
* |
| 1291 |
* This function creates a form for retrieving a forgotten username. |
| 1292 |
* |
| 1293 |
* @since 3.0.8 |
| 1294 |
* @since 3.4.0 Moved to shortcodes as private function, renamed from wpmem_page_forgot_username(). |
| 1295 |
* |
| 1296 |
* @param string $wpmem_regchk |
| 1297 |
* @param string $content |
| 1298 |
* @return string $content |
| 1299 |
*/ |
| 1300 |
function render_forgot_username( $wpmem_regchk, $content ) { |
| 1301 |
|
| 1302 |
if ( ! is_user_logged_in() ) { |
| 1303 |
|
| 1304 |
global $wpmem; |
| 1305 |
switch( $wpmem->regchk ) { |
| 1306 |
|
| 1307 |
case "usernamefailed": |
| 1308 |
$msg = wpmem_get_text( 'usernamefailed' ); |
| 1309 |
$content = $content |
| 1310 |
. wpmem_get_display_message( 'usernamefailed', $msg ) |
| 1311 |
. wpmem_forgot_username_form(); |
| 1312 |
$wpmem->regchk = ''; // Clear regchk. |
| 1313 |
break; |
| 1314 |
|
| 1315 |
case "usernamesuccess": |
| 1316 |
$email = wpmem_get_sanitized( 'user_email', '', 'post', 'email' ); // ( isset( $_POST['user_email'] ) ) ? sanitize_email( $_POST['user_email'] ) : ''; |
| 1317 |
$msg = sprintf( wpmem_get_text( 'usernamesuccess' ), $email ); |
| 1318 |
$content = $content . wpmem_get_display_message( 'usernamesuccess', $msg ); |
| 1319 |
$wpmem->regchk = ''; // Clear regchk. |
| 1320 |
break; |
| 1321 |
|
| 1322 |
default: |
| 1323 |
$content = $content . wpmem_forgot_username_form(); |
| 1324 |
break; |
| 1325 |
} |
| 1326 |
|
| 1327 |
} |
| 1328 |
|
| 1329 |
return $content; |
| 1330 |
|
| 1331 |
} |
| 1332 |
|
| 1333 |
/** |
| 1334 |
* Resend confirmation link form. |
| 1335 |
* |
| 1336 |
* This function creates a form for requesting a new confirmation link. |
| 1337 |
* |
| 1338 |
* @since 3.5.0 |
| 1339 |
* |
| 1340 |
* @param string $wpmem_regchk |
| 1341 |
* @param string $content |
| 1342 |
* @return string $content |
| 1343 |
*/ |
| 1344 |
function render_resend_confirm( $wpmem_regchk, $content ) { |
| 1345 |
|
| 1346 |
if ( ! is_user_logged_in() ) { |
| 1347 |
|
| 1348 |
global $wpmem; |
| 1349 |
switch( $wpmem->regchk ) { |
| 1350 |
|
| 1351 |
case "reconfirmfailed": |
| 1352 |
$msg = wpmem_get_text( 'pwdreseterr' ); |
| 1353 |
$content = $content |
| 1354 |
. wpmem_get_display_message( 'pwdreseterr', $msg ) |
| 1355 |
. wpmem_resend_confirmation_form(); |
| 1356 |
$wpmem->regchk = ''; // Clear regchk. |
| 1357 |
break; |
| 1358 |
|
| 1359 |
case "reconfirmsuccess": |
| 1360 |
$email = wpmem_get_sanitized( 'user_email', '', 'post', 'email' ); // ( isset( $_POST['user_email'] ) ) ? sanitize_email( $_POST['user_email'] ) : ''; |
| 1361 |
$msg = wpmem_get_text( 'reconfirm_success' ); |
| 1362 |
$content = $content . wpmem_get_display_message( 'reconfirm_success', $msg ); |
| 1363 |
$wpmem->regchk = ''; // Clear regchk. |
| 1364 |
break; |
| 1365 |
|
| 1366 |
default: |
| 1367 |
$content = $content . wpmem_resend_confirmation_form(); |
| 1368 |
break; |
| 1369 |
} |
| 1370 |
|
| 1371 |
} |
| 1372 |
|
| 1373 |
return $content; |
| 1374 |
|
| 1375 |
} |
| 1376 |
|
| 1377 |
/** |
| 1378 |
* Member Links Dialog. |
| 1379 |
* |
| 1380 |
* Outputs the links used on the members area. |
| 1381 |
* |
| 1382 |
* @since 2.0 |
| 1383 |
* @since 3.4.0 Replaces wpmem_inc_memberlinks(). |
| 1384 |
* |
| 1385 |
* @gloabl $user_login |
| 1386 |
* @global object $wpmem |
| 1387 |
* @param string $page |
| 1388 |
* @return string $str |
| 1389 |
*/ |
| 1390 |
function render_links( $page = 'member' ) { |
| 1391 |
|
| 1392 |
global $user_login, $wpmem; |
| 1393 |
|
| 1394 |
$logout = wpmem_logout_link(); |
| 1395 |
|
| 1396 |
switch ( $page ) { |
| 1397 |
|
| 1398 |
case 'register': |
| 1399 |
|
| 1400 |
$url = ( isset( $wpmem->user_pages['profile'] ) && '' != $wpmem->user_pages['profile'] ) ? $wpmem->user_pages['profile'] : get_option( 'home' ); |
| 1401 |
|
| 1402 |
// NOTE: DO NOT EDIT THESE. Use the filter below. |
| 1403 |
$arr = array( |
| 1404 |
'before_wrapper' => '<p class="register_status">' . sprintf( wpmem_get_text( 'register_status' ), $user_login ) . '</p>', |
| 1405 |
'wrapper_before' => '<ul class="register_links">', |
| 1406 |
'wrapper_after' => '</ul>', |
| 1407 |
'rows' => array( |
| 1408 |
'<li><a href="' . esc_url( $logout ) . '">' . wpmem_get_text( 'register_logout' ) . '</a></li>', |
| 1409 |
'<li><a href="' . esc_url( $url ) . '">' . wpmem_get_text( 'register_continue' ) . '</a></li>', |
| 1410 |
), |
| 1411 |
'after_wrapper' => '', |
| 1412 |
); |
| 1413 |
|
| 1414 |
/** |
| 1415 |
* Filter the register links array. |
| 1416 |
* |
| 1417 |
* @since 3.0.9 |
| 1418 |
* @since 3.1.0 Added after_wrapper |
| 1419 |
* |
| 1420 |
* @param array $arr { |
| 1421 |
* The components of the links. |
| 1422 |
* |
| 1423 |
* @type string $before_wrapper HTML before the wrapper (default: login status). |
| 1424 |
* @type string $wrapper_before The wrapper opening tag (default: <ul>). |
| 1425 |
* @type string $wrapper_after The wrapper closing tag (default: </ul>). |
| 1426 |
* @type array $rows Row items HTML. |
| 1427 |
* @type string $after_wrapper Anything that comes after the wrapper. |
| 1428 |
* } |
| 1429 |
*/ |
| 1430 |
$arr = apply_filters( "wpmem_{$page}_links_args", $arr ); |
| 1431 |
|
| 1432 |
$str = $arr['before_wrapper']; |
| 1433 |
$str.= $arr['wrapper_before']; |
| 1434 |
foreach ( $arr['rows'] as $row ) { |
| 1435 |
$str.= $row; |
| 1436 |
} |
| 1437 |
$str.= $arr['wrapper_after']; |
| 1438 |
$str.= $arr['after_wrapper']; |
| 1439 |
|
| 1440 |
/** |
| 1441 |
* Filter the links displayed on the Register page (logged in state). |
| 1442 |
* |
| 1443 |
* @since 2.8.3 |
| 1444 |
* |
| 1445 |
* @param string $str The default links. |
| 1446 |
*/ |
| 1447 |
$str = apply_filters( "wpmem_{$page}_links", $str ); |
| 1448 |
break; |
| 1449 |
|
| 1450 |
case 'login': |
| 1451 |
|
| 1452 |
$logout = rawurldecode( $logout ); |
| 1453 |
/* |
| 1454 |
* NOTE: DO NOT EDIT THESE. Use the filter hook below. |
| 1455 |
* |
| 1456 |
* Don't know how to use filter or action hooks to customize WP? |
| 1457 |
* See https://wpbitz.com/how-to-use-hooks-in-wordpress/ |
| 1458 |
*/ |
| 1459 |
$args = array( |
| 1460 |
'wrapper_before' => '<p class="login_status">', |
| 1461 |
'wrapper_after' => '</p>', |
| 1462 |
'user_login' => $user_login, |
| 1463 |
'welcome' => wpmem_get_text( 'login_welcome' ), |
| 1464 |
'logout_text' => wpmem_get_text( 'login_logout' ), |
| 1465 |
'logout_link' => '<a href="' . esc_url( $logout ) . '">%s</a>', |
| 1466 |
'separator' => '<br />', |
| 1467 |
); |
| 1468 |
/** |
| 1469 |
* Filter the status message parts. |
| 1470 |
* |
| 1471 |
* @since 2.9.9 |
| 1472 |
* |
| 1473 |
* @param array $args { |
| 1474 |
* The components of the links. |
| 1475 |
* |
| 1476 |
* @type string $wrapper_before The wrapper opening tag (default: <p>). |
| 1477 |
* @type string $wrapper_after The wrapper closing tag (default: </p>). |
| 1478 |
* @type string $user_login |
| 1479 |
* @type string $welcome |
| 1480 |
* @type string $logout_text |
| 1481 |
* @type string $logout_link |
| 1482 |
* @type string $separator |
| 1483 |
* } |
| 1484 |
*/ |
| 1485 |
$args = apply_filters( "wpmem_{$page}_links_args", $args ); |
| 1486 |
|
| 1487 |
// Assemble the message string. |
| 1488 |
$str = $args['wrapper_before'] |
| 1489 |
. sprintf( $args['welcome'], $args['user_login'] ) |
| 1490 |
. $args['separator'] |
| 1491 |
. sprintf( $args['logout_link'], $args['logout_text'] ) |
| 1492 |
. $args['wrapper_after']; |
| 1493 |
|
| 1494 |
/** |
| 1495 |
* Filter the links displayed on the Log In page (logged in state). |
| 1496 |
* |
| 1497 |
* @since 2.8.3 |
| 1498 |
* |
| 1499 |
* @param string $str The default links. |
| 1500 |
*/ |
| 1501 |
$str = apply_filters( "wpmem_{$page}_links", $str ); |
| 1502 |
break; |
| 1503 |
|
| 1504 |
case 'member': |
| 1505 |
default: |
| 1506 |
|
| 1507 |
// NOTE: DO NOT EDIT. Use the filter below. |
| 1508 |
$arr = array( |
| 1509 |
'before_wrapper' => '', |
| 1510 |
'wrapper_before' => '<ul>', |
| 1511 |
'wrapper_after' => '</ul>', |
| 1512 |
'rows' => array( |
| 1513 |
'<li><a href="' . esc_url( add_query_arg( 'a', 'edit', remove_query_arg( 'key' ) ) ) . '">' . wpmem_get_text( 'profile_edit' ) . '</a></li>', |
| 1514 |
'<li><a href="' . esc_url( add_query_arg( 'a', 'pwdchange', remove_query_arg( 'key' ) ) ) . '">' . wpmem_get_text( 'profile_password' ) . '</a></li>', |
| 1515 |
), |
| 1516 |
'after_wrapper' => '', |
| 1517 |
); |
| 1518 |
|
| 1519 |
if ( wpmem_is_exp_enabled() && $wpmem->use_exp == 1 && function_exists( 'wpmem_user_page_detail' ) ) { |
| 1520 |
$arr['rows'][] = wpmem_user_page_detail(); |
| 1521 |
} |
| 1522 |
|
| 1523 |
/** |
| 1524 |
* Filter the member links array. |
| 1525 |
* |
| 1526 |
* @since 3.0.9 |
| 1527 |
* @since 3.1.0 Added after_wrapper |
| 1528 |
* |
| 1529 |
* @param array $arr { |
| 1530 |
* The components of the links. |
| 1531 |
* |
| 1532 |
* @type string $before_wrapper Anything that comes before the wrapper. |
| 1533 |
* @type string $wrapper_before The wrapper opening tag (default: <ul>). |
| 1534 |
* @type string $wrapper_after The wrapper closing tag (default: </ul>). |
| 1535 |
* @type array $rows Row items HTML. |
| 1536 |
* @type string $after_wrapper Anything that comes after the wrapper. |
| 1537 |
* } |
| 1538 |
*/ |
| 1539 |
$arr = apply_filters( "wpmem_{$page}_links_args", $arr ); |
| 1540 |
|
| 1541 |
$str = $arr['before_wrapper']; |
| 1542 |
$str.= $arr['wrapper_before']; |
| 1543 |
foreach ( $arr['rows'] as $row ) { |
| 1544 |
$str.= $row; |
| 1545 |
} |
| 1546 |
$str.= $arr['wrapper_after']; |
| 1547 |
$str.= $arr['after_wrapper']; |
| 1548 |
|
| 1549 |
/** |
| 1550 |
* Filter the links displayed on the User Profile page (logged in state). |
| 1551 |
* |
| 1552 |
* @since 2.8.3 |
| 1553 |
* |
| 1554 |
* @param string $str The default links. |
| 1555 |
*/ |
| 1556 |
$str = apply_filters( "wpmem_{$page}_links", $str ); |
| 1557 |
break; |
| 1558 |
} |
| 1559 |
|
| 1560 |
return $str; |
| 1561 |
} |
| 1562 |
|
| 1563 |
function render_links_filter_args( $page, $args ) { |
| 1564 |
|
| 1565 |
} |
| 1566 |
} |
| 1567 |
|
| 1568 |
// End of file. |