BP_Component::includes( array $includes = array() )

Include required files.

Description

Please note that, by default, this method is fired on the bp_include hook, with priority 8. This is necessary so that core components are loaded in time to be available to third-party plugins. However, this load order means that third-party plugins whose main files are loaded at bp_include with priority 10 (as recommended), will not be loaded in time for their includes() method to fire automatically.

For this reason, it is recommended that your plugin has its own method or function for requiring necessary files. If you must use this method, you will have to call it manually in your constructor class, ie $this->includes();

Note that when you pass an array value like ‘actions’ to includes, it looks for the following three files (assuming your component is called ‘my_component’):

  • ./actions
  • ./bp-my_component/actions
  • ./bp-my_component/bp-my_component-actions.php

Parameters

$includes

(Optional) An array of file names, or file name chunks, to be parsed and then included.

Default value: array()

Source

File: bp-core/classes/class-bp-component.php

355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
public function includes( $includes = array() ) {
 
    // Bail if no files to include.
    if ( ! empty( $includes ) ) {
        $slashed_path = trailingslashit( $this->path );
 
        // Loop through files to be included.
        foreach ( (array) $includes as $file ) {
 
            $paths = array(
 
                // Passed with no extension.
                'bp-' . $this->id . '/bp-' . $this->id . '-' . $file  . '.php',
                'bp-' . $this->id . '-' . $file . '.php',
                'bp-' . $this->id . '/' . $file . '.php',
 
                // Passed with extension.
                $file,
                'bp-' . $this->id . '-' . $file,
                'bp-' . $this->id . '/' . $file,
            );
 
            foreach ( $paths as $path ) {
                if ( @is_file( $slashed_path . $path ) ) {
                    require( $slashed_path . $path );
                    break;
                }
            }
        }
    }
 
    /**
     * Fires at the end of the includes method inside BP_Component.
     *
     * This is a dynamic hook that is based on the component string ID.
     *
     * @since BuddyPress 1.5.0
     */
    do_action( 'bp_' . $this->id . '_includes' );
}

Changelog

Changelog
Version Description
BuddyPress 1.5.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.