| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Elementor Phone Number Block |
| 5 |
* |
| 6 |
* @package Copy the Code |
| 7 |
* @since 3.1.0 |
| 8 |
*/ |
| 9 |
namespace CopyTheCode\Elementor\Block; |
| 10 |
|
| 11 |
use CopyTheCode\Helpers; |
| 12 |
use Elementor\Widget_Base; |
| 13 |
use Elementor\Controls_Manager; |
| 14 |
/** |
| 15 |
* Phone Number Block |
| 16 |
* |
| 17 |
* @since 3.1.0 |
| 18 |
*/ |
| 19 |
class PhoneNumber extends Widget_Base { |
| 20 |
/** |
| 21 |
* Constructor |
| 22 |
*/ |
| 23 |
public function __construct( $data = [], $args = null ) { |
| 24 |
parent::__construct( $data, $args ); |
| 25 |
// Core. |
| 26 |
wp_enqueue_style( |
| 27 |
'ctc-blocks', |
| 28 |
COPY_THE_CODE_URI . 'classes/blocks/assets/css/style.css', |
| 29 |
[], |
| 30 |
COPY_THE_CODE_VER, |
| 31 |
'all' |
| 32 |
); |
| 33 |
wp_enqueue_script( |
| 34 |
'ctc-clipboard', |
| 35 |
COPY_THE_CODE_URI . 'assets/js/clipboard.js', |
| 36 |
['jquery'], |
| 37 |
COPY_THE_CODE_VER, |
| 38 |
true |
| 39 |
); |
| 40 |
// Block. |
| 41 |
wp_enqueue_style( |
| 42 |
'ctc-el-phone-number', |
| 43 |
COPY_THE_CODE_URI . 'classes/elementor/widgets/phone-number/style.css', |
| 44 |
['ctc-blocks'], |
| 45 |
COPY_THE_CODE_VER, |
| 46 |
'all' |
| 47 |
); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Get script dependencies |
| 52 |
*/ |
| 53 |
public function get_script_depends() { |
| 54 |
return ['ctc-el-phone-number']; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Get style dependencies |
| 59 |
*/ |
| 60 |
public function get_style_depends() { |
| 61 |
return ['ctc-el-phone-number']; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Get name |
| 66 |
*/ |
| 67 |
public function get_name() { |
| 68 |
return 'ctc_phone_number'; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Get title |
| 73 |
*/ |
| 74 |
public function get_title() { |
| 75 |
return esc_html__( 'Phone Number', 'copy-the-code' ); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Get icon |
| 80 |
*/ |
| 81 |
public function get_icon() { |
| 82 |
return 'eicon-number-field'; |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Get categories |
| 87 |
*/ |
| 88 |
public function get_categories() { |
| 89 |
return Helpers::get_categories(); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Get keywords |
| 94 |
*/ |
| 95 |
public function get_keywords() { |
| 96 |
return Helpers::get_keywords( [ |
| 97 |
'phone', |
| 98 |
'copy', |
| 99 |
'content', |
| 100 |
'number' |
| 101 |
] ); |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Render |
| 106 |
*/ |
| 107 |
public function render() { |
| 108 |
$phone_number = $this->get_settings( 'phone_number' ); |
| 109 |
if ( empty( $phone_number ) ) { |
| 110 |
return; |
| 111 |
} |
| 112 |
?> |
| 113 |
<span class="ctc-block ctc-phone-number"> |
| 114 |
<a href="tel:<?php |
| 115 |
echo esc_attr( $phone_number ); |
| 116 |
?>" class="ctc-block-content"> |
| 117 |
<?php |
| 118 |
echo esc_html( $phone_number ); |
| 119 |
?> |
| 120 |
</a> |
| 121 |
<span class="ctc-block-copy ctc-block-copy-icon" role="button" aria-label="Copied"> |
| 122 |
<?php |
| 123 |
echo Helpers::get_svg_copy_icon(); |
| 124 |
?> |
| 125 |
<?php |
| 126 |
echo Helpers::get_svg_checked_icon(); |
| 127 |
?> |
| 128 |
</span> |
| 129 |
<?php |
| 130 |
Helpers::render_copy_content( $this, [ |
| 131 |
'content' => $phone_number, |
| 132 |
] ); |
| 133 |
?> |
| 134 |
</span> |
| 135 |
<?php |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Register controls |
| 140 |
*/ |
| 141 |
protected function _register_controls() { |
| 142 |
$this->start_controls_section( 'phone_number_section', [ |
| 143 |
'label' => esc_html__( 'Phone Number', 'copy-the-code' ), |
| 144 |
] ); |
| 145 |
$this->add_control( 'phone_number', [ |
| 146 |
'label' => esc_html__( 'Phone Number', 'copy-the-code' ), |
| 147 |
'type' => Controls_Manager::TEXT, |
| 148 |
'default' => '+1234567890', |
| 149 |
'dynamic' => [ |
| 150 |
'active' => true, |
| 151 |
], |
| 152 |
] ); |
| 153 |
$this->end_controls_section(); |
| 154 |
Helpers::register_pro_sections( $this, ['Phone Number', 'Icon'] ); |
| 155 |
} |
| 156 |
|
| 157 |
} |
| 158 |
|