-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin.php
295 lines (259 loc) · 8.84 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?php
/**
* An extension for Connections Business Directory which adds clink to SMS and Call link shortcodes.
*
* @package Connections Business Directory Extension - Click To Call And SMS
* @category Extension
* @author Steven A. Zahm
* @license GPL-2.0+
* @link https://connections-pro.com
* @copyright Copyright (c) 2024 Steven A. Zahm
*
* @wordpress-plugin
* Plugin Name: Connections Business Directory Extension - Click To Call And SMS
* Plugin URI: https://connections-pro.com/
* Description: An extension for Connections Business Directory which adds clink to SMS and Call link shortcodes.
* Version: 1.0
* Requires at least: 6.0
* Requires PHP: 7.4
* Author: Steven A. Zahm
* Author URI: https://connections-pro.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: connections_call_sms
* Domain Path: /languages
*/
namespace Connections_Directory\Extension\Click_To_Call_And_SMS;
include __DIR__ . '/includes/Singleton.php';
final class Plugin {
use Singleton;
const VERSION = '1.0';
/**
* @var string The absolute path this file.
*
* @since 1.0
*/
private static $file = '';
/**
* @var string The URL to the plugin's folder.
*
* @since 1.
*/
private static $url = '';
/**
* @var string The absolute path to this plugin's folder.
*
* @since 1.0
*/
private static $path = '';
/**
* @var string The basename of the plugin.
*
* @since 1.0
*/
private static $basename = '';
protected function initialize() {
self::$file = __FILE__;
self::$url = plugin_dir_url( self::$file );
self::$path = plugin_dir_path( self::$file );
self::$basename = plugin_basename( self::$file );
/**
* This should run on the `plugins_loaded` action hook. Since the extension loads on the
* `plugins_loaded` action hook, load immediately.
*/
\cnText_Domain::register(
'connections_call_sms',
self::$basename,
'load'
);
$this->includes();
$this->hooks();
Content_Blocks\SMS::add();
Content_Blocks\Tel::add();
}
/**
* Include the dependencies.
*
* @since 1.0
*/
private function includes() {
require_once __DIR__ . '/includes/Content_Blocks/SMS.php';
require_once __DIR__ . '/includes/Content_Blocks/Tel.php';
require_once __DIR__ . '/includes/Shortcode/SMS.php';
require_once __DIR__ . '/includes/Shortcode/Tel.php';
}
/**
* Register the hooks.
*
* @since 1.0
*/
private function hooks() {
add_action( 'init', array( \Connections_Directory\Extension\Click_To_Call_And_SMS\Shortcode\SMS::class, 'add' ) );
add_action( 'init', array( \Connections_Directory\Extension\Click_To_Call_And_SMS\Shortcode\Tel::class, 'add' ) );
add_action( 'cn_metabox', array( __CLASS__, 'registerClickToCallMetabox' ) );
add_action( 'cn_metabox', array( __CLASS__, 'registerClickToSMSMetabox' ) );
// add_filter( 'cn_content_blocks', array( __CLASS__, 'settingsOption' ) );
}
/**
* Register the 'Click to Call' metabox.
*
* @internal
* @since 1.0
*/
public static function registerClickToCallMetabox() {
$atts = array(
'title' => 'Click to Call',
// Change this to a name which applies to your project.
'id' => 'click_to_call',
// Change this so it is unique to you project.
'context' => 'normal',
'priority' => 'core',
'fields' => array(
array(
'name' => 'Phone Number',
// Change this field name to something which applies to you project.
'show_label' => true,
// Whether to display the 'name'. Changing it to false will suppress the name.
'id' => '_click_to_call_phone_number',
// Change this so it is unique to you project. Each field id MUST be unique.
'type' => 'text',
// This is the field type being added.
'size' => 'regular',
// This can be changed to one of the following: 'small', 'regular', 'large'
'desc' => 'Enter the phone number for the click to call link.',
// Placement will depend on the field type.
// 'before' => 'Text that will be displayed before the field.',
// 'after' => 'Text that will be displayed after the field.',
),
array(
'name' => 'Link Text',
// Change this field name to something which applies to you project.
'show_label' => true,
// Whether to display the 'name'. Changing it to false will suppress the name.
'id' => '_click_to_call_text',
// Change this so it is unique to you project. Each field id MUST be unique.
'type' => 'text',
// This is the field type being added.
'size' => 'regular',
// This can be changed to one of the following: 'small', 'regular', 'large'
'desc' => 'Enter the link text.',
// Placement will depend on the field type.
// 'before' => 'Text that will be displayed before the field.',
// 'after' => 'Text that will be displayed after the field.',
),
),
);
\cnMetaboxAPI::add( $atts );
}
/**
* Register the 'Click to SMS' metabox.
*
* @internal
* @since 1.0
*/
public static function registerClickToSMSMetabox() {
$atts = array(
'title' => 'Click to SMS',
// Change this to a name which applies to your project.
'id' => 'click_to_sms',
// Change this so it is unique to you project.
'context' => 'normal',
'priority' => 'core',
'fields' => array(
array(
'name' => 'Phone Number',
// Change this field name to something which applies to you project.
'show_label' => true,
// Whether to display the 'name'. Changing it to false will suppress the name.
'id' => '_click_to_sms_phone_number',
// Change this so it is unique to you project. Each field id MUST be unique.
'type' => 'text',
// This is the field type being added.
'size' => 'regular',
// This can be changed to one of the following: 'small', 'regular', 'large'
'desc' => 'Enter the phone number for the click to SMS link.',
// Placement will depend on the field type.
// 'before' => 'Text that will be displayed before the field.',
// 'after' => 'Text that will be displayed after the field.',
),
array(
'name' => 'SMS Message Text',
// Change this field name to something which applies to you project.
'show_label' => true,
// Whether to display the 'name'. Changing it to false will suppress the name.
'id' => '_click_to_sms_message',
// Change this so it is unique to you project. Each field id MUST be unique.
'type' => 'text',
// This is the field type being added.
'size' => 'regular',
// This can be changed to one of the following: 'small', 'regular', 'large'
'desc' => 'Enter the SMS message text.',
// Placement will depend on the field type.
// 'before' => 'Text that will be displayed before the field.',
// 'after' => 'Text that will be displayed after the field.',
),
array(
'name' => 'Link Text',
// Change this field name to something which applies to you project.
'show_label' => true,
// Whether to display the 'name'. Changing it to false will suppress the name.
'id' => '_click_to_sms_text',
// Change this so it is unique to you project. Each field id MUST be unique.
'type' => 'text',
// This is the field type being added.
'size' => 'regular',
// This can be changed to one of the following: 'small', 'regular', 'large'
'desc' => 'Enter the link text.',
// Placement will depend on the field type.
// 'before' => 'Text that will be displayed before the field.',
// 'after' => 'Text that will be displayed after the field.',
),
),
);
\cnMetaboxAPI::add( $atts );
}
/**
* Generate the SMS link.
*
* @since 1.0
*
* @param string $number
* @param string $message
* @param string $text
*
* @return string
*/
public function generateSMSLink( string $number, string $message, string $text = '' ): string {
if ( 0 === strlen( $text ) ) {
$text = $number;
}
// URL encode the message.
$encodedMessage = urlencode( $message );
// Generate the sms link.
$url = "sms:{$number}?body={$encodedMessage}";
return '<a href="' . esc_url( $url ) . '">' . esc_html( $text ) . '</a>';
}
/**
* Generate the tel link.
*
* @since 1.0
*
* @param string $number
* @param string $text
*
* @return string
*/
public function generateTelLink( string $number, string $text = '' ): string {
if ( 0 === strlen( $text ) ) {
$text = $number;
}
return '<a href="' . esc_url( "tel:{$number}" ) . '">' . esc_html( $text ) . '</a>';
}
}
add_action(
'Connections_Directory/Loaded',
array(
'Connections_Directory\Extension\Click_To_Call_And_SMS\Plugin',
'getInstance',
)
);