| @@ -311,8 +311,134 @@ | ||
| 311 | 311 | return ! empty( get_option( 'merchant_pro_license_key' ) ); |
| 312 | 312 | } |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | +if ( ! function_exists( 'merchant_white_label_get_settings' ) ) { | |
| 316 | + /** | |
| 317 | + * Read the White Label settings stored by the aThemes White Label plugin. | |
| 318 | + * | |
| 319 | + * That option is the single source of truth, so values stay shared whether | |
| 320 | + * they were saved from Merchant's settings or from the aThemes White Label plugin. | |
| 321 | + * | |
| 322 | + * @return array | |
| 323 | + */ | |
| 324 | + function merchant_white_label_get_settings() { | |
| 325 | + $settings = get_option( 'athemes_white_label_settings', array() ); | |
| 326 | + | |
| 327 | + return is_array( $settings ) ? $settings : array(); | |
| 328 | + } | |
| 329 | +} | |
| 330 | + | |
| 331 | +if ( ! function_exists( 'merchant_white_label_is_available' ) ) { | |
| 332 | + /** | |
| 333 | + * Whether this site is entitled to White Label. | |
| 334 | + * | |
| 335 | + * False in the free plugin alone. Merchant Pro answers the filter with its | |
| 336 | + * Agency-tier check, so the free plugin never calls into Pro. | |
| 337 | + * | |
| 338 | + * @return bool | |
| 339 | + */ | |
| 340 | + function merchant_white_label_is_available() { | |
| 341 | + /** | |
| 342 | + * Filter White Label entitlement. | |
| 343 | + * | |
| 344 | + * @param bool $available Whether the site is entitled. | |
| 345 | + * | |
| 346 | + * @since 2.3.1 | |
| 347 | + */ | |
| 348 | + return (bool) apply_filters( 'merchant_white_label_available', false ); | |
| 349 | + } | |
| 350 | +} | |
| 351 | + | |
| 352 | +if ( ! function_exists( 'merchant_white_label_switch_key' ) ) { | |
| 353 | + /** | |
| 354 | + * The key Merchant's own White Label switch is stored under. | |
| 355 | + * | |
| 356 | + * @return string | |
| 357 | + */ | |
| 358 | + function merchant_white_label_switch_key() { | |
| 359 | + return 'merchant_activate_white_label'; | |
| 360 | + } | |
| 361 | +} | |
| 362 | + | |
| 363 | +if ( ! function_exists( 'merchant_white_label_is_switched_on' ) ) { | |
| 364 | + /** | |
| 365 | + * Whether Merchant's own White Label switch is on. | |
| 366 | + * | |
| 367 | + * @return bool | |
| 368 | + */ | |
| 369 | + function merchant_white_label_is_switched_on() { | |
| 370 | + $options = get_option( 'merchant', array() ); | |
| 371 | + | |
| 372 | + if ( ! is_array( $options ) || empty( $options['white-label'] ) || ! is_array( $options['white-label'] ) ) { | |
| 373 | + return false; | |
| 374 | + } | |
| 375 | + | |
| 376 | + return ! empty( $options['white-label'][ merchant_white_label_switch_key() ] ); | |
| 377 | + } | |
| 378 | +} | |
| 379 | + | |
| 380 | +if ( ! function_exists( 'merchant_white_label_plugin_is_switched_on' ) ) { | |
| 381 | + /** | |
| 382 | + * Whether the aThemes White Label plugin's own switch is on. | |
| 383 | + * | |
| 384 | + * Every aThemes product shares this key, so it only speaks for Merchant while | |
| 385 | + * the aThemes White Label plugin is the one in charge. | |
| 386 | + * | |
| 387 | + * @return bool | |
| 388 | + */ | |
| 389 | + function merchant_white_label_plugin_is_switched_on() { | |
| 390 | + $settings = merchant_white_label_get_settings(); | |
| 391 | + | |
| 392 | + return ! empty( $settings['activate_white_label'] ); | |
| 393 | + } | |
| 394 | +} | |
| 395 | + | |
| 396 | +if ( ! function_exists( 'merchant_white_label_plugin_is_applying' ) ) { | |
| 397 | + /** | |
| 398 | + * Whether the aThemes White Label plugin is the one white-labelling this site. | |
| 399 | + * | |
| 400 | + * Installed is not enough: the plugin has to be switched on, and the shared | |
| 401 | + * key alone proves nothing, since Botiga Pro writes it too. | |
| 402 | + * | |
| 403 | + * @return bool | |
| 404 | + */ | |
| 405 | + function merchant_white_label_plugin_is_applying() { | |
| 406 | + return merchant_white_label_plugin_available() && merchant_white_label_plugin_is_switched_on(); | |
| 407 | + } | |
| 408 | +} | |
| 409 | + | |
| 410 | +if ( ! function_exists( 'merchant_white_label_is_applied' ) ) { | |
| 411 | + /** | |
| 412 | + * Whether White Label is in effect for Merchant. | |
| 413 | + * | |
| 414 | + * Either switch is enough. The plugin's own switch forces it on whatever our | |
| 415 | + * tier says, the way it always has; Merchant's switch answers for the rest, | |
| 416 | + * entitlement included — so a site with the plugin merely installed and | |
| 417 | + * switched off still gets to use the feature from here. | |
| 418 | + * | |
| 419 | + * @return bool | |
| 420 | + */ | |
| 421 | + function merchant_white_label_is_applied() { | |
| 422 | + if ( merchant_white_label_plugin_is_applying() ) { | |
| 423 | + return true; | |
| 424 | + } | |
| 425 | + | |
| 426 | + return merchant_white_label_is_switched_on() && merchant_white_label_is_available(); | |
| 427 | + } | |
| 428 | +} | |
| 429 | + | |
| 430 | +if ( ! function_exists( 'merchant_white_label_plugin_available' ) ) { | |
| 431 | + /** | |
| 432 | + * Whether the aThemes White Label plugin is installed. | |
| 433 | + * | |
| 434 | + * @return bool | |
| 435 | + */ | |
| 436 | + function merchant_white_label_plugin_available() { | |
| 437 | + return class_exists( 'aThemes_White_Label' ); | |
| 438 | + } | |
| 439 | +} | |
| 440 | + | |
| 315 | 441 | /** |
| 316 | 442 | * Check if any shortcode starts with merchant doesn't exist. |
| 317 | 443 | * If the shortcode is not registered, register it with return null to guarantee it exists. |
| 318 | 444 | */ |