Skip to content

Commit 38692d0

Browse files
Merge pull request #1067 from equalizedigital/steve/pro-199-filter-admin-footer-message-only-on-our-settings-pages
added: Admin_Footer_Text class and corresponding PHPUnit tests
2 parents 2052c02 + 8fb0dac commit 38692d0

3 files changed

Lines changed: 469 additions & 0 deletions

File tree

admin/class-admin-footer-text.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* Filters the admin_footer_text on Accessibility Checker settings pages only.
4+
*
5+
* @package Accessibility_Checker\Admin
6+
*/
7+
8+
namespace EqualizeDigital\AccessibilityChecker\Admin;
9+
10+
if ( ! defined( 'ABSPATH' ) ) {
11+
exit; // Exit if accessed directly.
12+
}
13+
14+
/**
15+
* Class Admin_Footer_Text
16+
*
17+
* Handles filtering of admin footer text on Accessibility Checker settings pages.
18+
*
19+
* @since 1.27.0
20+
*/
21+
class Admin_Footer_Text {
22+
/**
23+
* Initialize the admin footer text filter.
24+
*
25+
* @since 1.27.0
26+
*/
27+
public function init() {
28+
add_filter( 'admin_footer_text', [ $this, 'filter_footer_text' ] );
29+
}
30+
31+
/**
32+
* Filter the admin footer text on our settings pages only.
33+
*
34+
* @since 1.27.0
35+
* @param string $footer_text The current footer text.
36+
* @return string
37+
*/
38+
public function filter_footer_text( $footer_text ) {
39+
if ( ! $this->is_settings_page() ) {
40+
return $footer_text;
41+
}
42+
43+
if ( $this->is_pro_active() ) {
44+
return sprintf(
45+
/* translators: %1$s: opening link tag, %2$s: closing link tag */
46+
esc_html__( 'Enjoying Accessibility Checker? %1$sPlease leave us a ★★★★★ rating.%2$s We really appreciate your support!', 'accessibility-checker' ),
47+
'<a href="' . esc_url( 'https://wordpress.org/support/plugin/accessibility-checker/reviews/#new-post' ) . '" target="_blank" aria-label="' . esc_attr__( 'Please leave us a five star rating (opens in new window)', 'accessibility-checker' ) . '">',
48+
'</a>'
49+
);
50+
}
51+
52+
$pro_link = edac_link_wrapper( 'https://equalizedigital.com/accessibility-checker/pricing/', 'admin-footer', 'admin-footer-text', false );
53+
return sprintf(
54+
/* translators: %1$s: opening link tag, %2$s: closing link tag */
55+
esc_html__( 'Want to do more with Accessibility Checker? %1$sUnlock Pro Features%2$s', 'accessibility-checker' ),
56+
'<a href="' . esc_url( $pro_link ) . '" target="_blank" aria-label="' . esc_attr__( 'Unlock Pro Features (opens in new window)', 'accessibility-checker' ) . '">',
57+
'</a>'
58+
);
59+
}
60+
61+
/**
62+
* Check if we are on the Accessibility Checker settings page.
63+
*
64+
* @since 1.27.0
65+
* @return bool
66+
*/
67+
protected function is_settings_page() {
68+
// Check if we're on an admin page and have a page parameter.
69+
if ( ! is_admin() || ! isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
70+
return false;
71+
}
72+
73+
// Sanitize and check if it's an accessibility checker page.
74+
$page = sanitize_text_field( wp_unslash( $_GET['page'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
75+
return strpos( $page, 'accessibility_checker' ) === 0;
76+
}
77+
78+
/**
79+
* Check if Pro is active with a valid license.
80+
*
81+
* @since 1.27.0
82+
* @return bool
83+
*/
84+
protected function is_pro_active() {
85+
// Pro is active if EDACP_VERSION is defined and license is valid.
86+
return defined( 'EDACP_VERSION' ) && defined( 'EDAC_KEY_VALID' ) && EDAC_KEY_VALID;
87+
}
88+
}

admin/class-admin.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use EDAC\Admin\SiteHealth\Information;
1111
use EDAC\Admin\Purge_Post_Data;
1212
use EDAC\Admin\Post_Save;
13+
use EqualizeDigital\AccessibilityChecker\Admin\Admin_Footer_Text;
1314

1415
/**
1516
* Admin handling class.
@@ -57,6 +58,9 @@ public function init(): void {
5758
$site_health_info = new Information();
5859
$site_health_info->init_hooks();
5960

61+
$admin_footer_text = new Admin_Footer_Text();
62+
$admin_footer_text->init();
63+
6064
$this->init_ajax();
6165

6266
$this->meta_boxes->init_hooks();

0 commit comments

Comments
 (0)