/**
  * Purge caches
  *
  * @subcommand purge
  */
 function purge()
 {
     delete_transient('pagelines_extend_themes');
     delete_transient('pagelines_extend_sections');
     delete_transient('pagelines_extend_plugins');
     delete_transient('pagelines_extend_integrations');
     pl_purge_section_cache();
     do_action('extend_flush');
     WP_CLI::success('Caches purged!');
 }
 /**
  *  Scans THEMEDIR/sections recursively for section files and auto loads them.
  *  Child section folder also scanned if found and dependencies resolved.
  *
  *  Section files MUST include a class header and optional depends header.
  *
  *  Example section header:
  *
  *	Section: BrandNav Section
  *	Author: PageLines
  *	Description: Branding and Nav Inline
  *	Version: 1.0.0
  *	Class Name: BrandNav
  *	Depends: PageLinesNav
  *
  *  @since 2.0
  */
 function pagelines_register_sections($reset = false, $echo = false)
 {
     global $pl_section_factory;
     if ($reset) {
         pl_purge_section_cache();
     }
     /**
      * If cache exists load into $sections array
      * If not populate array and prime cache
      */
     if (!($sections = get_transient('pagelines_sections_cache'))) {
         foreach (pl_get_section_dirs() as $type => $dir) {
             $sections[$type] = $this->get_sections($dir, $type);
         }
         // check for deps within the main parent sections, load last if found.
         foreach ($sections['parent'] as $key => $section) {
             if (!empty($section['depends'])) {
                 unset($sections['parent'][$key]);
                 $sections['parent'][$key] = $section;
             }
         }
         set_transient('pagelines_sections_cache', $sections, 86400);
     }
     if ($echo) {
         return $sections;
     }
     // filter main array containing child, parent and any custom sections
     $sections = apply_filters('pagelines_section_admin', $sections);
     $disabled = pl_get_disabled_sections();
     foreach ($sections as $tkey => $type) {
         if (!is_array($type)) {
             continue;
         }
         foreach ($type as $section) {
             if (empty($section['loadme'])) {
                 $section['loadme'] = false;
             }
             if ('parent' == $section['type'] || !is_multisite()) {
                 $section['loadme'] = true;
             }
             /**
              * Checks to see if we are a child section, if so disable the parent
              * Also if a parent section and disabled, skip.
              */
             if ('parent' != $section['type'] && isset($sections['parent'][$section['class']])) {
                 $disabled['parent'][$section['class']] = true;
             }
             if (isset($disabled[$section['type']][$section['class']]) && !$section['persistant']) {
                 continue;
             }
             // consolidate array vars
             $dep = 'parent' != $section['type'] && $section['depends'] ? $section['depends'] : null;
             $parent_dep = isset($sections['parent'][$section['depends']]) ? $sections['parent'][$section['depends']] : null;
             $dep_data = array('base_dir' => isset($parent_dep['base_dir']) ? $parent_dep['base_dir'] : null, 'base_url' => isset($parent_dep['base_url']) ? $parent_dep['base_url'] : null, 'base_file' => isset($parent_dep['base_file']) ? $parent_dep['base_file'] : null, 'name' => isset($parent_dep['name']) ? $parent_dep['name'] : null);
             $section_data = array('base_dir' => $section['base_dir'], 'base_url' => $section['base_url'], 'base_file' => $section['base_file'], 'name' => $section['name']);
             // do we have a dependency?
             if (isset($dep) && $section['loadme']) {
                 if (!class_exists($dep) && is_file($dep_data['base_file'])) {
                     include $dep_data['base_file'];
                     $pl_section_factory->register($dep, $dep_data);
                 }
                 // dep loaded...
                 if (!class_exists($section['class']) && class_exists($dep) && is_file($section['base_file'])) {
                     include $section['base_file'];
                     $pl_section_factory->register($section['class'], $section_data);
                 }
             } else {
                 if (!class_exists($section['class']) && is_file($section['base_file']) && !isset($disabled['parent'][$section['depends']])) {
                     include $section['base_file'];
                     $pl_section_factory->register($section['class'], $section_data);
                 }
             }
         }
     }
     pagelines_register_hook('pagelines_register_sections');
     // Hook
 }