<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
/**
 * Sanitization callback function for the Sifency Addons settings.
 *
 * This function is registered with `register_setting()` and is called by WordPress
 * before saving the options to the database. It receives the raw input from the form
 * and must return a clean, safe array of data to be stored.
 *
 * @param array $input The raw array of settings submitted from the form.
 * @return array The sanitized array of settings to be saved.
 */
function sifency_addons_sanitize_options( $input ) {

	$sanitized_input = array();

	$existing_options = get_option( 'sifency_addons_settings', array() );
	$sanitized_input  = $existing_options;

	if ( isset( $input['api_key'] ) ) {
		$sanitized_input['api_key'] = sanitize_text_field( $input['api_key'] );
	}

	if ( isset( $input['enable_awesome_feature'] ) && '1' === $input['enable_awesome_feature'] ) {
		$sanitized_input['enable_awesome_feature'] = '1';
	} else {
		$sanitized_input['enable_awesome_feature'] = '0';
	}

	if ( isset( $input['default_layout'] ) ) {
		$allowed_layouts  = array( 'grid', 'list', 'carousel' );
		$submitted_layout = $input['default_layout'];

		if ( in_array( $submitted_layout, $allowed_layouts, true ) ) {
			$sanitized_input['default_layout'] = $submitted_layout;
		} else {
			$sanitized_input['default_layout'] = 'grid';
		}
	}

	if ( isset( $input['notification_email'] ) ) {
		$sanitized_input['notification_email'] = sanitize_email( $input['notification_email'] );
	}

	if ( isset( $input['items_per_page'] ) ) {
		$sanitized_input['items_per_page'] = absint( $input['items_per_page'] );
	}

	return $sanitized_input;
}
function sifency_is_pro() {
	if ( class_exists( 'Sifency_Addons_Theme_Builder_Master' )
		&& method_exists( 'Sifency_Addons_Theme_Builder_Master', 'sync_environment_state' ) ) {
		return Sifency_Addons_Theme_Builder_Master::sync_environment_state();
	}
	return false;
}
