PluginProbe
MaxButtons – Create buttons / 7.13.2
MaxButtons – Create buttons v7.13.2
6.23 6.24 6.25 6.26 6.26.1 6.27 6.28 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.1.1 7.1.2 7.1.3 7.10 7.11 7.13 7.13.1 7.13.2 7.13.3 All 100 releases
maxbuttons / assets / integrations / shortcake / class-field-maxbutton.php

class-field-maxbutton.php in MaxButtons – Create buttons 7.13.2, at assets/integrations/shortcake/class-field-maxbutton.php

137 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace MaxButtons;
3 defined('ABSPATH') or die('No direct access permitted');
4 // Maxbutton field class
5
6 class Shortcake_Field_MaxButton
7 {
8
9 /**
10 * Shortcake Color Field controller instance.
11 *
12 * @access private
13 * @var object
14 */
15 private static $instance;
16
17 /**
18 * All registered post fields.
19 *
20 * @access private
21 * @var array
22 */
23 private $post_fields = array();
24
25 /**
26 * Settings for the Color Field.
27 *
28 * @access private
29 * @var array
30 */
31 private $fields = array(
32 'MaxButton' => array(
33 'template' => 'fusion-shortcake-field-maxbutton',
34 'view' => 'editAttributeFieldMaxButton',
35 ),
36 );
37
38 /**
39 * Get instance of Shortcake Color Field controller.
40 *
41 * Instantiates object on the fly when not already loaded.
42 *
43 * @return object
44 */
45 public static function get_instance() {
46 if ( ! isset( self::$instance ) ) {
47 self::$instance = new self;
48 self::$instance->setup_actions();
49 }
50 return self::$instance;
51 }
52
53 /**
54 * Set up actions needed for Color Field
55 */
56 private function setup_actions() {
57 add_filter( 'shortcode_ui_fields', array( $this, 'filter_shortcode_ui_fields' ) );
58 add_action( 'shortcode_ui_loaded_editor', array( $this, 'load_template' ) );
59 add_action( 'enqueue_shortcode_ui', array( $this, 'action_enqueue_shortcode_maxbutton' ), 99 );
60
61 }
62
63 /**
64 * Whether or not the color attribute is present in registered shortcode UI
65 *
66 * @return bool
67 */
68 private function maxbutton_attribute_present() {
69
70 foreach ( \Shortcode_UI::get_instance()->get_shortcodes() as $shortcode ) {
71
72 if ( empty( $shortcode['attrs'] ) ) {
73 continue;
74 }
75
76 foreach ( $shortcode['attrs'] as $attribute ) {
77 if ( empty( $attribute['type'] ) ) {
78 continue;
79 }
80
81 if ( 'MaxButton' === $attribute['type'] ) {
82 return true;
83 }
84 }
85 }
86
87 return false;
88 }
89
90 /**
91 * Add Color Field settings to Shortcake fields
92 *
93 * @param array $fields
94 * @return array
95 */
96 public function filter_shortcode_ui_fields( $fields ) {
97 return array_merge( $fields, $this->fields );
98 }
99
100 /**
101 * Output templates used by the color field.
102 */
103 public function load_template() {
104
105 if ( ! $this->maxbutton_attribute_present() ) {
106 return;
107 }
108
109 ?>
110
111 <script type="text/html" id="tmpl-fusion-shortcake-field-maxbutton">
112 <div class="field-block shortcode-ui-field-maxbutton shortcode-ui-attribute-{{ data.attr }}">
113 <button class="button-primary maxbutton_media_button" type="button" data-nonce="{{ data.nonce }}" name="{{ data.attr }}" value="{{ data.value }}">{{data.meta.select}}</button>
114 <p class='button_preview'>&nbsp;</p>
115
116
117 <input id='{{ data.attr }}' type='hidden' name='button_id' value='' >
118 <# if ( typeof data.description == 'string' ) { #>
119 <p class="description">{{{ data.description }}}</p>
120 <# } #>
121 </div>
122 </script>
123
124 <?php
125 }
126
127 public function action_enqueue_shortcode_maxbutton()
128 {
129
130 wp_enqueue_script('maxbutton-shortcake', MB()->get_plugin_url() . 'assets/integrations/shortcake/edit-attribute-field-maxbutton.js',
131 array('jquery','backbone','mce-view', 'shortcode-ui-js-hooks','shortcode-ui'), null, true);
132 //wp_localize_script( 'maxbutton-shortcake', 'shortcodeUIFieldData', $this->fields );
133
134 }
135
136 } // class
137