-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fund-me.php
67 lines (53 loc) · 2.08 KB
/
fund-me.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* Plugin Name: Fund me
* Plugin URI: https://github.com/natbienetre/wordpress-fund-me
* Version: 0.0.1
* GitHub Plugin URI: natbienetre/wordpress-fund-me
* Funding URI: https://github.com/sponsors/holyhope
* License: MPL-2.0
* License URI: https://www.mozilla.org/en-US/MPL/2.0/
* Description: Add a button to help get funding.
* Author: Pierre PÉRONNET
* Author URI: https://github.com/holyhope
* Text Domain: fundme
* Domain Path: /languages
*/
define( 'FUND_ME_PLUGIN_HEADER', 'Funding URI' );
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
require __DIR__ . '/vendor/autoload.php';
}
add_action( 'admin_init', 'fundme_admin_init' );
function fundme_admin_init() {
add_filter( 'plugin_action_links', 'fundme_plugins_action_links', 10, 3 );
add_filter( 'network_admin_plugin_action_links', 'fundme_plugins_action_links', 10, 3 );
add_filter( 'theme_action_links', 'fundme_themes_action_links', 10, 2 );
}
function fundme_plugins_action_links( array $actions, string $plugin_file, array $plugin_data ) {
if ( empty( $plugin_data[ FUND_ME_PLUGIN_HEADER ] ) ) {
return $actions;
}
$actions[] = fundme_action_link( $plugin_data[ FUND_ME_PLUGIN_HEADER ] );
return $actions;
}
function fundme_themes_action_links( array $actions, WP_Theme $theme ) {
$url = $theme->get( FUND_ME_PLUGIN_HEADER );
if ( ! $url ) {
return $actions;
}
$actions[] = fundme_action_link( $url );
return $actions;
}
function fundme_action_link( string $url ): string {
return '<a target="_blank" href="' . esc_attr( $url ) . '">' .
_x( "❤️\u{00A0}Show support", 'text link to sponsor the developper', 'fundme' ) .
'</a>';
}
add_filter( 'extra_plugin_headers', 'fundme_extra_funding_uri' );
add_filter( 'extra_theme_headers', 'fundme_extra_funding_uri' );
function fundme_extra_funding_uri( array $headers ): array {
if ( ! in_array( FUND_ME_PLUGIN_HEADER, $headers ) ) {
$headers[] = FUND_ME_PLUGIN_HEADER;
}
return $headers;
}