Skip to:
Content
Pages
Categories
Search
Top
Bottom

Styling BuddyPress Login Widget


  • Jld142
    Participant

    @jld142

    Hello guys,

    I have been using WordPress for about 8 months now and have just started using child themes to allow updating my code a lot easier – previously i used to ‘hack’ the code and edit core files.

    I use the Avada theme and have successfully created a child theme. I am now looking to edit the BuddyPress Login Widget via the child themes functions.php file.

    I have been doing some reading on these forums and have seen people talking about adding BuddyPress folders within a child theme.. Can someone clear this up for me please ?

Viewing 6 replies - 1 through 6 (of 6 total)

  • @mercime
    Participant

    @mercime

    @jld142 Based on title of this topic, you only want to change the styling aka CSS. If that’s the case, you do not need to add any BP folders/files in your child theme. Just override the style in your theme’s style.css file or whatever stylesheet is enqueued in your premium theme.

    If however, you want to change the markup or functionality in some form or the other, then you’d have to look at https://buddypress.trac.wordpress.org/browser/tags/2.3.2/src/bp-core/bp-core-widgets.php#L22 and make the fix in your child theme’s functions.php – no need to copy over any BP folder.


    Jld142
    Participant

    @jld142

    @mercime thank you for the response maybe I should have made the title clearer.

    I need to add more functionality to the widget, mainly a notification counter. I don’t want it displayed in the administration header as this will be hidden.


    Jld142
    Participant

    @jld142

    This is my current code:

    <?php
    
    /* Link parent CSS file */
    add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
    function enqueue_parent_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
    }
    
    /* Count number of user notifications */
    function cg_current_user_notification_count() {
        $notifications = bp_core_get_notifications_for_user(bp_loggedin_user_id(), 'object');
        $count = !empty($notifications) ? count($notifications) : 0;
     
        echo $count;
    }
    
    /* Remove register BuddyPress Widget creator */
    function remove_bp_core_register_widgets() {
        remove_action(bp_core_register_widgets());
    }
    add_action('init','remove_bp_core_register_widgets()');
    
    function new_bp_core_register_widgets() {
    	add_action('widgets_init', create_function('', 'return register_widget("new_BP_Core_Login_Widget");') );
    }
    add_action( 'bp_register_widgets', 'bp_core_register_widgets' );
    
    /* New BuddyPress Login Widget */
    class new_BP_Core_Login_Widget extends WP_Widget {
    
    	/**
    	 * Constructor method.
    	 */
    	public function __construct() {
    		parent::__construct(
    			false,
    			_x( '(BuddyPress) Log In', 'Title of the login widget', 'buddypress' ),
    			array(
    				'description' => __( 'Show a Log In form to logged-out visitors, and a Log Out link to those who are logged in.', 'buddypress' ),
    				'classname' => 'widget_bp_core_login_widget buddypress widget',
    			)
    		);
    	}
    
    	/**
    	 * Display the login widget.
    	 *
    	 * @see WP_Widget::widget() for description of parameters.
    	 *
    	 * @param array $args Widget arguments.
    	 * @param array $instance Widget settings, as saved by the user.
    	 */
    	public function widget( $args, $instance ) {
    		$title = isset( $instance['title'] ) ? $instance['title'] : '';
    
    		/**
    		 * Filters the title of the Login widget.
    		 *
    		 * @since BuddyPress (1.9.0)
    		 * @since BuddyPress (2.3.0) Added 'instance' and 'id_base' to arguments passed to filter.
    		 *
    		 * @param string $title    The widget title.
    		 * @param array  $instance The settings for the particular instance of the widget.
    		 * @param string $id_base  Root ID for all widgets of this type.
    		 */
    		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
    
    		echo $args['before_widget'];
    
    		echo $args['before_title'] . esc_html( $title ) . $args['after_title']; ?>
    
    		<?php if ( is_user_logged_in() ) : ?>
    
    			<?php
    
     		 	/**
    		 	 * Fires before the display of widget content if logged in.
    		 	 *
    		 	 * @since BuddyPress (1.9.0)
    		 	 */
    			do_action( 'bp_before_login_widget_loggedin' ); ?>
    
    			<div class="bp-login-widget-user-avatar">
    				<a href="<?php echo bp_loggedin_user_domain(); ?>">
    					<?php bp_loggedin_user_avatar( 'type=thumb&width=50&height=50' ); ?>
    				</a>
    			</div>
    
    			<div class="bp-login-widget-user-links">
    				<div class="bp-login-widget-user-link"><?php echo bp_core_get_userlink( bp_loggedin_user_id() ); ?></div>
    				<p>TEST</p>
    				<div class="bp-login-widget-user-logout"><a class="logout" href="<?php echo wp_logout_url( bp_get_requested_url() ); ?>"><?php _e( 'Log Out', 'buddypress' ); ?></a></div>
    			</div>
    
    			<?php
    
    			/**
    		 	 * Fires after the display of widget content if logged in.
    		 	 *
    		 	 * @since BuddyPress (1.9.0)
    		 	 */
    			do_action( 'bp_after_login_widget_loggedin' ); ?>
    
    		<?php else : ?>
    
    			<?php
    
    			/**
    		 	 * Fires before the display of widget content if logged out.
    		 	 *
    		 	 * @since BuddyPress (1.9.0)
    		 	 */
    			do_action( 'bp_before_login_widget_loggedout' ); ?>
    
    			<form name="bp-login-form" id="bp-login-widget-form" class="standard-form" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
    				<label for="bp-login-widget-user-login"><?php _e( 'Username', 'buddypress' ); ?></label>
    				<input type="text" name="log" id="bp-login-widget-user-login" class="input" value="" />
    
    				<label for="bp-login-widget-user-pass"><?php _e( 'Password', 'buddypress' ); ?></label>
    				<input type="password" name="pwd" id="bp-login-widget-user-pass" class="input" value="" <?php bp_form_field_attributes( 'password' ) ?> />
    
    				<div class="forgetmenot"><label><input name="rememberme" type="checkbox" id="bp-login-widget-rememberme" value="forever" /> <?php _e( 'Remember Me', 'buddypress' ); ?></label></div>
    
    				<input type="submit" name="wp-submit" id="bp-login-widget-submit" value="<?php esc_attr_e( 'Log In', 'buddypress' ); ?>" />
    
    				<?php if ( bp_get_signup_allowed() ) : ?>
    
    					<span class="bp-login-widget-register-link"><?php printf( __( '<a href="%s" title="Register for a new account">Register</a>', 'buddypress' ), bp_get_signup_page() ); ?></span>
    
    				<?php endif; ?>
    
    			</form>
    
    			<?php
    
    			/**
    		 	 * Fires after the display of widget content if logged out.
    		 	 *
    		 	 * @since BuddyPress (1.9.0)
    		 	 */
    			do_action( 'bp_after_login_widget_loggedout' ); ?>
    
    		<?php endif;
    
    		echo $args['after_widget'];
    	}
    
    	/**
    	 * Update the login widget options.
    	 *
    	 * @param array $new_instance The new instance options.
    	 * @param array $old_instance The old instance options.
    	 * @return array $instance The parsed options to be saved.
    	 */
    	public function update( $new_instance, $old_instance ) {
    		$instance             = $old_instance;
    		$instance['title']    = isset( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '';
    
    		return $instance;
    	}
    
    	/**
    	 * Output the login widget options form.
    	 *
    	 * @param $instance Settings for this widget.
    	 */
    	public function form( $instance = array() ) {
    
    		$settings = wp_parse_args( $instance, array(
    			'title' => '',
    		) ); ?>
    
    		<p>
    			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'buddypress' ); ?>
    			<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>" /></label>
    		</p>
    
    		<?php
    	}
    }
    
    ?>

    I was trying to following the below guide to remove the function that initializes the login widget and then redirect it to my own new one:

    http://venutip.com/content/right-way-override-theme-functions

    Obviously hasn’t worked. Any ideas ?


    Jld142
    Participant

    @jld142

    Anyone have any ideas ?


    Ingram_AV_98
    Participant

    @ingram_av_98

    Hi,

    Did you have any luck with this?

    I believe I had a similar issue and I managed to unregister the default BP Login Widget, and register my own so I could customise it. My login widget was a duplicate of theirs with many elements swapped around, and some added html.

    I can paste my code if it helps, it turns out it was really simple.

    I should have put it in a plugin, but it’s all in the functions.php for now as I’m building a bespoke theme.


    maxgx
    Participant

    @maxgx

    hi Ingram,
    would you be so kind to paste your code here?
    i’m after the very same thing, but have been unable to unregister BP’s widget and replace it with mine.
    i don’t mind storing it in functions.php too.
    thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar