acf_field_markdown

The Advanced Custom Fields: Markdown acf field markdown class.

Defined (2)

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

/acf-markdown-v4.php  
  1. class acf_field_markdown extends acf_field { 
  2.  
  3. // vars 
  4. var $settings, // will hold info such as dir / path 
  5. $defaults; // will hold default field options 
  6.  
  7.  
  8. /** 
  9. * __construct 
  10. * Set name / label needed for actions / filters 
  11. * @since 3.6 
  12. * @date 23/01/13 
  13. */ 
  14.  
  15. function __construct() 
  16. // vars 
  17. $this->name = 'markdown'; 
  18. $this->label = __('Markdown'); 
  19. $this->category = __("Basic", 'acf'); // Basic, Content, Choice, etc 
  20. $this->defaults = array( 
  21. 'autogrow' => '1',  
  22. //'sidebyside' => '1',  
  23. 'editor-theme' => 'dark',  
  24. 'preview-theme' => 'github',  
  25. 'syntax-highlight' => '0',  
  26. 'syntax-theme' => 'monokai_sublime',  
  27. 'tab-function' => '0',  
  28. 'media-upload' => '0' 
  29. ); 
  30.  
  31.  
  32. // do not delete! 
  33. parent::__construct(); 
  34.  
  35.  
  36. // settings 
  37. $this->settings = array( 
  38. 'path' => apply_filters('acf/helpers/get_path', __FILE__),  
  39. 'dir' => apply_filters('acf/helpers/get_dir', __FILE__),  
  40. 'version' => '1.1.4' 
  41. ); 
  42.  
  43.  
  44.  
  45. /** 
  46. * create_options() 
  47. * Create extra options for your field. This is rendered when editing a field. 
  48. * The value of $field['name'] can be used (like below) to save extra data to the $field 
  49. * @type action 
  50. * @since 3.6 
  51. * @date 23/01/13 
  52. * @param $field - an array holding all the field's data 
  53. */ 
  54.  
  55. function create_options( $field ) 
  56. // defaults? 
  57. $field = array_merge($this->defaults, $field); 
  58.  
  59. // key is needed in the field names to correctly save the data 
  60. $key = $field['name']; 
  61.  
  62.  
  63. // Create Field Options HTML 
  64. ?> 
  65. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  66. <td class="label"> 
  67. <label><?php _e("Autogrow", 'acf-markdown'); ?></label> 
  68. <p class="description"><?php _e("Automatically grow input field to fit it's content.", 'acf-markdown'); ?></p> 
  69. </td> 
  70. <td> 
  71. <?php 
  72.  
  73. do_action('acf/create_field', array( 
  74. 'type' => 'radio',  
  75. 'name' => 'fields['.$key.'][autogrow]',  
  76. 'value' => $field['autogrow'],  
  77. 'layout' => 'horizontal',  
  78. 'choices' => array( 
  79. '1' => __('Yes', 'acf-markdown'),  
  80. '0' => __('No', 'acf-markdown'),  
  81. )); 
  82.  
  83. ?> 
  84. </td> 
  85. </tr> 
  86. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  87. <td class="label"> 
  88. <label><?php _e("Editor Theme", 'acf-markdown'); ?></label> 
  89. <p class="description"><?php _e("Select theme to use for the markdown-editor.", 'acf-markdown'); ?></p> 
  90. </td> 
  91. <td> 
  92. <?php 
  93.  
  94. do_action('acf/create_field', array( 
  95. 'type' => 'select',  
  96. 'name' => 'fields['.$key.'][editor-theme]',  
  97. 'value' => $field['editor-theme'],  
  98. 'choices' => array( 
  99. 'dark' => 'Dark',  
  100. 'light' => 'Light',  
  101. )); 
  102.  
  103. ?> 
  104. </td> 
  105. </tr> 
  106. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  107. <td class="label"> 
  108. <label><?php _e("Preview Theme", 'acf-markdown'); ?></label> 
  109. <p class="description"><?php _e("Select theme to use for the preview.", 'acf-markdown'); ?></p> 
  110. </td> 
  111. <td> 
  112. <?php 
  113.  
  114. do_action('acf/create_field', array( 
  115. 'type' => 'select',  
  116. 'name' => 'fields['.$key.'][preview-theme]',  
  117. 'value' => $field['preview-theme'],  
  118. 'choices' => array( 
  119. 'github' => 'GitHub',  
  120. 'bartik' => 'Bartik',  
  121. 'preview-dark' => 'Dark',  
  122. )); 
  123.  
  124. ?> 
  125. </td> 
  126. </tr> 
  127. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  128. <td class="label"> 
  129. <label><?php _e("Syntax highlighting", 'acf-markdown'); ?></label> 
  130. <p class="description"><?php _e("Activate syntax highlighting for code blocks in preview.", 'acf-markdown'); ?></p> 
  131. </td> 
  132. <td> 
  133. <?php 
  134.  
  135. do_action('acf/create_field', array( 
  136. 'type' => 'radio',  
  137. 'name' => 'fields['.$key.'][syntax-highlight]',  
  138. 'value' => $field['syntax-highlight'],  
  139. 'layout' => 'horizontal',  
  140. 'choices' => array( 
  141. '1' => __('Yes', 'acf-markdown'),  
  142. '0' => __('No', 'acf-markdown'),  
  143. )); 
  144.  
  145. ?> 
  146. </td> 
  147. </tr> 
  148. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  149. <td class="label"> 
  150. <label><?php _e("Syntax Highlighting Theme", 'acf-markdown'); ?></label> 
  151. <p class="description"><?php _e('Select theme to use for syntax highlighting. <a href="https://highlightjs.org/static/test.html" target="_blank">View examples!</a>', 'acf-markdown'); ?></p> 
  152. </td> 
  153. <td> 
  154. <?php 
  155.  
  156. do_action('acf/create_field', array( 
  157. 'type' => 'select',  
  158. 'name' => 'fields['.$key.'][syntax-theme]',  
  159. 'value' => $field['syntax-theme'],  
  160. 'choices' => array( 
  161. 'arta' => 'Arta',  
  162. 'ascetic' => 'Ascetic',  
  163. 'atelier-dune.dark' => 'Atelier Dune - Dark',  
  164. 'atelier-dune.light' => 'Atelier Dune - Light',  
  165. 'atelier-forest.dark' => 'Atelier Forest - Dark',  
  166. 'atelier-forest.light' => 'Atelier Forest - Light',  
  167. 'atelier-heath.dark' => 'Atelier Heath - Dark',  
  168. 'atelier-heath.light' => 'Atelier Heath - Light',  
  169. 'atelier-lakeside.dark' => 'Atelier Lakeside - Dark',  
  170. 'atelier-lakeside.light' => 'Atelier Lakeside - Light',  
  171. 'atelier-seaside.dark' => 'Atelier Seaside - Dark',  
  172. 'atelier-seaside.light' => 'Atelier Seaside - Light',  
  173. 'brown_paper' => 'Brown Paper',  
  174. 'codepen-embed' => 'Codepen.io Embed',  
  175. 'color-brewer' => 'Colorbrewer',  
  176. 'dark' => 'Dark',  
  177. 'default' => 'Default',  
  178. 'docco' => 'Docco',  
  179. 'far' => 'FAR',  
  180. 'foundation' => 'Foundation',  
  181. 'github' => 'GitHub',  
  182. 'googlecode' => 'Google Code',  
  183. 'hybrid' => 'Hybrid',  
  184. 'idea' => 'IDEA',  
  185. 'ir_black' => 'IR Black',  
  186. 'kimbie.dark' => 'Kimbie - Dark',  
  187. 'kimbie.light' => 'Kimbie - Light',  
  188. 'magula' => 'Magula',  
  189. 'mono-blue' => 'Mono Blue',  
  190. 'monokai' => 'Monokai',  
  191. 'monokai_sublime' => 'Monokai Sublime',  
  192. 'obsidian' => 'Obsidian',  
  193. 'paraiso.dark' => 'Paraso - Dark',  
  194. 'paraiso.light' => 'Paraso - Light',  
  195. 'pojoaque' => 'Pojoaque',  
  196. 'railscasts' => 'Railscasts',  
  197. 'rainbow' => 'Rainbow',  
  198. 'school_book' => 'School Book',  
  199. 'solarized_dark' => 'Solarized - Dark',  
  200. 'solarized_light' => 'Solarized - Light',  
  201. 'sunburst' => 'Sunburst',  
  202. 'tomorrow' => 'Tomorrow',  
  203. 'tomorrow-night' => 'Tomorrow Night',  
  204. 'tomorrow-night-blue' => 'Tomorrow Night Blue',  
  205. 'tomorrow-night-bright' => 'Tomorrow Night Bright',  
  206. 'tomorrow-night-eighties' => 'Tomorrow Night Eighties',  
  207. 'vs' => 'Visual Studio',  
  208. 'xcode' => 'XCode',  
  209. 'zenburn' => 'Zenburn',  
  210. )); 
  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("Show Media Upload Buttons?", 'acf-markdown'); ?></label> 
  218. <p class="description"></p> 
  219. </td> 
  220. <td> 
  221. <?php 
  222.  
  223. do_action('acf/create_field', array( 
  224. 'type' => 'radio',  
  225. 'name' => 'fields['.$key.'][media-upload]',  
  226. 'value' => $field['media-upload'],  
  227. 'layout' => 'horizontal',  
  228. 'choices' => array( 
  229. '1' => __('Yes', 'acf-markdown'),  
  230. '0' => __('No', 'acf-markdown'),  
  231. )); 
  232.  
  233. ?> 
  234. </td> 
  235. </tr> 
  236. <?php 
  237.  
  238.  
  239.  
  240. /** 
  241. * create_field() 
  242. * Create the HTML interface for your field 
  243. * @param $field - an array holding all the field's data 
  244. * @type action 
  245. * @since 3.6 
  246. * @date 23/01/13 
  247. */ 
  248.  
  249. function create_field( $field ) 
  250. // defaults? 
  251. $field = array_merge($this->defaults, $field); 
  252.  
  253. $syntaxHighlight = false; 
  254.  
  255. if( $field['syntax-highlight'] == '1' ) { 
  256. $syntaxHighlight = true; 
  257. wp_enqueue_script( 'highlightjs' ); 
  258.  
  259. $id = 'editor_' . uniqid(); 
  260. $textareaId = $id . '_textarea'; 
  261.  
  262.  
  263. wp_localize_script( 'acf-input-markdown', $id, array( 
  264. 'containerId' => $id,  
  265. 'textareaId' => $textareaId,  
  266. 'basePath' => $this->settings['dir'] . "js/lib/EpicEditor-v0.2.2",  
  267. 'autogrow' => ($field['autogrow'] == '1'),  
  268. 'theme' => array( 
  269. 'base' => '/themes/base/epiceditor.css',  
  270. 'preview' => "/themes/preview/" . $field["preview-theme"] . ".css?v=1",  
  271. 'editor' => "/themes/editor/epic-" . $field["editor-theme"] . ".css?v=1" 
  272. ),  
  273. 'syntaxHighlight' => $syntaxHighlight,  
  274. 'syntaxTheme' => $this->settings['dir'] . "js/lib/highlight/styles/" . $field['syntax-theme'] . ".css",  
  275. //'tabFunction' => $field['tab-function'] 
  276. )); 
  277.  
  278. wp_enqueue_script( 'acf-input-markdown' ); 
  279. ?> 
  280. <?php if( $field['media-upload'] ) { ?> 
  281. <input type="hidden" name="wp-<?php echo $id; ?>-media-input" id="wp-<?php echo $id; ?>-media-input" class="wp-media-input" /> 
  282. <div id="wp-<?php echo $id; ?>-media-button" class="wp-media-buttons"> 
  283. <?php do_action( 'media_buttons' ); ?> 
  284. </div> 
  285. <?php } ?> 
  286. <input type="hidden" name="<?php echo $field['name']; ?>" id="<?php echo $textareaId; ?>" value="<?php echo $field['value']; ?>" /> 
  287. <div id="<?php echo $id; ?>" data-acf-markdown-editor></div> 
  288. <?php 
  289.  
  290.  
  291. /** 
  292. * input_admin_enqueue_scripts() 
  293. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is created. 
  294. * Use this action to add CSS + JavaScript to assist your create_field() action. 
  295. * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts 
  296. * @type action 
  297. * @since 3.6 
  298. * @date 23/01/13 
  299. */ 
  300.  
  301. function input_admin_enqueue_scripts() 
  302. // Note: This function can be removed if not used 
  303.  
  304. // register ACF scripts 
  305. wp_register_script( 'epiceditor', $this->settings['dir'] . 'js/lib/EpicEditor-v0.2.2/js/epiceditor.min.js', array(), '0.2.2' ); 
  306. wp_register_script( 'acf-input-markdown', $this->settings['dir'] . 'js/input.js', array( 'epiceditor', 'acf-input' ), $this->settings['version'] ); 
  307. wp_register_script( 'highlightjs', $this->settings['dir'] . 'js/lib/highlight/highlight.pack.js', array(), $this->settings['version'] ); 
  308.  
  309. wp_enqueue_script( 'epiceditor' ); 
  310.  
  311. wp_enqueue_media(); 
  312.  
  313. // register & include CSS 
  314. wp_register_style( 'acf-input-markdown', "{$dir}css/input.css", array(), $this->settings['version'] ); 
  315. wp_enqueue_style( 'acf-input-markdown' ); 
  316.  
  317.  
  318. /** 
  319. * input_admin_head() 
  320. * This action is called in the admin_head action on the edit screen where your field is created. 
  321. * Use this action to add CSS and JavaScript to assist your create_field() action. 
  322. * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head 
  323. * @type action 
  324. * @since 3.6 
  325. * @date 23/01/13 
  326. */ 
  327.  
  328. function input_admin_head() 
  329. // Note: This function can be removed if not used 
  330.  
  331.  
  332. /** 
  333. * field_group_admin_enqueue_scripts() 
  334. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited. 
  335. * Use this action to add CSS + JavaScript to assist your create_field_options() action. 
  336. * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts 
  337. * @type action 
  338. * @since 3.6 
  339. * @date 23/01/13 
  340. */ 
  341.  
  342. function field_group_admin_enqueue_scripts() 
  343. // Note: This function can be removed if not used 
  344.  
  345.  
  346. /** 
  347. * field_group_admin_head() 
  348. * This action is called in the admin_head action on the edit screen where your field is edited. 
  349. * Use this action to add CSS and JavaScript to assist your create_field_options() action. 
  350. * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head 
  351. * @type action 
  352. * @since 3.6 
  353. * @date 23/01/13 
  354. */ 
  355.  
  356. function field_group_admin_head() 
  357. // Note: This function can be removed if not used 
  358.  
  359.  
  360. /** 
  361. * load_value() 
  362. * This filter is applied to the $value after it is loaded from the db 
  363. * @type filter 
  364. * @since 3.6 
  365. * @date 23/01/13 
  366. * @param $value - the value found in the database 
  367. * @param $post_id - the $post_id from which the value was loaded 
  368. * @param $field - the field array holding all the field options 
  369. * @return $value - the value to be saved in the database 
  370. */ 
  371.  
  372. function load_value( $value, $post_id, $field ) 
  373. // Note: This function can be removed if not used 
  374. return $value; 
  375.  
  376.  
  377. /** 
  378. * update_value() 
  379. * This filter is applied to the $value before it is updated in the db 
  380. * @type filter 
  381. * @since 3.6 
  382. * @date 23/01/13 
  383. * @param $value - the value which will be saved in the database 
  384. * @param $post_id - the $post_id of which the value will be saved 
  385. * @param $field - the field array holding all the field options 
  386. * @return $value - the modified value 
  387. */ 
  388.  
  389. function update_value( $value, $post_id, $field ) 
  390. // Note: This function can be removed if not used 
  391. return $value; 
  392.  
  393.  
  394. /** 
  395. * format_value() 
  396. * This filter is applied to the $value after it is loaded from the db and before it is passed to the create_field action 
  397. * @type filter 
  398. * @since 3.6 
  399. * @date 23/01/13 
  400. * @param $value - the value which was loaded from the database 
  401. * @param $post_id - the $post_id from which the value was loaded 
  402. * @param $field - the field array holding all the field options 
  403. * @return $value - the modified value 
  404. */ 
  405.  
  406. function format_value( $value, $post_id, $field ) 
  407. // defaults? 
  408. /** 
  409. $field = array_merge($this->defaults, $field); 
  410. */ 
  411.  
  412. // perhaps use $field['preview_size'] to alter the $value? 
  413.  
  414.  
  415. // Note: This function can be removed if not used 
  416. return $value; 
  417.  
  418.  
  419. /** 
  420. * format_value_for_api() 
  421. * This filter is applied to the $value after it is loaded from the db and before it is passed back to the API functions such as the_field 
  422. * @type filter 
  423. * @since 3.6 
  424. * @date 23/01/13 
  425. * @param $value - the value which was loaded from the database 
  426. * @param $post_id - the $post_id from which the value was loaded 
  427. * @param $field - the field array holding all the field options 
  428. * @return $value - the modified value 
  429. */ 
  430.  
  431. function format_value_for_api( $value, $post_id, $field ) 
  432. // defaults? 
  433. /** 
  434. $field = array_merge($this->defaults, $field); 
  435. */ 
  436.  
  437. // perhaps use $field['preview_size'] to alter the $value? 
  438.  
  439.  
  440. // Note: This function can be removed if not used 
  441. return $value; 
  442.  
  443.  
  444. /** 
  445. * load_field() 
  446. * This filter is applied to the $field after it is loaded from the database 
  447. * @type filter 
  448. * @since 3.6 
  449. * @date 23/01/13 
  450. * @param $field - the field array holding all the field options 
  451. * @return $field - the field array holding all the field options 
  452. */ 
  453.  
  454. function load_field( $field ) 
  455. // Note: This function can be removed if not used 
  456. return $field; 
  457.  
  458.  
  459. /** 
  460. * update_field() 
  461. * This filter is applied to the $field before it is saved to the database 
  462. * @type filter 
  463. * @since 3.6 
  464. * @date 23/01/13 
  465. * @param $field - the field array holding all the field options 
  466. * @param $post_id - the field group ID (post_type = acf) 
  467. * @return $field - the modified field 
  468. */ 
  469.  
  470. function update_field( $field, $post_id ) 
  471. // Note: This function can be removed if not used 
  472. return $field; 
  473.  
  474.  
/acf-markdown-v5.php  
  1. class acf_field_markdown extends acf_field { 
  2.  
  3.  
  4. /** 
  5. * __construct 
  6. * This function will setup the field type data 
  7. * @type function 
  8. * @date 5/03/2014 
  9. * @since 5.0.0 
  10. * @param n/a 
  11. * @return n/a 
  12. */ 
  13.  
  14. function __construct() { 
  15.  
  16. /** 
  17. * name (string) Single word, no spaces. Underscores allowed 
  18. */ 
  19.  
  20. $this->name = 'markdown'; 
  21.  
  22.  
  23. /** 
  24. * label (string) Multiple words, can include spaces, visible when selecting a field type 
  25. */ 
  26.  
  27. $this->label = __('Markdown', 'acf-markdown'); 
  28.  
  29.  
  30. /** 
  31. * category (string) basic | content | choice | relational | jquery | layout | CUSTOM GROUP NAME 
  32. */ 
  33.  
  34. $this->category = 'basic'; 
  35.  
  36.  
  37. /** 
  38. * defaults (array) Array of default settings which are merged into the field object. These are used later in settings 
  39. */ 
  40.  
  41. $this->defaults = array( 
  42. 'autogrow' => '1',  
  43. //'sidebyside' => '1',  
  44. 'editor-theme' => 'dark',  
  45. 'preview-theme' => 'github',  
  46. 'syntax-highlight' => '0',  
  47. 'syntax-theme' => 'monokai_sublime',  
  48. 'tab-function' => '0',  
  49. 'media-upload' => '0' 
  50. ); 
  51.  
  52.  
  53. /** 
  54. * l10n (array) Array of strings that are used in JavaScript. This allows JS strings to be translated in PHP and loaded via: 
  55. * var message = acf._e('markdown', 'error'); 
  56. */ 
  57.  
  58. $this->l10n = array( 
  59. //'error' => __('Error! Please enter a higher value', 'acf-markdown'),  
  60. ); 
  61.  
  62.  
  63. // do not delete! 
  64. parent::__construct(); 
  65.  
  66.  
  67.  
  68. /** 
  69. * render_field_settings() 
  70. * Create extra settings for your field. These are visible when editing a field 
  71. * @type action 
  72. * @since 3.6 
  73. * @date 23/01/13 
  74. * @param $field (array) the $field being edited 
  75. * @return n/a 
  76. */ 
  77.  
  78. function render_field_settings( $field ) { 
  79.  
  80. /** 
  81. * acf_render_field_setting 
  82. * This function will create a setting for your field. Simply pass the $field parameter and an array of field settings. 
  83. * The array of settings does not require a `value` or `prefix`; These settings are found from the $field array. 
  84. * More than one setting can be added by copy/paste the above code. 
  85. * Please note that you must also have a matching $defaults value for the field name (font_size) 
  86. */ 
  87.  
  88. /**acf_render_field_setting( $field, array( 
  89. 'label' => __('Font Size', 'acf-markdown'),  
  90. 'instructions' => __('Customise the input font size', 'acf-markdown'),  
  91. 'type' => 'number',  
  92. 'name' => 'font_size',  
  93. 'prepend' => 'px',  
  94. ));*/ 
  95.  
  96. acf_render_field_setting( $field, array( 
  97. 'label' => __('Autogrow', 'acf-markdown'),  
  98. 'instructions' => __('Automatically grow input field to fit it\'s content.', 'acf-markdown'),  
  99. 'type' => 'radio',  
  100. 'name' => 'autogrow',  
  101. 'layout' => 'horizontal',  
  102. 'choices' => array( 
  103. '1' => __('Yes', 'acf-markdown'),  
  104. '0' => __('No', 'acf-markdown'),  
  105. )); 
  106.  
  107. /**acf_render_field_setting( $field, array( 
  108. 'label' => __('Side-by-side preview', 'acf-markdown'),  
  109. 'instructions' => __('Show preview side-by-side with the input field.', 'acf-markdown'),  
  110. 'type' => 'radio',  
  111. 'name' => 'sidebyside',  
  112. 'layout' => 'horizontal',  
  113. 'choices' => array( 
  114. '1' => __('Yes', 'acf-markdown'),  
  115. '0' => __('No', 'acf-markdown'),  
  116. ));*/ 
  117.  
  118. acf_render_field_setting( $field, array( 
  119. 'label' => __('Editor Theme', 'acf-markdown'),  
  120. 'instructions' => __('Select theme to use for the markdown-editor.', 'acf-markdown'),  
  121. 'type' => 'select',  
  122. 'name' => 'editor-theme',  
  123. 'choices' => array( 
  124. 'dark' => 'Dark',  
  125. 'light' => 'Light',  
  126. )); 
  127.  
  128. acf_render_field_setting( $field, array( 
  129. 'label' => __('Preview Theme', 'acf-markdown'),  
  130. 'instructions' => __('Select theme to use for the preview.', 'acf-markdown'),  
  131. 'type' => 'select',  
  132. 'name' => 'preview-theme',  
  133. 'choices' => array( 
  134. 'github' => 'GitHub',  
  135. 'bartik' => 'Bartik',  
  136. 'preview-dark' => 'Dark',  
  137. )); 
  138.  
  139. acf_render_field_setting( $field, array( 
  140. 'label' => __('Syntax highlighting', 'acf-markdown'),  
  141. 'instructions' => __('Activate syntax highlighting for code blocks in preview.', 'acf-markdown'),  
  142. 'type' => 'radio',  
  143. 'name' => 'syntax-highlight',  
  144. 'layout' => 'horizontal',  
  145. 'choices' => array( 
  146. '1' => __('Yes', 'acf-markdown'),  
  147. '0' => __('No', 'acf-markdown'),  
  148. )); 
  149.  
  150. acf_render_field_setting( $field, array( 
  151. 'label' => __('Syntax Highlighting Theme', 'acf-markdown'),  
  152. 'instructions' => __('Select theme to use for syntax highlighting. <a href="https://highlightjs.org/static/test.html" target="_blank">View examples!</a>', 'acf-markdown'),  
  153. 'type' => 'select',  
  154. 'name' => 'syntax-theme',  
  155. 'choices' => array( 
  156. 'arta' => 'Arta',  
  157. 'ascetic' => 'Ascetic',  
  158. 'atelier-dune.dark' => 'Atelier Dune - Dark',  
  159. 'atelier-dune.light' => 'Atelier Dune - Light',  
  160. 'atelier-forest.dark' => 'Atelier Forest - Dark',  
  161. 'atelier-forest.light' => 'Atelier Forest - Light',  
  162. 'atelier-heath.dark' => 'Atelier Heath - Dark',  
  163. 'atelier-heath.light' => 'Atelier Heath - Light',  
  164. 'atelier-lakeside.dark' => 'Atelier Lakeside - Dark',  
  165. 'atelier-lakeside.light' => 'Atelier Lakeside - Light',  
  166. 'atelier-seaside.dark' => 'Atelier Seaside - Dark',  
  167. 'atelier-seaside.light' => 'Atelier Seaside - Light',  
  168. 'brown_paper' => 'Brown Paper',  
  169. 'codepen-embed' => 'Codepen.io Embed',  
  170. 'color-brewer' => 'Colorbrewer',  
  171. 'dark' => 'Dark',  
  172. 'default' => 'Default',  
  173. 'docco' => 'Docco',  
  174. 'far' => 'FAR',  
  175. 'foundation' => 'Foundation',  
  176. 'github' => 'GitHub',  
  177. 'googlecode' => 'Google Code',  
  178. 'hybrid' => 'Hybrid',  
  179. 'idea' => 'IDEA',  
  180. 'ir_black' => 'IR Black',  
  181. 'kimbie.dark' => 'Kimbie - Dark',  
  182. 'kimbie.light' => 'Kimbie - Light',  
  183. 'magula' => 'Magula',  
  184. 'mono-blue' => 'Mono Blue',  
  185. 'monokai' => 'Monokai',  
  186. 'monokai_sublime' => 'Monokai Sublime',  
  187. 'obsidian' => 'Obsidian',  
  188. 'paraiso.dark' => 'Paraso - Dark',  
  189. 'paraiso.light' => 'Paraso - Light',  
  190. 'pojoaque' => 'Pojoaque',  
  191. 'railscasts' => 'Railscasts',  
  192. 'rainbow' => 'Rainbow',  
  193. 'school_book' => 'School Book',  
  194. 'solarized_dark' => 'Solarized - Dark',  
  195. 'solarized_light' => 'Solarized - Light',  
  196. 'sunburst' => 'Sunburst',  
  197. 'tomorrow' => 'Tomorrow',  
  198. 'tomorrow-night' => 'Tomorrow Night',  
  199. 'tomorrow-night-blue' => 'Tomorrow Night Blue',  
  200. 'tomorrow-night-bright' => 'Tomorrow Night Bright',  
  201. 'tomorrow-night-eighties' => 'Tomorrow Night Eighties',  
  202. 'vs' => 'Visual Studio',  
  203. 'xcode' => 'XCode',  
  204. 'zenburn' => 'Zenburn',  
  205. )); 
  206.  
  207. // media-upload 
  208. acf_render_field_setting( $field, array( 
  209. 'label' => __('Show Media Upload Buttons?', 'acf-markdown'),  
  210. 'instructions' => '',  
  211. 'type' => 'radio',  
  212. 'name' => 'media-upload',  
  213. 'layout' => 'horizontal',  
  214. 'choices' => array( 
  215. 1 => __("Yes", 'acf'),  
  216. 0 => __("No", 'acf'),  
  217. )); 
  218.  
  219. /**acf_render_field_setting( $field, array( 
  220. 'label' => __('Tab Key', 'acf-markdown'),  
  221. 'instructions' => __('What does the tab-key to do when the editor is focused?', 'acf-markdown'),  
  222. 'type' => 'select',  
  223. 'name' => 'tab-function',  
  224. 'choices' => array( 
  225. '0' => __('Normal functionality', 'acf-markdown'),  
  226. '2' => __('Insert 2 spaces', 'acf-markdown'),  
  227. '4' => __('Insert 4 spaces', 'acf-markdown'),  
  228. ));*/ 
  229.  
  230. /** 
  231. * render_field() 
  232. * Create the HTML interface for your field 
  233. * @param $field (array) the $field being rendered 
  234. * @type action 
  235. * @since 3.6 
  236. * @date 23/01/13 
  237. * @param $field (array) the $field being edited 
  238. * @return n/a 
  239. */ 
  240.  
  241. function render_field( $field ) { 
  242.  
  243. $dir = plugin_dir_url( __FILE__ ); 
  244.  
  245. /** 
  246. * Review the data of $field. 
  247. * This will show what data is available 
  248. */ 
  249.  
  250. /**echo '<pre>'; 
  251. print_r( $field ); 
  252. echo '</pre>';*/ 
  253. $syntaxHighlight = false; 
  254.  
  255. if( $field['syntax-highlight'] == '1' ) { 
  256. $syntaxHighlight = true; 
  257. wp_enqueue_script( 'highlightjs' ); 
  258.  
  259. $id = 'editor_' . uniqid(); 
  260. $textareaId = $id . '_textarea'; 
  261.  
  262. acf_hidden_input(array( 
  263. 'type' => 'hidden',  
  264. 'name' => $field['name'],  
  265. 'id' => $textareaId,  
  266. 'value' => $field['value'] 
  267. )); 
  268.  
  269. wp_localize_script( 'acf-input-markdown', $id, array( 
  270. 'containerId' => $id,  
  271. 'textareaId' => $textareaId,  
  272. 'basePath' => "{$dir}js/lib/EpicEditor-v0.2.2",  
  273. 'autogrow' => ($field['autogrow'] == '1'),  
  274. 'theme' => array( 
  275. 'base' => '/themes/base/epiceditor.css',  
  276. 'preview' => "/themes/preview/" . $field["preview-theme"] . ".css?v=1",  
  277. 'editor' => "/themes/editor/epic-" . $field["editor-theme"] . ".css?v=1" 
  278. ),  
  279. 'syntaxHighlight' => $syntaxHighlight,  
  280. 'syntaxTheme' => "{$dir}js/lib/highlight/styles/" . $field['syntax-theme'] . ".css",  
  281. //'tabFunction' => $field['tab-function'] 
  282. )); 
  283.  
  284. if( $field['media-upload'] ) { 
  285. acf_hidden_input(array( 
  286. 'type' => 'hidden',  
  287. 'name' => 'wp-' . $id . '-media-input',  
  288. 'id' => 'wp-' . $id . '-media-input',  
  289. 'class' => 'wp-media-input' 
  290. )); 
  291.  
  292. wp_enqueue_script( 'acf-input-markdown' ); 
  293. ?> 
  294. <?php if( $field['media-upload'] ) { ?> 
  295. <div id="wp-<?php echo $id; ?>-media-button" class="wp-media-buttons"> 
  296. <?php do_action( 'media_buttons' ); ?> 
  297. </div> 
  298. <?php } ?> 
  299. <div id="<?php echo $id; ?>" data-acf-markdown-editor class="acf-field-markdown-editor"></div> 
  300. <?php 
  301.  
  302.  
  303. /** 
  304. * input_admin_enqueue_scripts() 
  305. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is created. 
  306. * Use this action to add CSS + JavaScript to assist your render_field() action. 
  307. * @type action (admin_enqueue_scripts) 
  308. * @since 3.6 
  309. * @date 23/01/13 
  310. * @param n/a 
  311. * @return n/a 
  312. */ 
  313.  
  314. function input_admin_enqueue_scripts() { 
  315.  
  316. $dir = plugin_dir_url( __FILE__ ); 
  317.  
  318.  
  319. // register & include JS 
  320. wp_register_script( 'epiceditor', "{$dir}js/lib/EpicEditor-v0.2.2/js/epiceditor.js" ); 
  321. wp_register_script( 'acf-input-markdown', "{$dir}js/input.js", array( 'epiceditor' ), '1.1.4'); 
  322. wp_register_script( 'highlightjs', "{$dir}js/lib/highlight/highlight.pack.js" ); 
  323.  
  324. wp_enqueue_script( 'epiceditor' ); 
  325.  
  326. wp_enqueue_media(); 
  327.  
  328. // register & include CSS 
  329. wp_register_style( 'acf-input-markdown', "{$dir}css/input.css", array(), '1.1.4' ); 
  330. wp_enqueue_style( 'acf-input-markdown' ); 
  331.  
  332.  
  333. /** 
  334. * input_admin_head() 
  335. * This action is called in the admin_head action on the edit screen where your field is created. 
  336. * Use this action to add CSS and JavaScript to assist your render_field() action. 
  337. * @type action (admin_head) 
  338. * @since 3.6 
  339. * @date 23/01/13 
  340. * @param n/a 
  341. * @return n/a 
  342. */ 
  343.  
  344. /** 
  345.   
  346. function input_admin_head() { 
  347.   
  348.   
  349.   
  350.   
  351. */ 
  352.  
  353.  
  354. /** 
  355. * input_form_data() 
  356. * This function is called once on the 'input' page between the head and footer 
  357. * There are 2 situations where ACF did not load during the 'acf/input_admin_enqueue_scripts' and 
  358. * 'acf/input_admin_head' actions because ACF did not know it was going to be used. These situations are 
  359. * seen on comments / user edit forms on the front end. This function will always be called, and includes 
  360. * $args that related to the current screen such as $args['post_id'] 
  361. * @type function 
  362. * @date 6/03/2014 
  363. * @since 5.0.0 
  364. * @param $args (array) 
  365. * @return n/a 
  366. */ 
  367.  
  368. /** 
  369.   
  370. function input_form_data( $args ) { 
  371.   
  372.   
  373.   
  374.   
  375. */ 
  376.  
  377.  
  378. /** 
  379. * input_admin_footer() 
  380. * This action is called in the admin_footer action on the edit screen where your field is created. 
  381. * Use this action to add CSS and JavaScript to assist your render_field() action. 
  382. * @type action (admin_footer) 
  383. * @since 3.6 
  384. * @date 23/01/13 
  385. * @param n/a 
  386. * @return n/a 
  387. */ 
  388.  
  389. /** 
  390.   
  391. function input_admin_footer() { 
  392.   
  393.   
  394.   
  395.   
  396. */ 
  397.  
  398.  
  399. /** 
  400. * field_group_admin_enqueue_scripts() 
  401. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited. 
  402. * Use this action to add CSS + JavaScript to assist your render_field_options() action. 
  403. * @type action (admin_enqueue_scripts) 
  404. * @since 3.6 
  405. * @date 23/01/13 
  406. * @param n/a 
  407. * @return n/a 
  408. */ 
  409.  
  410. /** 
  411.   
  412. function field_group_admin_enqueue_scripts() { 
  413.   
  414.   
  415. */ 
  416.  
  417.  
  418. /** 
  419. * field_group_admin_head() 
  420. * This action is called in the admin_head action on the edit screen where your field is edited. 
  421. * Use this action to add CSS and JavaScript to assist your render_field_options() action. 
  422. * @type action (admin_head) 
  423. * @since 3.6 
  424. * @date 23/01/13 
  425. * @param n/a 
  426. * @return n/a 
  427. */ 
  428.  
  429. /** 
  430.   
  431. function field_group_admin_head() { 
  432.   
  433.   
  434. */ 
  435.  
  436.  
  437. /** 
  438. * load_value() 
  439. * This filter is applied to the $value after it is loaded from the db 
  440. * @type filter 
  441. * @since 3.6 
  442. * @date 23/01/13 
  443. * @param $value (mixed) the value found in the database 
  444. * @param $post_id (mixed) the $post_id from which the value was loaded 
  445. * @param $field (array) the field array holding all the field options 
  446. * @return $value 
  447. */ 
  448.  
  449. /** 
  450.   
  451. function load_value( $value, $post_id, $field ) { 
  452.   
  453. return $value; 
  454.   
  455.   
  456. */ 
  457.  
  458.  
  459. /** 
  460. * update_value() 
  461. * This filter is applied to the $value before it is saved in the db 
  462. * @type filter 
  463. * @since 3.6 
  464. * @date 23/01/13 
  465. * @param $value (mixed) the value found in the database 
  466. * @param $post_id (mixed) the $post_id from which the value was loaded 
  467. * @param $field (array) the field array holding all the field options 
  468. * @return $value 
  469. */ 
  470.  
  471. /** 
  472.   
  473. function update_value( $value, $post_id, $field ) { 
  474.   
  475. return $value; 
  476.   
  477.   
  478. */ 
  479.  
  480.  
  481. /** 
  482. * format_value() 
  483. * This filter is appied to the $value after it is loaded from the db and before it is returned to the template 
  484. * @type filter 
  485. * @since 3.6 
  486. * @date 23/01/13 
  487. * @param $value (mixed) the value which was loaded from the database 
  488. * @param $post_id (mixed) the $post_id from which the value was loaded 
  489. * @param $field (array) the field array holding all the field options 
  490. * @return $value (mixed) the modified value 
  491. */ 
  492.  
  493. /** 
  494.   
  495. function format_value( $value, $post_id, $field ) { 
  496.   
  497. // bail early if no value 
  498. if( empty($value) ) { 
  499.   
  500. return $value; 
  501.   
  502.   
  503.   
  504. // apply setting 
  505. if( $field['font_size'] > 12 ) { 
  506.   
  507. // format the value 
  508. // $value = 'something'; 
  509.   
  510.   
  511.   
  512. // return 
  513. return $value; 
  514.   
  515. */ 
  516.  
  517.  
  518. /** 
  519. * validate_value() 
  520. * This filter is used to perform validation on the value prior to saving. 
  521. * All values are validated regardless of the field's required setting. This allows you to validate and return 
  522. * messages to the user if the value is not correct 
  523. * @type filter 
  524. * @date 11/02/2014 
  525. * @since 5.0.0 
  526. * @param $valid (boolean) validation status based on the value and the field's required setting 
  527. * @param $value (mixed) the $_POST value 
  528. * @param $field (array) the field array holding all the field options 
  529. * @param $input (string) the corresponding input name for $_POST value 
  530. * @return $valid 
  531. */ 
  532.  
  533. /** 
  534.   
  535. function validate_value( $valid, $value, $field, $input ) { 
  536.   
  537. // Basic usage 
  538. if( $value < $field['custom_minimum_setting'] ) 
  539. $valid = false; 
  540.   
  541.   
  542. // Advanced usage 
  543. if( $value < $field['custom_minimum_setting'] ) 
  544. $valid = __('The value is too little!', 'acf-markdown'),  
  545.   
  546.   
  547. // return 
  548. return $valid; 
  549.   
  550.   
  551. */ 
  552.  
  553.  
  554. /** 
  555. * delete_value() 
  556. * This action is fired after a value has been deleted from the db. 
  557. * Please note that saving a blank value is treated as an update, not a delete 
  558. * @type action 
  559. * @date 6/03/2014 
  560. * @since 5.0.0 
  561. * @param $post_id (mixed) the $post_id from which the value was deleted 
  562. * @param $key (string) the $meta_key which the value was deleted 
  563. * @return n/a 
  564. */ 
  565.  
  566. /** 
  567.   
  568. function delete_value( $post_id, $key ) { 
  569.   
  570.   
  571.   
  572.   
  573. */ 
  574.  
  575.  
  576. /** 
  577. * load_field() 
  578. * This filter is applied to the $field after it is loaded from the database 
  579. * @type filter 
  580. * @date 23/01/2013 
  581. * @since 3.6.0 
  582. * @param $field (array) the field array holding all the field options 
  583. * @return $field 
  584. */ 
  585.  
  586. /** 
  587.   
  588. function load_field( $field ) { 
  589.   
  590. return $field; 
  591.   
  592.   
  593. */ 
  594.  
  595.  
  596. /** 
  597. * update_field() 
  598. * This filter is applied to the $field before it is saved to the database 
  599. * @type filter 
  600. * @date 23/01/2013 
  601. * @since 3.6.0 
  602. * @param $field (array) the field array holding all the field options 
  603. * @return $field 
  604. */ 
  605.  
  606. /** 
  607.   
  608. function update_field( $field ) { 
  609.   
  610. return $field; 
  611.   
  612.   
  613. */ 
  614.  
  615.  
  616. /** 
  617. * delete_field() 
  618. * This action is fired after a field is deleted from the database 
  619. * @type action 
  620. * @date 11/02/2014 
  621. * @since 5.0.0 
  622. * @param $field (array) the field array holding all the field options 
  623. * @return n/a 
  624. */ 
  625.  
  626. /** 
  627.   
  628. function delete_field( $field ) { 
  629.   
  630.   
  631.   
  632.   
  633. */ 
  634.  
  635.