-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspeech-shortcode.php
More file actions
executable file
·68 lines (57 loc) · 1.78 KB
/
speech-shortcode.php
File metadata and controls
executable file
·68 lines (57 loc) · 1.78 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
<?php
/**
* Plugin Name: Speech Shortcode
* Plugin URI: https://github.com/miya0001/speech-shortcode
* Description: Implementation of HTML5 Text Speech API as a WordPress Shortcode.
* Author: Takayuki Miyauchi
* Author URI: https://miya.io/
* Text Domain: speech-shortcode
* Domain Path: /languages
* Version: nightly
*
* @package Speech_Shortcode
*/
require_once( dirname( __FILE__ ) . '/vendor/autoload.php' );
class Speech_Shortcode
{
const version = 'nightly';
public function __construct()
{
add_action( 'init', array( $this, 'activate_autoupdate' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
add_shortcode( 'speech', array( $this, 'speech' ) );
}
public function activate_autoupdate() {
$plugin_slug = plugin_basename( __FILE__ );
$gh_user = 'miya0001';
$gh_repo = 'speech-shortcode';
new Miya\WP\GH_Auto_Updater( $plugin_slug, $gh_user, $gh_repo );
}
public function speech( $atts, $content )
{
$atts = shortcode_atts( array(
'lang' => apply_filters( 'speech_shortcode_default_lang', 'en-US' ),
'voice' => apply_filters( 'speech_shortcode_default_voice', '' ),
'rate' => apply_filters( 'speech_shortcode_default_rate', '1' ),
), $atts, 'speech' );
wp_enqueue_script(
'speech-shortcode',
plugins_url( 'js/speech-shortcode.min.js', __FILE__ ),
array(),
self::version,
true
);
return sprintf(
'<span class="speech-shortcode" data-lang="%1$s" data-voice="%2$s" data-rate="%3$s">%4$s</span>',
esc_attr( $atts['lang'] ),
esc_attr( $atts['voice'] ),
esc_attr( $atts['rate'] ),
wp_strip_all_tags( $content )
);
}
public function wp_enqueue_scripts()
{
wp_enqueue_style( 'dashicons' );
}
}
$speech_shortcode = new Speech_Shortcode();