Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Extending BuddyPress with BP_Component Class
Search
Renato Alves
September 27, 2016
Programming
0
210
Extending BuddyPress with BP_Component Class
English version of my talk given at WordCamp Rio de Janeiro in 2016.
Renato Alves
September 27, 2016
Tweet
Share
More Decks by Renato Alves
See All by Renato Alves
Estendendo o BuddyPress com a classe BP_Component
espellcaste
0
150
Criando sua Rede Social com o BuddyPress
espellcaste
2
220
Other Decks in Programming
See All in Programming
ニーリーにおけるプロダクトエンジニア
nealle
0
690
datadog dash 2025 LLM observability for reliability and stability
ivry_presentationmaterials
0
350
スタートアップの急成長を支えるプラットフォームエンジニアリングと組織戦略
sutochin26
0
160
プロダクト志向なエンジニアがもう一歩先の価値を目指すために意識したこと
nealle
0
120
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
160
Select API from Kotlin Coroutine
jmatsu
1
210
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
350
WindowInsetsだってテストしたい
ryunen344
1
210
Systèmes distribués, pour le meilleur et pour le pire - BreizhCamp 2025 - Conférence
slecache
0
120
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
150
WebViewの現在地 - SwiftUI時代のWebKit - / The Current State Of WebView
marcy731
0
100
LINEヤフー データグループ紹介
lycorp_recruit_jp
0
1.6k
Featured
See All Featured
Gamification - CAS2011
davidbonilla
81
5.3k
Rebuilding a faster, lazier Slack
samanthasiow
82
9.1k
Facilitating Awesome Meetings
lara
54
6.4k
Typedesign – Prime Four
hannesfritz
42
2.7k
Building Applications with DynamoDB
mza
95
6.5k
Building an army of robots
kneath
306
45k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Git: the NoSQL Database
bkeepers
PRO
430
65k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
17
950
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
GitHub's CSS Performance
jonrohan
1031
460k
Transcript
Extending BuddyPress with BP_Component Class WordCamp Rio | September 2016
Hi Rio! I'm Renato Alves Recifense/Pernambucano/Nordestino WordPress/BuddyPress/Freelancer Developer Full-stack developer
at Inglês na Rede Saucal WordPress Engineer bbPress and BuddyPress contributor
Our task: Integrate WooCommerce account page inside the BuddyPress user
profile. For this integration, we are gonna use BuddyPress BP_Component class.
BuddyPress?! What is it? :/ BuddyPress is a powerful community
plugin for WordPress that takes your site beyond the blog. With it, you'll be able to create any social network.
Use Cases Some real world examples of sites using BuddyPress
Inglês na Rede Users: +210 - https://inglesnarede.com.br
Tasty Kitchen Users: +230.000 - http://tastykitchen.com/
Tributário Users: +72.000 - https://tributario.com.br
Why integrate both plugins? Examples of WooCommerce and BuddyPress integrations
Sites with subscriptions and products; Sites where BP components are the focus; Avoid confusing the user.
I introduce BP_Component class
BP_Component Class What is it? Why does it exist? How
is it being used inside BuddyPress? How other plugins are using it? Menus; Component files; Cache groups; Post types/taxonomies registration; Database tables; Metadata tables; Permalinks; Rewrite rules.
BuddyPress Follow Downloads: +43.000
Tributário Users: +72.000
Integration Main Points Pages, endpoints and permalinks; Content; Redirection.
class IRB_WC_Account_Component extends BP_Component { public function __construct() { parent::start(
'bp_wc_account', __( 'Apoio', 'irb' ) ); $this->setup_hooks(); } public function setup_hooks() { add_filter( 'woocommerce_get_endpoint_url', array( $this, 'get_url' ), 10, 4 ); add_filter( 'woocommerce_get_myaccount_page_permalink', array( $this, 'account_url' ), 10, 1 ); add_filter( 'woocommerce_is_account_page', array( $this, 'is_account_page' ), 10, 1 ); add_filter( 'woocommerce_locate_template', array( $this, 'disable_account_nav' ), 10, 2 ); } public function disable_account_nav( $template = '', $template_name = '' ) { if ( 'myaccount/navigation.php' === $template_name && bp_is_current_component( 'minha-conta' ) ) { $template = plugin_dir_path( __FILE__ ) . 'dummy-nav.php'; } return $template; } // Continue.... # Plugin Beginning
public function setup_globals( $args = array() ) { $bp =
buddypress(); $bp->active_components[$this->id] = '1'; // Define slug, if needed if ( ! defined( 'BP_WC_ACCOUNT_SLUG' ) ) { define( 'BP_WC_ACCOUNT_SLUG', 'minha-conta' ); } $args = array( 'slug' => BP_WC_ACCOUNT_SLUG, 'has_directory' => false, ); parent::setup_globals( $args ); $this->irb_wc_link = ''; if ( is_user_logged_in() ) { $this->irb_wc_link = trailingslashit( bp_loggedin_user_domain() . $this->slug ); } } # Plugin globals
public function setup_nav( $main_nav = array(), $sub_nav = array() )
{ ... more code above foreach ( wc_get_account_menu_items() as $key_item => $item ) { // if ( 'dashboard' === $key_item || 'customer-logout' === $key_item ) { // continue; // } // Don't add edit-acount page // if ( bp_is_active( 'settings' ) && 'edit-account' === $key_item ) { // continue; // } ... more code below } # Menus
// WooCommerce uses it to redirect user after a form
entry is submited. public function account_url( $url = '' ) { global $wp; if ( ! bp_is_current_component( 'minha-conta' ) && ! isset( $wp->query_vars['customer-logout'] ) && empty( $this->was_redirected ) ) { return $url; } if ( isset( $wp->query_vars['customer-logout'] ) ) { return bp_get_root_domain(); } else { return trailingslashit( bp_loggedin_user_domain() . $this->slug ); } } # Filter URL
public function set_screen() { if ( bp_is_current_action( 'orders' ) &&
'view-order' === bp_action_variable( 0 ) && is_numeric( bp_action_variable( 1 ) ) ) { // WooCommerce usa a variável global $wp global $wp; unset( $wp->query_vars['orders'] ); $wp->query_vars['view-order'] = (int) bp_action_variable( 1 ); } remove_filter( 'the_title', 'wc_page_endpoint_title' ); add_action( 'bp_template_content', array( $this, 'wc_content' ) ); bp_core_load_template( 'members/single/plugins' ); } # Telling BP which screen to use
public function wc_content() { echo apply_filters( 'the_content', get_post_field( 'post_content', wc_get_page_id(
'myaccount' ) ) ); } # Content pre-WooCommerce 2.6
public function wc_content() { global $wp; $vars = $wp->query_vars['name']; if
( $vars == 'billing' ) { return woocommerce_account_edit_address( $vars ); } else if ( $vars == 'view-order' ) { return woocommerce_account_view_order( $wp->query_vars['page'] ); } else if ( $vars == 'minha-conta' ) { return woocommerce_account_content(); } else { do_action( 'woocommerce_account_' . $vars . '_endpoint'); } } # Content pos-WooCommerce 2.6
public function get_url( $url, $endpoint, $value, $permalink ) { if
( ! bp_is_current_component( 'minha-conta' ) ) { return $url; } $my_account_slugs = array_merge( wc_get_account_menu_items(), array( 'view-order' => true ) ); if ( isset( $my_account_slugs[ $endpoint ] ) ) { $slug = $endpoint; if ( 'view-order' === $endpoint ) { $slug = 'orders/' . $slug; } $url = trailingslashit( bp_loggedin_user_domain() . $this->slug ) . $slug; if ( ! empty( $value ) ) { $url = trailingslashit( $url ) . $value; } } return $url; } # Adjusting URLS
function irb_wc_account_component() { buddypress()->irb_wc_account = new IRB_WC_Acount_Component; } add_action( 'irb_wc_account_ready',
'irb_wc_account_component', 20 ); # Creating a class instance # Loading the component private function setup_actions() { if ( class_exists('WooCommerce') ) { require( $this->plugin_dir . 'woo/bp-wp-component.php' ); } # Adding the component do_action( 'irb_wc_account_ready' ); }
# Orders
# View Order
# My Addresses
# Edit Address
# Account Details
The end! Now go create your social network! =D
[email protected]
ralv.es // inglesnarede.com.br Questions?! Renato Alves