| Current Path : /home/ereika83/www/wp-content/plugins/instasuite-for-wordpress 4 3/admin/ |
| Current File : /home/ereika83/www/wp-content/plugins/instasuite-for-wordpress 4 3/admin/admin.php |
<?php
add_action('admin_menu', 'kyvio_add_admin');
function kyvio_add_admin() {
add_menu_page('Kyvio', 'Kyvio', 'manage_options', 'inst-settings', 'kyvio_admin');
}
function kyvio_admin() {
echo '<div class="wrap">' . "\n";
echo "\t" . '<div class="inst-admin">' . "\n";
require_once 'settings.php';
echo "\t" . '</div>' . "\n";
echo '</div>' . "\n";
}
add_action('admin_enqueue_scripts', 'kyvio_admin_scripts');
function kyvio_admin_scripts( $hook ) {
$panels = array(
'toplevel_page_inst-settings',
'post.php',
'post-new.php'
);
if ( !in_array($hook, $panels) ) return;
// load js and css for admin page
wp_enqueue_script('jquery');
wp_enqueue_script('switchery', KYVIO_JS . 'switchery.min.js', array('jquery'), '0.8.2', false);
wp_enqueue_style('inst-admin', KYVIO_CSS . 'admin.css');
}
add_action('admin_init', 'kyvio_admin_save');
function kyvio_admin_save() {
if ( isset($_POST['action']) && $_POST['action'] == 'instasuite_save' ) {
if ( !isset($_POST['_instasuite_nonce']) || !wp_verify_nonce($_POST['_instasuite_nonce'], 'instasuite_nonce') ) {
wp_die('Nonce Verification Failed.');
}
$token = sanitize_text_field($_POST['api_token']);
$fb_app_id = sanitize_text_field($_POST['fb_app_id']);
update_option('instasuite_token', $token);
update_option('instasuite_fb_app_id', $fb_app_id);
wp_redirect(admin_url('admin.php?page=inst-settings&saved=true'));
exit;
}
}
add_action('admin_init', 'inst_add_meta_box');
function inst_add_meta_box() {
$token = get_option('instasuite_token');
if ( !function_exists('add_meta_box') || empty($token) )
return;
global $pagenow;
if ( !empty($pagenow) && ('post-new.php' === $pagenow || 'post.php' === $pagenow) )
add_action('admin_footer', 'kyvio_admin_script');
add_meta_box('instasuite-meta-box', 'Kyvio Landing Page', 'inst_meta_box', 'page', 'normal', 'high');
add_meta_box('instasuite-meta-box', 'Kyvio Landing Page', 'inst_meta_box', 'post', 'normal', 'high');
}
function inst_meta_box( $post ) {
require_once 'metabox.php';
}
add_action('save_post', 'inst_save_meta');
function inst_save_meta( $post_id ) {
if ( !isset($_POST) )
return $post_id;
$nonce = $_POST['_inst_meta_nonce'];
if ( !wp_verify_nonce($nonce, 'inst-meta-nonce') )
return $post_id;
if ( 'page' === $_POST['post_type'] ) {
if ( !current_user_can( 'edit_page', $post_id ) ) return $post_id;
} else {
if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id;
}
if ( isset($_POST['enable_instasuite']) ) {
$meta = array(
'enable' => $_POST['enable_instasuite'],
'page_id' => $_POST['instasuitepage']
);
update_post_meta($post_id, 'instasuite_meta', $meta);
if ( !empty($_POST['instasuitepage']) ) {
list($funnel_id, $page_id) = explode(":", $_POST['instasuitepage'], 2);
$url = kyvio_call($funnel_id, $page_id, true);
$key = 'inst_' . md5($url);
delete_transient($key);
}
}
}
function kyvio_admin_script() {
?>
<script type="text/javascript">
var elems = Array.prototype.slice.call(document.querySelectorAll('.switchery'));
elems.forEach(function(html) {
var switchery = new Switchery(html);
});
jQuery(document).ready(function($){
$('input.switchery').each(function(){
var sw = $(this),
showOnEnable = sw.data('enableShow') || null,
hideOnEnable = sw.data('enableHide') || null,
showOnDisable = sw.data('disableShow') || null,
hideOnDisable = sw.data('disableHide') || null;
sw.change(function(){
if ( sw.is(":checked") ) {
if ( showOnEnable )
$(showOnEnable).show();
if ( hideOnEnable )
$(hideOnEnable).hide();
} else {
if ( showOnDisable )
$(showOnDisable).show();
if ( hideOnDisable )
$(hideOnDisable).hide();
}
}).change();
});
});
</script>
<?php
}