Beispiel #1
0
/**
 * Executes shortcode for settings, register, and login pages
 *
 * @since 2.4 
 *
 * @param  array $attr page|status|field
 * @param  string $content
 * @return string returns the result of wpmem_do_sc_pages|wpmem_list_users|wpmem_sc_expmessage|$content
 */
function wpmem_shortcode($attr, $content = null)
{
    // handles the 'page' attribute
    if (isset($attr['page'])) {
        if ($attr['page'] == 'user-list') {
            return do_shortcode(wpmem_list_users($attr, $content));
        } else {
            return do_shortcode(wpmem_do_sc_pages($attr['page']));
        }
    }
    // handles the 'status' attribute
    if (isset($attr['status'])) {
        if ($attr['status'] == 'in' && is_user_logged_in()) {
            return do_shortcode($content);
        } elseif ($attr['status'] == 'out' && !is_user_logged_in()) {
            return do_shortcode($content);
        } elseif ($attr['status'] == 'sub' && is_user_logged_in()) {
            if (WPMEM_USE_EXP == 1) {
                if (!wpmem_chk_exp()) {
                    return do_shortcode($content);
                } elseif ($attr['msg'] == true) {
                    return do_shortcode(wpmem_sc_expmessage());
                }
            }
        }
    }
    // handles the 'field' attribute
    if (isset($attr['field'])) {
        global $user_ID;
        $user_info = get_userdata($user_ID);
        return htmlspecialchars($user_info->{$attr}['field']) . do_shortcode($content);
    }
}
 /**
  * Executes various shortcodes 
  *
  * This function executes shortcodes for pages (settings, register, login, user-list, 
  * and tos pages), as well as login status and field attributes when the wp-members tag
  * is used.  Also executes shortcodes for login status with the wpmem_logged_in tags 
  * and fields when the wpmem_field tags are used.
  *
  * @since 2.4 
  *
  * @param  array  $attr page|url|status|msg|field|id
  * @param  string $content
  * @param  string $tag
  * @return string returns the result of wpmem_do_sc_pages|wpmem_list_users|wpmem_sc_expmessage|$content
  */
 function wpmem_shortcode($attr, $content = null, $tag = 'wp-members')
 {
     // set all default attributes to false
     $defaults = array('page' => false, 'url' => false, 'status' => false, 'msg' => false, 'field' => false, 'id' => false);
     // merge defaults with $attr and extract
     extract(shortcode_atts($defaults, $attr, $tag));
     // handles the 'page' attribute
     if ($page) {
         if ($page == 'user-list') {
             //return ( function_exists( 'wpmem_list_users' ) ) ? do_shortcode( wpmem_list_users( $attr, $content ) ) : '';
             if (function_exists('wpmem_list_users')) {
                 $content = do_shortcode(wpmem_list_users($attr, $content));
             }
         } elseif ($page == 'tos') {
             return $url;
         } else {
             //return do_shortcode( wpmem_do_sc_pages( $page ) );
             $content = do_shortcode(wpmem_do_sc_pages($page));
         }
         // resolve any texturize issues...
         if (strstr($content, '[wpmem_txt]')) {
             // fix the wptexturize
             remove_filter('the_content', 'wpautop');
             remove_filter('the_content', 'wptexturize');
             add_filter('the_content', 'wpmem_texturize', 99);
         }
         return $content;
     }
     // handles the 'status' attribute
     if ($status || $tag == 'wpmem_logged_in') {
         $do_return = false;
         // if using the wpmem_logged_in tag with no attributes & the user is logged in
         if ($tag == 'wpmem_logged_in' && !$attr && is_user_logged_in()) {
             $do_return = true;
         }
         // if there is a status attribute of "in" and the user is logged in
         if ($status == 'in' && is_user_logged_in()) {
             $do_return = true;
         }
         // if there is a status attribute of "out" and the user is not logged in
         if ($status == 'out' && !is_user_logged_in()) {
             $do_return = true;
         }
         // if there is a status attribute of "sub" and the user is logged in
         if ($status == 'sub' && is_user_logged_in()) {
             if (WPMEM_USE_EXP == 1) {
                 if (!wpmem_chk_exp()) {
                     $do_return = true;
                 } elseif ($msg == true) {
                     $do_return = true;
                     $content = wpmem_sc_expmessage();
                 }
             }
         }
         // return content (or empty content) depending on the result of the above logic
         return $do_return ? do_shortcode($content) : '';
     }
     // handles the wpmem_logged_out tag with no attributes & the user is not logged in
     if ($tag == 'wpmem_logged_out' && !$attr && !is_user_logged_in()) {
         return do_shortcode($content);
     }
     // handles the 'field' attribute
     if ($field || $tag == 'wpmem_field') {
         if ($id) {
             // we are getting some other user
             if ($id == 'get') {
                 $the_user_ID = isset($_GET['uid']) ? $_GET['uid'] : '';
             } else {
                 $the_user_ID = $id;
             }
         } else {
             // get the current user
             $the_user_ID = get_current_user_id();
         }
         $user_info = get_userdata($the_user_ID);
         // @todo - check this change
         return $user_info ? htmlspecialchars($user_info->{$field}) . do_shortcode($content) : do_shortcode($content);
         // return ( $user_info ) ? htmlspecialchars( $user_info->$field ) . do_shortcode( $content ) : '';
     }
     // logout link shortcode
     if (is_user_logged_in() && $tag == 'wpmem_logout') {
         $link = $url ? wpmem_chk_qstr($url) . 'a=logout' : wpmem_chk_qstr(get_permalink()) . 'a=logout';
         $text = $content ? $content : __('Click here to log out.', 'wp-members');
         return do_shortcode("<a href=\"{$link}\">{$text}</a>");
     }
 }
Beispiel #3
0
/**
 * Handles the logged in status shortcodes.
 *
 * There are two shortcodes to display content based on a user being logged
 * in - [wp-members status=in] and [wpmem_logged_in] (status=in is a legacy
 * shortcode, but will still function). There are several attributes that
 * can be used with the shortcode: in|out, sub for subscription only info,
 * id, and role. IDs and roles can be comma separated values for multiple
 * users and roles. Additionally, status=out can be used to display content
 * only to logged out users or visitors.
 *
 * @since 3.0.0
 *
 * @global object $wpmem The WP_Members object.
 *
 * @param  array  $atts
 * @param  string $content
 * @param  string $tag
 * @return string $content
 */
function wpmem_sc_logged_in($atts, $content = null, $tag = 'wpmem_logged_in')
{
    global $wpmem;
    // Handles the 'status' attribute.
    if (isset($atts['status']) || $tag == 'wpmem_logged_in') {
        $do_return = false;
        // If there is a status attribute of "out" and the user is not logged in.
        $do_return = isset($atts['status']) && $atts['status'] == 'out' && !is_user_logged_in() ? true : $do_return;
        if (is_user_logged_in()) {
            // In case $current_user is not already global
            $current_user = wp_get_current_user();
            // If there is a status attribute of "in" and the user is logged in.
            $do_return = isset($atts['status']) && $atts['status'] == 'in' ? true : $do_return;
            // If using the wpmem_logged_in tag with no attributes & the user is logged in.
            $do_return = $tag == 'wpmem_logged_in' && !$atts ? true : $do_return;
            // If there is an "id" attribute and the user ID is in it.
            if (isset($atts['id'])) {
                $ids = explode(',', $atts['id']);
                foreach ($ids as $id) {
                    if (trim($id) == $current_user->ID) {
                        $do_return = true;
                    }
                }
            }
            // If there is a "role" attribute and the user has a matching role.
            if (isset($atts['role'])) {
                $roles = explode(',', $atts['role']);
                foreach ($roles as $role) {
                    if (in_array(trim($role), $current_user->roles)) {
                        $do_return = true;
                    }
                }
            }
            // If there is a status attribute of "sub" and the user is logged in.
            if (isset($atts['status']) && $atts['status'] == 'sub' && is_user_logged_in()) {
                if (defined('WPMEM_EXP_MODULE') && $wpmem->use_exp == 1) {
                    if (!wpmem_chk_exp()) {
                        $do_return = true;
                    } elseif ($atts['msg'] == true) {
                        $do_return = true;
                        $content = wpmem_sc_expmessage();
                    }
                }
            }
        }
        // Return content (or empty content) depending on the result of the above logic.
        return $do_return ? do_shortcode($content) : '';
    }
}