Skip to content

Commit

Permalink
Updates to 1.11.28
Browse files Browse the repository at this point in the history
  • Loading branch information
MemberPress committed Apr 4, 2024
1 parent b6aaff4 commit 6d6d8df
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 113 deletions.
2 changes: 1 addition & 1 deletion app/controllers/MeprAppCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function mp_admin_header() {

if(MeprUtils::is_memberpress_admin_page()) {
$option = get_option( 'mepr_notifications' );
$notifications = ! empty($option) ? $option['feed'] : array();
$notifications = (is_array($option) && ! empty($option)) ? $option['feed'] : array();
if ( MeprNotifications::has_access() && ! empty( $notifications ) && count( $notifications ) > 0 ) {
foreach( $notifications as $key => $notification ) {
if (
Expand Down
1 change: 1 addition & 0 deletions app/controllers/MeprLoginCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ public function display_reset_password_form($mepr_key, $mepr_screenname) {
}
}
else {
$mepr_options = MeprOptions::fetch();
if(MeprReadyLaunchCtrl::template_enabled( 'login' )){
MeprView::render('/readylaunch/shared/unauthorized', get_defined_vars());
} else {
Expand Down
6 changes: 6 additions & 0 deletions app/gateways/MeprArtificialGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ public static function capture_txn_status_for_events($txn) {
MeprEvent::record('offline-payment-'.$txn->status, $txn);

if($txn->status == MeprTransaction::$complete_str) {

$sub = $txn->subscription();
if( $sub && $sub instanceof MeprSubscription ) {
$sub->limit_payment_cycles();
}

self::maybe_cancel_old_sub($txn, $gateway);
MeprUtils::send_transaction_receipt_notices($txn);
}
Expand Down
1 change: 1 addition & 0 deletions app/gateways/MeprAuthorizeProfileGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ public function process_single_order($txn, $dataValue, $dataDescriptor) {
$txn->save();

MeprUtils::send_signup_notices($txn);
MeprUtils::send_transaction_receipt_notices($txn);

add_filter( 'mepr-signup-checkout-url', function ( $uri, $txn ) {
$mepr_options = MeprOptions::fetch();
Expand Down
22 changes: 18 additions & 4 deletions app/helpers/MeprAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ public static function format_price_string($obj, $price = 0.00, $show_symbol = t
$product = false;
}

$proration_single_cycle = false;
if( $obj instanceof MeprSubscription && $obj->prorated_trial && $obj->trial && $obj->limit_cycles && 1 == $obj->limit_cycles_num ) {
$proration_single_cycle = true;
}

$tax_str = '';

if(!empty($obj->tax_rate) && $obj->tax_rate > 0.00) {
Expand Down Expand Up @@ -327,7 +332,14 @@ public static function format_price_string($obj, $price = 0.00, $show_symbol = t
list($conv_trial_type, $conv_trial_count) = MeprUtils::period_type_from_days($obj->trial_days);

$conv_trial_type_str = MeprUtils::period_type_name($conv_trial_type, $conv_trial_count);
$sub_str = __( '%1$s %2$s for %3$s%4$s then ', 'memberpress' );

// If proration and max number of payments is 1.
if( $proration_single_cycle ) {
$sub_str = __( '%1$s %2$s for %3$s%4$s ', 'memberpress' );
} else {
$sub_str = __( '%1$s %2$s for %3$s%4$s then ', 'memberpress' );
}

$price_str = sprintf( $sub_str, $conv_trial_count, $conv_trial_type_str, $trial_str, $upgrade_str );
}
else {
Expand All @@ -340,9 +352,11 @@ public static function format_price_string($obj, $price = 0.00, $show_symbol = t
}

if( $obj->limit_cycles and $obj->limit_cycles_num==1 ) {
$price_str .= $fprice;
if( $obj->limit_cycles_action=='expire' ) {
$price_str .= sprintf( __( ' for %1$d %2$s', 'memberpress' ), $period, $period_type_str );
if( ! $proration_single_cycle ) {
$price_str .= $fprice;
if( $obj->limit_cycles_action=='expire' ) {
$price_str .= sprintf( __( ' for %1$d %2$s', 'memberpress' ), $period, $period_type_str );
}
}
}
elseif( $obj->limit_cycles ) { // Prefix with payments count
Expand Down
4 changes: 2 additions & 2 deletions app/lib/MeprBaseDrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function drm_event( $event, $days, $drm_status ) {
$this->create_inplugin_notification( $drm_status );

// mark event complete.
$event_data[ $drm_event_key ] = MeprUtils::mysql_now();
$event_data[ $drm_event_key ] = MeprUtils::db_now();

$this->update_event( $event, $event_data );
}
Expand Down Expand Up @@ -233,4 +233,4 @@ protected function create_inplugin_notification( $drm_status ) {
}

abstract function run();
} //End class
} //End class
43 changes: 21 additions & 22 deletions app/lib/MeprReports.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static function get_transactions_count($status, $day = false, $month = fa
$andmonth = ($month)?" AND MONTH(created_at) = {$month}":"";
$andday = ($day)?" AND DAY(created_at) = {$day}":"";
$andyear = ($year)?" AND YEAR(created_at) = {$year}":"";
$andproduct = (!isset($product) || $product == "all")?"":" AND product_id = {$product}";
$andproduct = (!isset($product) || $product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);

$q = "SELECT COUNT(*)
FROM {$mepr_db->transactions}
Expand All @@ -30,7 +30,7 @@ public static function get_revenue($month = false, $day = false, $year = false,
$andmonth = ($month)?" AND MONTH(created_at) = {$month}":"";
$andday = ($day)?" AND DAY(created_at) = {$day}":"";
$andyear = ($year)?" AND YEAR(created_at) = {$year}":"";
$andproduct = (!isset($product) || $product == "all")?"":" AND product_id = {$product}";
$andproduct = (!isset($product) || $product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);

$q = "SELECT SUM(amount)
FROM {$mepr_db->transactions}
Expand All @@ -51,7 +51,7 @@ public static function get_collected($month = false, $day = false, $year = false
$andmonth = ($month)?" AND MONTH(created_at) = {$month}":"";
$andday = ($day)?" AND DAY(created_at) = {$day}":"";
$andyear = ($year)?" AND YEAR(created_at) = {$year}":"";
$andproduct = (!isset($product) || $product == "all")?"":" AND product_id = {$product}";
$andproduct = (!isset($product) || $product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);

$q = "SELECT (SUM(amount)+SUM(tax_amount))
FROM {$mepr_db->transactions}
Expand All @@ -72,7 +72,7 @@ public static function get_refunds($month = false, $day = false, $year = false,
$andmonth = ($month)?" AND MONTH(created_at) = {$month}":"";
$andday = ($day)?" AND DAY(created_at) = {$day}":"";
$andyear = ($year)?" AND YEAR(created_at) = {$year}":"";
$andproduct = (!isset($product) || $product == "all")?"":" AND product_id = {$product}";
$andproduct = (!isset($product) || $product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);

$q = "SELECT (SUM(amount)+SUM(tax_amount))
FROM {$mepr_db->transactions}
Expand All @@ -93,7 +93,7 @@ public static function get_taxes($month = false, $day = false, $year = false, $p
$andmonth = ($month)?" AND MONTH(created_at) = {$month}":"";
$andday = ($day)?" AND DAY(created_at) = {$day}":"";
$andyear = ($year)?" AND YEAR(created_at) = {$year}":"";
$andproduct = (!isset($product) || $product == "all")?"":" AND product_id = {$product}";
$andproduct = (!isset($product) || $product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);

$q = "SELECT SUM(tax_amount)
FROM {$mepr_db->transactions}
Expand Down Expand Up @@ -184,7 +184,7 @@ public static function get_monthly_data($type, $month, $year, $product, $q=array

$results = array();
$days_in_month = gmdate('t', mktime(0, 0, 0, $month, 1, $year));
$andproduct = ($product == "all")?"":" AND product_id = {$product}";
$andproduct = ($product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);
$where = MeprUtils::build_where_clause($q);

$selecttype = ($type == 'amounts')?"SUM(amount)":"COUNT(*)";
Expand Down Expand Up @@ -260,7 +260,7 @@ public static function get_yearly_data($type, $year, $product, $q=array()) {
$mepr_db = new MeprDb();

$results = array();
$andproduct = ($product == "all")?"":" AND product_id = {$product}";
$andproduct = ($product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);
$where = MeprUtils::build_where_clause($q);

$selecttype = ($type == "amounts")?"SUM(amount)":"COUNT(*)";
Expand Down Expand Up @@ -820,7 +820,7 @@ public static function get_recurring_revenue($month = false, $day = false, $year
$andmonth = ($month)?" AND MONTH(created_at) = {$month}":"";
$andday = ($day)?" AND DAY(created_at) = {$day}":"";
$andyear = ($year)?" AND YEAR(created_at) = {$year}":"";
$andproduct = (!isset($product) || $product == "all")?"":" AND product_id = {$product}";
$andproduct = (!isset($product) || $product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);

$q = "SELECT SUM(amount)
FROM {$mepr_db->transactions}
Expand Down Expand Up @@ -856,7 +856,7 @@ public static function get_date_range_transactions_counts(array $status_collecti
global $wpdb;
$mepr_db = new MeprDb();

$andproduct = (!isset($product) || $product == "all")?"":" AND product_id = {$product}";
$andproduct = (!isset($product) || $product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);

$q = "SELECT COUNT(*) as total_count, status
FROM {$mepr_db->transactions}
Expand Down Expand Up @@ -887,7 +887,7 @@ public static function get_date_range_revenue(\DateTimeImmutable $start_date, \D
global $wpdb;
$mepr_db = new MeprDb();

$andproduct = (!isset($product) || $product == "all")?"":" AND product_id = {$product}";
$andproduct = (!isset($product) || $product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);

$q = "SELECT SUM(amount)
FROM {$mepr_db->transactions}
Expand All @@ -904,7 +904,7 @@ public static function get_date_range_refunds(\DateTimeImmutable $start_date, \D
global $wpdb;
$mepr_db = new MeprDb();

$andproduct = (!isset($product) || $product == "all")?"":" AND product_id = {$product}";
$andproduct = (!isset($product) || $product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);

$q = "SELECT (SUM(amount)+SUM(tax_amount))
FROM {$mepr_db->transactions}
Expand All @@ -923,7 +923,7 @@ public static function get_monthly_dataset($type, $month, $year, $product, $q=ar

$results = array();
$days_in_month = gmdate('t', mktime(0, 0, 0, $month, 1, $year));
$andproduct = ($product == "all")?"":" AND product_id = {$product}";
$andproduct = ($product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);
$where = MeprUtils::build_where_clause($q);

$selecttype = ($type == 'amounts')?"SUM(amount)":"COUNT(*)";
Expand Down Expand Up @@ -980,7 +980,6 @@ public static function get_monthly_dataset($type, $month, $year, $product, $q=ar
FROM {$mepr_db->transactions}
WHERE YEAR(created_at) = {$year}
AND MONTH(created_at) = {$month}
AND DAY(created_at) = %d
AND txn_type = '".MeprTransaction::$payment_str."'
AND status IN ('".MeprTransaction::$complete_str."', '".MeprTransaction::$refunded_str."')
{$andproduct}{$where}
Expand All @@ -998,7 +997,7 @@ public static function get_monthly_dataset($type, $month, $year, $product, $q=ar
$results[$i]->$type = 0;
}

$resultset = $wpdb->get_results( $wpdb->prepare($sql) );
$resultset = $wpdb->get_results( $sql );

if( ! empty($resultset) ) {
foreach( $resultset as $row ) {
Expand All @@ -1019,7 +1018,7 @@ protected static function format_mepr_dataset($results) {
$ds[$row->mepr_day] = $row->mepr_value;
}

if( isset($row->mepr_month) && isset($row->mepr_month) ) {
if( isset($row->mepr_month) && isset($row->mepr_value) ) {
$ds[$row->mepr_month] = $row->mepr_value;
}
}
Expand All @@ -1034,7 +1033,7 @@ public static function get_revenue_dataset($month, $year, $product = null) {

$andmonth = ($month)?" AND MONTH(created_at) = {$month}":"";
$andyear = ($year)?" AND YEAR(created_at) = {$year}":"";
$andproduct = (!isset($product) || $product == "all")?"":" AND product_id = {$product}";
$andproduct = (!isset($product) || $product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);
$groupby = !empty($andmonth) ? "GROUP BY DAY(created_at)" : "GROUP BY MONTH(created_at)";
$mepr_col = !empty($andmonth) ? "DAY(created_at) as mepr_day" : "MONTH(created_at) as mepr_month";

Expand All @@ -1058,7 +1057,7 @@ public static function get_taxes_dataset($month = false, $year = false, $product

$andmonth = ($month)?" AND MONTH(created_at) = {$month}":"";
$andyear = ($year)?" AND YEAR(created_at) = {$year}":"";
$andproduct = (!isset($product) || $product == "all")?"":" AND product_id = {$product}";
$andproduct = (!isset($product) || $product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);
$groupby = !empty($andmonth) ? "GROUP BY DAY(created_at)" : "GROUP BY MONTH(created_at)";
$mepr_col = !empty($andmonth) ? "DAY(created_at) as mepr_day" : "MONTH(created_at) as mepr_month";

Expand All @@ -1082,7 +1081,7 @@ public static function get_refunds_dataset($month = false, $year = false, $produ

$andmonth = ($month)?" AND MONTH(created_at) = {$month}":"";
$andyear = ($year)?" AND YEAR(created_at) = {$year}":"";
$andproduct = (!isset($product) || $product == "all")?"":" AND product_id = {$product}";
$andproduct = (!isset($product) || $product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);
$groupby = !empty($andmonth) ? "GROUP BY DAY(created_at)" : "GROUP BY MONTH(created_at)";
$mepr_col = !empty($andmonth) ? "DAY(created_at) as mepr_day" : "MONTH(created_at) as mepr_month";

Expand All @@ -1106,7 +1105,7 @@ public static function get_collected_dataset($month = false, $year = false, $pro

$andmonth = ($month)?" AND MONTH(created_at) = {$month}":"";
$andyear = ($year)?" AND YEAR(created_at) = {$year}":"";
$andproduct = (!isset($product) || $product == "all")?"":" AND product_id = {$product}";
$andproduct = (!isset($product) || $product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);
$groupby = !empty($andmonth) ? "GROUP BY DAY(created_at)" : "GROUP BY MONTH(created_at)";
$mepr_col = !empty($andmonth) ? "DAY(created_at) as mepr_day" : "MONTH(created_at) as mepr_month";

Expand All @@ -1120,7 +1119,7 @@ public static function get_collected_dataset($month = false, $year = false, $pro
{$groupby}";

return self::format_mepr_dataset(
$wpdb->get_var($wpdb->get_results($q, MeprTransaction::$complete_str, MeprTransaction::$refunded_str, MeprTransaction::$payment_str))
$wpdb->get_results($wpdb->prepare($q, MeprTransaction::$complete_str, MeprTransaction::$refunded_str, MeprTransaction::$payment_str))
);
}

Expand All @@ -1129,7 +1128,7 @@ public static function get_yearly_dataset($type, $year, $product, $q=array()) {
$mepr_db = new MeprDb();

$results = array();
$andproduct = ($product == "all")?"":" AND product_id = {$product}";
$andproduct = ($product == "all")?"":$wpdb->prepare(" AND product_id = %d", $product);
$where = MeprUtils::build_where_clause($q);

$selecttype = ($type == "amounts")?"SUM(amount)":"COUNT(*)";
Expand Down Expand Up @@ -1198,7 +1197,7 @@ public static function get_yearly_dataset($type, $year, $product, $q=array()) {
$results[$i]->$type = 0;
}

$resultset = $wpdb->get_results( $wpdb->prepare($sql) );
$resultset = $wpdb->get_results( $sql );

if( ! empty($resultset) ) {
foreach( $resultset as $row ) {
Expand Down
9 changes: 4 additions & 5 deletions app/models/MeprCoupon.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,11 @@ public function maybe_apply_trial_override(&$obj) {
if( ($this->discount_mode=='trial-override' || $this->discount_mode=='first-payment') &&
$obj instanceof MeprSubscription &&
$obj->trial_amount > 0 &&
$obj->limit_cycles >= 1
$obj->limit_cycles &&
$obj->limit_cycles_num >= 1 &&
$obj->prorated_trial
) {
$product = $obj->product();
if(false == $product->trial){
$obj->limit_cycles_num = $obj->limit_cycles_num - 1;
}
$obj->limit_cycles_num = $obj->limit_cycles_num - 1;
}
}

Expand Down
5 changes: 4 additions & 1 deletion app/models/MeprSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -906,14 +906,17 @@ public function limit_payment_cycles() {
if($pm === false) { return; } //What else to do here?
$trial_offset = (($this->trial && $this->trial_amount > 0.00)?1:0);
if( 1 === $trial_offset && $this->prorated_trial && $this->trial && $this->limit_cycles ) {
$trial_offset = 0;
}

//Cancel this subscription if the payment cycles are limited and have been reached
if($this->status == MeprSubscription::$active_str && ($this->txn_count - $trial_offset) >= $this->limit_cycles_num) {

$_REQUEST['expire'] = true; // pass the expire
$_REQUEST['silent'] = true; // Don't want to send cancellation notices
try {
file_put_contents( WP_CONTENT_DIR . '/paypal-connect.log', 'Canceling sub', FILE_APPEND );
//file_put_contents( WP_CONTENT_DIR . '/paypal-connect.log', 'Canceling sub', FILE_APPEND );
$pm->process_cancel_subscription($this->id);
}
catch(Exception $e) {
Expand Down
6 changes: 5 additions & 1 deletion app/views/admin/members/list.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php if(!defined('ABSPATH')) {die('You are not allowed to call this page directly.');} ?>
<div class="wrap">
<h2><?php _e('Members', 'memberpress'); ?> <a href="<?php echo admin_url('admin.php?page=memberpress-members&action=new'); ?>" class="add-new-h2"><?php _e('Add New', 'memberpress'); ?></a></h2>
<h2>
<?php _e('Members', 'memberpress'); ?>
<?php MeprHooks::do_action('mepr-after-admin-members-heading'); ?>
<a href="<?php echo admin_url('admin.php?page=memberpress-members&action=new'); ?>" class="add-new-h2"><?php _e('Add New', 'memberpress'); ?></a>
</h2>

<?php if(!isset($errors)) { $errors = ''; } ?>
<?php MeprView::render('/admin/errors', compact('errors','message')); ?>
Expand Down
7 changes: 7 additions & 0 deletions app/views/readylaunch/shared/unauthorized.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div id="mepro-login-hero">
<div class="mepro-boxed">
<div class="mepro-login-contents">
<p><?php printf(_x('You\'re unauthorized to view this page. Why don\'t you %s and try again.', 'ui', 'memberpress'), "<a href=\"" . $mepr_options->login_page_url() . "\">" . _x('Login', 'ui', 'memberpress') . "</a>"); ?></p>
</div>
</div>
</div>
12 changes: 0 additions & 12 deletions app/views/readylaunch/unauthorized.php

This file was deleted.

0 comments on commit 6d6d8df

Please sign in to comment.