SlideShare a Scribd company logo
1 of 25
WRITING EXTENSIBLE
WORDPRESS PLUGINS
      Allen Snook
AGENDA

• Inspiration

• Concept

• Actions    and Filters

• Planning

• Pitfalls

• Hands      On
INSPIRATION


• Shane Pearlman’s
 presentation at WordCamp
 Seattle 2012 on Modern
 Tribe’s experiences



   http://www.slideshare.net/shanepearlman/the-capitalist-in-the-coop-the-art-science-of-the-premium-wordpress-business
CONCEPT
What the users and visitors experience


                        Premium Plugin
                          (Not Free)

                   BASE Plugin
              (FREE - WordPress.Org)

            WordPress Core
REQUIREMENTS

    Feature        Free Version   Premium Version
   Reporting           ✔                ✔
PayPal Standard        ✔                ✔
Gravity Payments                        ✔
  CSV Export                            ✔
MailChimp Integ.                        ✔
Link to Premium        ✔
GETTING HOOKED


• Actions

 • add_action($tag, $function   [, $priority [, $args]]);

 • do_action($tag, $arg);

 • remove_action($tag, $function    [, $priority [, $args]]);
function dgx_cart_queue_stylesheet() {
!    $styleurl = plugins_url('/css/styles.css', __FILE__);
!    wp_register_style('dgx_cart_css', $styleurl);
!    wp_enqueue_style('dgx_cart_css');
}
add_action('wp_print_styles', 'dgx_cart_queue_stylesheet');
GETTING HOOKED


• Filters

  • add_filter($tag, $function   [, $priority [, $args]]);

  • apply_filters($tag, $value   [,$var ...]);

  • remove_filter($tag, $function     [, $priority [, $args]]);
function dgx_social_butterfly_filter($content)
{
!    global $post;
!    if (is_single())
!    {
!    ! $content .= “<p>Appended to the content</p>”;
!    }
!    return $content;
}
add_filter('the_content', 'dgx_social_butterfly_filter');
PRIORITY AND ARGS

• Both add_action and
 add_filter accept two
 additional arguments -
 priority and the # of
 arguments

• You can use priority to
 arrange order of execution -
 think of it as a way of
 arranging cars on a train
PRIORITY


• For   example, instead of
        $content   =   dgx_donate_paypalstd_warning_section($content);
        $content   =   dgx_donate_get_donation_section($content);
        $content   =   dgx_donate_get_tribute_section($content);
        $content   =   dgx_donate_get_donor_section($content);
        $content   =   dgx_donate_get_billing_section($content);
        $content   =   dgx_donate_paypalstd_payment_section($content);
PRIORITY


• You   could do
        add_filter('dgx_donate_form',   'dgx_donate_paypalstd_warning_section', 1);
        add_filter('dgx_donate_form',   'dgx_donate_get_donation_section', 3);
        add_filter('dgx_donate_form',   'dgx_donate_get_tribute_section', 5);
        add_filter('dgx_donate_form',   'dgx_donate_get_donor_section', 7);
        add_filter('dgx_donate_form',   'dgx_donate_get_billing_section', 9);
        add_filter('dgx_donate_form',   'dgx_donate_paypalstd_payment_section', 11);


        $content = apply_filters('dgx_donate_form', $content);
WHEN TO USE WHICH


• In
   general, you will want to use filters for places where you
 need to return a value, and actions where you don’t

• For
    example, filters are great for customizing shortcodes since
 shortcodes don’t echo (they return)
MIND WARP


• Most of the time we have used add_action and add_filter as a
 single item, by itself, as we hooked into WordPress the
 platform

• When  writing extensible plugins, we need to mind warp a bit -
 our plugin becomes the platform - and you have to shift your
 perspective as a result
PLANNING

• Start
      with mockups of each
 view the user or visitor can
 see

• Identify
         in those mockups
 places where content needs
 to be added, removed or
 changed

• Use   your requirements
PLANNING 2

• Next, thinkabout the
 processing that needs to
 happen “behind the scenes”
 for specific events, e.g.
 adding a new post

• Think
      about what processing
 needs to “hook in” for the
 premium version
PLANNING 3


• For layers, like JavaScript,
 where you don’t have
 immediate access to
 WordPress actions and
 filters, use a data driven
 approach to “pass through”
 in a data agnostic fashion
JAVASCRIPT TRICKS


// Get the form data
var formData = {};
jQuery.each(jQuery('#dgx-cart-form').serializeArray(), function(i, field) {
         formData[field.name] = field.value;
         });

// Send the form data
formData['nonce'] = dgxCartAjax.nonce;
formData['action'] = 'dgx_cart_ajax_checkout1';
jQuery.post(dgxCartAjax.ajaxurl, formData, dgxCartCallback);
PLACES TO HOOK


• Thingsthat lend themselves to looping like rows in a table,
 sections in a form, columns on a settings page

• Save   actions (pass the postID as an argument)

• Footers   (great for adding/removing “upgrade to pro” link)
PITFALLS TO AVOID

• Your   base plugin could get deactivated

 • Ifyour extension plugin is calling functions in your base
   plugin, you should test for the base function before using it
   (e.g. if_function_exists)

• Don’t
      hook things that don’t need hooking (meta boxes,
 submenus)

• Don’t   expect to have all hooks identified in 1.0
KEY TAKE-AWAYS

• Think   of your base plugin as a platform

• Lookfor places where you will want to be able to insert / re-
 order content and processing

• Use   priority to arrange the “cars on the train”

• Keep    hook-unfriendly layers data agnostic

• Don’t   count on your base plugin always being there
HANDS ON
http://pastebin.com/m7RGJMHr

http://pastebin.com/HgXXhAUz
THANK YOU
allen@designgeneers.com
      @AllenSnook

More Related Content

What's hot

Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Marko Heijnen
 
PHPUnit with Mocking and Crawling
PHPUnit with Mocking and CrawlingPHPUnit with Mocking and Crawling
PHPUnit with Mocking and CrawlingTrung x
 
Render API - Pavel Makhrinsky
Render API - Pavel MakhrinskyRender API - Pavel Makhrinsky
Render API - Pavel MakhrinskyDrupalCampDN
 
Data::FormValidator Simplified
Data::FormValidator SimplifiedData::FormValidator Simplified
Data::FormValidator SimplifiedFred Moyer
 
WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3Mizanur Rahaman Mizan
 
Modularity and Layered Data Model
Modularity and Layered Data ModelModularity and Layered Data Model
Modularity and Layered Data ModelAttila Jenei
 
Geodaten & Drupal 7
Geodaten & Drupal 7Geodaten & Drupal 7
Geodaten & Drupal 7Michael Milz
 
Building secured wordpress themes and plugins
Building secured wordpress themes and pluginsBuilding secured wordpress themes and plugins
Building secured wordpress themes and pluginsTikaram Bhandari
 
Optimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page AppsOptimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page AppsMorgan Stone
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesAngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesEyal Vardi
 

What's hot (12)

Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5
 
PHPUnit with Mocking and Crawling
PHPUnit with Mocking and CrawlingPHPUnit with Mocking and Crawling
PHPUnit with Mocking and Crawling
 
Render API - Pavel Makhrinsky
Render API - Pavel MakhrinskyRender API - Pavel Makhrinsky
Render API - Pavel Makhrinsky
 
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
 
Data::FormValidator Simplified
Data::FormValidator SimplifiedData::FormValidator Simplified
Data::FormValidator Simplified
 
WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3
 
Django Vs Rails
Django Vs RailsDjango Vs Rails
Django Vs Rails
 
Modularity and Layered Data Model
Modularity and Layered Data ModelModularity and Layered Data Model
Modularity and Layered Data Model
 
Geodaten & Drupal 7
Geodaten & Drupal 7Geodaten & Drupal 7
Geodaten & Drupal 7
 
Building secured wordpress themes and plugins
Building secured wordpress themes and pluginsBuilding secured wordpress themes and plugins
Building secured wordpress themes and plugins
 
Optimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page AppsOptimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page Apps
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesAngularJS - $http & $resource Services
AngularJS - $http & $resource Services
 

Similar to Writing extensible Word press-plugins

Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Mike Schinkel
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)arcware
 
WordPress Accessibility: WordCamp Chicago
WordPress Accessibility: WordCamp ChicagoWordPress Accessibility: WordCamp Chicago
WordPress Accessibility: WordCamp ChicagoJoseph Dolson
 
WordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a FrameworkWordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a FrameworkExove
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin developmentMostafa Soufi
 
WordPress plugin #3
WordPress plugin #3WordPress plugin #3
WordPress plugin #3giwoolee
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction DjangoWade Austin
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPOscar Merida
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)Doris Chen
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Yevhen Kotelnytskyi
 
Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016Ian Wilson
 
So S.O.L.I.D Fu - Designing Better Code
So S.O.L.I.D Fu - Designing Better CodeSo S.O.L.I.D Fu - Designing Better Code
So S.O.L.I.D Fu - Designing Better CodeNeil Crookes
 
WordPress development paradigms, idiosyncrasies and other big words
WordPress development paradigms, idiosyncrasies and other big wordsWordPress development paradigms, idiosyncrasies and other big words
WordPress development paradigms, idiosyncrasies and other big wordsTomAuger
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme EnlightenmentAmanda Giles
 
Resource Routing in ExpressionEngine
Resource Routing in ExpressionEngineResource Routing in ExpressionEngine
Resource Routing in ExpressionEngineMichaelRog
 
Joomla! Day Chicago 2011 - Templating the right way - Jonathan Shroyer
Joomla! Day Chicago 2011 - Templating the right way - Jonathan ShroyerJoomla! Day Chicago 2011 - Templating the right way - Jonathan Shroyer
Joomla! Day Chicago 2011 - Templating the right way - Jonathan ShroyerSteven Pignataro
 
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...WordCamp Sydney
 
You're Doing it Wrong - WordCamp Atlanta
You're Doing it Wrong - WordCamp AtlantaYou're Doing it Wrong - WordCamp Atlanta
You're Doing it Wrong - WordCamp AtlantaChris Scott
 
Introduction to WordPress Development - Hooks
Introduction to WordPress Development - HooksIntroduction to WordPress Development - Hooks
Introduction to WordPress Development - HooksEdmund Chan
 

Similar to Writing extensible Word press-plugins (20)

Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
WordPress Accessibility: WordCamp Chicago
WordPress Accessibility: WordCamp ChicagoWordPress Accessibility: WordCamp Chicago
WordPress Accessibility: WordCamp Chicago
 
WordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a FrameworkWordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a Framework
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin development
 
WordPress plugin #3
WordPress plugin #3WordPress plugin #3
WordPress plugin #3
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?
 
Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016
 
So S.O.L.I.D Fu - Designing Better Code
So S.O.L.I.D Fu - Designing Better CodeSo S.O.L.I.D Fu - Designing Better Code
So S.O.L.I.D Fu - Designing Better Code
 
WordPress development paradigms, idiosyncrasies and other big words
WordPress development paradigms, idiosyncrasies and other big wordsWordPress development paradigms, idiosyncrasies and other big words
WordPress development paradigms, idiosyncrasies and other big words
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme Enlightenment
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
Resource Routing in ExpressionEngine
Resource Routing in ExpressionEngineResource Routing in ExpressionEngine
Resource Routing in ExpressionEngine
 
Joomla! Day Chicago 2011 - Templating the right way - Jonathan Shroyer
Joomla! Day Chicago 2011 - Templating the right way - Jonathan ShroyerJoomla! Day Chicago 2011 - Templating the right way - Jonathan Shroyer
Joomla! Day Chicago 2011 - Templating the right way - Jonathan Shroyer
 
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
 
You're Doing it Wrong - WordCamp Atlanta
You're Doing it Wrong - WordCamp AtlantaYou're Doing it Wrong - WordCamp Atlanta
You're Doing it Wrong - WordCamp Atlanta
 
Introduction to WordPress Development - Hooks
Introduction to WordPress Development - HooksIntroduction to WordPress Development - Hooks
Introduction to WordPress Development - Hooks
 

Recently uploaded

2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)Delhi Call girls
 
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)Delhi Call girls
 
The Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushThe Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushShivain97
 
WOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptxWOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptxpadhand000
 
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...PsychicRuben LoveSpells
 
LC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfLC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfpastor83
 
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)Delhi Call girls
 
Pokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy TheoryPokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy Theorydrae5
 
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morcall Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morvikas rana
 
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)Delhi Call girls
 
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girlsPooja Nehwal
 
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,dollysharma2066
 

Recently uploaded (15)

2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
 
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
 
The Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushThe Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by Mindbrush
 
WOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptxWOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptx
 
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
 
LC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfLC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdf
 
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
 
Pokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy TheoryPokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy Theory
 
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
 
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morcall Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
 
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
 
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
 
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
 
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
 

Writing extensible Word press-plugins

  • 2. AGENDA • Inspiration • Concept • Actions and Filters • Planning • Pitfalls • Hands On
  • 3. INSPIRATION • Shane Pearlman’s presentation at WordCamp Seattle 2012 on Modern Tribe’s experiences http://www.slideshare.net/shanepearlman/the-capitalist-in-the-coop-the-art-science-of-the-premium-wordpress-business
  • 4.
  • 5.
  • 6. CONCEPT What the users and visitors experience Premium Plugin (Not Free) BASE Plugin (FREE - WordPress.Org) WordPress Core
  • 7. REQUIREMENTS Feature Free Version Premium Version Reporting ✔ ✔ PayPal Standard ✔ ✔ Gravity Payments ✔ CSV Export ✔ MailChimp Integ. ✔ Link to Premium ✔
  • 8. GETTING HOOKED • Actions • add_action($tag, $function [, $priority [, $args]]); • do_action($tag, $arg); • remove_action($tag, $function [, $priority [, $args]]);
  • 9. function dgx_cart_queue_stylesheet() { ! $styleurl = plugins_url('/css/styles.css', __FILE__); ! wp_register_style('dgx_cart_css', $styleurl); ! wp_enqueue_style('dgx_cart_css'); } add_action('wp_print_styles', 'dgx_cart_queue_stylesheet');
  • 10. GETTING HOOKED • Filters • add_filter($tag, $function [, $priority [, $args]]); • apply_filters($tag, $value [,$var ...]); • remove_filter($tag, $function [, $priority [, $args]]);
  • 11. function dgx_social_butterfly_filter($content) { ! global $post; ! if (is_single()) ! { ! ! $content .= “<p>Appended to the content</p>”; ! } ! return $content; } add_filter('the_content', 'dgx_social_butterfly_filter');
  • 12. PRIORITY AND ARGS • Both add_action and add_filter accept two additional arguments - priority and the # of arguments • You can use priority to arrange order of execution - think of it as a way of arranging cars on a train
  • 13. PRIORITY • For example, instead of $content = dgx_donate_paypalstd_warning_section($content); $content = dgx_donate_get_donation_section($content); $content = dgx_donate_get_tribute_section($content); $content = dgx_donate_get_donor_section($content); $content = dgx_donate_get_billing_section($content); $content = dgx_donate_paypalstd_payment_section($content);
  • 14. PRIORITY • You could do add_filter('dgx_donate_form', 'dgx_donate_paypalstd_warning_section', 1); add_filter('dgx_donate_form', 'dgx_donate_get_donation_section', 3); add_filter('dgx_donate_form', 'dgx_donate_get_tribute_section', 5); add_filter('dgx_donate_form', 'dgx_donate_get_donor_section', 7); add_filter('dgx_donate_form', 'dgx_donate_get_billing_section', 9); add_filter('dgx_donate_form', 'dgx_donate_paypalstd_payment_section', 11); $content = apply_filters('dgx_donate_form', $content);
  • 15. WHEN TO USE WHICH • In general, you will want to use filters for places where you need to return a value, and actions where you don’t • For example, filters are great for customizing shortcodes since shortcodes don’t echo (they return)
  • 16. MIND WARP • Most of the time we have used add_action and add_filter as a single item, by itself, as we hooked into WordPress the platform • When writing extensible plugins, we need to mind warp a bit - our plugin becomes the platform - and you have to shift your perspective as a result
  • 17. PLANNING • Start with mockups of each view the user or visitor can see • Identify in those mockups places where content needs to be added, removed or changed • Use your requirements
  • 18. PLANNING 2 • Next, thinkabout the processing that needs to happen “behind the scenes” for specific events, e.g. adding a new post • Think about what processing needs to “hook in” for the premium version
  • 19. PLANNING 3 • For layers, like JavaScript, where you don’t have immediate access to WordPress actions and filters, use a data driven approach to “pass through” in a data agnostic fashion
  • 20. JAVASCRIPT TRICKS // Get the form data var formData = {}; jQuery.each(jQuery('#dgx-cart-form').serializeArray(), function(i, field) { formData[field.name] = field.value; }); // Send the form data formData['nonce'] = dgxCartAjax.nonce; formData['action'] = 'dgx_cart_ajax_checkout1'; jQuery.post(dgxCartAjax.ajaxurl, formData, dgxCartCallback);
  • 21. PLACES TO HOOK • Thingsthat lend themselves to looping like rows in a table, sections in a form, columns on a settings page • Save actions (pass the postID as an argument) • Footers (great for adding/removing “upgrade to pro” link)
  • 22. PITFALLS TO AVOID • Your base plugin could get deactivated • Ifyour extension plugin is calling functions in your base plugin, you should test for the base function before using it (e.g. if_function_exists) • Don’t hook things that don’t need hooking (meta boxes, submenus) • Don’t expect to have all hooks identified in 1.0
  • 23. KEY TAKE-AWAYS • Think of your base plugin as a platform • Lookfor places where you will want to be able to insert / re- order content and processing • Use priority to arrange the “cars on the train” • Keep hook-unfriendly layers data agnostic • Don’t count on your base plugin always being there

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n