I am working on a MemberMouse subscription Wordpress website. On a specific user page I want to display content for a finite period of time. The same should go into a widget.
[MM_Member_Decision membershipId='1' daysAsMember='1' daysAsMember='-3']
**HERE SHOULD BE CONTENT OR A PICTURE**
[/MM_Member_Decision]
Basically, I want to be able to display content for my members for a finite period of time (e.g. 24 hours only). And I want to be able to do this at any time in a member's life cycle (e.g. 7 days after they joined, 30 days after they joined, etc.)
Usually the SmartTags are looking like above, documentation below:
[MM_Member_Decision membershipId='1' daysAsMember='7']
This content will be displayed if the viewing member has been a member of membership level with ID #1 for at least 7 days.
[/MM_Member_Decision]
[MM_Member_Decision membershipId='1' daysAsMember='-10']
This content will be displayed if the viewing member has been a member of membership level with ID #1 for no more than 10 days.
[/MM_Member_Decision]
Even though this is useful, MemberMouse does not allow us to simultaneously define a positive and negative value for the daysAsMember parameter (or the daysWithBundle parameter for that matter). In other words, if we want to show John our "Super Awesome Content" on day 7 of his membership, and make it invisible again on day 8 (thus making it a 24 hour-only window of availability), we can't do that out of the box with MemberMouse.
I found this on the web as solution:
<?php if(mm_member_decision(array("daysAsMember"=>"1")) && mm_member_decision(array("daysAsMember"=>"-3")) && (mm_member_decision(array("hasBundle"=>"2")) == false)) { echo '"13")) . '">**HERE SHOULD BE CONTENT OR A PICTURE** ; } ?>
You'll notice that the first PHP tag checks to make sure the member has been a member for 1 days.
The second tag checks to make sure that he has not been a member for more than 3 days.
Then we check to make sure he does not have access to bundle with the ID number 2.
And if all of these conditions are met, we display the Text "HERE SHOULD BE CONTENT OR A PICTURE".
Then closing out the PHP statement.
So far so good. However, I am trying since a couple of days how to implement this matter into a widget or in a page. Since it is a PHP code it is a little more difficult. Addiontally, I am not sure if the PHP code is even correct. This was just a assumption I found on the web.
Any solution to this problem would be appreciated.
Thanks, Aron
The first thing you would do is create a widget. You can do that using the Widgets API. Then you can put whatever php code you want inside an instance of the widget.
Something like this should get you started (in functions.php or another theme file)
class MemberMouseFiniteContent extends WP_Widget {
function __construct(){
parent::__construct('mm-finite-content',
'MemberMouse Finite Content',
array('description' => 'A widget for displaying content in a time window')
);
}
// front-end
public function widget($args,$instance){
if( mm_member_decision(array("daysAsMember"=>"1"))
&& mm_member_decision(array("daysAsMember"=>"-3"))
&& (mm_member_decision(array("hasBundle"=>"2")) == false)
) {
echo 'HERE SHOULD BE CONTENT OR A PICTURE';
}
}
public function form($instance){
// if you want to configure the widget put the form here.
// @see https://codex.wordpress.org/Widgets_API
}
public function update($new,$old){
return $new;
}
}
// register the widget
add_action( 'widgets_init', function(){
register_widget( 'MemberMouseFiniteContent' );
});