<?php
/**
 * Plugin Name: PHP Compatibility Checker by Volade
 * Plugin URI: https://wordpress.org/plugins/php-compatibility-checker-by-volade/
 * Description: Scan plugins and themes for PHP version compatibility before you upgrade. Works without an account; full scans with Volade connected; history and CLI on V+.
 * Version: 1.0.0
 * Requires at least: 6.0
 * Requires PHP: 7.4
 * Author: Volade
 * Author URI: https://volade.com
 * License: GPL v2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: php-compatibility-checker-by-volade
 * Domain Path: /languages
 *
 * @license GPL-2.0-or-later
 */

defined( 'ABSPATH' ) || exit;

define( 'PCC_VERSION', '1.0.0' );
define( 'PCC_FILE', __FILE__ );
define( 'PCC_DIR', plugin_dir_path( __FILE__ ) );
define( 'PCC_URL', plugin_dir_url( __FILE__ ) );
define( 'PCC_SLUG', 'php-compatibility-checker-by-volade' );

require_once PCC_DIR . 'includes/class-pcc-settings.php';
require_once PCC_DIR . 'includes/class-pcc-i18n.php';
require_once PCC_DIR . 'includes/class-pcc-environment.php';
require_once PCC_DIR . 'includes/class-pcc-static-analyzer.php';
require_once PCC_DIR . 'includes/class-pcc-audit.php';
require_once PCC_DIR . 'includes/class-pcc-scanner.php';
require_once PCC_DIR . 'includes/class-pcc-presets.php';
require_once PCC_DIR . 'includes/class-pcc-wp-deprecations.php';
require_once PCC_DIR . 'includes/class-pcc-runtime-monitor.php';
require_once PCC_DIR . 'includes/class-pcc-health.php';
require_once PCC_DIR . 'includes/class-pcc-auto-rescan.php';
require_once PCC_DIR . 'includes/class-pcc-scheduler.php';
require_once PCC_DIR . 'includes/class-pcc-network-admin.php';
require_once PCC_DIR . 'includes/class-pcc-admin.php';
require_once PCC_DIR . 'includes/class-pcc-plugin.php';

if ( defined( 'WP_CLI' ) && WP_CLI ) {
	require_once PCC_DIR . 'includes/class-pcc-cli.php';
}

function pcc_load_volade_sdk() {
	$args = array(
		'plugin_file' => PCC_FILE,
		'plugin_slug' => PCC_SLUG,
		'plugin_name' => 'PHP Compatibility Checker by Volade',
		'sdk_path'    => PCC_DIR . 'volade-sdk/class-volade-sdk.php',
	);

	if ( function_exists( 'volade_sdk_boot' ) ) {
		volade_sdk_boot( $args );
		return;
	}

	$boot = PCC_DIR . 'volade-sdk/boot.php';
	if ( ! is_readable( $boot ) ) {
		add_action(
			'admin_notices',
			function () {
				if ( ! current_user_can( 'activate_plugins' ) ) {
					return;
				}
				echo '<div class="notice notice-error"><p>';
				echo '<strong>' . esc_html__( 'PHP Compatibility Checker by Volade', 'php-compatibility-checker-by-volade' ) . ':</strong> ';
				esc_html_e( 'The volade-sdk folder is missing. Scans remain under Tools → PHP Compatibility.', 'php-compatibility-checker-by-volade' );
				echo ' ';
				esc_html_e( 'Reinstall the complete plugin package — the volade-sdk folder must be included.', 'php-compatibility-checker-by-volade' );
				echo '</p></div>';
			}
		);
		return;
	}

	require_once $boot;

	volade_sdk_boot( $args );
}

pcc_load_volade_sdk();

PCC_Plugin::instance();

add_filter(
	'plugin_row_meta',
	function ( $links, $file ) {
		if ( plugin_basename( PCC_FILE ) !== $file ) {
			return $links;
		}
		$links[] = '<a href="https://wordpress.org/support/plugin/php-compatibility-checker-by-volade/" target="_blank" rel="noopener">' . esc_html__( 'Support', 'php-compatibility-checker-by-volade' ) . '</a>';
		$doc_url = function_exists( 'volade_extension_doc_url' ) ? volade_extension_doc_url( PCC_SLUG ) : 'https://volade.com/fr/cms/wordpress/extensions/' . PCC_SLUG;
		$links[] = '<a href="' . esc_url( $doc_url ) . '" target="_blank" rel="noopener">' . esc_html__( 'Documentation', 'php-compatibility-checker-by-volade' ) . '</a>';
		return $links;
	},
	10,
	2
);

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