Advertisement
firoze

tinymce-usages-users

Dec 17th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. <?php
  2.  
  3. /***********************************************/
  4. // tiny mc call this codes into your functions.php
  5.  
  6. // Hooks your functions into the correct filters
  7. function my_add_mce_button() {
  8. // check user permissions
  9. if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
  10. return;
  11. }
  12. // check if WYSIWYG is enabled
  13. if ( 'true' == get_user_option( 'rich_editing' ) ) {
  14. add_filter( 'mce_external_plugins', 'my_add_tinymce_plugin' );
  15. add_filter( 'mce_buttons', 'my_register_mce_button' );
  16. }
  17. }
  18. add_action('admin_head', 'my_add_mce_button');
  19.  
  20. // Declare script for new button
  21. function my_add_tinymce_plugin( $plugin_array ) {
  22. $plugin_array['my_mce_button'] = get_template_directory_uri() .'/js/tiny-mc.js'; // change here your js file location
  23. return $plugin_array;
  24. }
  25.  
  26. // Register new button in the editor
  27. function my_register_mce_button( $buttons ) {
  28. array_push( $buttons, 'my_mce_button' );
  29. return $buttons;
  30. }
  31.  
  32. /***********************************************/
  33. // call this codes into your js file
  34. (function() {
  35. tinymce.PluginManager.add('my_mce_button', function( editor, url ) {
  36. editor.addButton( 'my_mce_button', {
  37. text: 'Add Shortcodes',
  38. icon: false,
  39. type: 'menubutton',
  40. menu:[
  41.  
  42. // contact number
  43. {
  44. text:'contact number',
  45. onClick: function(){
  46. editor.insertContent('[contact-number]');
  47. }
  48. },
  49. //menu
  50. {
  51. text:'menu',
  52. onClick: function(){
  53. editor.insertContent('[menu name="Left Side Menu"]');
  54. }
  55. },
  56. //blog-post
  57. {
  58. text:'blog-post',
  59. onClick: function(){
  60. editor.insertContent('[blog-post]');
  61. }
  62. },
  63.  
  64. // TwentySlider
  65. {
  66. text:'TwentySlider',
  67. onClick: function(){
  68. editor.insertContent('[twentyslider]');
  69. }
  70. },
  71. // latest-post
  72. {
  73. text:'latest-post',
  74. onClick: function(){
  75. editor.insertContent('[latest-post]');
  76. }
  77. },
  78.  
  79. //Blog Post Start
  80. {
  81. text:'Blog Post',
  82. onClick: function() {
  83. editor.windowManager.open( {
  84. title: 'Insert Blog Post Shortcode',
  85. body: [
  86. {
  87. type: 'textbox',
  88. name: 'titleName',
  89. label: 'Blog Post Title', // Display Name
  90. },
  91. {
  92. type: 'textbox',
  93. name: 'descriptionName',
  94. label: 'Descriptions', // Display Name
  95. multiline: true,
  96. minWidth: 300,
  97. minHeight: 100
  98. },
  99. {
  100. type: 'textbox',
  101. name: 'categoryName',
  102. label: 'Category', // Display Name
  103. },
  104. {
  105. type: 'textbox',
  106. name: 'subtitleName',
  107. label: 'Subtitle', // Display Name
  108. },
  109. {
  110. type: 'textbox',
  111. name: 'postpageName',
  112. label: 'Post Per Page', // Display Name
  113. },
  114. ],
  115. // [blog-post textbox="ooo" multiline="ppp" listbox="undefined"]
  116. onsubmit: function( e ) {
  117. editor.insertContent( '[blog-post Title="' + e.data.titleName + '" Des="' + e.data.descriptionName + '" Category="' + e.data.categoryName + '" Subtitle="' + e.data.subtitleName + '" Post Per Page="' + e.data.postpageName + '"]');
  118. }
  119. });
  120. }
  121. }, // Blog Post End
  122.  
  123. //TwentySlider Start
  124. {
  125. text:'Twenty Slider',
  126. onClick: function() {
  127. editor.windowManager.open( {
  128. title: 'Insert Twenty Slider Shortcode',
  129. body: [
  130. {
  131. type: 'textbox',
  132. name: 'twentyName',
  133. label: 'TwentySlider Title', // Display Name
  134. },
  135. {
  136. type: 'textbox',
  137. name: 'twentydesName',
  138. label: 'Descriptions', // Display Name
  139. multiline: true,
  140. minWidth: 300,
  141. minHeight: 100
  142. },
  143. {
  144. type: 'textbox',
  145. name: 'twentysubtitleName',
  146. label: 'Subtitle', // Display Name
  147. },
  148. ],
  149.  
  150. // [blog-post textbox="ooo" multiline="ppp" listbox="undefined"]
  151. onsubmit: function( e ) {
  152. editor.insertContent( '[twentyslider Title="' + e.data.twentyName + '" Des="' + e.data.twentydesName + '" Subtitle="' + e.data.twentysubtitleName + '"]');
  153. }
  154. });
  155. }
  156. }, //TwentySlider End
  157. // add another shortcode
  158. ]
  159. });
  160. });
  161. })();
  162.  
  163. ?>
  164.  
  165.  
  166.  
  167.  
  168. // source link:http://www.wpexplorer.com/wordpress-tinymce-tweaks/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement