Skip to:
Content
Pages
Categories
Search
Top
Bottom

create subnav not working with child theme

  • Avatar of warut
    warut
    Participant

    @warut

    I make buddypress badge plugin with subnav in main Profile nav.

    with buddypress default theme it work fine but redirect to main page when using with any child theme.

Viewing 14 replies - 1 through 14 (of 14 total)
  • Avatar of warut
    warut
    Participant

    @warut

    here are my code :

    it work on bp default theme but going to mainpage after click Profile when using child theme.

    anyone know the problem? thanks

    /


    /

    function bp_badge_setup_nav() {

    global $bp;

    $profile_link = $bp->loggedin_user->domain . $bp->profile->slug . ‘/’;

    /* Create sub nav item for this component */

    bp_core_new_subnav_item( array(

    ‘name’ => __( ‘Badge’, ‘bp-badge’ ),

    ‘slug’ => ‘badge’,

    ‘parent_slug’ => $bp->profile->slug,

    ‘parent_url’ => $profile_link,

    ‘screen_function’ => ‘bp_badge_screen’,

    ‘position’ => 50,

    ‘user_has_access’ => bp_is_my_profile()

    ) );

    }

    add_action( ‘wp’, ‘bp_badge_setup_nav’, 2);

    add_action( ‘admin_menu’, ‘bp_badge_setup_nav’, 2 );

    /


    /

    function bp_badge_load_template_filter( $found_template, $templates ) {

    global $bp;

    if ( $bp->current_component != $bp->profile->slug && $bp->current_action !=‘badge’)

    return $found_template;

    foreach ( (array) $templates as $template ) {

    if ( file_exists( STYLESHEETPATH . ‘/’ . $template ) )

    $filtered_templates[] = STYLESHEETPATH . ‘/’ . $template;

    else

    $filtered_templates[] = dirname( __FILE__ ) . ‘/templates/’ . $template;

    }

    $found_template = $filtered_templates[0];

    return apply_filters( ‘bp_badge_load_template_filter’, $found_template );

    }

    add_filter( ‘bp_located_template’, ‘bp_badge_load_template_filter’, 10, 2 );

    /


    /

    function bp_badge_screen() {

    global $bp;

    /* Add a do action here, so your component can be extended by others. */

    do_action( ‘bp_badge_screen’ );

    /* This is going to look in wp-content/plugins/[plugin-name]/includes/templates/ first */

    bp_core_load_template( apply_filters( ‘bp_badge_template_screen’, ‘badge/screen’ ) );

    }

    Avatar of gregfielding
    gregfielding
    Participant

    @gregfielding

    @warut

    Are you having any luck with this?

    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    @warut

    Don’t use STYLESHEETPATH, use locate_template().

    Avatar of warut
    warut
    Participant

    @warut

    Thanks r-a-y !!!

    the problem is it cant find home.php in child theme so using locate_template() (as r-a-y recommend) to find template in parent theme is fix this.

    Avatar of gregfielding
    gregfielding
    Participant

    @gregfielding

    @warut

    Getting better…now I can see “Badge” under the profile menu…but when I click on THAT, I get redirected back to the front page…

    Avatar of warut
    warut
    Participant

    @warut

    do you use version 1.2? i test with child theme “BuddyPress Widget Theme 1.2.1″ and it work fine.

    Avatar of gregfielding
    gregfielding
    Participant

    @gregfielding

    1.2 is what’s in the directory.

    Avatar of pcwriter
    pcwriter
    Participant

    @pcwriter

    @warut

    Just tested v1.2 with BuddyPress Widget Theme (and my child theme) and get the same problem: redirect to home page whenever i click on a “Badge” link in profile or adminbar.

    Avatar of gregfielding
    gregfielding
    Participant

    @gregfielding

    @warut

    Is there some other place we should be getting this from?

    Avatar of warut
    warut
    Participant

    @warut

    sorry for that :| it not found badge/screen in child theme

    solution

    option 1. change the way loading template (already coding)

    option 2. copy badge/ from /buddypress-badge/includes/templates/ to your theme directory

    i will update by option 1 but i notice others bug

    anyone get error

    “Warning: Cannot modify header information – headers already sent by (output started at /home/tripsbuz/public_html/wp-content/themes/bp-default/header.php:3) in /home/tripsbuz/public_html/wp-includes/pluggable.php on line 868″

    i get it after change from use STYLESHEETPATH to use locate_template().

    Avatar of warut
    warut
    Participant

    @warut

    this code working with child theme (working but show error) but get another error

    @r-a-y is it correct method using locate_template()?

    Warning: Cannot modify header information – headers already sent by (output started at /home/tripsbuz/public_html/wp-content/themes/bp-default/header.php:3) in /home/tripsbuz/public_html/wp-includes/pluggable.php on line 868


    code


    function bp_badge_load_template_filter( $found_template, $templates ) {

    global $bp;

    if ( $bp->current_component != $bp->profile->slug && $bp->current_action !=‘badge’)

    return $found_template;

    locate_template( $templates, true );

    }

    add_filter( ‘bp_located_template’, ‘bp_badge_load_template_filter’, 10, 2 );

    function bp_gifts_load_subtemplate( $template_name ) {

    if ( file_exists(STYLESHEETPATH . ‘/’ . $template_name . ‘.php’)) {

    $located = STYLESHEETPATH . ‘/’ . $template_name . ‘.php’;

    echo STYLESHEETPATH . ‘/’ . $template_name . ‘.php’;

    } else if ( file_exists(TEMPLATEPATH . ‘/’ . $template_name . ‘.php’) ) {

    $located = TEMPLATEPATH . ‘/’ . $template_name . ‘.php’;

    echo TEMPLATEPATH . ‘/’ . $template_name . ‘.php’;

    } else{

    $located = dirname( __FILE__ ) . ‘/templates/’ . $template_name . ‘.php’;

    //echo dirname( __FILE__ ) . ‘/templates/’ . $template_name . ‘.php’;

    }

    include ($located);

    }

    function bp_badge_screen() {

    global $bp;

    do_action( ‘bp_badge_screen’ );

    bp_gifts_load_subtemplate( apply_filters( ‘bp_badge_template_screen’, ‘badge/screen’ ), true );

    }

    Avatar of warut
    warut
    Participant

    @warut

    I found this solution from web and it fix “Warning: Cannot modify header information” error.

    Is this a right solution ? because it hack wp file

    if this a best solution, if will update to v1.3 with upper code.


    for all those that have the error that says: bla bla bla on line 3 on header.php…. here is the solution:

    edit the file wp-includes/pluggable.php

    in line 863 replace:

    if ( $is_IIS ) {

    header(“Refresh: 0;url=$location”);

    } else {

    if ( php_sapi_name() != ‘cgi-fcgi’ )

    status_header($status); // This causes problems on IIS and some FastCGI setups

    header(“Location: $location”, true, $status);

    }

    with this:

    if( !headers_sent() ).

    {

    if ( $is_IIS ) {

    header(“Refresh: 0;url=$location”);

    } else {

    if ( php_sapi_name() != ‘cgi-fcgi’ )

    tatus_header($status); // This causes problems on IIS and some FastCGI setups

    header(“Location: $location”, true, $status);

    }


    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    @warut

    Sorry for telling you to use locate_template(). I didn’t read the thread properly.

    You don’t need the bp_badge_load_template_filter() function. It’s only needed for core components. Since your plugin is a subnav of a core component you can delete this function.

    Also, you need to tell your users to move the “badge” directory from the “includes/templates” folder into the child theme.

    Or you can use the following in your bp_badge_screen() function:

    function bp_badge_screen() {
    global $bp;

    /* Add a do action here, so your component can be extended by others. */

    do_action( 'bp_badge_screen' );

    add_action( 'bp_template_content', 'bp_badge_screen_content' );
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }

    function bp_badge_screen_content() {
    //the body contents of /badge/screen.php
    }

    Avatar of warut
    warut
    Participant

    @warut

    after searching all day ! finally done

    Thanks for your help again r-a-y :)

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

You must be logged in to reply to this topic.