Is there a way to wipe the data from a table created with New Blog Template?

Good Afternoon

I am using the New Blog Template plugin and when creating a new blog, I need to have a table from one of the plugins copied over but I don't need the data from the original table. Is there a way I can have the table copied over and then easily have it drop all the data so it is just a blank table? I found if I don't check the box for the table, it isn't created; but if the box is checked, the table is created with all the existing data.
Any help on this would be greatly appreciated. I love the plugin and am hoping there is an easy way to do this.

Thanks

Dustin

  • Vaughan

    hiya

    thanks for posting.

    unfortunately this isn't possible. you would need some custom coding to achieve this and i'm not sure how it would be done. I will need to ping the developer for more feedback on this, but he has just gone on vacation till the 26th.

    You might be able to find a developer to do this over at wpmu-jobs if it's an urgent matter, or if it's possible you could wait for him to return?

    hope this helps.

    thanks.

  • Ignacio

    Hi @Dustin.

    As Vaoughan pointed out, you'll need some custom coding, yet is not pretty difficult. You can use blog_templates-process_row filter. Here's a little example:

    add_filter('blog_templates-process_row', 'wipe_my_table', 10, 2);
    
    function wipe_my_table( $row, $table_name ) {
       if ( $table_name === 'my_table_name' )
          return false;
       else
          return true;
    
    }

    This will be executed when a table is being copied. New Blog Templates, pick every row and executes that code. If false is returned the row will not be copied.

    Regards.
    Ignacio.

  • Dustin

    Hi @Ignacio

    Thanks for the example. Looking at this, it looks like I just have to put in the table name I want wiped out as 'my_table_name', right? I just need to add this in my functions.php to make it work? I try not to add in to the actual plugin if at all possible because I don't want to worry about it being overwritten when there is an update.

    This will come in very handy because I have a couple of tables I will have to do this with.

    Thanks

    Dustin

  • Ignacio

    Hi @Dusting.

    Yes, you should replace my_table_name for your table name. I did not test the code but should work. Anyway, try not to test it in a place where you could loose data and do a backup of the tables before.

    You can add that code to your functions.php or even better in a plugin created by you, but functions.php could work.

    If you don't know how to create plugins, just read this. Is really easy to create a basic plugin like that:

    https://codex.wordpress.org/Writing_a_Plugin

    Just create it, add the function and network activate it.

    Regards.
    Ignacio.

  • Dustin

    Ignacio

    Thanks for the help with this. I actually found a new approach to this so I don't need to do this. I actually deactivated the plugin and instead of network activating it, I only activated it on my template site. I also made sure I didn't have any records in the database for the plugin in my template site. That way, when the new blog template creates the new site, the plugin is automatically added to the new site and the database table is a fresh table. I will keep a hold of this for future reference though.

    Thanks

    Dustin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.