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
Renato Alves
September 24, 2016
Programming
210
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
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
210
Heart of Swift Concurrency
koher
0
890
Are APIs Still Relevant in the AI Era?
soyuka
0
250
Jetpack Compose メカニズム
skydoves
0
440
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2k
FreeBSDでZabbixを動かす
kenkino
0
300
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
1
480
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
120
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
3k
AI活用は、個人から組織へ|マルチプレイヤーエージェントハーネス「QM」の社内活用事例 / AI use is moving from individuals to orgs
rkaga
1
110
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
150
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
3
350
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
580
From π to Pie charts
rasagy
1
370
Believing is Seeing
oripsolob
1
220
The Cost Of JavaScript in 2023
addyosmani
55
10k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
540
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Code Review Best Practice
trishagee
74
20k
Writing Fast Ruby
sferik
630
63k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
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