Skip to content

Instantly share code, notes, and snippets.

@designbuildtest
Created February 17, 2015 01:26
Show Gist options
  • Save designbuildtest/253114936af7baa06491 to your computer and use it in GitHub Desktop.
Save designbuildtest/253114936af7baa06491 to your computer and use it in GitHub Desktop.
Timely - Click to Call
if ( current_theme_supports( 'onehundred-call-to-action' ) ) {
function myplugin_call_to_action_customize_register($wp_customize) {
$wp_customize->add_section('call_to_action', array(
'title' => __('Call to Action Button', 'onehundred'),
'priority' => 25,
) );
$wp_customize->add_setting('myplugin_call_to_action_text', array(
'type' => 'option',
'transport' => 'postMessage',
'sanitize_callback' => 'sanitize_text_field',
) );
$wp_customize->add_control('myplugin_call_to_action_text', array(
'section' => 'call_to_action',
'type' => 'text',
'label' => __('Call to Action', 'onehundred'),
'settings' => 'myplugin_call_to_action_text',
'priority' => 10,
) );
$wp_customize->add_setting('myplugin_call_to_action_icon', array(
'type' => 'option',
//'sanitize_callback' => '',
) );
$wp_customize->add_control('myplugin_call_to_action_icon', array(
'section' => 'call_to_action',
'type' => 'select',
'label' => __('Call to Action icon', 'onehundred'),
'settings' => 'myplugin_call_to_action_icon',
'choices' => array(
'phone' => __( 'Phone', 'onehundred' ),
'book' => __( 'Book', 'onehundred' ),
'red' => __( 'Red', 'onehundred' ),
),
'priority' => 20,
) );
$wp_customize->add_setting('myplugin_call_to_action_page', array(
'type' => 'option',
'sanitize_callback' => 'absint',
) );
$wp_customize->add_control('myplugin_call_to_action_page', array(
'section' => 'call_to_action',
'type' => 'dropdown-pages',
'label' => __('Call to Action page', 'onehundred'),
'settings' => 'myplugin_call_to_action_page',
'priority' => 30,
) );
}
add_action('customize_register','myplugin_call_to_action_customize_register');
function myplugin_call_to_action_html() {
$call_to_action_text = get_option('myplugin_call_to_action_text');
//$call_to_action_icon = get_option('myplugin_call_to_action_icon','default');
$call_to_action_page = get_option('myplugin_call_to_action_page');
$timely_account_name = get_option('myplugin_timely');
if ($call_to_action_text) { ?>
<div class="call-to-action">
<?php
if ($timely_account_name) { ?>
<script id="timelyScript" src="https://book.gettimely.com/widget/book-button.js"></script>
<div style="display:none;"><script id="hideScript">var hideButton = new timelyButton('<?php esc_attr_e($timely_account_name); ?>',{buttonId:'hideScript'});</script></div>
<a class="myplugin_call_to_action_text" href="#" onclick="hideButton.start();"><strong><?php esc_attr_e($call_to_action_text); ?></strong></a><?php
}
elseif ($call_to_action_page) { ?>
<a class="myplugin_call_to_action_text" href="<?php echo get_permalink($call_to_action_page); ?>"><strong><?php esc_attr_e($call_to_action_text); ?></strong></a><?php
}
else { ?>
<span class="myplugin_call_to_action_text"><strong><?php esc_attr_e($call_to_action_text); ?></strong></span><?php
}
?>
</div><?php
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment