Redux_CDN

The evolve Redux CDN class.

Defined (1)

The class is defined in the following location(s).

/library/admin/redux-framework/inc/class.redux_cdn.php  
  1. class Redux_CDN { 
  2. static public $_parent; 
  3. static private $_set; 
  4.  
  5. private static function is_enqueued( $handle, $list = 'enqueued', $is_script ) { 
  6. if ( $is_script ) { 
  7. wp_script_is( $handle, $list ); 
  8. } else { 
  9. wp_style_is( $handle, $list ); 
  10.  
  11. private static function _register( $handle, $src_cdn, $deps, $ver, $footer_or_media, $is_script = true ) { 
  12. if ( $is_script ) { 
  13. wp_register_script( $handle, $src_cdn, $deps, $ver, $footer_or_media ); 
  14. } else { 
  15. wp_register_style( $handle, $src_cdn, $deps, $ver, $footer_or_media ); 
  16.  
  17. private static function _enqueue( $handle, $src_cdn, $deps, $ver, $footer_or_media, $is_script = true ) { 
  18. if ( $is_script ) { 
  19. wp_enqueue_script( $handle, $src_cdn, $deps, $ver, $footer_or_media ); 
  20. } else { 
  21. wp_enqueue_style( $handle, $src_cdn, $deps, $ver, $footer_or_media ); 
  22.  
  23. private static function _cdn( $register = true, $handle, $src_cdn, $deps, $ver, $footer_or_media, $is_script = true ) { 
  24. $tran_key = '_style_cdn_is_up'; 
  25. if ( $is_script ) { 
  26. $tran_key = '_script_cdn_is_up'; 
  27.  
  28. $cdn_is_up = get_transient( $handle . $tran_key ); 
  29. if ( $cdn_is_up ) { 
  30. if ( $register ) { 
  31. self::_register( $handle, $src_cdn, $deps, $ver, $footer_or_media, $is_script ); 
  32. } else { 
  33. self::_enqueue( $handle, $src_cdn, $deps, $ver, $footer_or_media, $is_script ); 
  34. } else { 
  35.  
  36. $prefix = $src_cdn[1] == "/" ? 'http:' : ''; 
  37. $cdn_response = @wp_remote_get( $prefix . $src_cdn ); 
  38.  
  39. if ( is_wp_error( $cdn_response ) || wp_remote_retrieve_response_code( $cdn_response ) != '200' ) { 
  40. if ( class_exists( 'Redux_VendorURL' ) ) { 
  41. $src = Redux_VendorURL::get_url( $handle ); 
  42.  
  43. if ( $register ) { 
  44. self::_register( $handle, $src, $deps, $ver, $footer_or_media, $is_script ); 
  45. } else { 
  46. self::_enqueue( $handle, $src, $deps, $ver, $footer_or_media, $is_script ); 
  47. } else { 
  48. if ( ! self::is_enqueued( $handle, 'enqueued', $is_script ) ) { 
  49. $msg = __( 'Please wait a few minutes, then try refreshing the page. Unable to load some remotely hosted scripts.', 'evolve' ); 
  50. if ( self::$_parent->args['dev_mode'] ) { 
  51. $msg = sprintf( __( 'If you are developing offline, please download and install the <a href="%s" target="_blank">Redux Vendor Support</a> plugin/extension to bypass the our CDN and avoid this warning', 'evolve' ), 'https://github.com/reduxframework/redux-vendor-support' ); 
  52.  
  53. self::$_parent->admin_notices[] = array( 
  54. 'type' => 'error',  
  55. 'msg' => '<strong>' . __( 'Redux Framework Warning', 'evolve' ) . '</strong><br/>' . sprintf( __( '%s CDN unavailable. Some controls may not render properly.', 'evolve' ), $handle ) . ' ' . $msg,  
  56. 'id' => $handle . $tran_key,  
  57. 'dismiss' => false,  
  58. ); 
  59.  
  60. } else { 
  61. set_transient( $handle . $tran_key, true, MINUTE_IN_SECONDS * self::$_parent->args['cdn_check_time'] ); 
  62.  
  63. if ( $register ) { 
  64. self::_register( $handle, $src_cdn, $deps, $ver, $footer_or_media, $is_script ); 
  65. } else { 
  66. self::_enqueue( $handle, $src_cdn, $deps, $ver, $footer_or_media, $is_script ); 
  67.  
  68. private static function _vendor_plugin( $register = true, $handle, $src_cdn, $deps, $ver, $footer_or_media, $is_script = true ) { 
  69. if ( class_exists( 'Redux_VendorURL' ) ) { 
  70. $src = Redux_VendorURL::get_url( $handle ); 
  71.  
  72. if ( $register ) { 
  73. self::_register( $handle, $src, $deps, $ver, $footer_or_media, $is_script ); 
  74. } else { 
  75. self::_enqueue( $handle, $src, $deps, $ver, $footer_or_media, $is_script ); 
  76. } else { 
  77. if ( ! self::$_set ) { 
  78. self::$_parent->admin_notices[] = array( 
  79. 'type' => 'error',  
  80. 'msg' => sprintf( __( 'The <a href="%s">Vendor Support plugin</a> (or extension) is either not installed or not activated and thus, some controls may not render properly. Please ensure that it is installed and <a href="%s">activated</a>', 'evolve' ), 'https://github.com/reduxframework/redux-vendor-support', admin_url( 'plugins.php' ) ),  
  81. 'id' => $handle . '23',  
  82. 'dismiss' => false,  
  83. ); 
  84.  
  85. self::$_set = true; 
  86.  
  87. public static function register_style( $handle, $src_cdn = false, $deps = array(), $ver = false, $media = 'all' ) { 
  88. if ( self::$_parent->args['use_cdn'] ) { 
  89. self::_cdn( true, $handle, $src_cdn, $deps, $ver, $media, $is_script = false ); 
  90. } else { 
  91. self::_vendor_plugin( true, $handle, $src_cdn, $deps, $ver, $media, $is_script = false ); 
  92.  
  93. public static function register_script( $handle, $src_cdn = false, $deps = array(), $ver = false, $in_footer = false ) { 
  94. if ( self::$_parent->args['use_cdn'] ) { 
  95. self::_cdn( true, $handle, $src_cdn, $deps, $ver, $in_footer, $is_script = true ); 
  96. } else { 
  97. self::_vendor_plugin( true, $handle, $src_cdn, $deps, $ver, $in_footer, $is_script = true ); 
  98.  
  99. public static function enqueue_style( $handle, $src_cdn = false, $deps = array(), $ver = false, $media = 'all' ) { 
  100. if ( self::$_parent->args['use_cdn'] ) { 
  101. self::_cdn( false, $handle, $src_cdn, $deps, $ver, $media, $is_script = false ); 
  102. } else { 
  103. self::_vendor_plugin( false, $handle, $src_cdn, $deps, $ver, $media, $is_script = false ); 
  104.  
  105. public static function enqueue_script( $handle, $src_cdn = false, $deps = array(), $ver = false, $in_footer = false ) { 
  106. if ( self::$_parent->args['use_cdn'] ) { 
  107. self::_cdn( false, $handle, $src_cdn, $deps, $ver, $in_footer, $is_script = true ); 
  108. } else { 
  109. self::_vendor_plugin( false, $handle, $src_cdn, $deps, $ver, $in_footer, $is_script = true );