PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.3.9.2
Pods – Custom Content Types and Fields v3.3.9.2
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 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 / classes / fields / slug.php
pods / classes / fields Last commit date
avatar.php 2 days ago boolean.php 2 days ago code.php 2 days ago color.php 2 days ago comment.php 2 days ago currency.php 2 days ago date.php 2 days ago datetime.php 2 days ago email.php 2 days ago file.php 2 days ago heading.php 2 days ago html.php 2 days ago link.php 2 days ago number.php 2 days ago oembed.php 2 days ago paragraph.php 2 days ago password.php 2 days ago phone.php 2 days ago pick.php 2 days ago slug.php 2 days ago taxonomy.php 2 days ago text.php 2 days ago time.php 2 days ago website.php 2 days ago wysiwyg.php 2 days ago
slug.php
131 lines
1 <?php
2
3 // Don't load directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 die( '-1' );
6 }
7
8 /**
9 * @package Pods\Fields
10 */
11 class PodsField_Slug extends PodsField {
12
13 /**
14 * {@inheritdoc}
15 */
16 public static $type = 'slug';
17
18 /**
19 * {@inheritdoc}
20 */
21 public static $label = 'Permalink (url-friendly)';
22
23 /**
24 * {@inheritdoc}
25 */
26 public static $prepare = '%s';
27
28 /**
29 * {@inheritdoc}
30 */
31 public static $pod_types = [
32 'pod',
33 'table',
34 ];
35
36 /**
37 * {@inheritdoc}
38 */
39 public function setup() {
40
41 static::$label = __( 'Permalink (url-friendly)', 'pods' );
42 }
43
44 /**
45 * {@inheritdoc}
46 */
47 public function options() {
48
49 $options = [
50 static::$type . '_placeholder' => [
51 'label' => __( 'HTML Placeholder', 'pods' ),
52 'default' => '',
53 'type' => 'text',
54 'help' => [
55 __( 'Placeholders can provide instructions or an example of the required data format for a field. Please note: It is not a replacement for labels or description text, and it is less accessible for people using screen readers.', 'pods' ),
56 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
57 ],
58 ],
59 ];
60
61 return $options;
62
63 }
64
65 /**
66 * {@inheritdoc}
67 */
68 public function schema( $options = null ) {
69
70 $schema = 'VARCHAR(200)';
71
72 return $schema;
73 }
74
75 /**
76 * {@inheritdoc}
77 */
78 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
79
80 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
81 $form_field_type = PodsForm::$field_type;
82
83 $value = $this->normalize_value_for_input( $value, $options, '-' );
84
85 $field_type = 'slug';
86
87 if ( isset( $options['name'] ) && ! pods_permission( $options ) ) {
88 if ( pods_v_bool( 'read_only_restricted', $options ) ) {
89 $options['readonly'] = true;
90
91 $field_type = 'text';
92 } else {
93 return;
94 }
95 } elseif ( ! pods_has_permissions( $options ) ) {
96 if ( pods_v_bool( 'read_only', $options ) ) {
97 $options['readonly'] = true;
98
99 $field_type = 'text';
100 }
101 }
102
103 if ( ! empty( $options['disable_dfv'] ) ) {
104 return pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
105 }
106
107 $type = pods_v( 'type', $options, static::$type );
108
109 $args = compact( array_keys( get_defined_vars() ) );
110 $args = (object) $args;
111
112 $this->render_input_script( $args );
113 }
114
115 /**
116 * {@inheritdoc}
117 */
118 public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
119
120 $index = pods_v( 'pod_index', pods_v( 'options', $pod, $pod, true ), 'id', true );
121
122 if ( empty( $value ) && isset( $fields[ $index ] ) ) {
123 $value = $fields[ $index ]['value'];
124 }
125
126 $value = pods_unique_slug( $value, $name, $pod, 0, $params->id, null, false );
127
128 return $value;
129 }
130 }
131