|
| 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 | +} |
0 commit comments