Changing default config for the Membership


I know that the Membership plugin stores options in wp_options and the rest of the data in tables with prefix m_. I would like to know how could I set some default configurations when the plugin is activated.

I’ve thought about using register activation hook and then do a insert query with the data on the database, but this hook only works if it is written inside the function and I would like to create this as a mu plugin so it doesn’t mess with updates of the membership plugin.

Any ideas?

  • DavidM
    • DEV MAN’s Mascot

    Hi transparencia,

    In case you didn’t see it already, Membership has its own plugin folder (membershipmembershipincludesplugins) where you could include your own plugins. I wouldn’t think extra files would be overwritten by an update but let me see if I can get the developer’s attention on this one as well as details on your specific request.



  • Barry
    • DEV MAN’s Mascot

    It shouldn’t overwrite new files when upgrading only replace those that already exist (though i honestly haven’t tested it too much so it may be worth checking).

    You could modify the upgrade.php file in membership to have custom code run when the plugin creates new tables – this file would be overwritten on updates though.

    I’ll add a hook into the new version that fires when a new installation has created it’s tables and then post back here with the details. If you then edit the upgrade.php file yourself and add that hook in, then create a plugin that has code that is fired when that hook is called – it should be future upgrade safe.

  • Barry
    • DEV MAN’s Mascot

    I’ve added the line:

    do_action( 'membership_create_new_tables' );

    at the very end of the function M_Createtables in the file membershipincludes/classes/upgrade.php

    If you add that line into your version, and then use something like:

    add_action('membership_create_new_tables',' my_default_config_function');

    in a separate plugin or in an add-on placed in the membership plugins membershipincludes/plugin directory.

    you can then put in the default config set-up code in your new function. The hook will fire when membership is newly activated on a site, but won’t be run for upgrades (e.g. that function is only run on initial installation).

    Let me know if that helps, or you need anything else added in for the next version.

  • transparencia
    • Design Lord, Child of Thor

    Hi Barry!

    It helps, I’ve added the hook in upgrades.php: M_createtables() and I’ve actually created a /plugin/default-config.php with this code:


    function membership_default_config ()
    global $wpdb;

    //Define the premium category
    $premium_cat = array('cat_name' => 'Premium Content', 'category_description' => 'Free users cannot see this.', 'category_nicename' => 'premium-content', 'category_parent' => '');

    // Create the category
    $my_cat_id = wp_insert_category($premium_cat);

    // Create post object
    $my_post = array(
    'post_title' => 'Premium Post',
    'post_content' => 'Free users cannot see this post.',
    'post_status' => 'draft',
    'post_author' => 1,
    'post_category' => array($my_cat_id)

    // Insert the post into the database
    wp_insert_post( $my_post );


    add_action('membership_create_new_tables',' membership_default_config');


    But then it doesn’t do anything, it doesn’t add anything to the tables. What do you think is wrong?

  • Barry
    • DEV MAN’s Mascot

    Can you do a quick experiment on a test site?

    Change the content of your function to just do a wp_mail() call to send you an email message – then you can see if it is fired correctly – that way we can narrow down the actual firing of the function from the content for debugging purposes.

  • Mason
    • DEV MAN’s Sidekick

    Hiya transparencia,

    Were you able to test according to Barry’s instructions? I’m going to leave this one open for the time being, but we’re keen to get this sorted for you quickly and with your help :slight_smile:

    If we don’t hear back from you soon, we’ll probably go ahead and mark this as resolved – but even doing that you can re-open at anytime and continue receiving support on this.


  • Mason
    • DEV MAN’s Sidekick


    Just noting that as we haven’t heard from you in about a month that we’re going to mark this one resolved. The new version of Membership really does a great job of making sure the database is up to date so please download this and give it a shot!


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.