PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / trunk
Pods – Custom Content Types and Fields vtrunk
trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / components / Markdown.php
pods / components Last commit date
I18n 4 months ago Migrate-ACF 4 months ago Migrate-CPTUI 4 months ago Migrate-PHP 3 months ago Migrate-Packages 4 months ago Roles 4 months ago Templates 4 months ago Advanced-Content-Types.php 4 months ago Advanced-Relationships.php 4 months ago Markdown.php 4 months ago Pages.php 4 months ago Table-Storage.php 4 months ago
Markdown.php
83 lines
1 <?php
2
3 // Don't load directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 die( '-1' );
6 }
7
8 /**
9 * ID: markdown-syntax
10 *
11 * Name: Markdown Syntax
12 *
13 * Description: Integration with Markdown (via Parsedown https://github.com/erusev/parsedown); Adds an option to enable Markdown syntax for Paragraph Text and WYSIWYG fields.
14 *
15 * Version: 2.0
16 *
17 * Category: Field Types
18 *
19 * @package Pods\Components
20 * @subpackage Markdown
21 */
22
23 add_filter( 'pods_form_ui_field_paragraph_display_value_pre_process', 'pods_markdown_maybe_parse_field_display_value', 10, 4 );
24 add_filter( 'pods_form_ui_field_wysiwyg_display_value_pre_process', 'pods_markdown_maybe_parse_field_display_value', 10, 4 );
25
26 /**
27 * Maybe parse Markdown for a field display value.
28 *
29 * @since 3.1.0
30 *
31 * @param mixed|null $value Current value.
32 * @param string $type Field type.
33 * @param string|null $name Field name.
34 * @param array|null $options Field options.
35 *
36 * @return mixed|null The parsed value if markdown is enabled, otherwise the value as it was originally passed.
37 */
38 function pods_markdown_maybe_parse_field_display_value(
39 $value,
40 $type,
41 $name = null,
42 $options = null
43 ) {
44 if ( ! class_exists( 'Pods__Prefixed__Parsedown' ) || 1 !== (int) pods_v( $type . '_allow_markdown', $options ) ) {
45 return $value;
46 }
47
48 $parsedown = new Pods__Prefixed__Parsedown();
49 $parsedown->setSafeMode( true );
50
51 return $parsedown->text( $value );
52 }
53
54 add_filter( 'pods_admin_setup_edit_paragraph_additional_field_options', 'pods_markdown_maybe_add_field_display_option', 10, 2 );
55 add_filter( 'pods_admin_setup_edit_wysiwyg_additional_field_options', 'pods_markdown_maybe_add_field_display_option', 10, 2 );
56
57 /**
58 * Maybe add field display option for Markdown.
59 *
60 * @since 3.1.0
61 *
62 * @param array $type_options The additional field type options.
63 * @param string $type Field type.
64 *
65 * @return array The additional field type options.
66 */
67 function pods_markdown_maybe_add_field_display_option(
68 $type_options,
69 $type
70 ) {
71 if ( ! class_exists( 'Pods__Prefixed__Parsedown' ) || ! isset( $type_options['output_options']['boolean_group'] ) ) {
72 return $type_options;
73 }
74
75 $type_options['output_options']['boolean_group'][ $type . '_allow_markdown' ] = [
76 'label' => __( 'Allow Markdown Syntax', 'pods' ),
77 'default' => 0,
78 'type' => 'boolean',
79 ];
80
81 return $type_options;
82 }
83