| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | if ( ! defined( 'ABSPATH' ) ) { |
| 12: | exit; |
| 13: | } |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | class EPL_Admin_Messages { |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | const DISMISSED_META_KEY = 'epl_dismissed_admin_messages'; |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | const FEEDSYNC_URL = 'https://feedsync.com.au/'; |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | const LEGACY_RETIRES = '2026-12-05'; |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | private static $show = null; |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | public static function init() { |
| 69: | add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_styles' ) ); |
| 70: | add_action( 'admin_notices', array( __CLASS__, 'render_notice' ), 20 ); |
| 71: | add_action( 'admin_post_epl_dismiss_admin_message', array( __CLASS__, 'dismiss_message' ) ); |
| 72: | } |
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 77: | |
| 78: | |
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: | private static function is_plugin_file_active( $basename ) { |
| 85: | $active = (array) get_option( 'active_plugins', array() ); |
| 86: | |
| 87: | if ( is_multisite() ) { |
| 88: | $active = array_merge( $active, array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) ) ); |
| 89: | } |
| 90: | |
| 91: | foreach ( $active as $plugin_file ) { |
| 92: | if ( basename( (string) $plugin_file ) === $basename ) { |
| 93: | return true; |
| 94: | } |
| 95: | } |
| 96: | |
| 97: | return false; |
| 98: | } |
| 99: | |
| 100: | |
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: | |
| 106: | private static function has_importer() { |
| 107: | return self::is_plugin_file_active( 'epl-wp-all-import.php' ); |
| 108: | } |
| 109: | |
| 110: | |
| 111: | |
| 112: | |
| 113: | |
| 114: | |
| 115: | |
| 116: | |
| 117: | private static function has_connector() { |
| 118: | return self::is_plugin_file_active( 'epl-feedsync-connector.php' ); |
| 119: | } |
| 120: | |
| 121: | |
| 122: | |
| 123: | |
| 124: | |
| 125: | |
| 126: | |
| 127: | private static function has_companion() { |
| 128: | return self::is_plugin_file_active( 'feedsync-companion.php' ); |
| 129: | } |
| 130: | |
| 131: | |
| 132: | |
| 133: | |
| 134: | |
| 135: | |
| 136: | |
| 137: | |
| 138: | |
| 139: | |
| 140: | public static function should_show() { |
| 141: | if ( null !== self::$show ) { |
| 142: | return self::$show; |
| 143: | } |
| 144: | |
| 145: | $show = ( self::has_importer() || self::has_connector() ) && ! self::has_companion(); |
| 146: | |
| 147: | |
| 148: | |
| 149: | |
| 150: | |
| 151: | |
| 152: | |
| 153: | |
| 154: | |
| 155: | self::$show = (bool) apply_filters( 'epl_admin_messages_show', $show, 'feedsync' ); |
| 156: | |
| 157: | return self::$show; |
| 158: | } |
| 159: | |
| 160: | |
| 161: | |
| 162: | |
| 163: | |
| 164: | |
| 165: | |
| 166: | public static function enqueue_styles() { |
| 167: | if ( ! current_user_can( 'edit_posts' ) || ( ! self::should_show() && ! self::is_addons_page() ) ) { |
| 168: | return; |
| 169: | } |
| 170: | |
| 171: | wp_enqueue_style( |
| 172: | 'epl-admin-messages', |
| 173: | EPL_PLUGIN_URL . 'lib/assets/css/style-admin-messages.css', |
| 174: | array(), |
| 175: | EPL_PROPERTY_VER |
| 176: | ); |
| 177: | } |
| 178: | |
| 179: | |
| 180: | |
| 181: | |
| 182: | |
| 183: | |
| 184: | |
| 185: | public static function render_notice() { |
| 186: | if ( ! current_user_can( 'edit_posts' ) || ! self::should_show() || self::is_addons_page() ) { |
| 187: | return; |
| 188: | } |
| 189: | |
| 190: | $creative = self::get_current_creative(); |
| 191: | if ( self::is_dismissed( $creative ) ) { |
| 192: | return; |
| 193: | } |
| 194: | |
| 195: | switch ( $creative ) { |
| 196: | case 'a': |
| 197: | self::render_creative_a(); |
| 198: | break; |
| 199: | case 'c': |
| 200: | self::render_creative_c(); |
| 201: | break; |
| 202: | default: |
| 203: | self::render_creative_b(); |
| 204: | break; |
| 205: | } |
| 206: | } |
| 207: | |
| 208: | |
| 209: | |
| 210: | |
| 211: | |
| 212: | |
| 213: | |
| 214: | private static function is_addons_page() { |
| 215: | return isset( $_GET['page'] ) && 'epl-addons' === sanitize_key( wp_unslash( $_GET['page'] ) ); |
| 216: | } |
| 217: | |
| 218: | |
| 219: | |
| 220: | |
| 221: | |
| 222: | |
| 223: | |
| 224: | |
| 225: | |
| 226: | |
| 227: | |
| 228: | |
| 229: | public static function render_addons_row() { |
| 230: | echo '<div class="epl-msg-addons-row">'; |
| 231: | self::render_creative_c( false ); |
| 232: | echo '</div>'; |
| 233: | } |
| 234: | |
| 235: | |
| 236: | |
| 237: | |
| 238: | |
| 239: | |
| 240: | |
| 241: | private static function get_current_creative() { |
| 242: | $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; |
| 243: | |
| 244: | if ( in_array( $page, array( 'epl-settings', 'epl-extensions' ), true ) ) { |
| 245: | return 'a'; |
| 246: | } |
| 247: | |
| 248: | if ( 0 === strpos( $page, 'pmxi-admin-' ) ) { |
| 249: | return 'c'; |
| 250: | } |
| 251: | |
| 252: | $screen = get_current_screen(); |
| 253: | if ( $screen && false !== strpos( $screen->id, 'pmxi' ) ) { |
| 254: | return 'c'; |
| 255: | } |
| 256: | |
| 257: | return 'b'; |
| 258: | } |
| 259: | |
| 260: | |
| 261: | |
| 262: | |
| 263: | |
| 264: | |
| 265: | |
| 266: | private static function get_product_label() { |
| 267: | return self::is_plugin_file_active( 'wp-all-import-pro.php' ) ? __( 'WP All Import Pro', 'easy-property-listings' ) : __( 'WP All Import', 'easy-property-listings' ); |
| 268: | } |
| 269: | |
| 270: | |
| 271: | |
| 272: | |
| 273: | |
| 274: | |
| 275: | |
| 276: | |
| 277: | |
| 278: | private static function render_detected( $on_this_site = true ) { |
| 279: | if ( ! self::has_importer() && self::has_connector() ) { |
| 280: | $text = $on_this_site |
| 281: | ? __( 'Easy Property Listings FeedSync Connector detected on this site', 'easy-property-listings' ) |
| 282: | : __( 'Easy Property Listings FeedSync Connector detected', 'easy-property-listings' ); |
| 283: | } else { |
| 284: | $text = $on_this_site |
| 285: | ? __( 'Easy Property Listings Import add-on detected on this site', 'easy-property-listings' ) |
| 286: | : __( 'Easy Property Listings Import add-on detected', 'easy-property-listings' ); |
| 287: | } |
| 288: | |
| 289: | printf( '<span class="epl-msg__detected"><span></span>%s</span>', esc_html( $text ) ); |
| 290: | } |
| 291: | |
| 292: | |
| 293: | |
| 294: | |
| 295: | |
| 296: | |
| 297: | |
| 298: | private static function render_from() { |
| 299: | printf( '<span class="epl-msg__from">%s</span>', esc_html__( 'Easy Property Listings', 'easy-property-listings' ) ); |
| 300: | } |
| 301: | |
| 302: | |
| 303: | |
| 304: | |
| 305: | |
| 306: | |
| 307: | |
| 308: | |
| 309: | private static function is_dismissed( $creative ) { |
| 310: | $dismissed = get_user_meta( get_current_user_id(), self::DISMISSED_META_KEY, true ); |
| 311: | $dismissed = is_array( $dismissed ) ? $dismissed : array(); |
| 312: | return in_array( $creative, $dismissed, true ); |
| 313: | } |
| 314: | |
| 315: | |
| 316: | |
| 317: | |
| 318: | |
| 319: | |
| 320: | |
| 321: | |
| 322: | private static function get_dismiss_url( $creative ) { |
| 323: | return wp_nonce_url( |
| 324: | add_query_arg( |
| 325: | array( |
| 326: | 'action' => 'epl_dismiss_admin_message', |
| 327: | 'epl_message' => $creative, |
| 328: | ), |
| 329: | admin_url( 'admin-post.php' ) |
| 330: | ), |
| 331: | 'epl_dismiss_admin_message_' . $creative |
| 332: | ); |
| 333: | } |
| 334: | |
| 335: | |
| 336: | |
| 337: | |
| 338: | |
| 339: | |
| 340: | |
| 341: | public static function dismiss_message() { |
| 342: | if ( ! current_user_can( 'edit_posts' ) ) { |
| 343: | wp_die( esc_html__( 'You do not have permission to dismiss this notice.', 'easy-property-listings' ) ); |
| 344: | } |
| 345: | |
| 346: | $creative = isset( $_GET['epl_message'] ) ? sanitize_key( wp_unslash( $_GET['epl_message'] ) ) : ''; |
| 347: | if ( ! in_array( $creative, array( 'a', 'b', 'c' ), true ) ) { |
| 348: | wp_die( esc_html__( 'Invalid message.', 'easy-property-listings' ) ); |
| 349: | } |
| 350: | |
| 351: | check_admin_referer( 'epl_dismiss_admin_message_' . $creative ); |
| 352: | |
| 353: | $dismissed = get_user_meta( get_current_user_id(), self::DISMISSED_META_KEY, true ); |
| 354: | $dismissed = is_array( $dismissed ) ? $dismissed : array(); |
| 355: | $dismissed[] = $creative; |
| 356: | update_user_meta( get_current_user_id(), self::DISMISSED_META_KEY, array_values( array_unique( $dismissed ) ) ); |
| 357: | |
| 358: | $redirect = wp_get_referer(); |
| 359: | wp_safe_redirect( $redirect ? $redirect : admin_url() ); |
| 360: | exit; |
| 361: | } |
| 362: | |
| 363: | |
| 364: | |
| 365: | |
| 366: | |
| 367: | |
| 368: | |
| 369: | private static function get_deadline_text() { |
| 370: | if ( current_time( 'Y-m-d' ) > self::LEGACY_RETIRES ) { |
| 371: | return ''; |
| 372: | } |
| 373: | return __( 'Using legacy FeedSync? It retires on 5 December 2026.', 'easy-property-listings' ); |
| 374: | } |
| 375: | |
| 376: | |
| 377: | |
| 378: | |
| 379: | |
| 380: | |
| 381: | |
| 382: | private static function render_deadline() { |
| 383: | $text = self::get_deadline_text(); |
| 384: | if ( '' === $text ) { |
| 385: | return; |
| 386: | } |
| 387: | printf( '<span class="epl-msg__deadline">%s</span>', esc_html( $text ) ); |
| 388: | } |
| 389: | |
| 390: | |
| 391: | |
| 392: | |
| 393: | |
| 394: | |
| 395: | |
| 396: | |
| 397: | private static function render_wire( $packets = 3 ) { |
| 398: | echo '<span class="epl-msg__wire" aria-hidden="true"></span>'; |
| 399: | echo '<span class="epl-msg__packets" aria-hidden="true">'; |
| 400: | for ( $i = 0; $i < $packets; $i++ ) { |
| 401: | echo '<i class="epl-msg__packet"></i>'; |
| 402: | } |
| 403: | echo '</span>'; |
| 404: | } |
| 405: | |
| 406: | |
| 407: | |
| 408: | |
| 409: | |
| 410: | |
| 411: | |
| 412: | |
| 413: | private static function render_dismiss( $creative ) { |
| 414: | printf( |
| 415: | '<a class="epl-msg__dismiss" href="%1$s" aria-label="%2$s">✕</a>', |
| 416: | esc_url( self::get_dismiss_url( $creative ) ), |
| 417: | esc_attr__( 'Dismiss FeedSync message', 'easy-property-listings' ) |
| 418: | ); |
| 419: | } |
| 420: | |
| 421: | |
| 422: | |
| 423: | |
| 424: | |
| 425: | |
| 426: | |
| 427: | private static function render_creative_a() { |
| 428: | ?> |
| 429: | <div class="epl-msg-wrap"> |
| 430: | <div class="epl-msg epl-msg--a"> |
| 431: | <?php self::render_wire( 4 ); ?> |
| 432: | <div class="epl-msg__mark" aria-label="FeedSync"> |
| 433: | <svg width="28" height="28" viewBox="0 0 28 28" fill="none" aria-hidden="true"><path d="M9 3H5a2 2 0 0 0-2 2v4M3 19v4a2 2 0 0 0 2 2h4" stroke="currentColor" stroke-width="2" stroke-linecap="round"/><circle cx="15" cy="7" r="1.4" fill="#4c7bff"/><circle cx="20.5" cy="7" r="1.4" fill="#4c7bff" opacity=".55"/><circle cx="15" cy="14" r="1.4" fill="#4c7bff"/><circle cx="20.5" cy="14" r="1.4" fill="#4c7bff" opacity=".55"/><circle cx="15" cy="21" r="1.4" fill="#4c7bff" opacity=".55"/><circle cx="20.5" cy="21" r="1.4" fill="#4c7bff" opacity=".3"/><path d="M9 14h1.5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg> |
| 434: | <strong>FeedSync</strong> |
| 435: | </div> |
| 436: | <div class="epl-msg__copy"> |
| 437: | <?php self::render_from(); ?> |
| 438: | <?php self::render_detected(); ?> |
| 439: | <h2><?php esc_html_e( 'Listings taking hours to show up?', 'easy-property-listings' ); ?></h2> |
| 440: | <p><?php esc_html_e( 'Move to FeedSync. Your listings go live the second your CRM sends them. No imports, no schedule, nothing to manage.', 'easy-property-listings' ); ?></p> |
| 441: | <?php self::render_deadline(); ?> |
| 442: | </div> |
| 443: | <div class="epl-msg__cta"> |
| 444: | <a class="epl-msg__button" href="<?php echo esc_url( self::FEEDSYNC_URL ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Move to FeedSync โ', 'easy-property-listings' ); ?></a> |
| 445: | <span><?php esc_html_e( 'Built for real estate feeds ยท since 2011', 'easy-property-listings' ); ?></span> |
| 446: | </div> |
| 447: | <?php self::render_dismiss( 'a' ); ?> |
| 448: | </div> |
| 449: | </div> |
| 450: | <?php |
| 451: | } |
| 452: | |
| 453: | |
| 454: | |
| 455: | |
| 456: | |
| 457: | |
| 458: | |
| 459: | private static function render_creative_b() { |
| 460: | ?> |
| 461: | <div class="epl-msg-wrap"> |
| 462: | <div class="epl-msg epl-msg--b"> |
| 463: | <?php self::render_wire( 3 ); ?> |
| 464: | <span class="epl-msg__badge"><?php esc_html_e( 'Slow site?', 'easy-property-listings' ); ?></span> |
| 465: | <div class="epl-msg__text"><?php self::render_from(); ?><strong><?php esc_html_e( 'Website slow when your imports run?', 'easy-property-listings' ); ?></strong> <?php esc_html_e( 'Move to FeedSync and your CRM syncs straight to your site. No imports at all.', 'easy-property-listings' ); ?><?php self::render_deadline(); ?></div> |
| 466: | <a class="epl-msg__button" href="<?php echo esc_url( self::FEEDSYNC_URL ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Move to FeedSync', 'easy-property-listings' ); ?></a> |
| 467: | <?php self::render_dismiss( 'b' ); ?> |
| 468: | </div> |
| 469: | </div> |
| 470: | <?php |
| 471: | } |
| 472: | |
| 473: | |
| 474: | |
| 475: | |
| 476: | |
| 477: | |
| 478: | |
| 479: | |
| 480: | private static function render_creative_c( $dismissible = true ) { |
| 481: | if ( self::has_companion() ) { |
| 482: | self::render_creative_c_active(); |
| 483: | return; |
| 484: | } |
| 485: | |
| 486: | $importer = self::has_importer(); |
| 487: | $legacy = ! $importer && self::has_connector(); |
| 488: | if ( $importer ) { |
| 489: | $source = self::get_product_label(); |
| 490: | } elseif ( $legacy ) { |
| 491: | $source = __( 'Legacy FeedSync', 'easy-property-listings' ); |
| 492: | } else { |
| 493: | $source = __( 'Scheduled imports', 'easy-property-listings' ); |
| 494: | } |
| 495: | ?> |
| 496: | <div class="epl-msg-wrap"> |
| 497: | <div class="epl-msg epl-msg--c"> |
| 498: | <div class="epl-msg__top"> |
| 499: | <div> |
| 500: | <?php self::render_from(); ?> |
| 501: | <?php |
| 502: | if ( $importer || $legacy ) { |
| 503: | self::render_detected( false ); |
| 504: | } |
| 505: | ?> |
| 506: | <h2><?php esc_html_e( 'Sold this morning.', 'easy-property-listings' ); ?> <em><?php esc_html_e( 'Still on your site tonight?', 'easy-property-listings' ); ?></em></h2> |
| 507: | <p> |
| 508: | <?php |
| 509: | if ( $importer ) { |
| 510: | echo esc_html( self::get_product_label() ) . ' ' . esc_html__( 'only updates your website when its next import runs. FeedSync updates it the second your CRM changes something.', 'easy-property-listings' ); |
| 511: | } elseif ( $legacy ) { |
| 512: | esc_html_e( 'The FeedSync Service replaces legacy FeedSync and updates your website the second your CRM changes something. Nothing to host or maintain.', 'easy-property-listings' ); |
| 513: | } else { |
| 514: | esc_html_e( 'Scheduled imports only update your website when the next one runs. FeedSync updates it the second your CRM changes something.', 'easy-property-listings' ); |
| 515: | } |
| 516: | ?> |
| 517: | </p> |
| 518: | <?php self::render_deadline(); ?> |
| 519: | </div> |
| 520: | <a class="epl-msg__button" href="<?php echo esc_url( self::FEEDSYNC_URL ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Move to FeedSync โ', 'easy-property-listings' ); ?></a> |
| 521: | </div> |
| 522: | <div class="epl-msg__lanes" aria-hidden="true"> |
| 523: | <div class="epl-msg__lane"> |
| 524: | <div class="epl-msg__who"><strong><?php esc_html_e( 'Your site now', 'easy-property-listings' ); ?></strong><span><?php echo esc_html( $source ); ?></span></div> |
| 525: | <div class="epl-msg__track"><i class="epl-msg__batch"></i></div> |
| 526: | <div class="epl-msg__end"><?php echo $legacy ? esc_html__( 'being retired', 'easy-property-listings' ) : esc_html__( 'updates every few hours', 'easy-property-listings' ); ?></div> |
| 527: | </div> |
| 528: | <div class="epl-msg__lane"> |
| 529: | <div class="epl-msg__who"><strong><?php esc_html_e( 'Your site on FeedSync', 'easy-property-listings' ); ?></strong><span><?php esc_html_e( 'direct from your CRM', 'easy-property-listings' ); ?></span></div> |
| 530: | <div class="epl-msg__track"><i class="epl-msg__stream"></i><i class="epl-msg__stream"></i><i class="epl-msg__stream"></i><i class="epl-msg__stream"></i><i class="epl-msg__stream"></i></div> |
| 531: | <div class="epl-msg__end"><?php esc_html_e( 'updates instantly', 'easy-property-listings' ); ?></div> |
| 532: | </div> |
| 533: | </div> |
| 534: | <?php |
| 535: | if ( $dismissible ) { |
| 536: | self::render_dismiss( 'c' ); |
| 537: | } |
| 538: | ?> |
| 539: | </div> |
| 540: | </div> |
| 541: | <?php |
| 542: | } |
| 543: | |
| 544: | |
| 545: | |
| 546: | |
| 547: | |
| 548: | |
| 549: | |
| 550: | private static function render_creative_c_active() { |
| 551: | ?> |
| 552: | <div class="epl-msg-wrap"> |
| 553: | <div class="epl-msg epl-msg--c epl-msg--active"> |
| 554: | <div class="epl-msg__top"> |
| 555: | <div> |
| 556: | <?php self::render_from(); ?> |
| 557: | <span class="epl-msg__detected"><span></span><?php esc_html_e( 'Active on this site', 'easy-property-listings' ); ?></span> |
| 558: | <h2><?php esc_html_e( 'Sold this morning.', 'easy-property-listings' ); ?> <em><?php esc_html_e( 'Gone from your site this second.', 'easy-property-listings' ); ?></em></h2> |
| 559: | <p><?php esc_html_e( "This site is on FeedSync: your CRM's changes reach your website the moment they're made.", 'easy-property-listings' ); ?></p> |
| 560: | </div> |
| 561: | <a class="epl-msg__button" href="<?php echo esc_url( self::FEEDSYNC_URL ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Open FeedSync โ', 'easy-property-listings' ); ?></a> |
| 562: | </div> |
| 563: | <div class="epl-msg__lanes" aria-hidden="true"> |
| 564: | <div class="epl-msg__lane"> |
| 565: | <div class="epl-msg__who"><strong><?php esc_html_e( 'Your site on FeedSync', 'easy-property-listings' ); ?></strong><span><?php esc_html_e( 'direct from your CRM', 'easy-property-listings' ); ?></span></div> |
| 566: | <div class="epl-msg__track"><i class="epl-msg__stream"></i><i class="epl-msg__stream"></i><i class="epl-msg__stream"></i><i class="epl-msg__stream"></i><i class="epl-msg__stream"></i></div> |
| 567: | <div class="epl-msg__end"><?php esc_html_e( 'updates instantly', 'easy-property-listings' ); ?></div> |
| 568: | </div> |
| 569: | </div> |
| 570: | </div> |
| 571: | </div> |
| 572: | <?php |
| 573: | } |
| 574: | } |
| 575: | |
| 576: | EPL_Admin_Messages::init(); |
| 577: | |