[New Blog Templates] Programmatically add option to new blog templates?

I would like to have the ability to add an option from my custom plugin into New Blog Templates plugin when creating a new blog template. The reason for this is so that I can set a blog_option for the new blog template that will later be used to see if one of my custom functions for copying the users profile information into the site should be triggered or not. It would be super simple such as a Yes or No box which runs:

add_blog_option ($blog_id, 'copy_profile_info', $copy_profile_info_value);

Is this possible?

  • Nahid

    Hey Buddy !
    Hope you are having a great day!

    This request has been escalated to the Second Level Support team. They'll be back to us with confirmations if something like this would be achievable within New Blog Templates in this ticket (or we'll be updating the ticket as soon as we hear back from them internally). Please note that the response time of the Second Level Support team might be a bit delayed than that of the general Support staff. Moreover, as this is a custom request, we cannot assure a workaround from our end just yet without investigation. This might get flagged as a feature request or you might need to consider custom development if this turns out to be undoable from our end. We really appreciate your patience and consideration regarding this.

    Kind regards,
    Nahid

  • Konstantinos Xenos

    Hi Buddy ,

    I made some changes in the plugin and I'm attaching a zip with these changed files :
    blogtemplates\blogtemplatesfiles\copier.php
    blogtemplates\blogtemplatesfiles\admin\main_menu.php

    Please replace the original files via FTP or your server's File Manager, but make sure to keep a backup first ( if possible a full website backup as well before proceeding to be safe ).

    What's new in here:
    When you create a new Blog Template, you'll find a new option called Profile Info as seen in the screenshot ( attached ). If selected there will be a new action firing whenever you create a new Site and it's template has this option enabled. You can easily hook into that for example with:

    add_action( 'nbt_add_profile_info', 'my_test_function' );
    function my_test_function() {
    	// run your code here
    }

    If you need further assistance please tell us. Also keep in mind that this will probably not be on an upcoming release since it's just for your specific tasks, so be mindful of any plugin updates as they will overwrite this code.

    Regards,
    Konstantinos

  • Konstantinos Xenos

    Hey Buddy !

    From your last comment I see that you're trying to get blog_id, user_id, probably you want the 'new' created blog id and the 'new' user that is getting created when you're creating a blog, correct? ( I'm not sure what the $meta is though that you're trying to read with it so I'll need some more feedback on that ).

    In any case inside our currently edited blogtemplatesfiles\copier.php at line 467 you'll find

    public function copy_profile_info() {
    	do_action( 'nbt_add_profile_info' );
    }

    This is what fires if you have the Profile Info option enabled ( options need a callback function ), and we're currently hooking into that by simply adding the do_action in there.

    If you change that to:

    public function copy_profile_info() {
    	$args = array(
    		'from_blog_id' => $this->template['blog_id'],
    		'to_blog_id'   => $this->new_blog_id,
    		'new_user_id'  => $this->user_id,
    	);
    	do_action( 'nbt_add_profile_info', $args );
    }

    Then you can change the test_function into something like this:

    add_action( 'nbt_add_profile_info', 'my_test_function' );
    function my_test_function( $args ) {
    	error_log( 'copying from: ' . $args['from_blog_id'] );
    	error_log( 'copying to: ' . $args['to_blog_id'] );
    	error_log( 'new user created id: ' . $args['new_user_id'] );
    }

    This gives you access to the "from_blog_id" blog id that you've made your template from, the blog id that gets created ( to_blog_id ) , and the user id that gets created as well ( new_user_id ).

    If you want I can provide an edited copier.php again if you don't feel comfortable editing the plugins files.

    Inside copier.php we already have plenty of actions and filters, but since the options have a callback function as I mentioned before this would be the easiest way for you to pass any information from the copier mechanism into your own functions.

    I hope this helps a bit more!

    Regards,
    Konstantinos

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.