<?php
/**
 * Plugin Name: UGCify – UGC for WooCommerce
 * Plugin URI: https://rextheme.com/
 * Description: Automatically collect and display customer photos and videos on WooCommerce product pages. Self-hosted. No monthly fees. Real social proof.
 * Version: 1.0.3
 * Requires at least: 6.1
 * Requires PHP: 7.4
 * Author: RexTheme
 * Author URI: https://rextheme.com
 * License: GPL v2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: ugcify
 * Domain Path: /languages
 *
 * @package Ugcify
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// Define plugin constants.
define( 'UGCIFY_VERSION', '1.0.3' );
define( 'UGCIFY_FILE', __FILE__ );
define( 'UGCIFY_PATH', plugin_dir_path( __FILE__ ) );
define( 'UGCIFY_URL', plugin_dir_url( __FILE__ ) );
define( 'UGCIFY_BASENAME', plugin_basename( __FILE__ ) );

// License constants.
$ugcify_protocol = ( ( ! empty( $_SERVER['HTTPS'] ) && 'off' !== $_SERVER['HTTPS'] ) || ( ! empty( $_SERVER['SERVER_PORT'] ) && 443 === (int) $_SERVER['SERVER_PORT'] ) ) ? 'https://' : 'http://';
define( 'UGCIFY_INSTANCE', str_replace( $ugcify_protocol, '', get_bloginfo( 'wpurl' ) ) );
unset( $ugcify_protocol );
define( 'UGCIFY_EDD_STORE_URL', 'https://rextheme.com' );
define( 'UGCIFY_EDD_LICENSE_URL', 'http://license.getwpfunnels.com/api/v1/licence' );
define( 'UGCIFY_EDD_ITEM_ID', 416274 );

// WordPress.org package URL for the free build. Used to restore the free version
// from the repo when a pro license is deactivated. A direct package download
// bypasses the update API, so it works even though the pro build carries an
// "Update URI" header that blocks WordPress.org auto-updates.
if ( ! defined( 'UGCIFY_WP_ORG_PACKAGE' ) ) {
	define( 'UGCIFY_WP_ORG_PACKAGE', 'https://downloads.wordpress.org/plugin/ugcify.latest-stable.zip' );
}

// Optional: set in wp-config.php when the EDD store is protected by HTTP Basic Auth
// (e.g. a staging server). Format: 'username:password'. Leave undefined on production.
//   define( 'UGCIFY_EDD_HTTP_AUTH', 'username:password' );

// Require Composer autoloader.
if ( file_exists( UGCIFY_PATH . 'vendor/autoload.php' ) ) {
	require_once UGCIFY_PATH . 'vendor/autoload.php';
}

// Include the Bootstrap class.
require_once UGCIFY_PATH . 'includes/Bootstrap.php';

/**
 * Plugin activation hook.
 *
 * @return void
 */
function ugcify_activate() {
	if ( class_exists( 'Ugcify\Bootstrap' ) ) {
		Ugcify\Bootstrap::activate();
	}
}
register_activation_hook( __FILE__, 'ugcify_activate' );

/**
 * Plugin deactivation hook.
 *
 * @return void
 */
function ugcify_deactivate() {
	if ( class_exists( 'Ugcify\Bootstrap' ) ) {
		Ugcify\Bootstrap::deactivate();
	}
}
register_deactivation_hook( __FILE__, 'ugcify_deactivate' );

/**
 * Initialize the plugin.
 *
 * @return void
 */
function ugcify_init() {
	if ( class_exists( 'Ugcify\Bootstrap' ) ) {
		Ugcify\Bootstrap::init();
	}
}
add_action( 'plugins_loaded', 'ugcify_init' );
