1: <?php
2: /**
3: * Admin messages: the FeedSync Service message for sites importing listings with the EPL WP All Import add-on.
4: *
5: * @package EPL
6: * @subpackage Admin
7: * @since 3.6
8: */
9:
10: // Exit if accessed directly.
11: if ( ! defined( 'ABSPATH' ) ) {
12: exit;
13: }
14:
15: /**
16: * Admin messages
17: *
18: * Today one message: the FeedSync Service, in three versions (creatives).
19: *
20: * Shown to users who can edit posts when the Easy Property Listings Import CSV, XML WP All
21: * Import add-on is active (the legacy FeedSync setup) and the FeedSync Service companion
22: * plugin isn't (the site hasn't moved yet). Filter epl_admin_messages_show to turn them off.
23: *
24: * Only one creative is displayed per screen:
25: * - A on EPL settings and extension screens.
26: * - C on WP All Import screens.
27: * - B throughout the remainder of the WordPress admin.
28: *
29: * Dismissal is stored per user and per creative.
30: *
31: * @since 3.6
32: */
33: class EPL_Admin_Messages {
34:
35: /**
36: * User meta key for dismissed messages.
37: *
38: * @var string
39: */
40: const DISMISSED_META_KEY = 'epl_dismissed_admin_messages';
41:
42: /**
43: * FeedSync destination.
44: *
45: * @var string
46: */
47: const FEEDSYNC_URL = 'https://feedsync.com.au/';
48:
49: /**
50: * Last day legacy FeedSync is supported (Y-m-d). The deadline line shows until the end of this day.
51: *
52: * @var string
53: */
54: const LEGACY_RETIRES = '2026-12-05';
55:
56: /**
57: * Whether the banners show on this site (cached for the request).
58: *
59: * @var bool|null
60: */
61: private static $show = null;
62:
63: /**
64: * Register hooks.
65: *
66: * @since 3.6
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: * Is a plugin with this main file name active?
76: *
77: * Matches on the file name only, so a renamed plugin folder still counts. Includes
78: * network-activated plugins on multisite.
79: *
80: * @param string $basename Plugin main file name, for example epl-wp-all-import.php.
81: * @return bool
82: * @since 3.6
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: * Is the EPL WP All Import add-on active?
102: *
103: * @return bool
104: * @since 3.6
105: */
106: private static function has_importer() {
107: return self::is_plugin_file_active( 'epl-wp-all-import.php' );
108: }
109:
110: /**
111: * Is the legacy EPL FeedSync Connector add-on active? It takes realtime updates from a
112: * self-hosted legacy FeedSync, which retires on 5 December 2026.
113: *
114: * @return bool
115: * @since 3.6
116: */
117: private static function has_connector() {
118: return self::is_plugin_file_active( 'epl-feedsync-connector.php' );
119: }
120:
121: /**
122: * Is the FeedSync Service companion plugin active (the site is on FeedSync)?
123: *
124: * @return bool
125: * @since 3.6
126: */
127: private static function has_companion() {
128: return self::is_plugin_file_active( 'feedsync-companion.php' );
129: }
130:
131: /**
132: * Should the banners show on this site?
133: *
134: * Yes when the EPL WP All Import add-on or the legacy EPL FeedSync Connector add-on is
135: * active and the FeedSync Service companion plugin isn't.
136: *
137: * @return bool
138: * @since 3.6
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: * Filters whether an admin message shows.
149: *
150: * @since 3.6
151: *
152: * @param bool $show True when the EPL WP All Import or EPL FeedSync Connector add-on is active and the FeedSync companion isn't.
153: * @param string $message Which message: feedsync.
154: */
155: self::$show = (bool) apply_filters( 'epl_admin_messages_show', $show, 'feedsync' );
156:
157: return self::$show;
158: }
159:
160: /**
161: * Enqueue the message stylesheet only where a message can show.
162: *
163: * @return void
164: * @since 3.6
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: * Show the message for the current screen.
181: *
182: * @return void
183: * @since 3.6
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: * Is this the EPL Add Ons page?
210: *
211: * @return bool
212: * @since 3.6
213: */
214: private static function is_addons_page() {
215: return isset( $_GET['page'] ) && 'epl-addons' === sanitize_key( wp_unslash( $_GET['page'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
216: }
217:
218: /**
219: * FeedSync Service row on the Add Ons page
220: *
221: * Creative C as a listing of the service, on every site, and it can't be dismissed.
222: * Sites already on FeedSync (companion active) see that it's active instead of the
223: * pitch. The "detected" chip and the WP All Import wording only appear when the EPL
224: * WP All Import add-on is active.
225: *
226: * @return void
227: * @since 3.6
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: * Determine which creative belongs on the current screen.
237: *
238: * @return string
239: * @since 3.6
240: */
241: private static function get_current_creative() {
242: $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only picks which banner to show; nothing is saved.
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: * Name of the active WP All Import edition, for the banner copy.
262: *
263: * @return string
264: * @since 3.6
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: * Output the "detected" chip naming the EPL import add-on, or the FeedSync Connector
272: * when that's the one active.
273: *
274: * @param bool $on_this_site Add "on this site".
275: * @return void
276: * @since 3.6
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: * Output the label saying which plugin shows the banner.
294: *
295: * @return void
296: * @since 3.6
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: * Determine whether a creative has been dismissed by the current user.
304: *
305: * @param string $creative Creative identifier.
306: * @return bool
307: * @since 3.6
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: * Build the dismiss URL for a creative.
317: *
318: * @param string $creative Creative identifier.
319: * @return string
320: * @since 3.6
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: * Store a per-user dismissal and return to the originating screen.
337: *
338: * @return void
339: * @since 3.6
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: * Legacy FeedSync retirement line, shown until the retirement date.
365: *
366: * @return string The line, or '' after the retirement date.
367: * @since 3.6
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: * Output the legacy FeedSync retirement line, when it still applies.
378: *
379: * @return void
380: * @since 3.6
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: * Output shared animated wire markup.
392: *
393: * @param int $packets Number of packets.
394: * @return void
395: * @since 3.6
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: * Output shared dismiss control.
408: *
409: * @param string $creative Creative identifier.
410: * @return void
411: * @since 3.6
412: */
413: private static function render_dismiss( $creative ) {
414: printf(
415: '<a class="epl-msg__dismiss" href="%1$s" aria-label="%2$s">&#10005;</a>',
416: esc_url( self::get_dismiss_url( $creative ) ),
417: esc_attr__( 'Dismiss FeedSync message', 'easy-property-listings' )
418: );
419: }
420:
421: /**
422: * Render flagship creative A.
423: *
424: * @return void
425: * @since 3.6
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: * Render global strip creative B.
455: *
456: * @return void
457: * @since 3.6
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: * Render WP All Import screen creative C.
475: *
476: * @param bool $dismissible Show the dismiss control. False on the Add Ons page.
477: * @return void
478: * @since 3.6
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: * Render creative C for a site already on FeedSync (Add Ons page only).
546: *
547: * @return void
548: * @since 3.6
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: