| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: UnoDock - Mobile Bottom Navigation |
| 4 |
* Plugin URI: https://unoizestudio.com |
| 5 |
* Description: A fully customizable bottom navigation bar for mobile, with 2 to 6 buttons, icons, colors, ordering and page visibility rules. |
| 6 |
* Version: 1.5.1 |
| 7 |
* Requires at least: 6.5 |
| 8 |
* Requires PHP: 8.0 |
| 9 |
* Author: UnoizeStudio |
| 10 |
* Author URI: https://unoizestudio.com |
| 11 |
* License: GPL v2 or later |
| 12 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 13 |
* Text Domain: unodock |
| 14 |
*/ |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; // Direct access not allowed. |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Freemius parallel-version bootstrap. |
| 22 |
* |
| 23 |
* If the premium edition has already initialized the shared SDK accessor, |
| 24 |
* register this file as the free basename and do not boot UnoDock twice. |
| 25 |
*/ |
| 26 |
if ( function_exists( 'unodock_fs' ) ) { |
| 27 |
$unodock_existing_fs = unodock_fs(); |
| 28 |
if ( $unodock_existing_fs ) { |
| 29 |
$unodock_existing_fs->set_basename( false, __FILE__ ); |
| 30 |
} |
| 31 |
} else { |
| 32 |
/** |
| 33 |
* Freemius SDK — handles licensing, updates, and the free/PRO feature gate. |
| 34 |
* Must be initialized as early as possible, before any other plugin code. |
| 35 |
*/ |
| 36 |
if ( ! function_exists( 'unodock_fs' ) ) { |
| 37 |
// Create a helper function for easy SDK access. |
| 38 |
function unodock_fs() { |
| 39 |
global $unodock_fs; |
| 40 |
|
| 41 |
if ( ! isset( $unodock_fs ) ) { |
| 42 |
$freemius_start = dirname( __FILE__ ) . '/vendor/freemius/start.php'; |
| 43 |
|
| 44 |
// Avoids a fatal error if the SDK hasn't been placed in vendor/freemius/ yet. |
| 45 |
if ( ! file_exists( $freemius_start ) ) { |
| 46 |
add_action( 'admin_notices', function () { |
| 47 |
echo '<div class="notice notice-error"><p>'; |
| 48 |
echo esc_html__( 'UnoDock: the Freemius SDK files are missing from vendor/freemius/. Licensing and updates are disabled until they are added.', 'unodock' ); |
| 49 |
echo '</p></div>'; |
| 50 |
} ); |
| 51 |
return null; |
| 52 |
} |
| 53 |
|
| 54 |
// Include Freemius SDK. |
| 55 |
require_once $freemius_start; |
| 56 |
|
| 57 |
$unodock_fs = fs_dynamic_init( array( |
| 58 |
'id' => '34602', |
| 59 |
'slug' => 'unodock', |
| 60 |
'type' => 'plugin', |
| 61 |
'public_key' => 'pk_7607ecb6a4cc2c217a92b8599e113', |
| 62 |
'is_premium' => false, |
| 63 |
'premium_suffix' => 'Pro', |
| 64 |
// If your plugin is a serviceware, set this option to false. |
| 65 |
'has_premium_version' => true, |
| 66 |
'has_addons' => false, |
| 67 |
'has_paid_plans' => true, |
| 68 |
'is_org_compliant' => true, |
| 69 |
'menu' => array( |
| 70 |
'slug' => 'unodock', |
| 71 |
'support' => false, |
| 72 |
), |
| 73 |
) ); |
| 74 |
} |
| 75 |
|
| 76 |
return $unodock_fs; |
| 77 |
} |
| 78 |
|
| 79 |
// Init Freemius. |
| 80 |
unodock_fs(); |
| 81 |
// Signal that SDK was initiated. |
| 82 |
do_action( 'unodock_fs_loaded' ); |
| 83 |
|
| 84 |
/** |
| 85 |
* Cleans up UnoDock's saved data, but only if the user opted into this |
| 86 |
* via the "Delete all settings when the plugin is uninstalled" setting. |
| 87 |
* Hooked to Freemius's "after_uninstall" action instead of using a |
| 88 |
* standalone uninstall.php file, since Freemius needs to intercept the |
| 89 |
* uninstall event first (e.g. to collect optional uninstall feedback) — |
| 90 |
* a plain uninstall.php file would prevent that from working. |
| 91 |
*/ |
| 92 |
function udock_after_uninstall_cleanup() { |
| 93 |
$settings = get_option( UNODOCK_OPTION_KEY ); |
| 94 |
|
| 95 |
if ( is_array( $settings ) && ! empty( $settings['general']['uninstall_cleanup'] ) ) { |
| 96 |
delete_option( UNODOCK_OPTION_KEY ); |
| 97 |
delete_option( 'udock_installed_at' ); |
| 98 |
delete_option( 'udock_review_dismissed' ); |
| 99 |
delete_option( 'udock_review_snooze_until' ); |
| 100 |
} |
| 101 |
} |
| 102 |
if ( function_exists( 'unodock_fs' ) && unodock_fs() ) { |
| 103 |
unodock_fs()->add_action( 'after_uninstall', 'udock_after_uninstall_cleanup' ); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
define( 'UNODOCK_VERSION', '1.5.1' ); |
| 108 |
define( 'UNODOCK_PATH', plugin_dir_path( __FILE__ ) ); |
| 109 |
define( 'UNODOCK_URL', plugin_dir_url( __FILE__ ) ); |
| 110 |
define( 'UNODOCK_BASENAME', plugin_basename( __FILE__ ) ); |
| 111 |
define( 'UNODOCK_OPTION_KEY', 'udock_settings' ); |
| 112 |
|
| 113 |
/** |
| 114 |
* Whether the current site has an active UnoDock PRO license. |
| 115 |
* Used only to show "Upgrade to PRO" prompts/links pointing to the |
| 116 |
* separate PRO plugin — this codebase contains no PRO functionality |
| 117 |
* itself, so there is nothing here to unlock. |
| 118 |
*/ |
| 119 |
function udock_is_pro() { |
| 120 |
static $is_pro = null; |
| 121 |
|
| 122 |
if ( null !== $is_pro ) { |
| 123 |
return $is_pro; |
| 124 |
} |
| 125 |
|
| 126 |
if ( ! function_exists( 'unodock_fs' ) ) { |
| 127 |
$is_pro = false; |
| 128 |
return $is_pro; |
| 129 |
} |
| 130 |
$fs = unodock_fs(); |
| 131 |
if ( ! $fs ) { |
| 132 |
$is_pro = false; |
| 133 |
return $is_pro; |
| 134 |
} |
| 135 |
$is_pro = $fs->can_use_premium_code(); |
| 136 |
return $is_pro; |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Maximum number of buttons allowed on the free version. |
| 141 |
*/ |
| 142 |
/** |
| 143 |
* Buttons are limited to 2-6: a design constraint (bottom nav bars stop |
| 144 |
* being usable/legible beyond this on a mobile screen), the same on every |
| 145 |
* version of the plugin — not a paywall. |
| 146 |
*/ |
| 147 |
function udock_max_buttons() { |
| 148 |
return 6; |
| 149 |
} |
| 150 |
function udock_min_buttons() { |
| 151 |
return 2; |
| 152 |
} |
| 153 |
|
| 154 |
require_once UNODOCK_PATH . 'includes/class-unodock-icons.php'; |
| 155 |
require_once UNODOCK_PATH . 'includes/class-unodock-settings.php'; |
| 156 |
require_once UNODOCK_PATH . 'includes/class-unodock-admin.php'; |
| 157 |
require_once UNODOCK_PATH . 'includes/class-unodock-frontend.php'; |
| 158 |
|
| 159 |
/** |
| 160 |
* Whether Popup Maker is active. Their plugin architecture changed |
| 161 |
* across versions — older releases exposed a global 'Popup_Maker' |
| 162 |
* class, current ones (1.20.0+) don't and instead always define the |
| 163 |
* 'popup_maker_config()' function; 'PUM_Install' has been present |
| 164 |
* since much earlier and covers versions in between. Checking all |
| 165 |
* three keeps this working across the range of versions in use. |
| 166 |
*/ |
| 167 |
function udock_is_popup_maker_active() { |
| 168 |
return class_exists( 'Popup_Maker' ) || class_exists( 'PUM_Install' ) || function_exists( 'popup_maker_config' ); |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* Returns a cache-busting version string for a plugin asset, based on the |
| 173 |
* file's last modification time. This means CSS/JS changes are always |
| 174 |
* picked up immediately, without needing a manual version bump. |
| 175 |
* |
| 176 |
* @param string $relative_path Path relative to the plugin folder, e.g. 'assets/css/admin.css'. |
| 177 |
*/ |
| 178 |
function udock_asset_version( $relative_path ) { |
| 179 |
$file = UNODOCK_PATH . ltrim( $relative_path, '/' ); |
| 180 |
return file_exists( $file ) ? (string) filemtime( $file ) : UNODOCK_VERSION; |
| 181 |
} |
| 182 |
|
| 183 |
/** |
| 184 |
* Sanitizes a color value that may include an alpha (transparency) |
| 185 |
* channel — accepts #rrggbb (opaque) or #rrggbbaa (with transparency). |
| 186 |
* WordPress core's sanitize_hex_color() only accepts 6-digit hex, so |
| 187 |
* this is a small extension of the same idea for our color pickers. |
| 188 |
* |
| 189 |
* @param string $value The raw color value. |
| 190 |
* @param string $fallback A safe 6 or 8-digit hex to fall back to if invalid. |
| 191 |
*/ |
| 192 |
function udock_sanitize_hex_alpha( $value, $fallback ) { |
| 193 |
if ( ! is_string( $value ) ) { |
| 194 |
return $fallback; |
| 195 |
} |
| 196 |
$value = trim( $value ); |
| 197 |
if ( '' === $value ) { |
| 198 |
return $fallback; |
| 199 |
} |
| 200 |
if ( preg_match( '/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/', $value ) ) { |
| 201 |
return strtolower( $value ); |
| 202 |
} |
| 203 |
return $fallback; |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Activation: creates the default settings if they don't exist yet. |
| 208 |
*/ |
| 209 |
function udock_activate() { |
| 210 |
if ( false === get_option( UNODOCK_OPTION_KEY ) ) { |
| 211 |
update_option( UNODOCK_OPTION_KEY, UNODOCK_Settings::get_defaults() ); |
| 212 |
} |
| 213 |
if ( false === get_option( 'udock_installed_at' ) ) { |
| 214 |
update_option( 'udock_installed_at', time() ); |
| 215 |
} |
| 216 |
} |
| 217 |
register_activation_hook( __FILE__, 'udock_activate' ); |
| 218 |
|
| 219 |
/** |
| 220 |
* Boots the plugin. |
| 221 |
*/ |
| 222 |
function udock_init() { |
| 223 |
new UNODOCK_Admin(); |
| 224 |
new UNODOCK_Frontend(); |
| 225 |
} |
| 226 |
add_action( 'plugins_loaded', 'udock_init' ); |
| 227 |
} |
| 228 |
|