
Hacking s2Member®
(it's easy with Hooks/Filters for WordPress®)
If you need to add custom processing routines, or modify the behavior of existing processing routines; please use s2Member's Hooks/Filters for WordPress®. Hooks & Filters, give you the ability to "hook into", and/or "filter" processing routines, with files/functions of your own; instead of editing the s2Member® plugin files directly. This way you won't need to merge your changes/tweaks each time a new version of s2Member® is released.
To create custom processing routines, place those routines into a PHP file here:
/wp-content/mu-plugins/s2-hacks.php
If you don't have an /mu-plugins/ directory, please create one. These are (mu) MUST USE plugins, which are loaded into WordPress® automatically; that's what you want! You can learn more about MUST USE Plugins here. If you're not familiar with Hooks/Filters for WordPress®, please read this article in the WordPress® Codex.
See also: the s2Member® Codex, where you will find all of s2Member's source code has been documented for PHP developers. The s2Member® Codex may help you understand some of the more advanced aspects of s2Member.
Adding a Hook (inside /wp-content/mu-plugins/s2-hacks.php)
Please make sure there are NO blank lines in your PHP file.
Do NOT introduce spaces/tabs/lines before or after the <?php ?>
tags.
<?php
add_action("hook_name", "my_action_hook_function");
function my_action_hook_function($vars = array())
{
echo "My Hook works.";
# Optional. s2Member® passes you an array of defined variables.
# print_r($vars); # Would give you a list of defined variables.
# These are PHP variables defined within the scope of the Hook,
# at the precise point in which the Hook is fired by s2Member®.
# $vars["__refs"] are also included (with some Hooks).
# These are internal PHP variable references (very useful).
# To learn all about references, please see PHP documentation:
# http://www.php.net/manual/en/language.references.pass.php
}
?>
Adding a Filter (inside /wp-content/mu-plugins/s2-hacks.php)
Please make sure there are NO blank lines in your PHP file.
Do NOT introduce spaces/tabs/lines before or after the <?php ?>
tags.
<?php
add_filter("filter_name", "my_filtering_function");
function my_filtering_function($original_value, $vars = array())
{
if($original_value !== "something I like")
return ($my_custom_value = "My Filter works.");
else # Return original value.
return $original_value;
# Optional. s2Member® passes you an array of defined variables.
# print_r($vars); # Would give you a list of defined variables.
# These are PHP variables defined within the scope of the Filter,
# at the precise point in which the Filter is fired by s2Member®.
# $vars["__refs"] are also included (with some Filters).
# These are internal PHP variable references (very useful).
# To learn all about references, please see PHP documentation:
# http://www.php.net/manual/en/language.references.pass.php
}
?>