Skip to:
Content
Pages
Categories
Search
Top
Bottom

a template question


  • grosbouff
    Participant

    @grosbouff

    Hi; i’m creating a new plugin that uses templates.

    I don’t like the fact that when you install a BP plugin, you have to move its templates to the current theme directory.

    So I would like to do this :

    check if the current theme has specific templates for the plugin

    if not, load the templates that are INSIDE the plugin directory.

    I try with this

    define ( ‘BP_MYPLUGIN_NAME’, ‘bp-myplugin’ );

    define ( ‘BP_MYPLUGIN_DIR’, WP_PLUGIN_DIR . ‘/’ . BP_MYPLUGIN_NAME );

    define ( ‘BP_MYPLUGIN_URL’, WP_PLUGIN_URL . ‘/’ . BP_MYPLUGIN_NAME );

    *********

    if ( !locate_template( array( ‘BP_MYPLUGIN_NAME.’/create.php’ ), false ))

    load_template(apply_filters( ‘my_plugin_template_create’, BP_MYPLUGIN_DIR.’/theme/create’));

    else

    bp_core_load_template( apply_filters( ‘my_plugin_template_create’, ‘BP_MYPLUGIN_NAME.’/create’ ) );

    But it does not work.

    Could anyone help ?

    Thanks !

Viewing 5 replies - 1 through 5 (of 5 total)
  • Yeah, have a look at how I”ve done this: http://svn.wp-plugins.org/achievements/tags/1.2/dp-achievements.php

    Look at my dpa_screen() and dpa_screen_filter_template() functions – be sure to also do the add_action(‘bp_located_template’, …) if you just copy and paste that.


    grosbouff
    Participant

    @grosbouff

    Hey DJPaul, thanks for your answer !

    There something good for me in there :)

    But, I still have a little problem.

    In my plugin php files;

    I use the bp_core_load_template() function to load my template, which is filtered by your (modified) function :

    function classified3s_screen_filter_template( $located_template, $template_name ) {

    if ( !empty( $located_template ) )

    return $located_template;

    if ( $bp->current_component != $bp->classified3s->slug )

    return false;

    $template_path = BP_CLASSIFIED3S_PLUGIN_DIR.”/theme/$template_name[0]”;

    if ( file_exists( $template_path ) ) {

    return $template_path;

    }

    return false;

    }

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

    and it works.

    So

    bp_core_load_template( apply_filters( ‘classified3s_template_classified3s_directory’, ‘directories/classified3s/index’ ) );

    loads the file inside myplugin/theme/classified3s/index.php because there is no specific themes files for the plugin in my current theme.

    Great.

    But inside that index.php file, I call another template :

    <?php bp_core_load_template( apply_filters( ‘classified3s_template_classified3s_loop’, ‘classified3s/classified3s-loop.php’ ) );?>

    which loads… nothing.

    Don’t know if you can see where the problem is.

    Thanks man !

    Also, this should be added to the core function. Check if the plugin contains a “theme” directory where are stored the default template files if no templates are found in the current theme.

    Because it’s annoying to have to move the files after having installed the plugin.

    Not sure from a quick look, hopefully someone can clue us in


    grosbouff
    Participant

    @grosbouff

    Maybe have I to use the locate_template in the template instead of bp_core_load_template ?


    grosbouff
    Participant

    @grosbouff

    (PS : the problem will be the same with the loaded CSS and JS files. You should really add something to the buddypress core to make this easier).

    Here’s how I did to load CSS & JS from the plugin directory (default) if there’s no files for the plugin into the current theme :

    define ( ‘BP_QUICKPRESS_PLUGIN_NAME’, ‘buddypress-quickpress’ );

    define ( ‘BP_QUICKPRESS_PLUGIN_URL’, WP_PLUGIN_URL . ‘/’ . BP_QUICKPRESS_PLUGIN_NAME );

    wp_enqueue_script( ‘bp-quickpress-expandable-tree-js’, apply_filters(‘bp_quickpress_locate_js’,’_inc/js/expandableTree.js’),array(‘jquery’), ‘1.0’ );

    wp_enqueue_style( ‘bp-quickpress-screen’, apply_filters(‘bp_quickpress_locate_css’,’style.css’) );

    function bp_quickpress_load_template_files($file) {

    $theme_path = STYLESHEETPATH . ‘/quickpress’;

    $theme_url = get_stylesheet_directory_uri() . ‘/quickpress’;

    if ( file_exists( $theme_path.’/’.$file ) ) {

    return $theme_url.’/’.$file;

    }else {

    return BP_QUICKPRESS_PLUGIN_URL.’/theme/quickpress/’.$file;

    }

    }

    add_filter(‘bp_quickpress_locate_js’,’bp_quickpress_load_template_files’);

    add_filter(‘bp_quickpress_locate_css’,’bp_quickpress_load_template_files’);

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘a template question’ is closed to new replies.
Skip to toolbar