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 ✔
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