advmceconf_admin

The Advanced TinyMCE Configuration advmceconf admin function.

Description

advmceconf_admin(); 

Usage

  1. if ( !function_exists( 'advmceconf_admin' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'advanced-tinymce-configuration/adv-mce-config.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = advmceconf_admin(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/adv-mce-config.php  
  1. function advmceconf_admin() { 
  2. global $advmceconf_show_defaults; 
  3.  
  4. if ( ! current_user_can('manage_options') ) 
  5. wp_die('Access denied'); 
  6.  
  7. $message = ''; 
  8. $options = get_option( 'advmceconf_options', array() ); 
  9. $version = get_option( 'advmceconf_version', 0 ); 
  10.  
  11. if ( ! empty($_POST['advmceconf_save']) ) { 
  12. check_admin_referer('advmceconf-save-options'); 
  13. $old_options = $options; 
  14.  
  15. if ( empty( $_POST['advmceconf_options'] ) || ! is_array( $_POST['advmceconf_options'] ) ) 
  16. $new_options = array(); 
  17. else 
  18. $new_options = $_POST['advmceconf_options']; 
  19.  
  20. if ( ! empty( $_POST['advmceconf-new'] ) && isset( $_POST['advmceconf-new-val'] ) ) 
  21. $new_options[ $_POST['advmceconf-new'] ] = $_POST['advmceconf-new-val']; 
  22.  
  23. foreach ( $new_options as $key => $val ) { 
  24. $key = preg_replace( '/[^a-z0-9_]+/i', '', $key ); 
  25. if ( empty($key) ) 
  26. continue; 
  27.  
  28. if ( isset( $_POST[$key] ) && empty( $_POST[$key] ) ) { 
  29. unset( $options[$key] ); 
  30. continue; 
  31.  
  32. $val = stripslashes($val); 
  33. if ( 'true' == $val ) 
  34. $options[$key] = true; 
  35. elseif ( 'false' == $val ) 
  36. $options[$key] = false; 
  37. else 
  38. $options[$key] = $val; 
  39.  
  40. if ( $options != $old_options ) { 
  41. update_option('advmceconf_options', $options); 
  42. $message = '<div class="updated fade"><p>' . __('Options saved.', 'adv-mce-config') . '</p></div>'; 
  43.  
  44. if ( $version < 12 && advmceconf_is_mce_version_4() ) { 
  45. update_option( 'advmceconf_version', 12 ); 
  46. $version = 12; 
  47. } elseif ( ! $version ) { 
  48. update_option( 'advmceconf_version', 11 ); 
  49. $version = 11; 
  50.  
  51. ?> 
  52. <div class="wrap"> 
  53. <?php screen_icon(); ?> 
  54. <h2><?php _e('Advanced TinyMCE Settings', 'adv-mce-config'); ?></h2> 
  55. <?php 
  56.  
  57. if ( $version < 12 && advmceconf_is_mce_version_4() ) { 
  58. ?> 
  59. <div class="error"><p> 
  60. <?php 
  61. _e('You are running TinyMCE 4.0 (WordPress 3.9 or newer) but the settings for the editor have not been updated. This can result in errors while editing, or the editor may fail completely. ', 'adv-mce-config'); 
  62. _e('(This notice will dissapear after the settings are updated.)', 'adv-mce-config'); 
  63. ?> 
  64. </p></div> 
  65. <?php 
  66.  
  67. if ( $message ) 
  68. echo $message; 
  69.  
  70. ?> 
  71. <div class="advmceconf-wrap"> 
  72. <h3><?php _e('How-to:', 'adv-mce-config'); ?></h3> 
  73. <ol> 
  74. <li><?php _e('To add a setting to TinyMCE, type the name on the left and the value on the right.', 'adv-mce-config'); ?></li> 
  75. <li><?php _e('Do not add quotes around the name or value.', 'adv-mce-config'); ?></li> 
  76. <li><?php _e('To remove a setting, delete both name and value.', 'adv-mce-config'); ?></li> 
  77. <li><?php _e('To add boolean values type <code>true</code> or <code>false</code>. These strings are converted to boolean when saving.', 'adv-mce-config'); ?></li> 
  78. <li><?php _e('You can add JavaScript arrays, objects and functions in the value field.', 'adv-mce-config'); ?></li> 
  79. <li><?php _e('When copying settings from the examples in the TinyMCE documentation, make sure you copy only the setting name and value, not the whole example.', 'adv-mce-config'); ?></li>  
  80. <li><?php _e('When pasting, make sure both the name and value do not start or end with empty spaces.', 'adv-mce-config'); ?></li> 
  81. <li><?php _e('Both the name and value must follow the JavaScript syntax. Line breaks are only allowed when using arrays or objects.', 'adv-mce-config'); ?></li> 
  82. </ol> 
  83.  
  84. <h4><?php _e('Example:', 'adv-mce-config'); ?></h4> 
  85. <p><?php _e('To add the <code>block_formats</code> setting from the example in the TinyMCE documentation:', 'adv-mce-config'); ?></p> 
  86. <p><img width="784" height="144" src="<?php echo plugins_url( 'images/block-formats-example.png', __FILE__ ); ?>" title="<?php esc_attr_e('Screenshot of the example.', 'adv-mce-config'); ?>"></p> 
  87. <p><?php _e('you need to enter <code>block_formats</code> in the Option name field and <code>Paragraph=p;Header 1=h1;Header 2=h2;Header 3=h3</code> in the Value field:', 'adv-mce-config'); ?></p> 
  88. <p><img width="784" height="137" src="<?php echo plugins_url( 'images/block-formats-setting.png', __FILE__ ); ?>" title="<?php esc_attr_e('Screenshot of the added setting.', 'adv-mce-config'); ?>"></p> 
  89.  
  90. <p><?php _e('Description of all settings is available in the', 'adv-mce-config'); ?> <a href="https://www.tinymce.com/docs/" target="_blank"><?php _e('TinyMCE documentation', 'adv-mce-config'); ?></a>.</p> 
  91. <?php 
  92.  
  93. ?> 
  94. <p><?php _e('Several of the more commonly used settings are:', 'adv-mce-config'); ?></p> 
  95. <ul class="ul-disc"> 
  96. <li><a href="https://www.tinymce.com/docs/configure/content-formatting/#block_formats" target="_blank">block_formats</a></li> 
  97. <li><a href="https://www.tinymce.com/docs/configure/content-formatting/#style_formats" target="_blank">style_formats</a></li> 
  98. <li><a href="https://www.tinymce.com/docs/configure/content-filtering/#invalid_elements" target="_blank">invalid_elements</a></li> 
  99. <li><a href="https://www.tinymce.com/docs/configure/content-filtering/#extended_valid_elements" target="_blank">extended_valid_elements</a></li> 
  100. </ul> 
  101. <?php 
  102.  
  103. ?> 
  104. </div> 
  105.  
  106. <table id="advmceconf-defaults" class="advmceconf-table showhide" style="display: none;"> 
  107. <thead><tr> 
  108. <th class="names"><?php _e('Name', 'adv-mce-config'); ?></th> 
  109. <th class="sep"> </th> 
  110. <th><?php _e('Value', 'adv-mce-config'); ?></th> 
  111. <th class="actions"> </th> 
  112. </tr></thead> 
  113. <tbody> 
  114. <?php 
  115.  
  116. ob_start(); 
  117. wp_editor( '', 'content', array( 'media_buttons' => false, 'quicktags' => false ) ); 
  118. ob_end_clean(); 
  119.  
  120. if ( !empty($advmceconf_show_defaults) && is_array($advmceconf_show_defaults) ) { 
  121. $n = 1; 
  122. $change = esc_attr( __('Change', 'adv-mce-config') ); 
  123.  
  124. foreach ( $advmceconf_show_defaults as $def_field => $def_value ) { 
  125. if ( is_bool( $def_value ) ) 
  126. $def_value = $def_value ? 'true' : 'false'; 
  127. ?> 
  128.  
  129. <tr> 
  130. <td id="name-<?php echo $n; ?>" class="names"><?php echo $def_field; ?></td> 
  131. <td class="sep">:</td> 
  132. <td id="val-<?php echo $n; ?>"><?php echo htmlspecialchars( $def_value, ENT_QUOTES ); ?></td> 
  133. <td class="actions"><input type="button" data-num="<?php echo $n; ?>" class="button" value="<?php echo $change; ?>" /></td> 
  134. </tr> 
  135. <?php 
  136.  
  137. $n++; 
  138.  
  139. ?> 
  140. </tbody> 
  141. </table> 
  142.  
  143. <p> 
  144. <button type="button" class="button showhide"><?php _e('Show the default TinyMCE settings', 'adv-mce-config'); ?></button> 
  145. <button type="button" class="button showhide" style="display: none;"><?php _e('Hide the default TinyMCE settings', 'adv-mce-config'); ?></button> 
  146. </p> 
  147.  
  148. <form method="post" action="" style="padding:10px 0"> 
  149. <table class="advmceconf-table" id="advmceconf-set"> 
  150. <thead><tr> 
  151. <th class="names"><?php _e('Option name', 'adv-mce-config'); ?></th> 
  152. <th><?php _e('Value', 'adv-mce-config'); ?></th> 
  153. <th class="actions"> </th> 
  154. </tr></thead> 
  155. <tbody> 
  156. <?php 
  157.  
  158. $remove = esc_attr( __('Remove', 'adv-mce-config') ); 
  159. foreach ( $options as $field => $value ) { 
  160. $field = esc_attr( $field ); 
  161. $id = "advmceconf_option-{$field}"; 
  162. $name = "advmceconf_options[{$field}]"; 
  163.  
  164. if ( is_bool($value) ) 
  165. $value = $value ? 'true' : 'false'; 
  166.  
  167. ?> 
  168. <tr> 
  169. <td class="names"><input type="text" name="<?php echo $field; ?>" id="<?php echo $field; ?>" value="<?php echo $field; ?>" /></td> 
  170. <td><textarea name="<?php echo $name; ?>" id="<?php echo $id; ?>" spellcheck="false"><?php echo htmlspecialchars( $value, ENT_NOQUOTES ); ?></textarea></td> 
  171. <td class="actions"><input type="button" class="button remove" value="<?php echo $remove; ?>" /></td> 
  172. </tr> 
  173. <?php 
  174.  
  175. ?> 
  176. <tr> 
  177. <td class="names"><input type="text" name="advmceconf-new" id="advmceconf-new" value="" /></td> 
  178. <td><textarea name="advmceconf-new-val" id="advmceconf-new-val" spellcheck="false"></textarea></td> 
  179. <td> </td> 
  180. </tr> 
  181. </tbody> 
  182. </table> 
  183.  
  184. <p class="submit"> 
  185. <?php wp_nonce_field('advmceconf-save-options'); ?> 
  186. <input type="submit" value="<?php esc_attr_e('Save Changes', 'adv-mce-config'); ?>" class="button-primary" name="advmceconf_save" /> 
  187. </p> 
  188. </form> 
  189. </div> 
  190.  
  191. <script type="text/javascript"> 
  192. jQuery(document).ready( function($) { 
  193. var defaults = []; 
  194.  
  195. $('#advmceconf-defaults td.names').each( function(n, el) { 
  196. defaults.push( $(el).text() ); 
  197. }); 
  198.  
  199. $('#advmceconf-set td.names').each( function(n, el) { 
  200. var text = $('input', el).val(); 
  201.  
  202. if ( text && $.inArray(text, defaults) > -1 ) { 
  203. $(el).parent().addClass('advmceconf-highlight'); 
  204. $('td.names:contains("' + text + '")', '#showhide').parent().addClass('advmceconf-highlight'); 
  205. }); 
  206.  
  207. $('button.showhide').on( 'click', function(e) { 
  208. $('table.showhide, button.showhide').toggle(); 
  209. }); 
  210.  
  211. $('#advmceconf-defaults').on( 'click', function(e) { 
  212. var num = $(e.target).data('num'); 
  213.  
  214. if ( num ) { 
  215. $('#advmceconf-new').val( $( '#name-' + num ).text() ); 
  216. $('#advmceconf-new-val').val( $( '#val-' + num ).text() ); 
  217. scrollTo(0, 50000); 
  218. }); 
  219.  
  220. $('#advmceconf-set').on( 'click', function(e) { 
  221. var target = $(e.target); 
  222.  
  223. if ( target.hasClass('remove') ) 
  224. target.closest('tr').find('input[type="text"], textarea').val(''); 
  225. }); 
  226. }); 
  227. </script> 
  228. <?php