Пример #1
0
 /**
  * @todo, insert some checks if all required plugins are installed and activated or notify user.
  *        Maybe a status module?
  */
 public static function init()
 {
     if (is_admin()) {
         ChecksumHandler::listen_for_validation();
         Notice::listen_for_notices();
         Acf::listen_for_updates();
         CptUI::listen_for_updates();
     }
     /*
      * @todo do not work properly
      */
     CptUI::register_custom_taxonomies_and_post_types();
 }
<?php

/**
 * Template Name: Solr Search
 * Description: Customized Solr Search Results
 */
$JS_PATH = get_template_directory_uri() . '/js/';
$acf = new Acf();
get_header();
?>

<script type="text/javascript" src="<?php 
echo $JS_PATH;
?>
/underscore.js"></script>
<script type="text/javascript" src="<?php 
echo $JS_PATH;
?>
/backbone.js"></script>
<script type="text/javascript" src="<?php 
echo $JS_PATH;
?>
/date.js"></script>

<script type="text/javascript">
  SELECT_FILTERS = <?php 
print json_encode($acf->get_acf_fields(47));
?>
;
  
  var MULTISELECT_FILTERS = [  
 function export($args, $assoc_args)
 {
     include 'bin/helpers.php';
     // if empty it will show export all fields
     $export_field = '';
     if (is_multisite()) {
         $choice = $this->select_blog();
         switch_to_blog($choice);
     }
     //if export all is used skip the question popup
     if (empty($args) || $args[0] != 'all') {
         $export_field = $this->select_acf_field();
     }
     if (empty($export_field)) {
         WP_CLI::success("Exporting all fieldgroups \n");
     } else {
         WP_CLI::success("Exporting fieldgroup: " . $choices[$choice] . " \n");
     }
     $field_groups = get_posts(array('numberposts' => -1, 'post_type' => 'acf', 'sort_column' => 'menu_order', 'order' => 'ASC', 'include' => $export_field));
     if ($field_groups) {
         if (substr(get_option('acf_version'), 0, 1) > 3) {
             $acf_fld_grp = new acf_field_group();
         } else {
             $acf = new Acf();
         }
         $path = get_stylesheet_directory() . '/field-groups/';
         if (!is_dir($path) && !mkdir($path, 0755, false)) {
             WP_CLI::line('fieldgroup directory exists or cant be created!');
         }
         foreach ($field_groups as $group) {
             $title = get_the_title($group->ID);
             $sanitized_title = sanitize_title($title);
             $subpath = $path . $sanitized_title;
             $uniquid_path = $subpath . '/uniqid';
             // retrieve the uniquid from the file if it exists else we make a new one
             $uniqid = file_exists($uniquid_path) ? file_get_contents($uniquid_path) : uniqid();
             if (substr(get_option('acf_version'), 0, 1) > 3) {
                 $field_group_array = array('id' => $uniqid, 'title' => $title, 'fields' => $acf_fld_grp->get_fields(array(), $group->ID), 'location' => $acf_fld_grp->get_location(array(), $group->ID), 'options' => $acf_fld_grp->get_options(array(), $group->ID), 'menu_order' => $group->menu_order);
             } else {
                 $field_group_array = array('id' => $uniqid, 'title' => $title, 'fields' => $acf->get_acf_fields($group->ID), 'location' => $acf->get_acf_location($group->ID), 'options' => $acf->get_acf_options($group->ID), 'menu_order' => $group->menu_order);
             }
             // each field_group gets it's own folder by field_group name
             if (!is_dir($subpath) && !mkdir($subpath, 0755, false)) {
                 WP_CLI::line('fieldgroup subdirectory exists or cant be created!');
             } else {
                 // let's write the array to a data.php file so it can be used later on
                 $fp = fopen($subpath . '/' . "data.php", "w");
                 $output = "<?php \n\$group = " . var_export($field_group_array, true) . ';';
                 fwrite($fp, $output);
                 fclose($fp);
                 // write the xml
                 include 'bin/xml_export.php';
                 // write the uniquid file if it doesn't exist
                 if (!file_exists($uniquid_path)) {
                     $fp = fopen($subpath . '/' . "uniqid", "w");
                     $output = $uniqid;
                     fwrite($fp, $output);
                     fclose($fp);
                 }
                 WP_CLI::success("Fieldgroup " . $title . " exported ");
             }
         }
     } else {
         //error seems to be returning and break out of my loop
         //WP_CLI::error( 'No field groups were found in the database' );
         echo 'No field groups were found in the database';
         echo ' ';
     }
     if (is_multisite()) {
         restore_current_blog();
     }
 }