-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathclass-shortcode-button.php
More file actions
126 lines (103 loc) · 3.76 KB
/
class-shortcode-button.php
File metadata and controls
126 lines (103 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* weForms Shortcode Button class
*
* @since 1.2.9
*/
class Weforms_Form_Button {
/**
* Constructor for shortcode class
*/
public function __construct() {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
add_action( 'media_buttons', [ $this, 'add_media_button' ], 20 );
add_action( 'admin_footer', [ $this, 'media_thickbox_content' ] );
}
/**
* Enqueue scripts and styles for form builder
*
* @global string $pagenow
*
* @return void
*/
public function enqueue_scripts() {
global $pagenow;
if ( !in_array( $pagenow, [ 'post.php', 'post-new.php'] ) ) {
return;
}
wp_enqueue_script( 'weforms-shortcode', WEFORMS_ASSET_URI . '/js/weforms-shortcode.js', ['jquery'] );
}
/**
* Adds a media button (for inserting a form) to the Post Editor
*
* @param int $editor_id The editor ID
*
* @return void
*/
public function add_media_button( $editor_id ) {
?>
<a href="#TB_inline?width=480&inlineId=weforms-media-dialog" class="button thickbox insert-form" data-editor="<?php echo esc_attr( $editor_id ); ?>" title="<?php esc_html_e( 'Add a Form', 'weforms' ); ?>">
<?php echo '<span class="wp-media-buttons-icon dashicons dashicons-welcome-widgets-menus"></span>' . esc_html__( ' Add Contact Form', 'weforms' ); ?>
</a>
<?php
}
/**
* Prints the thickbox popup content
*
* @return void
*/
public function media_thickbox_content() {
global $pagenow;
if ( !in_array( $pagenow, [ 'post.php', 'post-new.php'] ) ) {
return;
} ?>
<div id="weforms-media-dialog" style="display: none;">
<div class="weforms-popup-container">
<?php
$all_forms = weforms()->form->all();
$options = sprintf( "<option value='%s'>%s</option>", 0, __( '— Select Form —', 'weforms' ) );
foreach ( $all_forms['forms'] as $form ) {
$options .= sprintf( "<option value='%s'>%s</option>", esc_attr( $form->id ), esc_attr( $form->name ) );
} ?>
<div class="weforms-form-div">
<label><h3><?php esc_html_e( 'Select a form to insert', 'weforms' ); ?></h3></label>
<select id="weforms-form-select">
<?php echo wp_kses( $options, array( 'option' => array( 'value' => array() ) ) ); ?>
</select>
</div>
<div class="submit-button weforms-submit-div">
<button id="weforms-form-insert" class="button-primary"><?php esc_html_e( 'Insert Form', 'weforms' ); ?></button>
<button id="weforms-form-close" class="button-secondary" style="margin-left: 5px;" onClick="tb_remove();"><?php esc_html_e( 'Close', 'weforms' ); ?></a></button>
</div>
</div>
</div>
<style type="text/css">
.weforms-form-div {
padding: 10px;
clear: left;
}
.weforms-submit-div {
padding: 10px;
clear: left;
float: left;
width: 90%;
}
</style>
<?php
}
/**
* * Singleton object
*
* @staticvar boolean $instance
*
* @return \self
*/
public static function init() {
static $instance = false;
if ( !$instance ) {
$instance = new Weforms_Form_Button();
}
return $instance;
}
}
Weforms_Form_Button::init();