Filter uncanny-continuing-education-credits

edd_sl_plugin_updater_api_params

Filters the parameters sent in the API request. Filters the API parameters used for plugin updates before the request is sent.

add_filter( 'edd_sl_plugin_updater_api_params', $callback, 10, 1 );

Description

Modify the parameters sent to the plugin licensing API for version checks. This filter allows developers to add, remove, or alter data like license keys, item names, or IDs before the API request is made. Useful for custom license validation or dynamic API requests.


Usage

add_filter( 'edd_sl_plugin_updater_api_params', 'your_function_name', 10, 1 );

Parameters

$api_params (array)
The array of data sent in the request.

Return Value

The filtered value.


Examples

// Example: Add extra data to the EDD Software Licensing API request for plugin updates.
// This could be used, for example, to send the active theme or custom user roles.
add_filter( 'edd_sl_plugin_updater_api_params', 'my_custom_edd_sl_api_params', 10, 3 );

function my_custom_edd_sl_api_params( $api_params, $api_data, $plugin_file ) {

	// Ensure we're dealing with a valid array before proceeding.
	if ( ! is_array( $api_params ) ) {
		return $api_params;
	}

	// Add a custom parameter to the request.
	// For instance, let's add the active theme slug.
	$theme = wp_get_theme();
	if ( $theme ) {
		$api_params['active_theme_slug'] = $theme->get_stylesheet();
	}

	// You could also add other relevant information from $api_data or global WordPress environment.
	// For example, to send a custom identifier if it's present in $api_data:
	if ( isset( $api_data['custom_identifier'] ) ) {
		$api_params['custom_id'] = $api_data['custom_identifier'];
	}

	// It's important to return the modified $api_params array.
	return $api_params;
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/includes/EDD_SL_Plugin_Updater.php:603

private function get_version_from_remote() {
		$api_params = array(
			'edd_action'  => 'get_version',
			'license'     => ! empty( $this->api_data['license'] ) ? $this->api_data['license'] : '',
			'item_name'   => isset( $this->api_data['item_name'] ) ? $this->api_data['item_name'] : false,
			'item_id'     => isset( $this->api_data['item_id'] ) ? $this->api_data['item_id'] : false,
			'version'     => isset( $this->api_data['version'] ) ? $this->api_data['version'] : false,
			'slug'        => $this->slug,
			'author'      => $this->api_data['author'],
			'url'         => home_url(),
			'beta'        => $this->beta,
			'php_version' => phpversion(),
			'wp_version'  => get_bloginfo( 'version' ),
		);

		/**
		 * Filters the parameters sent in the API request.
		 *
		 * @param array  $api_params        The array of data sent in the request.
		 * @param array  $this->api_data    The array of data set up in the class constructor.
		 * @param string $this->plugin_file The full path and filename of the file.
		 */
		$api_params = apply_filters( 'edd_sl_plugin_updater_api_params', $api_params, $this->api_data, $this->plugin_file );

		$request = wp_remote_post(
			$this->api_url,
			array(
				'timeout'   => 15,
				'sslverify' => $this->verify_ssl(),
				'body'      => $api_params,
			)
		);

		if ( is_wp_error( $request ) || ( 200 !== wp_remote_retrieve_response_code( $request ) ) ) {
			$this->log_failed_request();

			return false;
		}

		$request = json_decode( wp_remote_retrieve_body( $request ) );

		if ( $request && isset( $request->sections ) ) {
			$request->sections = maybe_unserialize( $request->sections );
		} else {
			$request = false;
		}

		if ( $request && isset( $request->banners ) ) {
			$request->banners = maybe_unserialize( $request->banners );
		}

		if ( $request && isset( $request->icons ) ) {
			$request->icons = maybe_unserialize( $request->icons );
		}

		if ( ! empty( $request->sections ) ) {
			foreach ( $request->sections as $key => $section ) {
				$request->$key = (array) $section;
			}
		}

		return $request;
	}

Scroll to Top