Forked from yanknudtskov/wordpress-script-debugging.php
          
        
    
          Created
          June 18, 2018 06:57 
        
      - 
      
- 
        Save INDIAN2020/50c35705fa0aff8a4decf17532382921 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| // Using Script Debug to load non-minified scripts | |
| $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| wp_enqueue_script( 'my_awesome_script', "my_inc_dir/javascript_file{$min}.js", array( 'jquery' ), '0.1.0', true ); | |
| // Using script debug to log data in a javascript file | |
| wp_localize_script( 'my_awesome_script', 'mas_obj', array( | |
| // Set to true if debug is enabled, false otherwise | |
| 'is_debug' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? true : false, | |
| ) ); | |
| ?> | |
| <script type="text/javascript"> | |
| // Try and grab our object, if not make one. | |
| var our_script_l10n = window.mas_obj || {}; | |
| // Check if debug is available/true | |
| if ( our_script_l10n.is_debug ) { | |
| // We have debug on for our script, so alert the user. | |
| alert( 'Debug Works' ); | |
| } | |
| </script> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment