Builder
3 years ago
I18n
3 years ago
Migrate-ACF
3 years ago
Migrate-CPTUI
3 years ago
Migrate-Packages
2 years ago
Roles
4 years ago
Templates
2 years ago
Advanced-Content-Types.php
3 years ago
Advanced-Relationships.php
3 years ago
Markdown.php
2 years ago
Pages.php
3 years ago
Table-Storage.php
4 years ago
Markdown.php
77 lines
| 1 | <?php |
| 2 | /** |
| 3 | * ID: markdown-syntax |
| 4 | * |
| 5 | * Name: Markdown Syntax |
| 6 | * |
| 7 | * Description: Integration with Markdown (via Parsedown https://github.com/erusev/parsedown); Adds an option to enable Markdown syntax for Paragraph Text and WYSIWYG fields. |
| 8 | * |
| 9 | * Version: 2.0 |
| 10 | * |
| 11 | * Category: Field Types |
| 12 | * |
| 13 | * @package Pods\Components |
| 14 | * @subpackage Markdown |
| 15 | */ |
| 16 | |
| 17 | add_filter( 'pods_form_ui_field_paragraph_display_value_pre_process', 'pods_markdown_maybe_parse_field_display_value', 10, 4 ); |
| 18 | add_filter( 'pods_form_ui_field_wysiwyg_display_value_pre_process', 'pods_markdown_maybe_parse_field_display_value', 10, 4 ); |
| 19 | |
| 20 | /** |
| 21 | * Maybe parse Markdown for a field display value. |
| 22 | * |
| 23 | * @since 3.1.0 |
| 24 | * |
| 25 | * @param mixed|null $value Current value. |
| 26 | * @param string $type Field type. |
| 27 | * @param string|null $name Field name. |
| 28 | * @param array|null $options Field options. |
| 29 | * |
| 30 | * @return mixed|null The parsed value if markdown is enabled, otherwise the value as it was originally passed. |
| 31 | */ |
| 32 | function pods_markdown_maybe_parse_field_display_value( |
| 33 | $value, |
| 34 | $type, |
| 35 | $name = null, |
| 36 | $options = null |
| 37 | ) { |
| 38 | if ( ! class_exists( 'Pods__Prefixed__Parsedown' ) || 1 !== (int) pods_v( $type . '_allow_markdown', $options ) ) { |
| 39 | return $value; |
| 40 | } |
| 41 | |
| 42 | $parsedown = new Pods__Prefixed__Parsedown(); |
| 43 | $parsedown->setSafeMode( true ); |
| 44 | |
| 45 | return $parsedown->text( $value ); |
| 46 | } |
| 47 | |
| 48 | add_filter( 'pods_admin_setup_edit_paragraph_additional_field_options', 'pods_markdown_maybe_add_field_display_option', 10, 2 ); |
| 49 | add_filter( 'pods_admin_setup_edit_wysiwyg_additional_field_options', 'pods_markdown_maybe_add_field_display_option', 10, 2 ); |
| 50 | |
| 51 | /** |
| 52 | * Maybe add field display option for Markdown. |
| 53 | * |
| 54 | * @since 3.1.0 |
| 55 | * |
| 56 | * @param array $type_options The additional field type options. |
| 57 | * @param string $type Field type. |
| 58 | * |
| 59 | * @return array The additional field type options. |
| 60 | */ |
| 61 | function pods_markdown_maybe_add_field_display_option( |
| 62 | $type_options, |
| 63 | $type |
| 64 | ) { |
| 65 | if ( ! class_exists( 'Pods__Prefixed__Parsedown' ) || ! isset( $type_options['output_options']['boolean_group'] ) ) { |
| 66 | return $type_options; |
| 67 | } |
| 68 | |
| 69 | $type_options['output_options']['boolean_group'][ $type . '_allow_markdown' ] = [ |
| 70 | 'label' => __( 'Allow Markdown Syntax', 'pods' ), |
| 71 | 'default' => 0, |
| 72 | 'type' => 'boolean', |
| 73 | ]; |
| 74 | |
| 75 | return $type_options; |
| 76 | } |
| 77 |