| 1 |
<?php |
| 2 |
|
| 3 |
namespace Photonic_Plugin\Admin; |
| 4 |
|
| 5 |
if (!defined('ABSPATH')) { |
| 6 |
echo '<h1>WordPress not loaded!</h1>'; |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
if (!current_user_can('edit_posts')) { |
| 11 |
wp_die(esc_html__('You are not authorized to use this capability.', 'photonic')); |
| 12 |
} |
| 13 |
|
| 14 |
require_once 'Admin_Page.php'; |
| 15 |
|
| 16 |
class Shortcode_Replace extends Admin_Page { |
| 17 |
private static ?Shortcode_Replace $instance = null; |
| 18 |
|
| 19 |
public static function get_instance(): Shortcode_Replace { |
| 20 |
if (null === self::$instance) { |
| 21 |
self::$instance = new Shortcode_Replace(); |
| 22 |
} |
| 23 |
return self::$instance; |
| 24 |
} |
| 25 |
|
| 26 |
public function render_content() { |
| 27 |
?> |
| 28 |
<form method="post" id="photonic-helper-form" name="photonic-helper-form"> |
| 29 |
<div class="photonic-form-body fix"> |
| 30 |
<h2 class="photonic-section">What is the <code>gallery</code> shortcode?</h2> |
| 31 |
<p> |
| 32 |
The <code>gallery</code> shortcode is the backbone of creating galleries in WordPress. By default |
| 33 |
Photonic |
| 34 |
uses this and adds on a bunch of goodies to it. If you happen to deactivate Photonic, you wouldn't |
| 35 |
be dealing with |
| 36 |
a mess of shortcodes, since the <code>gallery</code> shortcode fails gracefully and without any ugly |
| 37 |
errors. |
| 38 |
</p> |
| 39 |
|
| 40 |
<h2 class="photonic-section">So why might you want to replace it?</h2> |
| 41 |
<p> |
| 42 |
Let's say you have an established website and have made heavy use of Photonic galleries. Then, one |
| 43 |
fine day, |
| 44 |
you change themes or add some plugin, which also uses the <code>gallery</code> shortcode. You now |
| 45 |
have a conflict! |
| 46 |
This page gives you a very easy way to work around this conflict. |
| 47 |
</p> |
| 48 |
<p> |
| 49 |
In addition, this method also lets you separate your shortcodes, so that in case you decide to |
| 50 |
switch over the shortcodes |
| 51 |
to Gutenberg blocks, you would only be targeting Photonic's shortcodes instead of others. |
| 52 |
</p> |
| 53 |
|
| 54 |
<h2 class="photonic-section">Alright, let's do it!</h2> |
| 55 |
<?php |
| 56 |
global $photonic_alternative_shortcode; |
| 57 |
if (empty($photonic_alternative_shortcode)) { |
| 58 |
?> |
| 59 |
<p> |
| 60 |
You have not defined a shortcode to which you can convert. Please do so from <em>Photonic → |
| 61 |
Settings → |
| 62 |
Generic Options → Generic settings → Custom Shortcode</em>. |
| 63 |
</p> |
| 64 |
<?php |
| 65 |
} |
| 66 |
elseif ('gallery' === trim($photonic_alternative_shortcode)) { |
| 67 |
?> |
| 68 |
<p> |
| 69 |
Please use something other than <code>gallery</code> as your custom shortcode. Using <code>photonic</code> |
| 70 |
is probably a good idea. |
| 71 |
</p> |
| 72 |
<?php |
| 73 |
} |
| 74 |
else { |
| 75 |
?> |
| 76 |
<p> |
| 77 |
You have your custom shortcode set up as |
| 78 |
<code><?php echo esc_html($photonic_alternative_shortcode); ?></code>. |
| 79 |
</p> |
| 80 |
|
| 81 |
<div id="photonic-shortcode-results"> |
| 82 |
<?php |
| 83 |
require_once 'Shortcode_Usage.php'; |
| 84 |
$usage = new Shortcode_Usage(); |
| 85 |
echo sprintf( |
| 86 |
esc_html__('%2$sThe following instances were found on your site for Photonic with the %4$s%1$s%5$s shortcode. %6$sPlease verify the instances below before replacing the shortcodes. It is strongly recommended to back up the posts listed below before the shortcode replacement.%7$s%3$s', 'photonic'), |
| 87 |
esc_attr($usage->tag), |
| 88 |
'<p>', |
| 89 |
'</p>', |
| 90 |
'<code>', |
| 91 |
'</code>', |
| 92 |
'<strong>', |
| 93 |
'</strong>' |
| 94 |
); |
| 95 |
$usage->prepare_items(); |
| 96 |
$usage->display(); |
| 97 |
?> |
| 98 |
|
| 99 |
</div> |
| 100 |
<?php |
| 101 |
} |
| 102 |
|
| 103 |
$user = get_current_user_id(); |
| 104 |
if (0 === $user) { |
| 105 |
$user = wp_rand(1); |
| 106 |
} |
| 107 |
wp_nonce_field('photonic-replace-shortcode-' . $user, '_photonic_replacement_nonce'); |
| 108 |
?> |
| 109 |
</div> |
| 110 |
</form> |
| 111 |
<?php |
| 112 |
} |
| 113 |
} |
| 114 |
|