Skip to content

Commit dff18a9

Browse files
committed
Add multisite connection configuration handling in fetch_option_connection_objs method
1 parent 0ec48dd commit dff18a9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

disciple-tools-storage-api.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,25 @@ public static function validate_url( $url ): string {
118118
public static function fetch_option_connection_objs(): object {
119119
$option = get_option( self::$option_dt_storage_connection_objects );
120120

121+
// If multisite, then ensure specified connection configuration is always included.
122+
if ( is_multisite() && !empty( get_site_option( 'dt_storage_multisite_connection_object', [] ) ) ) {
123+
$multisite_connection_objects = get_site_option( 'dt_storage_multisite_connection_object', [] );
124+
125+
// Check if there is a valid, specified multisite storage connection.
126+
if ( isset( $multisite_connection_objects['id'], $multisite_connection_objects['enabled'], $multisite_connection_objects['name'], $multisite_connection_objects['type'] ) && boolval( $multisite_connection_objects['enabled'] ) ) {
127+
$type = $multisite_connection_objects['type'];
128+
129+
// Ensure identified connection contains a valid type configuration.
130+
if ( isset( $multisite_connection_objects[ $type ]['access_key'], $multisite_connection_objects[ $type ]['secret_access_key'], $multisite_connection_objects[ $type ]['region'], $multisite_connection_objects[ $type ]['endpoint'], $multisite_connection_objects[ $type ]['bucket'] ) ) {
131+
132+
// Finally, update option, with identified multisite connection.
133+
$decoded_option = json_decode( !empty( $option ) ? $option : '{}' );
134+
$decoded_option->{$multisite_connection_objects['id']} = (object) $multisite_connection_objects;
135+
$option = json_encode( $decoded_option );
136+
}
137+
}
138+
}
139+
121140
if ( ! empty( $option ) ) {
122141

123142
$connection_objs = [];

0 commit comments

Comments
 (0)