Skip to content

Commit

Permalink
Merge pull request #15 from kimcoleman/fix-new-install-no-levels
Browse files Browse the repository at this point in the history
Fixing activation notice for PMPro not installed; fixing no child accounts to add to group
  • Loading branch information
kimcoleman authored Dec 6, 2023
2 parents a3afd6a + 9f40d3b commit d90379d
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 122 deletions.
80 changes: 79 additions & 1 deletion includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ) { ?>
<div class="updated notice is-dismissible">
Expand All @@ -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( '<a href="%s">%s</a>', 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(
'<div class="notice notice-warning"><p>%s</p></div>',
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( '<a href="%s">%s</a>', 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(
'<div class="notice notice-warning"><p>%s</p></div>',
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.
*/
Expand Down Expand Up @@ -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 );

Expand Down
Loading

0 comments on commit d90379d

Please sign in to comment.