| 1 |
<?php |
| 2 |
/** |
| 3 |
* Form preview: Output |
| 4 |
* |
| 5 |
* @package SimplePay |
| 6 |
* @subpackage Core |
| 7 |
* @copyright Copyright (c) 2022, Sandhills Development, LLC |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 4.4.2 |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace SimplePay\Core\FormPreview; |
| 13 |
|
| 14 |
use SimplePay\Core\EventManagement\SubscriberInterface; |
| 15 |
|
| 16 |
/** |
| 17 |
* FormPreviewOutput class. |
| 18 |
* |
| 19 |
* @since 4.4.2 |
| 20 |
*/ |
| 21 |
class FormPreviewOutput implements SubscriberInterface { |
| 22 |
|
| 23 |
/** |
| 24 |
* {@inheritdoc} |
| 25 |
*/ |
| 26 |
public function get_subscribed_events() { |
| 27 |
return array( |
| 28 |
'init' => 'maybe_output_preview', |
| 29 |
); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Outputs a payment form preview if the requested URL is correct. |
| 34 |
* |
| 35 |
* @since 4.4.2 |
| 36 |
* |
| 37 |
* @return void |
| 38 |
*/ |
| 39 |
public function maybe_output_preview() { |
| 40 |
if ( ! isset( $_GET['simpay-preview'] ) ) { |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 45 |
wp_die( |
| 46 |
esc_html__( |
| 47 |
'You do not have permission to preview this payment form.', |
| 48 |
'stripe' |
| 49 |
) |
| 50 |
); |
| 51 |
} |
| 52 |
|
| 53 |
$id = absint( $_GET['simpay-preview'] ); |
| 54 |
$form = simpay_get_form( $id ); |
| 55 |
|
| 56 |
if ( false === $form ) { |
| 57 |
wp_safe_redirect( |
| 58 |
add_query_arg( |
| 59 |
array( |
| 60 |
'post_type' => 'simple-pay', |
| 61 |
), |
| 62 |
admin_url( 'edit.php' ) |
| 63 |
) |
| 64 |
); |
| 65 |
exit; |
| 66 |
} |
| 67 |
|
| 68 |
$edit_form_url = add_query_arg( |
| 69 |
array( |
| 70 |
'post' => $id, |
| 71 |
'action' => 'edit', |
| 72 |
), |
| 73 |
admin_url( 'post.php' ) |
| 74 |
); |
| 75 |
|
| 76 |
$payment_page_enabled = get_post_meta( $id, '_enable_payment_page', true ); |
| 77 |
$payment_page_url = 'yes' === $payment_page_enabled |
| 78 |
? get_permalink( $id ) |
| 79 |
: ''; |
| 80 |
|
| 81 |
wp_enqueue_script( 'clipboard' ); |
| 82 |
wp_enqueue_script( 'wp-a11y' ); |
| 83 |
wp_enqueue_style( 'dashicons' ); |
| 84 |
|
| 85 |
wp_head(); |
| 86 |
?> |
| 87 |
|
| 88 |
<?php |
| 89 |
include_once SIMPLE_PAY_DIR . '/views/admin-form-preview-output.php'; // @phpstan-ignore-line |
| 90 |
exit; |
| 91 |
} |
| 92 |
|
| 93 |
} |
| 94 |
|