| 1 |
<?php |
| 2 |
/** |
| 3 |
* SureDonation Donate Button Markup Class file. |
| 4 |
* |
| 5 |
* @package SureDonation |
| 6 |
* @since 0.0.1 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace SureDonation\Inc\Fields; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; // Exit if accessed directly. |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* SureDonation Donate Button Markup Class. |
| 17 |
* |
| 18 |
* @since 0.0.1 |
| 19 |
*/ |
| 20 |
class Donate_Button_Markup extends Base { |
| 21 |
/** |
| 22 |
* Text displayed on the button. |
| 23 |
* |
| 24 |
* @var string |
| 25 |
* @since 0.0.1 |
| 26 |
*/ |
| 27 |
protected $button_text; |
| 28 |
|
| 29 |
/** |
| 30 |
* Initialize the properties based on block attributes. |
| 31 |
* |
| 32 |
* @param array<mixed> $attributes Block attributes. |
| 33 |
* @since 0.0.1 |
| 34 |
*/ |
| 35 |
public function __construct( $attributes ) { |
| 36 |
$this->slug = 'donate-button'; |
| 37 |
$this->button_text = $attributes['buttonText'] ?? __( 'Donate Now', 'suredonation' ); |
| 38 |
|
| 39 |
$this->set_properties( $attributes ); |
| 40 |
$this->set_unique_slug(); |
| 41 |
$this->set_markup_properties(); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Render donate button markup |
| 46 |
* |
| 47 |
* @since 0.0.1 |
| 48 |
* @return string |
| 49 |
*/ |
| 50 |
public function markup() { |
| 51 |
$classes = $this->get_field_classes(); |
| 52 |
|
| 53 |
ob_start(); |
| 54 |
?> |
| 55 |
<div data-block-id="<?php echo esc_attr( $this->block_id ); ?>" class="<?php echo esc_attr( $classes ); ?>"> |
| 56 |
<button |
| 57 |
type="submit" |
| 58 |
id="sd-submit-btn" |
| 59 |
class="sd-submit-button" |
| 60 |
> |
| 61 |
<div class="sd-submit-wrap"> |
| 62 |
<span class="sd-button-text"><?php echo esc_html( $this->button_text ); ?></span> |
| 63 |
<span class="sd-button-spinner" style="display: none;"> |
| 64 |
<svg class="sd-spinner" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 65 |
<circle class="sd-spinner-track" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle> |
| 66 |
<path class="sd-spinner-head" d="M12 2a10 10 0 0 1 10 10" stroke="currentColor" stroke-width="4" stroke-linecap="round"></path> |
| 67 |
</svg> |
| 68 |
</span> |
| 69 |
</div> |
| 70 |
</button> |
| 71 |
</div> |
| 72 |
<?php |
| 73 |
$output = ob_get_clean(); |
| 74 |
return false !== $output ? $output : ''; |
| 75 |
} |
| 76 |
} |
| 77 |
|