Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
9.09% covered (danger)
9.09%
1 / 11
0.00% covered (danger)
0.00%
0 / 3
CRAP
n/a
0 / 0
wpcomsh_suppress_crowdsignal_activation_redirect
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
wpcomsh_suppress_crowdsignal_forms_setup_notice
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
12
wpcomsh_suppress_crowdsignal_polldaddy_login_warning
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
4.12
1<?php
2/**
3 * Crowdsignal plugin tweaks for WoA sites.
4 *
5 * @package wpcomsh
6 */
7
8/**
9 * Prevent Crowdsignal Forms from hijacking wp-admin with its onboarding redirect.
10 *
11 * On activation Crowdsignal sets the `crowdsignal_forms_do_activation_redirect` option
12 * and, on the next admin_init, redirects to its settings page unless a Crowdsignal
13 * account is already connected. That connection lives in WordPress.com-managed state and
14 * isn't present in the site's options on Atomic, so the plugin's own guard misses and the
15 * redirect fires on every activation a WoA site sees: the Simple-to-Atomic transfer (which
16 * installs and activates the plugin) and every later managed version-bump reactivation.
17 * None of those should send the admin to Crowdsignal's settings page.
18 *
19 * wpcomsh only loads on Atomic, so clearing the flag here is inherently WoA-scoped. Running
20 * at priority 1 ensures the option is gone before Crowdsignal's own admin_init handler
21 * (priority 10) reads it, regardless of how the activation was triggered.
22 */
23function wpcomsh_suppress_crowdsignal_activation_redirect() {
24    if ( get_option( 'crowdsignal_forms_do_activation_redirect' ) ) {
25        delete_option( 'crowdsignal_forms_do_activation_redirect' );
26    }
27}
28add_action( 'admin_init', 'wpcomsh_suppress_crowdsignal_activation_redirect', 1 );
29
30/**
31 * Suppress Crowdsignal Forms' "getting started" setup notice on WoA sites.
32 *
33 * On activation Crowdsignal Forms enqueues a persistent "core setup" notice and renders it on
34 * the Plugins and Dashboard screens until the user either connects a Crowdsignal account or
35 * dismisses it. Because WoA activates the plugin during the Simple-to-Atomic transfer and again
36 * on every managed version-bump reactivation, and because the account connection lives in
37 * WordPress.com-managed state the plugin can't read locally, this notice reappears uninvited and
38 * clutters the Plugins page for users who never chose to install it.
39 *
40 * Crowdsignal Forms exposes a `crowdsignal_forms_show_admin_notice_{notice}` filter for exactly
41 * this purpose; returning false keeps the notice from rendering without disturbing its stored
42 * state or the plugin's own dismissal handling. The plugin's own callback on this filter runs at
43 * the default priority and returns true whenever no account is connected, so we hook at
44 * PHP_INT_MAX to have the final say regardless of hook-registration order.
45 *
46 * The suppression is scoped to the Plugins and Dashboard screens, which is where the notice is
47 * unsolicited clutter. Upstream also renders it on Crowdsignal Forms' own admin screen; there it
48 * is deliberate setup guidance for a user who navigated in on purpose, so we pass the incoming
49 * value through and leave the plugin's own logic in charge.
50 *
51 * Only the "core setup" notice is touched: the sibling "setup success" notice is gated on a
52 * `?msg=connect` request and is deliberate feedback shown right after a user completes setup, not
53 * part of the activation clutter, so it is left intact.
54 *
55 * @param bool $show Whether Crowdsignal Forms intends to show the notice.
56 * @return bool
57 */
58function wpcomsh_suppress_crowdsignal_forms_setup_notice( $show ) {
59    $screen = get_current_screen();
60    if ( $screen && in_array( $screen->id, array( 'plugins', 'dashboard' ), true ) ) {
61        return false;
62    }
63    return $show;
64}
65add_filter( 'crowdsignal_forms_show_admin_notice_core_setup', 'wpcomsh_suppress_crowdsignal_forms_setup_notice', PHP_INT_MAX );
66
67/**
68 * Suppress the Crowdsignal Dashboard (Polldaddy) "link your account" warning on WoA sites.
69 *
70 * The Crowdsignal Dashboard plugin (slug `polldaddy`) prints a "Crowdsignal features will be
71 * unavailable until you link your Crowdsignal.com account" warning on the Plugins screen and on
72 * its own poll/rating screens whenever no `polldaddy_api_key` option is stored. As with Crowdsignal
73 * Forms, WoA activates this plugin without the user asking, and the account link lives in
74 * WordPress.com-managed state the plugin can't read locally, so the warning is never actionable
75 * here and just clutters the Plugins page.
76 *
77 * Scope this to the Plugins screen only. On the plugin's own poll/rating screens the warning is
78 * the intended explanation for why features are unavailable, so leave it there.
79 *
80 * Unlike Crowdsignal Forms, this notice has no suppression filter: it is echoed directly from a
81 * named `admin_notices` callback. Remove that callback instead. The `current_screen` hook fires
82 * after all plugins have loaded (so polldaddy has already registered the callback) and before
83 * admin_notices renders, and remove_action is a no-op when the plugin is inactive.
84 *
85 * @param WP_Screen $screen The current admin screen.
86 */
87function wpcomsh_suppress_crowdsignal_polldaddy_login_warning( $screen ) {
88    if ( $screen && 'plugins' === $screen->id ) {
89        remove_action( 'admin_notices', 'polldaddy_login_warning' );
90    }
91}
92add_action( 'current_screen', 'wpcomsh_suppress_crowdsignal_polldaddy_login_warning' );