You should be extending BP_Component class to create new components.
Not sure we have a tutorial or clear example of how to extend BP_Component yet.
Are there any existing situations in the code I can look at?
I wrote a page about it in the codex but that page has been completely erased. Here’s the page that had info on extending it and when I went to respond to this topic and post a link I saw the page has been erased.
https://codex.buddypress.org/bp_component/
The revisions are even wiped out.
I wonder if someone deleted it. I don’t know how we’d tell, unless it’s in google’s history.
@johnjamesjacoby ping. Maybe we should disallow page deletion on the codex for non-admins?
If it was deleted it would not have revisions. Page is there.
I’d check out the BP Skeleton Component sample plugin. That should show you how to extend the BP_Component
class for your new plugin.
Thanks everyone, I’m on my way. But, now I’m getting a 500 error on plugin activation. I replaced out the deprecated component creation function above with the following:
define( 'BP_PCN_IS_INSTALLED', 1 );
define( 'BP_PCN_PLUGIN_DIR', dirname( __FILE__ ) );
/* Only load the component if BuddyPress is loaded and initialized. */
function bp_pcn_init() {
// Because the loader file uses BP_Component, it requires BP 1.5 or greater.
if ( version_compare( BP_VERSION, '1.5', 'active_components[$this->id] = '1';
}
function setup_globals() {
global $bp;
// Defining the slug in this way makes it possible for site admins to override it
if ( !defined( 'BP_PCN_SLUG' ) )
define( 'BP_PCN_SLUG', $this->id );
// Set up the $globals array to be passed along to parent::setup_globals()
$globals = array(
'slug' => BP_PCN_SLUG,
'root_slug' => isset( $bp->pages->{$this->id}->slug ) ? $bp->pages->{$this->id}->slug : BP_PCN_SLUG,
'has_directory' => false, // Set to false if not required
'notification_callback' => 'bp_pcn_format_notifications'
);
// Let BP_Component::setup_globals() do its work.
parent::setup_globals( $globals );
}
}
/* load component into $bp global */
function bp_pcn_load_core_component() {
global $bp;
$bp->pcn = new BP_PCN_Component;
}
add_action( 'bp_loaded', 'bp_pcn_load_core_component' );
Anyone know what I’m missing?
Decided to give up modifying my existing plugin and just modify the Skeleton plugin that r-a-y recommended—much better idea. I now have the notification count displaying! No notification text but I’m pretty sure I’ll get there. Thanks all!