-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
55 lines (48 loc) · 1.36 KB
/
index.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
<?php
/*
Plugin Name: Sparklines for WordPress
Plugin URI: https://github.com/nilspersson/sparklines-for-wordpress
Description: A simple plugin to enable inline charts powered by the Spark font by After the Flood.
Version: 1.0
Author: Nils Persson
Author URI: http://nilspersson.se/
*/
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
// The Shortcode
function atf_spark_shortcode( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'start' => '123',
'data' => '10,20,30,40,50,60,70,80,90,100',
'end' => '789',
'type' => 'bar-medium',
),
$atts,
'spark'
);
// Filter data
$noSpaces = str_replace(" ", "", $atts['data']);
$allValues = explode(",", $noSpaces);
$validValues = array_filter($allValues, function($x) {
return is_numeric($x);
});
$dataString = implode(",", $validValues);
// Return HTML
return '<span class="atf-spark atf-spark--' . $atts['type'] . '">'
. $atts['start']
. '{'
. $dataString
. '}'
. $atts['end']
. '</span>';
}
add_shortcode( 'spark', 'atf_spark_shortcode' );
function atf_spark_css() {
global $post;
if ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'spark') ) {
wp_enqueue_style('atf-spark-css', plugin_dir_url( __FILE__ ) . '/atf-spark.css?ver=' . (string)rand());
}
}
add_action( 'wp_enqueue_scripts', 'atf_spark_css' )
?>