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 / Template_Part_Cache.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
Template_Part_Cache.php
124 lines
1 <?php
2
3 /**
4 * Class Tribe__Template_Part_Cache
5 *
6 * @uses TribeEventsCache
7 */
8 class Tribe__Template_Part_Cache {
9
10 /**
11 * @var string
12 */
13 private $template;
14
15 /**
16 * @var int
17 */
18 private $expiration;
19
20 /**
21 * @var string
22 */
23 private $expiration_trigger;
24
25 /**
26 * @var TribeEventsCache
27 */
28 private $cache;
29
30 /**
31 * @var string
32 */
33 private $html;
34
35 /**
36 ** Short description
37 *
38 * @param $template - which template in the views directory is being cached (relative path).
39 * @param $id - a unique identifier for this fragment.
40 * @param $expiration - expiration time for the cached fragment.
41 * @param $expiration_trigger - wordpress hook to expire on.
42 */
43 public function __construct( $template, $id, $expiration, $expiration_trigger ) {
44 $this->template = $template;
45 $this->key = $template . '_' . $id;
46 $this->expiration = $expiration;
47 $this->expiration_trigger = $expiration_trigger;
48 $this->cache = new Tribe__Cache();
49
50 $this->add_hooks();
51 }
52
53 /**
54 * Hook in to show cached content and bypass queries where needed
55 */
56 public function add_hooks() {
57
58 // set the cached html in transients after the template part is included
59 add_filter( 'tribe_get_template_part_content', [ $this, 'set' ], 10, 2 );
60
61 // get the cached html right before the setup_view runs so it's available for bypassing any view logic
62 add_action( 'tribe_events_before_view', [ $this, 'get' ], 9, 1 );
63
64 // when the specified template part is included, show the cached html instead
65 add_filter( 'tribe_get_template_part_path_' . $this->template, [ $this, 'display' ] );
66 }
67
68 /**
69 * Checks if there is a cached html fragment in the transients, if it's there,
70 * don't include the requested file path. If not, just return the file path like normal
71 *
72 * @param $path file path to the month view template part
73 *
74 * @return bool
75 * @uses tribe_get_template_part_path_[template] hook
76 */
77 public function display( $path ) {
78
79 if ( $this->html !== false ) {
80 echo $this->html;
81
82 return false;
83 }
84
85 return $path;
86
87 }
88
89 /**
90 * Set cached html in transients
91 *
92 * @param $html
93 * @param $template
94 *
95 * @return string
96 * @uses tribe_get_template_part_content hook
97 */
98 public function set( $html, $template ) {
99 if ( $template == $this->template ) {
100 $this->cache->set_transient( $this->key, $html, $this->expiration, $this->expiration_trigger );
101 }
102
103 return $html;
104 }
105
106 /**
107 * Retrieve the cached html from transients, set class property
108 *
109 * @uses tribe_events_before_view hook
110 */
111 public function get() {
112
113 if ( isset( $this->html ) ) {
114
115 return $this->html;
116 }
117
118 $this->html = $this->cache->get_transient( $this->key, $this->expiration_trigger );
119
120 return $this->html;
121
122 }
123 }
124