Support » Plugin: Custom Content Type Manager » [Plugin: Custom Content Type Manager] importing CCT definitions at install time using wp-content/ins

  • Hi Everett, everyone,

    I am using wp-content/install.php to automatically install and activate CCTM & several other plugins at the time that wordpress is installed. I wouldl ove it if I could also provide a cctm.json file and activate its cct definitions at the same time — os when the user first logs in, all the cct’s are already activated and ready to go. Is this possible to do, and if so, what function do I need to invoke to do it? I see that the relevant code is in places like includes/CCTM_ImportExport.php and controlers/import_def.php, but it’s too sophisticated for me to follow.


Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor fireproofsocks


    Hi Matt –

    Good question. Since I’ve started writing unit tests, it’s forcing me to make my functions cleaner and more re-usable (it’s a lovely side effect of writing test cases).

    That function currently accepts one argument: the name of the .cctm.json definition file (not including the path info). E.g. “my-site.cctm.json”. It’s assumed that this file will live inside of wp-content/uploads/cctm/defs/

    So if you were going to automate this from an external file, you’d want to include the custom-content-type-manager/index.php file (that, in turn should include the necessary files), AND make sure you include the includes/CCTM_ImportExport.php file.

    Once you’ve loaded up the necessary classes, you’ll need to ensure that you have created the wp-content/uploads/cctm/defs/ and put your .cctm.json file in it. Once it’s in place, you should be able to do this:


    And that should upload your definition. Hope that helps. I may restructure this for the use-case you’ve outlined here (namely, installing stuff at the time of WP install).

    thanks as always Everett!

    I can’t seem to get this to work on install. I do have some code that will work if I insert it into a template:

    // now we need to activate the CCT definitions at startup
      if (file_exists(WP_PLUGIN_DIR . '/custom-content-type-manager/index.php') ) {
          require_once(WP_PLUGIN_DIR . '/custom-content-type-manager/index.php');
          require_once(WP_PLUGIN_DIR . '/custom-content-type-manager/includes/CCTM_ImportExport.php');
          $uploads_info = wp_upload_dir();
          prdebug("wp_uploads_dir basedir returns " . print_r($uploads_info) );
          $cctmdefspath = $uploads_info['basedir'] . "/cctm/defs/" . $CCTMDEFS;
            if (file_exists($cctmdefspath))
              prdebug("found it" . $cctmdefspath);
              // CCTM_ImportExport::activate_def($CCTMDEFS);
              prdebug("trying with a static string even though cctm is set to " . $CCTMDEFS);

    (sorry there’s some cruft in there — I was trying to see if something was going wrong with variable assignments, turned out not to be the culprit).

    At first I though maybe your function just wasn’t running, but by inserting some error checking code into activate_defs I was able to confirm that wordpress finds the json file, checks its accuracy, and even merges the data into the database (I looked in phpmyadmin).

    This all happens in the first stage of the install. But then in stage 2, the value of ctm_data in wp_options is reset to the default text (“this site was constructed in part with…” etc.). At this stage a bunch of new options — not CCTM related — are also added to the database. So I wonder if there’s some process in WP that overrides this option, or some code in CCTM that doesn’t activate until, say, first login or something, and which causes the option to be overwritten.

    regardless, I’m pretty pleased with my new wordpress build system, which lets me add plugins and themes automatically on install; it lives in github:

    and is in pretty terrible shape right now, but will get better over the coming month or so. With CCTM in particular it would be cool to be able to provide a kind of wordpress distro in just a few steps — that’s what I’m working towards. Loading the CCTM defs by default will cut one more step out..


    just had a look at the wordpress source —

    I am customizing wp_install_defaults and wp_install as per various guides e.g.:

    I looked at wp-admin/install.php and from what I can tell wp_install is called right at the end of the install process — so vanilla wordpres *should* be done with install when it finishes running. I’ve put my code right at the end of hte function, so I don’t see how the changes to wp_options would be reverted by wordpress. do you think CCTM is doing it somehow? thanks again,

    Plugin Contributor fireproofsocks


    Thanks Matt, for your careful attention to detail. It does sound like there should be a to customize this. I added a feature request:

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Custom Content Type Manager] importing CCT definitions at install time using wp-content/ins’ is closed to new replies.