| 1 |
<?php |
| 2 |
/** |
| 3 |
* HTML for displaying notices for the manage table. |
| 4 |
* |
| 5 |
* @package Code_Snippets |
| 6 |
* @subpackage Views |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace Code_Snippets; |
| 10 |
|
| 11 |
/** |
| 12 |
* Loaded from the manage menu. |
| 13 |
* |
| 14 |
* @var Manage_Menu $this |
| 15 |
*/ |
| 16 |
|
| 17 |
/** |
| 18 |
* Constant existence is checked with defined(). |
| 19 |
* |
| 20 |
* @noinspection PhpUndefinedConstantInspection |
| 21 |
*/ |
| 22 |
if ( defined( 'CODE_SNIPPETS_SAFE_MODE' ) && CODE_SNIPPETS_SAFE_MODE ) { |
| 23 |
?> |
| 24 |
<div id="message" class="notice notice-error fade is-dismissible"> |
| 25 |
<p> |
| 26 |
<strong><?php esc_html_e( 'Warning:', 'code-snippets' ); ?></strong> |
| 27 |
<?php |
| 28 |
// translators: 1: constant name, 2: file name. |
| 29 |
$text = __( 'Safe mode is active and snippets will not execute! Remove the %1$s constant from %2$s file to turn off safe mode.', 'code-snippets' ); |
| 30 |
printf( esc_html( $text ), '<code>CODE_SNIPPETS_SAFE_MODE</code>', '<code>wp-config.php</code>' ); |
| 31 |
?> |
| 32 |
|
| 33 |
<a href="https://codesnippets.pro/doc/safe-mode/" target="_blank"> |
| 34 |
<?php esc_html_e( 'Help', 'code-snippets' ); ?> |
| 35 |
</a> |
| 36 |
</p> |
| 37 |
</div> |
| 38 |
<?php |
| 39 |
} |
| 40 |
|
| 41 |
if ( empty( $_REQUEST['result'] ) ) { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
$result = sanitize_key( $_REQUEST['result'] ); |
| 46 |
|
| 47 |
$result_messages = [ |
| 48 |
'executed' => __( 'Snippet <strong>executed</strong>.', 'code-snippets' ), |
| 49 |
'activated' => __( 'Snippet <strong>activated</strong>.', 'code-snippets' ), |
| 50 |
'activated-multi' => __( 'Selected snippets <strong>activated</strong>.', 'code-snippets' ), |
| 51 |
'deactivated' => __( 'Snippet <strong>deactivated</strong>.', 'code-snippets' ), |
| 52 |
'deactivated-multi' => __( 'Selected snippets <strong>deactivated</strong>.', 'code-snippets' ), |
| 53 |
'deleted' => __( 'Snippet <strong>trashed</strong>.', 'code-snippets' ), |
| 54 |
'deleted-multi' => __( 'Selected snippets <strong>trashed</strong>.', 'code-snippets' ), |
| 55 |
'deleted_permanently' => __( 'Snippet <strong>permanently deleted</strong>.', 'code-snippets' ), |
| 56 |
'deleted-permanently-multi' => __( 'Selected snippets <strong>permanently deleted</strong>.', 'code-snippets' ), |
| 57 |
'restored' => __( 'Snippet <strong>restored</strong>.', 'code-snippets' ), |
| 58 |
'restored-multi' => __( 'Selected snippets <strong>restored</strong>.', 'code-snippets' ), |
| 59 |
'cloned' => __( 'Snippet <strong>cloned</strong>.', 'code-snippets' ), |
| 60 |
'cloned-multi' => __( 'Selected snippets <strong>cloned</strong>.', 'code-snippets' ), |
| 61 |
'cloud-refreshed' => __( 'Synced cloud data has been <strong>successfully</strong> refreshed.', 'code-snippets' ), |
| 62 |
]; |
| 63 |
|
| 64 |
// Add undo link for single snippet trash action |
| 65 |
if ( 'deleted' === $result && ! empty( $_REQUEST['ids'] ) ) { |
| 66 |
$deleted_ids = sanitize_text_field( $_REQUEST['ids'] ); |
| 67 |
$undo_url = wp_nonce_url( |
| 68 |
add_query_arg( |
| 69 |
[ |
| 70 |
'action' => 'restore', |
| 71 |
'ids' => $deleted_ids, |
| 72 |
] |
| 73 |
), |
| 74 |
'bulk-snippets' |
| 75 |
); |
| 76 |
|
| 77 |
// translators: %s: Undo URL. |
| 78 |
$undo_message = __( 'Snippet <strong>trashed</strong>. <a href="%s">Undo</a>', 'code-snippets' ); |
| 79 |
$result_messages['deleted'] = sprintf( $undo_message, esc_url( $undo_url ) ); |
| 80 |
} |
| 81 |
|
| 82 |
// Add undo link for bulk snippet trash action |
| 83 |
if ( 'deleted-multi' === $result && ! empty( $_REQUEST['ids'] ) ) { |
| 84 |
$deleted_ids = sanitize_text_field( $_REQUEST['ids'] ); |
| 85 |
$undo_url = wp_nonce_url( |
| 86 |
add_query_arg( array( |
| 87 |
'action' => 'restore', |
| 88 |
'ids' => $deleted_ids, |
| 89 |
) ), |
| 90 |
'bulk-snippets' |
| 91 |
); |
| 92 |
|
| 93 |
// translators: %s: Undo URL. |
| 94 |
$undo_message = __( 'Selected snippets <strong>trashed</strong>. <a href="%s">Undo</a>', 'code-snippets' ); |
| 95 |
$result_messages['deleted-multi'] = sprintf( $undo_message, esc_url( $undo_url ) ); |
| 96 |
} |
| 97 |
|
| 98 |
$result_messages = apply_filters( 'code_snippets/manage/result_messages', $result_messages ); |
| 99 |
|
| 100 |
if ( isset( $result_messages[ $result ] ) ) { |
| 101 |
$result_kses = [ |
| 102 |
'strong' => [], |
| 103 |
'a' => [ |
| 104 |
'href' => [], |
| 105 |
], |
| 106 |
]; |
| 107 |
|
| 108 |
printf( |
| 109 |
'<div id="message" class="notice notice-success fade is-dismissible"><p>%s</p></div>', |
| 110 |
wp_kses( $result_messages[ $result ], $result_kses ) |
| 111 |
); |
| 112 |
} |
| 113 |
|