Support » Plugin: Just Custom Fields » Please add import feature from versions 2.x

  • Resolved Chris

    (@camthor)


    Hi,

    By updating your plugin, all the information became inaccessible. I found a thread that recommended to replace the plugin by an older version (2.x) – this worked. But of course I’m not entirely happy to stay with an old version now …

    I need to use the custom fields to save the data because in a template I use “get_post_meta” to retrieve the values of the fields. Is there any comparable function for 3.x that I could use after upgrading?

    It would be really, really useful if you could add on the “import” screen also a button to import the data from the 2.x version. This is simply the most important case where you need an import function. Thanks!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Alex Prokopenko / JustCoded

    (@aprokopenko)

    First of all we will check that Export works good in v2.

    We do not use export/import much in our development process and just use file system storage (can be turned on in settings). So I’m not sure right now it works in v2. It was released very long time ago, so we should test it first.

    I will leave this thread open. If we have enough user posts about migration tool – we will definitely make it!

    hi, im currently working on a solution, that reads out the meta field names and inserts new fields into the new version of jcf – do you actually work on this? should i wait?

    for now i made a small script, displaying the old settings while having the new version activated, so conversion runs much faster now.

    for the functions.php:

    <php
    
    function old_jcf_settings(){
      $post_types = get_post_types();
      $jcf_fieldsets = 'jcf_fieldsets-';
      $jcf_fields = 'jcf_fields-';
      $jcf_settings = [];
      
      foreach ( $post_types as $post_type ) {
        $post_fieldsets = get_option($jcf_fieldsets . $post_type);
        $post_fields = get_option($jcf_fields . $post_type);
        
        if ( $post_fieldsets || $post_fields ) {
          $jcf_settings[$post_type] = [];
        
          if ( $post_fieldsets ) {
            $jcf_settings[$post_type]['fieldsets'] = $post_fieldsets;
          }    
          if ( $post_fields ) {
            $jcf_settings[$post_type]['fields'] = $post_fields;   
          }
        }
      }
      echo '<!-- old_jcf_settings: ', var_dump($jcf_settings), ' -->';     
    }
    
    ?>

    and then call it in any template file (example for page.php).

    <?php
      if ( is_page('test_custom_fields') ) {
        old_jcf_settings();
      }
    
    ?>

    its only displaying in the output source code, so the normal view isn’t disturbed while viewing. converting the output to json seems not so much effort, i just actually don’t know the structure of an import/export json file.

    Plugin Author Alex Prokopenko / JustCoded

    (@aprokopenko)

    Hi, yes we’re working on new version with migration feature, which will convert all v2.3 settings into v3.0.

    You can see on github what we’re working on right now:
    https://github.com/aprokopenko/justcustomfields/pull/75

    This is a Draft of Migrations module built by one of our developers. I didn’t check it by myself yet. I hope I will have time next week.

    that sounds good, also the migration of the upload media field.

    in while im done with the json output which seems to should import on the new versions (tested on a simple page)

    function old_jcf_settings($output_json = true){
      $post_types = get_post_types();
      $post_types_objects = get_post_types(null, null, 'objects');
      $jcf_fieldsets = 'jcf_fieldsets-';
      $jcf_fields = 'jcf_fields-';
      $jcf_settings = [];
      $new_jcf_settings = [];
      
      foreach ( $post_types as $post_type ) {
        $post_fieldsets = get_option($jcf_fieldsets . $post_type);
        $post_fields = get_option($jcf_fields . $post_type);
        
        if ( $post_fieldsets || $post_fields ) {
          $jcf_settings[$post_type] = [];
          if ( $post_fieldsets ) {
            $jcf_settings[$post_type]['fieldsets'] = $post_fieldsets;
            $new_jcf_settings['fieldsets'][$post_type] = array_merge(
              array('position' => null,'priority' => null),
              $post_fieldsets
            );
            foreach ( $post_fieldsets as $post_fieldset_id => $post_fieldset ) {
              $post_fieldset_fields = $post_fieldset['fields'];
              foreach ( $post_fieldset_fields as $post_fieldset_field => $enabled ) {
                $jcf_settings[$post_type]['fieldsets'][$post_fieldset_id]['fields'][$post_fieldset_field] = array_merge(
                  $post_fields[$post_fieldset_field],
                  array('enabled' => $enabled)
                );
              }
            }
          }
          if ( $post_fields ) {
            $new_jcf_settings['fields'] = [];
            $new_jcf_settings['fields'][$post_type] = $post_fields;
          }
          $new_jcf_settings['post_types'][$post_type] = $post_types_objects[$post_type];
        }
      }
      if ( $output_json ) {
        echo '<!-- old_jcf_settings: ', "\r\n";
        echo json_encode($jcf_settings), "\r\n";
        echo ' -->', "\r\n";
        
        echo '<!-- new_jcf_settings: ', "\r\n";
        echo json_encode($new_jcf_settings), "\r\n";
        echo ' -->', "\r\n";
      } else {
        echo '<!-- old_jcf_settings: ', "\r\n";
        echo var_dump($jcf_settings), "\r\n";
        echo ' -->', "\r\n";
        
        echo '<!-- new_jcf_settings: ', "\r\n";
        echo var_dump($new_jcf_settings), "\r\n";
        echo ' -->';
      }
    }

    just copy the “new_jcf_settings” output line in a json file and import.

    Plugin Author Alex Prokopenko / JustCoded

    (@aprokopenko)

    Hi @netzgestaltung,

    I’ve almost finished with the migration feature. The code is in the develop branch of my repository:
    https://github.com/aprokopenko/justcustomfields/tree/develop

    I need to run a lot of tests now (different versions of PHP, versions of WP 4.7, 4.7.1, 4.7.2), multisite version etc. (I added code for migrating multisites as well, however didn’t test it at all).

    Would be really great if you can download and test it. It works with file/db modes. For me it’s easier to test with file mode (because you just delete new file, copy old one – and can test again).
    Please backup your DB anyway 🙂

    Please let me know does it work for you.

    Plugin Author Alex Prokopenko / JustCoded

    (@aprokopenko)

    Hi,

    We launched new v3.1 with migration feature. Would be great if you can try and give your feedback.

    tested and works like a charm – i got a notice that there are old settings and that it will import it.

    afterwards, fields and settings where there – i tested only with text fields!

    good job!

    it also worked on pages where i previouly used my script to get the migration faster.

    tested with fields: datepicker, textarea, inputtext and checkbox.

    Plugin Author Alex Prokopenko / JustCoded

    (@aprokopenko)

    Cool, thanks for the feedback

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Please add import feature from versions 2.x’ is closed to new replies.