| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\FormBuilder\Routes; |
| 4 |
|
| 5 |
use Give\FormBuilder\FormBuilderRouteBuilder; |
| 6 |
use Give\Helpers\Form\Utils; |
| 7 |
|
| 8 |
/** |
| 9 |
* Route to edit an existing form |
| 10 |
*/ |
| 11 |
class EditFormRoute |
| 12 |
{ |
| 13 |
/** |
| 14 |
* @since 3.22.0 Add locale support |
| 15 |
* @since 3.0.3 Use isV3Form() method instead of 'post_content' to check if the form is built with Visual Builder |
| 16 |
* @since 3.0.0 |
| 17 |
* |
| 18 |
* @return void |
| 19 |
*/ |
| 20 |
public function __invoke() |
| 21 |
{ |
| 22 |
if (isset($_GET['post'], $_GET['action']) && 'edit' === $_GET['action']) { |
| 23 |
$locale = $_GET['locale'] ?? ''; |
| 24 |
// This conditional will be also triggered by WP edit bulk action |
| 25 |
// WP sends an array of IDs so if that is the case here, we can skip this |
| 26 |
if ( ! is_array($_GET['post'])) { |
| 27 |
$post = get_post(abs($_GET['post'])); |
| 28 |
if ('give_forms' === $post->post_type && Utils::isV3Form($post->ID)) { |
| 29 |
wp_redirect(FormBuilderRouteBuilder::makeEditFormRoute($post->ID, $locale)->getUrl()); |
| 30 |
exit(); |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
|