Skip to content

Instantly share code, notes, and snippets.

@ronalfy
Last active April 4, 2016 18:29
Show Gist options
  • Save ronalfy/285911b63422d413cd105e0058c81994 to your computer and use it in GitHub Desktop.
Save ronalfy/285911b63422d413cd105e0058c81994 to your computer and use it in GitHub Desktop.
Soliloquy Add Button
<?php
//Soliloquy Caption Modification
add_filter( 'soliloquy_output_caption', 'bigwing_home_data_filter', 10, 4 );
function bigwing_home_data_filter( $caption, $slider_id, $slider, $slider_data ) {
if ( 'homepage-slider' != $slider_data[ 'config' ][ 'slug' ] ) {
return $caption;
}
$slider_link = isset( $slider[ 'link' ] ) ? $slider[ 'link' ] : false;
$button_text = isset( $slider[ 'button_text' ] ) ? $slider[ 'button_text' ] : '';
$slider_title = isset( $slider[ 'title' ] ) ? $slider[ 'title' ] : '';
$slider_desc = isset( $slider[ 'caption' ] ) ? $slider[ 'caption' ] : '';
$html = '';
$html .= sprintf( '<div class="text-caption">%s</div>', apply_filters( 'opubco_the_content', $slider_desc ) );
if ( !empty( $button_text ) && $slider_link ) {
$html .= sprintf( '<div class="learn-more"><a href="%s"><span>%s</span></a></div>', esc_url( $slider_link ), esc_html( $button_text ) );
}
return $html;
}
//Add custom field to Soliloquy
add_action( 'soliloquy_before_image_meta_tab', 'bigwing_add_slider_meta', 10, 3 );
function bigwing_add_slider_meta( $id, $data, $post_id ) {
?>
<label class="setting">
<span class="name"><?php _e( 'Button Text', 'soliloquy' ); ?></span>
<input id="soliloquy-link-<?php echo absint( $id ); ?>" class="soliloquy-link" type="text" name="_soliloquy[meta_button_text]" value="<?php echo ( ! empty( $data['button_text'] ) ? esc_attr( $data['button_text'] ) : '' ); ?>" data-soliloquy-meta="button-text" />
</label>
<?php
}
add_filter( 'soliloquy_ajax_save_meta', 'bigwing_soliloquy_save_meta', 10, 4 );
function bigwing_soliloquy_save_meta( $slider_data, $meta, $attach_id, $post_id ) {
$button_text = false;
if ( isset( $meta[ 'button-text' ] ) ) {
$button_text = $meta[ 'button-text' ];
}
if ( $button_text ) {
$slider_data['slider'][$attach_id]['button_text'] = sanitize_text_field( $button_text );
}
return $slider_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment