Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback if connect plugin is unavailable #104

Open
bwmarkle opened this issue May 23, 2022 · 0 comments
Open

Fallback if connect plugin is unavailable #104

bwmarkle opened this issue May 23, 2022 · 0 comments

Comments

@bwmarkle
Copy link
Contributor

Central uses the connect plugin to accomplish many tasks.

If the connect plugin is disabled for any reason, several tasks must still be done to ensure a smooth user journey.

The following code needs to be ran in the event the connect plugin is unavailable.

		$optionConfigs = get_option( 'bg_connect_configs', [] );

		add_filter( 'BoldgridDemo/configs', function( $configs ) use ( $optionConfigs ) {
			$configs['servers']['asset'] = ! empty( $optionConfigs['asset_server'] ) ? $optionConfigs['asset_server'] : $configs['servers']['asset'];
			return $configs;
		} );

		// Inspirations
		add_filter( 'boldgrid_inspirations_configs', function ( $configs ) use ( $optionConfigs ) {
			$configs[ 'asset_server' ] = ! empty( $optionConfigs['asset_server'] ) ? $optionConfigs['asset_server'] : $configs['servers']['asset'];
			return $configs;
		} );

		// BoldGrid Library
		add_filter( 'Boldgrid\Library\Configs\set', function( $configs ) use ( $optionConfigs ) {
			$configs[ 'api' ] = ! empty( $optionConfigs['asset_server'] ) ? $optionConfigs['asset_server'] : $configs[ 'api' ];
			return $configs;
		} );

		// BoldGrid Connect Plugin.
		add_filter( 'boldgrid_connect_config_setup_configs', function( $configs ) use ( $optionConfigs ) {
			$configs['asset_server'] = ! empty( $optionConfigs['asset_server'] ) ? $optionConfigs['asset_server'] : $configs[ 'asset_server' ];
			$configs['central_url'] = ! empty( $optionConfigs['central_url'] ) ? $optionConfigs['central_url'] : $configs[ 'central_url' ];
			return $configs;
		} );

		/**
		 * Filters the bg_connect_configs option to merge option with static configs provided.
		 *
		 * @param mixed       $value   Value of the option.
		 * @param string      $option  Option name.
		 * @return false|mixed (Maybe) filtered option value.
		 */
		add_filter( 'option_bg_connect_configs', function( $value, $option ) {
			$value = is_array( $value ) ? $value : [];
			$conf = \Boldgrid_Connect_Service::get( 'configs' );
			$confs = array_merge( $conf, $value );

			// Brand being passed in from install loop through and update option with correct provider.
			if ( ! empty( $confs['brand'] ) ) {
				foreach ( $confs['branding'] as $brand => $opts ) {
					if ( strpos( strtolower( $brand ), $confs['brand'] ) !== false ) {
						update_site_option( 'boldgrid_connect_provider', $brand );
					}
				}
			}

			return $confs;
		}, 10, 2 );
@bwmarkle bwmarkle changed the title Fallback if central plugin is unavailable Fallback if connect plugin is unavailable May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant