| 1 |
<?php |
| 2 |
/** |
| 3 |
* Shared Functions |
| 4 |
* |
| 5 |
* A group of functions shared across my plugins, for consistency. |
| 6 |
* |
| 7 |
* @package simple-embed-code |
| 8 |
*/ |
| 9 |
|
| 10 |
// Exit if accessed directly. |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Add meta to plugin details |
| 18 |
* |
| 19 |
* Add options to plugin meta line |
| 20 |
* |
| 21 |
* @version 1.1 |
| 22 |
* @param string $links Current links. |
| 23 |
* @param string $file File in use. |
| 24 |
* @return string Links, now with settings added. |
| 25 |
*/ |
| 26 |
function sec_plugin_meta( $links, $file ) { |
| 27 |
|
| 28 |
if ( false !== strpos( $file, 'simple-code-embed.php' ) ) { |
| 29 |
|
| 30 |
$links = array_merge( |
| 31 |
$links, |
| 32 |
array( '<a href="https://github.com/dartiss/code-embed">' . __( 'Github', 'simple-embed-code' ) . '</a>' ), |
| 33 |
array( '<a href="https://wordpress.org/support/plugin/simple-embed-code">' . __( 'Support', 'simple-embed-code' ) . '</a>' ), |
| 34 |
array( '<a href="https://artiss.blog/donate">' . __( 'Donate', 'simple-embed-code' ) . '</a>' ), |
| 35 |
array( '<a href="https://wordpress.org/support/plugin/simple-embed-code/reviews/?filter=5" title="' . __( 'Rate the plugin on WordPress.org', 'simple-embed-code' ) . '" style="color: #ffb900">' . str_repeat( '<span class="dashicons dashicons-star-filled" style="font-size: 16px; width:16px; height: 16px"></span>', 5 ) . '</a>' ), |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
return $links; |
| 40 |
} |
| 41 |
|
| 42 |
add_filter( 'plugin_row_meta', 'sec_plugin_meta', 10, 2 ); |
| 43 |
|
| 44 |
/** |
| 45 |
* Modify actions links. |
| 46 |
* |
| 47 |
* Add or remove links for the actions listed against this plugin |
| 48 |
* |
| 49 |
* @version 1.1 |
| 50 |
* @param string $actions Current actions. |
| 51 |
* @param string $plugin_file The plugin. |
| 52 |
* @return string Actions, now with deactivation removed! |
| 53 |
*/ |
| 54 |
function sec_action_links( $actions, $plugin_file ) { |
| 55 |
|
| 56 |
// Make sure we only perform actions for this specific plugin! |
| 57 |
if ( strpos( $plugin_file, 'simple-code-embed.php' ) !== false ) { |
| 58 |
|
| 59 |
// Add link to the settings page. |
| 60 |
if ( current_user_can( 'manage_options' ) ) { |
| 61 |
array_unshift( $actions, '<a href="admin.php?page=ce-options">' . __( 'Settings', 'simple-embed-code' ) . '</a>' ); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
return $actions; |
| 66 |
} |
| 67 |
|
| 68 |
add_filter( 'plugin_action_links', 'sec_action_links', 10, 2 ); |
| 69 |
|
| 70 |
/** |
| 71 |
* WordPress Requirements Check |
| 72 |
* |
| 73 |
* Deactivate the plugin if certain requirements are not met. |
| 74 |
* |
| 75 |
* @version 1.1 |
| 76 |
*/ |
| 77 |
function sec_requirements_check() { |
| 78 |
|
| 79 |
$reason = ''; |
| 80 |
|
| 81 |
// Grab the plugin details. |
| 82 |
|
| 83 |
$plugins = get_plugins(); |
| 84 |
$name = $plugins[ CODE_EMBED_PLUGIN_BASE ]['Name']; |
| 85 |
|
| 86 |
// Check for a fork. |
| 87 |
|
| 88 |
if ( function_exists( 'calmpress_version' ) || function_exists( 'classicpress_version' ) ) { |
| 89 |
|
| 90 |
/* translators: 1: The plugin name. */ |
| 91 |
$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>'; |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
// If a requirement is not met, output the message and stop the plugin. |
| 96 |
|
| 97 |
if ( '' !== $reason ) { |
| 98 |
|
| 99 |
// Deactivate this plugin. |
| 100 |
|
| 101 |
deactivate_plugins( PLUGIN_NAME_PLUGIN_BASE ); |
| 102 |
|
| 103 |
// Set up a message and output it via wp_die. |
| 104 |
|
| 105 |
/* translators: 1: The plugin name. */ |
| 106 |
$message = '<p><b>' . sprintf( __( '%1$s has been deactivated', 'simple-embed-code' ), $name ) . '</b></p><p>' . __( 'Reason:', 'simple-embed-code' ) . '</p><ul>' . $reason . '</ul>'; |
| 107 |
|
| 108 |
$allowed = array( |
| 109 |
'p' => array(), |
| 110 |
'b' => array(), |
| 111 |
'ul' => array(), |
| 112 |
'li' => array(), |
| 113 |
); |
| 114 |
|
| 115 |
wp_die( wp_kses( $message, $allowed ), '', array( 'back_link' => true ) ); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
add_action( 'admin_init', 'sec_requirements_check' ); |
| 120 |
|