css
4 months ago
js
4 months ago
admin-bar.php
4 months ago
clear-cache.php
3 weeks ago
common.php
8 months ago
index.php
1 year ago
settings.php
5 hours ago
common.php
117 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Version check, activation, deactivation, uninstallation, etc. |
| 4 | */ |
| 5 | |
| 6 | |
| 7 | /** |
| 8 | * Define Namespaces |
| 9 | */ |
| 10 | namespace Apos37\ClearCache; |
| 11 | |
| 12 | |
| 13 | /** |
| 14 | * Exit if accessed directly. |
| 15 | */ |
| 16 | if ( !defined( 'ABSPATH' ) ) exit; |
| 17 | |
| 18 | |
| 19 | /** |
| 20 | * Instantiate the class |
| 21 | */ |
| 22 | new Common(); |
| 23 | |
| 24 | |
| 25 | /** |
| 26 | * The class |
| 27 | */ |
| 28 | class Common { |
| 29 | |
| 30 | /** |
| 31 | * Constructor |
| 32 | */ |
| 33 | public function __construct() { |
| 34 | |
| 35 | // PHP Version check |
| 36 | $this->check_php_version(); |
| 37 | |
| 38 | // Add links to the website and discord |
| 39 | add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 2 ); |
| 40 | |
| 41 | } // End __construct() |
| 42 | |
| 43 | |
| 44 | /** |
| 45 | * Prevent loading the plugin if PHP version is not minimum |
| 46 | * |
| 47 | * @return void |
| 48 | */ |
| 49 | public function check_php_version() { |
| 50 | if ( version_compare( PHP_VERSION, CCEVERYWHERE_MIN_PHP_VERSION, '<=' ) ) { |
| 51 | add_action( 'admin_init', function() { |
| 52 | deactivate_plugins( CCEVERYWHERE_BASENAME ); |
| 53 | } ); |
| 54 | add_action( 'admin_notices', function() { |
| 55 | /* translators: 1: Plugin name, 2: Required PHP version */ |
| 56 | $notice = sprintf( __( '%1$s requires PHP %2$s or newer.', 'clear-cache-everywhere' ), |
| 57 | CCEVERYWHERE_NAME, |
| 58 | CCEVERYWHERE_MIN_PHP_VERSION |
| 59 | ); |
| 60 | echo wp_kses_post( |
| 61 | '<div class="notice notice-error"><p>' . esc_html( $notice ) . '</p></div>' |
| 62 | ); |
| 63 | } ); |
| 64 | return; |
| 65 | } |
| 66 | } // End check_php_version() |
| 67 | |
| 68 | |
| 69 | /** |
| 70 | * Add links to plugin row |
| 71 | * |
| 72 | * @param array $links |
| 73 | * @return array |
| 74 | */ |
| 75 | public function plugin_row_meta( $links, $file ) { |
| 76 | $text_domain = CCEVERYWHERE_TEXTDOMAIN; |
| 77 | if ( $text_domain . '/' . $text_domain . '.php' == $file ) { |
| 78 | |
| 79 | $guide_url = CCEVERYWHERE_GUIDE_URL; |
| 80 | $docs_url = CCEVERYWHERE_DOCS_URL; |
| 81 | $support_url = CCEVERYWHERE_SUPPORT_URL; |
| 82 | $plugin_name = CCEVERYWHERE_NAME; |
| 83 | |
| 84 | $our_links = [ |
| 85 | 'guide' => [ |
| 86 | // translators: Link label for the plugin's user-facing guide. |
| 87 | 'label' => __( 'How-To Guide', 'clear-cache-everywhere' ), |
| 88 | 'url' => $guide_url |
| 89 | ], |
| 90 | 'docs' => [ |
| 91 | // translators: Link label for the plugin's developer documentation. |
| 92 | 'label' => __( 'Developer Docs', 'clear-cache-everywhere' ), |
| 93 | 'url' => $docs_url |
| 94 | ], |
| 95 | 'support' => [ |
| 96 | // translators: Link label for the plugin's support page. |
| 97 | 'label' => __( 'Support', 'clear-cache-everywhere' ), |
| 98 | 'url' => $support_url |
| 99 | ], |
| 100 | ]; |
| 101 | |
| 102 | $row_meta = []; |
| 103 | foreach ( $our_links as $key => $link ) { |
| 104 | // translators: %1$s is the link label, %2$s is the plugin name. |
| 105 | $aria_label = sprintf( __( '%1$s for %2$s', 'clear-cache-everywhere' ), $link[ 'label' ], $plugin_name ); |
| 106 | $row_meta[ $key ] = '<a href="' . esc_url( $link[ 'url' ] ) . '" target="_blank" aria-label="' . esc_attr( $aria_label ) . '">' . esc_html( $link[ 'label' ] ) . '</a>'; |
| 107 | } |
| 108 | |
| 109 | // Add the links |
| 110 | return array_merge( $links, $row_meta ); |
| 111 | } |
| 112 | |
| 113 | // Return the links |
| 114 | return (array) $links; |
| 115 | } // End plugin_row_meta() |
| 116 | |
| 117 | } |