forked from wp-activators/elementor-pro-activator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
92 lines (86 loc) · 3.64 KB
/
functions.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* Requires at least: 3.1.0
* Requires PHP: 7.1
*/
if ( ! function_exists( 'is_plugin_active' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if ( ! function_exists( 'wp_get_current_user' ) ) {
require_once( ABSPATH . 'wp-includes/pluggable.php' );
}
if ( ! function_exists( 'is_plugin_installed' ) ) {
function is_plugin_installed( $plugin ): bool {
$installed_plugins = get_plugins();
return isset( $installed_plugins[ $plugin ] );
}
}
if ( ! function_exists( 'activator_admin_notice_ignored' ) ) {
function activator_admin_notice_ignored(): bool {
global $pagenow;
$action = $_REQUEST['action'] ?? '';
return $pagenow == 'update.php' && in_array( $action, [ 'install-plugin', 'upload-plugin' ], true );
}
}
if ( ! function_exists( 'activator_admin_notice_plugin_install' ) ) {
function activator_admin_notice_plugin_install( string $plugin, ?string $wp_plugin_id, string $plugin_name, string $activator_name, string $domain ): bool {
if ( ! is_plugin_installed( $plugin ) ) {
if ( ! current_user_can( 'install_plugins' ) ) {
return true;
}
$install_url = wp_nonce_url( self_admin_url( "update.php?action=install-plugin&plugin={$wp_plugin_id}" ), "install-plugin_{$wp_plugin_id}" );
$message = '<h3>' . esc_html__( "{$activator_name} plugin requires installing the {$plugin_name} plugin", $domain ) . '</h3>';
$message .= '<p>' . __( "Install and activate the \"{$plugin_name}\" plugin to access all the <b>{$activator_name}</b> features.", $domain ) . '</p>';
if ( $wp_plugin_id !== null ) {
$message .= '<p>' . sprintf( '<a href="%s" class="button-primary">%s</a>', $install_url, esc_html__( 'Install Now', $domain ) ) . '</p>';
}
add_action( 'admin_notices', function () use ( $message ) {
?>
<div class="notice notice-error">
<p><?= $message ?></p>
</div><?php
} );
return true;
}
return false;
}
}
if ( ! function_exists( 'activator_admin_notice_plugin_activate' ) ) {
function activator_admin_notice_plugin_activate( string $plugin, string $activator_name, string $domain ): bool {
if ( ! is_plugin_active( $plugin ) ) {
if ( ! current_user_can( 'activate_plugins' ) ) {
return true;
}
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
# sub str from the beginning of $plugin to the first '/'
$plugin_id = substr( $plugin, 0, strpos( $plugin, '/' ) );
$activate_action = sprintf(
'<a href="%s" id="activate-%s" class=button-primary aria-label="%s">%s</a>',
wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $plugin ) . '&plugin_status=all&paged=1&s=', 'activate-plugin_' . $plugin ),
esc_attr( $plugin_id ),
/* translators: %s: Plugin name. */
esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin_data['Name'] ) ),
__( 'Activate Now' )
);
$message = '<h3>' . esc_html__( "You're not using \"{$plugin_data['Name']}\" plugin yet!", $domain ) . '</h3>';
$message .= '<p>' . __( "Activate the \"{$plugin_data['Name']}\" plugin to start using all of <b>{$activator_name}</b> plugin’s features.", $domain ) . '</p>';
$message .= '<p>' . $activate_action . '</p>';
add_action( 'admin_notices', function () use ( $message ) {
?>
<div class="notice notice-warning">
<p><?= $message ?></p>
</div><?php
} );
return true;
}
return false;
}
}
if ( ! function_exists( 'activator_json_response' ) ) {
function activator_json_response( $data ) {
return [
'response' => [ 'code' => 200, 'message' => 'OK' ],
'body' => json_encode( $data )
];
}
}