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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Cloudinary
* Plugin URI: https://cloudinary.com/documentation/wordpress_integration
* Description: With the Cloudinary plugin, you can upload and manage your media assets in the cloud, then deliver them to your users through a fast content delivery network, improving your website’s loading speed and overall user experience. Apply multiple transformations and take advantage of a full digital asset management solution without leaving WordPress.
* Version: 2.0.3
* Version: 2.0.4
* Author: Cloudinary Ltd., XWP
* Author URI: https://cloudinary.com/
* License: GPLv2+
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
let field = $(this),
value = field.val();

let reg = new RegExp(/^(cloudinary:\/\/){1}(\d)*[:]{1}[^:@]*[@]{1}[^@]*$/g );
let reg = new RegExp(/^(?:CLOUDINARY_URL=)?(cloudinary:\/\/){1}(\d)*[:]{1}[^:@]*[@]{1}[^@]*$/g );
if( reg.test( value ) ){
field.addClass( 'settings-valid-field' );
field.removeClass( 'settings-invalid-field' );
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,43 @@ public function media_library_script() {
public function verify_connection( $data ) {
if ( empty( $data['cloudinary_url'] ) ) {
delete_option( 'cloudinary_connection_signature' );
add_settings_error( 'cloudinary_connect', 'connection_error', __( 'Connection to Cloudinary has been removed.', 'cloudinary' ), 'notice-warning' );

add_settings_error(
'cloudinary_connect',
'connection_error',
__( 'Connection to Cloudinary has been removed.', 'cloudinary' ),
'notice-warning'
);

return $data;
}

$data['cloudinary_url'] = str_replace( 'CLOUDINARY_URL=', '', $data['cloudinary_url'] );
$current = $this->plugin->config['settings']['connect'];

if ( $current['cloudinary_url'] === $data['cloudinary_url'] ) {
return $data;
}

if ( ! preg_match( '~^cloudinary://~', $data['cloudinary_url'] ) ) {
add_settings_error( 'cloudinary_connect', 'format_mismatch', __( 'The Environment variable URL must be in this format: cloudinary://API_Key:API_Secret@Cloud_Name', 'cloudinary' ), 'error' );
// Pattern match to ensure validity of the provided url
if ( ! preg_match( '~^(?:CLOUDINARY_URL=)?cloudinary://[0-9]+:[A-Za-z_0-9]+@[A-Za-z]+~', $data['cloudinary_url'] ) ) {
add_settings_error(
'cloudinary_connect',
'format_mismatch',
__( 'The environment variable URL must be in this format: cloudinary://API_KEY:API_SECRET@CLOUD_NAME', 'cloudinary' ),
'error'
);

return $current;
}

$result = $this->test_connection( $data['cloudinary_url'] );

if ( ! empty( $result['message'] ) ) {
add_settings_error( 'cloudinary_connect', $result['type'], $result['message'], 'error' );

return $current;
}

add_settings_error( 'cloudinary_connect', 'connection_success', __( 'Successfully connected to Cloudinary.', 'cloudinary' ), 'updated' );
update_option( 'cloudinary_connection_signature', md5( $data['cloudinary_url'] ) );

Expand Down Expand Up @@ -169,9 +185,9 @@ function ( $a ) {
if ( 4 > count( $valid ) ) {
$result['type'] = 'invalid_url';
$result['message'] = sprintf(
// translators: Placeholder refers to the expected URL format.
// translators: Placeholder refers to the expected URL format.
__( 'Incorrect Format. Expecting: %s', 'cloudinary' ),
'<code>cloudinary://API_Key:API_Secret@Cloud_Name</code>'
'<code>cloudinary://API_KEY:API_SECRET@CLOUD_NAME</code>'
);

return $result;
Expand Down Expand Up @@ -305,7 +321,7 @@ public function get_config() {
if ( empty( $signature ) || version_compare( $this->plugin->version, $version, '>' ) ) {
// Check if there's a previous version, or missing signature.
$cld_url = get_option( 'cloudinary_url', null );
if ( is_null( $cld_url ) ) {
if ( null === $cld_url ) {
// Post V1.
$data = get_option( 'cloudinary_connect', array() );
if ( ! isset( $data['cloudinary_url'] ) || empty( $data['cloudinary_url'] ) ) {
Expand All @@ -317,7 +333,10 @@ public function get_config() {
'cloudinary_url' => $cld_url,
);
}

$data['cloudinary_url'] = str_replace( 'CLOUDINARY_URL=', '', $data['cloudinary_url'] );
$test = $this->test_connection( $data['cloudinary_url'] );

if ( 'connection_success' === $test['type'] ) {
$signature = md5( $data['cloudinary_url'] );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function init_player() {
if ( ! empty( $has_video ) || ! empty( $video_tags ) ) {
// Setup initial scripts.
wp_enqueue_style( 'cld-player' );
wp_enqueue_style( 'cld-player-local' );
wp_enqueue_style( 'cld-player-local', $this->media->plugin->dir_url . 'css/video.css', null, self::PLAYER_VER );
wp_enqueue_script( 'cld-player' );

// Init cld script object.
Expand Down Expand Up @@ -417,10 +417,8 @@ public function enqueue_block_assets() {
/**
* Register assets for the player.
*/
public function register_scripts_styles() {
public static function register_scripts_styles() {
wp_register_style( 'cld-player', 'https://unpkg.com/cloudinary-video-player@' . self::PLAYER_VER . '/dist/cld-video-player.min.css', null, self::PLAYER_VER );
wp_register_style( 'cld-player-local', $this->media->plugin->dir_url . 'css/video.css', null, self::PLAYER_VER );

wp_register_script( 'cld-core', 'https://unpkg.com/cloudinary-core@' . self::CORE_VER . '/cloudinary-core-shrinkwrap.min.js', null, self::CORE_VER, true );
wp_register_script( 'cld-player', 'https://unpkg.com/cloudinary-video-player@' . self::PLAYER_VER . '/dist/cld-video-player.min.js', array( 'cld-core' ), self::PLAYER_VER, true );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'fields' => array(
'cloudinary_url' => array(
'label' => __( 'Environment variable URL', 'cloudinary' ),
'placeholder' => 'cloudinary://API_Key:API_Secret@Cloud_Name',
'placeholder' => 'cloudinary://API_KEY:API_SECRET@CLOUD_NAME',
'required' => true,
'suffix' => '<button type="submit" class="button button-primary"><span class="dashicons dashicons-admin-plugins"></span> ' . __( 'Save connection', 'cloudinary' ) . '</button>',
),
Expand Down