| 1 |
<?php |
| 2 |
|
| 3 |
defined('ABSPATH') or die('Jog on!'); |
| 4 |
|
| 5 |
function sh_cd_pages_your_shortcodes_edit( $action = 'add' ) { |
| 6 |
|
| 7 |
if ( false === in_array( $action, [ 'add', 'edit', 'save' ] ) ) { |
| 8 |
return; |
| 9 |
} |
| 10 |
|
| 11 |
if ( false === current_user_can( 'manage_options' ) ) { |
| 12 |
wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); |
| 13 |
} |
| 14 |
|
| 15 |
// Saving / Inserting a shortcode? |
| 16 |
if ( $action == 'save' ) { |
| 17 |
|
| 18 |
$save_result = sh_cd_shortcodes_save_post(); |
| 19 |
|
| 20 |
$message = ( true === $save_result ) ? 'Your shortcode has been saved!' : 'There was an error saving your shortcode!'; |
| 21 |
|
| 22 |
sh_cd_message_display( $message, ! $save_result ); |
| 23 |
} |
| 24 |
|
| 25 |
// Load |
| 26 |
$shortcode = ( false === empty( $_GET['id'] ) ) ? |
| 27 |
sh_cd_db_shortcodes_by_id( (int) $_GET['id'] ) : |
| 28 |
sh_cd_get_values_from_post( [ 'id', 'slug', 'previous_slug', 'data', 'disabled' ] ); |
| 29 |
|
| 30 |
$shortcode['data'] = stripslashes( $shortcode['data'] ); |
| 31 |
|
| 32 |
?> |
| 33 |
|
| 34 |
<div class="wrap"> |
| 35 |
<div id="icon-options-general" class="icon32"></div> |
| 36 |
<div id="poststuff"> |
| 37 |
<div id="post-body" class="metabox-holder columns-3"> |
| 38 |
<div id="post-body-content"> |
| 39 |
<div class="meta-box-sortables ui-sortable"> |
| 40 |
<div class="postbox"> |
| 41 |
<h3 class="hndle"><span>Add / Edit a shortcode</span></h3> |
| 42 |
<div style="padding: 0px 15px 0px 15px"> |
| 43 |
<?php |
| 44 |
|
| 45 |
if ( true === $save_result ) : |
| 46 |
|
| 47 |
printf('<p>Your shortcode has been saved successfully. <a href="%s">Return to all shortcodes</a>.', |
| 48 |
sh_cd_link_your_shortcodes() ); |
| 49 |
|
| 50 |
else: |
| 51 |
?> |
| 52 |
<form method="post" action="<?php echo sh_cd_link_your_shortcodes() . '&action=save'; ?>"> |
| 53 |
<input type="hidden" id="id" name="id" value="<?php echo esc_attr( $shortcode['id'] ); ?>" /> |
| 54 |
<h4>Slug</h4> |
| 55 |
<p><small>Specify the unique identifier for this shortcode.</small></p> |
| 56 |
<input type="text" required class="regular-text" size="100" id="slug" name="slug" |
| 57 |
placeholder="Slug" |
| 58 |
value="<?php echo esc_attr( $shortcode['slug'] )?>" /> |
| 59 |
<?php |
| 60 |
|
| 61 |
$previous_slug = ( false === empty( $shortcode['previous_slug'] ) ) ? $shortcode['previous_slug'] : $shortcode['slug']; |
| 62 |
|
| 63 |
?> |
| 64 |
<input type="hidden" id="previous_slug" name="previous_slug" value="<?php echo esc_attr( $previous_slug )?>" /> |
| 65 |
<?php if ('edit' == $action): ?> |
| 66 |
<p><small>Note: You can not edit a slug name. Editing a slug name may cause issues throughout your site. Please delete this shortcode and create another.</small></p> |
| 67 |
<?php endif; ?> |
| 68 |
<h4>Shortcode content</h4> |
| 69 |
<p><small>Specify the text, HTML, media, data, etc that should be rendered wherever the shortcode is placed.</small></p> |
| 70 |
<?php wp_editor( $shortcode['data'], 'data', [ 'textarea_name' => 'data' ] ); ?> |
| 71 |
<h4>Disable?</h4> |
| 72 |
<p>If disabled, nothing will be rendered where the shortcode has been placed.</p> |
| 73 |
<select id="disabled" name="disabled"> |
| 74 |
<option value="0" <?php selected( $shortcode['disabled'], 0 ); ?>>No</option> |
| 75 |
<option value="1" <?php selected( $shortcode['disabled'], 1 ); ?>>Yes</option> |
| 76 |
</select> |
| 77 |
<div class="sh-cd-button-row"> |
| 78 |
<a class="comment-submit button" href="<?php echo sh_cd_link_your_shortcodes(); ?>">Cancel</a> |
| 79 |
<input name="submit_button" type="submit" value="Save Shortcode" class="comment-submit button button-primary"> |
| 80 |
</div> |
| 81 |
</form> |
| 82 |
<?php endif; ?> |
| 83 |
</div> |
| 84 |
</div> |
| 85 |
</div> |
| 86 |
</div> |
| 87 |
</div> |
| 88 |
<br class="clear"> |
| 89 |
</div> |
| 90 |
</div> |
| 91 |
<?php |
| 92 |
} |
| 93 |
|
| 94 |
|