<?php
/**
 * Plugin Name: PW Feed
 * Plugin URI: https://www.pwfeed.com
 * Description: Google Merchant Center preparation, analysis, connection, and health management platform for WooCommerce stores.
 * Version: 1.9.39
 * Author: PW Feed
 * Author URI: https://www.pwfeed.com
 * Update URI: https://www.pwfeed.com/pw-feed/
 * Text Domain: pw-merchant-api-system
 * Domain Path: /languages
 * Requires at least: 5.8
 * Requires PHP: 7.4
 */

if (!defined('ABSPATH')) { exit; }

define('PTMS_VERSION', '1.9.39');
define('PTMS_FILE', __FILE__);
define('PTMS_DIR', plugin_dir_path(__FILE__));
define('PTMS_URL', plugin_dir_url(__FILE__));
define('PTMS_CONNECT_SERVICE_URL', 'https://connect.ibmw.com.tr');
define('PTMS_LICENSE_PANEL_URL', 'https://www.pwfeed.com/licenses.html');
define('PTMS_TRUST_PRODUCT_KEY', 'pw-merchant');
define('PTMS_SUPPORT_URL', 'https://www.pwfeed.com/support.html');

require_once PTMS_DIR . 'includes/class-ptms-data-detector.php';
require_once PTMS_DIR . 'includes/class-ptms-license.php';
require_once PTMS_DIR . 'includes/class-ptms-updater.php';
require_once PTMS_DIR . 'includes/class-ptms-core.php';
require_once PTMS_DIR . 'includes/class-ptms-admin.php';
require_once PTMS_DIR . 'includes/trust2/class-ptms-license-client-v2.php';

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

add_action('plugins_loaded', static function () {
    load_plugin_textdomain(
        'pw-merchant-api-system',
        false,
        dirname(plugin_basename(PTMS_FILE)) . '/languages'
    );

    PTMS_Core::instance();
    PTMS_License::instance();
    PTMS_Updater::instance();
    if (is_admin()) { PTMS_Admin::instance(); PTMS_License_Client_V2::instance(); }
});


add_filter('plugin_action_links_' . plugin_basename(PTMS_FILE), static function ($links) {
    if (current_user_can('update_plugins')) {
        $url = wp_nonce_url(
            admin_url('admin-post.php?action=ptms_update_refresh'),
            'ptms_update_refresh'
        );
        $links[] = '<a href="' . esc_url($url) . '">' . esc_html__('Check for updates', 'pw-merchant-api-system') . '</a>';
    }
    return $links;
});

add_action('admin_notices', static function () {
    if (!current_user_can('update_plugins')) { return; }
    if (!isset($_GET['ptms_update_refreshed'])) { return; }
    echo '<div class="notice notice-success is-dismissible"><p>'
        . esc_html__('PW Feed update information was refreshed through PW Trust and Trust2.', 'pw-merchant-api-system')
        . '</p></div>';
});
