Subscribe by Email and Facebook

I have the plugins: subscribe by email, ultimate facebook, slide-in/popup.

How can I use these together to allow a user to easily subscribe to a network site using their email or facebook?

  • Adam Czajczyk

    Hello fonderco!

    Currently these two plugins are not integrated. The Subscribe by Email plugin requires user to fill in subscription form and Ultimate Facebook can't do this automatically.

    A workaround that I'm thinking of may be to use Ultimate Facebook in a regular way so users could login/register via Facebook to your site (you could also put a FB Connect widget near the Subscribe form on page) and then use some custom code to "pre-fill" the subscription form with user e-mail address fetched from his/her profile.

    There are two aspects of such an approach though that are worth noting:

    1. Subscription "by Facebook" would automatically create a user account for that user on your site (register user)

    2. This would also automatically subscribe all logged in users of your site.

    I haven't tried that yet but it should be doable with a bit of custom code. The workflow of the code would be like this:

    - fetch logged in user's e-mail address from his/her profile
    - fill subscription widget form with that e-mail with JS
    - submit form with JS

    This code seems to be working fine on my test setup:

    <?php
    function auto_subscribe_by_email() {
    	$logged_user = wp_get_current_user();
    	$logged_user_mail = $logged_user->user_email;
    	?>
    	<script type="text/javascript">
    	document.getElementsByClassName('sbe-widget-form-field')[0].setAttribute("value", "<?php echo $logged_user_mail;?>");
    	document.forms["sbe-widget-subscribe-form-2"].submit();
    	</script>
    	<?
    }
    
    add_action('wp_footer','auto_subscribe_by_email');

    To use it create an empty file with a ".php" extension, put the code inside and upload it to your server to the "/wp-content/mu-plugins" folder. If there's no "mu-plugins" folder inside "wp-content" folder, simply create it.

    The code takes an e-mail of a logged in user and then if there's a Subscribe by E-mail widget on a page it fills in the form and submits it automatically. If a user is already subscribed and logged in the subscription form won't be visible (Subscribe by Email plugin takes care of it) and instead an information of subscription will be shown - therefore the form won't be filled and submited again.

    Depending on your policy you may or may not enable "auto opt-in" option in Subscribe by Email settings. If it's disabled, there'll be a "Thank you" message shown until user confirms subscription by clicking on a link in a confirmation e-mail. Otherwise, user should be fully subscribed automatically.

    Best regards,
    Adam