Plugin Directory

Changeset 3835111


Ignore:
Timestamp:
11/30/2026 12:46:43 PM (less than one hour ago)
Author:
lukastech
Message:

Release 3.0.0: Added human check, ticket pass, and portal pass landing templates; enhanced dwell time tracking with cache-bypassing beacons and sessionStorage; removed BOM; improved builder workflow and security.

Location:
custom-link-shortener
Files:
10 added
3 edited
5 copied

Legend:

Unmodified
Added
Removed
  • custom-link-shortener/tags/3.0.0/custom-link-shortener.php

    r3823045 r3835111  
    1 <?php
     1<?php
    22/*
    33Plugin Name: Custom Link Shortener
    44Description: A custom URL shortener with analytics, weighted rotating links, internal dwell time tracking, random blog post redirect, keyword auto-linker, location tracking, password protection, QR codes, click goals, pause/unpause, bulk delete, and REST API.
    5 Version: 2.8.2
     5Version: 3.0.0
    66Author: Lukastech
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
    99Requires at least: 5.0
    10 Tested up to: 7.1
     10Tested up to: 7.2
    1111Requires PHP: 7.4
    1212Text Domain: custom-link-shortener
    … …  
    1515defined('ABSPATH') or die('No script kiddies please!');
    1616
    17 define('WPCS_VERSION', '2.8.2');
     17define('WPCS_VERSION', '3.0.0');
     18define('WPCS_PLUGIN_DIR', plugin_dir_path(__FILE__));
     19define('WPCS_PLUGIN_URL', plugin_dir_url(__FILE__));
    1820
    1921// --------------------------------------------------
    … …  
    2426    wpcs_create_db();
    2527    wpcs_ensure_columns();
     28    if (class_exists('WPCS_Landing_Pages')) {
     29        WPCS_Landing_Pages::ensure_table();
     30    }
    2631    wpcs_add_rewrite_rule();
    27     flush_rewrite_rules();
    28 }
    29 
    30 add_action('admin_init', 'wpcs_ensure_columns');
    31 add_action('plugins_loaded', 'wpcs_check_db_version');
     32    if (class_exists('WPCS_Landing_Pages')) {
     33        WPCS_Landing_Pages::add_rewrite_rules();
     34    }
     35    if (function_exists('flush_rewrite_rules')) {
     36        flush_rewrite_rules();
     37    }
     38}
     39
     40add_action('init', 'wpcs_check_db_version', 20);
    3241function wpcs_check_db_version() {
    3342    $current_version = get_option('wpcs_db_version', '1.0');
    34     $target_version  = '2.8.2';
     43    $target_version  = '3.0.0';
    3544   
    3645    if (version_compare($current_version, $target_version, '<')) {
    3746        wpcs_create_db();
    3847        wpcs_ensure_columns();
     48        if (class_exists('WPCS_Landing_Pages')) {
     49            WPCS_Landing_Pages::ensure_table();
     50        }
     51        if (class_exists('WPCS_Landing_Pages')) {
     52            WPCS_Landing_Pages::add_rewrite_rules();
     53        }
     54        global $wp_rewrite;
     55        if (is_object($wp_rewrite) && function_exists('flush_rewrite_rules')) {
     56            flush_rewrite_rules(false);
     57        }
    3958        update_option('wpcs_db_version', $target_version);
    4059    }
    … …  
    164183    dbDelta($sql_destinations);
    165184    dbDelta($sql_clicks);
     185
     186    $table_landing_pages = $wpdb->prefix . 'wpcs_landing_pages';
     187    $sql_landing_pages = "CREATE TABLE $table_landing_pages (
     188        id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
     189        slug varchar(191) NOT NULL,
     190        title varchar(255) NOT NULL,
     191        template_style varchar(50) NOT NULL DEFAULT 'pulsar',
     192        niche varchar(50) NOT NULL DEFAULT 'general',
     193        headline text NULL,
     194        subheadline text NULL,
     195        hide_header tinyint(1) NOT NULL DEFAULT 0,
     196        primary_btn_text varchar(255) NULL,
     197        primary_btn_url text NULL,
     198        primary_btn_shortlink_id bigint(20) unsigned DEFAULT 0,
     199        secondary_btn_text varchar(255) NULL,
     200        secondary_btn_url text NULL,
     201        secondary_btn_shortlink_id bigint(20) unsigned DEFAULT 0,
     202        choices_json longtext NULL,
     203        badge_text varchar(255) NULL,
     204        highlight_strip varchar(255) NULL,
     205        meta_pixel_id varchar(100) NULL,
     206        google_analytics_id varchar(100) NULL,
     207        tiktok_pixel_id varchar(100) NULL,
     208        custom_head_code longtext NULL,
     209        custom_html_body longtext NULL,
     210        disclaimer_text text NULL,
     211        views bigint(20) unsigned NOT NULL DEFAULT 0,
     212        clicks bigint(20) unsigned NOT NULL DEFAULT 0,
     213        created_at datetime DEFAULT CURRENT_TIMESTAMP,
     214        updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     215        PRIMARY KEY  (id),
     216        UNIQUE KEY uq_slug (slug)
     217    ) $charset_collate;";
     218    dbDelta($sql_landing_pages);
    166219}
    167220
    … …  
    470523    }
    471524
    472     // Internal Dwell-Time Hand-Off
     525    // Internal & Cross-Subdomain Dwell-Time Hand-Off (*.vautobasics.com)
    473526    $site_host   = wp_parse_url(home_url(), PHP_URL_HOST);
    474527    $dest_host   = wp_parse_url($target_url, PHP_URL_HOST);
    475     $is_internal = empty($dest_host) || (strcasecmp($site_host, $dest_host) === 0);
     528    $is_internal = wpcs_is_internal_host($site_host, $dest_host);
    476529
    477530    if ($is_internal && $click_id && !$is_bot) {
    478         $target_url = add_query_arg('wpcs_ref', $click_id, $target_url);
     531        $target_url = add_query_arg([
     532            'wpcs_ref'      => $click_id,
     533            'wpcs_endpoint' => rawurlencode(admin_url('admin-ajax.php'))
     534        ], $target_url);
    479535    }
    480536
    … …  
    503559// Internal Page Dwell Time Tracker & Beacon Endpoint
    504560// --------------------------------------------------
     561/**
     562 * Helper: Detect whether target host is internal or belongs to the same domain network (e.g. *.vautobasics.com)
     563 */
     564function wpcs_is_internal_host($site_host, $dest_host) {
     565    if (empty($dest_host) || strcasecmp($site_host, $dest_host) === 0) {
     566        return true;
     567    }
     568    $site_parts = explode('.', strtolower($site_host));
     569    $dest_parts = explode('.', strtolower($dest_host));
     570    if (count($site_parts) >= 2 && count($dest_parts) >= 2) {
     571        $site_root = implode('.', array_slice($site_parts, -2));
     572        $dest_root = implode('.', array_slice($dest_parts, -2));
     573        if ($site_root === $dest_root) {
     574            return true;
     575        }
     576    }
     577    return false;
     578}
     579
     580function wpcs_get_dwell_tracker_html() {
     581    ob_start();
     582    wpcs_render_dwell_tracker();
     583    return ob_get_clean();
     584}
     585
    505586add_action('wp_footer', 'wpcs_render_dwell_tracker', 99);
    506587function wpcs_render_dwell_tracker() {
    507     if (!isset($_GET['wpcs_ref'])) return;
    508     $ref_id = absint($_GET['wpcs_ref']);
    509     if (!$ref_id) return;
     588    if (is_admin()) return;
     589    $default_endpoint = esc_url(admin_url('admin-ajax.php'));
    510590    ?>
    511     <script id="wpcs-dwell-tracker">
    512     (function() {
    513         var clickId = <?php echo (int)$ref_id; ?>;
    514         var startTime = Date.now();
    515         var totalActive = 0;
    516         var lastActiveTime = startTime;
    517         var isHidden = false;
    518         var sent = false;
    519 
    520         document.addEventListener('visibilitychange', function() {
    521             if (document.visibilityState === 'hidden') {
    522                 isHidden = true;
    523                 totalActive += Math.round((Date.now() - lastActiveTime) / 1000);
    524             } else {
    525                 isHidden = false;
    526                 lastActiveTime = Date.now();
     591    <script id="wpcs-dwell-tracker" data-cfasync="false" data-no-optimize="1" data-no-defer="1" data-no-minify="1" data-pagespeed-no-defer nowprocket>
     592    (function () {
     593        var KEY = 'wpcs_dwell', MAX = 7200;
     594        var params = new URLSearchParams(window.location.search);
     595        var urlRef = parseInt(params.get('wpcs_ref'), 10) || 0;
     596        var state = null;
     597
     598        try { state = JSON.parse(sessionStorage.getItem(KEY) || 'null'); } catch (e) {}
     599
     600        if (urlRef) {
     601            // New click, or same click being reloaded
     602            if (!state || state.id !== urlRef) {
     603                var ep = params.get('wpcs_endpoint') || '<?php echo $default_endpoint; ?>';
     604                state = { id: urlRef, endpoint: ep, total: 0 };
    527605            }
     606            // Clean the URL so visitors don't share tracking params
     607            try {
     608                params.delete('wpcs_ref');
     609                params.delete('wpcs_endpoint');
     610                var qs = params.toString();
     611                history.replaceState(null, '', location.pathname + (qs ? '?' + qs : '') + location.hash);
     612            } catch (e) {}
     613        }
     614
     615        if (!state || !state.id || !state.endpoint) return;
     616
     617        // Only allow endpoints on the same root domain
     618        try {
     619            var epHost = new URL(state.endpoint).hostname.split('.').slice(-2).join('.');
     620            var myHost = location.hostname.split('.').slice(-2).join('.');
     621            if (epHost !== myHost) return;
     622        } catch (e) { return; }
     623
     624        var base = state.total || 0;
     625        var activeMs = 0;
     626        var last = (document.visibilityState === 'visible') ? Date.now() : null;
     627
     628        function tick() {
     629            if (last !== null) { var n = Date.now(); activeMs += (n - last); last = n; }
     630        }
     631
     632        function send() {
     633            tick();
     634            var total = Math.min(base + Math.round(activeMs / 1000), MAX);
     635            if (total < 1) return;
     636            state.total = total;
     637            try { sessionStorage.setItem(KEY, JSON.stringify(state)); } catch (e) {}
     638
     639            var body = 'action=wpcs_record_dwell&click_id=' + state.id + '&dwell_seconds=' + total;
     640            var sent = false;
     641            if (navigator.sendBeacon) {
     642                sent = navigator.sendBeacon(state.endpoint,
     643                    new Blob([body], { type: 'application/x-www-form-urlencoded' }));
     644            }
     645            if (!sent && window.fetch) {
     646                fetch(state.endpoint, {
     647                    method: 'POST', body: body, keepalive: true, mode: 'cors', credentials: 'omit',
     648                    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
     649                }).catch(function () {});
     650            }
     651        }
     652
     653        window.__wpcs_send_dwell = send;
     654
     655        document.addEventListener('visibilitychange', function () {
     656            if (document.visibilityState === 'hidden') { tick(); last = null; send(); }
     657            else { last = Date.now(); }
    528658        });
    529 
    530         function sendDwellTime() {
    531             if (sent) return;
    532             if (!isHidden) {
    533                 totalActive += Math.round((Date.now() - lastActiveTime) / 1000);
    534             }
    535             if (totalActive < 1) return;
    536             sent = true;
    537 
    538             var data = new FormData();
    539             data.append('action', 'wpcs_record_dwell');
    540             data.append('click_id', clickId);
    541             data.append('dwell_seconds', Math.min(totalActive, 7200));
    542 
    543             var ajaxUrl = '<?php echo esc_url(admin_url('admin-ajax.php')); ?>';
    544             if (navigator.sendBeacon) {
    545                 navigator.sendBeacon(ajaxUrl, data);
    546             } else {
    547                 var xhr = new XMLHttpRequest();
    548                 xhr.open('POST', ajaxUrl, false);
    549                 xhr.send(data);
    550             }
    551         }
    552 
    553         window.addEventListener('pagehide', sendDwellTime);
    554         window.addEventListener('beforeunload', sendDwellTime);
     659        window.addEventListener('pagehide', send);
     660
     661        setTimeout(send, 2000);
     662        setInterval(send, 10000);
    555663    })();
    556664    </script>
    … …  
    561669add_action('wp_ajax_wpcs_record_dwell', 'wpcs_ajax_record_dwell');
    562670function wpcs_ajax_record_dwell() {
    563     $click_id = absint($_POST['click_id'] ?? 0);
    564     $seconds  = absint($_POST['dwell_seconds'] ?? 0);
     671    // CORS: only allow origins on the same root domain
     672    $origin = isset($_SERVER['HTTP_ORIGIN']) ? esc_url_raw(wp_unslash($_SERVER['HTTP_ORIGIN'])) : '';
     673    if ($origin) {
     674        $o_host = wp_parse_url($origin, PHP_URL_HOST);
     675        if ($o_host && wpcs_is_internal_host(wp_parse_url(home_url(), PHP_URL_HOST), $o_host)) {
     676            header('Access-Control-Allow-Origin: ' . $origin);
     677            header('Access-Control-Allow-Credentials: true');
     678            header('Vary: Origin');
     679        }
     680    }
     681    header('Access-Control-Allow-Methods: POST, OPTIONS');
     682    header('Access-Control-Allow-Headers: Content-Type');
     683
     684    if (($_SERVER['REQUEST_METHOD'] ?? '') === 'OPTIONS') {
     685        status_header(200);
     686        exit;
     687    }
     688
     689    $click_id = absint($_REQUEST['click_id'] ?? 0);
     690    $seconds  = absint($_REQUEST['dwell_seconds'] ?? 0);
     691
     692    if (!$click_id || !$seconds) {
     693        $raw = file_get_contents('php://input');
     694        if (!empty($raw)) {
     695            $parsed = [];
     696            parse_str($raw, $parsed);
     697            if (!empty($parsed['click_id'])) $click_id = absint($parsed['click_id']);
     698            if (!empty($parsed['dwell_seconds'])) $seconds = absint($parsed['dwell_seconds']);
     699        }
     700    }
     701
    565702    if ($click_id && $seconds > 0) {
    566703        global $wpdb;
    567704        $click_tbl = $wpdb->prefix . 'wpcs_clicks';
    568         $wpdb->update($click_tbl, ['dwell_time' => min($seconds, 7200)], ['id' => $click_id]);
    569     }
    570     wp_die();
     705        // GREATEST() so a late/out-of-order beacon never lowers the value
     706        $wpdb->query($wpdb->prepare(
     707            "UPDATE {$click_tbl} SET dwell_time = GREATEST(dwell_time, %d) WHERE id = %d",
     708            min($seconds, 7200),
     709            $click_id
     710        ));
     711    }
     712    wp_send_json_success();
    571713}
    572714
    … …  
    9241066    );
    9251067
     1068    if (class_exists('WPCS_Landing_Pages')) {
     1069        add_submenu_page(
     1070            $top_slug,
     1071            __('Landing Pages & Pre-Landers', 'custom-link-shortener'),
     1072            __('Landing Pages', 'custom-link-shortener'),
     1073            'manage_options',
     1074            'wpcs-landing-pages',
     1075            ['WPCS_Landing_Pages', 'render_admin_page']
     1076        );
     1077    }
     1078
    9261079    add_submenu_page(
    9271080        $top_slug,
    … …  
    9461099        update_option('wpcs_autolink_max_total',     absint($_POST['wpcs_autolink_max_total']));
    9471100
     1101        if (class_exists('WPCS_Landing_Pages')) {
     1102            update_option('wpcs_default_meta_pixel',   WPCS_Landing_Pages::extract_meta_pixel_id(wp_unslash($_POST['wpcs_default_meta_pixel'] ?? '')));
     1103            update_option('wpcs_default_ga_id',        WPCS_Landing_Pages::extract_ga_id(wp_unslash($_POST['wpcs_default_ga_id'] ?? '')));
     1104            update_option('wpcs_default_tiktok_pixel', WPCS_Landing_Pages::extract_tiktok_pixel_id(wp_unslash($_POST['wpcs_default_tiktok_pixel'] ?? '')));
     1105        } else {
     1106            update_option('wpcs_default_meta_pixel',   sanitize_text_field(wp_unslash($_POST['wpcs_default_meta_pixel'] ?? '')));
     1107            update_option('wpcs_default_ga_id',        sanitize_text_field(wp_unslash($_POST['wpcs_default_ga_id'] ?? '')));
     1108            update_option('wpcs_default_tiktok_pixel', sanitize_text_field(wp_unslash($_POST['wpcs_default_tiktok_pixel'] ?? '')));
     1109        }
     1110
    9481111        wpcs_add_rewrite_rule();
     1112        if (class_exists('WPCS_Landing_Pages')) {
     1113            WPCS_Landing_Pages::add_rewrite_rules();
     1114        }
    9491115        flush_rewrite_rules();
    9501116        echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__('Settings saved and rewrite rules flushed.', 'custom-link-shortener') . '</p></div>';
    … …  
    10531219                    <label for="wpcs_alert_email"><strong><?php esc_html_e('Click Goal Alert Email', 'custom-link-shortener'); ?></strong></label>
    10541220                    <input type="email" id="wpcs_alert_email" name="wpcs_alert_email" value="<?php echo esc_attr($alert_email); ?>" style="max-width:400px;">
     1221                </div>
     1222            </div>
     1223
     1224            <div class="wpcs-card wpcs-partition-card">
     1225                <div class="wpcs-partition-header">
     1226                    <h2><span class="dashicons dashicons-chart-line"></span> <?php esc_html_e('Global Tracking Pixels & Analytics Defaults', 'custom-link-shortener'); ?></h2>
     1227                </div>
     1228                <p class="description" style="margin-bottom:1.25rem;">
     1229                    <?php esc_html_e('Configure default tracking IDs for your landing pages. When creating or editing landing pages, any tracking fields left blank will automatically inherit these global defaults. You can paste either the clean ID or the full tracking code snippet (the smart extractor will clean it automatically).', 'custom-link-shortener'); ?>
     1230                </p>
     1231                <div class="form-field" style="margin-bottom:1.25rem;">
     1232                    <label for="wpcs_default_meta_pixel"><strong><?php esc_html_e('Default Meta Pixel ID', 'custom-link-shortener'); ?></strong></label>
     1233                    <input type="text" id="wpcs_default_meta_pixel" name="wpcs_default_meta_pixel" value="<?php echo esc_attr(get_option('wpcs_default_meta_pixel', '')); ?>" placeholder="e.g. 1312023820383414" style="max-width:400px; width:100%;">
     1234                    <p class="description"><?php esc_html_e('Fires standard PageView on landing page visit and PrelanderClick on button click.', 'custom-link-shortener'); ?></p>
     1235                </div>
     1236                <div class="form-field" style="margin-bottom:1.25rem;">
     1237                    <label for="wpcs_default_ga_id"><strong><?php esc_html_e('Default Google Analytics / GTM ID', 'custom-link-shortener'); ?></strong></label>
     1238                    <input type="text" id="wpcs_default_ga_id" name="wpcs_default_ga_id" value="<?php echo esc_attr(get_option('wpcs_default_ga_id', '')); ?>" placeholder="e.g. G-Q7V54CNSGL or GT-XXXXX" style="max-width:400px; width:100%;">
     1239                    <p class="description"><?php esc_html_e('Google Analytics 4 Measurement ID or Google Tag Manager Container ID.', 'custom-link-shortener'); ?></p>
     1240                </div>
     1241                <div class="form-field" style="margin-bottom:1.25rem;">
     1242                    <label for="wpcs_default_tiktok_pixel"><strong><?php esc_html_e('Default TikTok Pixel ID', 'custom-link-shortener'); ?></strong></label>
     1243                    <input type="text" id="wpcs_default_tiktok_pixel" name="wpcs_default_tiktok_pixel" value="<?php echo esc_attr(get_option('wpcs_default_tiktok_pixel', '')); ?>" placeholder="e.g. C8X9ABCD1234" style="max-width:400px; width:100%;">
     1244                    <p class="description"><?php esc_html_e('TikTok Pixel ID for tracking pre-lander views and outbound clicks.', 'custom-link-shortener'); ?></p>
    10551245                </div>
    10561246            </div>
    … …  
    19222112        : ($this_month_clicks > 0 ? 100 : 0);
    19232113
    1924     $overall_ctr = ($total_impressions > 0) ? round(($total_clicks / $total_impressions) * 100, 1) . '%' : '0.0%';
     2114    $last_click = $wpdb->get_row("SELECT l.alias, c.clicked_at FROM {$clicks_tbl} c JOIN {$links_tbl} l ON c.link_id = l.id WHERE c.is_bot = 0 ORDER BY c.clicked_at DESC LIMIT 1");
     2115    $last_click_text = __('No clicks yet', 'custom-link-shortener');
     2116    if ($last_click) {
     2117        $last_click_text = sprintf(__('%s ago via /%s', 'custom-link-shortener'), human_time_diff(strtotime($last_click->clicked_at), current_time('timestamp')), esc_html($last_click->alias));
     2118    }
    19252119
    19262120    $selected_cat = sanitize_text_field($_GET['filter_category'] ?? '');
    … …  
    19802174        </div>
    19812175        <div class="wpcs-stat-card wpcs-stat--warning">
    1982             <div class="stat-label"><?php esc_html_e('Average CTR', 'custom-link-shortener'); ?></div>
    1983             <div class="stat-value"><?php echo esc_html($overall_ctr); ?></div>
    1984             <div class="stat-sub"><?php echo ($total_impressions > 0) ? sprintf(esc_html__('Across %s views', 'custom-link-shortener'), number_format_i18n($total_impressions)) : esc_html__('From on-site links (No impressions recorded yet)', 'custom-link-shortener'); ?></div>
     2176            <div class="stat-label"><?php esc_html_e('Last Click', 'custom-link-shortener'); ?></div>
     2177            <div class="stat-value" style="font-size:1.1rem; line-height:1.3; word-break:break-word; font-weight:700;"><?php echo esc_html($last_click_text); ?></div>
     2178            <div class="stat-sub"><?php esc_html_e('Most recent activity', 'custom-link-shortener'); ?></div>
    19852179        </div>
    19862180    </div>
    … …  
    21372331                            <td style="text-align:center;">
    21382332                                <span class="wpcs-click-count"><?php echo number_format_i18n($link->total_clicks); ?></span>
    2139                                 <small class="wpcs-text-muted" style="display:block; font-size:11px;">
    2140                                     <?php echo ($link_impressions > 0) ? 'CTR: <strong>' . esc_html($link_ctr) . '</strong>' : '<span title="' . esc_attr__('No on-site impressions recorded yet', 'custom-link-shortener') . '">' . esc_html__('0.0% CTR', 'custom-link-shortener') . '</span>'; ?>
    2141                                 </small>
    21422333                            </td>
    21432334                            <td><?php echo $last_click_date; ?></td>
    … …  
    22062397    foreach ($dests as $d) {
    22072398        $dh = wp_parse_url($d->destination_url, PHP_URL_HOST);
    2208         if (empty($dh) || strcasecmp($site_host, $dh) === 0) {
     2399        if (wpcs_is_internal_host($site_host, $dh)) {
    22092400            $has_internal = true;
    22102401            break;
    … …  
    24802671add_action('admin_enqueue_scripts', 'wpcs_enqueue_admin_assets');
    24812672function wpcs_enqueue_admin_assets($hook) {
    2482     if (!isset($_GET['page']) || !in_array($_GET['page'], ['wpcs-shortener', 'wpcs-analytics', 'wpcs-settings'], true)) {
     2673    if (!isset($_GET['page']) || !in_array($_GET['page'], ['wpcs-shortener', 'wpcs-analytics', 'wpcs-settings', 'wpcs-landing-pages'], true)) {
    24832674        return;
    24842675    }
    … …  
    24932684add_action('admin_head', 'wpcs_inline_admin_styles');
    24942685function wpcs_inline_admin_styles() {
    2495     if (!isset($_GET['page']) || !in_array($_GET['page'], ['wpcs-shortener', 'wpcs-analytics', 'wpcs-settings'], true)) {
     2686    if (!isset($_GET['page']) || !in_array($_GET['page'], ['wpcs-shortener', 'wpcs-analytics', 'wpcs-settings', 'wpcs-landing-pages'], true)) {
    24962687        return;
    24972688    }
    … …  
    28373028add_action('admin_footer', 'wpcs_inline_admin_scripts');
    28383029function wpcs_inline_admin_scripts() {
    2839     if (!isset($_GET['page']) || !in_array($_GET['page'], ['wpcs-shortener', 'wpcs-analytics', 'wpcs-settings'], true)) {
     3030    if (!isset($_GET['page']) || !in_array($_GET['page'], ['wpcs-shortener', 'wpcs-analytics', 'wpcs-settings', 'wpcs-landing-pages'], true)) {
    28403031        return;
    28413032    }
    … …  
    29263117        }
    29273118
    2928         jQuery(document).ready(function($) {
     3119        jQuery(function($) {
    29293120            $(document).on('click', '.wpcs-copy', function(e) {
    29303121                e.preventDefault();
    … …  
    32263417}
    32273418
     3419// --------------------------------------------------
     3420// Modular Subsystems (Safe Isolated Loaders)
     3421// --------------------------------------------------
     3422$wpcs_templates_file = WPCS_PLUGIN_DIR . 'includes/class-wpcs-templates.php';
     3423if (file_exists($wpcs_templates_file)) {
     3424    require_once $wpcs_templates_file;
     3425}
     3426
     3427$wpcs_lp_file = WPCS_PLUGIN_DIR . 'includes/class-wpcs-landing-pages.php';
     3428if (file_exists($wpcs_lp_file)) {
     3429    require_once $wpcs_lp_file;
     3430}
  • custom-link-shortener/tags/3.0.0/js/admin.js

    r3823045 r3835111  
    112112
    113113    // --------------------------------------------------
    114     // DOM Ready Setup
    115     // --------------------------------------------------
    116     $(document).ready(function() {
     114    // DOM Ready Setup (jQuery 4 / Migrate 3.6.0 compatible)
     115    // --------------------------------------------------
     116    $(function() {
    117117
    118118        // 1. Copy URL with tactile text change + toast
    … …  
    351351    });
    352352
     353
     354    // --------------------------------------------------
     355    // Smart Tracking ID Auto-Extractors on Settings Page
     356    // --------------------------------------------------
     357    function wpcsExtractMeta(val) {
     358        if (!val) return '';
     359        val = val.trim();
     360        var initMatch = val.match(/fbq\s*\(\s*['"]init['"]\s*,\s*['"]?(\d+)['"]?/i);
     361        if (initMatch) return initMatch[1];
     362        var trMatch = val.match(/[?&]id=(\d+)/i);
     363        if (trMatch) return trMatch[1];
     364        var numMatch = val.match(/\b\d{10,20}\b/);
     365        if (numMatch) return numMatch[0];
     366        if (/<script|fbq/i.test(val)) return val.replace(/[^0-9]/g, '');
     367        return val.trim();
     368    }
     369
     370    function wpcsExtractGA(val) {
     371        if (!val) return '';
     372        val = val.trim();
     373        var gMatch = val.match(/\b(G-[A-Z0-9]+|GT-[A-Z0-9]+|UA-\d+-\d+|AW-\d+)\b/i);
     374        if (gMatch) return gMatch[1].toUpperCase();
     375        return val.trim();
     376    }
     377
     378    function wpcsExtractTikTok(val) {
     379        if (!val) return '';
     380        val = val.trim();
     381        var ttqMatch = val.match(/ttq\.load\s*\(\s*['"]([A-Z0-9]+)['"]/i);
     382        if (ttqMatch) return ttqMatch[1].toUpperCase();
     383        var sdkMatch = val.match(/[?&]sdkid=([A-Z0-9]+)/i);
     384        if (sdkMatch) return sdkMatch[1].toUpperCase();
     385        var codeMatch = val.match(/\b([A-Z0-9]{9,25})\b/i);
     386        if (codeMatch && !/script|function|document|window/i.test(codeMatch[0])) return codeMatch[1].toUpperCase();
     387        return val.trim();
     388    }
     389
     390    function wpcsAttachExtractor(selector, fn, name) {
     391        $(document).on('paste input change', selector, function() {
     392            var $el = $(this);
     393            var raw = $el.val();
     394            if (!raw) return;
     395            var clean = fn(raw);
     396            if (clean && clean !== raw) {
     397                $el.val(clean);
     398                if (window.wpcsShowToast) {
     399                    window.wpcsShowToast('Extracted ' + name + ' ID: ' + clean);
     400                }
     401            }
     402        });
     403    }
     404
     405    $(function() {
     406        wpcsAttachExtractor('#wpcs_default_meta_pixel', wpcsExtractMeta, 'Meta Pixel');
     407        wpcsAttachExtractor('#wpcs_default_ga_id', wpcsExtractGA, 'Google Analytics');
     408        wpcsAttachExtractor('#wpcs_default_tiktok_pixel', wpcsExtractTikTok, 'TikTok Pixel');
     409    });
     410
    353411})(jQuery);
    354 
  • custom-link-shortener/tags/3.0.0/readme.txt

    r3823045 r3835111  
    44Tags: url-shortener, custom-links, click-tracking, auto-linker, affiliate-links
    55Requires at least: 5.0
    6 Tested up to: 7.1
    7 Stable tag: 2.8.2
     6Tested up to: 7.2
     7Stable tag: 3.0.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    103103== Changelog ==
    104104
     105=== 2.9.0 ===
     106- Added High-Converting Bridge & Pre-Lander Landing Page Engine with 5 optimized styles (Direct Action Pulsar, Digital Verification Badge, Minimalist Choice, Official Notice, and Quiz Stepper) plus Raw Custom HTML mode
     107- Added Live Split-Screen Builder with real-time Mobile (375px) and Desktop interactive device frame previews
     108- Added Creative Niche & Compliance Presets with auto-suggested legal & earnings disclaimers (Surveys, Jobs, Relocation, Finance, Health, Universal)
     109- Added Discrete Micro-Compliance Footer ensuring 100% ad network policy compliance across Meta, TikTok, and Google Ads without cluttering the page
     110- Added Per-Landing-Page Pixel Tracking for Meta Pixel, Google tag (gtag.js), TikTok Pixel, and custom head scripts with automated beacon event tracking
     111- Added Dynamic Automated UTM & Query Parameter Passthrough to preserve attribution tags
     112- Verified 100% WordPress 7.2 & PHP 8.6 compatibility and updated jQuery 4 / jQuery Migrate 3.6.0 handlers
     113
    105114=== 2.8.2 ===
    106115- Fixed backwards-compatibility query to guarantee all existing shortlinks display seamlessly on dashboard
    … …  
    140149== Upgrade Notice ==
    141150
     151=== 3.0.0 ===
     152Major release adding 3 high-converting pre-lander templates (Anti-Bot Human Verification with simulated signal analysis, Perforated Ticket Pass, and Tech Access Portal Pass), real-time progressive dwell time telemetry, template lock security, and builder workflow optimizations.
     153
     154=== 2.9.0 ===
     155Introduces the Arbitrage & Bridge Landing Page Engine, live split-screen mobile/desktop preview builder, creative niche compliance disclaimers, per-page pixel tracking, and WordPress 7.2 compatibility.
     156
    142157=== 2.8.2 ===
    143158- Fixed backwards-compatibility query to guarantee all existing shortlinks display seamlessly on dashboard
  • custom-link-shortener/trunk/custom-link-shortener.php

    r3823045 r3835111  
    1 <?php
     1<?php
    22/*
    33Plugin Name: Custom Link Shortener
    44Description: A custom URL shortener with analytics, weighted rotating links, internal dwell time tracking, random blog post redirect, keyword auto-linker, location tracking, password protection, QR codes, click goals, pause/unpause, bulk delete, and REST API.
    5 Version: 2.8.2
     5Version: 3.0.0
    66Author: Lukastech
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
    99Requires at least: 5.0
    10 Tested up to: 7.1
     10Tested up to: 7.2
    1111Requires PHP: 7.4
    1212Text Domain: custom-link-shortener
    … …  
    1515defined('ABSPATH') or die('No script kiddies please!');
    1616
    17 define('WPCS_VERSION', '2.8.2');
     17define('WPCS_VERSION', '3.0.0');
     18define('WPCS_PLUGIN_DIR', plugin_dir_path(__FILE__));
     19define('WPCS_PLUGIN_URL', plugin_dir_url(__FILE__));
    1820
    1921// --------------------------------------------------
    … …  
    2426    wpcs_create_db();
    2527    wpcs_ensure_columns();
     28    if (class_exists('WPCS_Landing_Pages')) {
     29        WPCS_Landing_Pages::ensure_table();
     30    }
    2631    wpcs_add_rewrite_rule();
    27     flush_rewrite_rules();
    28 }
    29 
    30 add_action('admin_init', 'wpcs_ensure_columns');
    31 add_action('plugins_loaded', 'wpcs_check_db_version');
     32    if (class_exists('WPCS_Landing_Pages')) {
     33        WPCS_Landing_Pages::add_rewrite_rules();
     34    }
     35    if (function_exists('flush_rewrite_rules')) {
     36        flush_rewrite_rules();
     37    }
     38}
     39
     40add_action('init', 'wpcs_check_db_version', 20);
    3241function wpcs_check_db_version() {
    3342    $current_version = get_option('wpcs_db_version', '1.0');
    34     $target_version  = '2.8.2';
     43    $target_version  = '3.0.0';
    3544   
    3645    if (version_compare($current_version, $target_version, '<')) {
    3746        wpcs_create_db();
    3847        wpcs_ensure_columns();
     48        if (class_exists('WPCS_Landing_Pages')) {
     49            WPCS_Landing_Pages::ensure_table();
     50        }
     51        if (class_exists('WPCS_Landing_Pages')) {
     52            WPCS_Landing_Pages::add_rewrite_rules();
     53        }
     54        global $wp_rewrite;
     55        if (is_object($wp_rewrite) && function_exists('flush_rewrite_rules')) {
     56            flush_rewrite_rules(false);
     57        }
    3958        update_option('wpcs_db_version', $target_version);
    4059    }
    … …  
    164183    dbDelta($sql_destinations);
    165184    dbDelta($sql_clicks);
     185
     186    $table_landing_pages = $wpdb->prefix . 'wpcs_landing_pages';
     187    $sql_landing_pages = "CREATE TABLE $table_landing_pages (
     188        id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
     189        slug varchar(191) NOT NULL,
     190        title varchar(255) NOT NULL,
     191        template_style varchar(50) NOT NULL DEFAULT 'pulsar',
     192        niche varchar(50) NOT NULL DEFAULT 'general',
     193        headline text NULL,
     194        subheadline text NULL,
     195        hide_header tinyint(1) NOT NULL DEFAULT 0,
     196        primary_btn_text varchar(255) NULL,
     197        primary_btn_url text NULL,
     198        primary_btn_shortlink_id bigint(20) unsigned DEFAULT 0,
     199        secondary_btn_text varchar(255) NULL,
     200        secondary_btn_url text NULL,
     201        secondary_btn_shortlink_id bigint(20) unsigned DEFAULT 0,
     202        choices_json longtext NULL,
     203        badge_text varchar(255) NULL,
     204        highlight_strip varchar(255) NULL,
     205        meta_pixel_id varchar(100) NULL,
     206        google_analytics_id varchar(100) NULL,
     207        tiktok_pixel_id varchar(100) NULL,
     208        custom_head_code longtext NULL,
     209        custom_html_body longtext NULL,
     210        disclaimer_text text NULL,
     211        views bigint(20) unsigned NOT NULL DEFAULT 0,
     212        clicks bigint(20) unsigned NOT NULL DEFAULT 0,
     213        created_at datetime DEFAULT CURRENT_TIMESTAMP,
     214        updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     215        PRIMARY KEY  (id),
     216        UNIQUE KEY uq_slug (slug)
     217    ) $charset_collate;";
     218    dbDelta($sql_landing_pages);
    166219}
    167220
    … …  
    470523    }
    471524
    472     // Internal Dwell-Time Hand-Off
     525    // Internal & Cross-Subdomain Dwell-Time Hand-Off (*.vautobasics.com)
    473526    $site_host   = wp_parse_url(home_url(), PHP_URL_HOST);
    474527    $dest_host   = wp_parse_url($target_url, PHP_URL_HOST);
    475     $is_internal = empty($dest_host) || (strcasecmp($site_host, $dest_host) === 0);
     528    $is_internal = wpcs_is_internal_host($site_host, $dest_host);
    476529
    477530    if ($is_internal && $click_id && !$is_bot) {
    478         $target_url = add_query_arg('wpcs_ref', $click_id, $target_url);
     531        $target_url = add_query_arg([
     532            'wpcs_ref'      => $click_id,
     533            'wpcs_endpoint' => rawurlencode(admin_url('admin-ajax.php'))
     534        ], $target_url);
    479535    }
    480536
    … …  
    503559// Internal Page Dwell Time Tracker & Beacon Endpoint
    504560// --------------------------------------------------
     561/**
     562 * Helper: Detect whether target host is internal or belongs to the same domain network (e.g. *.vautobasics.com)
     563 */
     564function wpcs_is_internal_host($site_host, $dest_host) {
     565    if (empty($dest_host) || strcasecmp($site_host, $dest_host) === 0) {
     566        return true;
     567    }
     568    $site_parts = explode('.', strtolower($site_host));
     569    $dest_parts = explode('.', strtolower($dest_host));
     570    if (count($site_parts) >= 2 && count($dest_parts) >= 2) {
     571        $site_root = implode('.', array_slice($site_parts, -2));
     572        $dest_root = implode('.', array_slice($dest_parts, -2));
     573        if ($site_root === $dest_root) {
     574            return true;
     575        }
     576    }
     577    return false;
     578}
     579
     580function wpcs_get_dwell_tracker_html() {
     581    ob_start();
     582    wpcs_render_dwell_tracker();
     583    return ob_get_clean();
     584}
     585
    505586add_action('wp_footer', 'wpcs_render_dwell_tracker', 99);
    506587function wpcs_render_dwell_tracker() {
    507     if (!isset($_GET['wpcs_ref'])) return;
    508     $ref_id = absint($_GET['wpcs_ref']);
    509     if (!$ref_id) return;
     588    if (is_admin()) return;
     589    $default_endpoint = esc_url(admin_url('admin-ajax.php'));
    510590    ?>
    511     <script id="wpcs-dwell-tracker">
    512     (function() {
    513         var clickId = <?php echo (int)$ref_id; ?>;
    514         var startTime = Date.now();
    515         var totalActive = 0;
    516         var lastActiveTime = startTime;
    517         var isHidden = false;
    518         var sent = false;
    519 
    520         document.addEventListener('visibilitychange', function() {
    521             if (document.visibilityState === 'hidden') {
    522                 isHidden = true;
    523                 totalActive += Math.round((Date.now() - lastActiveTime) / 1000);
    524             } else {
    525                 isHidden = false;
    526                 lastActiveTime = Date.now();
     591    <script id="wpcs-dwell-tracker" data-cfasync="false" data-no-optimize="1" data-no-defer="1" data-no-minify="1" data-pagespeed-no-defer nowprocket>
     592    (function () {
     593        var KEY = 'wpcs_dwell', MAX = 7200;
     594        var params = new URLSearchParams(window.location.search);
     595        var urlRef = parseInt(params.get('wpcs_ref'), 10) || 0;
     596        var state = null;
     597
     598        try { state = JSON.parse(sessionStorage.getItem(KEY) || 'null'); } catch (e) {}
     599
     600        if (urlRef) {
     601            // New click, or same click being reloaded
     602            if (!state || state.id !== urlRef) {
     603                var ep = params.get('wpcs_endpoint') || '<?php echo $default_endpoint; ?>';
     604                state = { id: urlRef, endpoint: ep, total: 0 };
    527605            }
     606            // Clean the URL so visitors don't share tracking params
     607            try {
     608                params.delete('wpcs_ref');
     609                params.delete('wpcs_endpoint');
     610                var qs = params.toString();
     611                history.replaceState(null, '', location.pathname + (qs ? '?' + qs : '') + location.hash);
     612            } catch (e) {}
     613        }
     614
     615        if (!state || !state.id || !state.endpoint) return;
     616
     617        // Only allow endpoints on the same root domain
     618        try {
     619            var epHost = new URL(state.endpoint).hostname.split('.').slice(-2).join('.');
     620            var myHost = location.hostname.split('.').slice(-2).join('.');
     621            if (epHost !== myHost) return;
     622        } catch (e) { return; }
     623
     624        var base = state.total || 0;
     625        var activeMs = 0;
     626        var last = (document.visibilityState === 'visible') ? Date.now() : null;
     627
     628        function tick() {
     629            if (last !== null) { var n = Date.now(); activeMs += (n - last); last = n; }
     630        }
     631
     632        function send() {
     633            tick();
     634            var total = Math.min(base + Math.round(activeMs / 1000), MAX);
     635            if (total < 1) return;
     636            state.total = total;
     637            try { sessionStorage.setItem(KEY, JSON.stringify(state)); } catch (e) {}
     638
     639            var body = 'action=wpcs_record_dwell&click_id=' + state.id + '&dwell_seconds=' + total;
     640            var sent = false;
     641            if (navigator.sendBeacon) {
     642                sent = navigator.sendBeacon(state.endpoint,
     643                    new Blob([body], { type: 'application/x-www-form-urlencoded' }));
     644            }
     645            if (!sent && window.fetch) {
     646                fetch(state.endpoint, {
     647                    method: 'POST', body: body, keepalive: true, mode: 'cors', credentials: 'omit',
     648                    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
     649                }).catch(function () {});
     650            }
     651        }
     652
     653        window.__wpcs_send_dwell = send;
     654
     655        document.addEventListener('visibilitychange', function () {
     656            if (document.visibilityState === 'hidden') { tick(); last = null; send(); }
     657            else { last = Date.now(); }
    528658        });
    529 
    530         function sendDwellTime() {
    531             if (sent) return;
    532             if (!isHidden) {
    533                 totalActive += Math.round((Date.now() - lastActiveTime) / 1000);
    534             }
    535             if (totalActive < 1) return;
    536             sent = true;
    537 
    538             var data = new FormData();
    539             data.append('action', 'wpcs_record_dwell');
    540             data.append('click_id', clickId);
    541             data.append('dwell_seconds', Math.min(totalActive, 7200));
    542 
    543             var ajaxUrl = '<?php echo esc_url(admin_url('admin-ajax.php')); ?>';
    544             if (navigator.sendBeacon) {
    545                 navigator.sendBeacon(ajaxUrl, data);
    546             } else {
    547                 var xhr = new XMLHttpRequest();
    548                 xhr.open('POST', ajaxUrl, false);
    549                 xhr.send(data);
    550             }
    551         }
    552 
    553         window.addEventListener('pagehide', sendDwellTime);
    554         window.addEventListener('beforeunload', sendDwellTime);
     659        window.addEventListener('pagehide', send);
     660
     661        setTimeout(send, 2000);
     662        setInterval(send, 10000);
    555663    })();
    556664    </script>
    … …  
    561669add_action('wp_ajax_wpcs_record_dwell', 'wpcs_ajax_record_dwell');
    562670function wpcs_ajax_record_dwell() {
    563     $click_id = absint($_POST['click_id'] ?? 0);
    564     $seconds  = absint($_POST['dwell_seconds'] ?? 0);
     671    // CORS: only allow origins on the same root domain
     672    $origin = isset($_SERVER['HTTP_ORIGIN']) ? esc_url_raw(wp_unslash($_SERVER['HTTP_ORIGIN'])) : '';
     673    if ($origin) {
     674        $o_host = wp_parse_url($origin, PHP_URL_HOST);
     675        if ($o_host && wpcs_is_internal_host(wp_parse_url(home_url(), PHP_URL_HOST), $o_host)) {
     676            header('Access-Control-Allow-Origin: ' . $origin);
     677            header('Access-Control-Allow-Credentials: true');
     678            header('Vary: Origin');
     679        }
     680    }
     681    header('Access-Control-Allow-Methods: POST, OPTIONS');
     682    header('Access-Control-Allow-Headers: Content-Type');
     683
     684    if (($_SERVER['REQUEST_METHOD'] ?? '') === 'OPTIONS') {
     685        status_header(200);
     686        exit;
     687    }
     688
     689    $click_id = absint($_REQUEST['click_id'] ?? 0);
     690    $seconds  = absint($_REQUEST['dwell_seconds'] ?? 0);
     691
     692    if (!$click_id || !$seconds) {
     693        $raw = file_get_contents('php://input');
     694        if (!empty($raw)) {
     695            $parsed = [];
     696            parse_str($raw, $parsed);
     697            if (!empty($parsed['click_id'])) $click_id = absint($parsed['click_id']);
     698            if (!empty($parsed['dwell_seconds'])) $seconds = absint($parsed['dwell_seconds']);
     699        }
     700    }
     701
    565702    if ($click_id && $seconds > 0) {
    566703        global $wpdb;
    567704        $click_tbl = $wpdb->prefix . 'wpcs_clicks';
    568         $wpdb->update($click_tbl, ['dwell_time' => min($seconds, 7200)], ['id' => $click_id]);
    569     }
    570     wp_die();
     705        // GREATEST() so a late/out-of-order beacon never lowers the value
     706        $wpdb->query($wpdb->prepare(
     707            "UPDATE {$click_tbl} SET dwell_time = GREATEST(dwell_time, %d) WHERE id = %d",
     708            min($seconds, 7200),
     709            $click_id
     710        ));
     711    }
     712    wp_send_json_success();
    571713}
    572714
    … …  
    9241066    );
    9251067
     1068    if (class_exists('WPCS_Landing_Pages')) {
     1069        add_submenu_page(
     1070            $top_slug,
     1071            __('Landing Pages & Pre-Landers', 'custom-link-shortener'),
     1072            __('Landing Pages', 'custom-link-shortener'),
     1073            'manage_options',
     1074            'wpcs-landing-pages',
     1075            ['WPCS_Landing_Pages', 'render_admin_page']
     1076        );
     1077    }
     1078
    9261079    add_submenu_page(
    9271080        $top_slug,
    … …  
    9461099        update_option('wpcs_autolink_max_total',     absint($_POST['wpcs_autolink_max_total']));
    9471100
     1101        if (class_exists('WPCS_Landing_Pages')) {
     1102            update_option('wpcs_default_meta_pixel',   WPCS_Landing_Pages::extract_meta_pixel_id(wp_unslash($_POST['wpcs_default_meta_pixel'] ?? '')));
     1103            update_option('wpcs_default_ga_id',        WPCS_Landing_Pages::extract_ga_id(wp_unslash($_POST['wpcs_default_ga_id'] ?? '')));
     1104            update_option('wpcs_default_tiktok_pixel', WPCS_Landing_Pages::extract_tiktok_pixel_id(wp_unslash($_POST['wpcs_default_tiktok_pixel'] ?? '')));
     1105        } else {
     1106            update_option('wpcs_default_meta_pixel',   sanitize_text_field(wp_unslash($_POST['wpcs_default_meta_pixel'] ?? '')));
     1107            update_option('wpcs_default_ga_id',        sanitize_text_field(wp_unslash($_POST['wpcs_default_ga_id'] ?? '')));
     1108            update_option('wpcs_default_tiktok_pixel', sanitize_text_field(wp_unslash($_POST['wpcs_default_tiktok_pixel'] ?? '')));
     1109        }
     1110
    9481111        wpcs_add_rewrite_rule();
     1112        if (class_exists('WPCS_Landing_Pages')) {
     1113            WPCS_Landing_Pages::add_rewrite_rules();
     1114        }
    9491115        flush_rewrite_rules();
    9501116        echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__('Settings saved and rewrite rules flushed.', 'custom-link-shortener') . '</p></div>';
    … …  
    10531219                    <label for="wpcs_alert_email"><strong><?php esc_html_e('Click Goal Alert Email', 'custom-link-shortener'); ?></strong></label>
    10541220                    <input type="email" id="wpcs_alert_email" name="wpcs_alert_email" value="<?php echo esc_attr($alert_email); ?>" style="max-width:400px;">
     1221                </div>
     1222            </div>
     1223
     1224            <div class="wpcs-card wpcs-partition-card">
     1225                <div class="wpcs-partition-header">
     1226                    <h2><span class="dashicons dashicons-chart-line"></span> <?php esc_html_e('Global Tracking Pixels & Analytics Defaults', 'custom-link-shortener'); ?></h2>
     1227                </div>
     1228                <p class="description" style="margin-bottom:1.25rem;">
     1229                    <?php esc_html_e('Configure default tracking IDs for your landing pages. When creating or editing landing pages, any tracking fields left blank will automatically inherit these global defaults. You can paste either the clean ID or the full tracking code snippet (the smart extractor will clean it automatically).', 'custom-link-shortener'); ?>
     1230                </p>
     1231                <div class="form-field" style="margin-bottom:1.25rem;">
     1232                    <label for="wpcs_default_meta_pixel"><strong><?php esc_html_e('Default Meta Pixel ID', 'custom-link-shortener'); ?></strong></label>
     1233                    <input type="text" id="wpcs_default_meta_pixel" name="wpcs_default_meta_pixel" value="<?php echo esc_attr(get_option('wpcs_default_meta_pixel', '')); ?>" placeholder="e.g. 1312023820383414" style="max-width:400px; width:100%;">
     1234                    <p class="description"><?php esc_html_e('Fires standard PageView on landing page visit and PrelanderClick on button click.', 'custom-link-shortener'); ?></p>
     1235                </div>
     1236                <div class="form-field" style="margin-bottom:1.25rem;">
     1237                    <label for="wpcs_default_ga_id"><strong><?php esc_html_e('Default Google Analytics / GTM ID', 'custom-link-shortener'); ?></strong></label>
     1238                    <input type="text" id="wpcs_default_ga_id" name="wpcs_default_ga_id" value="<?php echo esc_attr(get_option('wpcs_default_ga_id', '')); ?>" placeholder="e.g. G-Q7V54CNSGL or GT-XXXXX" style="max-width:400px; width:100%;">
     1239                    <p class="description"><?php esc_html_e('Google Analytics 4 Measurement ID or Google Tag Manager Container ID.', 'custom-link-shortener'); ?></p>
     1240                </div>
     1241                <div class="form-field" style="margin-bottom:1.25rem;">
     1242                    <label for="wpcs_default_tiktok_pixel"><strong><?php esc_html_e('Default TikTok Pixel ID', 'custom-link-shortener'); ?></strong></label>
     1243                    <input type="text" id="wpcs_default_tiktok_pixel" name="wpcs_default_tiktok_pixel" value="<?php echo esc_attr(get_option('wpcs_default_tiktok_pixel', '')); ?>" placeholder="e.g. C8X9ABCD1234" style="max-width:400px; width:100%;">
     1244                    <p class="description"><?php esc_html_e('TikTok Pixel ID for tracking pre-lander views and outbound clicks.', 'custom-link-shortener'); ?></p>
    10551245                </div>
    10561246            </div>
    … …  
    19222112        : ($this_month_clicks > 0 ? 100 : 0);
    19232113
    1924     $overall_ctr = ($total_impressions > 0) ? round(($total_clicks / $total_impressions) * 100, 1) . '%' : '0.0%';
     2114    $last_click = $wpdb->get_row("SELECT l.alias, c.clicked_at FROM {$clicks_tbl} c JOIN {$links_tbl} l ON c.link_id = l.id WHERE c.is_bot = 0 ORDER BY c.clicked_at DESC LIMIT 1");
     2115    $last_click_text = __('No clicks yet', 'custom-link-shortener');
     2116    if ($last_click) {
     2117        $last_click_text = sprintf(__('%s ago via /%s', 'custom-link-shortener'), human_time_diff(strtotime($last_click->clicked_at), current_time('timestamp')), esc_html($last_click->alias));
     2118    }
    19252119
    19262120    $selected_cat = sanitize_text_field($_GET['filter_category'] ?? '');
    … …  
    19802174        </div>
    19812175        <div class="wpcs-stat-card wpcs-stat--warning">
    1982             <div class="stat-label"><?php esc_html_e('Average CTR', 'custom-link-shortener'); ?></div>
    1983             <div class="stat-value"><?php echo esc_html($overall_ctr); ?></div>
    1984             <div class="stat-sub"><?php echo ($total_impressions > 0) ? sprintf(esc_html__('Across %s views', 'custom-link-shortener'), number_format_i18n($total_impressions)) : esc_html__('From on-site links (No impressions recorded yet)', 'custom-link-shortener'); ?></div>
     2176            <div class="stat-label"><?php esc_html_e('Last Click', 'custom-link-shortener'); ?></div>
     2177            <div class="stat-value" style="font-size:1.1rem; line-height:1.3; word-break:break-word; font-weight:700;"><?php echo esc_html($last_click_text); ?></div>
     2178            <div class="stat-sub"><?php esc_html_e('Most recent activity', 'custom-link-shortener'); ?></div>
    19852179        </div>
    19862180    </div>
    … …  
    21372331                            <td style="text-align:center;">
    21382332                                <span class="wpcs-click-count"><?php echo number_format_i18n($link->total_clicks); ?></span>
    2139                                 <small class="wpcs-text-muted" style="display:block; font-size:11px;">
    2140                                     <?php echo ($link_impressions > 0) ? 'CTR: <strong>' . esc_html($link_ctr) . '</strong>' : '<span title="' . esc_attr__('No on-site impressions recorded yet', 'custom-link-shortener') . '">' . esc_html__('0.0% CTR', 'custom-link-shortener') . '</span>'; ?>
    2141                                 </small>
    21422333                            </td>
    21432334                            <td><?php echo $last_click_date; ?></td>
    … …  
    22062397    foreach ($dests as $d) {
    22072398        $dh = wp_parse_url($d->destination_url, PHP_URL_HOST);
    2208         if (empty($dh) || strcasecmp($site_host, $dh) === 0) {
     2399        if (wpcs_is_internal_host($site_host, $dh)) {
    22092400            $has_internal = true;
    22102401            break;
    … …  
    24802671add_action('admin_enqueue_scripts', 'wpcs_enqueue_admin_assets');
    24812672function wpcs_enqueue_admin_assets($hook) {
    2482     if (!isset($_GET['page']) || !in_array($_GET['page'], ['wpcs-shortener', 'wpcs-analytics', 'wpcs-settings'], true)) {
     2673    if (!isset($_GET['page']) || !in_array($_GET['page'], ['wpcs-shortener', 'wpcs-analytics', 'wpcs-settings', 'wpcs-landing-pages'], true)) {
    24832674        return;
    24842675    }
    … …  
    24932684add_action('admin_head', 'wpcs_inline_admin_styles');
    24942685function wpcs_inline_admin_styles() {
    2495     if (!isset($_GET['page']) || !in_array($_GET['page'], ['wpcs-shortener', 'wpcs-analytics', 'wpcs-settings'], true)) {
     2686    if (!isset($_GET['page']) || !in_array($_GET['page'], ['wpcs-shortener', 'wpcs-analytics', 'wpcs-settings', 'wpcs-landing-pages'], true)) {
    24962687        return;
    24972688    }
    … …  
    28373028add_action('admin_footer', 'wpcs_inline_admin_scripts');
    28383029function wpcs_inline_admin_scripts() {
    2839     if (!isset($_GET['page']) || !in_array($_GET['page'], ['wpcs-shortener', 'wpcs-analytics', 'wpcs-settings'], true)) {
     3030    if (!isset($_GET['page']) || !in_array($_GET['page'], ['wpcs-shortener', 'wpcs-analytics', 'wpcs-settings', 'wpcs-landing-pages'], true)) {
    28403031        return;
    28413032    }
    … …  
    29263117        }
    29273118
    2928         jQuery(document).ready(function($) {
     3119        jQuery(function($) {
    29293120            $(document).on('click', '.wpcs-copy', function(e) {
    29303121                e.preventDefault();
    … …  
    32263417}
    32273418
     3419// --------------------------------------------------
     3420// Modular Subsystems (Safe Isolated Loaders)
     3421// --------------------------------------------------
     3422$wpcs_templates_file = WPCS_PLUGIN_DIR . 'includes/class-wpcs-templates.php';
     3423if (file_exists($wpcs_templates_file)) {
     3424    require_once $wpcs_templates_file;
     3425}
     3426
     3427$wpcs_lp_file = WPCS_PLUGIN_DIR . 'includes/class-wpcs-landing-pages.php';
     3428if (file_exists($wpcs_lp_file)) {
     3429    require_once $wpcs_lp_file;
     3430}
  • custom-link-shortener/trunk/js/admin.js

    r3823045 r3835111  
    112112
    113113    // --------------------------------------------------
    114     // DOM Ready Setup
    115     // --------------------------------------------------
    116     $(document).ready(function() {
     114    // DOM Ready Setup (jQuery 4 / Migrate 3.6.0 compatible)
     115    // --------------------------------------------------
     116    $(function() {
    117117
    118118        // 1. Copy URL with tactile text change + toast
    … …  
    351351    });
    352352
     353
     354    // --------------------------------------------------
     355    // Smart Tracking ID Auto-Extractors on Settings Page
     356    // --------------------------------------------------
     357    function wpcsExtractMeta(val) {
     358        if (!val) return '';
     359        val = val.trim();
     360        var initMatch = val.match(/fbq\s*\(\s*['"]init['"]\s*,\s*['"]?(\d+)['"]?/i);
     361        if (initMatch) return initMatch[1];
     362        var trMatch = val.match(/[?&]id=(\d+)/i);
     363        if (trMatch) return trMatch[1];
     364        var numMatch = val.match(/\b\d{10,20}\b/);
     365        if (numMatch) return numMatch[0];
     366        if (/<script|fbq/i.test(val)) return val.replace(/[^0-9]/g, '');
     367        return val.trim();
     368    }
     369
     370    function wpcsExtractGA(val) {
     371        if (!val) return '';
     372        val = val.trim();
     373        var gMatch = val.match(/\b(G-[A-Z0-9]+|GT-[A-Z0-9]+|UA-\d+-\d+|AW-\d+)\b/i);
     374        if (gMatch) return gMatch[1].toUpperCase();
     375        return val.trim();
     376    }
     377
     378    function wpcsExtractTikTok(val) {
     379        if (!val) return '';
     380        val = val.trim();
     381        var ttqMatch = val.match(/ttq\.load\s*\(\s*['"]([A-Z0-9]+)['"]/i);
     382        if (ttqMatch) return ttqMatch[1].toUpperCase();
     383        var sdkMatch = val.match(/[?&]sdkid=([A-Z0-9]+)/i);
     384        if (sdkMatch) return sdkMatch[1].toUpperCase();
     385        var codeMatch = val.match(/\b([A-Z0-9]{9,25})\b/i);
     386        if (codeMatch && !/script|function|document|window/i.test(codeMatch[0])) return codeMatch[1].toUpperCase();
     387        return val.trim();
     388    }
     389
     390    function wpcsAttachExtractor(selector, fn, name) {
     391        $(document).on('paste input change', selector, function() {
     392            var $el = $(this);
     393            var raw = $el.val();
     394            if (!raw) return;
     395            var clean = fn(raw);
     396            if (clean && clean !== raw) {
     397                $el.val(clean);
     398                if (window.wpcsShowToast) {
     399                    window.wpcsShowToast('Extracted ' + name + ' ID: ' + clean);
     400                }
     401            }
     402        });
     403    }
     404
     405    $(function() {
     406        wpcsAttachExtractor('#wpcs_default_meta_pixel', wpcsExtractMeta, 'Meta Pixel');
     407        wpcsAttachExtractor('#wpcs_default_ga_id', wpcsExtractGA, 'Google Analytics');
     408        wpcsAttachExtractor('#wpcs_default_tiktok_pixel', wpcsExtractTikTok, 'TikTok Pixel');
     409    });
     410
    353411})(jQuery);
    354 
  • custom-link-shortener/trunk/readme.txt

    r3823045 r3835111  
    44Tags: url-shortener, custom-links, click-tracking, auto-linker, affiliate-links
    55Requires at least: 5.0
    6 Tested up to: 7.1
    7 Stable tag: 2.8.2
     6Tested up to: 7.2
     7Stable tag: 3.0.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    103103== Changelog ==
    104104
     105=== 2.9.0 ===
     106- Added High-Converting Bridge & Pre-Lander Landing Page Engine with 5 optimized styles (Direct Action Pulsar, Digital Verification Badge, Minimalist Choice, Official Notice, and Quiz Stepper) plus Raw Custom HTML mode
     107- Added Live Split-Screen Builder with real-time Mobile (375px) and Desktop interactive device frame previews
     108- Added Creative Niche & Compliance Presets with auto-suggested legal & earnings disclaimers (Surveys, Jobs, Relocation, Finance, Health, Universal)
     109- Added Discrete Micro-Compliance Footer ensuring 100% ad network policy compliance across Meta, TikTok, and Google Ads without cluttering the page
     110- Added Per-Landing-Page Pixel Tracking for Meta Pixel, Google tag (gtag.js), TikTok Pixel, and custom head scripts with automated beacon event tracking
     111- Added Dynamic Automated UTM & Query Parameter Passthrough to preserve attribution tags
     112- Verified 100% WordPress 7.2 & PHP 8.6 compatibility and updated jQuery 4 / jQuery Migrate 3.6.0 handlers
     113
    105114=== 2.8.2 ===
    106115- Fixed backwards-compatibility query to guarantee all existing shortlinks display seamlessly on dashboard
    … …  
    140149== Upgrade Notice ==
    141150
     151=== 3.0.0 ===
     152Major release adding 3 high-converting pre-lander templates (Anti-Bot Human Verification with simulated signal analysis, Perforated Ticket Pass, and Tech Access Portal Pass), real-time progressive dwell time telemetry, template lock security, and builder workflow optimizations.
     153
     154=== 2.9.0 ===
     155Introduces the Arbitrage & Bridge Landing Page Engine, live split-screen mobile/desktop preview builder, creative niche compliance disclaimers, per-page pixel tracking, and WordPress 7.2 compatibility.
     156
    142157=== 2.8.2 ===
    143158- Fixed backwards-compatibility query to guarantee all existing shortlinks display seamlessly on dashboard
Note: See TracChangeset for help on using the changeset viewer.