PluginProbe
MaxButtons – Create buttons / 6.7
MaxButtons – Create buttons v6.7
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 6.7, at assets/integrations/shortcake/class-field-maxbutton.php

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