Custom Effects Integration for Wordpress

Wordpress implementation custom effects

 
If you want to use "Custom effects" you need to follow steps described below:
 
Step 1. Add SDK for the usage of "Custom effects".
wp_enqueue_script('sosdk', 'http://api-dev.solidopinion.com/api/dev/sosdk.php');
Step 2. Create js script for your "Custom effects" and put it in your active theme folder.
wp_enqueue_script('add_effect-script', get_template_directory_uri() . '/js/solidopinion_effects.js');
Step 3. In SolidOpinion_effects.js paste function getPoints(code) which send AJAX request with your effect code.

Note: Don't forget to change YOUR_EFFECT_CODE to your effect code.
function getPoints(code){
    jQuery.post(
        myajax.url,
        {
            action : 'add_effect',
            effectcode: code,
            usercode: SOSDK.usercode
        },
        function( response ) {
            console.log( response );
        }
    );
}

( function( $ ) {
       // Set customm effect to any events on your site
       // For example: click to button with id custom_effect 
	$( document ).on( 'click', '#custom_effect', function( e ) {
		getPoints('YOUR_EFFECT_CODE');
	} );
} )( jQuery );
Step 4. Paste this code to your theme file functions.php.

Note: Don't forget to change YOUR_SOLIDOPINION_SHORNAME  to your site shorname
add_action('wp_enqueue_scripts', 'add_effect_load_scripts');
add_action( 'wp_ajax_nopriv_add_effect', 'myajax_submit' );
add_action( 'wp_ajax_add_effect', 'myajax_submit' );

function add_effect_load_scripts() {
    wp_enqueue_script('sosdk', 'http://api-dev.solidopinion.com/api/dev/sosdk.php');
    wp_enqueue_script('add_effect-script', get_template_directory_uri() . '/js/solidopinion_effects.js');
    wp_localize_script('add_effect-script', 'myajax', array( 'url'   => admin_url('admin-ajax.php') ) );
}

function myajax_submit() {
    if(isset($_POST['usercode'])) {

        $ch = curl_init();

        $postData = 'sitename=YOUR_SOLIDOPINION_SHORNAME&usercode='.$_POST['usercode'].'&effectcode='.$_POST['effectcode'];
        curl_setopt($ch, CURLOPT_URL,'api-dev.solidopinion.com/api/user/adduserpoints');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POST, count($postData));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

        $output = curl_exec($ch);

        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($httpCode == 200) {
             echo("OK! api-dev.solidopinion.com/api/user/adduserpoints/".$postData);
        }
        else {
            echo("FAIL! ".$httpCode." ".$output);
        }

        curl_close($ch);

    }
	exit;
}
Step 5. Add your server IP to allowed IP's in your integration settings on SolidOpinion backend.



Step 6. Click the "Save changes" button.




Happy commenting!
SolidOpinion

Feedback and Knowledge Base