PageRenderTime 41ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/shop quần áo starloveshop.com/wp-content/plugins/advanced-custom-fields/core/fields/wysiwyg.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 378 lines | 188 code | 89 blank | 101 comment | 10 complexity | 0254cf6eab843136c399633acd83b374 MD5 | raw file
  1. <?php
  2. // Create an acf version of the_content filter (acf_the_content)
  3. if( isset($GLOBALS['wp_embed']) )
  4. {
  5. add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'run_shortcode' ), 8 );
  6. add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );
  7. }
  8. add_filter( 'acf_the_content', 'capital_P_dangit', 11 );
  9. add_filter( 'acf_the_content', 'wptexturize' );
  10. add_filter( 'acf_the_content', 'convert_smilies' );
  11. add_filter( 'acf_the_content', 'convert_chars' );
  12. add_filter( 'acf_the_content', 'wpautop' );
  13. add_filter( 'acf_the_content', 'shortcode_unautop' );
  14. add_filter( 'acf_the_content', 'prepend_attachment' );
  15. add_filter( 'acf_the_content', 'do_shortcode', 11);
  16. class acf_field_wysiwyg extends acf_field
  17. {
  18. /*
  19. * __construct
  20. *
  21. * Set name / label needed for actions / filters
  22. *
  23. * @since 3.6
  24. * @date 23/01/13
  25. */
  26. function __construct()
  27. {
  28. // vars
  29. $this->name = 'wysiwyg';
  30. $this->label = __("Wysiwyg Editor",'acf');
  31. $this->category = __("Content",'acf');
  32. $this->defaults = array(
  33. 'toolbar' => 'full',
  34. 'media_upload' => 'yes',
  35. 'default_value' => '',
  36. );
  37. // do not delete!
  38. parent::__construct();
  39. // filters
  40. add_filter( 'acf/fields/wysiwyg/toolbars', array( $this, 'toolbars'), 1, 1 );
  41. add_filter( 'mce_external_plugins', array( $this, 'mce_external_plugins'), 20, 1 );
  42. }
  43. /*
  44. * mce_external_plugins
  45. *
  46. * This filter will add in the tinyMCE 'code' plugin which is missing in WP 3.9
  47. *
  48. * @type function
  49. * @date 18/04/2014
  50. * @since 5.0.0
  51. *
  52. * @param $post_id (int)
  53. * @return $post_id (int)
  54. */
  55. function mce_external_plugins( $plugins ){
  56. // global
  57. global $wp_version;
  58. // WP 3.9 an above
  59. if( version_compare($wp_version, '3.9', '>=' ) ) {
  60. // add code
  61. $plugins['code'] = apply_filters('acf/get_info', 'dir') . 'js/tinymce.code.min.js';
  62. }
  63. // return
  64. return $plugins;
  65. }
  66. /*
  67. * toolbars()
  68. *
  69. * This filter allowsyou to customize the WYSIWYG toolbars
  70. *
  71. * @param $toolbars - an array of toolbars
  72. *
  73. * @return $toolbars - the modified $toolbars
  74. *
  75. * @type filter
  76. * @since 3.6
  77. * @date 23/01/13
  78. */
  79. function toolbars( $toolbars ) {
  80. // global
  81. global $wp_version;
  82. // vars
  83. $editor_id = 'acf_settings';
  84. if( version_compare($wp_version, '3.9', '>=' ) ) {
  85. // Full
  86. $toolbars['Full'] = array(
  87. 1 => apply_filters( 'mce_buttons', array('bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'hr', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv' ), $editor_id ),
  88. 2 => apply_filters( 'mce_buttons_2', array( 'formatselect', 'underline', 'alignjustify', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo', 'wp_help', 'code' ), $editor_id ),
  89. 3 => apply_filters('mce_buttons_3', array(), $editor_id),
  90. 4 => apply_filters('mce_buttons_4', array(), $editor_id),
  91. );
  92. // Basic
  93. $toolbars['Basic'] = array(
  94. 1 => apply_filters( 'teeny_mce_buttons', array('bold', 'italic', 'underline', 'blockquote', 'strikethrough', 'bullist', 'numlist', 'alignleft', 'aligncenter', 'alignright', 'undo', 'redo', 'link', 'unlink', 'fullscreen'), $editor_id ),
  95. );
  96. } else {
  97. // Full
  98. $toolbars['Full'] = array(
  99. 1 => apply_filters( 'mce_buttons', array('bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'justifyleft', 'justifycenter', 'justifyright', 'link', 'unlink', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv' ), $editor_id ),
  100. 2 => apply_filters( 'mce_buttons_2', array( 'formatselect', 'underline', 'justifyfull', 'forecolor', 'pastetext', 'pasteword', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo', 'wp_help', 'code' ), $editor_id ),
  101. 3 => apply_filters('mce_buttons_3', array(), $editor_id),
  102. 4 => apply_filters('mce_buttons_4', array(), $editor_id),
  103. );
  104. // Basic
  105. $toolbars['Basic'] = array(
  106. 1 => apply_filters( 'teeny_mce_buttons', array('bold', 'italic', 'underline', 'blockquote', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'undo', 'redo', 'link', 'unlink', 'fullscreen'), $editor_id ),
  107. );
  108. }
  109. // Custom - can be added with acf/fields/wysiwyg/toolbars filter
  110. return $toolbars;
  111. }
  112. /*
  113. * input_admin_head()
  114. *
  115. * This action is called in the admin_head action on the edit screen where your field is created.
  116. * Use this action to add css and javascript to assist your create_field() action.
  117. *
  118. * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head
  119. * @type action
  120. * @since 3.6
  121. * @date 23/01/13
  122. */
  123. function input_admin_head()
  124. {
  125. add_action( 'admin_footer', array( $this, 'admin_footer') );
  126. }
  127. function admin_footer()
  128. {
  129. ?>
  130. <div style="display:none;">
  131. <?php wp_editor( '', 'acf_settings' ); ?>
  132. </div>
  133. <?php
  134. }
  135. /*
  136. * create_field()
  137. *
  138. * Create the HTML interface for your field
  139. *
  140. * @param $field - an array holding all the field's data
  141. *
  142. * @type action
  143. * @since 3.6
  144. * @date 23/01/13
  145. */
  146. function create_field( $field )
  147. {
  148. global $wp_version;
  149. // vars
  150. $id = 'wysiwyg-' . $field['id'] . '-' . uniqid();
  151. ?>
  152. <div id="wp-<?php echo $id; ?>-wrap" class="acf_wysiwyg wp-editor-wrap" data-toolbar="<?php echo $field['toolbar']; ?>" data-upload="<?php echo $field['media_upload']; ?>">
  153. <?php if( user_can_richedit() && $field['media_upload'] == 'yes' ): ?>
  154. <?php if( version_compare($wp_version, '3.3', '<') ): ?>
  155. <div id="editor-toolbar">
  156. <div id="media-buttons" class="hide-if-no-js">
  157. <?php do_action( 'media_buttons' ); ?>
  158. </div>
  159. </div>
  160. <?php else: ?>
  161. <div id="wp-<?php echo $id; ?>-editor-tools" class="wp-editor-tools">
  162. <div id="wp-<?php echo $id; ?>-media-buttons" class="hide-if-no-js wp-media-buttons">
  163. <?php do_action( 'media_buttons' ); ?>
  164. </div>
  165. </div>
  166. <?php endif; ?>
  167. <?php endif; ?>
  168. <div id="wp-<?php echo $id; ?>-editor-container" class="wp-editor-container">
  169. <textarea id="<?php echo $id; ?>" class="wp-editor-area" name="<?php echo $field['name']; ?>" ><?php
  170. if( user_can_richedit() )
  171. {
  172. echo wp_richedit_pre( $field['value'] );
  173. }
  174. else
  175. {
  176. echo wp_htmledit_pre( $field['value'] );
  177. }
  178. ?></textarea>
  179. </div>
  180. </div>
  181. <?php
  182. }
  183. /*
  184. * create_options()
  185. *
  186. * Create extra options for your field. This is rendered when editing a field.
  187. * The value of $field['name'] can be used (like bellow) to save extra data to the $field
  188. *
  189. * @type action
  190. * @since 3.6
  191. * @date 23/01/13
  192. *
  193. * @param $field - an array holding all the field's data
  194. */
  195. function create_options( $field )
  196. {
  197. // vars
  198. $key = $field['name'];
  199. ?>
  200. <tr class="field_option field_option_<?php echo $this->name; ?>">
  201. <td class="label">
  202. <label><?php _e("Default Value",'acf'); ?></label>
  203. <p><?php _e("Appears when creating a new post",'acf') ?></p>
  204. </td>
  205. <td>
  206. <?php
  207. do_action('acf/create_field', array(
  208. 'type' => 'textarea',
  209. 'name' => 'fields['.$key.'][default_value]',
  210. 'value' => $field['default_value'],
  211. ));
  212. ?>
  213. </td>
  214. </tr>
  215. <tr class="field_option field_option_<?php echo $this->name; ?>">
  216. <td class="label">
  217. <label><?php _e("Toolbar",'acf'); ?></label>
  218. </td>
  219. <td>
  220. <?php
  221. $toolbars = apply_filters( 'acf/fields/wysiwyg/toolbars', array() );
  222. $choices = array();
  223. if( is_array($toolbars) )
  224. {
  225. foreach( $toolbars as $k => $v )
  226. {
  227. $label = $k;
  228. $name = sanitize_title( $label );
  229. $name = str_replace('-', '_', $name);
  230. $choices[ $name ] = $label;
  231. }
  232. }
  233. do_action('acf/create_field', array(
  234. 'type' => 'radio',
  235. 'name' => 'fields['.$key.'][toolbar]',
  236. 'value' => $field['toolbar'],
  237. 'layout' => 'horizontal',
  238. 'choices' => $choices
  239. ));
  240. ?>
  241. </td>
  242. </tr>
  243. <tr class="field_option field_option_<?php echo $this->name; ?>">
  244. <td class="label">
  245. <label><?php _e("Show Media Upload Buttons?",'acf'); ?></label>
  246. </td>
  247. <td>
  248. <?php
  249. do_action('acf/create_field', array(
  250. 'type' => 'radio',
  251. 'name' => 'fields['.$key.'][media_upload]',
  252. 'value' => $field['media_upload'],
  253. 'layout' => 'horizontal',
  254. 'choices' => array(
  255. 'yes' => __("Yes",'acf'),
  256. 'no' => __("No",'acf'),
  257. )
  258. ));
  259. ?>
  260. </td>
  261. </tr>
  262. <?php
  263. }
  264. /*
  265. * format_value_for_api()
  266. *
  267. * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
  268. *
  269. * @type filter
  270. * @since 3.6
  271. * @date 23/01/13
  272. *
  273. * @param $value - the value which was loaded from the database
  274. * @param $post_id - the $post_id from which the value was loaded
  275. * @param $field - the field array holding all the field options
  276. *
  277. * @return $value - the modified value
  278. */
  279. function format_value_for_api( $value, $post_id, $field )
  280. {
  281. // apply filters
  282. $value = apply_filters( 'acf_the_content', $value );
  283. // follow the_content function in /wp-includes/post-template.php
  284. $value = str_replace(']]>', ']]&gt;', $value);
  285. return $value;
  286. }
  287. }
  288. new acf_field_wysiwyg();
  289. ?>