Upload
corsonr
View
3.190
Download
0
Embed Size (px)
DESCRIPTION
Apprenez à ouvrir votre code aux développeurs: pourquoi ? Comment ? Crée des plugins modulaires pour assurer la pérennité de vos produits.
Citation preview
OUVRIR VOS PLUGINSAUX AUTRES DÉVELOPPEURS
Petite leçon de modularité© Rémi Corson | WPtech Nantes | 29 Novembre 2014
RémiCORSON
Ninjineer @ WooThemes
remicorson.com@remicorson
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
DON'T SPEAK FRENCH?
HTTP://GOO.GL/W2G9RX© Rémi Corson | WPtech Nantes | 29 Novembre 2014
POURQUOI ?© Rémi Corson | WPtech Nantes | 29 Novembre 2014
"De la même manière que nous modifions WordPress avec nos plugins, nous
pouvons altérer nos plugins par d'autres plugins"
— Pippin Williamson, Lead Developer Easy Digital Downloads
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
"L'ouverture de votre code est la meilleure façon de faire croître votre produit rapidement; Plus de dévs = plus de
contributions"— Mike Jolley, Lead Developer WooCommerce
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
"Il est important de créer des opportunités d'affaires autour de votre produit afin d'assurer sa durabilité et
sa rentabilité"— Mark Forrester, co-fondateur de WooThemes
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
"Permettre de modifier ou d'ajouter des fonctionnalités à votre plugin étend
naturellement sa base"— Magnus Jepson, co-fondateur de WooThemes
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
WOOCOMMERCE SUBSCRIPTIONSEST LE PRODUIT QUI SE VEND LE PLUSSUR WOOTHEMES.COM
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
LA SOCIÉTÉ Skyverge EMPLOIE6 PERSONNES À TEMPS PLEIN
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
DÉFINITION© Rémi Corson | WPtech Nantes | 29 Novembre 2014
UN PLUGIN MODULABLE EST UN PLUGIN POUVANT ÊTRE
MODIFIÉ & ETENDUSANS QUE SON CODE NE SOIT MODIFIÉ
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
MODULABLE=
FLEXIBLE, ADAPTABLE, AJUSTABLE© Rémi Corson | WPtech Nantes | 29 Novembre 2014
MODULABLE!=
INADAPTABLE, REBELLE, RÉCALCITRANT© Rémi Corson | WPtech Nantes | 29 Novembre 2014
EXEMPLES© Rémi Corson | WPtech Nantes | 29 Novembre 2014
UN PLUGIN DE ECOMMERCEPERMETTANT D'AJOUTER DES MOYENS DE PAIEMENTOU DES OPTIONS DE LIVRAISON (FEDEX, UPS...)
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
UN PLUGIN DE FORUMSPERMETTANT DE RESTREINDRE LES CONVERSATIONSSELON LE RÔLE DES UTILISATEURS
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
UN PLUGIN TYPE SLIDERPERMETTANT DE CUSTOMISERLE VISUEL DES SLIDES
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
TEXTESIMAGES
DONNÉESVISUELS
FONCTIONS© Rémi Corson | WPtech Nantes | 29 Novembre 2014
COMMENT ?© Rémi Corson | WPtech Nantes | 29 Novembre 2014
ADD_ACTION()DO_ACTION()ADD_FILTER()
APPLY_FILTERS()© Rémi Corson | WPtech Nantes | 29 Novembre 2014
LES ACTIONS SONT DÉCLENCHÉES PAR DES ÉVÉNEMENTS SPÉCIFIQUES:
- PUBLICATION D'UN ARTICLE- ACTIVATION D'UN THÈME- AFFICHAGE D'UNE PAGE DE L'ADMIN
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
LES FILTRES SONT DES FONCTIONSPERMETTANT DE MANIPULER LES DONNÉES
LANCÉES ENTRE LA BASEET LE NAVIGATEUR ET
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
CODE© Rémi Corson | WPtech Nantes | 29 Novembre 2014
function mon_shortcode() { ob_start(); ?>
<div id="conteneur"> <p>Mon message</p> </div>
<?php return get_ob_clean();}add_shortcode( 'affiche_message', 'mon_shortcode' );
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
function mon_shortcode() { ob_start(); ?>
<div id="conteneur"> <p>Mon message</p> <?php do_action( 'sous_message' ); ?> </div>
<?php return get_ob_clean();}add_shortcode( 'affiche_message', 'mon_shortcode' );
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
CE QUI PERMET...© Rémi Corson | WPtech Nantes | 29 Novembre 2014
function mon_shortcode() { ob_start(); ?>
<div id="conteneur"> <p>Mon message</p> <?php do_action( 'sous_message' ); ?> </div>
<?php return get_ob_clean();}add_shortcode( 'affiche_message', 'mon_shortcode' );
function ajoute_contenu() { echo '<p>2eme message sous mon 1er message</p>'; }add_action( 'sous_message', 'ajoute_contenu' );
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
EN DÉTAIL...function ajoute_contenu() { echo '<p>2eme message sous mon 1er message</p>'; }add_action( 'sous_message', 'ajoute_contenu' );
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
LE RÉSULTAT <div id="conteneur"> <p>Mon message</p> <p>2eme message sous mon 1er message</p> </div>
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
AUTRE MÉTHODE© Rémi Corson | WPtech Nantes | 29 Novembre 2014
function mon_shortcode() { $output = '<div id="conteneur">'; $output .= '<p>Mon message</p>'; $output .= '</div>';
return apply_filters( 'mon_message', $output );}add_shortcode( 'affiche_message', 'mon_shortcode' );
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
function mon_shortcode() { $output = '<div id="conteneur">'; $output .= '<p>Mon message</p>'; $output .= '</div>';
return apply_filters( 'mon_message', $output );}add_shortcode( 'affiche_message', 'mon_shortcode' );
function embed_conteneur( $output ) { return '<div id="conteneur_principal">' . $output . '</div>';}apply_filters( 'mon_message', 'embed_conteneur' );
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
EN DÉTAIL...function embed_conteneur( $output ) { return '<div id="conteneur_principal">' . $output . '</div>';}apply_filters( 'mon_message', 'embed_conteneur' );
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
LE RÉSULTAT<div id="conteneur_principal"> <div id="conteneur"> <p>Mon message</p> </div></div>
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
function mon_shortcode() { ob_start(); ?>
<div id="conteneur"> <p>Mon message</p> <?php do_action( 'sous_message' ); ?> </div>
<?php $output = get_ob_clean();
return apply_filters( 'mon_message', $output );}add_shortcode( 'affiche_message', 'mon_shortcode' );
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
MODÈLES© Rémi Corson | WPtech Nantes | 29 Novembre 2014
UTILISER DES MODÈLESC'EST CHARGER SES PROPRES FICHIERSET NE PAS UTILISER LES MODÈLES PAR DÉFAUT
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
add_filter( 'template_include', 'rc_template_chooser');
function rc_template_chooser( $template ) {
// Récupère l'ID du post $post_id = get_the_ID();
// Charger le modèle par défaut pour les autres CPTs if ( get_post_type( $post_id ) != 'testimonial' ) { return $template; }
// Utiliser notre propre modèle if ( is_single() ) { return rc_get_template_hierarchy( 'single' ); }
}
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
function rc_get_template_hierarchy( $template ) {
// Récupère le slug du modèle $template_slug = rtrim( $template, '.php' ); $template = $template_slug . '.php';
// Existe t-il un modèle dans le dossier du thème ? (single.php) if ( $theme_file = locate_template( array( 'plugin_template/' . $template ) ) ) { $file = $theme_file; } else { $file = RC_BASE_DIR . '/includes/templates/' . $template; }
return apply_filters( 'rc_template_' . $template, $file );}
CODE COMPLET + TUTORIAL© Rémi Corson | WPtech Nantes | 29 Novembre 2014
111 MODÈLES© Rémi Corson | WPtech Nantes | 29 Novembre 2014
API© Rémi Corson | WPtech Nantes | 29 Novembre 2014
DÉFINITIONUNE API EST UN ENSEMBLE NORMALISÉ DE CLASSES,DE MÉTHODES OU DE FONCTIONS SERVANT DE FAÇADE
PAR LAQUELLE UN LOGICIEL OFFRE DES SERVICESÀ D'AUTRES LOGICIELS
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
REST (REPRESENTATIONAL STATE TRANSFER)EST UN STYLE D’ARCHITECTUREPOUR LES SYSTÈMES HYPERMÉDIA DISTRIBUÉS.REST N’EST PAS UN PROTOCOLE (TEL QUE HTTP)
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
LA WC REST API PERMET CRÉER DES DONNÉES,
DE LIRE, DE METTRE À JOUR,ET SUPPRIMER AU FORMAT JSON
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
EXEMPLES:http://site.fr/wc-api/v2/products
http://site.fr/wc-api/v2/ordershttp://site.fr/wc-api/v2/orders?status=completed
http://site.fr/wc-api/v2/orders?filter[created_at_min]=2013-11-01© Rémi Corson | WPtech Nantes | 29 Novembre 2014
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
EN SAVOIR +http://docs.woothemes.com/document/woocommerce-rest-api/
http://gerhardpotgieter.com/2014/02/10/woocommerce-rest-api-client-library/
http://docs.woocommercev2.apiary.io/introduction/authentication/over-http
© Rémi Corson | WPtech Nantes | 29 Novembre 2014
GITHUBTRELLOGITTERGISTS
TRANSIFEX© Rémi Corson | WPtech Nantes | 29 Novembre 2014
MERCI !© Rémi Corson | WPtech Nantes | 29 Novembre 2014
-25% SUR WOOTHEMES.COM
WOO-WPTECH© Rémi Corson | WPtech Nantes | 29 Novembre 2014