PluginProbe
Gallery Box / trunk
Gallery Box vtrunk
trunk 1.3.1 1.3.3 1.4.0 1.4.1 1.4.2 1.5.1 1.7.35
gallery-box / admin / add-button-tinymce.php

add-button-tinymce.php in Gallery Box trunk, at admin/add-button-tinymce.php

86 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Add custom button in TinyMCE editor for Gallery Box shortcode.
4 *
5 * @link http://themeforest.digitalkroy.com/gallery-box/
6 * @since 1.0.0
7 * @package Gallery box wordpress plugin
8 */
9
10 // Hooks your functions into the correct filters
11 if (! function_exists('gbox_add_mce_button')) :
12 function gbox_add_mce_button()
13 {
14 // check user permissions
15 if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
16 return;
17 }
18 // check if WYSIWYG is enabled
19 if ('true' == get_user_option('rich_editing')) {
20 add_filter('mce_external_plugins', 'gbox_tinymce_scripts');
21 add_filter('mce_buttons', 'gbox_tinymce_register');
22 }
23 }
24 add_action('admin_head', 'gbox_add_mce_button');
25 endif;
26 // Declare script for new button
27 if (! function_exists('gbox_tinymce_scripts')) :
28 function gbox_tinymce_scripts($plugin_array)
29 {
30 // check administrator or editor
31 if (current_user_can('administrator')) {
32 $plugin_array['gbox_button'] = plugins_url('/../assets/js/admin-mce-button.js', __FILE__);
33 return $plugin_array;
34 } else {
35 $plugin_array['gbox_button'] = plugins_url('/../assets/js/mce-button.js', __FILE__);
36 return $plugin_array;
37 }
38 }
39 endif;
40 // Register new button in the editor
41 if (! function_exists('gbox_tinymce_register')) :
42 function gbox_tinymce_register($buttons)
43 {
44 array_push($buttons, 'gbox_button');
45 return $buttons;
46 }
47 endif;
48 // Add gallery post id dynamical in TinyMCE editor custom button
49 if (! function_exists('gbox_tinymce_shortcode_list_id')) :
50 function gbox_tinymce_shortcode_list_id()
51 {
52 $gposts = get_posts(array(
53 'post_type' => 'gallery_box',
54 'post_status' => 'publish',
55 'posts_per_page' => -1,
56 'suppress_filters' => true
57 ));
58 $tinyMCE_list_gbox = array();
59 $count = 1;
60 if ($gposts) :
61 foreach ($gposts as $gpost) :
62 $post_ID = $gpost->ID;
63 if (!empty($gpost->post_title)) {
64 $post_title = $gpost->post_title;
65 } else {
66 $post_title = 'Untitled gallery id -' . $post_ID;
67 }
68 $tinyMCE_list_gbox[] = array('text' => $post_title, 'value' => '[gallerybox id="' . $post_ID . '"]');
69 endforeach;
70 else:
71 $tinyMCE_list_gbox[] = array('text' => __('No gallery found', 'gallery-box'), 'value' => '');
72 endif;
73 $gbox_jscode = $tinyMCE_list_gbox;
74 if (is_admin()) {
75 ?>
76 <script type="text/javascript">
77 var gbox_post_id = <?php echo json_encode($gbox_jscode); ?>
78 </script>
79 <?php
80 }
81 }
82 foreach (array('post.php', 'post-new.php') as $hook) {
83 add_action("admin_head-$hook", 'gbox_tinymce_shortcode_list_id');
84 }
85 endif;
86