Shortcode.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Helpers\Frontend; |
| 4 | |
| 5 | class Shortcode |
| 6 | { |
| 7 | /** |
| 8 | * Get give_receipt shortcode with attributes from confirmation page. |
| 9 | * |
| 10 | * @since 2.7.0 |
| 11 | * @return string |
| 12 | */ |
| 13 | public static function getReceiptShortcodeFromConfirmationPage() |
| 14 | { |
| 15 | $post = get_post(give_get_option('success_page', 0)); |
| 16 | $content = $post->post_content; |
| 17 | |
| 18 | if ( ! empty($content)) { |
| 19 | preg_match('/\[give_receipt(.*?)]/i', $content, $matches); |
| 20 | |
| 21 | if (isset($matches[0])) { |
| 22 | return $matches[0]; |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | return ''; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @since 3.4.0 |
| 31 | */ |
| 32 | public static function isValidDonation(int $donationId): bool |
| 33 | { |
| 34 | return ! empty($donationId) && 'give_payment' === get_post_type($donationId); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @since 3.4.0 |
| 39 | */ |
| 40 | public static function isValidForm(int $formId): bool |
| 41 | { |
| 42 | return ! empty($formId) && 'give_forms' === get_post_type($formId); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @since 3.4.0 |
| 47 | */ |
| 48 | public static function isPublishedForm(int $formId): bool |
| 49 | { |
| 50 | return self::isValidForm($formId) && 'publish' === get_post_status($formId); |
| 51 | } |
| 52 | } |
| 53 |