New Blog Templates Custom Integration

Hello :slight_smile:

I'm trying to customly integrate the New Blogs Templates plugin into Gravity Forms where it's bound on the user selection (unknowingly).

The code provided within the plugin is quite cloudy as an outsider. I'm wondering what I need to send to WordPress to overwrite the default template and select the one based upon a selection.

A simple mock-up code would look like this:

$awesome_template = '1';
$another_template = '2';
$selected_form_option = strstr($entry['9'], '|', true); // outputs e.g. 1, 2 or 3

if ($selected_form_option == 2) {
add_blog_option($site_id, 'blog_template', $awesome_template);
} else if ($selected_form_option == 3) {
add_blog_option($site_id, 'blog_template', $another_template);
}

I'm quite unsure if this would work because I see you guys are integrating the nbt_get_model function which does a lot of SQL queries...
I also cannot find this meta value back on the existing blogs using a template.

Any idea's?

  • Predrag Dubajic

    Hey @Sybre,

    Hope you're doing well today :slight_smile:

    I understand that this is only mockup of the code you are looking to use but did you already tested something to see what is going on?

    I am tagging an available developer from second level support line in this thread for his valuable opinion on this issue. Please note that, developer response might be slower than usual staff response, so we appreciate your patience on this.

    Best regards,
    Predrag

  • Jose

    Hello there @Sybre,

    Hope you are doing well today.

    I found this thread missed in the queue while doing some house cleaning. It got missed somehow, so apologizes about it.

    Wondering if you are still working on this.

    I'm not sure if you are aware, but latest releases of NBT have built-in integration with GF using the User Registration add-on. Are you trying to achieve something different here?

    Please advise,

    Cheers,
    Jose

    • Sybre Waaijer

      Hi @Jose, thanks for dropping by!

      What I want to achieve is that the NBT plugin runs in the background without the users' knowledge. So if a user were to select option A of something in Gravity Forms, they'll get blog template A. If they were to select option B of something in Gravity Forms, they'll get blog template B, and so on.

      This could be an awesome way to preemptively fill in the blog based on the selection the user made, for example if they wanted a webshop so they'll get a blog template specifically for that, without selecting the blog template for it afterwards.

      An example code would be:

      add_action("gform_site_created", "fire_blog_template_code", 10, 4);
      function fire_blog_template_code($site_id, $user_id, $entry, $config) {
      global $wpdb;
      if ($entry['8'] == 'A') {
      //get template A for $site_id
      } else if ($entry['8'] == 'B' ) {
      //get template B for $site_id
      }
      }

      I hope this informs you well enough :slight_smile: Have a great day!

  • Jose

    Well, in that case, you can simply modify the existing GF integration.

    You will find the integration routine in the file ..wp-content/plugins/blogtemplates/blogtemplatesfiles/integration.php, line 187.

    The trick is in the method nbt_save_new_blog_meta().
    There, you would want to change this part:

    if ( isset( $_POST['blog_template' ] ) && $model->get_template( absint( $_POST['blog_template'] ) ) )
    		$meta['blog_template'] = absint( $_POST['blog_template'] );

    In something like this:

    if ( !empty( $_POST['interests_field'] ){//Assuming that your field name will be 'interests_field'.
            switch($_POST['some_field']){
    
                case 'webshop':
                    $meta['blog_template'] = 1;//Assuming that template ID for webshops is 1.
                    break;
                case 'portfolio':
                    $meta['blog_template'] = 2;//Assuming that template ID for portfolio is 2.
                    break;
                case 'classifieds':
                    $meta['blog_template'] = 3;//Assuming that template ID for classifieds is 3.
                    break;
            }
        }

    Hope this helps to point you in the right direction :slight_smile:

    Side note: you MUST have a dev environment where to test this :wink:

    Cheers,
    Jose

  • Jose

    Sure thing.

    This would do the trick:

    add_action( 'nbt_object_create', 'set_gravity_forms_hooks', 20 );//Hook on priority 20 to ensure that default hooks are already added.
    
    function override_gravity_forms_hooks( $blog_templates ) {
        //Remove default hooks.
        remove_filter( 'gform_user_registration_new_site_meta', 'nbt_save_new_blog_meta' );
        remove_filter( 'gform_user_registration_signup_meta', 'nbt_save_new_blog_meta' );
        //Add custom hooks.
        add_filter( 'gform_user_registration_new_site_meta', 'custom_nbt_save_new_blog_meta', 20 );
        add_filter( 'gform_user_registration_signup_meta', 'custom_nbt_save_new_blog_meta', 20 );
    }
    
    function custom_nbt_save_new_blog_meta( $meta ){
        //Copy/paste the code from nbt_save_new_blog_meta() here and apply the modifications.
    }

    Cheers!
    Jose

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.