How to add a function to retrieve data from a social media service

If you want to create your own social button and want to retrieve the number of shares via WordPress you can use the wpbfsb_get_remote_functions filter hook. You can find the filter in the classes/model/remote.php file (see get_remote_functions() function).

How to add a remote function

Crate a new plugin file and use the above mentioned filter hook to add a new function to the list:

<?php
/*
Plugin Name: My Fixed Social Share Remote Function for X
*/

add_filter( 'wpbfsb_get_remote_functions', 'my_wpbfsb_remote_fcn_add_x' );

/**
 * Adds a new function to the drop-down list on the edit screen.
 *
 * @param array $functions
 *
 * @return array
 */
function my_wpbfsb_remote_fcn_add_x( $functions ) {

	$functions['x'] = array(
		'label'    => __( 'Platform X', 'wpbfsb' ),
		'function' => 'my_wpbfsb_remote_get_x_statistics'
	);

	return $functions;
}

/**
 * Returns the number of shares, likes, etc.
 *
 * @param string|null $url
 *
 * @return int The number of shares, likes, etc.
 */
function my_wpbfsb_remote_get_x_statistics( $url = null ) {

	// retrieve the currents page URL
	$url = WPB_Fixed_Social_Share_Model_Remote::get_current_url( $url );

	// use the plugins remote functionality (supports caching)
	$parsed_results = WPB_Fixed_Social_Share_Model_Remote::remote(
	// name (important for caching)
		'google_plus_likes',

		// the url
		$url,

		// the url that should be pinged
		'https://clients6.google.com/rpc',

		// other POST parameters
		array(
			'method'  => 'post',
			'headers' => array(
				'Content-type' => 'application/json'
			),
			'body'    => '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]'
		)
	);

	// do whatever is needed to catch the number of shares
	if ( isset( $parsed_results[0]['result']['metadata']['globalCounts']['count'] ) ) {
		return $parsed_results[0]['result']['metadata']['globalCounts']['count'];
	}

	// otherwise return 0
	return 0;
}

Save your file maybe like my-fixed-social-share-remote-function-for-x.php and upload it to the wp-contents/plugins/ folder. Then activate it from the plugin list.

After this, add a new button and choose your just created function from the dropdown list like this.

Remote Function List
Choose the new function from the dropdown list