Here are a set of functions I recently wrote to move a group from DisplayBuddy Rotate Images to DisplayBuddy Slideshow. The user wanted to add some controls to the rotating images, which meant they needed to use Slideshow instead. So these functions make it extremely easy/fast for the user/developer.
[php]
/**
* Returns Slideshow defaults
*
* @return array defaults
*/
function get_slideshow_defaults() {
return array (
'title' => '',
'images' => array(),
'layout' => 'default' ,
'type' => 'slider' ,
'enable_css_files' => 'true' ,
'image_width' => 500 ,
'image_height' => 300 ,
'thumb_image_width' => 85 ,
'thumb_image_height' => 65 ,
'slider-align' => 'center' ,
'slider-effect' => 'random' ,
'slider-slices' => 15 ,
'slider-animSpeed' => 466 ,
'slider-pauseTime' => 233 ,
'slider-directionNav' => 'true' ,
'slider-directionNavHide' => 'true' ,
'slider-controlNav' => 'true' ,
'slider-controlNavThumbs' => 'false' ,
'slider-keyboardNav' => 'false' ,
'slider-pauseOnHover' => 'true' ,
'slider-captionOpacity' => 0.8 ,
'slider-shadows' => 'true' ,
'cycle-align' => 'center' ,
'cycle-fx' => 'fade' ,
'cycle-timeout' => 4000 ,
'cycle-continuous' => 0,
'cycle-speed' => 1000 ,
'cycle-speedIn' => 0 ,
'cycle-speedOut' => 0 ,
'cycle-sync' => 1 ,
'cycle-random' => 0 ,
'cycle-pause' => 1 ,
'cycle-autostop' => 0 ,
'cycle-autostopCount' => 3 ,
'cycle-delay' => 0,
'cycle-randomizeEffects' => 1,
'cycle-pb_pager' => 0,
);
}
/**
* Moves a group from Rotating Images to Slideshow
* and creates a backup of both for optional reset.
*
* @param string Group name
*/
function wps_move_rigroup_to_slideshow( $name ) {
$pluginbuddy_slideshow = get_option ( 'pluginbuddy_slideshow' );
$rotating_images = get_option ( 'ithemes-rotating-images' );
$count = 0;
$slideshow_defaults = get_slideshow_defaults();
foreach ( $rotating_images['groups'] as $group ) {
$count++;
if ( $group['name'] == $name ) {
$slideshow_defaults['title'] = $group['name'];
foreach ( $group['options']['image_ids'] as $image ) {
$slideshow_defaults['images'][] = $image['attachment_id'];
}
$pluginbuddy_slideshow['groups'][] = $slideshow_defaults;
unset($rotating_images['groups'][$count]);
break;
}
}
//Create backup for reset (future use)
update_option ( 'pluginbuddy_slideshow-backup' , $pluginbuddy_slideshow );
update_option ( 'ithemes-rotating-images-backup' , $rotating_images );
//Save
update_option ( 'pluginbuddy_slideshow' , $pluginbuddy_slideshow );
update_option ( 'ithemes-rotating-images' , $rotating_images );
}
/**
* Moves all groups from Rotating Images to Slideshow
* with an option to exclude some groups
* and creates a backup of both for optional reset.
*
* @param array Group names (string)
*/
function wps_move_rigroups_to_slideshow( $excludes ) {
$rotating_images = get_option ( 'ithemes-rotating-images' );
$count = 0;
$slideshow_defaults = get_slideshow_defaults();
foreach ( $rotating_images['groups'] as $group ) {
$count++;
foreach ( $excludes as $exclude ) {
if ( $group['name'] == $exclude )
continue 2;
}
$slideshow_defaults['title'] = $group['name'];
foreach ( $group['options']['image_ids'] as $image ) {
$slideshow_defaults['images'][] = $image['attachment_id'];
}
$pluginbuddy_slideshow['groups'][] = $slideshow_defaults;
unset($rotating_images['groups'][$count]);
}
//Create backup for reset (future use)
update_option ( 'pluginbuddy_slideshow-backup' , $pluginbuddy_slideshow );
update_option ( 'ithemes-rotating-images-backup' , $rotating_images );
//Save
update_option ( 'pluginbuddy_slideshow' , $pluginbuddy_slideshow );
update_option ( 'ithemes-rotating-images' , $rotating_images );
}
[/php]
Leave a Reply