Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/instagram-feed/admin/SBI_Callout.php
+++ b/instagram-feed/admin/SBI_Callout.php
@@ -357,8 +357,10 @@
}
$process_percent = $process === 0 ? 0 : intval(100 / (sizeof($plugins_list) / $process));
+ // SMASH-1670: use a trusted, explicit admin base instead of letting
+ // add_query_arg() fall back to the attacker-controlled $_SERVER['REQUEST_URI'].
$dismiss_callout = wp_nonce_url(
- add_query_arg(['sb_dismiss' => 'callout']),
+ add_query_arg(['sb_dismiss' => 'callout'], admin_url('index.php')),
'sb-callout',
'sb_nonce'
);
@@ -367,14 +369,14 @@
<div class="sb-callout-ctn" data-type="<?php echo $type ?>">
<div class="sb-callout-top sb-fs">
<div class="sb-callout-top-heading">
- <svg width="16" height="17" viewBox="0 0 16 17" fill="none">
+ <svg width="16" height="17" viewBox="0 0 16 17" fill="none" aria-hidden="true" focusable="false">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M7.908 0.5C11.2231 0.5 13.9095 3.82243 13.9095 7.92084C13.9095 11.7725 11.5374 14.9377 8.50226 15.3061L9.23157 16.1975L7.1529 16.3743L7.48441 15.3245C4.36702 15.0556 1.90527 11.8498 1.90527 7.92084C1.90527 3.82243 4.59293 0.5 7.908 0.5ZM9.62864 6.08918L9.3398 3.10897L7.49633 5.42022L4.85195 3.91264L5.62324 6.66616L2.82813 7.56509L5.43923 8.88209L4.40933 11.6475L7.08659 10.4207L8.41253 13.0003L9.2858 10.1197L12.1663 10.6611L10.4565 8.18805L12.6214 6.17515L9.62864 6.08918Z"
fill="#FE544F"/>
</svg>
<strong>
<span class="sb-callout-only-visible">
- <svg width="13" height="14" viewBox="0 0 13 14" fill="none">
+ <svg width="13" height="14" viewBox="0 0 13 14" fill="none" aria-hidden="true" focusable="false">
<path d="M6.49984 5.375C6.06886 5.375 5.65553 5.5462 5.35079 5.85095C5.04604 6.1557 4.87484 6.56902 4.87484 7C4.87484 7.43098 5.04604 7.8443 5.35079 8.14905C5.65553 8.4538 6.06886 8.625 6.49984 8.625C6.93081 8.625 7.34414 8.4538 7.64889 8.14905C7.95363 7.8443 8.12484 7.43098 8.12484 7C8.12484 6.56902 7.95363 6.1557 7.64889 5.85095C7.34414 5.5462 6.93081 5.375 6.49984 5.375ZM6.49984 9.70833C5.78154 9.70833 5.09267 9.42299 4.58476 8.91508C4.07685 8.40717 3.7915 7.71829 3.7915 7C3.7915 6.28171 4.07685 5.59283 4.58476 5.08492C5.09267 4.57701 5.78154 4.29167 6.49984 4.29167C7.21813 4.29167 7.90701 4.57701 8.41492 5.08492C8.92283 5.59283 9.20817 6.28171 9.20817 7C9.20817 7.71829 8.92283 8.40717 8.41492 8.91508C7.90701 9.42299 7.21813 9.70833 6.49984 9.70833ZM6.49984 2.9375C3.7915 2.9375 1.47859 4.62208 0.541504 7C1.47859 9.37792 3.7915 11.0625 6.49984 11.0625C9.20817 11.0625 11.5211 9.37792 12.4582 7C11.5211 4.62208 9.20817 2.9375 6.49984 2.9375Z"
fill="#0068A0"/>
</svg>
@@ -383,7 +385,7 @@
<span class="sb-fs"><?php echo __('Smash Balloon Feeds', 'instagram-feed') ?></span>
</strong>
</div>
- <span <?php echo self::js_open_link(esc_url($dismiss_callout), '_self') ?> class="sb-callout-top-dismiss"></span>
+ <a href="<?php echo esc_url($dismiss_callout); ?>" class="sb-callout-top-dismiss" aria-label="<?php echo esc_attr__('Dismiss', 'instagram-feed'); ?>"></a>
</div>
<div class="sb-callout-progress sb-fs">
<div
@@ -393,7 +395,7 @@
<span>
<?php echo esc_attr($process_percent); ?>%
</span>
- <svg width="71" height="71" viewBox="0 0 71 71" class="sb-progress-svg">
+ <svg width="71" height="71" viewBox="0 0 71 71" class="sb-progress-svg" aria-hidden="true" focusable="false">
<circle class="sb-progress-svg-bg"></circle>
<circle class="sb-progress-svg-fg"></circle>
</svg>
@@ -412,9 +414,9 @@
<?php echo ($key === 'instagram' ? __('Create an', 'instagram-feed') : __('Create a', 'instagram-feed')) . ' ' . ucfirst($key) . ' ' . __('Feed', 'instagram-feed') ?>
</span>
<?php if (sizeof($plugins_list) === 1) { ?>
- <span <?php echo self::js_open_link(esc_url(admin_url('admin.php?page=' . $plugin['page']))) ?> class="sb-callout-item-btn">
+ <a href="<?php echo esc_url(admin_url('admin.php?page=' . $plugin['page'])); ?>" target="_blank" rel="noopener noreferrer" class="sb-callout-item-btn">
<?php echo __('Go to Plugin', 'instagram-feed') ?>
- </span>
+ </a>
<?php } ?>
</div>
<?php } ?>
@@ -423,12 +425,12 @@
$next_p = self::next_plugin($plugins_list);
?>
<div class="sb-callout-bottom-btns sb-fs">
- <span <?php echo self::js_open_link(esc_url(admin_url('admin.php?page=' . $plugins_list[$next_p]['page']))) ?> class="sb-callout-item-btn">
+ <a href="<?php echo esc_url(admin_url('admin.php?page=' . $plugins_list[$next_p]['page'])); ?>" target="_blank" rel="noopener noreferrer" class="sb-callout-item-btn">
<?php echo __('Go to', 'instagram-feed') . ' ' . ucfirst($next_p) . ' ' . __('Plugin', 'instagram-feed') ?>
- </span>
- <span <?php echo self::js_open_link(esc_url($dismiss_callout), '_self') ?> class="sb-callout-item-btn sb-callout-item-btn-grey">
+ </a>
+ <a href="<?php echo esc_url($dismiss_callout); ?>" class="sb-callout-item-btn sb-callout-item-btn-grey">
<?php echo __('Skip this step', 'instagram-feed') ?>
- </span>
+ </a>
</div>
<?php } ?>
</div>
@@ -437,18 +439,6 @@
}
/**
- * Open Link
- *
- * @return string
- *
- * @since X.X
- */
- public static function js_open_link($url, $target = "_blank")
- {
- return 'onclick="window.open('' . $url . '', '' . $target . '')" ';
- }
-
- /**
* Get Next Plugin for Setup
*
* @return int
--- a/instagram-feed/admin/SBI_Global_Settings.php
+++ b/instagram-feed/admin/SBI_Global_Settings.php
@@ -28,6 +28,7 @@
use function json_decode;
use function sbi_is_pro_version;
use function stripslashes;
+use InstagramFeedUsageTrackingConfig as SmashTrackingConfig;
class SBI_Global_Settings
{
@@ -170,20 +171,27 @@
$sbi_settings['email_notification'] = sanitize_text_field($advanced['email_notification']);
$sbi_settings['email_notification_addresses'] = sanitize_text_field($advanced['email_notification_addresses']);
- $usage_tracking = get_option('sbi_usage_tracking', array('last_send' => 0, 'enabled' => sbi_is_pro_version()));
- if (isset($advanced['email_notification_addresses'])) {
- $usage_tracking['enabled'] = false;
- if (isset($advanced['usage_tracking'])) {
- if (!is_array($usage_tracking)) {
- $usage_tracking = array(
- 'enabled' => $advanced['usage_tracking'],
- 'last_send' => 0,
- );
- } else {
- $usage_tracking['enabled'] = $advanced['usage_tracking'];
- }
+ if ( isset( $advanced['usage_tracking'] ) ) {
+ $tracking_enabled = (bool) $advanced['usage_tracking'];
+ $usage_tracking = get_option(
+ 'sbi_usage_tracking',
+ array(
+ 'enabled' => SmashTrackingConfig::DEFAULT_ENABLED,
+ 'last_send' => 0,
+ )
+ );
+ $last_send = is_array( $usage_tracking ) && isset( $usage_tracking['last_send'] ) ? $usage_tracking['last_send'] : 0;
+ update_option(
+ 'sbi_usage_tracking',
+ array(
+ 'enabled' => $tracking_enabled,
+ 'last_send' => $last_send,
+ ),
+ false
+ );
+ if ( ! $tracking_enabled ) {
+ wp_clear_scheduled_hook( SmashTrackingConfig::CRON_HOOK );
}
- update_option('sbi_usage_tracking', $usage_tracking, false);
}
// Update the sbi_style_settings option that contains data for translation and advanced tabs
@@ -1052,7 +1060,7 @@
),
'usageBox' => array(
'title' => __('Usage Tracking', 'instagram-feed'),
- 'helpText' => sprintf(__('This helps to prevent plugin and theme conflicts by sending a report in the background once per week about your settings and relevant site stats. It does not send sensitive information like access tokens, email addresses, or user info. This will also not affect your site performance. %s', 'instagram-feed'), '<a href="' . $usage_tracking_url . '" target="_blank">' . __('Learn More', 'instagram-feed') . '</a>'),
+ 'helpText' => sprintf( __( 'Send a weekly report to Smash Balloon to help improve the product. No sensitive data is collected. You can disable this at any time. %s', 'instagram-feed' ), '<a href="' . $usage_tracking_url . '" target="_blank">' . __( 'Learn More', 'instagram-feed' ) . '</a>' ),
),
'resetErrorBox' => array(
'title' => __('Reset Error Log', 'instagram-feed'),
@@ -1181,7 +1189,6 @@
$sbi_cache_cron_interval = $sbi_settings['sbi_cache_cron_interval'];
$sbi_cache_cron_time = $sbi_settings['sbi_cache_cron_time'];
$sbi_cache_cron_am_pm = $sbi_settings['sbi_cache_cron_am_pm'];
- $usage_tracking = get_option('sbi_usage_tracking', array('last_send' => 0, 'enabled' => sbi_is_pro_version()));
$sbi_ajax = $sbi_settings['sb_instagram_ajax_theme'];
$active_gdpr_plugin = SB_Instagram_GDPR_Integrations::gdpr_plugins_active();
$sbi_preserve_setitngs = $sbi_settings['sb_instagram_preserve_settings'];
@@ -1220,7 +1227,7 @@
'advanced' => array(
'sbi_enable_resize' => !$sbi_settings['sb_instagram_disable_resize'],
'image_format' => $sbi_settings['image_format'],
- 'usage_tracking' => $usage_tracking['enabled'],
+ 'usage_tracking' => SmashTrackingConfig::is_enabled(),
'sbi_ajax' => $sbi_ajax,
'sb_ajax_initial' => $sbi_settings['sb_ajax_initial'],
'sbi_enqueue_js_in_head' => $sbi_settings['enqueue_js_in_head'],
--- a/instagram-feed/admin/views/settings/tab/advanced.php
+++ b/instagram-feed/admin/views/settings/tab/advanced.php
@@ -104,7 +104,6 @@
</div>
</div>
-
<div class="sb-tab-box sb-load-ajax-box sb-reset-box-style clearfix">
<div class="tab-label">
<h3>{{advancedTab.ajaxInitial.title}}</h3>
--- a/instagram-feed/inc/Builder/SBI_Db.php
+++ b/instagram-feed/inc/Builder/SBI_Db.php
@@ -903,6 +903,12 @@
delete_option('sb_instagram_errors');
delete_option('sbi_usage_tracking_config');
delete_option('sbi_usage_tracking');
+ delete_option( 'sbi_smash_usage_tracking' );
+ delete_option( 'sbi_smash_usage_tracking_site_token' );
+ delete_option( 'sbi_smash_usage_tracking_schedule' );
+ delete_option( 'sbi_smash_usage_events' );
+ delete_option( 'sbi_smash_usage_active_dates' );
+ delete_option( 'sbi_smash_usage_session_durations' );
delete_option('sbi_oembed_token');
delete_option('sbi_top_api_calls');
delete_option('sbi_rating_notice');
@@ -915,6 +921,7 @@
$wp_roles->remove_cap('administrator', 'manage_instagram_feed_options');
wp_clear_scheduled_hook('sbi_feed_update');
wp_clear_scheduled_hook('sbi_usage_tracking_cron');
+ wp_clear_scheduled_hook( InstagramFeedUsageTrackingConfig::CRON_HOOK );
}
/**
--- a/instagram-feed/inc/Builder/Tabs/SBI_Settings_Tab.php
+++ b/instagram-feed/inc/Builder/Tabs/SBI_Settings_Tab.php
@@ -83,10 +83,47 @@
public static function get_settings_filters_moderation_controls()
{
return [
+ // Active post-type toggles — Photos, Feed Videos, Reels all work in Free
+ // via the existing media + videotypes pipeline
+ // (see SB_Instagram_Settings::filter_for_builder()).
+ //
+ // Note: we intentionally do NOT set 'stacked' here. The Vue template
+ // reads control.stacked as a truthiness check — and the string 'false'
+ // is truthy in JS, so 'stacked' => 'false' would end up rendering as
+ // data-stacked="true" and trigger the 5px padding override meant for
+ // stacked controls. Omitting the key keeps the 20px default padding
+ // so the heading doesn't crowd the tab's top border.
[
'type' => 'heading',
'strongHeading' => 'true',
- 'heading' => __('Show specific types of posts', 'instagram-feed')
+ 'heading' => __('Show specific types of posts', 'instagram-feed'),
+ 'checkViewDisabled' => 'moderationMode',
+ ],
+ [
+ 'type' => 'checkbox',
+ 'id' => 'photosposts',
+ 'label' => __('Photos', 'instagram-feed'),
+ 'reverse' => 'true',
+ 'stacked' => 'true',
+ 'checkViewDisabled' => 'moderationMode',
+ 'ajaxAction' => 'feedFlyPreview',
+ 'options' => [
+ 'enabled' => true,
+ 'disabled' => false,
+ ],
+ ],
+ [
+ 'type' => 'checkbox',
+ 'id' => 'videosposts',
+ 'label' => __('Feed Videos', 'instagram-feed'),
+ 'reverse' => 'true',
+ 'stacked' => 'true',
+ 'checkViewDisabled' => 'moderationMode',
+ 'ajaxAction' => 'feedFlyPreview',
+ 'options' => [
+ 'enabled' => true,
+ 'disabled' => false,
+ ],
],
[
'type' => 'checkbox',
@@ -98,22 +135,23 @@
'ajaxAction' => 'feedFlyPreview',
'options' => [
'enabled' => true,
- 'disabled' => false
- ]
+ 'disabled' => false,
+ ],
],
[
'type' => 'separator',
'top' => 20,
- 'bottom' => 20
+ 'bottom' => 20,
],
+ // Pro upsell section — word filters + visual moderation stay paid.
[
'type' => 'heading',
'heading' => __('Advanced', 'instagram-feed'),
'proLabel' => true,
'description' => __('Visually moderate your feed or hide specific posts with Instagram Feed Pro.', 'instagram-feed'),
'checkExtensionPopup' => 'filtermoderation',
- 'checkExtensionPopupLearnMore' => 'filtermoderation'
+ 'checkExtensionPopupLearnMore' => 'filtermoderation',
],
[
@@ -130,8 +168,8 @@
'labelStrong' => true,
'options' => [
'enabled' => true,
- 'disabled' => false
- ]
+ 'disabled' => false,
+ ],
],
'moderationTypes' => [
'allow' => [
@@ -141,8 +179,8 @@
'block' => [
'label' => __('Block List', 'instagram-feed'),
'description' => __('Show all posts by default so you can select the ones you want to hide', 'instagram-feed'),
- ]
- ]
+ ],
+ ],
],
[
'type' => 'heading',
@@ -151,18 +189,18 @@
'checkExtensionDimmed' => 'filtermoderation',
'checkExtensionPopup' => 'filtermoderation',
'disabledInput' => true,
- 'checkViewDisabled' => 'moderationMode'
+ 'checkViewDisabled' => 'moderationMode',
],
[
'type' => 'textarea',
'id' => 'includewords',
'heading' => __('Only show posts containing', 'instagram-feed'),
- 'tooltip' => __('Show your active stories from Instagram when your header avatar is clicked. Displays a colored ring around your avatar when a story is available.', 'instagram-feed'),
+ 'tooltip' => __('Only show posts which contain certain words or hashtags in the caption.', 'instagram-feed'),
'placeholder' => __('Add words here to only show posts containing these words', 'instagram-feed'),
'checkExtensionDimmed' => 'filtermoderation',
'checkExtensionPopup' => 'filtermoderation',
'disabledInput' => true,
- 'checkViewDisabled' => 'moderationMode'
+ 'checkViewDisabled' => 'moderationMode',
],
[
'type' => 'separator',
@@ -171,9 +209,8 @@
'checkExtensionDimmed' => 'filtermoderation',
'checkExtensionPopup' => 'filtermoderation',
'disabledInput' => true,
- 'checkViewDisabled' => 'moderationMode'
+ 'checkViewDisabled' => 'moderationMode',
],
-
[
'type' => 'textarea',
'id' => 'excludewords',
@@ -183,71 +220,8 @@
'placeholder' => __('Add words here to hide any posts containing these words', 'instagram-feed'),
'checkExtensionDimmed' => 'filtermoderation',
'checkExtensionPopup' => 'filtermoderation',
- 'disabledInput' => true,
- 'checkViewDisabled' => 'moderationMode'
- ],
-
- [
- 'type' => 'heading',
- 'strongHeading' => 'true',
- 'stacked' => 'true',
- 'heading' => __('Show specific types of posts', 'instagram-feed'),
- 'checkExtensionDimmed' => 'filtermoderation',
- 'checkExtensionPopup' => 'filtermoderation',
- 'disabledInput' => true,
- 'checkViewDisabled' => 'moderationMode'
- ],
-
- [
- 'type' => 'checkbox',
- 'id' => 'photosposts',
- 'label' => __('Photos', 'instagram-feed'),
- 'reverse' => 'true',
- 'stacked' => 'true',
- 'checkViewDisabled' => 'moderationMode',
- 'ajaxAction' => 'feedFlyPreview',
- 'checkExtensionDimmed' => 'filtermoderation',
- 'checkExtensionPopup' => 'filtermoderation',
- 'disabledInput' => true,
- 'options' => [
- 'enabled' => true,
- 'disabled' => false
- ]
- ],
-
- [
- 'type' => 'checkbox',
- 'id' => 'videosposts',
- 'label' => __('Feed Videos', 'instagram-feed'),
- 'reverse' => 'true',
- 'stacked' => 'true',
- 'checkViewDisabled' => 'moderationMode',
- 'ajaxAction' => 'feedFlyPreview',
- 'checkExtensionDimmed' => 'filtermoderation',
- 'checkExtensionPopup' => 'filtermoderation',
- 'disabledInput' => true,
- 'options' => [
- 'enabled' => true,
- 'disabled' => false
- ]
- ],
- [
- 'type' => 'checkbox',
- 'id' => 'igtvposts',
- 'label' => __('IGTV Videos', 'instagram-feed'),
- 'reverse' => 'true',
- 'stacked' => 'true',
'checkViewDisabled' => 'moderationMode',
- 'ajaxAction' => 'feedFlyPreview',
- 'checkExtensionDimmed' => 'filtermoderation',
- 'checkExtensionPopup' => 'filtermoderation',
- 'disabledInput' => true,
- 'options' => [
- 'enabled' => true,
- 'disabled' => false
- ]
],
-
[
'type' => 'separator',
'top' => 10,
@@ -255,9 +229,8 @@
'checkExtensionDimmed' => 'filtermoderation',
'checkExtensionPopup' => 'filtermoderation',
'disabledInput' => true,
- 'checkViewDisabled' => 'moderationMode'
+ 'checkViewDisabled' => 'moderationMode',
],
-
[
'type' => 'number',
'id' => 'offset',
@@ -270,10 +243,8 @@
'checkExtensionDimmed' => 'filtermoderation',
'checkExtensionPopup' => 'filtermoderation',
'disabledInput' => true,
- 'checkViewDisabled' => 'moderationMode'
+ 'checkViewDisabled' => 'moderationMode',
],
-
-
];
}
--- a/instagram-feed/inc/Helpers/SB_Instagram_Tracking.php
+++ b/instagram-feed/inc/Helpers/SB_Instagram_Tracking.php
@@ -1,343 +0,0 @@
-<?php
-
-namespace InstagramFeedHelpers;
-
-use InstagramFeedBuilderSBI_Db;
-use InstagramFeedBuilderSBI_Source;
-use SB_Instagram_API_Connect;
-use SB_Instagram_Cache;
-use SB_Instagram_Settings;
-
-if (!defined('ABSPATH')) {
- exit;
-}
-
-/**
- * Tracking functions for reporting plugin usage to the Smash Balloon site for users that have opted in
- *
- * @copyright Copyright (c) 2018, Chris Christoff
- * @since 5.6
- */
-class SB_Instagram_Tracking
-{
- public function __construct()
- {
- add_action('init', array($this, 'schedule_send'));
- add_filter('cron_schedules', array($this, 'add_schedules'));
- add_action('sbi_usage_tracking_cron', array($this, 'send_checkin'));
- }
-
- public function send_checkin($override = false, $ignore_last_checkin = false)
- {
- $home_url = trailingslashit(home_url());
- if (strpos($home_url, 'smashballoon.com') !== false) {
- return false;
- }
-
- if (!$this->tracking_allowed() && !$override) {
- return false;
- }
-
- // Send a maximum of once per week
- $usage_tracking = get_option(
- 'sbi_usage_tracking',
- array(
- 'last_send' => 0,
- 'enabled' => sbi_is_pro_version(),
- )
- );
- if (is_numeric($usage_tracking['last_send']) && $usage_tracking['last_send'] > strtotime('-1 week') && !$ignore_last_checkin) {
- return false;
- }
-
- $request = wp_safe_remote_post(
- 'https://usage.smashballoon.com/v1/checkin/',
- array(
- 'method' => 'POST',
- 'timeout' => 5,
- 'redirection' => 5,
- 'httpversion' => '1.1',
- 'blocking' => false,
- 'body' => $this->get_data(),
- 'user-agent' => 'MI/' . SBIVER . '; ' . get_bloginfo('url'),
- )
- );
-
- // If we have completed successfully, recheck in 1 week
- $usage_tracking['last_send'] = time();
- update_option('sbi_usage_tracking', $usage_tracking, false);
- return true;
- }
-
- private function tracking_allowed()
- {
- $usage_tracking = get_option(
- 'sbi_usage_tracking',
- array(
- 'last_send' => 0,
- 'enabled' => sbi_is_pro_version(),
- )
- );
- return isset($usage_tracking['enabled']) ? $usage_tracking['enabled'] : sbi_is_pro_version();
- }
-
- public function get_data()
- {
- $data = array();
-
- // Retrieve current theme info
- $theme_data = wp_get_theme();
-
- $count_b = 1;
- if (is_multisite()) {
- if (function_exists('get_blog_count')) {
- $count_b = get_blog_count();
- } else {
- $count_b = 'Not Set';
- }
- }
-
- $php_version = rtrim(ltrim(sanitize_text_field(phpversion())));
- $php_version = !empty($php_version) ? substr($php_version, 0, strpos($php_version, '.', strpos($php_version, '.') + 1)) : phpversion();
-
- global $wp_version;
- $data['this_plugin'] = 'if';
- $data['php_version'] = $php_version;
- $data['mi_version'] = SBIVER;
- $data['wp_version'] = $wp_version;
- $data['server'] = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '';
- $data['multisite'] = is_multisite();
- $data['url'] = home_url();
- $data['themename'] = $theme_data->Name;
- $data['themeversion'] = $theme_data->Version;
- $data['settings'] = array();
- $data['pro'] = (int)sbi_is_pro_version();
- $data['sites'] = $count_b;
- $data['usagetracking'] = get_option('sbi_usage_tracking_config', false);
- $num_users = function_exists('count_users') ? count_users() : 'Not Set';
- $data['usercount'] = is_array($num_users) ? $num_users['total_users'] : 1;
- $data['timezoneoffset'] = date('P');
-
- $settings_to_send = array();
- $raw_settings = get_option('sb_instagram_settings', array());
- $feeds = SBI_Db::feeds_query();
- $feed_settings = [];
-
- if (!empty($feeds)) {
- // recursive json decode
- $feed_settings = array_map(static function ($item) {
- return json_decode($item, true);
- }, json_decode($feeds[0]['settings'], true));
- // map array values to key => value pairs in the $feed_settings array
- array_walk($feed_settings, static function ($value, $key) use (&$feed_settings) {
- if (is_array($value)) {
- unset($feed_settings[$key]);
- foreach ($value as $value_key => $value_item) {
- $feed_settings[$key . '_' . $value_key] = $value_item;
- }
- }
- }, []);
- }
-
- $settings_to_send = array_merge($settings_to_send, $feed_settings);
- $con_bus_accounts = 0;
- $recently_searched_hashtags = 0;
- $access_tokens_tried = array();
- $sources = SBI_Db::source_query();
- if (!empty($sources)) {
- $sources = SBI_Source::convert_sources_to_connected_accounts($sources);
- foreach ($sources as $source) {
- if (isset($source['account_type']) && $source['account_type'] === 'business') {
- $con_bus_accounts++;
- $source['type'] = $source['account_type'];
- if (!in_array($source['access_token'], $access_tokens_tried, true) && class_exists('SB_Instagram_API_Connect')) {
- $access_tokens_tried[] = $source['access_token'];
- $connection = new SB_Instagram_API_Connect($source, 'recently_searched_hashtags', array('hashtag' => ''));
- $connection->connect();
-
- $recently_searched_data = !$connection->is_wp_error() ? $connection->get_data() : false;
- $num_hashatags_searched = $recently_searched_data && isset($recently_searched_data) && !isset($recently_searched_data['data']) && is_array($recently_searched_data) ? count($recently_searched_data) : 0;
- $recently_searched_hashtags = $recently_searched_hashtags + $num_hashatags_searched;
- }
- }
- }
- }
- $settings_to_send['business_accounts'] = $con_bus_accounts;
- $settings_to_send['recently_searched_hashtags'] = $recently_searched_hashtags;
- $sbi_cache = new SB_Instagram_Cache(null);
-
- $settings_to_send['num_found_feed_caches'] = (int)$sbi_cache->get_cache_count();
- $settings_to_send['recently_requested_caches'] = (int)$sbi_cache->get_cache_count(true);
-
- $settings_to_send['custom_header_template'] = '' !== locate_template('sbi/header.php', false, false) ? 1 : 0;
- $settings_to_send['custom_header_boxed_template'] = '' !== locate_template('sbi/header-boxed.php', false, false) ? 1 : 0;
- $settings_to_send['custom_header_generic_template'] = '' !== locate_template('sbi/header-generic.php', false, false) ? 1 : 0;
- $settings_to_send['custom_item_template'] = '' !== locate_template('sbi/item.php', false, false) ? 1 : 0;
- $settings_to_send['custom_footer_template'] = '' !== locate_template('sbi/footer.php', false, false) ? 1 : 0;
- $settings_to_send['custom_feed_template'] = '' !== locate_template('sbi/feed.php', false, false) ? 1 : 0;
- $settings_to_send['num_found_feeds'] = count($feeds);
-
- $sbi_current_white_names = get_option('sb_instagram_white_list_names', array());
- if (empty($sbi_current_white_names)) {
- $settings_to_send['num_white_lists'] = 0;
- } else {
- $settings_to_send['num_white_lists'] = count($sbi_current_white_names);
- }
-
- $data['settings'] = $settings_to_send;
-
- // Retrieve current plugin information
- if (!function_exists('get_plugins')) {
- include ABSPATH . '/wp-admin/includes/plugin.php';
- }
-
- $plugins = get_plugins();
- $active_plugins = get_option('active_plugins', array());
- $plugins_to_send = array();
-
- foreach ($plugins as $plugin_path => $plugin) {
- // If the plugin isn't active, don't show it.
- if (!in_array($plugin_path, $active_plugins)) {
- continue;
- }
-
- $plugins_to_send[] = $plugin['Name'];
- }
-
- $data['active_plugins'] = $plugins_to_send;
- $data['locale'] = get_locale();
-
- return $data;
- }
-
- public function schedule_send()
- {
- if (!wp_next_scheduled('sbi_usage_tracking_cron')) {
- $tracking = array();
- $tracking['day'] = rand(0, 6);
- $tracking['hour'] = rand(0, 23);
- $tracking['minute'] = rand(0, 59);
- $tracking['second'] = rand(0, 59);
- $tracking['offset'] = ($tracking['day'] * DAY_IN_SECONDS) +
- ($tracking['hour'] * HOUR_IN_SECONDS) +
- ($tracking['minute'] * MINUTE_IN_SECONDS) +
- $tracking['second'];
- $last_sunday = strtotime('next sunday') - (7 * DAY_IN_SECONDS);
- if (($last_sunday + $tracking['offset']) > time() + 6 * HOUR_IN_SECONDS) {
- $tracking['initsend'] = $last_sunday + $tracking['offset'];
- } else {
- $tracking['initsend'] = strtotime('next sunday') + $tracking['offset'];
- }
-
- wp_schedule_event($tracking['initsend'], 'weekly', 'sbi_usage_tracking_cron');
- update_option('sbi_usage_tracking_config', $tracking);
- }
- }
-
- public function add_schedules($schedules = array())
- {
- // Adds once weekly to the existing schedules.
- $schedules['weekly'] = array(
- 'interval' => 604800,
- 'display' => __('Once Weekly', 'instagram-feed'),
- );
- return $schedules;
- }
-
- private function normalize_and_format($key, $value)
- {
- $normal_bools = array(
- 'sb_instagram_preserve_settings',
- 'sb_instagram_ajax_theme',
- 'enqueue_js_in_head',
- 'disable_js_image_loading',
- 'sb_instagram_disable_resize',
- 'sb_instagram_favor_local',
- 'sbi_hover_inc_username',
- 'sbi_hover_inc_icon',
- 'sbi_hover_inc_date',
- 'sbi_hover_inc_instagram',
- 'sbi_hover_inc_location',
- 'sbi_hover_inc_caption',
- 'sbi_hover_inc_likes',
- 'sb_instagram_disable_lightbox',
- 'sb_instagram_captionlinks',
- 'sb_instagram_show_btn',
- 'sb_instagram_show_caption',
- 'sb_instagram_lightbox_comments',
- 'sb_instagram_show_meta',
- 'sb_instagram_show_header',
- 'sb_instagram_show_followers',
- 'sb_instagram_show_bio',
- 'sb_instagram_outside_scrollable',
- 'sb_instagram_stories',
- 'sb_instagram_show_follow_btn',
- 'sb_instagram_autoscroll',
- 'sb_instagram_disable_font',
- 'sb_instagram_backup',
- 'sb_instagram_at',
- 'sb_ajax_initial',
- 'sbi_br_adjust',
- 'sb_instagram_feed_width_resp',
- 'enqueue_css_in_shortcode',
- 'sb_instagram_disable_mob_swipe',
- 'sb_instagram_disable_awesome',
- 'sb_instagram_media_vine',
- 'custom_template',
- 'disable_admin_notice',
- 'enable_email_report',
- 'sb_instagram_carousel',
- 'sb_instagram_carousel_arrows',
- 'sb_instagram_carousel_pag',
- 'sb_instagram_carousel_autoplay',
- );
- $custom_text_settings = array(
- 'sb_instagram_btn_text',
- 'sb_instagram_follow_btn_text',
- 'sb_instagram_custom_bio',
- 'sb_instagram_custom_avatar',
- 'sb_instagram_custom_css',
- 'sb_instagram_custom_js',
- 'email_notification_addresses',
- );
- $comma_separate_counts_settings = array(
- 'sb_instagram_user_id',
- 'sb_instagram_tagged_ids',
- 'sb_instagram_hashtag',
- 'sb_instagram_highlight_ids',
- 'sb_instagram_highlight_hashtag',
- 'sb_instagram_hide_photos',
- 'sb_instagram_exclude_words',
- 'sb_instagram_include_words',
- );
- $defaults = SB_Instagram_Settings::default_settings();
-
- if (is_array($value)) {
- if (empty($value)) {
- return 0;
- }
- return count($value);
- // 0 for anything that might be false, 1 for everything else
- } elseif (in_array($key, $normal_bools, true)) {
- if (in_array($value, array(false, 0, '0', 'false', ''), true)) {
- return 0;
- }
- return 1;
-
- // if a custom text setting, we just want to know if it's different than the default
- } elseif (in_array($key, $custom_text_settings, true)) {
- if ($defaults[$key] === $value) {
- return 0;
- }
- return 1;
- } elseif (in_array($key, $comma_separate_counts_settings, true)) {
- if (str_replace(' ', '', $value) === '') {
- return 0;
- }
- $split_at_comma = explode(',', $value);
- return count($split_at_comma);
- }
-
- return $value;
- }
-}
--- a/instagram-feed/inc/UsageTracking/Config.php
+++ b/instagram-feed/inc/UsageTracking/Config.php
@@ -0,0 +1,117 @@
+<?php
+/**
+ * Smash Usage Tracking configuration.
+ *
+ * API URL and option names. Reusable across plugins.
+ *
+ * @package InstagramFeedUsageTracking
+ * @since 6.10
+ */
+
+namespace InstagramFeedUsageTracking;
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
+class Config {
+
+ /**
+ * Option key: enabled flag and last_send timestamp.
+ * Reuses the legacy usage-tracking option so existing consent carries over.
+ */
+ const OPTION_TRACKING = 'sbi_usage_tracking';
+
+ /**
+ * Default enabled state when the option has never been saved.
+ * Matches the legacy default: opt-in required for the free plugin.
+ */
+ const DEFAULT_ENABLED = false;
+
+ /**
+ * Option key: site token returned by the API.
+ */
+ const OPTION_SITE_TOKEN = 'sbi_smash_usage_tracking_site_token';
+
+ /**
+ * Option key: schedule metadata (optional).
+ */
+ const OPTION_SCHEDULE = 'sbi_smash_usage_tracking_schedule';
+
+ /**
+ * Option key: dates when plugin was active (Y-m-d), for days_active metric.
+ */
+ const OPTION_ACTIVE_DATES = 'sbi_smash_usage_active_dates';
+
+ /**
+ * Option key: last N session durations in seconds, for session_duration metric.
+ */
+ const OPTION_SESSION_DURATIONS = 'sbi_smash_usage_session_durations';
+
+ /**
+ * Cron hook name. Different from the Pro plugin and the legacy hook to avoid duplicate sends
+ * on sites where both free and pro are installed simultaneously.
+ */
+ const CRON_HOOK = 'sbi_free_smash_usage_tracking_cron';
+
+ /**
+ * Max request timeout in seconds for usage report (large payloads).
+ */
+ const REQUEST_TIMEOUT = 30;
+
+ /**
+ * Max payload size in bytes before send is skipped (default 2MB).
+ */
+ const MAX_PAYLOAD_BYTES = 2097152;
+
+ /**
+ * Register-site endpoint path (relative to API base).
+ */
+ const REGISTER_SITE_PATH = '/v1/register-site';
+
+ /**
+ * Usage report endpoint path (relative to API base).
+ */
+ const USAGE_REPORT_PATH = '/v1/usage-report';
+
+ /**
+ * Get the API base URL (filterable).
+ *
+ * @return string
+ */
+ public static function get_api_url() {
+ $url = defined( 'SBI_SMASH_USAGE_TRACKING_API_URL' ) ? SBI_SMASH_USAGE_TRACKING_API_URL : '';
+ return (string) apply_filters( 'sbi_smash_usage_tracking_api_url', $url );
+ }
+
+ /**
+ * Get full URL for register-site endpoint.
+ *
+ * @return string
+ */
+ public static function get_register_site_url() {
+ return rtrim( self::get_api_url(), '/' ) . self::REGISTER_SITE_PATH;
+ }
+
+ /**
+ * Get full URL for usage-report endpoint.
+ *
+ * @return string
+ */
+ public static function get_usage_report_url() {
+ return rtrim( self::get_api_url(), '/' ) . self::USAGE_REPORT_PATH;
+ }
+
+ /**
+ * Check if tracking is enabled.
+ *
+ * @return bool
+ */
+ public static function is_enabled() {
+ $opt = get_option( self::OPTION_TRACKING, false );
+ if ( ! is_array( $opt ) || ! array_key_exists( 'enabled', $opt ) ) {
+ return self::DEFAULT_ENABLED;
+ }
+ return ! empty( $opt['enabled'] );
+ }
+}
--- a/instagram-feed/inc/UsageTracking/Core/PayloadBuilder.php
+++ b/instagram-feed/inc/UsageTracking/Core/PayloadBuilder.php
@@ -0,0 +1,141 @@
+<?php
+/**
+ * Builds the full usage report payload (schema_version, site_token, snapshot, dynamic_metrics).
+ *
+ * @package InstagramFeedUsageTrackingCore
+ * @since 6.10
+ */
+
+namespace InstagramFeedUsageTrackingCore;
+
+use InstagramFeedUsageTrackingConfig;
+use InstagramFeedUsageTrackingReporterInterface;
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
+class PayloadBuilder {
+
+ /**
+ * @var ReporterInterface
+ */
+ private $reporter;
+
+ /**
+ * @param ReporterInterface $reporter Plugin-specific reporter.
+ */
+ public function __construct( ReporterInterface $reporter ) {
+ $this->reporter = $reporter;
+ }
+
+ /**
+ * Build the full payload for the usage-report endpoint.
+ *
+ * @param string $site_token Site token from RegisterSite.
+ * @param string $period_start Period start (e.g. Y-m-d).
+ * @param string $period_end Period end (e.g. Y-m-d).
+ * @return array
+ */
+ public function build( $site_token, $period_start, $period_end ) {
+ $payload_id = $this->generate_payload_id();
+ $slug = $this->reporter->get_plugin_slug();
+ $snapshot = $this->reporter->get_configuration_snapshot();
+ $license_tier = isset( $snapshot['license_tier'] ) ? $snapshot['license_tier'] : 'free';
+ $license_status = isset( $snapshot['license_status'] ) ? $snapshot['license_status'] : null;
+ $license_expires = isset( $snapshot['license_expires'] ) ? $snapshot['license_expires'] : null;
+ $license_item_id = isset( $snapshot['license_item_id'] ) ? $snapshot['license_item_id'] : null;
+ $version = isset( $snapshot['version'] ) ? $snapshot['version'] : (defined( 'SBIVER' ) ? SBIVER : '');
+ unset( $snapshot['license_tier'], $snapshot['license_status'], $snapshot['license_expires'], $snapshot['license_item_id'], $snapshot['version'] );
+
+ $type = (function_exists( 'sbi_is_pro_version' ) && sbi_is_pro_version()) ? 'pro' : 'free';
+
+ $dynamic_metrics = $this->reporter->get_dynamic_metrics( $period_start, $period_end );
+ $errors = isset( $dynamic_metrics['errors'] ) ? $dynamic_metrics['errors'] : array();
+ unset( $dynamic_metrics['errors'] );
+
+ return array(
+ 'schema_version' => $this->reporter->get_schema_version(),
+ 'plugin' => $slug,
+ 'type' => $type,
+ 'site_token' => $site_token,
+ 'payload_id' => $payload_id,
+ 'period_start' => $period_start,
+ 'period_end' => $period_end,
+ 'plugin_info' => array(
+ 'slug' => 'instagram',
+ 'version' => $version,
+ 'license_tier' => $license_tier,
+ 'license_status' => $license_status,
+ 'license_expires' => $license_expires,
+ 'license_item_id' => $license_item_id,
+ ),
+ 'configuration_snapshot' => $snapshot,
+ 'errors' => $errors,
+ 'dynamic_metrics' => $dynamic_metrics,
+ 'active_plugins' => $this->get_active_plugins(),
+ 'active_theme' => $this->get_active_theme(),
+ );
+ }
+
+ /**
+ * Generate a unique payload ID (UUID v4 style).
+ *
+ * @return string
+ */
+ private function generate_payload_id() {
+ if ( function_exists( 'wp_generate_uuid4' ) ) {
+ return wp_generate_uuid4();
+ }
+ return sprintf(
+ '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
+ wp_rand( 0, 0xffff ),
+ wp_rand( 0, 0xffff ),
+ wp_rand( 0, 0xffff ),
+ wp_rand( 0, 0x0fff ) | 0x4000,
+ wp_rand( 0, 0x3fff ) | 0x8000,
+ wp_rand( 0, 0xffff ),
+ wp_rand( 0, 0xffff ),
+ wp_rand( 0, 0xffff )
+ );
+ }
+
+ private function get_active_plugins(): array {
+ if ( ! function_exists( 'get_plugins' ) ) {
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
+ }
+
+ $all_plugins = get_plugins();
+ $active_basenames = array_merge(
+ (array) get_option( 'active_plugins', array() ),
+ array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) )
+ );
+
+ $result = array();
+ foreach ( array_unique( $active_basenames ) as $basename ) {
+ if ( ! isset( $all_plugins[ $basename ] ) ) {
+ continue;
+ }
+ $data = $all_plugins[ $basename ];
+ $result[] = array(
+ 'slug' => $basename,
+ 'name' => isset( $data['Name'] ) ? sanitize_text_field( (string) $data['Name'] ) : null,
+ 'version' => isset( $data['Version'] ) ? sanitize_text_field( (string) $data['Version'] ) : null,
+ 'author' => isset( $data['Author'] ) ? wp_strip_all_tags( (string) $data['Author'] ) : null,
+ );
+ }
+
+ return $result;
+ }
+
+ private function get_active_theme(): ?array {
+ $theme = wp_get_theme();
+ if ( ! $theme->exists() ) {
+ return null;
+ }
+ return array(
+ 'name' => sanitize_text_field( (string) $theme->get( 'Name' ) ),
+ 'version' => sanitize_text_field( (string) $theme->get( 'Version' ) ),
+ );
+ }
+}
--- a/instagram-feed/inc/UsageTracking/Core/RegisterSite.php
+++ b/instagram-feed/inc/UsageTracking/Core/RegisterSite.php
@@ -0,0 +1,76 @@
+<?php
+/**
+ * Register-site API client. Fetches site_token from the API and stores it.
+ *
+ * @package InstagramFeedUsageTrackingCore
+ * @since 6.10
+ */
+
+namespace InstagramFeedUsageTrackingCore;
+
+use InstagramFeedUsageTrackingConfig;
+use InstagramFeedUsageTrackingReporterInterface;
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
+class RegisterSite {
+
+ /**
+ * Register the site with the API and store the returned site_token.
+ *
+ * @param ReporterInterface $reporter Plugin reporter (for slug/version).
+ * @return string|null Site token on success, null on failure.
+ */
+ public function register( ReporterInterface $reporter ) {
+ $existing = get_option( Config::OPTION_SITE_TOKEN, '' );
+ if ( '' !== $existing && is_string( $existing ) ) {
+ return $existing;
+ }
+
+ $url = Config::get_register_site_url();
+ $body = array(
+ 'site_url' => home_url(),
+ 'plugin_slug' => $reporter->get_plugin_slug(),
+ 'plugin_version' => defined( 'SBIVER' ) ? SBIVER : '',
+ );
+
+ $response = wp_remote_post(
+ $url,
+ array(
+ 'method' => 'POST',
+ 'timeout' => 15,
+ 'redirection' => 5,
+ 'headers' => array(
+ 'Content-Type' => 'application/json',
+ ),
+ 'body' => wp_json_encode( $body ),
+ )
+ );
+
+ if ( is_wp_error( $response ) ) {
+ return null;
+ }
+
+ $code = wp_remote_retrieve_response_code( $response );
+ if ( $code < 200 || $code >= 300 ) {
+ return null;
+ }
+
+ $body_raw = wp_remote_retrieve_body( $response );
+ $data = json_decode( $body_raw, true );
+ if ( ! is_array( $data ) ) {
+ return null;
+ }
+
+ $token = isset( $data['site_token'] ) ? $data['site_token'] : (isset( $data['token'] ) ? $data['token'] : null);
+ if ( null === $token || '' === $token || ! is_string( $token ) ) {
+ return null;
+ }
+
+ $token = sanitize_text_field( $token );
+ update_option( Config::OPTION_SITE_TOKEN, $token, false );
+ return $token;
+ }
+}
--- a/instagram-feed/inc/UsageTracking/Core/Scheduler.php
+++ b/instagram-feed/inc/UsageTracking/Core/Scheduler.php
@@ -0,0 +1,92 @@
+<?php
+/**
+ * Schedules the weekly usage tracking cron.
+ *
+ * @package InstagramFeedUsageTrackingCore
+ * @since 6.10
+ */
+
+namespace InstagramFeedUsageTrackingCore;
+
+use InstagramFeedUsageTrackingConfig;
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
+class Scheduler {
+
+ /**
+ * Ensure weekly cron is scheduled when tracking is enabled.
+ * Call on init or when enabling the option.
+ */
+ public function schedule() {
+ $this->cleanup_legacy();
+
+ if ( ! Config::is_enabled() ) {
+ return;
+ }
+
+ if ( wp_next_scheduled( Config::CRON_HOOK ) ) {
+ return;
+ }
+
+ $tracking = array(
+ 'day' => wp_rand( 0, 6 ),
+ 'hour' => wp_rand( 0, 23 ),
+ 'minute' => wp_rand( 0, 59 ),
+ 'second' => wp_rand( 0, 59 ),
+ );
+ $tracking['offset'] = ($tracking['day'] * DAY_IN_SECONDS)
+ + ($tracking['hour'] * HOUR_IN_SECONDS)
+ + ($tracking['minute'] * MINUTE_IN_SECONDS)
+ + $tracking['second'];
+
+ $last_sunday = strtotime( 'next sunday' ) - (7 * DAY_IN_SECONDS);
+ if ( ($last_sunday + $tracking['offset']) > time() + 6 * HOUR_IN_SECONDS ) {
+ $tracking['initsend'] = $last_sunday + $tracking['offset'];
+ } else {
+ $tracking['initsend'] = strtotime( 'next sunday' ) + $tracking['offset'];
+ }
+
+ wp_schedule_event( $tracking['initsend'], 'weekly', Config::CRON_HOOK );
+ update_option( Config::OPTION_SCHEDULE, $tracking, false );
+ }
+
+ /**
+ * Add weekly schedule if not already present.
+ *
+ * @param array $schedules Existing cron schedules.
+ * @return array
+ */
+ public function add_schedules( $schedules ) {
+ if ( ! isset( $schedules['weekly'] ) ) {
+ $schedules['weekly'] = array(
+ 'interval' => 604800,
+ 'display' => __( 'Once Weekly', 'instagram-feed' ),
+ );
+ }
+ return $schedules;
+ }
+
+ /**
+ * Unschedule the cron when tracking is disabled.
+ */
+ public function unschedule() {
+ wp_clear_scheduled_hook( Config::CRON_HOOK );
+ }
+
+ /**
+ * Clear the removed legacy tracking cron and delete its superseded options.
+ * Guarded so steady-state cost is a no-op.
+ */
+ private function cleanup_legacy() {
+ if ( wp_next_scheduled( 'sbi_usage_tracking_cron' ) ) {
+ wp_clear_scheduled_hook( 'sbi_usage_tracking_cron' );
+ }
+ if ( get_option( 'sbi_smash_usage_tracking', null ) !== null ) {
+ delete_option( 'sbi_smash_usage_tracking' );
+ delete_option( 'sbi_usage_tracking_config' );
+ }
+ }
+}
--- a/instagram-feed/inc/UsageTracking/Core/Sender.php
+++ b/instagram-feed/inc/UsageTracking/Core/Sender.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Sends the usage report payload to the API.
+ *
+ * @package InstagramFeedUsageTrackingCore
+ * @since 6.10
+ */
+
+namespace InstagramFeedUsageTrackingCore;
+
+use InstagramFeedUsageTrackingConfig;
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
+class Sender {
+
+ /**
+ * Send the usage report payload to the API.
+ * Skips send if payload exceeds max size to avoid timeouts; uses longer timeout for large bodies.
+ *
+ * @param array $payload Full JSON-serializable payload.
+ * @return bool True if request was sent successfully (2xx), false otherwise.
+ */
+ public function send( array $payload ) {
+ $url = Config::get_usage_report_url();
+ $body = wp_json_encode( $payload );
+ if ( false === $body ) {
+ return false;
+ }
+
+ $max_bytes = (int) apply_filters( 'sbi_smash_usage_tracking_max_payload_bytes', Config::MAX_PAYLOAD_BYTES );
+ if ( $max_bytes > 0 && strlen( $body ) > $max_bytes ) {
+ if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG && function_exists( 'error_log' ) ) {
+ error_log( '[SBI Usage Tracking] Payload size ' . strlen( $body ) . ' exceeds max ' . $max_bytes . ', send skipped.' );
+ }
+ return false;
+ }
+
+ $timeout = (int) apply_filters( 'sbi_smash_usage_tracking_request_timeout', Config::REQUEST_TIMEOUT );
+ $timeout = max( 15, min( 120, $timeout ) );
+
+ $response = wp_remote_post(
+ $url,
+ array(
+ 'method' => 'POST',
+ 'timeout' => $timeout,
+ 'redirection' => 5,
+ 'httpversion' => '1.1',
+ 'blocking' => true,
+ 'headers' => array(
+ 'Content-Type' => 'application/json',
+ ),
+ 'body' => $body,
+ 'user-agent' => 'SBI/' . (defined( 'SBIVER' ) ? SBIVER : '') . '; ' . get_bloginfo( 'url' ),
+ )
+ );
+
+ if ( is_wp_error( $response ) ) {
+ return false;
+ }
+
+ $code = wp_remote_retrieve_response_code( $response );
+ return $code >= 200 && $code < 300;
+ }
+}
--- a/instagram-feed/inc/UsageTracking/EventRecorder.php
+++ b/instagram-feed/inc/UsageTracking/EventRecorder.php
@@ -0,0 +1,88 @@
+<?php
+/**
+ * Records usage events for the current period (stored in sbi_smash_usage_events).
+ *
+ * @package InstagramFeedUsageTracking
+ * @since 6.10
+ */
+
+namespace InstagramFeedUsageTracking;
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
+class EventRecorder {
+
+ const OPTION_NAME = 'sbi_smash_usage_events';
+
+ /**
+ * Record one occurrence of an event (increments count and sets last_date to today).
+ *
+ * @param string $event_name Event name (e.g. plugin_installed, setting_changed).
+ */
+ public static function record( $event_name ) {
+ if ( ! Config::is_enabled() ) {
+ return;
+ }
+ if ( '' === $event_name || ! is_string( $event_name ) ) {
+ return;
+ }
+ $event_name = sanitize_text_field( $event_name );
+ if ( strlen( $event_name ) > 100 ) {
+ $event_name = substr( $event_name, 0, 100 );
+ }
+ $events = get_option( self::OPTION_NAME, array() );
+ if ( ! is_array( $events ) ) {
+ $events = array();
+ }
+ $current = isset( $events[ $event_name ] ) ? $events[ $event_name ] : 0;
+ $count = is_array( $current ) && isset( $current['count'] ) ? (int) $current['count'] + 1 : (is_numeric( $current ) ? (int) $current + 1 : 1);
+ $events[ $event_name ] = array(
+ 'count' => $count,
+ 'last_date' => gmdate( 'Y-m-d' ),
+ );
+ update_option( self::OPTION_NAME, $events, false );
+ }
+
+ /**
+ * Record today as an active day (for days_active metric). Keeps last 90 days.
+ */
+ public static function record_active_day() {
+ $option_key = InstagramFeedUsageTrackingConfig::OPTION_ACTIVE_DATES;
+ $dates = get_option( $option_key, array() );
+ if ( ! is_array( $dates ) ) {
+ $dates = array();
+ }
+ $today = gmdate( 'Y-m-d' );
+ if ( ! in_array( $today, $dates, true ) ) {
+ $dates[] = $today;
+ rsort( $dates );
+ $dates = array_slice( $dates, 0, 90 );
+ update_option( $option_key, $dates, false );
+ }
+ }
+
+ /**
+ * Record a session duration in seconds (for session_duration metric). Keeps last 10.
+ *
+ * @param int $seconds Duration in seconds.
+ */
+ public static function record_session_duration( $seconds ) {
+ if ( ! Config::is_enabled() ) {
+ return;
+ }
+ $seconds = (int) $seconds;
+ if ( $seconds <= 0 || $seconds > 86400 ) {
+ return;
+ }
+ $option_key = InstagramFeedUsageTrackingConfig::OPTION_SESSION_DURATIONS;
+ $durations = get_option( $option_key, array() );
+ if ( ! is_array( $durations ) ) {
+ $durations = array();
+ }
+ $durations[] = $seconds;
+ $durations = array_slice( $durations, -10 );
+ update_option( $option_key, $durations, false );
+ }
+}
--- a/instagram-feed/inc/UsageTracking/Instagram/InstagramFreeReporter.php
+++ b/instagram-feed/inc/UsageTracking/Instagram/InstagramFreeReporter.php
@@ -0,0 +1,798 @@
+<?php
+/**
+ * Instagram reporter for Smash Usage Tracking — Free plugin variant.
+ *
+ * Identical to a Pro reporter except license methods always return
+ * free/null values since the Free plugin has no EDD license infrastructure.
+ *
+ * @package InstagramFeedUsageTrackingInstagram
+ * @since 6.10
+ */
+
+namespace InstagramFeedUsageTrackingInstagram;
+
+use InstagramFeedUsageTrackingReporterInterface;
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
+class InstagramFreeReporter implements ReporterInterface {
+
+ const SCHEMA_VERSION = '1.0';
+
+ /**
+ * Plugin slug for payload root.
+ *
+ * @return string
+ */
+ public function get_plugin_slug() {
+ return 'instagram';
+ }
+
+ /**
+ * Schema version for the report payload.
+ *
+ * @return string
+ */
+ public function get_schema_version() {
+ return self::SCHEMA_VERSION;
+ }
+
+ /**
+ * Configuration snapshot (environment, settings, sources, feeds).
+ *
+ * @return array
+ */
+ public function get_configuration_snapshot() {
+ $global_settings = $this->get_global_settings();
+
+ // Single DB scan — reused for latest sample, summary, and features map.
+ $all_feed_data = $this->get_all_feed_data();
+
+ return array(
+ 'environment' => $this->get_environment(),
+ 'global_settings' => $global_settings,
+ 'sources' => $this->get_sources_summary(),
+ 'latest_10_feeds' => $this->get_latest_feeds( $all_feed_data ),
+ 'feeds' => $this->get_feeds_summary( $all_feed_data ),
+ 'features_enabled' => $this->get_features_enabled( $all_feed_data, $global_settings ),
+ 'template_usage' => $this->get_template_usage( $all_feed_data ),
+ 'source_types' => $this->get_source_types( $all_feed_data ),
+ 'version' => defined( 'SBIVER' ) ? SBIVER : '',
+ 'license_tier' => $this->get_license_tier(),
+ 'license_status' => $this->get_license_status(),
+ 'license_expires' => $this->get_license_expires(),
+ 'license_item_id' => $this->get_license_item_id(),
+ );
+ }
+
+ /**
+ * Dynamic metrics for the given period.
+ *
+ * @param string|int $period_start Start of period (ISO 8601 or timestamp).
+ * @param string|int $period_end End of period (ISO 8601 or timestamp).
+ * @return array
+ */
+ public function get_dynamic_metrics( $period_start, $period_end ) {
+ $ts_start = is_numeric( $period_start ) ? (int) $period_start : strtotime( $period_start );
+ $ts_end = is_numeric( $period_end ) ? (int) $period_end : strtotime( $period_end );
+
+ return array(
+ 'period_start' => $period_start,
+ 'period_end' => $period_end,
+ 'performance' => $this->get_performance_metrics(),
+ 'errors' => $this->get_error_metrics(),
+ 'events' => $this->get_events_for_period( $ts_start, $ts_end ),
+ 'days_active' => $this->get_days_active( $period_start, $period_end ),
+ 'session_duration' => $this->get_session_duration(),
+ );
+ }
+
+ /**
+ * Environment data (WP, PHP, theme, locale, multisite, install age).
+ *
+ * @return array
+ */
+ private function get_environment() {
+ $install_ts = null;
+ $statuses = get_option( 'sbi_statuses', array() );
+ if ( ! empty( $statuses['first_install'] ) && is_numeric( $statuses['first_install'] ) ) {
+ $install_ts = (int) $statuses['first_install'];
+ }
+ if ( null === $install_ts ) {
+ $install_ts = (int) get_option( 'sbi_installed_timestamp', 0 );
+ }
+ $install_age_days = $install_ts ? max( 0, (int) ((time() - $install_ts) / DAY_IN_SECONDS) ) : 0;
+
+ $theme = wp_get_theme();
+ $theme_name = $theme->exists() ? $theme->get( 'Name' ) : '';
+
+ return array(
+ 'wp_version' => get_bloginfo( 'version' ),
+ 'php_version' => PHP_VERSION,
+ 'active_theme' => $theme_name,
+ 'locale' => get_locale(),
+ 'multisite' => is_multisite(),
+ 'site_count' => is_multisite() ? (int) get_blog_count() : 1,
+ 'active_plugins_count' => count(
+ array_unique(
+ array_merge(
+ (array) get_option( 'active_plugins', array() ),
+ array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) )
+ )
+ )
+ ),
+ 'install_age_days' => $install_age_days,
+ );
+ }
+
+ /**
+ * Global Instagram Feed settings (caching, gdpr, preserve, advanced tab).
+ *
+ * @return array
+ */
+ private function get_global_settings() {
+ $settings = get_option( 'sb_instagram_settings', array() );
+ if ( ! is_array( $settings ) ) {
+ $settings = array();
+ }
+
+ return array(
+ 'caching_type' => isset( $settings['sbi_caching_type'] ) ? $settings['sbi_caching_type'] : 'background',
+ 'cron_interval' => isset( $settings['sbi_cache_cron_interval'] ) ? $settings['sbi_cache_cron_interval'] : '12hours',
+ 'gdpr' => isset( $settings['gdpr'] ) ? $settings['gdpr'] : 'auto',
+ 'preserve_settings' => ! empty( $settings['sb_instagram_preserve_settings'] ),
+ 'optimize_images' => empty( $settings['sb_instagram_disable_resize'] ),
+ 'ajax_theme_loading_fix' => ! empty( $settings['sb_instagram_ajax_theme'] ),
+ 'ajax_initial_load' => ! empty( $settings['sb_ajax_initial'] ),
+ 'disable_js_image_load' => ! empty( $settings['disable_js_image_loading'] ),
+ 'disable_admin_notice' => ! empty( $settings['disable_admin_notice'] ),
+ 'enable_email_report' => ! empty( $settings['enable_email_report'] ) && 'off' !== $settings['enable_email_report'],
+ 'email_notification_day' => isset( $settings['email_notification'] ) ? $settings['email_notification'] : '',
+ 'email_notification_set' => ! empty( $settings['email_notification_addresses'] ),
+ 'enqueue_js_in_head' => ! empty( $settings['enqueue_js_in_head'] ),
+ 'enqueue_css_in_shortcode' => ! empty( $settings['enqueue_css_in_shortcode'] ),
+ );
+ }
+
+ /**
+ * Sources summary (connected accounts count, account types).
+ *
+ * @return array
+ */
+ private function get_sources_summary() {
+ global $wpdb;
+ $sources_table = $wpdb->prefix . 'sbi_sources';
+ $table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $sources_table ) ) === $sources_table;
+
+ $connected_accounts_count = 0;
+ $account_type = array(
+ 'personal' => 0,
+ 'business' => 0,
+ 'basic' => 0,
+ );
+
+ if ( $table_exists ) {
+ $connected_accounts_count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$sources_table}" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name derived from $wpdb->prefix, not user input.
+ $personal_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$sources_table} WHERE account_type = %s", 'personal' ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name derived from $wpdb->prefix, not user input.
+ $business_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$sources_table} WHERE account_type = %s", 'business' ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name derived from $wpdb->prefix, not user input.
+ $basic_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$sources_table} WHERE account_type = %s", 'basic' ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name derived from $wpdb->prefix, not user input.
+ $account_type = array(
+ 'personal' => $personal_count,
+ 'business' => $business_count,
+ 'basic' => $basic_count,
+ );
+ }
+
+ return array(
+ 'connected_accounts_count' => $connected_accounts_count,
+ 'account_type' => $account_type,
+ );
+ }
+
+ /**
+ * Whitelist of feed setting keys to track.
+ *
+ * @var string[]
+ */
+ private static $feed_settings_whitelist = array(
+ 'type',
+ 'layout',
+ 'cols',
+ 'colsmobile',
+ 'num',
+ 'nummobile',
+ 'loadmore',
+ 'showheader',
+ 'lightbox',
+ 'disablelightbox',
+ 'enablemoderationmode',
+ 'shoppablelist',
+ 'moderationlist',
+ 'stories',
+ 'carousel',
+ 'hashtag',
+ 'tagged',
+ 'order',
+ 'mediatype',
+ 'videostypes',
+ 'igtvposts',
+ 'hoverdisplay',
+ 'captionlinks',
+ 'cachetime',
+ 'cacheunit',
+ 'headerstyle',
+ 'headersize',
+ 'outside_scrollable',
+ );
+
+ /**
+ * Load every feed's decoded settings plus feed_name, sorted newest-first.
+ *
+ * @return array[]
+ */
+ private function get_all_feed_data(): array {
+ global $wpdb;
+ $table = $wpdb->prefix . 'sbi_feeds';
+ $table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) === $table;
+
+ if ( ! $table_exists ) {
+ return array();
+ }
+
+ $rows = $wpdb->get_results(
+ "SELECT feed_name, settings FROM {$table} ORDER BY last_modified DESC LIMIT 500", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name derived from $wpdb->prefix, not user input.
+ ARRAY_A
+ );
+
+ $out = array();
+ foreach ( $rows as $row ) {
+ $decoded = ! empty( $row['settings'] ) ? json_decode( $row['settings'], true ) : array();
+ $out[] = array(
+ 'feed_name' => isset( $row['feed_name'] ) ? sanitize_text_field( (string) $row['feed_name'] ) : '',
+ 'settings' => is_array( $decoded ) ? $decoded : array(),
+ );
+ }
+
+ return $out;
+ }
+
+ /**
+ * Latest 15 feeds with whitelisted settings.
+ *
+ * @param array[] $all_feed_data From get_all_feed_data().
+ * @return array
+ */
+ private function get_latest_feeds( array $all_feed_data ): array {
+ $feeds = array();
+ foreach ( array_slice( $all_feed_data, 0, 15 ) as $row ) {
+ $feed_name = $row['feed_name'];
+ if ( strlen( $feed_name ) > 255 ) {
+ $feed_name = substr( $feed_name, 0, 255 );
+ }
+ $feeds[] = array(
+ 'feed_name' => $feed_name,
+ 'settings' => $this->pick_whitelisted_settings( $row['settings'] ),
+ );
+ }
+ return $feeds;
+ }
+
+ /**
+ * Aggregate feed type and layout distribution across ALL feeds.
+ *
+ * @param array[] $all_feed_data From get_all_feed_data().
+ * @return array
+ */
+ private function get_feeds_summary( array $all_feed_data ): array {
+ $by_type = array();
+ $by_layout = array();
+
+ foreach ( $all_feed_data as $row ) {
+ $s = $row['settings'];
+ $type = isset( $s['type'] ) ? (string) $s['type'] : 'user';
+ $layout = isset( $s['layout'] ) ? (string) $s['layout'] : 'grid';
+
+ $by_type[ $type ] = ($by_type[ $type ] ?? 0) + 1;
+ $by_layout[ $layout ] = ($by_layout[ $layout ] ?? 0) + 1;
+ }
+
+ return array(
+ 'total_count' => count( $all_feed_data ),
+ 'by_type' => $by_type,
+ 'by_layout' => $by_layout,
+ );
+ }
+
+ /**
+ * Flat boolean feature map for the Laravel dashboard's feature adoption page.
+ *
+ * @param array[] $all_feed_data From get_all_feed_data().
+ * @param array $global_settings From get_global_settings().
+ * @return array<string,bool>
+ */
+ private function get_features_enabled( array $all_feed_data, array $global_settings ): array {
+ $feed_flags = array(
+ 'lightbox' => false,
+ 'load_more' => false,
+ 'show_header' => false,
+ 'masonry_layout' => false,
+ 'carousel_layout' => false,
+ 'highlight_layout' => false,
+ 'hashtag_feeds' => false,
+ 'tagged_feeds' => false,
+ 'stories' => false,
+ 'moderation' => false,
+ 'shoppable' => false,
+ 'ajax_initial' => false,
+ );
+
+ foreach ( $all_feed_data as $row ) {
+ $s = $row['settings'];
+
+ if ( ! $feed_flags['lightbox'] && empty( $s['disablelightbox'] ) && empty( $s['sb_instagram_disable_lightbox'] ) ) {
+$feed_flags['lightbox'] = true;
+ }
+ if ( ! $feed_flags['load_more'] && ! empty( $s['loadmore'] ) ) {
+$feed_flags['load_more'] = true;
+ }
+ if ( ! $feed_flags['show_header'] && ! empty( $s['showheader'] ) ) {
+$feed_flags['show_header'] = true;
+ }
+ if ( ! $feed_flags['masonry_layout'] && isset( $s['layout'] ) && 'masonry' === $s['layout'] ) {
+$feed_flags['masonry_layout'] = true;
+ }
+ if ( ! $feed_flags['carousel_layout'] && isset( $s['layout'] ) && 'carousel' === $s['layout'] ) {
+$feed_flags['carousel_layout'] = true;
+ }
+ if ( ! $feed_flags['highlight_layout'] && isset( $s['layout'] ) && 'highlight' === $s['layout'] ) {
+$feed_flags['highlight_layout'] = true;
+ }
+ if ( ! $feed_flags['hashtag_feeds'] && isset( $s['type'] ) && 'hashtag' === $s['type'] ) {
+$feed_flags['hashtag_feeds'] = true;
+ }