Advertisement
patrickwdaly

Fancybox for WordPress HTTPS Fix

Apr 6th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | None | 0 0
  1. <?php
  2.  
  3. /* Re-registers and enqueues scripts to use the correct protocol */
  4. add_action( 'wp_enqueue_scripts', '04062012_fix_protocol', 10 );
  5. add_action( 'admin_enqueue_scripts', '04062012_fix_protocol_admin', 10 );
  6.  
  7. /*
  8.  * Fixes how Fancybox enqueues scripts and styles so that
  9.  * they will be included with the correct protocol (i.e. https)
  10.  * Specific to the frontend, see also 04062012_fix_protocol_admin()
  11.  */
  12. function 04062012_fix_protocol() {
  13.  
  14.     $settings = get_option( 'mfbfw' );
  15.    
  16.     // Check if script should be loaded in footer
  17.     if ( isset($settings['loadAtFooter']) && $settings['loadAtFooter'] ) {
  18.         $footer = true;
  19.     } else {
  20.         $footer = false;
  21.     }
  22.    
  23.     // Check if plugin should not call jQuery script (for troubleshooting only)
  24.     if ( isset($settings['nojQuery']) && $settings['nojQuery'] ) {
  25.         $jquery = false;
  26.     } else {
  27.         $jquery = array('jquery');
  28.     }          
  29.  
  30.     wp_dequeue_style( 'fancybox' );
  31.     wp_dequeue_style( 'jquery-ui' );
  32.    
  33.     wp_deregister_script( 'fancybox' );
  34.     wp_deregister_script( 'jqueryeasing' );
  35.     wp_deregister_script( 'jquerymousewheel' );
  36.    
  37.     wp_enqueue_style( 'fancybox', plugins_url( 'fancybox-for-wordpress/fancybox/fancybox.css' ) );
  38.     wp_enqueue_style( 'jquery-ui', plugins_url( 'fancybox-for-wordpress/css/jquery-ui.css' ) ); // Load jQuery UI Tabs CSS for Admin Page
  39.    
  40.     wp_register_script( 'fancybox', plugins_url( 'fancybox-for-wordpress/fancybox/jquery.fancybox.js' ), $jquery, '1.3.4', $footer ); // Main Fancybox script
  41.     wp_register_script( 'jqueryeasing', plugins_url( 'fancybox-for-wordpress/js/jquery.easing.1.3.min.js' ), false, '1.3', $footer ); // Main Fancybox script
  42.     wp_register_script( 'jquerymousewheel', plugins_url( 'fancybox-for-wordpress/js/jquery.mousewheel.3.0.4.pack.js' ), false, '3.0.4', $footer ); // Main Fancybox script
  43.  
  44.  
  45. }
  46.  
  47. /*
  48.  * Fixes how Fancybox enqueues scripts and styles so that
  49.  * they will be included with the correct protocol (i.e. https)
  50.  * Specific to admin styles and scripts
  51.  */
  52. function 04062012_fix_protocol_admin() {
  53.  
  54.     wp_dequeue_style( 'fancybox-admin' );
  55.     wp_dequeue_script( 'fancybox-admin' );
  56.    
  57.     wp_enqueue_style( 'fancybox-admin', plugins_url( 'fancybox-for-wordpress/css/fancybox-admin.css' ) ); // Load custom CSS for Admin Page
  58.    
  59.     wp_enqueue_script( 'jquery-ui-core' ); // Load jQuery UI Core JS for Admin Page
  60.     wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) ); // Load jQuery UI Tabs JS for Admin Page
  61.     wp_enqueue_script( 'fancybox-admin', plugins_url( 'fancybox-for-wordpress/js/admin.js' ), array( 'jquery' ) ); // Load specific JS for Admin Page
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement