PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.5
Pods – Custom Content Types and Fields v2.8.23.5
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 / tribe-common / src / Tribe / Post_Transient.php
pods / tribe-common / src / Tribe Last commit date
Admin 1 week ago Ajax 1 week ago Asset 1 week ago Context 1 week ago Customizer 1 week ago Debug_Bar 1 week ago Dialog 1 week ago Documentation 1 week ago Duplicate 1 week ago Editor 1 week ago Image 1 week ago JSON_LD 1 week ago Languages 1 week ago Log 1 week ago Meta 1 week ago Models 1 week ago PUE 1 week ago Process 1 week ago Promoter 1 week ago REST 1 week ago Repository 1 week ago Service_Providers 1 week ago Shortcode 1 week ago Support 1 week ago Tabbed_View 1 week ago Tooltip 1 week ago Traits 1 week ago Utils 1 week ago Validator 1 week ago Widget 1 week ago Abstract_Deactivation.php 1 week ago Abstract_Plugin_Register.php 1 week ago App_Shop.php 1 week ago Assets.php 1 week ago Assets_Pipeline.php 1 week ago Autoloader.php 1 week ago Cache.php 1 week ago Cache_Listener.php 1 week ago Changelog_Reader.php 1 week ago Container.php 1 week ago Context.php 1 week ago Cost_Utils.php 1 week ago Credits.php 1 week ago Customizer.php 1 week ago DB_Lock.php 1 week ago Data.php 1 week ago Date_Utils.php 1 week ago Db.php 1 week ago Debug.php 1 week ago Dependency.php 1 week ago Deprecation.php 1 week ago Editor.php 1 week ago Error.php 1 week ago Exception.php 1 week ago Extension.php 1 week ago Extension_Loader.php 1 week ago Feature_Detection.php 1 week ago Field.php 1 week ago Field_Conditional.php 1 week ago Freemius.php 1 week ago Log.php 1 week ago Main.php 1 week ago Notices.php 1 week ago Plugin_Meta_Links.php 1 week ago Plugins.php 1 week ago Plugins_API.php 1 week ago Post_History.php 1 week ago Post_Transient.php 1 week ago Promise.php 1 week ago Repository.php 1 week ago Rewrite.php 1 week ago Settings.php 1 week ago Settings_Manager.php 1 week ago Settings_Tab.php 1 week ago Simple_Table.php 1 week ago Support.php 1 week ago Tabbed_View.php 1 week ago Template.php 1 week ago Template_Factory.php 1 week ago Template_Part_Cache.php 1 week ago Templates.php 1 week ago Terms.php 1 week ago Timezones.php 1 week ago Tracker.php 1 week ago Updater.php 1 week ago Validate.php 1 week ago View_Helpers.php 1 week ago
Post_Transient.php
215 lines
1 <?php
2
3 /**
4 * A Class to handle Transients for posts, useful for caching complex structures
5 * It uses the same logic as WordPress Transient, but instead of options it will
6 * use the Post Meta as the table
7 *
8 * @since 4.1
9 */
10 class Tribe__Post_Transient {
11
12 /**
13 * Get (and instantiate, if necessary) the instance of the class
14 *
15 * @since 4.1
16 * @static
17 * @return self
18 *
19 */
20 public static function instance() {
21 return tribe( 'post-transient' );
22 }
23
24 /**
25 * Fetches the Transient Data
26 *
27 * @since 4.1
28 *
29 * @param int $post_id The Post ID, can also be a WP_Post
30 * @param string $transient Post Meta to Fetch
31 *
32 * @return mixed Value stored on the Post Transient.
33 */
34 public function get( $post_id, $transient ) {
35 global $_wp_using_ext_object_cache;
36
37 if ( is_numeric( $post_id ) ) {
38 $post_id = (int) $post_id;
39 } else {
40 $post = get_post( $post_id );
41 $post_id = $post->ID;
42 }
43
44 if ( has_filter( 'tribe_pre_post_meta_transient_' . $transient ) ) {
45 /**
46 * Attach an action before getting the new Transient
47 *
48 * @since 4.1
49 *
50 * @param int $post_id Post ID
51 * @param string $transient The Post Meta Key
52 */
53 $pre = apply_filters( 'tribe_pre_post_meta_transient_' . $transient, $post_id, $transient );
54 if ( false !== $pre ) {
55 return $pre;
56 }
57 }
58
59 if ( $_wp_using_ext_object_cache ) {
60 $value = wp_cache_get( "tribe_{$transient}-{$post_id}", "tribe_post_meta_transient-{$post_id}" );
61 } else {
62 $meta_timeout = '_transient_timeout_' . $transient;
63 $meta = '_transient_' . $transient;
64 $value = get_post_meta( $post_id, $meta, false );
65
66 // if there aren't any values, communicate that it did not fetch data from post transient
67 if ( ! is_array( $value ) || 0 === count( $value ) ) {
68 return false;
69 }
70
71 // grab the first value, because that's all we care about
72 $value = current( $value );
73
74 if ( $value && ! defined( 'WP_INSTALLING' ) ) {
75 if ( get_post_meta( $post_id, $meta_timeout, true ) < time() ) {
76 $this->delete( $post_id, $transient );
77
78 return false;
79 }
80 }
81 }
82
83 /**
84 * Attach an action after getting the new Transient
85 *
86 * @since 4.1
87 *
88 * @param int $post_id Post ID
89 * @param string $transient The Post Meta Key
90 */
91 return has_filter( 'tribe_post_meta_transient_' . $transient )
92 ? apply_filters( 'tribe_post_meta_transient_' . $transient, $value, $post_id )
93 : $value;
94 }
95
96 /**
97 * Delete a post meta transient.
98 *
99 * @since 4.1
100 *
101 * @param int $post_id The Post ID, can also be a WP_Post.
102 * @param string $transient Post Meta to Delete.
103 * @param string $value Only delete if the value Matches.
104 *
105 * @return boolean If we were able to delete the transient.
106 */
107 public function delete( $post_id, $transient, $value = null ) {
108 global $_wp_using_ext_object_cache;
109
110 if ( is_numeric( $post_id ) ) {
111 $post_id = (int) $post_id;
112 } else {
113 $post = get_post( $post_id );
114 $post_id = $post->ID;
115 }
116
117 /**
118 * Use this to pre attach an action to deleting a Post Transient
119 *
120 * @since 4.1
121 *
122 * @param int $post_id Post ID
123 * @param string $transient The Post Meta Key
124 */
125 do_action( 'tribe_delete_post_meta_transient_' . $transient, $post_id, $transient );
126
127 if ( $_wp_using_ext_object_cache ) {
128 $result = wp_cache_delete( "tribe_{$transient}-{$post_id}", "tribe_post_meta_transient-{$post_id}" );
129 } else {
130 $meta_timeout = '_transient_timeout_' . $transient;
131 $meta = '_transient_' . $transient;
132 $result = delete_post_meta( $post_id, $meta, $value );
133 if ( $result ) {
134 delete_post_meta( $post_id, $meta_timeout, $value );
135 }
136 }
137
138 if ( $result ) {
139 /**
140 * Use this to attach an Action to when the Transient is deleted
141 *
142 * @since 4.1
143 *
144 * @param int $post_id Post ID
145 * @param string $transient The Post Meta Key
146 */
147 do_action( 'tribe_deleted_post_meta_transient', $transient, $post_id, $transient );
148 }
149
150 return $result;
151 }
152
153 /**
154 * Sets a new value for the Transient.
155 *
156 * @since 4.1
157 *
158 * @param int $post_id The Post ID, can also be a WP_Post.
159 * @param string $transient Post Meta to set.
160 * @param string $value Only delete if the value Matches.
161 * @param int $expiration How long this transient will be valid, in seconds.
162 *
163 * @return int|false Meta ID on success, false on failure.
164 */
165 public function set( $post_id, $transient, $value, $expiration = 0 ) {
166 global $_wp_using_ext_object_cache;
167
168 if ( is_numeric( $post_id ) ) {
169 $post_id = (int) $post_id;
170 } else {
171 $post = get_post( $post_id );
172 $post_id = $post->ID;
173 }
174
175 $this->delete( $post_id, $transient );
176
177 /**
178 * Attach an action before setting the new Transient
179 *
180 * @since 4.1
181 *
182 * @param int $post_id Post ID
183 * @param string $transient The Post Meta Key
184 */
185 if ( has_filter( 'tribe_pre_set_post_meta_transient_' . $transient ) ) {
186 $value = apply_filters( 'tribe_pre_set_post_meta_transient_' . $transient, $value, $post_id, $transient );
187 }
188
189 if ( $_wp_using_ext_object_cache ) {
190 $result = wp_cache_set( "tribe_{$transient}-{$post_id}", $value, "tribe_post_meta_transient-{$post_id}", $expiration );
191 } else {
192 $meta_timeout = '_transient_timeout_' . $transient;
193 $meta = '_transient_' . $transient;
194 if ( $expiration ) {
195 add_post_meta( $post_id, $meta_timeout, time() + $expiration, true );
196 }
197 $result = add_post_meta( $post_id, $meta, $value, true );
198 }
199
200 if ( $result ) {
201 /**
202 * Attach an action after setting the new Transient
203 *
204 * @since 4.1
205 *
206 * @param int $post_id Post ID
207 * @param string $transient The Post Meta Key
208 */
209 do_action( 'tribe_set_post_meta_transient_' . $transient, $post_id, $transient );
210 }
211
212 return $result;
213 }
214 }
215