Skip to content

Instantly share code, notes, and snippets.

@kimwhite
Last active August 16, 2024 12:56
Show Gist options
  • Save kimwhite/bd88fe488f6d5d7a06d9499d28c6632b to your computer and use it in GitHub Desktop.
Save kimwhite/bd88fe488f6d5d7a06d9499d28c6632b to your computer and use it in GitHub Desktop.
This recipe remove the default code that adds the sponsor area to membership account page
<?php
/**
* This recipe remove the default code that addes the sponsor area to membership account page
* Needed when using WPML
*
* 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/
*/
remove_filter( "the_content", "pmprosm_the_content_account_page", 30 );
function my_pmprosm_the_content_account_page( $content ) {
global $post, $pmpro_pages, $current_user, $wpdb;
if( ! is_admin() && false !== strpos( $content, '<!-- end pmpro_account -->' ) ) {
//what's their code?
$code_id = pmprosm_getCodeByUserID( $current_user->ID );
if ( isset( $current_user->membership_level->ID ) ) {
$pmprosm_values = pmprosm_getValuesByMainLevel( $current_user->membership_level->ID );
} else {
$pmprosm_values = '';
}
if(! empty( $code_id ) && ! empty( $pmprosm_values ) ) {
$code = pmprosm_getDiscountCodeByCodeID( $code_id );
if( ! is_array( $pmprosm_values['sponsored_level_id'] ) ) {
$sponsored_level_ids = array($pmprosm_values['sponsored_level_id']);
} else {
$sponsored_level_ids = $pmprosm_values['sponsored_level_id'];
}
// No sponsored levels to use codes for.
if( empty( $sponsored_level_ids ) || empty( $sponsored_level_ids[0] ) ) {
return $content;
}
$code_urls = pmprosm_get_checkout_urls( $code );
ob_start();
$limit = 1;
if( isset( $pmprosm_values['max_seats'] ) ) {
$limit = $pmprosm_values['max_seats'];
}
// Removing a sponsored member?
if( isset( $_REQUEST['pmprosm_remove_member_id'] ) && isset( $_REQUEST['pmprosm_remove_member_level'] ) ) {
// Check nonce.
if( wp_verify_nonce( $_REQUEST['_wpnonce'], 'pmprosm_remove_member' ) ) {
// Nonce is good. Remove the member.
$removed = pmprosm_remove_member_from_seat( intval( $_REQUEST['pmprosm_remove_member_id'] ), intval( $_REQUEST['pmprosm_remove_member_level'] ), $current_user->ID );
if ( $removed !== false ) {
$member = get_userdata( intval( $_REQUEST['pmprosm_remove_member_id'] ) );
$removed_message = sprintf( __( 'Sponsored User: %s was removed. (Membership Level: %s)', 'pmpro-sponsored-members' ), $member->display_name, intval( $_REQUEST['pmprosm_remove_member_level'] ) );
}
}
}
// Get members.
$member_ids = pmprosm_getChildren($current_user->ID);
?>
<div id="pmpro_account-sponsored" class="pmpro_box">
<h3><?php esc_html_e( "Sponsored Seats", "pmpro-sponsored-members" );?></h3>
<?php if (empty($pmprosm_values['hide_display_discount_code']) || $pmprosm_values['hide_display_discount_code'] === false ) { ?>
<p><?php printf(esc_html__("Give this code to your sponsored members to use at checkout: %s", "pmpro-sponsored-members"), '<strong>' . $code->code . '</strong>');?></p>
<?php if(count($code_urls) > 1) { ?>
<p><?php esc_html_e("Or provide one of these direct links to register:", "pmpro-sponsored-members");?></p>
<?php } else { ?>
<p><?php esc_html_e("Or provide this direct link to register:", "pmpro-sponsored-members");?></p>
<?php } ?>
<ul>
<?php foreach($code_urls as $code_url) { ?>
<li><?php echo esc_html( $code_url['name'] );?>: <strong><a target="_blank" href="<?php echo esc_url( $code_url['url'] );?>"><?php echo esc_url( $code_url['url'] );?></a></strong></li>
<?php } ?>
</ul>
<?php } // hide_display_discount_code ?>
<div class="pmpro_message pmpro_default">
<?php if(empty($code->uses)) { ?>
<?php esc_html_e( "This code has unlimited uses.", "pmpro-sponsored-members" );?>
<?php } else { ?>
<?php printf( esc_html__("%s/%s uses.", "pmpro-sponsored-members" ), count( $member_ids ), $code->uses );?>
<?php } ?>
</div>
<?php
// Did we remove a child earlier?
if ( ! empty( $removed_message ) ) {
?>
<div class="pmpro_message pmpro_success"><?php echo esc_html( $removed_message ); ?></div>
<?php
}
// use same account display as in admin
if ( ! empty( $member_ids ) ) {
echo "<hr />";
echo pmprosm_display_sponsored_accounts( $member_ids );
}
?>
</div> <!-- end pmpro_account-sponsored -->
<?php
$temp_content = ob_get_contents();
ob_end_clean();
$content = str_replace( '<!-- end pmpro_account-profile -->', '<!-- end pmpro_account-profile -->' . $temp_content, $content );
}
}
return $content;
}
add_filter( "the_content", "my_pmprosm_the_content_account_page", 30 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment