Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Estendendo o BuddyPress com a classe BP_Component
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Renato Alves
September 24, 2016
Programming
220
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Estendendo o BuddyPress com a classe BP_Component
Renato Alves
September 24, 2016
More Decks by Renato Alves
See All by Renato Alves
Extending BuddyPress with BP_Component Class
espellcaste
0
270
Criando sua Rede Social com o BuddyPress
espellcaste
2
230
Other Decks in Programming
See All in Programming
Agents on Rails - Rails at Scale 2026
irinanazarova
0
520
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.5k
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
950
AWSに止められる覚悟してますか?
morizo_1984
2
520
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
510
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.1k
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.9k
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.6k
パーソナライズPodcastを作った話
repunit11
0
130
contenteditable と日本語入力に向き合う
colorful12
0
180
外から家のPCの電源入れたい!をPHPで解決する
kawashimo0
1
130
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
240
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
174
15k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
520
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
GitHub's CSS Performance
jonrohan
1033
470k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.1k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.3k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
420
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
490
Paper Plane
katiecoart
PRO
4
54k
The Invisible Side of Design
smashingmag
301
52k
Design in an AI World
tapps
1
350
Transcript
Estendendo o BP com a Classe BP_Component WordCamp Rio |
Setembro 2016
Olá Rio! Sou Renato Alves Recifense/Pernambucano/Nordestino Desenvolvedor WordPress/BuddyPress/Freelancer Desenvolvedor Full-stack
no Inglês na Rede WordPress Engineer na agência canadense Saucal Contribuidor dos plugins bbPress e BuddyPress
Nossa tarefa: Integrar a página de contas do WooCommerce no
perfil de usuários do BuddyPress. Nessa integração, iremos utilizar a classe BP_Component do BuddyPress.
BuddyPress?! O que é isso? :/ O BuddyPress é um
plugin de rede sociais. Com ele, você será capaz de criar qualquer tipo de comunidade online/offline, intranets ou grupos de usuários.
Exemplos de Uso Veja como o BuddyPress está sendo usado
em sites reais.
Inglês na Rede Usuários: +210 - https://inglesnarede.com.br
Tasty Kitchen Usuários: +230.000 - http://tastykitchen.com/
Tributário Usuários: +72.000 - https://tributario.com.br
Por que integrar esses dois plugins? Exemplos de integração do
BuddyPress e o WooCommerce Sites com assinaturas e produtos; Sites que tem como foco, componentes do BP; Evitar confundir o usuário.
Vos apresento a classe: BP_Component
Classe BP_Component O que é a classe BP_Component? Por que
ela existe? Como ela é usada no BuddyPress? Como ela está sendo utilizada por plugins? Menus; Arquivos do Component; Grupo de cache; Registra post types/taxonomies; Tabelas de banco de dados; Tabelas de metadados; Adiciona Permalinks; Rewrite rules.
BuddyPress Follow Downloads: +43.000
Tributário Usuários: +72.000
Requisitos de Integração Páginas, endpoints e permalinks; Conteúdo; Redirecionamento.
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; } // Continua.... # Início do Plugin
public function setup_globals( $args = array() ) { $bp =
buddypress(); $bp->active_components[$this->id] = '1'; // Definir um slug, se necessário 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 ); } } # Informações Globais do Plugin
public function setup_nav( $main_nav = array(), $sub_nav = array() )
{ ... tem código mais aqui em cima foreach ( wc_get_account_menu_items() as $key_item => $item ) { // if ( 'dashboard' === $key_item || 'customer-logout' === $key_item ) { // continue; // } // Não inclua a página edit-account // if ( bp_is_active( 'settings' ) && 'edit-account' === $key_item ) { // continue; // } ... continuação da criação dos menus } # Menus opcionais
// O WooCommerce usa para direcionar o usuário após o
formulário é enviado. 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 ); } } # Filtro de 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' ); } # Dizendo ao BP que tela usar
public function wc_content() { echo apply_filters( 'the_content', get_post_field( 'post_content', wc_get_page_id(
'myaccount' ) ) ); } # Pre Woo 2.6 - Conteúdo interno de cada tela
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'); } } # Pós Woo 2.6 - Conteúdo interno de cada tela
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; } # Ajustando as 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 ); # Criando a instância # Carregando o componente onde quiser private function setup_actions() { if ( class_exists('WooCommerce') ) { require( $this->plugin_dir . 'woo/bp-wp-component.php' ); } # Adicionando o component do_action( 'irb_wc_account_ready' ); }
# Pedidos
# Visualizar Pedido
# Meus Endereços
# Editar Endereço
# Detalhes de Conta
Fim! Agora vá criar sua rede social! =D
[email protected]
ralv.es // inglesnarede.com.br Dúvidas?! Renato Alves