<?php
/**
 * Plugin Name: Gustavo Portfolio Core
 * Plugin URI:  https://gustavoo.me/
 * Description: Conteúdo, configurações e integrações do portfólio de Gustavo Oliveira.
 * Version:     1.6.0
 * Requires at least: 6.5
 * Requires PHP: 8.0
 * Requires Plugins: fluentform, fluent-crm, fluent-smtp
 * Author:      Gustavo Oliveira
 * Author URI:  https://gustavoo.me/
 * Text Domain: gustavoo-portfolio-core
 * License:     GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 *
 * @package GustavoPortfolioCore
 */

defined( 'ABSPATH' ) || exit;

define( 'GSO_PORTFOLIO_CORE_VERSION', '1.6.0' );
define( 'GSO_PORTFOLIO_CORE_FILE', __FILE__ );
define( 'GSO_PORTFOLIO_CORE_DIR', plugin_dir_path( __FILE__ ) );

require_once GSO_PORTFOLIO_CORE_DIR . 'includes/class-gso-projects.php';
require_once GSO_PORTFOLIO_CORE_DIR . 'includes/class-gso-portfolio-settings.php';
require_once GSO_PORTFOLIO_CORE_DIR . 'includes/class-gso-newsletter-widget.php';
require_once GSO_PORTFOLIO_CORE_DIR . 'includes/class-gso-seeder.php';
require_once GSO_PORTFOLIO_CORE_DIR . 'includes/class-gso-portfolio-core.php';

register_activation_hook( __FILE__, array( 'GSO_Portfolio_Core', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'GSO_Portfolio_Core', 'deactivate' ) );

GSO_Portfolio_Core::init();

if ( ! function_exists( 'gso_portfolio_get_settings' ) ) {
	/**
	 * Return all portfolio settings merged with defaults.
	 *
	 * @return array<string, mixed>
	 */
	function gso_portfolio_get_settings() {
		return GSO_Portfolio_Settings::get_settings();
	}
}

if ( ! function_exists( 'gso_portfolio_get_setting' ) ) {
	/**
	 * Return one portfolio setting.
	 *
	 * @param string $key     Setting key.
	 * @param mixed  $default Fallback value.
	 * @return mixed
	 */
	function gso_portfolio_get_setting( $key, $default = null ) {
		$settings = gso_portfolio_get_settings();

		return array_key_exists( $key, $settings ) ? $settings[ $key ] : $default;
	}
}

if ( ! function_exists( 'gso_render_fluent_form' ) ) {
	/**
	 * Render a Fluent Form using a trusted numeric ID.
	 *
	 * @param int $form_id Fluent Forms form ID.
	 * @return string
	 */
	function gso_render_fluent_form( $form_id ) {
		$form_id = absint( $form_id );

		if ( ! $form_id || ! shortcode_exists( 'fluentform' ) ) {
			return '';
		}

		return do_shortcode( sprintf( '[fluentform id="%d"]', $form_id ) );
	}
}

if ( ! function_exists( 'gso_portfolio_render_fluent_form' ) ) {
	/**
	 * Backwards-compatible descriptive alias for the form helper.
	 *
	 * @param int $form_id Fluent Forms form ID.
	 * @return string
	 */
	function gso_portfolio_render_fluent_form( $form_id ) {
		return gso_render_fluent_form( $form_id );
	}
}
