diff --git a/includes/admin.php b/includes/admin.php
index 80ffe3e..313ed80 100644
--- a/includes/admin.php
+++ b/includes/admin.php
@@ -20,6 +20,11 @@ function pmprogroupacct_admin_notice_activation_hook() {
* @since 1.0
*/
function pmprogroupacct_admin_notice() {
+ // Paid Memberships Pro not activated, let's bail.
+ if ( ! defined( 'PMPRO_VERSION' ) ) {
+ return;
+ }
+
// Check transient, if available display notice.
if ( get_transient( 'pmpro-group-accounts-admin-notice' ) ) { ?>
@@ -32,6 +37,79 @@ function pmprogroupacct_admin_notice() {
}
add_action( 'admin_notices', 'pmprogroupacct_admin_notice' );
+/**
+ * Show a message if Paid Memberships Pro is inactive or not installed.
+ */
+function pmprogroupacct_required_installed() {
+ // The required plugins for this Add On to work.
+ $required_plugins = array(
+ 'paid-memberships-pro' => __( 'Paid Memberships Pro', 'pmpro-group-accounts' ),
+ );
+
+ // Check if the required plugins are installed.
+ $missing_plugins = array();
+ foreach ( $required_plugins as $plugin => $name ) {
+ if ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin ) ) {
+ $missing_plugins[$plugin] = $name;
+ }
+ }
+
+ // If there are missing plugins, show a notice.
+ if ( ! empty( $missing_plugins ) ) {
+ // Build install links here.
+ $install_plugins = array();
+ foreach( $missing_plugins as $path => $name ) {
+ $install_plugins[] = sprintf( '%s', esc_url( wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $path ), 'install-plugin_' . $path ) ), esc_html( $name ) );
+ }
+
+ // Show notice with install_plugin links.
+ printf(
+ '
%s
',
+ sprintf(
+ /* translators: 1: This plugin's name. 2: Required plugin name(s). */
+ esc_html__( 'The following plugin(s) are required for the %1$s plugin to work: %2$s', 'pmpro-group-accounts' ),
+ esc_html__( 'Group Accounts', 'pmpro-group-accounts' ),
+ implode( ', ', $install_plugins ) // $install_plugins was escaped when built.
+ )
+ );
+
+ return; // Bail here, so we only show one notice at a time.
+ }
+
+ // Check if the required plugins are active and show a notice with activation links if they are not
+ $inactive_plugins = array();
+ foreach ( $required_plugins as $plugin => $name ) {
+ $full_path = $plugin . '/' . $plugin . '.php';
+ if ( ! is_plugin_active( $full_path ) ) {
+ $inactive_plugins[$plugin] = $name;
+ }
+ }
+
+ // If there are inactive plugins, show a notice.
+ if ( ! empty( $inactive_plugins ) ) {
+ // Build activate links here.
+ $activate_plugins = array();
+ foreach( $inactive_plugins as $path => $name ) {
+ $full_path = $path . '/' . $path . '.php';
+ $activate_plugins[] = sprintf( '%s', esc_url( wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $full_path ), 'activate-plugin_' . $full_path ) ), esc_html( $name ) );
+ }
+
+ // Show notice with activate_plugin links.
+ printf(
+ '
%s
',
+ sprintf(
+ /* translators: 1: This plugin's name. 2: Required plugin name(s). */
+ esc_html__( 'The following plugin(s) are required for the %1$s plugin to work: %2$s', 'pmpro-group-accounts' ),
+ esc_html__( 'Group Accounts', 'pmpro-group-accounts' ),
+ implode( ', ', $activate_plugins ) // $activate_plugins was escaped when built.
+ )
+ );
+
+ return; // Bail here, so we only show one notice at a time.
+ }
+}
+add_action( 'admin_notices', 'pmprogroupacct_required_installed' );
+
/**
* Show the group information associated with a child order on the Edit Order page.
*/
@@ -89,7 +167,7 @@ function pmprogroupacct_after_order_settings( $order ) {
function pmprogroupacct_manage_orderslist_columns( $columns ) {
$columns['pmprogroupacct_code'] = __( 'Group Code', 'pmpro-group-accounts' );
$columns['pmprogroupacct_parent'] = __( 'Parent Account', 'pmpro-group-accounts' );
- return $columns;
+ return $columns;
}
add_filter( 'pmpro_manage_orderslist_columns', 'pmprogroupacct_manage_orderslist_columns', 10, 1 );
diff --git a/includes/edit-level.php b/includes/edit-level.php
index c90dd4d..03a3065 100644
--- a/includes/edit-level.php
+++ b/includes/edit-level.php
@@ -24,127 +24,154 @@ function pmprogroupacct_pmpro_membership_level_before_content_settings( $level )
$settings = array_merge( $settings, $saved_settings );
}
+ // Get all membership levels.
+ $all_levels = pmpro_getAllLevels( true, true );
+
+ // Remove the current level from the list of levels.
+ unset( $all_levels[ $level->id ] );
+
// Build the settings UI.
+ if ( count( $all_levels ) === 0 ) {
+ $section_visibility = 'hidden';
+ $section_activated = 'false';
+ } else {
+ $section_visibility = 'shown';
+ $section_activated = 'true';
+ }
?>
-
+
-
-
+
>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ create an additional membership level to use as the child account for this group.', 'pmpro-group-accounts' ), add_query_arg( array( 'page' => 'pmpro-membershiplevels' ), admin_url( 'admin.php' ) ) ); ?>
+