File "BeaconDeactivationTracker.php"

Full Path: /home/jlklyejr/public_html/post-date/wp-content/plugins/flexible-shipping/src/WPDesk/FS/TableRate/Beacon/BeaconDeactivationTracker.php
File size: 997 bytes
MIME-type: text/x-php
Charset: utf-8

<?php
/**
 * Deactivation tracker data.
 *
 * @package WPDesk\FS\TableRate
 */

namespace WPDesk\FS\TableRate\Beacon;

use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable;

/**
 * Can add beacon data to deactivation tracker data.
 */
class BeaconDeactivationTracker implements Hookable {

	const ADDITIONAL_DATA = 'additional_data';

	/**
	 * Hooks.
	 */
	public function hooks() {
		add_filter( 'wpdesk_tracker_deactivation_data', [ $this, 'append_beacon_data_to_deactivation_tracker' ] );
	}

	/**
	 * Set new rules table data to data array.
	 *
	 * @param array $data Data.
	 *
	 * @return array
	 * @internal
	 */
	public function append_beacon_data_to_deactivation_tracker( array $data ) {
		if ( empty( $data[ self::ADDITIONAL_DATA ] ) || ! is_array( $data[ self::ADDITIONAL_DATA ] ) ) {
			$data[ self::ADDITIONAL_DATA ] = [];
		}

		$data[ self::ADDITIONAL_DATA ]['beacon'] = [ 'clicked' => 1 === (int) get_option( BeaconClickedAjax::OPTION_NAME, 0 ) ? 'yes' : 'no' ];

		return $data;
	}
}