• Resolved Robert Peake

    (@robertpeake)


    While it’s great to see this being developed again, version 2.0 of the plugin breaks backwards-compatibility with the 1.x strain in that:

    • the API secret and API key are lost upon upgrade
    • player_id is required in the short code whereas it was not before
    • video_width parameter is no longer respected

    Any one of these will cause websites to be defaced at time of upgrade. While the secret/key can be easily re-entered, modifying dozens of shortcodes to include a default player and/or width is problematic and less flexible than the previous version of the plugin.

    Here is a diff/patch for ooyala.php that corrects all of the above issues, porting all v1.x settings and defaults to the v2.x format.

    8c8
    < Version: 2.0
    ---
    > Version: 2.1
    43c43
    < 	const settings_key = 'ooyala';
    ---
    > 	const settings_key = 'ooyala2';
    60a61
    >         'player_id' => '' //the default player id to use
    71c72,74
    < 		'secret' => ''
    ---
    > 		'secret' => '',
    >         'player_id' => '',
    >         'video_width' => '',
    103a107,118
    >
    > 		// Back-port all API settings from v1.x
    > 		add_action( 'plugins_loaded', array( $this, 'ooyala_backport_api_secret' ) );
    >
    >         // Load player defaults from WordPress media settings
    >         $ooyala2 = get_option( Ooyala::settings_key, $this->settings_default );
    >         if (isset($ooyala2['video_width']) && !empty($ooyala2['video_width'])) {
    >            $this->playerDefaults['width'] = $ooyala2['video_width'];
    >         }
    >         if (isset($ooyala2['player_id']) && !empty($ooyala2['player_id'])) {
    >            $this->playerDefaults['player_id'] = $ooyala2['player_id'];
    >         }
    129c144
    < 				<td scope="row"><input type="text" name="ooyala[key]" class="widefat" id="ooyala-apikey" value="<?php echo esc_attr( $option['key'] ); ?>" /></td>
    ---
    > 				<td scope="row"><input type="text" name="<?php echo Ooyala::settings_key; ?>[key]" class="widefat" id="ooyala-apikey" value="<?php if (isset($option['key'])) echo esc_attr( $option['key'] ); ?>" /></td>
    133c148
    < 				<td scope="row"><input type="text" name="ooyala[secret]" class="widefat" id="ooyala-apisecret" value="<?php echo esc_attr( $option['secret'] ); ?>" /></td>
    ---
    > 				<td scope="row"><input type="text" name="<?php echo Ooyala::settings_key; ?>[secret]" class="widefat" id="ooyala-apisecret" value="<?php if (isset($option['secret'])) echo esc_attr( $option['secret'] ); ?>" /></td>
    139a155,162
    > 			<tr>
    > 				<th scope="row"><label for="ooyala-playerid"><?php esc_html_e( "Default Player ID", 'ooyala' ); ?></label></th>
    > 				<td scope="row"><input type="text" name="<?php echo Ooyala::settings_key; ?>[player_id]" class="widefat" id="ooyala-playerid" value="<?php if (isset($option['player_id'])) echo esc_attr( $option['player_id'] ); ?>" /></td>
    > 			</tr>
    > 			<tr>
    > 				<th scope="row"><label for="ooyala-videowidth"><?php esc_html_e( "Default Video Width", 'ooyala' ); ?></label></th>
    > 				<td scope="row"><input type="text" name="<?php echo Ooyala::settings_key; ?>[video_width]" class="widefat" id="ooyala-video_width" value="<?php if (isset($option['video_width'])) echo esc_attr( $option['video_width'] ); ?>" /></td>
    > 			</tr>
    157a181,188
    > 		if( isset( $settings['player_id'] ) && is_string( $settings['player_id'] ) ) {
    > 			$validated['player_id'] = sanitize_text_field( $settings['player_id'] );
    > 		}
    >
    > 		if( isset( $settings['video_width'] ) && is_string( $settings['video_width'] ) ) {
    > 			$validated['video_width'] = sanitize_text_field( $settings['video_width'] );
    > 		}
    >
    378c409
    < 		if ( !$atts['code'] || !$atts['player_id'] ) {
    ---
    > 		if ( !isset($atts['code']) ) {
    380c411,415
    < 		}
    ---
    >         }
    >
    >         //fill in default player_id if not present in shortcode
    >         $atts['player_id'] = isset( $atts['player_id'] )  ? $atts['player_id'] : $this->playerDefaults['player_id'];
    >
    432a468
    >         <?php if (isset($atts['player_id'])): ?>
    433a470
    >         <?php endif; ?>
    448a486,509
    > 	function ooyala_backport_api_secret() {
    > 	    $modified = false;
    > 	    $ooyala = get_option('ooyala', array('api_key' => '', 'api_secret' => '', 'player_id' => '', 'video_width' => ''));
    > 	    $ooyala2 = get_option( Ooyala::settings_key, $this->settings_default );
    > 	    if (empty($ooyala2['key']) && !empty($ooyala['api_key'])) {
    >             $ooyala2['key'] = $ooyala['api_key'];
    >             $modified = true;
    > 	    }
    > 	    if (empty($ooyala2['secret']) && !empty($ooyala['api_secret'])) {
    >             $ooyala2['secret'] = $ooyala['api_secret'];
    >             $modified = true;
    > 	    }
    > 	    if (empty($ooyala2['player_id']) && !empty($ooyala['player_id'])) {
    >             $ooyala2['player_id'] = $ooyala['player_id'];
    >             $modified = true;
    > 	    }
    > 	    if (empty($ooyala2['video_width']) && !empty($ooyala['video_width'])) {
    >             $ooyala2['video_width'] = $ooyala['video_width'];
    >             $modified = true;
    > 	    }
    > 	    if ($modified) {
    > 		    update_option(Ooyala::settings_key, $ooyala2);
    > 	    }
    > 	}

    https://www.ads-software.com/plugins/ooyala-video-browser/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Maintain Backwards Compatibility with v1.x’ is closed to new replies.