<?php
/**
 * Plugin Name: Where Next Connector
 * Description: Adds a reusable deep-link button for sending WordPress content to the Where Next app.
 * Version: 1.3.7
 * Author: Where Next
 * Author URI: https://wherenext.dev
 * Plugin URI: https://wherenext.dev/wordpress-connector
 * Update URI: https://wherenext.dev/wordpress-connector/
 * Requires at least: 6.0
 * Requires PHP: 8.0
 * Text Domain: where-next-connector
 */

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

if (!function_exists('wnc_fs')) {
    /**
     * Return the Where Next Connector Freemius SDK instance.
     *
     * @return Freemius
     */
    function wnc_fs() {
        global $wnc_fs;

        if (!isset($wnc_fs)) {
            require_once dirname(__FILE__) . '/vendor/freemius/start.php';

            $wnc_fs = fs_dynamic_init([
                'id'                  => '34687',
                'slug'                => 'where-next-connector',
                'type'                => 'plugin',
                'public_key'          => 'pk_d8543f648d2b9e4ae50213078a50c',
                'is_premium'          => false,
                'has_premium_version' => false,
                'has_addons'          => false,
                'has_paid_plans'      => true,
                'is_org_compliant'    => false,
                'menu'                => [
                    'slug'    => 'where-next',
                    'support' => false,
                ],
            ]);
        }

        return $wnc_fs;
    }

    wnc_fs();
    do_action('wnc_fs_loaded');
}

define('WNC_VERSION', '1.3.7');
define('WNC_APP_SCHEME', 'wherenext');
define('WNC_APP_ROUTE', 'import-place');
define('WNC_PATH', plugin_dir_path(__FILE__));
define('WNC_URL', plugin_dir_url(__FILE__));

require_once WNC_PATH . 'includes/freemius-branding.php';
require_once WNC_PATH . 'includes/helpers.php';
require_once WNC_PATH . 'includes/licensing.php';
require_once WNC_PATH . 'includes/pro.php';

require_once WNC_PATH . 'includes/admin-menu.php';
require_once WNC_PATH . 'includes/admin.php';
require_once WNC_PATH . 'includes/pro-page.php';
require_once WNC_PATH . 'includes/analytics-page.php';
require_once WNC_PATH . 'includes/help-page.php';

require_once WNC_PATH . 'includes/frontend.php';
require_once WNC_PATH . 'includes/dashboard-widget.php';

// The universal package contains Pro modules, but only loads them when a
// valid Freemius licence is active.
if (wnc_is_pro_active()) {
    require_once WNC_PATH . 'includes/pro-autoplace.php';
    require_once WNC_PATH . 'includes/pro-visibility.php';
    require_once WNC_PATH . 'includes/pro-actions.php';
    require_once WNC_PATH . 'includes/pro-qr.php';
    require_once WNC_PATH . 'includes/pro-floating.php';
    require_once WNC_PATH . 'includes/analytics.php';
}

require_once WNC_PATH . 'includes/class-connect-metabox.php';
require_once WNC_PATH . 'includes/class-connect-tags.php';
require_once WNC_PATH . 'includes/class-connect-settings.php';
require_once WNC_PATH . 'includes/class-connect-health.php';
require_once WNC_PATH . 'includes/class-quality-dashboard.php';
require_once WNC_PATH . 'includes/class-plugin-updater.php';

WNC_Connect_Settings::init();
WNC_Connect_Metabox::init();
WNC_Connect_Tags::init();
WNC_Connect_Health::init();
WNC_Quality_Dashboard::init();
WNC_Plugin_Updater::init();

add_filter('kses_allowed_protocols', function ($protocols) {
    $protocols[] = 'wherenext';
    return $protocols;
});
