007_TF_Embedding-Titan-Framework-in-Your-ProjectThis tutorial is helpful to make your project independent. Requiring your users to install another plugin to activate your plugin might be a hassle for some people.

However, one caveat would be that since the framework is embedded, updates and bug fixes to the framework won’t be available. You would have to be the one to push out updates to your project if you need to update the embedded framework.

The method will show you how to use the embedded copy of the framework in your project. And when the framework plugin is activated, the plugin will be used instead of the embedded one.

The two methods

There are two methods available for use, depending on the Titan Framework installed.

The new version of embedding

This method applies to version 1.6 and above. For older methods, refer further below.

  1. Create a folder named titan-framework in your project and put all the framework code there. (important: the PHP scripts should be inside the titan-framework folder)Afterwards, in your functions.php or your main plugin script, add the code below:
  2. Afterwards, in your functions.php or your main plugin script, add the code below:

Then proceed normally with creating your options.

The old version of embedding

This method is for older versions 1.1.1 to 1.5.x

  1. Create a folder named titan-framework in your project and put all the framework code there. (important: the PHP scripts should be inside the titan-framework folder)Afterwards, in your functions.php or your main plugin script, add the code below as your first lines.
  2. Afterwards, in your functions.php or your main plugin script, add the code below as your first lines.

After that, you can proceed normally to creating your options.

Changelog

08/03/2014

  • New method of embedding

03/31/2014

  • Now requires correctly for plugins and themes (thanks @Sagar)

03/26/2014

  • Now also detects for other embedded frameworks (thanks @MickeyKay and @pagelab)

14 thoughts

  1. Hi,

    If the framework is embeded in the theme, how the plugin version deals with it? It just ignores it?

    Thanks!

    1. Your theme will use it’s embedded copy, but when the framework plugin is activated, it’ll be used instead.

  2. Hi,
    This is awesome plugin.
    Your given code has a one issue. we should use theme path instead of plugin path when embedding framework.
    This line
    “require_once( plugin_dir_path( __FILE__ ) . ‘titan-framework/titan-framework.php’ );”
    should be
    require_once( get_template_directory() . ‘/titan-framework/titan-framework.php’ );

    Please correct me If I am doing something wrong.

    Thanks

  3. Hey Benjamin,

    I must be doing something really stupid but I have no idea why my options aren’t getting saved. The form is displayed (I’m using the demo code exactly as it is, with a require to a file), but when I click “save” it reloads all blank again and if I check the db I still get an empty theme options ( s:35:”a:1:{s:14:”my_text_option”;s:0:””;}”; )

    Do you have any idea of what could be the reason for this?

    Kind Regards,
    -Roch

  4. Hey Benjamin,

    I must be doing something really stupid but I have no idea why my options aren’t getting saved. The form is displayed (I’m using the demo code exactly as it is, with a require to a file), but when I click “save” it reloads all blank again and if I check the db I still get an empty theme options ( s:35:”a:1:{s:14:”my_text_option”;s:0:””;}”; )

    Do you have any idea of what could be the reason for this?

    Kind Regards,
    -Roch
    [getting a weird error with your comments form so I’m not sure if you’re getting this]

  5. In addition to my previous comment, metaboxes are being created / saved fine (I’m using for a plugin to I don’t care about theme customizer options).

    Kind Regards,
    -Roch

  6. Hi, I tried using this tutorial to embed Titan Framework into my theme but I am getting this error “Class ‘TitanFramework’ not found” am I doing anything wrong?

    I had to change this line

    new TitanFrameworkEmbedder();

    to this

    (new TitanFrameworkEmbedder())->perform_check();

    Regards
    Ammar

Leave a Reply