Paid Memberships Pro includes three reports in the Memberships > Reports screen of the WordPress admin. These reports highlight Sales and Revenue, Signups and Cancellations, as well as data for Member Visits, Views and Logins.

In this code recipe, we show you how to new blank report you can use as a basis to create your own report widget or report details page. Your custom report, like this one we made to show membership order refund rate, appears like any other built-in report in the Memberships admin area.

Banner for Advanced Code Recipe Tutorial for Paid Memberships Pro

The Code Recipe

This code recipe creates the placeholder code for your new custom report widget and report page. You will need additional development to create the actual report contents. Check this post on how to create a refund rate report. You can also see this recipe that shows you how to query active members based on usermeta, which is useful for creating custom member reports.

<?php
/**
* Create a custom report
*
* title: Create a custom report
* layout: snippet
* collection: admin-pages
* category: reports
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
/**
* Add a Custom Report to the Memberships > Reports Screen in Paid Memberships Pro.
*
* For each report, add a line like:
* global $pmpro_reports;
* $pmpro_reports['slug'] = 'Title';
*
* For each report, also write two functions:
* pmpro_report_{slug}_widget() to show up on the report homepage.
* pmpro_report_{slug}_page() to show up when users click on the report page widget.
*
*/
global $pmpro_reports;
$pmpro_reports['sample'] = __('My Sample Report', 'pmpro-reports-extras');
// Sample Report for Metabox
function pmpro_report_sample_widget() { ?>
<span id="pmpro_report_sample" class="pmpro_report-holder">
<p>Hi! I'm a sample report!</p>
<?php if ( function_exists( 'pmpro_report_sample_page' ) ) { ?>
<p class="pmpro_report-button">
<a class="button button-primary" href="<?php echo admin_url( 'admin.php?page=pmpro-reports&report=sample' ); ?>"><?php _e('Details', 'paid-memberships-pro' );?></a>
</p>
<?php } ?>
</span>
<?php
}
// Sample Report for Individual Report Page
function pmpro_report_sample_page() { ?>
<h1><?php _e( 'This is a Sample', 'pmpro-reports-extras' ); ?></h2>
<p>This report demonstrates how to add a custom report to PMPro. Enjoy!.</p>
<?php
}

Adding the Recipe to Your Website

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.

If you are using a plugin for PMPro Customizations, you can keep things organized by saving your customized report code in a separate .php file and then require it within the Customizations plugin, like this:

require_once(dirname(__FILE__) . "/reports/pmpro-reports-extras.php");

Screenshot: The Sample Report Widget

Screenshot of the Memberships > Reports admin screen with a sample report widget.

Free Course: Membership Site Development—The Basics

Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.

Featured Image for Membership Site Development Course: The Basics


Was this article helpful?
YesNo