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
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
200
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
260
Criando sua Rede Social com o BuddyPress
espellcaste
2
230
Other Decks in Programming
See All in Programming
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
4.9k
AI駆動開発で崩れていくコードベースを立て直す
kyoko_nr_nr
1
450
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
100
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.2k
AutonomyとControlのあいだ:Graflowで記述するAIエージェント協調
myui
0
110
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
340
スマートグラスで並列バイブコーディング
hyshu
0
110
3Dシーンの圧縮
fadis
1
680
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
200
TAKTでAI駆動開発の品質を設計する
j5ik2o
6
1.1k
CSC307 Lecture 17
javiergs
PRO
0
320
A2UI という光を覗いてみる
satohjohn
1
120
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.4k
Code Reviewing Like a Champion
maltzj
528
40k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
180
Game over? The fight for quality and originality in the time of robots
wayneb77
1
190
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
200
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
580
Design in an AI World
tapps
1
230
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
150
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
720
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
140
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