PluginProbe
A Random Number / 1.0
A Random Number v1.0
trunk 1.0 1.1 1.2
a-random-number / a-random-number.php

a-random-number.php in A Random Number 1.0, at a-random-number.php

70 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: A Random Number
4 * Plugin URI: http://www.macardam.com/a-random-number/
5 * Description: Outputs a random number via shortcode. It's magic.
6 * Version: 1.0.0
7 * Author: Macardam
8 * Author URI: http://www.macardam.com/
9 * License: GPL2
10 */
11
12 /* Random Number Function */
13 function randomNumber( $atts ){
14 $atts = shortcode_atts( array(
15 'min' => '1',
16 'max' => '100'
17 ), $atts, 'randomnumber' );
18 $arandomnumber = mt_rand( $atts['min'], $atts['max'] );
19 $prettynumber = number_format($arandomnumber);
20
21 return $prettynumber;
22 }
23
24 /* Assigning Shortcode */
25 add_shortcode('arandomnumber', 'randomNumber');
26
27 /* Adding Button to Editor */
28 add_action('admin_head', 'a_random_number_button');
29
30 function a_random_number_button() {
31 global $typenow;
32 // check user permissions
33 if ( !current_user_can('edit_posts') && !current_user_can('edit_pages') ) {
34 return;
35 }
36 // verify the post type
37 if( ! in_array( $typenow, array( 'post', 'page' ) ) )
38 return;
39 // check if WYSIWYG is enabled
40 if ( get_user_option('rich_editing') == 'true') {
41 add_filter("mce_external_plugins", "arandomnumber_add_tinymce_plugin");
42 add_filter('mce_buttons', 'arandomnumber_register_my_tc_button');
43 }
44 }
45
46 function arandomnumber_add_tinymce_plugin($plugin_array) {
47 $plugin_array['arandomnumber_tc_button'] = plugins_url( '/arandomnumber-button.js', __FILE__ );
48 return $plugin_array;
49 }
50
51 function arandomnumber_register_my_tc_button($buttons) {
52 array_push($buttons, "arandomnumber_tc_button");
53 return $buttons;
54 }
55
56 /* Adding QuickTag Button */
57 function arn_quicktags() {
58
59 if ( wp_script_is( 'quicktags' ) ) {
60 ?>
61 <script type="text/javascript">
62 QTags.addButton( 'arandomnumber', 'A Random Number', '[arandomnumber min=1 max=100]' );
63 </script>
64 <?php
65 }
66
67 }
68 add_action( 'admin_print_footer_scripts', 'arn_quicktags' );
69
70 ?>