| 1 |
<?php |
| 2 |
|
| 3 |
defined('ABSPATH') or die('Jog on!'); |
| 4 |
|
| 5 |
function sh_cd_pages_your_shortcodes_edit( $action = 'add', $save_result = NULL ) { |
| 6 |
|
| 7 |
if ( false === in_array( $action, [ 'add', 'edit', 'save' ] ) ) { |
| 8 |
return; |
| 9 |
} |
| 10 |
|
| 11 |
sh_cd_permission_check(); |
| 12 |
|
| 13 |
// Saving / Inserting a shortcode? |
| 14 |
if ( false === $save_result ) { |
| 15 |
sh_cd_message_display( __( 'There was an error saving your shortcode!' , SH_CD_SLUG ), ! $save_result ); |
| 16 |
} |
| 17 |
global $wpdb; |
| 18 |
|
| 19 |
// Load |
| 20 |
$shortcode = ( false === empty( $_GET['id'] ) ) ? |
| 21 |
sh_cd_db_shortcodes_by_id( (int) $_GET['id'] ) : |
| 22 |
sh_cd_get_values_from_post( [ 'id', 'slug', 'previous_slug', 'data', 'disabled', 'multisite' ] ); |
| 23 |
|
| 24 |
$shortcode['data'] = stripslashes( $shortcode['data'] ); |
| 25 |
|
| 26 |
?> |
| 27 |
|
| 28 |
<div class="wrap"> |
| 29 |
<div id="icon-options-general" class="icon32"></div> |
| 30 |
<div id="poststuff"> |
| 31 |
<div id="post-body" class="metabox-holder columns-3"> |
| 32 |
<div id="post-body-content"> |
| 33 |
<div class="meta-box-sortables ui-sortable"> |
| 34 |
<div class="postbox"> |
| 35 |
<div class="postbox-header"> |
| 36 |
<h2 class="hndle"><span><?php echo __( 'Add / Edit a shortcode', SH_CD_SLUG ); ?></span></h2> |
| 37 |
</div> |
| 38 |
<div style="padding: 0px 15px 0px 15px"> |
| 39 |
<?php |
| 40 |
|
| 41 |
if ( true === $save_result ) : |
| 42 |
|
| 43 |
printf('<p>%1$s. |
| 44 |
<a href="%2$s">%3$s</a>. |
| 45 |
</p>', |
| 46 |
__( 'Your shortcode has been saved successfully', SH_CD_SLUG ), |
| 47 |
sh_cd_link_your_shortcodes(), |
| 48 |
__( 'Return to all shortcodes', SH_CD_SLUG ) |
| 49 |
); |
| 50 |
|
| 51 |
else: |
| 52 |
?> |
| 53 |
<form method="post" action="<?php echo sh_cd_link_your_shortcodes() . '&action=save'; ?>"> |
| 54 |
<input type="hidden" id="id" name="id" value="<?php echo esc_attr( $shortcode['id'] ); ?>" /> |
| 55 |
|
| 56 |
<div class="sh-cd-button-row sh-cd-border-bottom"> |
| 57 |
<a class="comment-submit button" href="<?php echo sh_cd_link_your_shortcodes(); ?>"><?php echo __( 'Cancel', SH_CD_SLUG ); ?></a> |
| 58 |
<input name="submit_button" type="submit" value="Save Shortcode" class="comment-submit button button-primary"> |
| 59 |
</div> |
| 60 |
<h4><?php echo __( 'Slug', SH_CD_SLUG ); ?></h4> |
| 61 |
<p><small><?php echo __( 'Specify the unique identifier for this shortcode', SH_CD_SLUG ); ?>.</small></p> |
| 62 |
<input type="text" required class="regular-text" size="100" id="slug" name="slug" |
| 63 |
placeholder="Slug" |
| 64 |
value="<?php echo esc_attr( $shortcode['slug'] )?>" /> |
| 65 |
<?php |
| 66 |
|
| 67 |
$previous_slug = ( false === empty( $shortcode['previous_slug'] ) ) ? $shortcode['previous_slug'] : $shortcode['slug']; |
| 68 |
|
| 69 |
?> |
| 70 |
<input type="hidden" id="previous_slug" name="previous_slug" value="<?php echo esc_attr( $previous_slug )?>" /> |
| 71 |
|
| 72 |
<h4><?php echo __( 'Shortcode Content', SH_CD_SLUG ); ?></h4> |
| 73 |
<p><small><?php echo __( 'Specify the text, HTML, media, data, etc that should be rendered wherever the shortcode is placed.', SH_CD_SLUG ); ?></small></p> |
| 74 |
<?php wp_editor( $shortcode['data'], 'data', [ 'textarea_name' => 'data' ] ); ?> |
| 75 |
|
| 76 |
<h4><?php echo __( 'Disable?', SH_CD_SLUG ); ?></h4> |
| 77 |
<p><?php echo __( 'If disabled, nothing will be rendered where the shortcode has been placed.', SH_CD_SLUG ); ?></p> |
| 78 |
<select id="disabled" name="disabled"> |
| 79 |
<option value="0" <?php selected( $shortcode['disabled'], 0 ); ?>><?php echo __( 'No', SH_CD_SLUG ); ?></option> |
| 80 |
<option value="1" <?php selected( $shortcode['disabled'], 1 ); ?>><?php echo __( 'Yes', SH_CD_SLUG ); ?></option> |
| 81 |
</select> |
| 82 |
|
| 83 |
<h4><?php echo __( 'Global?', SH_CD_SLUG ); ?></h4> |
| 84 |
|
| 85 |
<p><?php echo __( 'Can this be used by all sites within your multi-site? If Yes, your shortcode will be promoted so it can be used across your entire multi site. Please note, shortcode slugs are not unique across a multi site. Therefore, if you have two Global shortcodes with the same slug, the shortcode created or updated most recently shall be the one rendered. It is best practice to give all Global shortcodes a unique slug. A Global shortcode with always be displayed before a local shortcode with the same slug. Upon saving, it may take a Global shortcode upto 30 seconds to update across all your sites.', SH_CD_SLUG ); ?></p> |
| 86 |
<select id="multisite" name="multisite" <?php if ( false === SH_CD_IS_PREMIUM ) { echo 'disabled="disabled"'; } ?>> |
| 87 |
<option value="0" <?php selected( $shortcode['multisite'], 0 ); ?>><?php echo __( 'No', SH_CD_SLUG ); ?></option> |
| 88 |
<option value="1" <?php selected( $shortcode['multisite'], 1 ); ?>><?php echo __( 'Yes', SH_CD_SLUG ); ?></option> |
| 89 |
</select> |
| 90 |
<?php if ( false === SH_CD_IS_PREMIUM ) : ?> |
| 91 |
<p> |
| 92 |
<i class="far fa-credit-card"></i> |
| 93 |
<a href="<?php echo sh_cd_license_upgrade_link(); ?>"> |
| 94 |
<?php echo __( 'Multi site support is for Premium users. Upgrade now.', SH_CD_SLUG ); ?> |
| 95 |
</a> |
| 96 |
</p> |
| 97 |
<?php endif; ?> |
| 98 |
|
| 99 |
<div class="sh-cd-button-row sh-cd-border-top"> |
| 100 |
<a class="comment-submit button" href="<?php echo sh_cd_link_your_shortcodes(); ?>"><?php echo __( 'Cancel', SH_CD_SLUG ); ?></a> |
| 101 |
<input name="submit_button" type="submit" value="Save Shortcode" class="comment-submit button button-primary"> |
| 102 |
</div> |
| 103 |
</form> |
| 104 |
<?php endif; ?> |
| 105 |
</div> |
| 106 |
</div> |
| 107 |
</div> |
| 108 |
</div> |
| 109 |
</div> |
| 110 |
<br class="clear"> |
| 111 |
</div> |
| 112 |
</div> |
| 113 |
<?php |
| 114 |
} |
| 115 |
|
| 116 |
|