コード例 #1
0
 /**
  * Check that the stamp is valid between the files and the database
  * Calling action/hook "wpbase/checksum/synchronize" if not valid
  */
 public static function validate()
 {
     $stamp = get_option('wpbase_checksum', '');
     if (!ChecksumHandler::is_valid($stamp)) {
         do_action('wpbase/checksum/synchronize');
     }
 }
コード例 #2
0
ファイル: WpBase.php プロジェクト: digitalunited/wp-base
 /**
  * @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();
 }
コード例 #3
0
ファイル: CptUI.php プロジェクト: digitalunited/wp-base
 /**
  * Sync from files, reading from json and updates the options for CPT
  * @todo might not be needed, remove later if the json solution works
  */
 public static function synchronize()
 {
     $path = self::get_configuration_path();
     $filename = "{$path}/post_type.json";
     if (file_exists($filename)) {
         $json = file_get_contents($filename);
         $json = json_decode($json, true);
         update_option('cpt_custom_post_types', $json);
         do_action('wpbase/cpt/generate', array('post_type', 'cpt_custom_post_types'));
     }
     $filename = "{$path}/taxonomy.json";
     if (file_exists($filename)) {
         $json = file_get_contents($filename);
         $json = json_decode($json, true);
         update_option('cpt_custom_tax_types', $json);
         do_action('wpbase/cpt/generate', array('taxonomy', 'cpt_custom_tax_types'));
     }
     ChecksumHandler::stamp();
 }
コード例 #4
0
ファイル: Acf.php プロジェクト: digitalunited/wp-base
 /**
  * Synchronize Acf from json files
  *
  * @throws \Exception
  */
 public static function synchronize()
 {
     global $wpdb;
     $path = self::get_configuration_path();
     $sql = "DELETE FROM {$wpdb->posts} WHERE post_type='acf-field' OR post_type='acf-field-group';";
     $wpdb->query($sql);
     // Just because we love implicit eval
     $files = glob("{$path}/*.json");
     if (is_array($files)) {
         foreach ($files as $file) {
             $json = file_get_contents($file);
             $json = json_decode($json, true);
             // copied from acf settings-export.php / import function
             $fields = acf_extract_var($json, 'fields');
             $fields = acf_prepare_fields_for_import($fields);
             $field_group = acf_update_field_group($json);
             $ref[$field_group['key']] = $field_group['ID'];
             $order[$field_group['ID']] = 0;
             foreach ($fields as $field) {
                 if (empty($field['parent'])) {
                     $field['parent'] = $field_group['ID'];
                 } elseif (isset($ref[$field['parent']])) {
                     $field['parent'] = $ref[$field['parent']];
                 }
                 if (!isset($order[$field['parent']])) {
                     $order[$field['parent']] = 0;
                 }
                 $field['menu_order'] = $order[$field['parent']];
                 $order[$field['parent']]++;
                 $field = acf_update_field($field);
                 $ref[$field['key']] = $field['ID'];
             }
             // /copied
         }
     }
     ChecksumHandler::stamp();
 }