| 1 |
<?php |
| 2 |
defined('ABSPATH') or die('No direct access permitted'); |
| 3 |
|
| 4 |
$button = MB()->getClass("button"); //new maxButton(); |
| 5 |
$button_id = 0; |
| 6 |
|
| 7 |
if ($_POST) { |
| 8 |
if (! check_admin_referer("button-edit","maxbuttons_button")) |
| 9 |
{ |
| 10 |
exit("Request not valid"); |
| 11 |
} |
| 12 |
|
| 13 |
$button_id = intval($_POST["button_id"]); |
| 14 |
|
| 15 |
if ($button_id > 0) |
| 16 |
$button->set($button_id); |
| 17 |
$return = $button->save($_POST); |
| 18 |
if (is_int($return) && $button_id <= 0) |
| 19 |
$button_id = $return; |
| 20 |
|
| 21 |
if ($button_id === 0) |
| 22 |
{ |
| 23 |
error_log(__("Maxbuttons Error: Button id should never be zero","maxbuttons")); |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
$button->set($button_id); |
| 28 |
wp_redirect(admin_url('admin.php?page=maxbuttons-controller&action=button&id=' . $button_id)); |
| 29 |
exit(); |
| 30 |
} |
| 31 |
|
| 32 |
if (isset($_GET['id']) && $_GET['id'] != '') { |
| 33 |
$button = MB()->getClass('button'); // reset |
| 34 |
$button_id = intval($_GET["id"]); |
| 35 |
if ($button_id == 0) |
| 36 |
{ |
| 37 |
$error = __("Maxbuttons button id is zero. Your data is not saved correctly! Please check your database.","maxbuttons"); |
| 38 |
MB()->add_notice('error', $error); |
| 39 |
} |
| 40 |
// returns bool |
| 41 |
$return = $button->set($button_id); |
| 42 |
if ($return === false) |
| 43 |
{ |
| 44 |
$error = __("MaxButtons could not find this button in the database. It might not be possible to save this button! Please check your database or contact support! ", "maxbuttons"); |
| 45 |
MB()->add_notice('error', $error); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
$admin = MB()->getClass('admin'); |
| 51 |
$page_title = __("Button editor","maxbuttons"); |
| 52 |
$action = "<a class='page-title-action add-new-h2' href='" . admin_url() . "admin.php?page=maxbuttons-controller&action=edit'>" . __('Add New', 'maxbuttons') . "</a>"; |
| 53 |
$admin->get_header(array("title" => $page_title, "title_action" => $action) ); |
| 54 |
?> |
| 55 |
<form id="new-button-form" action="<?php echo admin_url('admin.php?page=maxbuttons-controller&action=button&noheader=true'); ?>" method="post"> |
| 56 |
<input type="hidden" name="button_id" value="<?php echo $button_id ?>"> |
| 57 |
<?php wp_nonce_field("button-edit","maxbuttons_button") ?> |
| 58 |
|
| 59 |
<div class="form-actions"> |
| 60 |
<a class="button-primary button button-save" href='javascript:void(0);'><?php _e('Save', 'maxbuttons') ?></a> |
| 61 |
<?php if ($button_id > 0): ?> |
| 62 |
<a id="button-copy" class="maxmodal button" data-modal='copy-button' href="javascript:void(0)"><?php _e('Copy', 'maxbuttons') ?></a> |
| 63 |
<a id="button-trash" class="button" href="<?php admin_url() ?>admin.php?page=maxbuttons-controller&action=trash&id=<?php echo $button_id ?>"><?php _e('Move to Trash', 'maxbuttons') ?></a> |
| 64 |
<a class="button maxmodal" href="javascript:void(0);" data-modal='delete-button'><?php _e("Delete","maxbuttons"); ?> </a> |
| 65 |
<?php endif; // button_id > 0 ?> |
| 66 |
|
| 67 |
<?php do_action('mb/editor/form-actions', $button); ?> |
| 68 |
</div> |
| 69 |
|
| 70 |
<div class="maxmodal-data" id="delete-button"> |
| 71 |
<span class='title'><?php _e("Removing button","maxbuttons"); ?></span> |
| 72 |
<span class="content"><p><?php _e("You are about to permanently remove this button. Are you sure?", "maxbuttons"); ?></p></span> |
| 73 |
<div class='controls'> |
| 74 |
<a href="<?php admin_url() ?>admin.php?page=maxbuttons-controller&action=delete&id=<?php echo $button_id ?>" class="button-primary big"><?php _e("Yes","maxbuttons"); ?></a> |
| 75 |
|
| 76 |
<a class="modal_close button-primary"><?php _e("No", "maxbuttons"); ?></a> |
| 77 |
|
| 78 |
</div> |
| 79 |
</div> |
| 80 |
|
| 81 |
<div class='maxmodal-data' id='copy-button'> |
| 82 |
<span class='title'><?php _e("Copy this button","maxbuttons"); ?></span> |
| 83 |
<span class="content"><p><?php _e("Do you want to copy this button to a new button?","maxbuttons"); ?></p> |
| 84 |
<p><?php _e('Did you know you can use shortcodes for text and links?', 'maxbuttons'); ?></p> |
| 85 |
|
| 86 |
<p class="example"> |
| 87 |
<strong><?php _e("Add the same button with different link","maxbuttons"); ?></strong><br> |
| 88 |
[maxbutton id="<?php echo $button_id ?>" url="http://yoururl"] |
| 89 |
</p> |
| 90 |
|
| 91 |
<p class="example"><strong><?php _e("Use the same button but change the text","maxbuttons"); ?> </strong><br /> |
| 92 |
[maxbutton id="<?php echo $button_id ?>" text="yourtext"] |
| 93 |
</p> |
| 94 |
|
| 95 |
</span> |
| 96 |
<span class="controls"><a class='button-primary modal_close' href="<?php admin_url() ?>admin.php?page=maxbuttons-controller&action=copy&id=<?php echo $button_id ?>"><?php _e('Copy', 'maxbuttons') ?></a> |
| 97 |
<a class='button modal_close'><?php _e("Cancel",'maxbuttons'); ?></a> |
| 98 |
</span> |
| 99 |
|
| 100 |
|
| 101 |
</div> |
| 102 |
|
| 103 |
<?php |
| 104 |
/** Display admin notices [deprecated] |
| 105 |
* @ignore |
| 106 |
*/ |
| 107 |
|
| 108 |
|
| 109 |
/** Display admin notices |
| 110 |
* |
| 111 |
* Hook to display admin notices on error and other occurences in the editor. Follows WP guidelines on format. |
| 112 |
* @since 4.20 |
| 113 |
*/ |
| 114 |
do_action("mb/editor/display_notices"); |
| 115 |
?> |
| 116 |
|
| 117 |
<?php if ($button_id > 0): ?> |
| 118 |
<div class="mb-message shortcode"> |
| 119 |
<?php $button_name = $button->getName(); |
| 120 |
|
| 121 |
?> |
| 122 |
<?php _e('To use this button, place the following shortcode anywhere you want it to appear in your site content:', 'maxbuttons') ?> |
| 123 |
<strong>[maxbutton id="<?php echo $button_id ?>"]</strong> |
| 124 |
<span class='shortcode-expand closed'><?php _e("See more examples","maxbuttons"); ?> |
| 125 |
<span class="dashicons-before dashicons-arrow-down"></span> |
| 126 |
</span> |
| 127 |
|
| 128 |
<div class="expanded"> |
| 129 |
<p class="example"> |
| 130 |
<strong><?php _e("Add a button by using the button name","maxbuttons"); ?></strong> |
| 131 |
[maxbutton name="<?php echo $button_name; ?>"] |
| 132 |
</p> |
| 133 |
<p class="example"> |
| 134 |
<strong><?php _e("Add the same button with different link","maxbuttons"); ?></strong> |
| 135 |
[maxbutton id="<?php echo $button_id ?>" url="http://yoururl"] |
| 136 |
</p> |
| 137 |
|
| 138 |
<p class="example"><strong><?php _e("Use the same button but change the text","maxbuttons"); ?> </strong> |
| 139 |
[maxbutton id="<?php echo $button_id ?>" text="yourtext"] |
| 140 |
</p> |
| 141 |
<p class="example"><strong><?php _e("All possible shortcode options","maxbuttons"); ?></strong> |
| 142 |
[maxbutton id="<?php echo $button_id ?>" text="yourtext" url="http://yoururl" window="new" nofollow="true"] |
| 143 |
</p> |
| 144 |
|
| 145 |
<h4><?php _e("Some tips","maxbuttons"); ?></h4> |
| 146 |
<p><?php _e("If you use this button on a static page, on multiple pages, or upload your theme to another WordPress installation choose an unique name and use ", |
| 147 |
"maxbuttons"); ?> <strong>[maxbutton name='my-buy-button' url='http://yoururl']</strong>. |
| 148 |
|
| 149 |
|
| 150 |
<?php _e("By using this syntax when you edit and save your button it will be changed everywhere it is used on your site. If you delete the button and create a new one with the same name the new button will be used on your site.","maxbuttons"); ?> |
| 151 |
</p> |
| 152 |
|
| 153 |
</div> |
| 154 |
</div> |
| 155 |
<?php endif; ?> |
| 156 |
|
| 157 |
<div class="output"> |
| 158 |
<div class="header"><?php _e('Preview', 'maxbuttons') ?> |
| 159 |
<span class='preview-toggle dashicons dashicons-arrow-up'> </span> |
| 160 |
</div> |
| 161 |
<div class="inner"> |
| 162 |
|
| 163 |
<p><?php _e('The top is the normal button, the bottom one is the hover.', 'maxbuttons') ?></p> |
| 164 |
<div class="result"> |
| 165 |
|
| 166 |
<?php $button->display(array("mode" => 'editor', "load_css" => "element")); ?> |
| 167 |
|
| 168 |
<p> </p> |
| 169 |
|
| 170 |
<?php $button->display(array("mode" => 'editor', "preview_part" => ":hover", "load_css" => "element")); ?> |
| 171 |
|
| 172 |
<?php $button->display_field_map(); ?> |
| 173 |
</div> |
| 174 |
|
| 175 |
<input type='hidden' id='colorpicker_current' value=''> |
| 176 |
|
| 177 |
<div class="input color preview nodrag"> |
| 178 |
<input type="text" name="button_preview" id="button_preview" class="color-field"> |
| 179 |
</div> |
| 180 |
|
| 181 |
<div class="note"><?php _e('Change this color to see your button on a different background.', 'maxbuttons') ?></div> |
| 182 |
<input type="hidden" id="button_preview" value='' /> |
| 183 |
<input style="display: none;" type="text" id="button_output" name="button_output" value="" /> |
| 184 |
|
| 185 |
<div class="clear"></div> |
| 186 |
</div> <!-- inner --> |
| 187 |
</div> <!-- output --> |
| 188 |
|
| 189 |
<?php #### STARTING FIELDS; |
| 190 |
|
| 191 |
|
| 192 |
$button->admin_fields(); |
| 193 |
|
| 194 |
?> |
| 195 |
|
| 196 |
<div class="form-actions"> |
| 197 |
<a href="#" class="button-primary button-save"><?php _e('Save', 'maxbuttons') ?></a> |
| 198 |
</div> |
| 199 |
</form> |
| 200 |
|
| 201 |
|
| 202 |
</div> |
| 203 |
<?php $admin->get_footer(); ?> |
| 204 |
|