-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathshared.php
More file actions
121 lines (92 loc) · 3.35 KB
/
shared.php
File metadata and controls
121 lines (92 loc) · 3.35 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* Shared Functions
*
* A group of functions shared across my plugins, for consistency.
*
* @package simple-embed-code
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Add meta to plugin details
*
* Add options to plugin meta line.
*
* Internal code version: 1.3
*
* @param array $links Current links.
* @param string $file File in use.
* @return array Links, now with settings added.
*/
function sec_plugin_meta( $links, $file ) {
if ( CODE_EMBED_PLUGIN_BASE === $file ) {
$links = array_merge(
$links,
array( '<a href="' . esc_url( 'https://github.com/dartiss/code-embed' ) . '">' . __( 'Github', 'simple-embed-code' ) . '</a>' ),
array( '<a href="' . esc_url( 'https://wordpress.org/support/plugin/simple-embed-code' ) . '">' . __( 'Support', 'simple-embed-code' ) . '</a>' ),
array( '<a href="' . esc_url( 'https://wordpress.org/support/plugin/simple-embed-code/reviews/' ) . '">' . __( 'Write a Review', 'simple-embed-code' ) . '</a>' ),
array( '<a href="' . esc_url( 'https://artiss.blog/donate' ) . '">' . __( 'Donate', 'simple-embed-code' ) . '</a>' ),
);
}
return $links;
}
add_filter( 'plugin_row_meta', 'sec_plugin_meta', 10, 2 );
/**
* Modify action links.
*
* Add links for the actions listed against this plugin.
*
* Internal code version: 1.1
*
* @param array $actions Current actions.
* @param string $plugin_file The plugin.
* @return array List of plugin actions.
*/
function sec_action_links( $actions, $plugin_file ) {
// Make sure we only perform actions for this specific plugin!
if ( CODE_EMBED_PLUGIN_BASE === $plugin_file ) {
// Add link to the settings page.
if ( current_user_can( 'manage_options' ) ) {
array_unshift( $actions, '<a href="' . admin_url( 'options-general.php?page=ce-options' ) . '">' . __( 'Settings', 'simple-embed-code' ) . '</a>' );
}
}
return $actions;
}
add_filter( 'plugin_action_links', 'sec_action_links', 10, 2 );
/**
* WordPress Requirements Check
*
* Deactivate the plugin if certain requirements are not met.
*
* Internal code version: 1.1
*/
function sec_requirements_check() {
$reason = '';
// Grab the plugin details.
$plugins = get_plugins();
$name = $plugins[ CODE_EMBED_PLUGIN_BASE ]['Name'];
// Check for a fork.
if ( function_exists( 'calmpress_version' ) || function_exists( 'classicpress_version' ) ) {
/* translators: 1: The plugin name. */
$reason .= '<li>' . sprintf( __( 'A fork of WordPress was detected. %1$s has not been tested on this fork and, as a consequence, the author will not provide any support.', 'simple-embed-code' ), $name ) . '</li>';
}
// If a requirement is not met, output the message and stop the plugin.
if ( '' !== $reason ) {
// Deactivate this plugin.
deactivate_plugins( CODE_EMBED_PLUGIN_BASE );
// Set up a message and output it via wp_die.
/* translators: 1: The plugin name. */
$message = '<p><strong>' . sprintf( __( '%1$s has been deactivated', 'simple-embed-code' ), $name ) . '</strong></p><p>' . __( 'Reason:', 'simple-embed-code' ) . '</p><ul>' . $reason . '</ul>';
$allowed = array(
'p' => array(),
'b' => array(),
'ul' => array(),
'li' => array(),
);
wp_die( wp_kses( $message, $allowed ), '', array( 'back_link' => true ) );
}
}
add_action( 'admin_init', 'sec_requirements_check' );