latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Extensions / Hacks (Posting Guidelines)

Home Forums Community Forum Unofficial Extensions/Hacks Extensions / Hacks (Posting Guidelines)

This topic contains 1 reply, has 1 voice. Last updated by  Jason (Lead Developer) 4 years, 10 months ago.

Topic Author Topic
Posted: Friday Mar 2nd, 2012 at 1:28 am #7003
Staff Member
Hi there. Welcome to our “Unofficial Extensions/Hacks” sub-forum.

We’re making this available so that anyone may contribute here. If you would like to share Extensions and/or Hacks that you’ve written for s2Member, we’d love to see! Please feel free to post them.

Posting Guidelines:

  • Please describe what your Extension and/or Hack does exactly.
  • Please provide installation instructions, and post any required code snippets.
  • Please discuss any negative repercussions that you’re aware of.

That’s it. We hope to see many contributions from both our customers, and from others in the s2Member Community. We’ll also maintain a separate category in the s2Member Knowledge Base with any Extensions/Hacks that I write myself, or that another s2Member Support Rep has been willing to share.

See also: http://www.s2member.com/kb-category/extensions-hacks/

List Of Topic Replies

Viewing 1 replies (of 1 total)
Author Replies
Author Replies
Posted: Friday Mar 2nd, 2012 at 1:31 am #7006
Staff Member

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&#91;"__refs"&#93; 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&#91;"__refs"&#93; 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
	}
?>
Viewing 1 replies (of 1 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.