Example #1
0
 /**
  * Prints Minify string for JS files recursively
  *
  * This function will traverse all script groups recursively to print scripts
  * while retaining dependencies. Use actions provided to add other things
  * before or after the output.
  *
  * @since 1.3.0
  * @uses $wp_scripts
  * @return void
  */
 function print_scripts($position = 'header', $groups = false, $recursive = false)
 {
     global $wp_scripts;
     if (!$recursive) {
         do_action('bwp_minify_before_' . $position . '_scripts');
     }
     $groups = !$groups ? $this->min_scripts : $groups;
     $group_position = $position;
     foreach ($groups as $group_handle => $group) {
         // if group is already done, no need to process anything
         if (!empty($this->min_scripts[$group_handle]['done'])) {
             continue;
         }
         if ($group['position'] == 'original' || $group['position'] == 'oblivion') {
             // @since 1.3.1 if this group is handled by WordPress or is
             // forgotten, do not procceed and mark as done
             $this->min_scripts[$group_handle]['done'] = true;
             continue;
         }
         // if this is not the correct position for the group
         if ($group['position'] != $position) {
             if ($recursive) {
                 return $group['position'];
             } else {
                 continue;
             }
         }
         // print dependencies first
         $deps = array();
         if (0 < sizeof($group['depend'])) {
             foreach ($group['depend'] as $dep => $active) {
                 if (isset($this->min_scripts[$dep])) {
                     $deps[$dep] = $this->min_scripts[$dep];
                 }
             }
             $group_position = $this->print_scripts($position, $deps, true);
         }
         // resolve dependencies failed, ignore this group for now
         if ($group_position != $position) {
             // this group needs to move to a new position, trigger events
             do_action('bwp_minify_moved_group', 'script', $group_handle, $group_position);
             $this->min_scripts[$group_handle]['position'] = $group_position;
             continue;
         }
         // print this group using minify tag
         if (isset($group['string']) && 0 < sizeof($group['string'])) {
             // print l10n data first if this group has any
             if (isset($this->todo_l10n[$group_handle])) {
                 $this->print_scripts_l10n($this->todo_l10n[$group_handle]);
             }
             // if this is a minify string
             echo $this->get_minify_tag('script', $group, $group_handle);
         } else {
             if (!empty($group['handle'])) {
                 // we control the position but not the output
                 $wp_scripts->do_item($group['handle']);
             }
         }
         $this->min_scripts[$group_handle]['done'] = true;
     }
     if (!$recursive) {
         do_action('bwp_minify_after_' . $position . '_scripts');
         // save detector's log whenever we finish printing a footer batch
         if (false !== strpos($position, 'footer')) {
             $this->detector->commit_logs();
         }
     }
     return $group_position;
 }