| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class to add campaign title field to a campaign form in the builder. |
| 4 |
* |
| 5 |
* @package Charitable |
| 6 |
* @author David Bisset |
| 7 |
* @copyright Copyright (c) 2023, WP Charitable LLC |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 1.8.0 |
| 10 |
* @version 1.8.9.1 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
if ( ! class_exists( 'Charitable_Field_Campaign_Title' ) ) : |
| 18 |
|
| 19 |
/** |
| 20 |
* Class to add campaign title field to a campaign form in the builder. |
| 21 |
* |
| 22 |
* @version 1.8.9.1 |
| 23 |
*/ |
| 24 |
class Charitable_Field_Campaign_Title extends Charitable_Builder_Field { |
| 25 |
|
| 26 |
/** |
| 27 |
* Primary class constructor. |
| 28 |
* |
| 29 |
* @since 1.8.0 |
| 30 |
*/ |
| 31 |
public function init() { |
| 32 |
|
| 33 |
// Basic information. |
| 34 |
$this->name = esc_html__( 'Campaign Title', 'charitable' ); |
| 35 |
$this->type = 'campaign-title'; |
| 36 |
$this->icon = 'fa-text-width'; |
| 37 |
$this->order = 10; |
| 38 |
|
| 39 |
// Edit/Duplication information. |
| 40 |
$this->can_be_edited = true; |
| 41 |
$this->can_be_deleted = true; |
| 42 |
$this->can_be_duplicated = true; |
| 43 |
$this->edit_label = esc_html__( 'Edit Campaign Title', 'charitable' ); |
| 44 |
$this->edit_type = 'campaign-title'; |
| 45 |
$this->edit_section = 'standard'; |
| 46 |
|
| 47 |
// Misc. |
| 48 |
$this->tooltip = esc_html__( 'Placeholder tool tip', 'charitable' ); |
| 49 |
$this->preview_character_limit = 150; |
| 50 |
|
| 51 |
// Define additional field properties. |
| 52 |
add_action( 'charitable_frontend_js', [ $this, 'frontend_js' ] ); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Campaign Title options panel inside the builder. |
| 57 |
* |
| 58 |
* @since 1.8.0 |
| 59 |
* |
| 60 |
* @param array $field Campaign Title settings. |
| 61 |
*/ |
| 62 |
public function field_options( $field ) { |
| 63 |
/* |
| 64 |
* Basic field options. |
| 65 |
*/ |
| 66 |
|
| 67 |
// Options open markup. |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Render the field. |
| 72 |
* |
| 73 |
* @since 1.8.0 |
| 74 |
* |
| 75 |
* @param array $field_data Any field data. |
| 76 |
* @param array $campaign_data Amount data and settings. |
| 77 |
* @param integer $field_id The field ID. |
| 78 |
* @param string $mode Where the field is being displayed ("preview" or "template"). |
| 79 |
* @param array $template_data Tempalate data. |
| 80 |
*/ |
| 81 |
public function render( $field_data = false, $campaign_data = false, $field_id = false, $mode = 'template', $template_data = false ) { |
| 82 |
|
| 83 |
$campaign_title = ! empty( $campaign_data['title'] ) ? esc_html( stripslashes( $campaign_data['title'] ) ) : esc_html__( 'Campaign', 'charitable' ); |
| 84 |
|
| 85 |
$html = '<div class="charitable-field-campaign-title title-description" data-field-type="' . $this->type . '"> |
| 86 |
<div class="charitable-campaign-builder-placeholder-preview-text charitable-prevent-select">'; |
| 87 |
|
| 88 |
if ( $campaign_title ) { |
| 89 |
|
| 90 |
$html .= wpautop( |
| 91 |
'<h1 class="charitable-campaign-title">' . wp_kses( |
| 92 |
strlen( $campaign_title ) > $this->preview_character_limit ? substr( $campaign_title, 0, $this->preview_character_limit ) . '...' : $campaign_title, |
| 93 |
[ |
| 94 |
'strong' => [], |
| 95 |
'em' => [], |
| 96 |
] |
| 97 |
) . '</h1>' |
| 98 |
); |
| 99 |
|
| 100 |
} else { |
| 101 |
|
| 102 |
$html .= '<div class="row"> |
| 103 |
<div class="column"> |
| 104 |
<span class="placeholder"></span> |
| 105 |
</div> |
| 106 |
</div>'; |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
$html .= ' </div> |
| 111 |
</div>'; |
| 112 |
|
| 113 |
return $html; |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Campaign Title preview inside the builder. |
| 118 |
* |
| 119 |
* @since 1.8.0 |
| 120 |
* @version 1.8.9.1 |
| 121 |
* |
| 122 |
* @param array $field_data Field data and settings. |
| 123 |
* @param array $campaign_data Campaign data and settings. |
| 124 |
* @param array $field_id Field ID. |
| 125 |
* @param string $theme Template data. |
| 126 |
*/ |
| 127 |
public function field_preview( $field_data = false, $campaign_data = false, $field_id = false, $theme = '' ) { |
| 128 |
|
| 129 |
$html = $this->field_title( $this->name ); |
| 130 |
$html .= $this->field_wrapper( $this->render( $field_data, $campaign_data, $field_id, 'preview' ), $field_data ); |
| 131 |
|
| 132 |
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* The display on the campaign front-end. |
| 137 |
* |
| 138 |
* @since 1.8.0 |
| 139 |
* @version 1.8.9.1 |
| 140 |
* |
| 141 |
* @param string $field_type The passed field type. |
| 142 |
* @param array $field_data Any field data. |
| 143 |
* @param array $campaign_data Amount data and settings. |
| 144 |
*/ |
| 145 |
public function field_display( $field_type = '', $field_data = false, $campaign_data = false ) { |
| 146 |
|
| 147 |
$html = $this->field_display_wrapper( $this->render( $field_data, $campaign_data ), $field_data ); |
| 148 |
|
| 149 |
echo apply_filters( 'charitable_campaign_builder_' . $this->type . '_field_display', $html, $campaign_data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* The display on the form settings backend when the user clicks on the field/block. |
| 154 |
* |
| 155 |
* @since 1.8.0 |
| 156 |
* @version 1.8.9.1 |
| 157 |
* |
| 158 |
* @param array $field Campaign Title settings. |
| 159 |
* @param array $campaign_data Campaign data and settings. |
| 160 |
*/ |
| 161 |
public function settings_display( $field_id = false, $campaign_data = false ) { |
| 162 |
|
| 163 |
if ( ! class_exists( 'Charitable_Builder_Form_Fields' ) ) { |
| 164 |
return; |
| 165 |
} |
| 166 |
|
| 167 |
$charitable_builder_form_fields = new Charitable_Builder_Form_Fields(); |
| 168 |
|
| 169 |
$settings = isset( $campaign_data['fields'][ $field_id ] ) ? $campaign_data['fields'][ $field_id ] : false; |
| 170 |
|
| 171 |
add_action( 'charitable_builder_' . $this->type . '_settings_display_start', [ $this, 'settings_section_top' ], 10, 2 ); |
| 172 |
add_action( 'charitable_builder_' . $this->type . '_settings_display_end', [ $this, 'settings_section_bottom' ], 10, 2 ); |
| 173 |
|
| 174 |
ob_start(); |
| 175 |
|
| 176 |
?> |
| 177 |
|
| 178 |
<h4 class="charitable-panel-field" data-field-id="<?php echo intval( $field_id ); ?>"><?php echo esc_html( $this->name ); ?> (ID: <?php echo intval( $field_id ); ?>)</h4> |
| 179 |
|
| 180 |
<div class="charitable-panel-field charitable-panel-field-section" data-field-id="<?php echo intval( $field_id ); ?>"> |
| 181 |
|
| 182 |
<?php echo do_action( 'charitable_builder_' . $this->type . '_settings_display_start', $field_id, $campaign_data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 183 |
|
| 184 |
</div> |
| 185 |
|
| 186 |
<?php |
| 187 |
|
| 188 |
echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 189 |
isset( $settings['title'] ) ? $settings['title'] : false, |
| 190 |
esc_html__( 'Campaign Title', 'charitable' ), |
| 191 |
array( |
| 192 |
'id' => 'field_' . esc_attr( $this->type ) . '_title' . '_' . intval( $field_id ), // phpcs:ignore |
| 193 |
'name' => array( '_fields', intval( $field_id ), 'title' ), |
| 194 |
'field_id' => intval( $field_id ), |
| 195 |
'default' => ! empty( $campaign_data['title'] ) ? esc_html( $campaign_data['title'] ) : false, |
| 196 |
'class' => 'charitable-campaign-builder-title', |
| 197 |
'special' => 'campaign_title', |
| 198 |
) |
| 199 |
); |
| 200 |
|
| 201 |
echo $charitable_builder_form_fields->generate_align( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 202 |
isset( $settings['align'] ) ? $settings['align'] : esc_attr( $this->align_default ), |
| 203 |
esc_html__( 'Align', 'charitable' ), |
| 204 |
array( |
| 205 |
'id' => 'field_' . esc_attr( $this->type ) . '_align' . '_' . intval( $field_id ), // phpcs:ignore |
| 206 |
'name' => array( '_fields', intval( $field_id ), 'align' ), |
| 207 |
'field_id' => intval( $field_id ), |
| 208 |
'default' => 'left', |
| 209 |
) |
| 210 |
); |
| 211 |
|
| 212 |
/* CSS CLASS */ |
| 213 |
|
| 214 |
echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 215 |
isset( $settings['css_class'] ) ? $settings['css_class'] : false, |
| 216 |
esc_html__( 'CSS Class', 'charitable' ), |
| 217 |
array( |
| 218 |
'id' => 'field_' . esc_attr( $this->type ) . '_css_class' . '_' . intval( $field_id ), |
| 219 |
'name' => array( '_fields', intval( $field_id ), 'css_class' ), |
| 220 |
'field_id' => intval( $field_id ), |
| 221 |
'tooltip' => esc_html__( 'Add CSS classes (seperated by a space) for this field to customize it\'s appearance in your theme.', 'charitable' ), |
| 222 |
) |
| 223 |
); |
| 224 |
|
| 225 |
?> |
| 226 |
|
| 227 |
<div class="charitable-panel-field charitable-panel-field-section" data-field-id="<?php echo intval( $field_id ); ?>"> |
| 228 |
|
| 229 |
<?php do_action( 'charitable_builder_' . $this->type . '_settings_display_end', $field_id, $campaign_data ); ?> |
| 230 |
|
| 231 |
</div> |
| 232 |
|
| 233 |
<?php |
| 234 |
|
| 235 |
$html = ob_get_clean(); |
| 236 |
|
| 237 |
return $html; |
| 238 |
} |
| 239 |
|
| 240 |
/** |
| 241 |
* Display content above the content settings in the panel in the admin via hook. |
| 242 |
* |
| 243 |
* @since 1.8.0 |
| 244 |
* |
| 245 |
* @param integer $field_id Field ID. |
| 246 |
* @param array $campaign_data Data on campaign. |
| 247 |
*/ |
| 248 |
public function settings_section_top( $field_id = false, $campaign_data = false ) { |
| 249 |
} |
| 250 |
|
| 251 |
/** |
| 252 |
* Display content above the content settings in the panel in the admin via hook. |
| 253 |
* |
| 254 |
* @since 1.8.0 |
| 255 |
* |
| 256 |
* @param integer $field_id Field ID. |
| 257 |
* @param array $campaign_data Data on campaign. |
| 258 |
*/ |
| 259 |
public function settings_section_bottom( $field_id = false, $campaign_data = false ) { |
| 260 |
} |
| 261 |
|
| 262 |
/** |
| 263 |
* Enqueue frontend limit option js. |
| 264 |
* |
| 265 |
* @since 1.8.0 |
| 266 |
* |
| 267 |
* @param array $forms Forms on the current page. |
| 268 |
*/ |
| 269 |
public function frontend_js( $forms ) { |
| 270 |
} |
| 271 |
|
| 272 |
/** |
| 273 |
* Format and sanitize field. |
| 274 |
* |
| 275 |
* @since 1.8.0 |
| 276 |
* |
| 277 |
* @param int $field_id Campaign Title ID. |
| 278 |
* @param mixed $field_submit Campaign Title value that was submitted. |
| 279 |
* @param array $campaign_data Form data and settings. |
| 280 |
*/ |
| 281 |
public function format( $field_id, $field_submit, $campaign_data ) { |
| 282 |
} |
| 283 |
|
| 284 |
/** |
| 285 |
* Validate field on form submit. |
| 286 |
* |
| 287 |
* @since 1.8.0 |
| 288 |
* |
| 289 |
* @param int $field_id Campaign Title ID. |
| 290 |
* @param mixed $field_submit Campaign Title value that was submitted. |
| 291 |
* @param array $campaign_data Form data and settings. |
| 292 |
*/ |
| 293 |
public function validate( $field_id, $field_submit, $campaign_data ) { |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
new Charitable_Field_Campaign_Title(); |
| 299 |
|
| 300 |
|
| 301 |
endif; |