name = esc_html__( 'Donate Amount', 'charitable' ); $this->type = 'donate-amount'; $this->icon = 'fa fa-dollar'; $this->order = 100; $this->group = 'standard'; $this->align_default = 'center'; // Edit/Duplication information. $this->can_be_edited = true; $this->can_be_deleted = true; $this->can_be_duplicated = false; $this->edit_label = esc_html__( 'Edit Donate Amount', 'charitable' ); $this->edit_type = 'donate-amount'; $this->edit_section = 'standard'; $this->max_allowed = 1; // Misc. $this->tooltip = ''; // Define additional field properties. // add_action( 'charitable_frontend_js', [ $this, 'frontend_js' ] ); // add_action( 'charitable_builder_backend_scripts', [ $this, 'builder_js' ]); // admin_enqueue_scripts. add_filter( 'charitable_builder_field_button_attributes', [ $this, 'make_unique_button' ], 10, 4 ); } /** * Field options panel inside the builder. * * @since 1.8.0 * * @param array $field Field settings. */ public function field_options( $field ) { /* * Basic field options. */ // Options open markup. } /** * Render the field. * * @since 1.8.0 * * @param array $field_data Any field data. * @param array $campaign_data Amount data and settings. * @param integer $field_id The field ID. * @param string $mode Where the field is being displayed ("preview" or "template"). * @param array $template_data Tempalate data. */ public function render( $field_data = false, $campaign_data = false, $field_id = false, $mode = 'template', $template_data = false ) { $headline = ! empty( $field_data['headline'] ) ? esc_html( $field_data['headline'] ) : false; $campaign_id = isset( $campaign_data['id'] ) && 0 !== intval( $campaign_data['id'] ) ? intval( $campaign_data['id'] ) : false; $preview_or_template_css = ( 'preview' === $mode ) ? 'preview' : 'template'; $input_disabled_attr = ( 'preview' === $mode ) ? 'disabled="true"' : false; $donation_amount_found = false; $currency_helper = charitable_get_currency_helper(); ob_start(); if ( 'preview' === $mode ) : echo '
'; endif; if ( 'preview' === $mode || ( 'template' === $mode && false !== $headline ) ) : echo '
' . esc_html( $headline ) . '
'; endif; // if there is no campaign id, then we assume this is a new campaign and assign the default donation amounts. if ( false === $campaign_id ) { echo '
'; } else { $campaign = charitable_get_campaign( $campaign_id ); // We want the button to contain a donation amount, but we go with what is in the SESSION first, then the DEFAULT amount. $donation_amount_in_session = $campaign->get_donation_amount_in_session(); if ( ! $campaign ) : echo '

Cannot recieve donations.

'; echo '
'; $html = ob_get_clean(); echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped return; endif; $suggested_donations = $campaign->get_suggested_donations(); if ( empty( $suggested_donations ) && ! $campaign->get( 'allow_custom_donations' ) ) : echo '

No donation options available.

'; echo ' '; $html = ob_get_clean(); echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped return; endif; echo '
'; } if ( 'preview' === $mode ) : echo ' '; endif; $html = ob_get_clean(); return $html; } /** * Donate Amount preview inside the builder. * * @since 1.8.0 * * @param array $field_data Field data and settings. * @param array $campaign_data Campaign data and settings. * @param array $field_id Field ID. * @param string $theme Template data. */ public function field_preview( $field_data = false, $campaign_data = false, $field_id = false, $theme = '' ) { $html = $this->field_title( $this->name ); $html .= $this->field_wrapper( $this->render( $field_data, $campaign_data, $field_id, 'preview' ), $field_data ); echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * The display on the campaign front-end. * * @since 1.8.0 * * @param string $field_type The passed field type. * @param array $field_data Any field data. * @param array $campaign_data Amount data and settings. */ public function field_display( $field_type = '', $field_data = false, $campaign_data = false ) { $html = $this->field_display_wrapper( $this->render( $field_data, $campaign_data ), $field_data ); echo apply_filters( 'charitable_campaign_builder_' . $this->type . '_field_display', $html, $campaign_data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Donate Amount display on the form front-end. * * @since 1.8.0 * * @param integer $field_id Number ID. * @param array $campaign_data Amount data and settings. */ public function settings_display( $field_id = false, $campaign_data = false ) { if ( ! class_exists( 'Charitable_Builder_Form_Fields' ) ) { return; } $charitable_builder_form_fields = new Charitable_Builder_Form_Fields(); $settings = isset( $campaign_data['fields'][ $field_id ] ) ? $campaign_data['fields'][ $field_id ] : false; ob_start(); ?>

name ); ?> (ID: )

generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped isset( $settings['headline'] ) ? $settings['headline'] : '', esc_html__( 'Headline', 'charitable' ), array( 'id' => 'field_' . esc_attr( $this->type ) . '_headline' . '_' . intval( $field_id ), // phpcs:ignore 'name' => array( '_fields', intval( $field_id ), 'headline' ), 'field_id' => intval( $field_id ), 'tooltip' => esc_html__( 'Add a headline to this field.', 'charitable' ), 'class' => 'charitable-campaign-builder-headline', ) ); echo $charitable_builder_form_fields->generate_divider( false, false, array( 'field_id' => $field_id ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $charitable_builder_form_fields->generate_donation_amounts_mini( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $campaign_data, esc_html__( 'Suggested Donation Amounts', 'charitable' ), array( 'from' => 'field', 'id' => 'field_' . esc_attr( $this->type ) . '_donation_amounts' . '_' . intval( $field_id ), // phpcs:ignore 'name' => array( '_fields', intval( $field_id ), 'donation_amounts' ), 'field_id' => intval( $field_id ), 'default' => false, ) ); echo $charitable_builder_form_fields->generate_divider( false, false, array( 'field_id' => $field_id ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $campaign_settings = false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display/routing parameter if ( ! empty( $_GET['campaign_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display/routing parameter $campaign_id = intval( wp_unslash( $_GET['campaign_id'] ) ); if ( $campaign_id > 0 ) { $campaign_settings = get_post_meta( $campaign_id, 'campaign_settings_v2', true ); } } $default_allow_custom = false !== $campaign_settings && ! isset( $campaign_settings['settings']['donation-options']['allow_custom_donations'] ) ? false : '1'; echo $charitable_builder_form_fields->generate_toggle( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $default_allow_custom, esc_html__( 'Allow Custom Donations', 'charitable' ), array( 'id' => 'field_' . esc_attr( $this->type ) . '_allow_custom_donations' . '_' . intval( $field_id ), // phpcs:ignore 'name' => array( '_fields', intval( $field_id ), 'allow_custom_donations' ), 'container_class' => 'charitable-campaign-builder-allow-custom-donations', 'field_id' => esc_attr( $field_id ), 'checked_value' => '1', ) ); echo $charitable_builder_form_fields->generate_divider( false, false, array( 'field_id' => $field_id ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped isset( $settings['css_class'] ) ? $settings['css_class'] : false, esc_html__( 'CSS Class', 'charitable' ), array( 'id' => 'field_' . esc_attr( $this->type ) . '_css_class' . '_' . intval( $field_id ), 'name' => array( '_fields', intval( $field_id ), 'css_class' ), 'field_id' => intval( $field_id ), 'tooltip' => esc_html__( 'Add CSS classes (seperated by a space) for this field to customize it\'s appearance in your theme.', 'charitable' ), ) ); ?> generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped isset( $settings['headline'] ) ? $settings['headline'] : '', esc_html__( 'Headline', 'charitable' ), array( 'id' => 'field_' . esc_attr( $this->type ) . '_headline' . '_' . intval( $field_id ), // phpcs:ignore 'name' => array( '_fields', intval( $field_id ), 'headline' ), 'field_id' => intval( $field_id ), 'tooltip' => esc_html__( 'Add a headline to this field.', 'charitable' ), 'class' => 'charitable-campaign-builder-headline', ) ); echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $settings['css_class'], esc_html__( 'CSS Class', 'charitable' ), array( 'id' => 'field_' . esc_attr( $this->type ) . '_css_class', 'name' => array( 'fields', esc_attr( $this->type ), 'css_class' ), 'tooltip' => esc_html( $this->tooltip ), ) ); ?> $html ] ); exit; } /** * Enqueue frontend js. * * @since 1.8.0 */ public function frontend_js() { } /** * Enqueue frontend limit option js. * * @since 1.8.0 * * @param array $min Min or not. */ public function builder_js( $min ) { } /** * Amountat and sanitize field. * * @since 1.8.0 * * @param int $field_id Field type. * @param mixed $field_submit Field value that was submitted. * @param array $campaign_data Campaign data and settings. */ public function format( $field_id, $field_submit, $campaign_data ) { } /** * Validate field on form submit. * * @since 1.8.0 * * @param int $field_id Field ID. * @param mixed $field_submit Field value that was submitted. * @param array $campaign_data Campaign data and settings. */ public function validate( $field_id, $field_submit, $campaign_data ) { } /** * Return attributes that disable the field button if campaign_data shows one already exists in the template. * * @since 1.8.0 * * @param array $field_attr All the settings for this field button. * @param array $field Field data. * @param array $campaign_data Campaign data and settings. * @param array $current_fields Current fields according to saved campaign data. */ public function make_unique_button( $field_attr = false, $field = false, $campaign_data = false, $current_fields = false ) { if ( false === $field || false === $campaign_data || false === $current_fields || ! is_array( $campaign_data ) || ! is_array( $current_fields ) || empty( $field['type'] ) ) { return $field_attr; } if ( ! empty( $field['type'] ) && $field['type'] !== $this->type ) { return $field_attr; } // is this already in the template? if ( in_array( $this->type, $current_fields, true ) ) { $field_attr['class'][] = 'charitable-disabled'; } return $field_attr; } /** * Possible depreciated function. * * @since 1.8.0 * * @param string $field Field type. * @param array $field_atts Field value that was submitted. * @param array $campaign_data Campaign data and settings. */ public function section_top( $field, $field_atts, $campaign_data ) { } /** * Possible depreciated function. * * @since 1.8.0 * * @param string $field Field type. * @param array $field_atts Field value that was submitted. * @param array $campaign_data Campaign data and settings. */ public function section_bottom( $field, $field_atts, $campaign_data ) { } } new Charitable_Field_Donate_Amount(); endif;