-
Notifications
You must be signed in to change notification settings - Fork 1
/
rpg-dice-roller.php
108 lines (91 loc) · 2.36 KB
/
rpg-dice-roller.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
<?php
/*
Plugin Name: RPG Dice Roller
Plugin URI: http://www.martyhimmel.me/rpg-dice-roller/
Description: Dice roller designed for table top RPGs.
Version: 1.1.0
Author: Martin Himmel
Author URI: http://www.martyhimmel.me
Donate link: http://www.martyhimmel.me
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
defined('ABSPATH') or die('Plugin file cannot be accessed directly.');
if (!class_exists('MHRPGDiceRoller')) {
class MHRPGDiceRoller {
/**
* Set up the plugin.
*/
function __construct() {
add_shortcode('mh_rpg_dice_roller', array($this, 'shortcode'));
}
/**
* Set up the shortcode.
*
* @param array $atts Attributes
* @param string $content Content passed in to the shortcode
* @return string Shortcode output
*/
function shortcode($atts, $content = null) {
$this->enqueue_js();
ob_start();
require_once('form/form.html');
$html = ob_get_clean();
return $html;
}
/**
* Register scripts with WordPress.
*/
function enqueue_js() {
if (!wp_script_is('mh_rpg_dice_roller', 'enqueued')) {
wp_register_script(
'mh_rpg_dice_roller',
plugin_dir_url(__FILE__) . 'js/mh-rpg-dice-roller.js'
);
wp_enqueue_script('mh_rpg_dice_roller');
}
}
} // End class
} // End if(!class_exists)
if (!class_exists('MHRPGDiceRollerWidget')) {
class MHRPGDiceRollerWidget extends WP_Widget{
/**
* Set up the widget in the menu.
*/
function __construct() {
parent::__construct(
'mh_rpg_dice_roller',
'RPG Dice Roller',
array('description' => 'Dice roller for table top RPGs')
);
}
/**
* Register scripts with WordPress.
*/
function enqueue_js() {
if (!wp_script_is('mh_rpg_dice_roller', 'enqueued')) {
wp_register_script(
'mh_rpg_dice_roller',
plugin_dir_url(__FILE__) . 'js/mh-rpg-dice-roller.js'
);
wp_enqueue_script('mh_rpg_dice_roller');
}
}
/**
* Runs the widget code.
*/
function widget($args, $instance) {
$this->enqueue_js();
require_once('form/form-widget.html');
}
} // End class
} // End if(!class_exists)
if (class_exists('MHRPGDiceRoller')) {
new MHRPGDiceRoller();
}
if (class_exists('MHRPGDiceRollerWidget')) {
function mh_register_rpg_dice_roller_widget() {
register_widget('MHRPGDiceRollerWidget');
}
add_action('widgets_init', 'mh_register_rpg_dice_roller_widget');
}