• Hi,
    I am using a php function which lets me restrict some parts of my posts to be visible only to the site members. In my post editor I put the restricted content between [member] and [/member] short codes and when a non-member visits the page, he sees a text instead of the restricted content which says “You need to be a member to see this part”.
    I need to include the social login widget within that message which a non-member sees on the page. I don’t know how to do that.
    I need a kind helping hand in this regard. Lots of thanks in advance.
    The restricting php function that I use is as follows (I have included it in my theme’s function.php file):

    add_shortcode( 'member', 'member_check_shortcode' );
    
    function member_check_shortcode( $atts, $content = null ) {
    	 if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
    		return do_shortcode($content);
    	return '<div style="background-color: #DDEEFF; padding: 10px; border: 2px dotted navy"><h4 style="background-color: navy;padding: 0px;text-align: center"><b><font color="white">You need to be a member to see this part</font></b></h4></div>';
    }

    I need to show the social login widget in that message box which replaces restricted content. Thanks for your kind help in advance.
    Best,
    Omid

    https://www.ads-software.com/plugins/wordpress-social-login/

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can try outputting the login form with wp_login_form(); function right where you need it. The WSL social block should be there.

    Thread Starter Omid Reza Rajabi

    (@orrajabi)

    Thanks for your reply. Since I am still very novice in coding, could you please give me more specific instructions as what to do and where and how to include it?
    Thanks a lot

    Try this:

    add_shortcode( 'member', 'member_check_shortcode' );
    
    function member_check_shortcode( $atts, $content = null ) {
    
        if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
            return do_shortcode($content);
    
        // prepare arguments for login form
        // see https://codex.www.ads-software.com/Function_Reference/wp_login_form
        // for all parameters
        $args = array(
            'echo' => false,
        );
    
        // get login form html
        $login_form = wp_login_form( $args );
    
        // prepare all html
        $output = '<div style="background-color: #DDEEFF; padding: 10px; border: 2px dotted navy">';
        $output .= '<h4 style="background-color: navy;padding: 0px;text-align: center; font-weight: bold; color: white;">You need to be a member to see this part</h4>';
        $output .= $login_form;
        $output .= '</div>';
    
        return $output;
    
    }

    Haven’t tested it but should work. Let me know if anything is broken.

    And it would be good to move the styles out of the tags (div/h4) and place them in your stylesheet.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘integrating the widget within a php function code’ is closed to new replies.