Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/804 #122

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions s2member-pro/includes/classes/sc-last-payment-in.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?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());
}
}
}
49 changes: 49 additions & 0 deletions s2member-pro/includes/classes/sc-last-payment.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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);
}
}
}
1 change: 1 addition & 0 deletions s2member-pro/includes/codes.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
Add WordPress Editor Shortcodes.
*/
add_shortcode('s2Drip', 'c_ws_plugin__s2member_pro_sc_drip::shortcode');
add_shortcode('s2LastPayment', 'c_ws_plugin__s2member_sc_last_payment::sc_last_payment_details');

add_shortcode('s2MOP', 'c_ws_plugin__s2member_pro_sc_mop_vars_notice::shortcode');
add_shortcode('s2MOPNotice', 'c_ws_plugin__s2member_pro_sc_mop_vars_notice::shortcode');
Expand Down