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 / src / Pods / WP / Revisions.php
pods / src / Pods / WP Last commit date
UI 4 months ago Bindings.php 4 months ago Meta.php 4 months ago Revisions.php 4 months ago
Revisions.php
117 lines
1 <?php
2
3 namespace Pods\WP;
4
5 // Don't load directly.
6 if ( ! defined( 'ABSPATH' ) ) {
7 die( '-1' );
8 }
9
10 use Pods\Whatsit\Pod;
11 use PodsForm;
12
13 /**
14 * Revisions specific functionality.
15 *
16 * @since 3.2.0
17 */
18 class Revisions {
19
20 /**
21 * Add the class hooks.
22 *
23 * @since 3.2.0
24 */
25 public function hook() {
26 add_filter( 'wp_post_revision_meta_keys', [ $this, 'wp_post_revision_meta_keys' ], 10, 2 );
27 }
28
29 /**
30 * Remove the class hooks.
31 *
32 * @since 3.2.0
33 */
34 public function unhook() {
35 remove_filter( 'wp_post_revision_meta_keys', [ $this, 'wp_post_revision_meta_keys' ] );
36 }
37
38 /**
39 * Filter the available post revision meta keys to include the ones registered by Pods.
40 *
41 * @since 3.2.0
42 *
43 * @param array $revisioned_keys The list of revisioned meta keys.
44 * @param string $post_type The post type.
45 *
46 * @return array The list of revisioned meta keys.
47 */
48 public function wp_post_revision_meta_keys( $revisioned_keys, $post_type ): array {
49 $meta = pods_container( Meta::class );
50
51 // Determine if we need to revision keys manually or if meta is already being registered.
52 if ( $meta->should_register_meta() ) {
53 return $revisioned_keys;
54 }
55
56 $api = pods_api();
57
58 $pod = $api->load_pod( [ 'name' => $post_type ] );
59
60 if ( ! $pod instanceof Pod || 'post_type' !== $pod->get_type() || 'meta' !== $pod->get_storage() ) {
61 return $revisioned_keys;
62 }
63
64 $revisionable_field_types = self::get_revisionable_field_types();
65
66 // Get the fields that are enabled for revisioning.
67 if ( 1 === (int) $pod->get_arg( 'revisions_revision_all_fields', 0 ) ) {
68 $revisionable_fields = $pod->get_fields( [
69 'type' => $revisionable_field_types,
70 'names' => true,
71 ] );
72 } else {
73 $revisionable_fields = $pod->get_fields( [
74 'type' => $revisionable_field_types,
75 'args' => [
76 'revisions_revision_field' => 1,
77 ],
78 'names' => true,
79 ] );
80 }
81
82 $revisioned_keys = array_merge( $revisioned_keys, array_values( $revisionable_fields ) );
83 $revisioned_keys = array_unique( array_values( $revisioned_keys ) );
84
85 return $revisioned_keys;
86 }
87
88 /**
89 * Get the list of revisionable field types.
90 *
91 * @since 3.2.0
92 *
93 * @return array The list of revisionable field types.
94 */
95 public static function get_revisionable_field_types(): array {
96 $field_types = PodsForm::field_types_list();
97 $tableless_field_types = PodsForm::tableless_field_types();
98 $layout_field_types = PodsForm::layout_field_types();
99
100 $revisionable_field_types = [];
101
102 foreach ( $field_types as $field_type ) {
103 if (
104 in_array( $field_type, $tableless_field_types, true )
105 || in_array( $field_type, $layout_field_types, true )
106 ) {
107 continue;
108 }
109
110 $revisionable_field_types[] = $field_type;
111 }
112
113 return $revisionable_field_types;
114 }
115
116 }
117