|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace YIKES\EasyForms\Form; |
|
4
|
|
|
|
|
5
|
|
|
trait FormHelper { |
|
6
|
|
|
public function form_title( $title, $custom_title, $form_name ) { |
|
7
|
|
|
if ( $title ) { |
|
8
|
|
|
if ( ! empty( $custom_title ) ) { |
|
9
|
|
|
/** |
|
10
|
|
|
* Filter the title that is displayed through the shortcode. |
|
11
|
|
|
* |
|
12
|
|
|
* @param string $title The title to display. |
|
13
|
|
|
* @param int $form_id The form ID. |
|
14
|
|
|
*/ |
|
15
|
|
|
return apply_filters( 'yikes-mailchimp-form-title', apply_filters( 'the_title', $custom_title ), $this->form_id ); |
|
|
|
|
|
|
16
|
|
|
} else { |
|
17
|
|
|
return apply_filters( 'yikes-mailchimp-form-title', apply_filters( 'the_title', $form_name ), $this->form_id ); |
|
18
|
|
|
} |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
return false; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function form_description( $description, $custom_description ) { |
|
25
|
|
|
if ( $description ) { |
|
26
|
|
|
if ( ! empty( $custom_description ) ) { |
|
27
|
|
|
/** |
|
28
|
|
|
* Filter the description that is displayed through the shortcode. |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $title The title to display. |
|
31
|
|
|
* @param int $form_id The form ID. |
|
32
|
|
|
*/ |
|
33
|
|
|
return apply_filters( 'yikes-mailchimp-form-description', $custom_description, $this->form_id ); |
|
34
|
|
|
} else { |
|
35
|
|
|
return apply_filters( 'yikes-mailchimp-form-description', $this->form_data['form_description'], $this->form_id ); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
} else { |
|
38
|
|
|
return false; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function reduce_field_count() { |
|
43
|
|
|
$this->field_count = $this->field_count --; |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function set_field_count() { |
|
47
|
|
|
return isset( $this->form_data['fields'] ) ? count( $this->form_data['fields'] ) : 0; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function form_classes( bool $is_submitted ) { |
|
51
|
|
|
$form_classes = $this->form_data['form_settings']['yikes-easy-mc-form-class-names']; |
|
52
|
|
|
$form_classes .= ' yikes-easy-mc-form yikes-easy-mc-form-' . $this->form_id; |
|
53
|
|
|
|
|
54
|
|
|
if ( isset( $this->form_inline ) && $this->form_inline != 0 ) { |
|
|
|
|
|
|
55
|
|
|
$form_classes .= ' yikes-mailchimp-form-inline '; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$form_classes .= ' '; |
|
59
|
|
|
|
|
60
|
|
|
$form_classes = apply_filters( 'yikes-mailchimp-form-class', $form_classes, $this->form_id ); |
|
61
|
|
|
|
|
62
|
|
|
if ( $is_submitted && $this->form_data['submission_settings']['hide_form_post_signup'] == 1 ) { |
|
63
|
|
|
$form_classes .= ' yikes-easy-mc-display-none'; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $form_classes; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function inline_form_override() { |
|
70
|
|
|
return isset( $this->has_recaptcha ) || ( function_exists( 'is_plugin_active' ) && is_plugin_active( 'eu-opt-in-compliance-for-mailchimp/yikes-inc-easy-mailchimp-eu-law-compliance-extension.php' ) ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function edit_form_link() { |
|
74
|
|
|
if( current_user_can( apply_filters( 'yikes-mailchimp-user-role-access' , 'manage_options' ) ) ) { |
|
75
|
|
|
$edit_form_link = '<span class="edit-link">'; |
|
76
|
|
|
$edit_form_link .= '<a class="post-edit-link" href="' . esc_url( admin_url( 'admin.php?page=yikes-mailchimp-edit-form&id=' . $this->form_id ) ) . '" title="' . __( 'Edit' , 'yikes-inc-easy-mailchimp-extender' ) . ' ' . ucwords( $this->form_data['form_name'] ) . '">' . __( 'Edit Form' , 'yikes-inc-easy-mailchimp-extender' ) . '</a>'; |
|
77
|
|
|
$edit_form_link .= '</span>'; |
|
78
|
|
|
$edit_form_link = apply_filters( 'yikes-mailchimp-front-end-form-action-links', $edit_form_link, $this->form_id, ucwords( $this->form_data['form_name'] ) ); |
|
79
|
|
|
} else { |
|
80
|
|
|
$edit_form_link = ''; |
|
81
|
|
|
} |
|
82
|
|
|
return $edit_form_link; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: