Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions php/class-connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public function __construct( Plugin $plugin ) {
add_action( 'update_option_cloudinary_connect', array( $this, 'updated_option' ) );
add_action( 'cloudinary_status', array( $this, 'check_status' ) );
add_action( 'cloudinary_version_upgrade', array( $this, 'upgrade_connection' ) );

add_filter( 'cloudinary_setting_get_value', array( $this, 'maybe_connection_string_constant' ), 10, 2 );
}

/**
Expand Down Expand Up @@ -729,6 +731,49 @@ public function upgrade_connection( $old_version ) {
}
}

/**
* Checks if connection string constant is defined.
*
* @return bool
*/
public function has_connection_string_constant() {
return defined( 'CLOUDINARY_CONNECTION_STRING' );
}

/**
* Filters the connection parts.
*
* @param mixed $value The default value.
* @param string $setting The setting slug.
*
* @return mixed
*/
public function maybe_connection_string_constant( $value, $setting ) {
if ( ! $this->has_connection_string_constant() ) {
return $value;
}

static $url = null;

if ( empty( $url ) ) {
$url = str_replace( 'CLOUDINARY_URL=', '', CLOUDINARY_CONNECTION_STRING );
}

if ( 'cloudinary_url' === $setting ) {
$value = $url;
}

if ( 'signature' === $setting ) {
$value = md5( $url );
}

if ( 'connect' === $setting ) {
$value['cloudinary_url'] = $url;
}

return $value;
}

/**
* Check if the switch account param is set.
*
Expand Down
11 changes: 10 additions & 1 deletion php/ui/component/class-switch-cloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Cloudinary\UI\Component;

use Cloudinary\UI\Component;
use function Cloudinary\get_plugin_instance;

/**
* Connect Link Component.
Expand All @@ -25,7 +26,8 @@ class Switch_Cloud extends Submit {
*/
protected function submit_button( $struct ) {

$url = add_query_arg(
$plugin = get_plugin_instance();
$url = add_query_arg(
array(
'switch-account' => true,
),
Expand All @@ -40,6 +42,13 @@ protected function submit_button( $struct ) {
'button-primary',
);

if ( $plugin->get_component( 'connect' )->has_connection_string_constant() ) {
unset( $struct['attributes']['href'] );
$struct['element'] = 'button';
$struct['attributes']['disabled'] = 'disabled';
$struct['attributes']['title'] = __( 'Connection string defined by constant.', 'cloudinary' );
}

return $struct;
}
}