Plugin Customization Lost During Plugin Upgates

You have two options I can see after looking at the plugin, although there may be other ways to tackle this my time is limited so I’ll give you some insight on what you can do now, in the interim.

First of all the plugin author provides you some additional filters:

  • newsletter_profile_extra
  • newsletter_subscription_extra
  • newsletter_profile_save

(see newsletter/subscription/subscription.php)

You can use these filters to add additional controls to the appropriate subscription and profile pages.

However, note that from a glance, there does not appear to be any filters to augment the existing fields such as the sex/gender field.

But… What you can do is use these filters to add an extra field like a checkbox that asks the user whether they are a couple and if they mark this checkbox you can use the third filter newsletter_profile_save to filter the values before they are inserted into the database.

At this point, you would determine that IF the checkbox is marked then you replace the sex post value with “couple” or “c” or whatever the database value you wish to be stored for later retrieval:

//pseudo-code example
if ( isset($_POST['are_you_a_couple']) && $_POST['are_you_a_couple'] === 1 ) {
   $_POST['sex'] = 'couple';
}

The process described above is a high level overview only and is far more work than my next proposed solution which is to enqueue your own, custom JavaScript file on the appropriate pages where the form controls show and add the additional option to the sex/gender drop down field.

An example would be to add the following code to your theme functions.php file:

/**
 * Proper way to enqueue scripts and styles
 */
function custom_newsletter_scripts() {
    wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/custom-control.js', array(), '1.0.0', true );
}

add_action( 'wp_enqueue_scripts', 'custom_newsletter_scripts' );

Then create you custom-control.js file in your theme placed under the /js/ directory or wherever you wish to store the script, just ensure your path reflects that in your call to wp_enqueue_script above.

In your JavaScript file you may do something to this effect:

;(function($){

  $(document).ready(function(){

     $('#gender_select_menu')
         .append($("<option></option>")
         .attr("value",'c')
         .text('Couple')); 

  });

})(jQuery);

Code example is rough, execute your JavaScript as per your liking, if the control does not exist at the point of DOMReady you might wish to add a timeout or modify the DOM on $(window).load(function(){});

This should be enough to get you going in the right direction and keep your changes future proof from any further loss on plugin updates.