Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Group Extension API – Display() under Admin


  • nickpeplow
    Participant

    @nickpeplow

    Hello Buddypress Community!

    I’m having a problem getting a page to display correctly when it’s located under the admin menu of a buddypress group

    Ideal outcome: Page using the Display() method located as a subnav under the admin tab
    Docs referenced: http://codex.buddypress.org/developer/group-extension-api

    – I am using the Group Extension API to create a new page under the ‘admin’ navigation tab of a group
    – From the documentation, I cant see a way to set the location of a Display() to be under “Admin” nav using the __construct()
    – To get a page to appear under “Admin” nav option, It seems I need to apply an edit or create method to it
    – Edit and Create methods include a <form>, I do not want this page to have a form on it, as I’m echoing a shortcode.
    – This shortcode displays correctly when echo’d in a Display() method

    Any idea how I can get just a simple page to display without a form being applied?

    Thanks
    Nick

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

  • danbp
    Participant

    @danbp

    Hi @nickpeplow,

    it’s not possible to add sub nav items with the group API and the only other possibility that eventually could work a day (but not tomorrow 😉 ) would be bp_core_new_subnav_item(), but it is a Todo, as stated in bp-groups-classes.php:3307

    Here are 2 snippets (i tested them within bp-custom.php – BP 2.0.2 Twentythirteen)

    This one let you add some content on the new screen.

    function add_admin_tab_content() {
    	echo 'Quis scelerisque lacinia tempus nullam felis';
    	}
    add_action( 'groups_custom_edit_steps', 'add_admin_tab_content' );

    This one create a sub nav item when you’re on the group admin screen

    
    function bpfr_add_page_to_group() {
    	
    	if ( class_exists( 'BP_Group_Extension' ) ) :
      
    class My_Custom_Group_Extension extends BP_Group_Extension {
     
        function __construct() {
            $args = array(  
    			'slug' => 'houba-houba',
    			'parent_slug' => 'admin', // URL slug of the parent nav item
                'nav_item_position' => 100,
                'screens' => array(
                    'edit' => array(
                        'name' => 'Houba Houba', // the tab name                 
                    ),
                    'create' => array(
                        'position' => 100,
                    ),
                ),
            );
            parent::init( $args );
        }
     
    
         function settings_screen( $group_id ) {
    		// don't remove this function
               }  
    } // end of class
    
    		bp_register_group_extension( 'My_Custom_Group_Extension' );
     
    	endif;
    }
    add_filter('bp_groups_default_extension', 'bpfr_add_page_to_group' );

    Once installed you will see that the “save change” button is still there. This button is contextual and cannot be removed, as it is used elsewhere. So you make it diseapear with the appropriate CSS with display:none!important; on the div with the ID of your/each group save button.

    If you want to display that only for one group, you add a condition to bp_register_group_extension like this

    } // end class
    ////////////////////////////////////////////////////////////
    /* display content only in one group (ex. group_ID is 14) */
    ////////////////////////////////////////////////////////////
         
        // check for a group ID
            if( bp_has_groups() ) {
                // Grab current group ID
                bp_the_group();
                $group_id = bp_get_group_ID();
            }
         
        //////////////////////////////////////////
        /* apply our changes only to this group */
        //////////////////////////////////////////
         
            // conditionnal action
            if ( $group_id == 14 ) {   
                bp_register_group_extension( 'My_Custom_Group_Extension' );          
            } 
    

    Voilà ! May this help.

    More BP tips and tricks on my blog. (FR, sometimes EN – but php is always in english)


    nickpeplow
    Participant

    @nickpeplow

    Hi Dan

    Thanks so much for looking into this so promptly, I really appreciate it!

    I have added the code, but am still running into the same issue as the method you are using to create this page is edit –‘edit’ => array(

    It therefore still includes the form action as a wrapper. As the shortcode I’m including (WP Job Manager – Submit Job Listing) has a form in it, im getting a “Are you sure you want to do this?” when submitting that form.

    <form action=”http://mydomainwashere.com/groups/group-slug/admin/houba-houba&#8221; name=”group-settings-form” id=”group-settings-form” class=”standard-form” method=”post” enctype=”multipart/form-data” role=”main”>


    danbp
    Participant

    @danbp

    I guess you have to remove your custom code before using my snippets.

    The 1st function let you add custom content on the tab. It’s not a WP page on which you can use a shortcode to call your job form.

    I’ll check that.


    shanebp
    Moderator

    @shanebp

    Interesting thread.
    This would be my approach:

    function bpfr_add_page_to_group() {
    	
    	if ( class_exists( 'BP_Group_Extension' ) ) :
    		  
    		class Bongo_Group_Extension extends BP_Group_Extension {
    		 
    		    function __construct() {
    		        $args = array(  
    		  	    'slug'              => 'bongo',
    			    'parent_slug'       => 'admin', 
    		            'nav_item_position' => 100,
    		
    		            'screens' => array(
    		                'edit' => array(
    		                    'name' => 'Bongo', // the tab name                 
    		                ),
    		            ),
    		        );
    		        parent::init( $args );
    		    }
    		 
    		
    		    function settings_screen( $group_id = NULL ) {
    				// don't remove this function
                                    //  = NULL is necessary to avoid Strict Standards warning
    		    }  
    		} // end of class
    
    		bp_register_group_extension( 'Bongo_Group_Extension' );
     
    	endif;
    }
    add_filter('bp_groups_default_extension', 'bpfr_add_page_to_group' );

    Then, to avoid loading the form, create a template overload of
    \buddypress\bp-templates\bp-legacy\buddypress\groups\single\admin.php

    And add a conditional check of the action_variable.
    Just before the form tag, add:

    <?php 
    global $bp; 
    if( $bp->action_variables[0] != 'bongo' ) :
    ?>

    Right after the form close tag, add:

    <?php else :
    	echo 'this is the bongo page'; 
    endif;
    ?>

    Awkward, but seems to work.
    The Group_Extension_API does need some work re making it easier to add tabs and tab counts.
    I think the core devs are aware of this, but perhaps an enhancement ticket is in order?


    @danbp

    >The 1st function let you add custom content on the tab.
    afaik – that function adds the content on every page under ‘Admin’.


    danbp
    Participant

    @danbp

    I tested and get correctly anything from the plugin. What i did:

    – installed the plugin
    – create a new page called job
    – added the shortcode [jobs] [submit_job_form] [job_dashboard]
    – saved

    In bp-custom i added this snippet, similar to the previous but who let’s you add a page to a group.

    function bpfr_add_page_to_group() {
    	
    	if ( class_exists( 'BP_Group_Extension' ) ) :
    	
    	class BPFR_Custom_Group_Extension extends BP_Group_Extension {
    		
    		//   building the tab 
    		
    		function __construct() {
    			$args = array(
                'slug' => 'jobs', // tab slug - mandatory
                'name' => 'Job Center'  // tab name - mandatory        
    			);
    			parent::init( $args );
    		} // end construct()
    		
    		
    		// content display 		 
    		
    		function display() {    
    			
    			// grab page or post ID
    			$id = 240;  
    			$p = get_post($id);     
    			
    			// output the title     
    			echo '<h3>'.apply_filters('the_content', $p->post_title).'</h3>';
    			// output the post      
    			echo apply_filters('the_content', $p->post_content); 
    			// end option 
    			
    		}   // end display() 
    	} // end class	
      
    		bp_register_group_extension( 'BPFR_Custom_Group_Extension' ); 
     
    	endif; 
    }
    add_filter('bp_groups_default_extension', 'bpfr_add_page_to_group' );

    So far i see everything is working !

    EDIT: working yes, but not on the admin tab.

    @shanebp
    you’re right, but it’s only an example for how things can be done. 😉


    danbp
    Participant

    @danbp

    @shanebp on his best, a long time ago… but this was before BP 1.8. Today it’s a bit different with the Group API.


    nickpeplow
    Participant

    @nickpeplow

    Thanks to Dan & Shane for both taking a look into my issue! You have both been unexpectedly detailed in your response and its much appreciated

    I think for now, my best option would be to continue with the content being shown on the Display() tab, but with it hidden to those who are not admins (purpose was to allow admins to submit jobs, in the admin backend)

    The reason I’m a bit hesitant to display another page is because its one more thing for me to track, exclude from search etc, plus as it would be outside of the buddypress loop I would not be able to easily include any of the $bp values if required in future (e.g. group name).


    nickpeplow
    Participant

    @nickpeplow

    Obviously open to other suggestions 🙂

    Dan, your bp_register_group_extension function from your first response will come in very handy as I can see myself modifying it to restrict the display() page to just admins.


    danbp
    Participant

    @danbp

    I’m on another path by trying to get the plugin template of job-dashboard, via my child-theme… and by keeping the admin sub tab in place.
    Half done for the moment, but not sure to get a satisfying result without hacking the plugin to get it BP compliant.

    My first suggestion is really working well on a extra tab and adding restriction to a wp page is really easy to achieve. So i would probably not investigate much longer. It’s cold and rainy, so i can work on it. But if the sun comes out, i go motorbiking. 😉


    nickpeplow
    Participant

    @nickpeplow

    Got it working on a regular tab, thanks for all the suggestions!

    Will keep an eye on any changes to the menu in future that might apply to this


    danbp
    Participant

    @danbp

    I was unable to get a correctly working form when i use the plugin page on the ADMIN tab. It shows only. So i revert back to get the job manager on a separate page who shows up on a group page.
    The snippet is set for admins only and to work only on group ID 13 and 9.

    Anything is commented so you can modify that

    Here a slightly modified version of my previous.
    Install the plugin and use the shortcodes as indicated by the author and add the snippet to theme’s functions.php or bp-custom.php

    function bpfr_add_page_to_group() {
    	global $bp;		
    	if ( bp_is_active( 'groups' ) )
    	
    	// allow oly admin's 
    	// this works also on single install
    	if ( is_super_admin() ) :
    	
    	if ( class_exists( 'BP_Group_Extension' ) ) :
    	
    	class Job_Center_Group_Extension extends BP_Group_Extension {	
    	 
    	 //building the tab		
    		function __construct() {
    			$args = array(
                'slug' 		  => 'jobcenter',  // tab slug - mandatory
                'name'        => 'Job Center', // tab name - mandatory  
    			//'parent_slug' => 'admin',  
    			
    			);
    			parent::init( $args );
    		} // end construct()		
    	
    	  // content display		
    		function display() {   
    			
    			// grab page or post ID
    			$id = 240; 
    			$p = get_post($id); 
    
    			// output the post		
    		
    			echo apply_filters('the_content', $p->post_content);
    		}   // end display()
    	} // end class	
    	
    	//display content only in one group (ex. group_ID is 14) 	
        // check for a group ID
    	if( bp_has_groups() ) {
    		// Grab current group ID
    		bp_the_group();
    		$group_id = bp_get_group_ID();
    	}	
    	
        // apply our changes only to this group	
    	// conditionnal action
    	if ( $group_id == 9 OR $group_id == 13 ) {   
    		bp_register_group_extension( 'Job_Center_Group_Extension' );          
    	}      
    	
    	endif;
    	endif;
    }
    add_filter('bp_groups_default_extension', 'bpfr_add_page_to_group' );

    If you want to modify one of the plugin templates, make a copy of wp-job-manager/templates/ folder in your child theme and rename it job_manager ( ! no other name).

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Resolved] Group Extension API – Display() under Admin’ is closed to new replies.
Skip to toolbar