callbacks ) || ! is_array( $registered->callbacks ) ) { continue; } foreach ( $registered->callbacks as $priority => $callbacks ) { $sig .= $hook . ':' . $priority . ':' . implode( ',', array_keys( $callbacks ) ) . ';'; } } return md5( $sig ); } public static function peek( $product_id ) { $product_id = (int) $product_id; if ( ! isset( self::$memo[ $product_id ] ) ) { return null; } $entry = self::$memo[ $product_id ]; if ( ! isset( $entry['sig'] ) || $entry['sig'] !== self::filter_signature() ) { self::$invalidations++; self::flush( $product_id ); return null; } self::$hits++; return $entry['payload']; } public static function store( $product_id, array $payload ) { $product_id = (int) $product_id; if ( $product_id <= 0 ) { return; } self::$builds++; $max = (int) apply_filters( 'aieo_variation_payload_max_products', 25 ); if ( ! isset( self::$memo[ $product_id ] ) ) { self::$order[] = $product_id; } self::$memo[ $product_id ] = array( 'sig' => self::filter_signature(), 'payload' => $payload, ); while ( $max > 0 && count( self::$order ) > $max ) { $evict = array_shift( self::$order ); unset( self::$memo[ $evict ] ); } } public static function flush( $product_id = 0 ) { $product_id = (int) $product_id; if ( $product_id <= 0 ) { self::$memo = array(); self::$order = array(); return; } unset( self::$memo[ $product_id ] ); $pos = array_search( $product_id, self::$order, true ); if ( false !== $pos ) { unset( self::$order[ $pos ] ); self::$order = array_values( self::$order ); } } public static function flush_for_variation( $variation_id ) { $parent = (int) wp_get_post_parent_id( (int) $variation_id ); if ( $parent > 0 ) { self::flush( $parent ); } } public static function flush_for_product_object( $product ) { if ( ! is_object( $product ) || ! method_exists( $product, 'get_id' ) ) { self::flush(); return; } $id = (int) $product->get_id(); if ( method_exists( $product, 'get_parent_id' ) ) { $parent = (int) $product->get_parent_id(); if ( $parent > 0 ) { self::flush( $parent ); return; } } self::flush( $id ); } public static function stats() { return array( 'builds' => self::$builds, 'hits' => self::$hits, 'products' => count( self::$memo ), 'invalidations' => self::$invalidations, ); } }