Plugin Directory

Changeset 2555307


Ignore:
Timestamp:
06/28/2021 02:02:10 PM (5 years ago)
Author:
abigegg
Message:

Commit 0.6.1 to trunk

Location:
hatch
Files:
1 edited
6 copied

Legend:

Unmodified
Added
Removed
  • hatch/trunk/abe-hatch.php

    r2553568 r2555307  
    33 * Plugin name: Hatch
    44 * Author: A Big Egg
    5  * Version: 0.6.0
     5 * Version: 0.6.1
    66 * Description: Provides helper functions for working with Timber and ACF. Requires Timber (timber-library) and works well with Advanced Custom Fields Pro and Gravity Forms.
    77 */
     
    1717    static $taxonomy_transformers = [];
    1818    static $main_transformer      = false;
     19
     20    static $post_cache            = [];
    1921
    2022    function __construct() {
     
    269271     */
    270272    static function get_post( $post = false ) {
    271         $the_post = Timber::get_post( $post );
    272 
    273         return self::construct_post( $the_post );
     273        return self::construct_post( $post );
    274274    }
    275275   
     
    278278     *
    279279     * @param  mixed $post_id
    280      * @return void
     280     * @return mixed
    281281     */
    282282    static function construct_post( $post_id = 0 ) {
    283         if ( ! $post_id ) {
    284             return $post_id;
    285         }
    286 
     283        if ( ! empty( $post_id ) ) {
     284
     285            // we have a TimberPost or WP_Post
     286            if ( is_object( $post_id ) ) {
     287                $post_id = $post_id->ID;
     288            }
     289
     290            if ( isset( self::$post_cache[$post_id] ) ) {
     291                return self::$post_cache[$post_id];
     292            }
     293        }
     294
     295        // cache did not hit
    287296        $post = new Timber\Post( $post_id );
    288297
    289         $thumb_id = get_post_thumbnail_id( $post );
     298        $thumb_id = get_post_thumbnail_id( $post->ID );
    290299
    291300        if ( $thumb_id ) {
     
    296305            $post = self::transform_post( $post );
    297306        }
    298    
     307
     308        self::$post_cache[$post->ID] = $post;
    299309
    300310        return $post;
Note: See TracChangeset for help on using the changeset viewer.