forked from themeskult/wp-reading-time
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-reading-time.php
executable file
·73 lines (56 loc) · 2.36 KB
/
wp-reading-time.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
<?php
/*
Plugin Name: WP Reading Time
Plugin URI: https://github.com/themeskult/wp-reading-time
Description: It's a simple plugin that calculates the remaining reading time as you scroll down.
Version: 1.0
Author: Ricardo Rauch
Author URI: http://themeskult.com
Author Email: [email protected]
License:
Copyright 2013 WP Reading Time ([email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class WPReadingTime {
/*--------------------------------------------*
* Constructor
*--------------------------------------------*/
/**
* Initializes the plugin by setting localization, filters, and administration functions.
*/
function __construct() {
// Register site styles and scripts
add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_scripts' ) );
add_action('wp_footer', array( $this, 'my_custom_js'));
// Register hooks that are fired when the plugin is activated, deactivated, and uninstalled, respectively.
register_activation_hook( __FILE__, array( $this, 'activate' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
register_uninstall_hook( __FILE__, array( $this, 'uninstall' ) );
} // end constructor
/**
* Registers and enqueues plugin-specific scripts.
*/
public function register_plugin_scripts() {
wp_enqueue_script( 'jquery-reading-time', plugins_url("wp-reading-time/js/jquery.readingTime.js"), array('jquery'));
} // end register_plugin_scripts
public function my_custom_js() {
echo "
<script type='text/javascript' charset='utf-8'>
(function($) {
$('body.single .post').readingTime();
})( jQuery );
</script>
";
}
} // end class
// WPReadingTime: Update the instantiation call of your plugin to the name given at the class definition
$plugin_name = new WPReadingTime();