function pre_update_metadata()

in web/wp-content/plugins/acf-extended/includes/modules/performance/module-performance-ultra.php [159:248]


    function pre_update_metadata($return, $post_id, $name, $value, $hidden){
    
        // bail early
        // if acf
        //    or disabled module
        //    or bypass
        if($name === $this->meta_key || !$this->is_enabled($post_id) || $this->bypass){
            return $return;
        }
        
        // get store
        $acf = $this->get_store($post_id);
        
        // prefix
        $prefix = $hidden ? '_' : '';
        
        // value
        $acf["{$prefix}{$name}"] = $value;
    
        // update store
        $this->update_store($post_id, $acf);
        
        // unlash for preload on same page as update
        acf_enable_filter('acfe/performance_ultra/unslash');
    
        // manual update
        // outside acf/save_post, probably in update_field()
        if($this->compile !== $post_id){
            $this->update_meta($acf, $post_id);
        }
        
        // disallow on revision
        // use 'save as individual meta' on post only
        if(!wp_is_post_revision($post_id)){
            
            // try to get meta reference
            $field = acf_maybe_get_field($name, $post_id);
            
            // in case the name was passed as "_textarea" with $hidden = false
            // like in acf_copy_metadata()
            // we must search for field key directly through value
            if(!$field && acfe_starts_with($name, '_') && acf_is_field_key($value)){
                $field = acf_get_field($value);
            }
            
            // save as individual meta
            if($field && !empty($field['acfe_save_meta'])){
                return $return;
            }
            
        }
    
        // get config
        $config = $this->get_config();
        
        switch($config['mode']){
    
            // test + rollback
            // save normal meta
            case 'test':
            case 'rollback': {
                return $return;
            }
    
            // production
            // delete normal meta
            case 'production': {
    
                // use normal acf logic
                $this->do_bypass(function($name, $post_id, $hidden){
        
                    // check if meta exists
                    // this will get meta cache instead of db call
                    if(acf_get_metadata($post_id, $name, $hidden) !== null){
                        acf_delete_metadata($post_id, $name, $hidden);
                    }
        
                }, array($name, $post_id, $hidden));
    
                // do not save normal meta
                return true;
                
            }
            
        }
    
        // return
        return $return;
        
    }