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?

  • Barry

    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

    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

    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?