-
Notifications
You must be signed in to change notification settings - Fork 1
/
the-insertr.php
48 lines (39 loc) · 1.08 KB
/
the-insertr.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
<?php
/**
* Plugin Name: The Insertr
* Plugin URI: https://github.com/herdl/the-insertr
* Description: Wordpress dynamic keyword insertion plugin.
* Author: Herdl
* Version: 1.4.0
* Author URI: https://herdl.com
*/
if (!defined('WPINC')) {
die('No direct access allowed');
}
function insertr_function(array $attributes): string {
$attributes = shortcode_atts([
'key' => '',
'fallback' => '',
'case' => '',
], $attributes, 'insertr');
$key = $attributes['key'];
$adword = '';
$case = 'lower';
if (isset($_GET[$key])) {
$adword = urldecode(wp_strip_all_tags($_GET[$key]));
} else if ($attributes['fallback']) {
$adword = $attributes['fallback'];
}
if ($attributes['case']) {
$case = $attributes['case'];
}
if ($case === 'lower') {
$adword = strtolower($adword);
} else if ($case === 'upper') {
$adword = strtoupper($adword);
} else if ($case === 'title') {
$adword = ucwords($adword);
}
return esc_html($adword);
}
add_shortcode('insertr', 'insertr_function');