Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/paid-memberships-pro/preheaders/confirmation.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + global $current_user, $pmpro_invoice;
3 +
4 + // Redirect non-user to the login page; pass the Confirmation page as the redirect_to query arg.
5 + if ( ! is_user_logged_in() ) {
6 + // Get level ID from URL parameter.
7 + if ( ! empty( $_REQUEST['pmpro_level'] ) ) {
8 + $confirmation_url = add_query_arg( 'pmpro_level', sanitize_text_field( $_REQUEST['pmpro_level'] ), pmpro_url( 'confirmation' ) );
9 + } else {
10 + $confirmation_url = pmpro_url( 'confirmation' );
11 + }
12 + wp_redirect( add_query_arg( 'redirect_to', urlencode( $confirmation_url ), pmpro_login_url() ) );
13 + exit;
14 + }
15 +
16 + // If there was a level passed, grab it.
17 + $confirmation_level = ! empty( $_REQUEST['pmpro_level'] ) ? intval( $_REQUEST['pmpro_level'] ) : null;
18 + $confirmation_level = empty( $confirmation_level ) && ! empty( $_REQUEST['level'] ) ? intval( $_REQUEST['level'] ) : $confirmation_level; // Backwards compatibility.
19 +
20 + // Get the corresponding invoice.
21 + $pmpro_invoice = new MemberOrder();
22 + if ( ! empty( $confirmation_level ) ) {
23 + $pmpro_invoice->getLastMemberOrder( $current_user->ID, apply_filters( 'pmpro_confirmation_order_status', array( 'success', 'pending', 'token' ) ), $confirmation_level );
24 + } else {
25 + // If there wasn't a confirmation level passed, get the last invoice for the current user and use that level.
26 + $pmpro_invoice->getLastMemberOrder( $current_user->ID, apply_filters( 'pmpro_confirmation_order_status', array( 'success', 'pending', 'token' ) ) );
27 + $confirmation_level = $pmpro_invoice->membership_id;
28 + }
29 +
30 + // If no invoice was found or we still don't have a level, redirect to the account page.
31 + if ( empty( $pmpro_invoice ) || empty( $confirmation_level ) ) {
32 + $redirect_url = pmpro_url( 'account' );
33 + wp_redirect( $redirect_url );
34 + exit;
35 + }
36 +
37 + // Get the full level object.
38 + $user_level = pmpro_getSpecificMembershipLevelForUser( $current_user->ID, $confirmation_level );
39 + $current_user->membership_level = $user_level; // Backwards compatibility.
40 +
41 + // If the user doesn't have the level they are confirming (including pending checkouts), redirect them to the account page.
42 + if ( ! in_array( $pmpro_invoice->status, array( 'pending', 'token' ) ) && empty( $user_level ) ) {
43 + $redirect_url = pmpro_url( 'account' );
44 + wp_redirect( $redirect_url );
45 + exit;
46 + }
47 +
48 + // Enqueue PMPro Confirmation script.
49 + wp_register_script(
50 + 'pmpro_confirmation',
51 + plugins_url( 'js/pmpro-confirmation.js', PMPRO_BASE_FILE ),
52 + array( 'jquery' ),
53 + PMPRO_VERSION
54 + );
55 + wp_localize_script(
56 + 'pmpro_confirmation',
57 + 'pmpro',
58 + array(
59 + 'restUrl' => get_rest_url(),
60 + 'nonce' => wp_create_nonce( 'wp_rest' ),
61 + 'code' => $pmpro_invoice->code,
62 + )
63 + );
64 + wp_enqueue_script( 'pmpro_confirmation' );
65 +