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
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
280
Criando sua Rede Social com o BuddyPress
espellcaste
2
230
Other Decks in Programming
See All in Programming
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
150
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
120
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
4
1.8k
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
1.5k
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.2k
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
110
Getting Started with Vibe Coding
miccheng
0
180
Groovy as a human and AI friendly programming language
paulk
0
180
クラウドゲーミングのパフォーマンス最適化に挑む / Cloud Gaming Performance Tuning
vivion
0
320
SFCで実現する病院・医療システムの動的組み立て式UI
koukimiura
1
170
はじめてのPLATEAU
nokonoko1203
1
520
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
210
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
290
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.5k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
970
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
580
Large-scale JavaScript Application Architecture
addyosmani
516
110k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
570
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
550
How Software Deployment tools have changed in the past 20 years
geshan
2
35k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
670
A Tale of Four Properties
chriscoyier
163
24k
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