Skip to:
Content
Pages
Categories
Search
Top
Bottom

Unable to find BP_Group_Extention


  • Jimtrim
    Participant

    @jimtrim

    When I try to extend Buddypress’ groups, I get false from the function-call class_exists( 'BP_Group_Extension' ). The function is called during my plugin initiation, and I am able to do other Buddypress-calls, like xprofile_insert_field(...).

    I’ve also tried running

    if ( class_exists( 'BP_Group_Extension' ) ) {
        ...
    }

    at the end of my main plugin-file, still returning false.

    Any help for getting my plugin to find the BP_Group_Extension-class will be greatly appriciated.

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

  • jessy
    Participant

    @jessy-marco

    This works for me: codex


    Jimtrim
    Participant

    @jimtrim

    That’s the same as I am trying. My problem is that class_exists( 'BP_Group_Extension' ) returns false, which means that what I put in my if never get executed. But I’m happy to hear it’s working for you, what version of BP are you running? And are you running this in a plugin or in a theme?


    shanebp
    Moderator

    @shanebp

    Just to be sure, do you have ‘User Groups’ enabled here /wp-admin/admin.php?page=bp-components ?

    What hook are you using to call your extension ?
    This should work:

    function jim_add_group_extension() { 
       if ( class_exists( 'BP_Group_Extension' ) ) {
        ...
       }
    }
    add_action('bp_init', 'jim_add_group_extension');

    Jimtrim
    Participant

    @jimtrim

    I’m doing a call to bp_register_group_extension( 'EP_Group_Tasks' ); with a class I want to extend the BP_Group_Extensionclass. Full code of the file:

    <?php
    /**
     * User: jimtrim
     * Date: 11/11/14
     * Time: 09:17
     */
    
    if ( class_exists( 'BP_Group_Extension' ) ) {
    
    	class BP_Group_Tasks extends BP_Group_Extension{
    		/**
    		 * Here you can see more customization of the config options
    		 */
    		function __construct() {
    			$args = array(
    				'slug'              => 'tasks',
    				'name'              => __('Tasks', 'revyweb'),
    				'nav_item_position' => 90,
    				'screens'           => array(
    					'create' => array(
    						'name'        => __('Create task', 'revyweb'),
    						'submit_text' => __('Save task', 'revyweb')
    					),
    					'edit' => array(
    						'name'        => __('Edit task', 'revyweb'),
    						'submit_text' => __('Save task', 'revyweb')
    					),
    					'admin' => array(
    						'name'        => __('Administer task', 'revyweb'),
    						'submit_text' => __('Save task', 'revyweb')
    					),
    				),
    			);
    			parent::init( $args );
    		}
    
    		function display() {
    			//get_template_part( 'buddypress/custom/view', 'tasks' );
    			$group_id = bp_get_group_id();
    			echo "GET READY FOR SOME TASKS";
    
    		}
    
    		public function settings_screen( $group_id = null ) {
    
    			//get_template_part( 'buddypress/custom/settings', 'tasks' );
    			$setting = groups_get_groupmeta( $group_id, 'task_name' );
    
    			?>
    				Save your task name here: <input type="text" name="task_name" value="<?php echo esc_attr( $setting ) ?>" />
    			<?php
    
    		}
    
    		function settings_screen_save( $group_id = NULL ) {
    			$setting = '';
    
    			if ( isset( $_POST['task_name'] ) ) {
    				$setting = $_POST['task_name'];
    			}
    
    			groups_update_groupmeta( $group_id, 'task_name', $setting );
    		}
    
    	}
    
    	bp_register_group_extension( 'EP_Group_Tasks' );
    
    } else {
    	$msg = "Class BP_Group_Extension not found for Revyweb_Personal";
    //	trigger_error($msg, E_USER_NOTICE);
    	echo $msg;
    }

    Edit: yes, User Groups are enabled, and I can display user groups on the frontend, but I can’t add my own BP_Group_Extention


    shanebp
    Moderator

    @shanebp

    BP_Group_Extension will not be available until BP is fully loaded.

    Did you try using the function wrapper I provided ?


    Jimtrim
    Participant

    @jimtrim

    I only get fatal error class declarations may not be nested. I that I may have this be a function living in the global scope, but thats extremly ugly OOP-wise.

    Also: according to Group Extension API/ it should not be neccessary, as this method is to declare the class during plugin initiation.


    Jimtrim
    Participant

    @jimtrim

    I’ve tried with putting the function on the global scope, and yes, class_exists( 'BP_Group_Extension' ) now returns true, but there is no added menu item in the groups, and no slug called tasks


    jessy
    Participant

    @jessy-marco

    The latest BP and WP, and thanks to maintainers for updating codex. Pretty sweet.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Unable to find BP_Group_Extention’ is closed to new replies.
Skip to toolbar