| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\DonationForms\Actions; |
| 4 |
|
| 5 |
/** |
| 6 |
* The URL of a donation form's own page: the give_forms single, addressed by |
| 7 |
* post type and id so it resolves under every permalink setting. WordPress |
| 8 |
* redirects it to the pretty permalink. |
| 9 |
* |
| 10 |
* Used by the block's new-tab launcher and shipped to the external embed |
| 11 |
* script, which appends the form id itself. |
| 12 |
* |
| 13 |
* @since 4.17.0 |
| 14 |
*/ |
| 15 |
class GenerateDonationFormPageUrl |
| 16 |
{ |
| 17 |
/** |
| 18 |
* @since 4.17.0 |
| 19 |
* |
| 20 |
* @param int|null $formId Omit for the base URL without a form id. |
| 21 |
*/ |
| 22 |
public function __invoke(?int $formId = null): string |
| 23 |
{ |
| 24 |
$args = ['post_type' => 'give_forms']; |
| 25 |
|
| 26 |
if ($formId !== null) { |
| 27 |
$args['p'] = $formId; |
| 28 |
} |
| 29 |
|
| 30 |
return esc_url_raw(add_query_arg($args, home_url('/'))); |
| 31 |
} |
| 32 |
} |
| 33 |
|