Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Last active July 23, 2019 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remcotolsma/ecc33e2f14c5035aabc876d73fbe0b62 to your computer and use it in GitHub Desktop.
Save remcotolsma/ecc33e2f14c5035aabc876d73fbe0b62 to your computer and use it in GitHub Desktop.
Restrict Content Pro update 2 to 3 fixer
<?php
define( 'WP_USE_THEMES', false );
require '../../../../wp-blog-header.php';
global $wpdb;
$query = new WP_Query(
array(
'post_type' => 'pronamic_pay_subscr',
'post_status' => 'any',
'posts_per_page' => -1,
'no_found_rows' => true,
'meta_query' => array(
array(
'key' => '_pronamic_subscription_source',
'value' => 'restrictcontentpro',
),
),
)
);
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Restrict Content Pro update version 2 to 3 fixer</title>
</head>
<body>
<h1>Restrict Content Pro update version 2 to 3 fixer</h1>
<div>
<h2>Subscriptions</h2>
<?php if ( $query->have_posts() ) : ?>
<table class="table table-striped">
<thead>
<tr>
<th scope="col" colspan="6"></th>
<th scope="col" colspan="3">Restrict Content Pro</th>
</tr>
<tr>
<th scope="col">ID</th>
<th scope="col">Title</th>
<th scope="col">Status</th>
<th scope="col">Source</th>
<th scope="col">Source ID</th>
<th scope="col">User ID</th>
<th scope="col">Customer</th>
<th scope="col">Member (deprecated)</th>
<th scope="col">Membership</th>
</tr>
</thead>
<tbody>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<tr>
<?php
$post_id = get_the_ID();
$status = get_post_meta( $post_id, '_pronamic_subscription_status', true );
$source = get_post_meta( $post_id, '_pronamic_subscription_source', true );
$source_id = get_post_meta( $post_id, '_pronamic_subscription_source_id', true );
$user_id = $source_id;
$rcp_customer = null;
$rcp_member = null;
$rcp_membership = null;
$rcp_customer = rcp_get_customer_by_user_id( $user_id );
if ( false !== $rcp_customer ) {
$rcp_membership = rcp_get_customer_single_membership( $rcp_customer->get_id() );
}
if ( is_object( $rcp_membership ) ) {
update_post_meta( $post_id, '_pronamic_subscription_source', 'rcp_membership' );
update_post_meta( $post_id, '_pronamic_subscription_source_id', $rcp_membership->get_id() );
}
?>
<td>
<?php echo esc_html( get_the_ID() ); ?>
</td>
<td>
<?php echo esc_html( get_the_title() ); ?>
</td>
<td>
<?php echo esc_html( $status ); ?>
</td>
<td>
<?php echo esc_html( $source ); ?>
</td>
<td>
<?php echo esc_html( $source_id ); ?>
</td>
<td>
<?php echo esc_html( $user_id ); ?>
</td>
<td>
<?php var_dump( $rcp_customer ); ?>
</td>
<td>
<?php var_dump( $rcp_member ); ?>
</td>
<td>
<?php var_dump( $rcp_membership ); ?>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</div>
<div>
<h2>Payments</h2>
<?php
$rcp_payments = new RCP_Payments();
$query = new WP_Query(
array(
'post_type' => 'pronamic_payment',
'post_status' => 'any',
'posts_per_page' => -1,
'no_found_rows' => true,
'meta_query' => array(
array(
'key' => '_pronamic_payment_source',
'value' => 'restrictcontentpro',
),
),
)
);
?>
<?php if ( $query->have_posts() ) : ?>
<table class="table table-striped">
<thead>
<tr>
<th scope="col" colspan="7"></th>
<th scope="col" colspan="4">Restrict Content Pro</th>
</tr>
<tr>
<th scope="col">ID</th>
<th scope="col">Title</th>
<th scope="col">Status</th>
<th scope="col">Transaction ID</th>
<th scope="col">Source</th>
<th scope="col">Source ID</th>
<th scope="col">User ID</th>
<th scope="col">Customer</th>
<th scope="col">Member (deprecated)</th>
<th scope="col">Membership</th>
<th scope="col">Payment</th>
</tr>
</thead>
<tbody>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<tr>
<?php
$post_id = get_the_ID();
$status = get_post_meta( $post_id, '_pronamic_payment_status', true );
$source = get_post_meta( $post_id, '_pronamic_payment_source', true );
$source_id = get_post_meta( $post_id, '_pronamic_payment_source_id', true );
$transaction_id = get_post_meta( $post_id, '_pronamic_payment_transaction_id', true );
$user_id = $source_id;
$rcp_customer = null;
$rcp_member = null;
$rcp_membership = null;
$rcp_payment = $rcp_payments->get_payment_by( 'transaction_id', $transaction_id );
$rcp_customer = rcp_get_customer_by_user_id( $user_id );
if ( false !== $rcp_customer ) {
$rcp_membership = rcp_get_customer_single_membership( $rcp_customer->get_id() );
}
if ( is_object( $rcp_payment ) ) {
update_post_meta( $post_id, '_pronamic_payment_source', 'rcp_payment' );
update_post_meta( $post_id, '_pronamic_payment_source_id', $rcp_payment->id );
}
?>
<td>
<?php echo esc_html( get_the_ID() ); ?>
</td>
<td>
<?php echo esc_html( get_the_title() ); ?>
</td>
<td>
<?php echo esc_html( $status ); ?>
</td>
<td>
<?php echo esc_html( $transaction_id ); ?>
</td>
<td>
<?php echo esc_html( $source ); ?>
</td>
<td>
<?php echo esc_html( $source_id ); ?>
</td>
<td>
<?php echo esc_html( $user_id ); ?>
</td>
<td>
<?php var_dump( $rcp_customer ); ?>
</td>
<td>
<?php var_dump( $rcp_member ); ?>
</td>
<td>
<?php var_dump( $rcp_membership ); ?>
</td>
<td>
<?php var_dump( $rcp_payment ); ?>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</div>
<div>
<h2>Subscriptions Next Payment Delivery Date</h2>
<?php
$query = new WP_Query(
array(
'post_type' => 'pronamic_pay_subscr',
'post_status' => 'any',
'posts_per_page' => -1,
'no_found_rows' => true,
'meta_query' => array(
array(
'key' => '_pronamic_subscription_payment_method',
'value' => 'direct_debit_ideal',
),
array(
'key' => '_pronamic_subscription_next_payment',
'compare' => 'EXISTS',
),
array(
'key' => '_pronamic_subscription_next_payment_delivery_date',
'compare' => 'NOT EXISTS',
),
),
)
);
?>
<?php if ( $query->have_posts() ) : ?>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Title</th>
<th scope="col">Status</th>
<th scope="col">Source</th>
<th scope="col">Source ID</th>
<th scope="col">Next Payment Date</th>
</tr>
</thead>
<tbody>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<tr>
<?php
$post_id = get_the_ID();
$status = get_post_meta( $post_id, '_pronamic_subscription_status', true );
$source = get_post_meta( $post_id, '_pronamic_subscription_source', true );
$source_id = get_post_meta( $post_id, '_pronamic_subscription_source_id', true );
$next_payment_date_string = get_post_meta( $post_id, '_pronamic_subscription_next_payment', true );
$next_payment_date = new DateTime( $next_payment_date_string );
$next_payment_delivery_date = clone $next_payment_date;
$day_of_week = $next_payment_date->format( 'l' );
switch ( $day_of_week ) {
case 'Monday':
$next_payment_delivery_date->modify( '-3 days' );
break;
case 'Saturday':
$next_payment_delivery_date->modify( '-2 days' );
break;
case 'Sunday':
$next_payment_delivery_date->modify( '-3 days' );
break;
default:
$next_payment_delivery_date->modify( '-1 day' );
break;
}
$next_payment_delivery_date->setTime( 0, 0, 0 );
update_post_meta( $post_id, '_pronamic_subscription_next_payment_delivery_date', $next_payment_delivery_date->format( 'Y-m-d H:i:s' ) );
?>
<td>
<?php echo esc_html( get_the_ID() ); ?>
</td>
<td>
<?php echo esc_html( get_the_title() ); ?>
</td>
<td>
<?php echo esc_html( $status ); ?>
</td>
<td>
<?php echo esc_html( $source ); ?>
</td>
<td>
<?php echo esc_html( $source_id ); ?>
</td>
<td>
<?php var_dump(expression)( $next_payment_date_string ); ?>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment