sample.php
4.71 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
namespace uncanny_pro_toolkit;
use uncanny_learndash_toolkit as toolkit;
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Class Sample
* @package uncanny_pro_toolkit
*/
class Sample extends toolkit\Config implements toolkit\RequiredFunctions {
/**
* Class constructor
*/
public function __construct() {
add_action( 'plugins_loaded', array( __CLASS__, 'run_frontend_hooks' ) );
}
/*
* Initialize frontend actions and filters
*/
public static function run_frontend_hooks() {
if ( true === self::dependants_exist() ) {
/* ADD FILTERS ACTIONS FUNCTION */
}
}
/**
* Does the plugin rely on another function or plugin
*
* @return boolean || string Return either true or name of function or plugin
*
*/
public static function dependants_exist() {
/* Checks for LearnDash */
global $learndash_post_types;
if ( ! isset( $learndash_post_types ) ) {
return 'Plugin: LearnDash';
}
/* Check for gravity forms */
if ( ! has_action( 'gform_loaded' ) ) {
return 'Plugin: Gravity Forms';
}
// Return true if no dependency or dependency is available
return true;
}
/**
* Description of class in Admin View
*
* @return array
*/
public static function get_details() {
$class_title = esc_html__( 'Sample Title', 'uncanny-pro-toolkit' );
$kb_link = 'http://www.uncannyowl.com';
/* Sample Simple Description with shortcode */
$class_description = esc_html__( 'Sample Description B', 'uncanny-pro-toolkit' );
/* Icon as text - max four characters wil fit */
$class_icon = '<span class="uo_icon_text">[ /]</span>'; // Shortcode
/* Icon as wp dashicon */
$class_icon = '<span class="uo_icon_dashicon dashicons dashicons-admin-users"></span>';
/* Icon as fontawesome icon */
$class_icon = '<i class="uo_icon_pro_fa uo_icon_fa fa fa-book "></i><span class="uo_pro_text">PRO</span>';
/* Icon as img */
//icons have variable widths and hieght
$icon_styles = 'width: 40px; padding-top: 5px; padding-left: 9px;';
$class_icon = '<img style="' . $icon_styles . '" src="' . self::get_admin_media( 'gravity-forms-icon.png' ) . '" />';
$tags = 'learndash'; // learndash | general
$type = 'pro';
return array(
'title' => $class_title,
'type' => $type,
'tags' => $tags,
'kb_link' => $kb_link, // OR set as null not to display
'description' => $class_description,
'dependants_exist' => self::dependants_exist(),
/*'settings' => false, // OR */
'settings' => self::get_class_settings( $class_title ),
'icon' => $class_icon,
);
}
/**
* HTML for modal to create settings
*
* @static
*
* @param $class_title
*
* @return HTML
*/
public static function get_class_settings( $class_title ) {
// Get pages to populate drop down
$args = array(
'sort_order' => 'asc',
'sort_column' => 'post_title',
'post_type' => 'page',
'post_status' => 'publish',
);
$pages = get_pages( $args );
$drop_down = array();
array_push( $drop_down, array(
'value' => '',
'text' => esc_attr__( 'Select a Page', 'uncanny-pro-toolkit' )
) );
foreach ( $pages as $page ) {
if ( empty( $page->post_title ) ) {
$page->post_title = esc_attr__( '(no title)', 'uncanny-pro-toolkit' );
}
array_push( $drop_down, array( 'value' => $page->ID, 'text' => $page->post_title ) );
}
// Create options
$options = array(
array(
'type' => 'html',
'class' => 'uo-additional-information',
'inner_html' => esc_attr__( '<div>Some Extra Information for the user</div>', 'uncanny-pro-toolkit' ),
),
array(
'type' => 'checkbox',
'label' => 'Settings A',
'option_name' => 'a',
),
array(
'type' => 'text',
'label' => 'Settings B',
'option_name' => 'b',
),
array(
'type' => 'radio',
'label' => 'Settings Gender',
'radio_name' => 'uo_gender',
'radios' => array(
array( 'value' => 'male', 'text' => 'Male' ),
array( 'value' => 'female', 'text' => 'Female' ),
array( 'value' => 'other', 'text' => 'Other' ),
),
),
array(
'type' => 'select',
'label' => 'Settings Car',
'select_name' => 'car',
'options' => array(
array( 'value' => 'volvo', 'text' => 'Volvo' ),
array( 'value' => 'saab', 'text' => 'Saab' ),
array( 'value' => 'ford', 'text' => 'Ford' ),
),
),
array(
'type' => 'select',
'label' => 'Login Page',
'select_name' => 'login_page',
'options' => $drop_down,
),
);
// Build html
$html = self::settings_output( array(
'class' => __CLASS__,
'title' => $class_title,
'options' => $options,
) );
return $html;
}
}