1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253:
<?php
class CTA_Enqueues {
static $scripts_queue;
public function __construct() {
self::load_hooks();
}
public static function load_hooks() {
add_action('wp_enqueue_scripts', array(__CLASS__, 'frontend_enqueues'));
add_action('admin_enqueue_scripts', array(__CLASS__, 'backend_enqueues'));
}
public static function frontend_enqueues() {
global $post, $wp_query;
if (!isset($post)) {
return;
}
wp_enqueue_script('jquery');
self::frontend_cta_enqueue();
self::frontend_non_cta_enqueue();
}
public static function frontend_cta_enqueue() {
global $post;
if ( isset($post) && $post->post_type == 'wp-call-to-action' ) {
return;
}
wp_enqueue_script('jquery');
}
public static function frontend_non_cta_enqueue() {
global $post;
if ( $post->post_type != 'wp-call-to-action' ) {
return;
}
wp_enqueue_style('cta-css', WP_CTA_URLPATH . 'assets/css/cta-load.css', array() ,false , true);
if ( current_user_can( 'manage_options' )) {
wp_enqueue_script('frontend-cta-admin', WP_CTA_URLPATH . 'assets/js/admin/frontend-admin-cta.js' , array() , null , true);
wp_localize_script( 'frontend-cta-admin', 'ctafrontend', array('ajax_url' => admin_url( 'admin-ajax.php' ) ));
}
}
public static function backend_enqueues( $hook ) {
global $post;
if (!isset($post) || $post->post_type != 'wp-call-to-action') {
return;
}
self::dequeue_3rd_party_scripts();
wp_enqueue_style('wp-cta-admin-css', WP_CTA_URLPATH . 'assets/css/admin-style.css', array() ,false , true);
self::backend_cta_enqueues( $hook );
self::frontend_editor_enqueues( $hook );
self::reenqueue_3rd_party_scripts( $hook );
}
public static function backend_cta_enqueues( $hook ) {
global $post;
$screen = get_current_screen();
if ((isset($screen) && $screen->post_type != 'wp-call-to-action')){
return;
}
global $CTA_Variations;
$CTAExtensions = CTA_Load_Extensions();
wp_enqueue_script(array('jquery', 'jqueryui', 'editor', 'thickbox', 'media-upload'));
wp_enqueue_script('jpicker', WP_CTA_URLPATH . 'assets/lib/jpicker/jpicker-1.1.6.min.js' , array() , null , false);
wp_localize_script( 'jpicker', 'jpicker', array( 'thispath' => WP_CTA_URLPATH . 'assets/lib/jpicker/images/'));
wp_enqueue_style('jpicker-css', WP_CTA_URLPATH . 'assets/lib/jpicker/css/jPicker-1.1.6.min.css', array() , null , false);
wp_dequeue_script('jquery-qtip');
wp_enqueue_script('jquery-qtip', WP_CTA_URLPATH . 'assets/lib/jquery-qtip/jquery.qtip.min.js' , array() , null , false);
wp_enqueue_script('load-qtip', WP_CTA_URLPATH . 'assets/lib/jquery-qtip/load.qtip.js', array('jquery-qtip') , null , false);
wp_enqueue_style('qtip-css', WP_CTA_URLPATH . 'assets/css/jquery.qtip.min.css');
wp_enqueue_style('wp-cta-only-cpt-admin-css', WP_CTA_URLPATH . 'assets/css/admin-wp-cta-cpt-only-style.css' , array() );
wp_enqueue_script( 'wp-cta-admin-clear-stats-ajax-request', WP_CTA_URLPATH . 'assets/js/ajax.clearstats.js', array( 'jquery') , null , true);
wp_localize_script( 'wp-cta-admin-clear-stats-ajax-request', 'ajaxadmin', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'wp_call_to_action_clear_nonce' => wp_create_nonce('wp-call-to-action-clear-nonce') ));
if (isset($_GET['page']) && $_GET['page'] === 'wp_cta_global_settings') {
wp_enqueue_script('cta-settings-js', WP_CTA_URLPATH . 'assets/js/admin/admin.global-settings.js' , array() , null , true );
}
if ($screen->id == 'edit-wp-call-to-action') {
wp_enqueue_script('wp-call-to-action-list', WP_CTA_URLPATH . 'assets/js/admin/admin.wp-call-to-action-list.js' , array() , null , true );
wp_enqueue_style('wp-call-to-action-list-css', WP_CTA_URLPATH.'assets/css/admin-wp-call-to-action-list.css');
wp_admin_css('thickbox');
add_thickbox();
}
if (isset($hooks) && $hook == 'post-new.php' || $hook == 'post.php') {
add_filter( 'wp_default_editor', array(__CLASS__, 'set_default_editor_mode'));
wp_enqueue_script('wp-cta-post-edit-ui', WP_CTA_URLPATH . 'assets/js/admin/admin.post-edit.js' , array() , null , false);
wp_localize_script( 'wp-cta-post-edit-ui', 'wp_cta_post_edit_ui', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'post_id' => $post->ID, 'variation_id' => $CTA_Variations->get_current_variation_id(), 'wp_call_to_action_meta_nonce' => wp_create_nonce('wp-call-to-action-meta-nonce'), 'wp_call_to_action_template_nonce' => wp_create_nonce('wp-cta-nonce') ));
wp_enqueue_script('wp-cta-js-metaboxes', WP_CTA_URLPATH . 'assets/js/admin/admin.metaboxes.js' , array() , null , false );
$template_data = $CTAExtensions->definitions;
$template_data = json_encode($template_data);
$template = get_post_meta($post->ID, 'wp-cta-selected-template', true);
$template = apply_filters('wp_cta_selected_template',$template);
$template = strtolower($template);
$params = array('selected_template'=>$template, 'templates'=>$template_data);
wp_localize_script('wp-cta-js-metaboxes', 'data', $params);
}
if ($hook == 'post.php') {
wp_enqueue_style('admin-post-edit-css', WP_CTA_URLPATH . 'assets/css/admin-post-edit.css');
}
if ($hook == 'post-new.php'){
wp_enqueue_script('wp-cta-js-create-new', WP_CTA_URLPATH . 'assets/js/admin/admin.post-new.js', array('jquery'), null, false );
wp_enqueue_style('wp-cta-css-post-new', WP_CTA_URLPATH . 'assets/css/admin-post-new.css');
}
}
public static function frontend_editor_enqueues() {
if (!isset($_GET['page'])||$_GET['page']!='wp-cta-frontend-editor') {
return;
}
wp_enqueue_script(array('jquery', 'editor', 'thickbox', 'media-upload'));
wp_dequeue_script('jquery-cookie');
wp_enqueue_script('jquery-cookie', WP_CTA_URLPATH . 'assets/js/jquery.cookie.js' , array() , null , true );
wp_enqueue_style( 'wp-admin' );
wp_admin_css('thickbox');
add_thickbox();
wp_enqueue_style('wp-cta-admin-css', WP_CTA_URLPATH . 'assets/css/admin-style.css');
wp_enqueue_script('wp-cta-post-edit-ui', WP_CTA_URLPATH . 'assets/js/admin/admin.post-edit.js' , array() , null , true );
wp_localize_script( 'wp-cta-post-edit-ui', 'wp_cta_post_edit_ui', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'wp_call_to_action_meta_nonce' => wp_create_nonce('wp-call-to-action-meta-nonce') ));
wp_enqueue_script('wp-cta-frontend-editor-js', WP_CTA_URLPATH . 'assets/js/customizer.save.js' , array() , null , true );
wp_enqueue_script('jpicker', WP_CTA_URLPATH . 'assets/lib/jpicker/jpicker-1.1.6.min.js' , array() , null , true);
wp_localize_script( 'jpicker', 'jpicker', array( 'thispath' => WP_CTA_URLPATH . 'assets/lib/jpicker/images/'));
wp_enqueue_style('jpicker-css', WP_CTA_URLPATH . 'assets/lib/jpicker/css/jPicker-1.1.6.min.css');
wp_enqueue_style('jpicker-css', WP_CTA_URLPATH . 'assets/lib/jpicker/css/jPicker.css');
wp_enqueue_style('wp-cta-customizer-frontend', WP_CTA_URLPATH . 'assets/css/customizer.frontend.css');
wp_dequeue_script('form-population');
wp_dequeue_script('inbound-analytics');
wp_enqueue_script('jquery-easing', WP_CTA_URLPATH . 'assets/js/jquery.easing.min.js' , array() , null , true );
}
public static function set_default_editor_mode() {
return 'html';
}
public static function dequeue_3rd_party_scripts() {
global $wp_scripts;
if ( !empty( $wp_scripts->queue ) ) {
self::$scripts_queue = $wp_scripts->queue;
foreach ( $wp_scripts->queue as $handle ) {
wp_dequeue_script( $handle );
}
}
}
public static function reenqueue_3rd_party_scripts() {
if(isset(self::$scripts_queue)) {
foreach ( self::$scripts_queue as $handle ) {
wp_enqueue_script( $handle );
}
}
}
}
$CTA_Enqueues = new CTA_Enqueues();