Sales Pipeline: Snippets
Add a "Pipelines" menu to the admin toolbar
/**
* Groundhogg Sales Pipelines → WP Admin Bar
*
* Adds a "Pipelines" menu to the admin toolbar with direct links
* to each Groundhogg Sales Pipeline.
*
* Safe to use as a WPCode snippet. Does not modify plugin files.
*/
add_action( 'admin_bar_menu', 'gh_snippet_add_pipelines_to_admin_bar', 9999 );
function gh_snippet_add_pipelines_to_admin_bar( $wp_admin_bar ) {
// Only show if admin bar is visible
if ( ! is_admin_bar_showing() ) {
return;
}
// Limit to admins / CRM managers
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
// Make sure Groundhogg is active
if ( ! function_exists( '\Groundhogg\get_db' ) ) {
return;
}
$db = \Groundhogg\get_db( 'pipelines' );
if ( ! $db ) {
return;
}
// Root menu item
$wp_admin_bar->add_node( [
'id' => 'gh-pipelines-root',
'title' => 'Pipelines',
'href' => admin_url( 'admin.php?page=gh_pipelines' ),
] );
// Fetch pipelines
$pipelines = $db->query( [
'limit' => 50,
] );
if ( empty( $pipelines ) ) {
return;
}
foreach ( $pipelines as $pipeline ) {
if ( empty( $pipeline->ID ) ) {
continue;
}
$wp_admin_bar->add_node( [
'id' => 'gh-pipeline-' . $pipeline->ID,
'parent' => 'gh-pipelines-root',
'title' => esc_html( $pipeline->title ),
'href' => admin_url(
'admin.php?page=gh_pipeline&action=edit&pipeline=' . intval( $pipeline->ID )
),
] );
}
}