Support

Account

Home Forums Feature Requests Support Multisite options for all sites through sitemeta table Reply To: Support Multisite options for all sites through sitemeta table

  • Seems I can’t edit my answer after some time. These are the filters I ended up using:

    
    $field_key = 'foo';
    
    add_filter( "acf/load_value/key=$field_key", function ( $original_value ) use ( $field_key ) {
        $network_value = get_site_option( $field_key, null );
    
        if ( ! is_null( $network_value ) ) {
            // Return the value from the "sitemeta" table, if available
            return $network_value;
        } else {
            // This will only happen if the field was never updated.
            return $original_value;
        }
    
    } );
    
    add_filter( "acf/update_value/key=$field_key", function ( $value ) use ( $field_key ) {
        $old_network_value = get_site_option( $field_key, null );
    
        // Replicate the field value to the "sitemeta" table
        if ( is_null( $old_network_value ) ) {
            add_site_option( $field_key, $value );
        } else {
            update_site_option( $field_key, $value );
        }
    
        $new_network_value = get_site_option( $field_key );
    
        return $new_network_value;
    } );