-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitchio-button.php
More file actions
69 lines (62 loc) · 1.64 KB
/
itchio-button.php
File metadata and controls
69 lines (62 loc) · 1.64 KB
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
<?php
/*
* Plugin Name: Itch.io Button Shortcode
* Plugin URI: https://github.com/OmiyaGames/itchio-button
* Description: Adds the [itchio-button] shortcode.
* Version: 1.0.0
* Author: Taro Omiya
* Author URI: https://omiyagames.com
* License: GPL v2
**/
// Make sure to add in the script from itch.io
function append_script() {
?>
<script type="text/javascript" src="https://static.itch.io/api.js"></script>
<?php
}
add_action( 'wp_head', 'append_script' );
// Add Shortcode
function itchio_button_shortcode( $atts , $content = null ) {
static $i = 0;
// Attributes
$atts = shortcode_atts(
array(
'user' => '',
'game' => '',
'width' => '',
'height' => '',
'text' => 'Download'
),
$atts,
'itchio-button'
);
// Generate output
$output = '<button id="itchio-button' . $i . '">' . $atts['text'] . '</button>';
$output .= "\n";
$output .= '<script type="text/javascript">';
$output .= "\n";
$output .= 'Itch.attachBuyButton(document.getElementById("itchio-button' . $i . '"), {';
$output .= "\n";
if( !empty( $atts['width'] ) ) {
$output .= 'width: "' . $atts['width'] . '",';
$output .= "\n";
}
if( !empty( $atts['height'] ) ) {
$output .= 'height: "' . $atts['height'] . '",';
$output .= "\n";
}
$output .= 'user: "' . $atts['user'] . '",';
$output .= "\n";
$output .= 'game: "' . $atts['game'] . '"';
$output .= "\n";
$output .= '});';
$output .= "\n";
$output .= '</script>';
$output .= "\n";
// Increment static ID value
$i++;
// Return code
return $output;
}
add_shortcode( 'itchio-button', 'itchio_button_shortcode' );
?>