Skip to content

Commit

Permalink
Updates to 1.11.25
Browse files Browse the repository at this point in the history
  • Loading branch information
MemberPress committed Feb 21, 2024
1 parent 011f41f commit 0df461a
Show file tree
Hide file tree
Showing 50 changed files with 1,665 additions and 487 deletions.
41 changes: 26 additions & 15 deletions app/controllers/MeprAppCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,21 +988,32 @@ public static function add_dashboard_widgets()

public static function weekly_stats_widget() {
$mepr_options = MeprOptions::fetch();
$failed_transactions = $pending_transactions = $refunded_transactions = $completed_transactions = $revenue = $refunds = 0;
$time = time();
for($i = 0; $i < 7; $i++) {
$ts = $time - MeprUtils::days($i);
$month = gmdate('n', $ts);
$day = gmdate('j', $ts);
$year = gmdate('Y', $ts);

$pending_transactions += MeprReports::get_transactions_count(MeprTransaction::$pending_str, $day, $month, $year);
$failed_transactions += MeprReports::get_transactions_count(MeprTransaction::$failed_str, $day, $month, $year);
$refunded_transactions += MeprReports::get_transactions_count(MeprTransaction::$refunded_str, $day, $month, $year);
$completed_transactions += MeprReports::get_transactions_count(MeprTransaction::$complete_str, $day, $month, $year);

$revenue += MeprReports::get_revenue($month, $day, $year);
$refunds += MeprReports::get_refunds($month, $day, $year);

$status_collection = array(
MeprTransaction::$pending_str,
MeprTransaction::$failed_str,
MeprTransaction::$refunded_str,
MeprTransaction::$complete_str
);

$start_date = new \DateTimeImmutable('-6 days', new \DateTimeZone('UTC'));
$end_date = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));

$status_data = MeprReports::get_date_range_transactions_counts($status_collection, $start_date, $end_date);
$pending_transactions = $status_data[MeprTransaction::$pending_str];
$failed_transactions = $status_data[MeprTransaction::$failed_str];
$refunded_transactions = $status_data[MeprTransaction::$refunded_str];
$completed_transactions = $status_data[MeprTransaction::$complete_str];

$revenue = MeprReports::get_date_range_revenue($start_date, $end_date);
$refunds = MeprReports::get_date_range_refunds($start_date, $end_date);

if( empty($revenue) || is_null($revenue) ) {
$revenue = 0;
}

if( empty($refunds) || is_null($refunds) ) {
$refunds = 0;
}

MeprView::render('/admin/widgets/admin_stats_widget', get_defined_vars());
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/MeprCoursesCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function ajax_courses_action() {
$message = $installed ? esc_html__( 'Courses has been installed and activated successfully. Enjoy!', 'memberpress' ) : esc_html__( 'Courses could not be installed. Please check your license settings, or contact MemberPress support for help.', 'memberpress' );
break;
case 'activate' : // Just activate (already installed)
$activated = activate_plugin( $this->courses_slug );
$activated = is_null( activate_plugin( $this->courses_slug ) );
$result = 'success';
$message = esc_html__( 'Courses has been activated successfully. Enjoy!', 'memberpress' );
break;
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/MeprGrowthToolsCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class MeprGrowthToolsCtrl extends MeprBaseCtrl
{
public function load_hooks()
{
if (class_exists('\MemberPress\Caseproof\GrowthTools\App')) {
if (class_exists('\MemberPress\Caseproof\GrowthTools\App') && version_compare(phpversion(), '7.4', '>=')) {
add_action('admin_enqueue_scripts', function () {
$screen = get_current_screen();
if ($screen->id == 'memberpress_page_memberpress-growth-tools') {
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/MeprLoginCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function process_forgot_password_form() {

extract($_POST, EXTR_SKIP);

$mepr_user_or_email = wp_unslash($mepr_user_or_email);

if(empty($errors)) {
$is_email = (is_email($mepr_user_or_email) and email_exists($mepr_user_or_email));
$is_username = username_exists($mepr_user_or_email);
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/MeprMembersCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public function table_search_box() {
if(isset($_REQUEST['page']) && $_REQUEST['page']=='memberpress-members') {
$membership = (isset($_REQUEST['membership'])?$_REQUEST['membership']:false);
$status = (isset($_REQUEST['status'])?$_REQUEST['status']:'all');
$prds = MeprCptModel::all('MeprProduct');
$prds = MeprCptModel::all('MeprProduct', false, array('orderby' => 'title', 'order' => 'ASC'));
MeprView::render('/admin/members/search_box', compact('membership','status','prds'));
}
}
Expand Down
168 changes: 164 additions & 4 deletions app/controllers/MeprProductsCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public function load_hooks() {

// Cleanup list view
add_filter('views_edit-'.MeprProduct::$cpt, 'MeprAppCtrl::cleanup_list_view' );

// Category filter
add_action('init', 'MeprProductsCtrl::register_taxonomy');
add_action('admin_init', 'MeprProductsCtrl::register_filter_queries');
add_action('restrict_manage_posts', 'MeprProductsCtrl::render_memberships_filters', 10, 1);
add_action('admin_footer-edit.php', 'MeprProductsCtrl::render_categories_button');
}

public function register_post_type() {
Expand Down Expand Up @@ -64,13 +70,53 @@ public function register_post_type() {
register_post_type( $this->cpt->slug, $this->cpt->config );
}

public static function register_taxonomy() {
register_taxonomy(
MeprProduct::$taxonomy_product_category,
MeprProduct::$cpt,
array(
'labels' => array(
'name' => esc_html_x( 'Categories', 'taxonomy general name', 'memberpress' ),
'singular_name' => esc_html_x( 'Category', 'taxonomy singular name', 'memberpress' ),
'search_items' => esc_html__( 'Search Categories', 'memberpress' ),
'all_items' => esc_html__( 'All Categories', 'memberpress' ),
'parent_item' => esc_html__( 'Parent Category', 'memberpress' ),
'parent_item_colon' => esc_html__( 'Parent Category:', 'memberpress' ),
'edit_item' => esc_html__( 'Edit Category', 'memberpress' ),
'update_item' => esc_html__( 'Update Category', 'memberpress' ),
'add_new_item' => esc_html__( 'Add New Category', 'memberpress' ),
'new_item_name' => esc_html__( 'New Category Name', 'memberpress' ),
'menu_name' => esc_html__( 'Categories', 'memberpress' ),
'separate_items_with_commas' => esc_html__( 'Separate Categories with commas', 'memberpress' ),
'add_or_remove_items' => esc_html__( 'Add or remove Categories', 'memberpress' ),
'choose_from_most_used' => esc_html__( 'Choose from the most used', 'memberpress' ),
'popular_items' => esc_html__( 'Popular Categories', 'memberpress' ),
'not_found' => esc_html__( 'Not Found', 'memberpress' ),
'no_terms' => esc_html__( 'No Categories', 'memberpress' ),
'items_list' => esc_html__( 'Categories list', 'memberpress' ),
'items_list_navigation' => esc_html__( 'Categories list navigation', 'memberpress' )
),
'hierarchical' => false,
'show_ui' => true,
'show_admin_column' => true,
'rewrite' => false,
'capabilities' => array(
'manage_terms' => 'manage_options',
'edit_terms' => 'manage_options',
'delete_terms' => 'manage_options',
'assign_terms' => 'manage_options'
)
)
);
}

public static function columns($columns) {
$columns = array(
"cb" => "<input type=\"checkbox\" />",
"ID" => __("ID", 'memberpress'),
"title" => __("Membership Title", 'memberpress'),
"terms" => __("Terms", 'memberpress'),
"url" => __('URL', 'memberpress')
"ID" => esc_html__("ID", 'memberpress'),
"title" => esc_html__("Membership Title", 'memberpress'),
"terms" => esc_html__("Terms", 'memberpress'),
"url" => esc_html__('URL', 'memberpress')
);
return MeprHooks::apply_filters('mepr-admin-memberships-columns', $columns);
}
Expand Down Expand Up @@ -840,4 +886,118 @@ public static function shortcode_price($atts = array(), $content = '') {
return MeprUtils::format_float_drop_zero_decimals($display_price);
}

/**
* Render filters for membership products.
*/
public static function render_memberships_filters($post_type) {
if ($post_type === MeprProduct::$cpt) {
$taxonomy = MeprProduct::$taxonomy_product_category;
$selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
$info_taxonomy = get_taxonomy($taxonomy);

if( false === $info_taxonomy ) {
return;
}

$taxonomy_args = array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
'fields' => 'ids',
'number' => 1
);

$taxonomy_terms = get_terms( $taxonomy_args );

if ( empty( $taxonomy_terms ) ) {
return;
}

wp_dropdown_categories(array(
'show_option_all' => sprintf( esc_html__( 'Show all %s', 'memberpress' ), $info_taxonomy->label ),
'taxonomy' => $taxonomy,
'name' => $taxonomy,
'orderby' => 'name',
'selected' => $selected,
'show_count' => true,
'hide_empty' => false
));

echo wp_kses(
sprintf( '<input type="submit" id="mepr_filter_submit" class="button" value="%s">', esc_html__('Filter', 'memberpress') ),
array(
'input' => array(
'type' => array(),
'name' => array(),
'id' => array(),
'class'=> array(),
'value'=> array(),
)
)
);
}
}

public static function register_filter_queries() {
add_action('parse_query', 'MeprProductsCtrl::filter_memberships');
}

/**
* Filter the memberships as per selected taxonomy.
*
* @param $query
*/
public static function filter_memberships($query) {
global $pagenow;
$taxonomy = MeprProduct::$taxonomy_product_category;
if (
$pagenow == 'edit.php' && is_admin()
&& isset($query->query_vars['post_type'])
&& $query->query_vars['post_type'] === MeprProduct::$cpt
&& isset($query->query_vars[$taxonomy])
&& is_numeric($query->query_vars[$taxonomy])
&& 0 < absint($query->query_vars[$taxonomy])
) {
$term = get_term_by('id', (int) $query->query_vars[$taxonomy], $taxonomy);
if ($term && ! is_wp_error($term)) {
$query->query_vars[$taxonomy] = $term->slug;
}
}
}
/**
* Render category button beside 'Add New' button.
*
* @return void
*/
public static function render_categories_button(){
if ( empty( $_GET['post_type'] ) || MeprProduct::$cpt !== $_GET['post_type'] ) {
return;
}
$category_link = add_query_arg( array(
'taxonomy' => MeprProduct::$taxonomy_product_category,
'post_type' => MeprProduct::$cpt
),
esc_url(admin_url('edit-tags.php'))
);
$category_btn = wp_kses(
sprintf(
'<a href="%1$s" class="page-title-action" target = _blank>%2$s</a>',
$category_link,
esc_html__( 'Categories', 'memberpress' )
),
array(
'a' => array(
'href' => array(),
'class' => array(),
'target' => array()
)
)
);
?>
<script>
jQuery(document).ready(function($) {
$('.wrap .wp-header-end').before("<?php echo addslashes( $category_btn ); ?>");
});
</script>
<?php
}
} //End class
2 changes: 1 addition & 1 deletion app/controllers/MeprReadyLaunchCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function pricing_table_shortcode( $atts = array() ) {
* @return void
*/
public function account_shortcode( $atts = array() ) {
wp_enqueue_script( 'alpinejs', MEPR_JS_URL . '/js/vendor/alpine.min.js', array(), MEPR_VERSION, true );
wp_enqueue_script( 'alpinejs', MEPR_JS_URL . '/vendor/alpine.min.js', array(), MEPR_VERSION, true );
wp_enqueue_script( 'mepr-accountjs', MEPR_JS_URL . '/readylaunch/account.js', array( 'jquery' ), MEPR_VERSION, true );
wp_localize_script(
'mepr-accountjs',
Expand Down
72 changes: 66 additions & 6 deletions app/controllers/MeprReportsCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ public function load_hooks() {
add_action('wp_ajax_mepr_month_report', 'MeprReportsCtrl::load_monthly');
add_action('wp_ajax_mepr_year_report', 'MeprReportsCtrl::load_yearly');
add_action('wp_ajax_mepr_widget_report', 'MeprReportsCtrl::load_widget');
add_action('wp_ajax_mepr_overall_info_blocks', 'MeprReportsCtrl::load_overall_info');
add_action('wp_ajax_mepr_month_info_blocks', 'MeprReportsCtrl::load_month_info_blocks');
add_action('wp_ajax_mepr_month_info_table', 'MeprReportsCtrl::load_month_info_table');
add_action('wp_ajax_mepr_year_info_blocks', 'MeprReportsCtrl::load_year_info_blocks');
add_action('wp_ajax_mepr_year_info_table', 'MeprReportsCtrl::load_year_info_table');
add_action('wp_ajax_mepr_all_time_info_blocks', 'MeprReportsCtrl::load_all_time_info_blocks');
}

public static function main() {
Expand Down Expand Up @@ -155,14 +161,14 @@ public static function monthly_table( $export = false ) {
$q = (isset($_REQUEST['q']) && $_REQUEST['q'] != 'none')?$_REQUEST['q']:array();

if( $export ) {
$txns = MeprReports::get_monthly_data('transactions', $month, $year, $product, $q);
$amts = MeprReports::get_monthly_data('amounts', $month, $year, $product, $q);
$txns = MeprReports::get_monthly_dataset('transactions', $month, $year, $product, $q);
$amts = MeprReports::get_monthly_dataset('amounts', $month, $year, $product, $q);
$filename = "memberpress-monthly-{$month}-{$year}-{$type}-for-{$product}";
$results = self::format_for_csv( $txns, $amts );
MeprUtils::render_csv( array_values($results), $filename );
}

$results = MeprReports::get_monthly_data($type, $month, $year, $product);
$results = MeprReports::get_monthly_dataset($type, $month, $year, $product);

$chart_data =
array( 'cols' =>
Expand Down Expand Up @@ -221,13 +227,13 @@ public static function yearly_table($export=false) {

if( $export ) {
$filename = "memberpress-yearly-{$year}-{$type}-for-{$product}";
$txns = MeprReports::get_yearly_data('transactions', $year, $product, $q);
$amts = MeprReports::get_yearly_data('amounts', $year, $product, $q);
$txns = MeprReports::get_yearly_dataset('transactions', $year, $product, $q);
$amts = MeprReports::get_yearly_dataset('amounts', $year, $product, $q);
$results = self::format_for_csv( $txns, $amts );
MeprUtils::render_csv( $results, $filename );
}

$results = MeprReports::get_yearly_data($type, $year, $product);
$results = MeprReports::get_yearly_dataset($type, $year, $product);

$chart_data =
array( 'cols' =>
Expand Down Expand Up @@ -314,4 +320,58 @@ public static function format_for_csv( $txns, $amts ) {

return $csv;
}

public static function load_overall_info() {
check_ajax_referer('mepr_reports', 'report_nonce');
wp_send_json_success(array(
'output' => MeprView::get_string("/admin/reports/overall_info_blocks")
));
}

protected static function do_common_vars(){
$curr_month = (isset($_GET['month']) && !empty($_GET['month']))?$_GET['month']:gmdate('n');
$curr_year = (isset($_GET['year']) && !empty($_GET['year']))?$_GET['year']:gmdate('Y');
$curr_product = (isset($_GET['product']) && !empty($_GET['product']))?$_GET['product']:'all';

return array(
'curr_month' => $curr_month,
'curr_year' => $curr_year,
'curr_product' => $curr_product
);
}

public static function load_month_info_blocks() {
check_ajax_referer('mepr_reports', 'report_nonce');
wp_send_json_success(array(
'output' => MeprView::get_string("/admin/reports/month_info_blocks", self::do_common_vars())
));
}

public static function load_month_info_table() {
check_ajax_referer('mepr_reports', 'report_nonce');
wp_send_json_success(array(
'output' => MeprView::get_string("/admin/reports/month_table", self::do_common_vars())
));
}

public static function load_year_info_blocks() {
check_ajax_referer('mepr_reports', 'report_nonce');
wp_send_json_success(array(
'output' => MeprView::get_string("/admin/reports/year_info_blocks", self::do_common_vars())
));
}

public static function load_year_info_table() {
check_ajax_referer('mepr_reports', 'report_nonce');
wp_send_json_success(array(
'output' => MeprView::get_string("/admin/reports/year_table", self::do_common_vars())
));
}

public static function load_all_time_info_blocks() {
check_ajax_referer('mepr_reports', 'report_nonce');
wp_send_json_success(array(
'output' => MeprView::get_string("/admin/reports/all_time_info_blocks", self::do_common_vars())
));
}
}

0 comments on commit 0df461a

Please sign in to comment.