<?php
/**
 * CFX License Manager Helper
 *
 * @package    Instalist
 * @link       htps://codingfix.com
 * @since      1\.0\.0
 * @author     Marco Gasi
 *
 * Plugin Name:       WordPress API Plugin Boilerplate
 * Description:       Provides a boilerplate starting point for creating custom WP API endpoints
 * Version:           1\.0\.0
 */

/**
 * CFX License Manager Helper Class
 *
 * @package    Instalist
 * @subpackage Instalist/includes
 * @since      1\.0\.0
 * @author     Marco Gasi
 */
class CFX_Helper {

	/**
	 * Create a custom log file for the plugin.
	 *
	 * @param mixed $message The message to log (string, array, or object).
	 */
	public static function custom_log( $message ) {
		$log_file = WP_CONTENT_DIR . '/debug-custom.log';
		if ( is_array( $message ) || is_object( $message ) ) {
			error_log( print_r( '[' . gmdate( 'Y-m-d H:i:s' ) . '] ' . $message, true ), 3, $log_file );
		} else {
			error_log( '[' . gmdate( 'Y-m-d H:i:s' ) . '] ' . $message . "\n", 3, $log_file );
		}
	}

	/**
	 * Check if Pluginer Premium is fully active (license valid and plugin active).
	 *
	 * @return bool True if Pluginer Premium is fully active, false otherwise.
	 */
	public static function is_premium_fully_active() {
		$license = get_option( 'pluginer_license_data', array() );

		$has_license = ( ! empty( $license['status'] ) && 'active' === $license['status'] );
		$has_addon   = function_exists( 'Pluginer_Premium' ) || defined( 'PLUGINER_PREMIUM_VERSION' );

		return ( $has_license && $has_addon );
	}

	/**
	 * Send response back to javascript ajax caller.
	 *
	 * @param    array $response The result of the API query.
	 *
	 * @since    1.0.0
	 */
	public static function plgnr_return_response( $response ) {
		echo wp_json_encode( $response );
		wp_die();
	}
}
