| 1 |
<?php |
| 2 |
/** |
| 3 |
* Support and feedback where people go looking for them. |
| 4 |
* |
| 5 |
* The review notice only appears after ten days and twenty-five confirmed |
| 6 |
* opt-ins, and it can be dismissed for good — so it cannot be the only route to |
| 7 |
* us. These entries are always there. |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace forge12\contactform7\CF7DoubleOptIn; |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Add Support and Feedback next to Activate/Deactivate in the plugin list. |
| 18 |
* |
| 19 |
* Typed loosely because this is a public filter: another plugin can hand over |
| 20 |
* something that is not the array WordPress documents, and losing the whole |
| 21 |
* plugin row over our two links would be a poor trade. |
| 22 |
* |
| 23 |
* @param mixed $links The action links WordPress collected so far. |
| 24 |
* |
| 25 |
* @return mixed |
| 26 |
*/ |
| 27 |
function add_plugin_action_links( $links ) { |
| 28 |
if ( ! is_array( $links ) ) { |
| 29 |
return $links; |
| 30 |
} |
| 31 |
|
| 32 |
$own = array( |
| 33 |
'f12_doi_support' => sprintf( |
| 34 |
'<a href="%s" target="_blank" rel="noopener">%s</a>', |
| 35 |
esc_url( get_support_url( 'plugin-list' ) ), |
| 36 |
esc_html__( 'Support', 'double-opt-in' ) |
| 37 |
), |
| 38 |
'f12_doi_feedback' => sprintf( |
| 39 |
'<a href="%s" target="_blank" rel="noopener">%s</a>', |
| 40 |
esc_url( get_feedback_url( 'plugin-list' ) ), |
| 41 |
esc_html__( 'Feedback', 'double-opt-in' ) |
| 42 |
), |
| 43 |
); |
| 44 |
|
| 45 |
// Appended rather than prepended: Deactivate and Settings are what someone |
| 46 |
// opened this row for. |
| 47 |
return array_merge( $links, $own ); |
| 48 |
} |
| 49 |
|
| 50 |
if ( defined( 'FORGE12_OPTIN_BASENAME' ) ) { |
| 51 |
add_filter( 'plugin_action_links_' . FORGE12_OPTIN_BASENAME, __NAMESPACE__ . '\add_plugin_action_links' ); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Add a Feedback & Support entry to the plugin's admin menu. |
| 56 |
* |
| 57 |
* add_submenu_page() cannot point at an external address, so the entry is |
| 58 |
* registered normally and its href rewritten afterwards. |
| 59 |
*/ |
| 60 |
function add_feedback_menu_item(): void { |
| 61 |
$slug = 'f12-doi-feedback'; |
| 62 |
|
| 63 |
add_submenu_page( |
| 64 |
'f12-doi-admin', |
| 65 |
__( 'Feedback', 'double-opt-in' ), |
| 66 |
__( 'Feedback & Support', 'double-opt-in' ), |
| 67 |
'manage_options', |
| 68 |
$slug, |
| 69 |
'__return_null' |
| 70 |
); |
| 71 |
|
| 72 |
point_menu_item_at( $slug, get_feedback_url( 'admin-menu' ) ); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Send a registered submenu entry to an external address, and open it in a new tab. |
| 77 |
* |
| 78 |
* The URL travels as a JSON string literal and is compared against the |
| 79 |
* attribute value rather than being interpolated into a selector: escaping it |
| 80 |
* for a selector HTML-encodes the ampersands in the query string, so the |
| 81 |
* selector would ask for `…&from=…` while the anchor carries `…&from=…`, |
| 82 |
* match nothing, and quietly open in the same tab. Throwing an admin out of |
| 83 |
* their dashboard on the way to a bug report is a good way to lose the report. |
| 84 |
* |
| 85 |
* @param string $slug The slug the entry was registered under. |
| 86 |
* @param string $url Where it should actually go. |
| 87 |
*/ |
| 88 |
function point_menu_item_at( string $slug, string $url ): void { |
| 89 |
global $submenu; |
| 90 |
|
| 91 |
if ( ! isset( $submenu['f12-doi-admin'] ) || ! is_array( $submenu['f12-doi-admin'] ) ) { |
| 92 |
return; |
| 93 |
} |
| 94 |
|
| 95 |
foreach ( $submenu['f12-doi-admin'] as $index => $item ) { |
| 96 |
if ( isset( $item[2] ) && $item[2] === $slug ) { |
| 97 |
$submenu['f12-doi-admin'][ $index ][2] = $url; |
| 98 |
break; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
add_action( |
| 103 |
'admin_footer', |
| 104 |
function () use ( $url ) { |
| 105 |
?> |
| 106 |
<script> |
| 107 |
(function () { |
| 108 |
var target = <?php echo wp_json_encode( $url ); ?>; |
| 109 |
document.querySelectorAll('#adminmenu a').forEach(function (a) { |
| 110 |
if (a.getAttribute('href') === target) { |
| 111 |
a.setAttribute('target', '_blank'); |
| 112 |
a.setAttribute('rel', 'noopener'); |
| 113 |
} |
| 114 |
}); |
| 115 |
})(); |
| 116 |
</script> |
| 117 |
<?php |
| 118 |
} |
| 119 |
); |
| 120 |
} |
| 121 |
|
| 122 |
// Priority 100: after the plugin's own pages are registered, so the parent menu |
| 123 |
// exists and the entry lands at the bottom. |
| 124 |
add_action( 'admin_menu', __NAMESPACE__ . '\add_feedback_menu_item', 100 ); |
| 125 |
|