-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy-shortcode-plugin.php
84 lines (71 loc) · 1.94 KB
/
my-shortcode-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
<?php
/**
* Plugin Name: My Shortcode Plugin
* Description: To display a custom message do: [my_shortcode_plugin name="name here"] or maybe it's [shortcode]description[shortcode]
* Version: 1.1.0
* Author: REInVent
*/
//register our shortcode
add_shortcode('shortcode', 'my_shortcode');
//register uninstall.php
register_uninstall_hook(plugin_dir_url(__FILE__).'uninstall.php', 'uninstall_my_shortcode_plugin');
function my_shortcode_init() {
function my_shortcode( $atts = array(), $content = null, $tag ) {
//array of allowed html for tags wp_kses
$allow = array(
'br' => array(),
'em' => array(),
'strong' => array(),
);
//check if name or url set otherwise assign them a default value
$atts_array = shortcode_atts( array(
'name' => 'World',
'url' => '#'
), $atts );
//create a custom string to greet the user - don't trust the user - EXCELLENT!
$text = "
<style>
.card {
max-width: 400px;
margin: 20px;
text-align: left;
}
.card-border {
border-style: double;
max-width: 450px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}
.image {
float: right;
width: 150px;
}
</style>
<div class='wrap'>
<div class='card-border'>
<div class='card'>
<h2>" . esc_attr($atts_array['name']) . "</h2>
<img src='" . esc_url($atts_array['url']) . "' class='image' alt='profile picture' />
<p>" . esc_attr($content) . "</p>
</div>
</div>
</div>
<br />
";
//return our custom string
return $text;
}
}
function shortcode_options_page() {
add_menu_page(
'Shortcode',
'Shortcode',
'manage_options',
plugin_dir_path(__FILE__) . 'admin/view.php',
null,
plugin_dir_url(__FILE__) . 'css/icon.png',
20
);
}
add_action( 'admin_menu', 'shortcode_options_page' );
add_action('init', 'my_shortcode_init');
?>