| 1 |
<?php |
| 2 |
namespace MaxButtons; |
| 3 |
defined('ABSPATH') or die('No direct access permitted'); |
| 4 |
|
| 5 |
class mbCake |
| 6 |
{ |
| 7 |
|
| 8 |
public static function init() |
| 9 |
{ |
| 10 |
add_action('register_shortcode_ui', array(maxUtils::namespaceit('mbCake'), 'register')); |
| 11 |
add_action('init', array(maxUtils::namespaceit('mbCake'), 'initField')); |
| 12 |
add_action('shortcode_ui_after_do_shortcode', array(maxUtils::namespaceit('mbCake'), 'shortcode')); |
| 13 |
|
| 14 |
// Load FA within TinyMCE |
| 15 |
// add_action('admin_enqueue_scripts', array(maxUtils::namespaceit('mbCake'), 'editor_styles')) ; |
| 16 |
|
| 17 |
} |
| 18 |
|
| 19 |
public static function initField() |
| 20 |
{ |
| 21 |
require_once('class-field-maxbutton.php'); |
| 22 |
|
| 23 |
Shortcake_Field_MaxButton::get_instance(); |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
public static function shortcode($shortcode) |
| 28 |
{ |
| 29 |
|
| 30 |
if (strpos ($shortcode, 'maxbutton') === false) |
| 31 |
return; // not our shorts |
| 32 |
|
| 33 |
|
| 34 |
// style controls the output - if set to something else assume css is there. |
| 35 |
if (strpos ( $shortcode, 'style') === false) |
| 36 |
{ |
| 37 |
preg_match('/id=?("|\'|)([0-9]+)/i', $shortcode, $match); |
| 38 |
if (count($match) == 0) |
| 39 |
return; // happens when adding new button from shortcake |
| 40 |
|
| 41 |
$button_id = $match[2]; |
| 42 |
|
| 43 |
$button = MB()->getClass('button'); |
| 44 |
$button->set($button_id); |
| 45 |
|
| 46 |
$button->parse_button(); |
| 47 |
$button->parse_css('preview'); |
| 48 |
$button->display_css(); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
public static function register() |
| 54 |
{ |
| 55 |
|
| 56 |
shortcode_ui_register_for_shortcode( 'maxbutton', |
| 57 |
array( |
| 58 |
/* |
| 59 |
* How the shortcode should be labeled in the UI. Required argument. |
| 60 |
*/ |
| 61 |
'label' => esc_html__( 'MaxButtons', 'maxbuttons' ), |
| 62 |
/* |
| 63 |
* Include an icon with your shortcode. Optional. |
| 64 |
* Use a dashicon, or full URL to image. |
| 65 |
*/ |
| 66 |
'listItemImage' => '<img src="' . MB()->get_plugin_url() . 'assets/integrations/shortcake/assets/banner.png">', |
| 67 |
//'dashicons-editor-quote', |
| 68 |
/* |
| 69 |
* Limit this shortcode UI to specific posts. Optional. |
| 70 |
*/ |
| 71 |
//'post_type' => array( 'post' ), |
| 72 |
|
| 73 |
/* |
| 74 |
* Register UI for the "inner content" of the shortcode. Optional. |
| 75 |
* If no UI is registered for the inner content, then any inner content |
| 76 |
* data present will be backed up during editing. |
| 77 |
*/ |
| 78 |
/* |
| 79 |
* Register UI for attributes of the shortcode. Optional. |
| 80 |
* |
| 81 |
* If no UI is registered for an attribute, then the attribute will |
| 82 |
* not be editable through Shortcake's UI. However, the value of any |
| 83 |
* unregistered attributes will be preserved when editing. |
| 84 |
* |
| 85 |
* Each array must include 'attr', 'type', and 'label'. |
| 86 |
* 'attr' should be the name of the attribute. |
| 87 |
* 'type' options include: text, checkbox, textarea, radio, select, email, |
| 88 |
* url, number, and date, post_select, attachment, color. |
| 89 |
* Use 'meta' to add arbitrary attributes to the HTML of the field. |
| 90 |
* Use 'encode' to encode attribute data. Requires customization to callback to decode. |
| 91 |
* Depending on 'type', additional arguments may be available. |
| 92 |
*/ |
| 93 |
'attrs' => array( |
| 94 |
|
| 95 |
array( |
| 96 |
'label' => esc_html__( 'Button', 'maxbuttons' ), |
| 97 |
'attr' => 'id', |
| 98 |
'type' => 'MaxButton', |
| 99 |
'nonce' => wp_create_nonce('maxajax'), |
| 100 |
'meta' => array('select' => __("Select a button","maxbuttons")), |
| 101 |
|
| 102 |
), |
| 103 |
array( |
| 104 |
'label' => esc_html__( 'Custom URL [optional]', 'maxbuttons' ), |
| 105 |
'attr' => 'url', |
| 106 |
'type' => 'url', |
| 107 |
'encode' => true, |
| 108 |
'meta' => array( |
| 109 |
'placeholder' => esc_html__( 'http://', '' ), |
| 110 |
'data-test' => 1, |
| 111 |
), |
| 112 |
), |
| 113 |
array( |
| 114 |
'label' => esc_html__( 'Custom Text [optional]', 'maxbuttons' ), |
| 115 |
'attr' => 'text', |
| 116 |
'type' => 'text', |
| 117 |
'query' => array( 'post_type' => 'page' ), |
| 118 |
|
| 119 |
), |
| 120 |
), |
| 121 |
) |
| 122 |
); |
| 123 |
|
| 124 |
|
| 125 |
} |
| 126 |
|
| 127 |
} |
| 128 |
|
| 129 |
mbCake::init(); |
| 130 |
|