s2member
s2member copied to clipboard
Feature Request: Shortcode to Allow Showing Member's Last Payment Amount
It would be great if we had a way to display a member's last payment amount as well as their last payment date & time. This could be an extension of s2EOT /]
or a new shortcode.
Reference Internal/Private Ticket: https://websharks.zendesk.com/agent/tickets/9882
s2Member KBA: [s2EOT /]
Shortcode Documentation
@kristineds Would you like to take a shot at outlining this one for Renz?
What we can do is start by adding a new shortcode for the last payment.
add_shortcode('s2LastPayment', ...);
See: https://codex.wordpress.org/Function_Reference/add_shortcode
How to get the last payment time for a specific user.
$user_id = 123;
$last_payment_time = get_user_option('s2member_last_payment_time', $user_id);
// This returns a Unix Timestamp (UTC).
To begin with, let's work on making the shortcode return the last payment time.
[s2LastPayment show="time" /]
A format=""
attribute would be helpful also; i.e., to format the date/time.
Also requested here: https://websharks.zendesk.com/agent/tickets/11877
@jaswsinc Here's my take on the outline. I think I'm missing something but I'm not sure what exactly. :)
Next Actions
- Add a new shortcode for the last payment. After this line and add the following code:
add_shortcode('s2LastPayment', 'c_ws_plugin__s2member_sc_last_payment::sc_last_payment_details');
- Create a new file in the
s2member/includes/classes/
calledsc-last-payment-in.inc.php
, add the following:
<?php
/**
* Shortcode `[s2LastPayment /]` (inner processing routines).
*
* Copyright: © 2009-2011
* {@link http://websharks-inc.com/ WebSharks, Inc.}
* (coded in the USA)
*
* Released under the terms of the GNU General Public License.
* You should have received a copy of the GNU General Public License,
* along with this software. In the main directory, see: /licensing/
* If not, see: {@link http://www.gnu.org/licenses/}.
*
* @package s2Member\s2LastPayment
* @since 160328
*/
if(!defined('WPINC')) // MUST have WordPress.
exit('Do not access this file directly.');
if(!class_exists('c_ws_plugin__s2member_sc_last_payment_in'))
{
/**
* Shortcode `[s2LastPayment /]` (inner processing routines).
*
* @package s2Member\s2LastPayment
* @since 160328
*/
class c_ws_plugin__s2member_sc_last_payment_in
{
/**
* Handles the Shortcode for: `[s2LastPayment /]`.
*
* @package s2Member\s2LastPayment
* @since 160328
*
* @attaches-to ``add_shortcode('s2LastPayment');``
*
* @param array $attr An array of Attributes.
* @param string $content Content inside the Shortcode.
* @param string $shortcode The actual Shortcode name itself.
*
* @return string Value of the requested data.
*/
public static function sc_last_payment_details($attr = array(), $content = '', $shortcode = '')
{
if(empty($attr['user_id']) || !(integer)$attr['user_id'])
$attr['user_id'] = $user_id = get_current_user_id();
else $user_id = (integer)$attr['user_id'];
$last_payment_time = get_user_option('s2member_last_payment_time', $user_id);
// This returns a Unix Timestamp (UTC).
$attr = shortcode_atts( // Attributes.
array(
'user_id' => '0', // Current.
'show' => 'time', // Current.
'format' => 'M jS, Y, g:i a T',
'timezone' => '', // Default timezone; i.e., GMT/UTC.
),
c_ws_plugin__s2member_utils_strings::trim_qts_deep((array)$attr)
);
// Initialize Last Payment details/output date format.
$time = null; // Initialize the time calculation.
if($last_payment['time']) // // Do we have a time to work with?
{
$time = new DateTime(date('Y-m-d H:i:s', $last_payment['time']));
if($attr['timezone'] && strtoupper($attr['timezone']) !== 'UTC')
$time->setTimezone(new DateTimeZone($attr['timezone']));
}
if($time && $attr['format'] === 'timestamp')
$date = (string)$time->getTimestamp();
else if($time && $attr['format'] === 'default')
$date = $time->format(get_option('format'));
else if($time && $attr['format'])
$date = $time->format($attr['format']);
else if($time) // Default date/time format.
$date = $time->format('M jS, Y, g:i a T');
else $date = ''; // Default date; i.e., nothing.
$details = str_ireplace('%%date%%', esc_html($date), $details);
// Return the details/output from this shortcode.
return apply_filters('ws_plugin__s2member_sc_last_payment_details', $details, get_defined_vars());
}
}
}
- Create a new file in the
s2member/includes/classes/
calledsc-last-payment.inc.php
, add the following:
<?php
/**
* Shortcode `[s2LastPayment /]`.
*
* Copyright: © 2009-2011
* {@link http://websharks-inc.com/ WebSharks, Inc.}
* (coded in the USA)
*
* Released under the terms of the GNU General Public License.
* You should have received a copy of the GNU General Public License,
* along with this software. In the main directory, see: /licensing/
* If not, see: {@link http://www.gnu.org/licenses/}.
*
* @package s2Member\s2LastPayment
* @since 160328
*/
if(!defined('WPINC')) // MUST have WordPress.
exit ('Do not access this file directly.');
if(!class_exists('c_ws_plugin__s2member_sc_last_payment'))
{
/**
* Shortcode `[s2LastPayment /]`.
*
* @package s2Member\s2LastPayment
* @since 160328
*/
class c_ws_plugin__s2member_sc_last_payment
{
/**
* Handles the Shortcode for: `[s2LastPayment /]`.
*
* @package s2Member\s2LastPayment
* @since 160120
*
* @attaches-to ``add_shortcode('s2LastPayment');``
*
* @param array $attr An array of Attributes.
* @param string $content Content inside the Shortcode.
* @param string $shortcode The actual Shortcode name itself.
*
* @return string Return-value of inner routine.
*/
public static function sc_last_payment_details($attr = array(), $content = '', $shortcode = '')
{
return c_ws_plugin__s2member_sc_last_payment_in::sc_last_payment_details($attr, $content, $shortcode);
}
}
}
- Submit PR.
@jaswsinc cc: @kristineds
Hi submitted PR, in the example Kristine outlined it referenced the s2Member lite files. However, I changed files and added files to s2Member Pro due to the Pro
tag. Please let me know if that is correct.
Thanks!
@renzms Thanks for changing that! My bad. Were you able to test if the code is working as expected? :) cc @jaswsinc
Is there a reason why this is still open after 5 years? Is it implemented? When can we expect it if not? Where is it documented if so?