PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / trunk
JetFormBuilder — Dynamic Blocks Form Builder vtrunk
3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / actions-v2 / redirect-to-page / redirect-to-page-action.php
jetformbuilder / modules / actions-v2 / redirect-to-page Last commit date
assets 2 months ago redirect-to-page-action.php 1 year ago redirect-to-page.php 2 years ago
redirect-to-page-action.php
124 lines
1 <?php
2
3 namespace JFB_Modules\Actions_V2\Redirect_To_Page;
4
5 // If this file is called directly, abort.
6 use Jet_Form_Builder\Actions\Action_Handler;
7 use Jet_Form_Builder\Actions\Types\Base;
8 use Jet_Form_Builder\Classes\Tools;
9 use Jet_Form_Builder\Exceptions\Action_Exception;
10 use Jet_Form_Builder\Exceptions\Repository_Exception;
11 use JFB_Modules\Actions_V2\Insert_Post\Insert_Post_Action;
12 use JFB_Modules\Rich_Content;
13
14 if ( ! defined( 'WPINC' ) ) {
15 die;
16 }
17
18 /**
19 * Define Base_Type class
20 */
21 class Redirect_To_Page_Action extends Base {
22
23 public function get_name() {
24 return __( 'Redirect to Page', 'jet-form-builder' );
25 }
26
27 public function get_id() {
28 return 'redirect_to_page';
29 }
30
31 public function get_redirect_url() {
32 $type = ! empty( $this->settings['redirect_type'] ) ? $this->settings['redirect_type'] : 'static_page';
33
34 switch ( $type ) {
35 case 'static_page':
36 $to_page = $this->settings['redirect_page'] ?? '';
37
38 return empty( $to_page ) ? false : get_permalink( $to_page );
39
40 case 'current_page':
41 return jet_fb_handler()->refer;
42
43 case 'inserted_post':
44 /** @var Insert_Post_Action $insert_instance */
45 try {
46 $insert_instance = jet_form_builder()->actions->get_action( 'insert_post' );
47 } catch ( Repository_Exception $exception ) {
48 return false;
49 }
50
51 $context = $insert_instance->get_inserted_post_context();
52
53 if ( ! $context ) {
54 return false;
55 }
56
57 return get_permalink( $context['ID'] );
58
59 default:
60 $this->settings['redirect_url'] = Tools::to_string(
61 $this->settings['redirect_url'] ?? ''
62 );
63
64 return Rich_Content\Module::rich( $this->settings['redirect_url'] );
65 }
66 }
67
68 public function get_url_with_hash( $url ) {
69 if ( empty( $this->settings['redirect_hash'] ) ) {
70 return $url;
71 }
72
73 return trailingslashit( $url ) . '#' . $this->settings['redirect_hash'];
74 }
75
76 public function get_url_with_args( $url ) {
77 $redirect_args = array();
78
79 if ( ! empty( $this->settings['redirect_args'] ) ) {
80 foreach ( $this->settings['redirect_args'] as $arg ) {
81 $value = jet_fb_context()->get_value( $arg );
82
83 $redirect_args[ $arg ] = ! empty( $value ) ? $value : 0;
84 }
85 }
86
87 $redirect_args = apply_filters( 'jet-form-builder/actions/redirect-to-page/redirect-args', $redirect_args, $this );
88
89 return add_query_arg( urlencode_deep( $redirect_args ), $url );
90 }
91
92 public function get_completed_redirect_url( $url = '' ) {
93 if ( ! $url ) {
94 $url = $this->get_redirect_url();
95 }
96 $url = $this->get_url_with_hash( $url );
97
98 return $this->get_url_with_args( $url );
99 }
100
101 /**
102 * @param array $request
103 * @param Action_Handler $handler
104 *
105 * @return mixed|void
106 * @throws Action_Exception
107 */
108 public function do_action( array $request, Action_Handler $handler ) {
109 $to_url = $this->get_redirect_url();
110
111 if ( ! $to_url ) {
112 // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
113 throw new Action_Exception( 'failed', $this->settings );
114 }
115
116 $to_url = $this->get_completed_redirect_url( $to_url );
117
118 $handler->response_data['open_in_new_tab'] = ! empty( $this->settings['open_in_new_tab'] );
119
120 $handler->response_data['redirect'] = $to_url;
121 }
122
123 }
124