Version Description
- fixed script and styles equeue
- Added new feature for custom wrapper elements.
Download this release
Release Info
Developer | krozero199 |
Plugin | WP Custom Widget area |
Version | 1.2.5 |
Comparing to | |
See all releases |
Code changes from version 1.2.2 to 1.2.5
- README.txt +8 -2
- admin/class-wp-custom-widget-area-admin.php +164 -30
- admin/css/wp-custom-widget-area-admin.css +5 -0
- admin/js/wp-custom-widget-area-admin.js +116 -16
- admin/partials/cwa-admin-display.php +11 -2
- admin/partials/cwa-help.php +36 -1
- admin/partials/cwa-menu-admin-display.php +2 -1
- includes/class-custom-widget-area.php +1 -1
- includes/class-wp-custom-widget-area-activator.php +4 -5
- includes/config.php +7 -4
- wp-custom-widget-area.php +17 -7
README.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: krozero
|
3 |
Tags: widget area, custom widget area, widget, simple widget area, custom sidebar, dynamic sidebar, menu, menus, custom menu, custom menu locations, menu location, menu area
|
4 |
Requires at least: 3.0.1
|
5 |
-
Tested up to: 4.
|
6 |
-
Stable tag: 1.2.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -76,6 +76,9 @@ It allows you to show custom widget areas and menu locations created with this p
|
|
76 |
3. ** Menu locations ** create and use menus anywhere.
|
77 |
|
78 |
== Changelog ==
|
|
|
|
|
|
|
79 |
|
80 |
= 1.2.2 =
|
81 |
* Widget area bug fix for tag less code display on frontend. support ticket : widget-title-showing-in-code-form
|
@@ -128,6 +131,9 @@ It allows you to show custom widget areas and menu locations created with this p
|
|
128 |
|
129 |
|
130 |
== Upgrade Notice ==
|
|
|
|
|
|
|
131 |
|
132 |
= 1.2.2 =
|
133 |
* Widget area bug fix for tag less code display on frontend. support ticket : widget-title-showing-in-code-form
|
2 |
Contributors: krozero
|
3 |
Tags: widget area, custom widget area, widget, simple widget area, custom sidebar, dynamic sidebar, menu, menus, custom menu, custom menu locations, menu location, menu area
|
4 |
Requires at least: 3.0.1
|
5 |
+
Tested up to: 4.7
|
6 |
+
Stable tag: 1.2.5
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
76 |
3. ** Menu locations ** create and use menus anywhere.
|
77 |
|
78 |
== Changelog ==
|
79 |
+
= 1.2.5 =
|
80 |
+
* fixed script and styles equeue
|
81 |
+
* Added new feature for custom wrapper elements.
|
82 |
|
83 |
= 1.2.2 =
|
84 |
* Widget area bug fix for tag less code display on frontend. support ticket : widget-title-showing-in-code-form
|
131 |
|
132 |
|
133 |
== Upgrade Notice ==
|
134 |
+
= 1.2.5 =
|
135 |
+
* fixed script and styles equeue
|
136 |
+
* Added new feature for custom wrapper elements.
|
137 |
|
138 |
= 1.2.2 =
|
139 |
* Widget area bug fix for tag less code display on frontend. support ticket : widget-title-showing-in-code-form
|
admin/class-wp-custom-widget-area-admin.php
CHANGED
@@ -51,13 +51,16 @@ class Custom_Widget_Area_Admin {
|
|
51 |
* @var string $plugin_name The name of this plugin.
|
52 |
* @var string $version The version of this plugin.
|
53 |
*/
|
|
|
|
|
|
|
54 |
public function __construct( $plugin_name, $version ) {
|
55 |
-
global $
|
56 |
$this->view = new CWA_View();
|
57 |
$this->menuView = new Menu_View();
|
58 |
$this->plugin_name = $plugin_name;
|
59 |
$this->version = $version;
|
60 |
-
$this->table_name =
|
61 |
$this->setup_ajax_request();
|
62 |
add_action( 'widgets_init', array($this, 'registerSidebar'));
|
63 |
$this->registerMenuLocations();
|
@@ -93,7 +96,8 @@ class Custom_Widget_Area_Admin {
|
|
93 |
/* Widget functions start */
|
94 |
public function add_cwa(){
|
95 |
|
96 |
-
global
|
|
|
97 |
$wpdb->show_errors();
|
98 |
//get parameter $x = $_POST['x'];
|
99 |
$data = $_POST['data'];
|
@@ -105,29 +109,54 @@ class Custom_Widget_Area_Admin {
|
|
105 |
//var_export($table_name);
|
106 |
if($data['cwa_name'] !== '' && $data['cwa_id'] !== '' ){
|
107 |
$new_data = $this->validatePost();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
//echo "id: " .$this->check_cwa_id($new_data['cwa_id']);
|
109 |
$task =$data['task'];
|
110 |
-
|
111 |
-
|
112 |
//var_dump($new_data);
|
113 |
if($this->check_cwa_id($new_data['cwa_id']) || (isset($data['task']) && $data['task'] == 'update') ){
|
114 |
$new_data['last_updated'] = date('Y-m-d');
|
115 |
$new_data['cwa_type'] = "widget";
|
116 |
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
}
|
|
|
|
|
126 |
}
|
127 |
else{
|
128 |
wp_send_json(array('code' => 0, 'message' => 'Widget id already registered'));
|
129 |
|
130 |
}
|
|
|
|
|
131 |
}
|
132 |
else{
|
133 |
wp_send_json(array('code' => 0, 'message' => 'Widget area name or id not defined'));
|
@@ -135,10 +164,29 @@ class Custom_Widget_Area_Admin {
|
|
135 |
die(); // this is required to terminate immediately and return a proper response
|
136 |
}
|
137 |
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
|
140 |
public function delete_cwa(){
|
141 |
global $table_name, $wpdb;
|
|
|
142 |
$wpdb->show_errors();
|
143 |
$cwa_id = esc_html($_POST['data']['cwa_id']);
|
144 |
|
@@ -212,6 +260,9 @@ class Custom_Widget_Area_Admin {
|
|
212 |
$row = $wpdb->get_row( $sql, 'OBJECT');
|
213 |
|
214 |
}
|
|
|
|
|
|
|
215 |
wp_send_json($row);
|
216 |
die();
|
217 |
}
|
@@ -229,27 +280,104 @@ class Custom_Widget_Area_Admin {
|
|
229 |
$this->createSidebar($row);
|
230 |
}
|
231 |
|
|
|
232 |
}
|
233 |
public function createSidebar($row){
|
234 |
//register_widget( 'wp_custom_widget_area' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
register_sidebar( array(
|
236 |
'name' => __($row->cwa_name, 'wp_custom_widget_area' ),
|
237 |
'id' => $row->cwa_id,
|
238 |
'description' => __( $row->cwa_description, 'wp_custom_widget_area' ),
|
239 |
-
'before_widget' =>
|
240 |
-
'after_widget' =>
|
241 |
-
'before_title' =>
|
242 |
-
'after_title' =>
|
243 |
) );
|
244 |
}
|
245 |
|
246 |
/* Widget functions end */
|
247 |
|
248 |
-
|
|
|
|
|
249 |
/* Menu functions start */
|
250 |
public function add_menu(){
|
251 |
|
252 |
-
global
|
|
|
253 |
$wpdb->show_errors();
|
254 |
//get parameter $x = $_POST['x'];
|
255 |
$data = $_POST['data'];
|
@@ -298,7 +426,6 @@ class Custom_Widget_Area_Admin {
|
|
298 |
}
|
299 |
public function check_menu_id($id=null){
|
300 |
global $wpdb;
|
301 |
-
|
302 |
if(empty($id))
|
303 |
$cwa_id = $_POST['data']['cwa_id'];
|
304 |
else
|
@@ -400,8 +527,8 @@ class Custom_Widget_Area_Admin {
|
|
400 |
*
|
401 |
* @since 1.1.5
|
402 |
*/
|
403 |
-
public function enqueue_styles() {
|
404 |
-
|
405 |
/**
|
406 |
* This function is provided for demonstration purposes only.
|
407 |
*
|
@@ -413,8 +540,11 @@ class Custom_Widget_Area_Admin {
|
|
413 |
* between the defined hooks and the functions defined in this
|
414 |
* class.
|
415 |
*/
|
416 |
-
|
417 |
-
|
|
|
|
|
|
|
418 |
|
419 |
}
|
420 |
|
@@ -423,7 +553,7 @@ class Custom_Widget_Area_Admin {
|
|
423 |
*
|
424 |
* @since 1.1.5
|
425 |
*/
|
426 |
-
public function enqueue_scripts() {
|
427 |
|
428 |
/**
|
429 |
* This function is provided for demonstration purposes only.
|
@@ -436,10 +566,14 @@ class Custom_Widget_Area_Admin {
|
|
436 |
* between the defined hooks and the functions defined in this
|
437 |
* class.
|
438 |
*/
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
|
|
|
|
|
|
|
|
443 |
|
444 |
}
|
445 |
|
51 |
* @var string $plugin_name The name of this plugin.
|
52 |
* @var string $version The version of this plugin.
|
53 |
*/
|
54 |
+
const ENCRYPTION_KEY = "!@#$%^&*";
|
55 |
+
|
56 |
+
private $errors = array();
|
57 |
public function __construct( $plugin_name, $version ) {
|
58 |
+
global $wpdb;
|
59 |
$this->view = new CWA_View();
|
60 |
$this->menuView = new Menu_View();
|
61 |
$this->plugin_name = $plugin_name;
|
62 |
$this->version = $version;
|
63 |
+
$this->table_name = TABLE_NAME;
|
64 |
$this->setup_ajax_request();
|
65 |
add_action( 'widgets_init', array($this, 'registerSidebar'));
|
66 |
$this->registerMenuLocations();
|
96 |
/* Widget functions start */
|
97 |
public function add_cwa(){
|
98 |
|
99 |
+
global $wpdb;
|
100 |
+
$table_name = TABLE_NAME;
|
101 |
$wpdb->show_errors();
|
102 |
//get parameter $x = $_POST['x'];
|
103 |
$data = $_POST['data'];
|
109 |
//var_export($table_name);
|
110 |
if($data['cwa_name'] !== '' && $data['cwa_id'] !== '' ){
|
111 |
$new_data = $this->validatePost();
|
112 |
+
//var_dump($new_data['before_after_widget']);
|
113 |
+
if($new_data['widget_wrapper_tg'] == "custom" && !empty($new_data['before_after_widget'])){
|
114 |
+
$new_data['cwa_widget_wrapper'] = $new_data['before_after_widget'];
|
115 |
+
|
116 |
+
}
|
117 |
+
if($new_data['widget_header_wrapper_tg'] == "custom" && !empty($new_data['before_after_title'])){
|
118 |
+
$new_data['cwa_widget_header_wrapper'] = $new_data['before_after_title'];
|
119 |
+
|
120 |
+
}
|
121 |
+
//var_dump($new_data);
|
122 |
//echo "id: " .$this->check_cwa_id($new_data['cwa_id']);
|
123 |
$task =$data['task'];
|
124 |
+
//$new_data['before_after_widget'] = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, self::ENCRYPTION_KEY, $new_data['before_after_widget'], MCRYPT_MODE_ECB);
|
125 |
+
|
126 |
//var_dump($new_data);
|
127 |
if($this->check_cwa_id($new_data['cwa_id']) || (isset($data['task']) && $data['task'] == 'update') ){
|
128 |
$new_data['last_updated'] = date('Y-m-d');
|
129 |
$new_data['cwa_type'] = "widget";
|
130 |
|
131 |
+
if($this->validateWidgetFormData($new_data)){
|
132 |
+
unset($new_data['widget_wrapper_tg']);
|
133 |
+
unset($new_data['widget_header_wrapper_tg']);
|
134 |
+
unset($new_data['before_after_widget']);
|
135 |
+
unset($new_data['before_after_title']);
|
136 |
+
unset($new_data['task']);
|
137 |
+
unset($new_data['updateid']);
|
138 |
+
|
139 |
+
|
140 |
+
$row = $wpdb->replace( $table_name, $new_data );
|
141 |
+
//var_dump($wpdb->print_error());
|
142 |
+
if($row && !$task ){
|
143 |
+
wp_send_json(array('code'=>1, 'message' => $new_data['cwa_id'].' created successfully.'));
|
144 |
+
}
|
145 |
+
elseif($row && $task ){
|
146 |
+
wp_send_json(array('code'=>1, 'message' => $new_data['cwa_id'].' updated successfully.'));
|
147 |
+
}
|
148 |
+
}else{
|
149 |
+
wp_send_json($this->errors);
|
150 |
}
|
151 |
+
|
152 |
+
|
153 |
}
|
154 |
else{
|
155 |
wp_send_json(array('code' => 0, 'message' => 'Widget id already registered'));
|
156 |
|
157 |
}
|
158 |
+
|
159 |
+
|
160 |
}
|
161 |
else{
|
162 |
wp_send_json(array('code' => 0, 'message' => 'Widget area name or id not defined'));
|
164 |
die(); // this is required to terminate immediately and return a proper response
|
165 |
}
|
166 |
|
167 |
+
//validate post data.
|
168 |
+
public function validateWidgetFormData($data){
|
169 |
+
$ret = true;
|
170 |
+
|
171 |
+
if($data['widget_wrapper_tg'] == 'custom' && $this->isJson(html_entity_decode(stripcslashes($data['before_after_widget']))) == false ){
|
172 |
+
//array_push($this->errors, array('code' => 0, 'message' => stripcslashes($data['before_after_widget'])));
|
173 |
+
|
174 |
+
//array_push($this->errors, array('code' => 0, 'message' => $this->isJson(stripcslashes($data['before_after_widget'])."")));
|
175 |
+
array_push($this->errors, array('code' => 0, 'message' => 'Please Enter Valid Json object for "Before After widget" field.'));
|
176 |
+
}
|
177 |
+
if($data['widget_header_wrapper_tg'] == 'custom' && $this->isJson(html_entity_decode(stripcslashes($data['before_after_title']))) == false){
|
178 |
+
array_push($this->errors, array('code' => 0, 'message' => 'Please Enter Valid Json object for "Before/After widget title" field.'));
|
179 |
+
}
|
180 |
+
|
181 |
+
if(count($this->errors)>0){
|
182 |
+
$ret = false;
|
183 |
+
}
|
184 |
+
return $ret;
|
185 |
+
}
|
186 |
|
187 |
public function delete_cwa(){
|
188 |
global $table_name, $wpdb;
|
189 |
+
$table_name = TABLE_NAME;
|
190 |
$wpdb->show_errors();
|
191 |
$cwa_id = esc_html($_POST['data']['cwa_id']);
|
192 |
|
260 |
$row = $wpdb->get_row( $sql, 'OBJECT');
|
261 |
|
262 |
}
|
263 |
+
|
264 |
+
$row->cwa_widget_wrapper = stripslashes(html_entity_decode ($row->cwa_widget_wrapper, ENT_QUOTES));
|
265 |
+
$row->cwa_widget_header_wrapper = stripslashes(html_entity_decode($row->cwa_widget_header_wrapper, ENT_QUOTES));
|
266 |
wp_send_json($row);
|
267 |
die();
|
268 |
}
|
280 |
$this->createSidebar($row);
|
281 |
}
|
282 |
|
283 |
+
//exit();
|
284 |
}
|
285 |
public function createSidebar($row){
|
286 |
//register_widget( 'wp_custom_widget_area' );
|
287 |
+
$before_widget = '<'.$row->cwa_widget_wrapper.' id="%1$s" class="widget %2$s '.$row->cwa_widget_class.'">';
|
288 |
+
$after_widget = '</'.$row->cwa_widget_wrapper.'>';
|
289 |
+
|
290 |
+
$before_title = '<'.$row->cwa_widget_header_wrapper.' class="widgettitle '.$row->cwa_widget_header_class.'">';
|
291 |
+
$after_title = '</'.$row->cwa_widget_header_wrapper.'>';
|
292 |
+
|
293 |
+
|
294 |
+
$row->cwa_widget_wrapper = stripslashes(html_entity_decode ($row->cwa_widget_wrapper, ENT_QUOTES));
|
295 |
+
//var_dump($row->cwa_widget_wrapper);
|
296 |
+
if($this->isJson($row->cwa_widget_wrapper)){
|
297 |
+
//var_dump($row->cwa_widget_wrapper);
|
298 |
+
$cwa_widget_wrappers = json_decode(trim(preg_replace('/\s\s+/', ' ',$row->cwa_widget_wrapper)), true);
|
299 |
+
$before_widget = '';
|
300 |
+
$after_widget = '';
|
301 |
+
//var_dump($row->cwa_widget_wrapper);
|
302 |
+
foreach ($cwa_widget_wrappers as $wrapper) {
|
303 |
+
# code...
|
304 |
+
$before_widget .= '<';
|
305 |
+
$after_widget .= '</';
|
306 |
+
|
307 |
+
foreach ($wrapper as $key => $value) {
|
308 |
+
# code...
|
309 |
+
if($key == "tag"){
|
310 |
+
$before_widget .= $wrapper['tag']. " " ;
|
311 |
+
$after_widget .= $wrapper['tag'];
|
312 |
+
//var_dump($before_widget);
|
313 |
+
}
|
314 |
+
else{
|
315 |
+
$before_widget .= $key . '="'.$value.'"' ;
|
316 |
+
}
|
317 |
+
}
|
318 |
+
|
319 |
+
$before_widget .= '>';
|
320 |
+
$after_widget .= '>';
|
321 |
+
|
322 |
+
}
|
323 |
+
//var_dump($before_widget); //exit();
|
324 |
+
}
|
325 |
+
|
326 |
+
$row->cwa_widget_header_wrapper = stripslashes(html_entity_decode ($row->cwa_widget_header_wrapper, ENT_QUOTES));
|
327 |
+
if($this->isJson($row->cwa_widget_header_wrapper)){
|
328 |
+
$cwa_widget_wrappers = json_decode(trim(preg_replace('/\s\s+/', ' ',$row->cwa_widget_header_wrapper)), true);
|
329 |
+
$before_title = '';
|
330 |
+
$after_title = '';
|
331 |
+
//var_dump($row->cwa_widget_wrapper);
|
332 |
+
foreach ($cwa_widget_wrappers as $wrapper) {
|
333 |
+
# code...
|
334 |
+
$before_title .= '<';
|
335 |
+
$after_title .= '</';
|
336 |
+
|
337 |
+
|
338 |
+
//sett div as tag if tag is not defined in json data
|
339 |
+
if(!array_key_exists('tag', $wrapper)){
|
340 |
+
$before_title .= "div " ;
|
341 |
+
$after_title .= "div";
|
342 |
+
}
|
343 |
+
foreach ($wrapper as $key => $value) {
|
344 |
+
# code...
|
345 |
+
|
346 |
+
if($key == "tag"){
|
347 |
+
$before_title .= $wrapper['tag']. " " ;
|
348 |
+
$after_title .= $wrapper['tag'];
|
349 |
+
}
|
350 |
+
else{
|
351 |
+
$before_title .= $key . '="'.$value.'"' ;
|
352 |
+
}
|
353 |
+
}
|
354 |
+
$before_title .= '>';
|
355 |
+
$after_title .= '>';
|
356 |
+
|
357 |
+
}
|
358 |
+
}
|
359 |
+
|
360 |
register_sidebar( array(
|
361 |
'name' => __($row->cwa_name, 'wp_custom_widget_area' ),
|
362 |
'id' => $row->cwa_id,
|
363 |
'description' => __( $row->cwa_description, 'wp_custom_widget_area' ),
|
364 |
+
'before_widget' => $before_widget,
|
365 |
+
'after_widget' => $after_widget,
|
366 |
+
'before_title' => $before_title,
|
367 |
+
'after_title' => $after_title,
|
368 |
) );
|
369 |
}
|
370 |
|
371 |
/* Widget functions end */
|
372 |
|
373 |
+
public function isJson($json_string){
|
374 |
+
return !preg_match('/[^,:{}\\[\\]0-9.\\-+Eaeflnr-u \\n\\r\\t]/', preg_replace('/"(\\.|[^"\\\\])*"/', '', $json_string));
|
375 |
+
}
|
376 |
/* Menu functions start */
|
377 |
public function add_menu(){
|
378 |
|
379 |
+
global $wpdb;
|
380 |
+
$table_name = TABLE_NAME;
|
381 |
$wpdb->show_errors();
|
382 |
//get parameter $x = $_POST['x'];
|
383 |
$data = $_POST['data'];
|
426 |
}
|
427 |
public function check_menu_id($id=null){
|
428 |
global $wpdb;
|
|
|
429 |
if(empty($id))
|
430 |
$cwa_id = $_POST['data']['cwa_id'];
|
431 |
else
|
527 |
*
|
528 |
* @since 1.1.5
|
529 |
*/
|
530 |
+
public function enqueue_styles($hook) {
|
531 |
+
//wp_die($hook);
|
532 |
/**
|
533 |
* This function is provided for demonstration purposes only.
|
534 |
*
|
540 |
* between the defined hooks and the functions defined in this
|
541 |
* class.
|
542 |
*/
|
543 |
+
if($hook == 'toplevel_page_custom_widget_area' || $hook == 'cwa-settings_page_custom_menu_location' || $hook == 'cwa-settings_page_cwa_help') {
|
544 |
+
|
545 |
+
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wp-custom-widget-area-admin.css', array(), $this->version, 'all' );
|
546 |
+
}
|
547 |
+
|
548 |
|
549 |
}
|
550 |
|
553 |
*
|
554 |
* @since 1.1.5
|
555 |
*/
|
556 |
+
public function enqueue_scripts($hook) {
|
557 |
|
558 |
/**
|
559 |
* This function is provided for demonstration purposes only.
|
566 |
* between the defined hooks and the functions defined in this
|
567 |
* class.
|
568 |
*/
|
569 |
+
if($hook == 'toplevel_page_custom_widget_area' || $hook == 'cwa-settings_page_custom_menu_location' || $hook == 'cwa-settings_page_cwa_help') {
|
570 |
+
|
571 |
+
wp_enqueue_script( 'tooltip', plugin_dir_url( __FILE__ ) . 'js/jquery.tooltipster.min.js', array( ), $this->version, false );
|
572 |
+
wp_enqueue_script( 'hashchange', plugin_dir_url( __FILE__ ) . 'js/jquery.hashchange.min.js', array( ), $this->version, false );
|
573 |
+
wp_enqueue_script( 'easytabs', plugin_dir_url( __FILE__ ) . 'js/jquery.easytabs.min.js', array( 'hashchange'), $this->version, false );
|
574 |
+
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wp-custom-widget-area-admin.js', array( 'jquery', 'tooltip', 'easytabs'), $this->version, false );
|
575 |
+
}
|
576 |
+
|
577 |
|
578 |
}
|
579 |
|
admin/css/wp-custom-widget-area-admin.css
CHANGED
@@ -56,6 +56,7 @@
|
|
56 |
.cwa-form-row{
|
57 |
margin-bottom: 5px;
|
58 |
padding: 5px;
|
|
|
59 |
}
|
60 |
.cwa-form input[type=text], .cwa-form input[type=password], .cwa-form input[type=email], .cwa-form select, .cwa-form textarea{
|
61 |
padding: 5px 10px;
|
@@ -202,3 +203,7 @@
|
|
202 |
.no-data{
|
203 |
color: #999;
|
204 |
}
|
|
|
|
|
|
|
|
56 |
.cwa-form-row{
|
57 |
margin-bottom: 5px;
|
58 |
padding: 5px;
|
59 |
+
position: relative;
|
60 |
}
|
61 |
.cwa-form input[type=text], .cwa-form input[type=password], .cwa-form input[type=email], .cwa-form select, .cwa-form textarea{
|
62 |
padding: 5px 10px;
|
203 |
.no-data{
|
204 |
color: #999;
|
205 |
}
|
206 |
+
.fieldSwitcher{
|
207 |
+
cursor: pointer;
|
208 |
+
vertical-align: top;
|
209 |
+
}
|
admin/js/wp-custom-widget-area-admin.js
CHANGED
@@ -47,8 +47,8 @@
|
|
47 |
//console.log(data);
|
48 |
reloadCwaTable();
|
49 |
showCwaError(data);
|
50 |
-
|
51 |
-
|
52 |
});
|
53 |
//}
|
54 |
}
|
@@ -71,6 +71,19 @@
|
|
71 |
var self = this;
|
72 |
checkId(self, $(self).val(), 'widget');
|
73 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
$(document).on('click', '.cwa-edit-link', function(e){
|
76 |
e.preventDefault();
|
@@ -83,11 +96,44 @@
|
|
83 |
$('#cwa-form input[name=task]').val('update');
|
84 |
$('#cwa-form input[name=updateid]').val(data['cwa_id']);
|
85 |
$('#cwa-form input[name=cwa_id]').prop('disabled', 'disabled');
|
|
|
|
|
|
|
86 |
for (var k in data){
|
87 |
if (typeof data[k] !== 'function') {
|
88 |
//alert("Key is " + k + ", value is" + target[k]);
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
}
|
92 |
}
|
93 |
//console.log(data);
|
@@ -112,7 +158,7 @@
|
|
112 |
var id = $(this).data('id');
|
113 |
|
114 |
$.post(ajaxurl,{'action': 'delete_menu', 'data': {'cwa_id': id}}, function(data){
|
115 |
-
console.log(data);
|
116 |
showCwaError(data);
|
117 |
|
118 |
reloadMenuTable();
|
@@ -120,6 +166,7 @@
|
|
120 |
});
|
121 |
|
122 |
|
|
|
123 |
$('#cwa-advance-btn').on('click', function(e){
|
124 |
e.preventDefault();
|
125 |
$('#cwa-form .advanced').toggle('show').toggleClass('hide');
|
@@ -170,7 +217,7 @@
|
|
170 |
});
|
171 |
|
172 |
$('#cwa-menu-form input[name=cwa_id]').on('keyup', function(){
|
173 |
-
console.log("hey");
|
174 |
var self = this;
|
175 |
checkId(self, $(self).val(), 'menu');
|
176 |
});
|
@@ -188,11 +235,11 @@
|
|
188 |
$('#tab-container').easytabs();
|
189 |
|
190 |
runTooltip();
|
191 |
-
|
192 |
});
|
193 |
|
194 |
function validateForm(arr){
|
195 |
-
window.xt = arr;
|
196 |
return true;
|
197 |
}
|
198 |
function checkId(self, cwa_id, type){
|
@@ -205,7 +252,7 @@
|
|
205 |
$(self).next('.cwa-form-message').html("<label class='cwa-success' style='padding-left: 5px;'>"+data.message+"</label>");
|
206 |
}
|
207 |
|
208 |
-
console.log(data);
|
209 |
});
|
210 |
};
|
211 |
function reloadCwaTable(){
|
@@ -225,20 +272,30 @@
|
|
225 |
});
|
226 |
}
|
227 |
function showCwaError(obj){
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
$('.cwa-error').html(message).addClass(type).fadeIn();
|
233 |
-
|
234 |
-
|
235 |
-
|
|
|
236 |
}
|
237 |
function resetForm(){
|
238 |
$('.cwa-form input[type="hidden"]' ).val('');
|
239 |
$('.cwa-form input[disabled]' ).prop('disabled', false);
|
240 |
$('.cwa-form select' ).children(':first-child').prop('selected', true);
|
241 |
$('.cwa-form input[type="text"]' ).val('');
|
|
|
242 |
$('.cwa-form input[type="submit"]' ).val('Create');
|
243 |
$('.cwa-form .cwa-form-message' ).empty();
|
244 |
|
@@ -253,5 +310,48 @@
|
|
253 |
trigger: 'click'
|
254 |
});
|
255 |
}
|
|
|
|
|
|
|
256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
})( jQuery );
|
47 |
//console.log(data);
|
48 |
reloadCwaTable();
|
49 |
showCwaError(data);
|
50 |
+
if(!Array.isArray(data))
|
51 |
+
resetForm();
|
52 |
});
|
53 |
//}
|
54 |
}
|
71 |
var self = this;
|
72 |
checkId(self, $(self).val(), 'widget');
|
73 |
});
|
74 |
+
|
75 |
+
|
76 |
+
$('#cwa-form #before_after_widget, #cwa-form #before_after_title').on('keyup', function(){
|
77 |
+
var self = this;
|
78 |
+
if(!isJSON($(this).val()) && $(this).val() != ""){
|
79 |
+
$(this).parent().find('.cwa-form-message').html('<label class="cwa-warning" style="position:absolute; top: 40%; max-width: 178px;">Error: Please Enter Valid Json object.</label>');
|
80 |
+
}
|
81 |
+
else{
|
82 |
+
$(this).parent().find('.cwa-form-message').html('');
|
83 |
+
}
|
84 |
+
});
|
85 |
+
|
86 |
+
$('#cwa-form a.fieldSwitcher').on('click', fieldSwitcher);
|
87 |
|
88 |
$(document).on('click', '.cwa-edit-link', function(e){
|
89 |
e.preventDefault();
|
96 |
$('#cwa-form input[name=task]').val('update');
|
97 |
$('#cwa-form input[name=updateid]').val(data['cwa_id']);
|
98 |
$('#cwa-form input[name=cwa_id]').prop('disabled', 'disabled');
|
99 |
+
|
100 |
+
var contentElementsArray = ['li','div','span','aside'];
|
101 |
+
var headerElementArray = ['h1','h2','h3','h4','h5','h6'];
|
102 |
for (var k in data){
|
103 |
if (typeof data[k] !== 'function') {
|
104 |
//alert("Key is " + k + ", value is" + target[k]);
|
105 |
+
if(k == "cwa_widget_wrapper"){
|
106 |
+
console.log(data[k]);
|
107 |
+
if(contentElementsArray.indexOf(data[k]) >= 0){
|
108 |
+
$('#cwa-form [name='+k+']').val(data[k]);
|
109 |
+
if($('#cwa-form #before_after_widget').siblings('a.fieldSwitcher').text() == "Default"){
|
110 |
+
$('#cwa-form #before_after_widget').siblings('a.fieldSwitcher').trigger('click');
|
111 |
+
}
|
112 |
+
}
|
113 |
+
else{
|
114 |
+
$('#cwa-form #before_after_widget').val(data[k]);
|
115 |
+
if($('#cwa-form #before_after_widget').siblings('a.fieldSwitcher').text() == "Custom"){
|
116 |
+
$('#cwa-form #before_after_widget').siblings('a.fieldSwitcher').trigger('click');
|
117 |
+
}
|
118 |
+
}
|
119 |
+
}else if(k == "cwa_widget_header_wrapper"){
|
120 |
+
if(headerElementArray.indexOf(data[k]) >= 0){
|
121 |
+
$('#cwa-form [name='+k+']').val(data[k]);
|
122 |
+
if($('#cwa-form #before_after_title').siblings('a.fieldSwitcher').text() == "Default"){
|
123 |
+
$('#cwa-form #before_after_title').siblings('a.fieldSwitcher').trigger('click');
|
124 |
+
}
|
125 |
+
}
|
126 |
+
else{
|
127 |
+
$('#cwa-form #before_after_title').val(data[k]);
|
128 |
+
if($('#cwa-form #before_after_title').siblings('a.fieldSwitcher').text() == "Custom"){
|
129 |
+
$('#cwa-form #before_after_title').siblings('a.fieldSwitcher').trigger('click');
|
130 |
+
}
|
131 |
+
}
|
132 |
+
}
|
133 |
+
else{
|
134 |
+
$('#cwa-form [name='+k+']').val(data[k]);
|
135 |
+
}
|
136 |
+
|
137 |
}
|
138 |
}
|
139 |
//console.log(data);
|
158 |
var id = $(this).data('id');
|
159 |
|
160 |
$.post(ajaxurl,{'action': 'delete_menu', 'data': {'cwa_id': id}}, function(data){
|
161 |
+
//console.log(data);
|
162 |
showCwaError(data);
|
163 |
|
164 |
reloadMenuTable();
|
166 |
});
|
167 |
|
168 |
|
169 |
+
|
170 |
$('#cwa-advance-btn').on('click', function(e){
|
171 |
e.preventDefault();
|
172 |
$('#cwa-form .advanced').toggle('show').toggleClass('hide');
|
217 |
});
|
218 |
|
219 |
$('#cwa-menu-form input[name=cwa_id]').on('keyup', function(){
|
220 |
+
//console.log("hey");
|
221 |
var self = this;
|
222 |
checkId(self, $(self).val(), 'menu');
|
223 |
});
|
235 |
$('#tab-container').easytabs();
|
236 |
|
237 |
runTooltip();
|
238 |
+
enableTextareaTab();
|
239 |
});
|
240 |
|
241 |
function validateForm(arr){
|
242 |
+
//window.xt = arr;
|
243 |
return true;
|
244 |
}
|
245 |
function checkId(self, cwa_id, type){
|
252 |
$(self).next('.cwa-form-message').html("<label class='cwa-success' style='padding-left: 5px;'>"+data.message+"</label>");
|
253 |
}
|
254 |
|
255 |
+
//console.log(data);
|
256 |
});
|
257 |
};
|
258 |
function reloadCwaTable(){
|
272 |
});
|
273 |
}
|
274 |
function showCwaError(obj){
|
275 |
+
if(Array.isArray(obj)){
|
276 |
+
var message = '';
|
277 |
+
for(var i = 0; i<obj.length; i++){
|
278 |
+
var type = (obj[i].code === 0)? "cwa-warning" : "cwa-success" ;
|
279 |
+
message += obj[i].message + "<br>";
|
280 |
+
}
|
281 |
+
}else{
|
282 |
+
var type = (obj.code === 0)? "cwa-warning" : "cwa-success" ;
|
283 |
+
//console.log(obj.code === 0);
|
284 |
+
var message = obj.message;
|
285 |
+
|
286 |
+
}
|
287 |
$('.cwa-error').html(message).addClass(type).fadeIn();
|
288 |
+
setTimeout(function(){
|
289 |
+
$('.cwa-error').fadeOut().html("").removeClass(type);
|
290 |
+
}, 5000);
|
291 |
+
|
292 |
}
|
293 |
function resetForm(){
|
294 |
$('.cwa-form input[type="hidden"]' ).val('');
|
295 |
$('.cwa-form input[disabled]' ).prop('disabled', false);
|
296 |
$('.cwa-form select' ).children(':first-child').prop('selected', true);
|
297 |
$('.cwa-form input[type="text"]' ).val('');
|
298 |
+
$('.cwa-form textarea' ).val('');
|
299 |
$('.cwa-form input[type="submit"]' ).val('Create');
|
300 |
$('.cwa-form .cwa-form-message' ).empty();
|
301 |
|
310 |
trigger: 'click'
|
311 |
});
|
312 |
}
|
313 |
+
function enableTextareaTab(){
|
314 |
+
$(document).delegate('.cwa-form-row textarea', 'keydown', function(e) {
|
315 |
+
var keyCode = e.keyCode || e.which;
|
316 |
|
317 |
+
if (keyCode == 9) {
|
318 |
+
e.preventDefault();
|
319 |
+
var start = $(this).get(0).selectionStart;
|
320 |
+
var end = $(this).get(0).selectionEnd;
|
321 |
+
|
322 |
+
// set textarea value to: text before caret + tab + text after caret
|
323 |
+
$(this).val($(this).val().substring(0, start)
|
324 |
+
+ "\t"
|
325 |
+
+ $(this).val().substring(end));
|
326 |
+
|
327 |
+
// put caret at right position again
|
328 |
+
$(this).get(0).selectionStart =
|
329 |
+
$(this).get(0).selectionEnd = start + 1;
|
330 |
+
}
|
331 |
+
});
|
332 |
+
}
|
333 |
+
function fieldSwitcher(){
|
334 |
+
if($(this).parent().find('textarea').hasClass('hidden')){
|
335 |
+
$(this).text("Default");
|
336 |
+
$(this).parent().find('.tg').val('custom');
|
337 |
+
|
338 |
+
//console.log($(this).parent().find('.tg').val());
|
339 |
+
}else{
|
340 |
+
$(this).text("Custom");
|
341 |
+
$(this).parent().find('.tg').val('');
|
342 |
+
}
|
343 |
+
$(this).parent().find('select').toggleClass('hidden');
|
344 |
+
$(this).parent().find('textarea').toggleClass('hidden');
|
345 |
+
|
346 |
+
}
|
347 |
+
|
348 |
+
function isJSON(data) {
|
349 |
+
var ret = true;
|
350 |
+
try {
|
351 |
+
JSON.parse(data);
|
352 |
+
}catch(e) {
|
353 |
+
ret = false;
|
354 |
+
}
|
355 |
+
return ret;
|
356 |
+
}
|
357 |
})( jQuery );
|
admin/partials/cwa-admin-display.php
CHANGED
@@ -56,6 +56,7 @@ class CWA_view
|
|
56 |
<div class="cwa-error" style="display:none;">
|
57 |
|
58 |
</div>
|
|
|
59 |
<div id="cwa-table-wrap">
|
60 |
<?php
|
61 |
self::widgetTable();
|
@@ -93,6 +94,10 @@ class CWA_view
|
|
93 |
<option value="aside">aside</option>
|
94 |
<option value="span">span</option>
|
95 |
</select>
|
|
|
|
|
|
|
|
|
96 |
<span class="cwa-form-message"></span>
|
97 |
</div>
|
98 |
<div class="cwa-form-row">
|
@@ -108,7 +113,11 @@ class CWA_view
|
|
108 |
<option value="h5">h5</option>
|
109 |
<option value="h6">h6</option>
|
110 |
</select>
|
|
|
|
|
|
|
111 |
<span class="cwa-form-message"></span>
|
|
|
112 |
</div>
|
113 |
|
114 |
</div>
|
@@ -175,8 +184,8 @@ class CWA_view
|
|
175 |
}
|
176 |
|
177 |
public function getWidgetData(){
|
178 |
-
global $wpdb
|
179 |
-
|
180 |
$sql = "SELECT * FROM $table_name WHERE cwa_type='widget'";
|
181 |
|
182 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
56 |
<div class="cwa-error" style="display:none;">
|
57 |
|
58 |
</div>
|
59 |
+
|
60 |
<div id="cwa-table-wrap">
|
61 |
<?php
|
62 |
self::widgetTable();
|
94 |
<option value="aside">aside</option>
|
95 |
<option value="span">span</option>
|
96 |
</select>
|
97 |
+
<textarea id="before_after_widget" name="before_after_widget" placeholder="Before/ After widget" title='i.e. <br>[{ <br> "tag": "div", <br> "id": "widget-outer", <br> "class": "widget-outer", <br> "data-tag": "outer" <br> }, <br> { <br> "tag": "div", <br> "class": "widget-inner", <br> ... <br>}, <br> ...'] class="tooltip hidden" style="min-height: 150px;" ></textarea>
|
98 |
+
<input id="widget_wrapper_tg" class="tg" name="widget_wrapper_tg" type="hidden">
|
99 |
+
|
100 |
+
<a class="fieldSwitcher">Custom</a>
|
101 |
<span class="cwa-form-message"></span>
|
102 |
</div>
|
103 |
<div class="cwa-form-row">
|
113 |
<option value="h5">h5</option>
|
114 |
<option value="h6">h6</option>
|
115 |
</select>
|
116 |
+
<textarea id="before_after_title" name="before_after_title" placeholder="Before/ After widget" title='i.e. <br>[{ <br> "tag": "div", <br> "id": "widget-outer", <br> "class": "widget-outer", <br> "data-tag": "outer" <br> }, <br> { <br> "tag": "div", <br> "class": "widget-inner", <br> ... <br>}, <br> ...]' class="tooltip hidden" style="min-height: 150px;" ></textarea>
|
117 |
+
<input id="widget_header_wrapper_tg" name="widget_header_wrapper_tg" class="tg" type="hidden">
|
118 |
+
<a class="fieldSwitcher">Custom</a>
|
119 |
<span class="cwa-form-message"></span>
|
120 |
+
|
121 |
</div>
|
122 |
|
123 |
</div>
|
184 |
}
|
185 |
|
186 |
public function getWidgetData(){
|
187 |
+
global $wpdb;
|
188 |
+
$table_name = TABLE_NAME;
|
189 |
$sql = "SELECT * FROM $table_name WHERE cwa_type='widget'";
|
190 |
|
191 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
admin/partials/cwa-help.php
CHANGED
@@ -92,7 +92,41 @@ function help_page(){
|
|
92 |
<br>
|
93 |
|
94 |
</p>
|
95 |
-
<h2 style="margin-top: 0;">How to
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
<p>
|
97 |
<ol class="list">
|
98 |
<li><h4>Click on the edit link. </h4>
|
@@ -109,6 +143,7 @@ function help_page(){
|
|
109 |
</li>
|
110 |
</ol>
|
111 |
</p>
|
|
|
112 |
</div>
|
113 |
</div>
|
114 |
<div id="custom-menu-location">
|
92 |
<br>
|
93 |
|
94 |
</p>
|
95 |
+
<h2 style="margin-top: 0;">How to add custom wrapper tag? [New]</h2>
|
96 |
+
<p>
|
97 |
+
<ol class="list">
|
98 |
+
<li><h4>Click on custom link. </h4>
|
99 |
+
<br>
|
100 |
+
<img src="<?php echo $plugin_url;?>/admin/img/help/cwa_widget_advanced_1.png">
|
101 |
+
</li>
|
102 |
+
<li><h4>Enter a valid Json object array </h4>
|
103 |
+
<p>
|
104 |
+
i.e:
|
105 |
+
<code>
|
106 |
+
[{
|
107 |
+
"tag": "div",
|
108 |
+
"id" : "outer-widget",
|
109 |
+
"class" : "outer-class"
|
110 |
+
},
|
111 |
+
{
|
112 |
+
"tag": "div",
|
113 |
+
"id" : "inner-widget",
|
114 |
+
"class" : "inner-class"
|
115 |
+
}]
|
116 |
+
</code><br>
|
117 |
+
</p>
|
118 |
+
|
119 |
+
<img src="<?php echo $plugin_url;?>/admin/img/help/cwa_widget_advanced_2.png">
|
120 |
+
</li>
|
121 |
+
|
122 |
+
<li>
|
123 |
+
<h4>Then submit a changes by clicking update button. </h4>
|
124 |
+
|
125 |
+
</li>
|
126 |
+
</ol>
|
127 |
+
</p>
|
128 |
+
|
129 |
+
<h2 style="margin-top: 0;">How to Update existing widget area? </h2>
|
130 |
<p>
|
131 |
<ol class="list">
|
132 |
<li><h4>Click on the edit link. </h4>
|
143 |
</li>
|
144 |
</ol>
|
145 |
</p>
|
146 |
+
|
147 |
</div>
|
148 |
</div>
|
149 |
<div id="custom-menu-location">
|
admin/partials/cwa-menu-admin-display.php
CHANGED
@@ -131,7 +131,8 @@ class Menu_view
|
|
131 |
}
|
132 |
|
133 |
public function getMenuData(){
|
134 |
-
global $wpdb
|
|
|
135 |
|
136 |
$sql = "SELECT * FROM $table_name WHERE cwa_type='menu'";
|
137 |
|
131 |
}
|
132 |
|
133 |
public function getMenuData(){
|
134 |
+
global $wpdb;
|
135 |
+
$table_name = TABLE_NAME;
|
136 |
|
137 |
$sql = "SELECT * FROM $table_name WHERE cwa_type='menu'";
|
138 |
|
includes/class-custom-widget-area.php
CHANGED
@@ -69,7 +69,7 @@ class Custom_Widget_Area {
|
|
69 |
public function __construct() {
|
70 |
|
71 |
$this->plugin_name = 'wp-custom-widget-area';
|
72 |
-
$this->version =
|
73 |
|
74 |
$this->load_dependencies();
|
75 |
$this->set_locale();
|
69 |
public function __construct() {
|
70 |
|
71 |
$this->plugin_name = 'wp-custom-widget-area';
|
72 |
+
$this->version = KZ_DB_VERSION;
|
73 |
|
74 |
$this->load_dependencies();
|
75 |
$this->set_locale();
|
includes/class-wp-custom-widget-area-activator.php
CHANGED
@@ -31,9 +31,8 @@ class Custom_Widget_Area_Activator {
|
|
31 |
*/
|
32 |
public static function activate() {
|
33 |
|
34 |
-
global $wpdb;
|
35 |
-
|
36 |
-
$table_name = $wpdb->prefix . 'cwa';
|
37 |
$charset_collate = '';
|
38 |
|
39 |
if ( ! empty( $wpdb->charset ) ) {
|
@@ -50,9 +49,9 @@ class Custom_Widget_Area_Activator {
|
|
50 |
cwa_description text NOT NULL,
|
51 |
cwa_id varchar(100) NOT NULL ,
|
52 |
cwa_widget_class text ,
|
53 |
-
cwa_widget_wrapper
|
54 |
cwa_widget_header_class text,
|
55 |
-
cwa_widget_header_wrapper
|
56 |
cwa_type varchar(10),
|
57 |
last_updated date NOT NULL,
|
58 |
UNIQUE KEY id (id)
|
31 |
*/
|
32 |
public static function activate() {
|
33 |
|
34 |
+
global $wpdb, $kz_db_version, $table_name;
|
35 |
+
|
|
|
36 |
$charset_collate = '';
|
37 |
|
38 |
if ( ! empty( $wpdb->charset ) ) {
|
49 |
cwa_description text NOT NULL,
|
50 |
cwa_id varchar(100) NOT NULL ,
|
51 |
cwa_widget_class text ,
|
52 |
+
cwa_widget_wrapper text,
|
53 |
cwa_widget_header_class text,
|
54 |
+
cwa_widget_header_wrapper text,
|
55 |
cwa_type varchar(10),
|
56 |
last_updated date NOT NULL,
|
57 |
UNIQUE KEY id (id)
|
includes/config.php
CHANGED
@@ -1,7 +1,10 @@
|
|
1 |
<?php
|
2 |
/*plugin configs*/
|
3 |
-
global $wpdb;
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
7 |
?>
|
1 |
<?php
|
2 |
/*plugin configs*/
|
3 |
+
global $wpdb, $table_name, $kz_db_version;
|
4 |
+
define('KZ_DB_VERSION', '1.2.5');
|
5 |
+
define('TABLE_NAME', $wpdb->prefix . 'cwa');
|
6 |
+
define('CHARSET_COLLATE', '');
|
7 |
+
$table_name = TABLE_NAME;
|
8 |
+
$kz_db_version = KZ_DB_VERSION;
|
9 |
+
|
10 |
?>
|
wp-custom-widget-area.php
CHANGED
@@ -16,7 +16,7 @@
|
|
16 |
* Plugin Name: WP Custom Widget area
|
17 |
* Plugin URI: http://kishorkhambu.com.np/plugins/
|
18 |
* Description: A wordpress plugin to create custom dynamic widget area.
|
19 |
-
* Version: 1.2.
|
20 |
* Author: Kishor Khambu
|
21 |
* Author URI: http://kishorkhambu.com.np
|
22 |
* License: GPL-2.0+
|
@@ -81,7 +81,8 @@ function cb(){
|
|
81 |
|
82 |
|
83 |
function myplugin_update_db_check() {
|
84 |
-
global $kz_db_version, $wpdb
|
|
|
85 |
$current_version = get_site_option( 'kz_db_version' );
|
86 |
//update_site_option('kz_db_version', '1.0.4'); exit;
|
87 |
// var_dump($table_name); exit;
|
@@ -92,16 +93,25 @@ function myplugin_update_db_check() {
|
|
92 |
if(empty($row)){
|
93 |
$x = $wpdb->query("ALTER TABLE $table_name ADD cwa_type varchar (10) ");
|
94 |
$updaterow = $wpdb->get_results( "SELECT id FROM $table_name");
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
}
|
100 |
|
101 |
}
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
}
|
104 |
|
|
|
105 |
run_plugin_name();
|
106 |
}
|
107 |
add_action( 'plugins_loaded', 'myplugin_update_db_check' );
|
16 |
* Plugin Name: WP Custom Widget area
|
17 |
* Plugin URI: http://kishorkhambu.com.np/plugins/
|
18 |
* Description: A wordpress plugin to create custom dynamic widget area.
|
19 |
+
* Version: 1.2.5
|
20 |
* Author: Kishor Khambu
|
21 |
* Author URI: http://kishorkhambu.com.np
|
22 |
* License: GPL-2.0+
|
81 |
|
82 |
|
83 |
function myplugin_update_db_check() {
|
84 |
+
global $kz_db_version, $wpdb;
|
85 |
+
$table_name = TABLE_NAME;
|
86 |
$current_version = get_site_option( 'kz_db_version' );
|
87 |
//update_site_option('kz_db_version', '1.0.4'); exit;
|
88 |
// var_dump($table_name); exit;
|
93 |
if(empty($row)){
|
94 |
$x = $wpdb->query("ALTER TABLE $table_name ADD cwa_type varchar (10) ");
|
95 |
$updaterow = $wpdb->get_results( "SELECT id FROM $table_name");
|
96 |
+
foreach ($updaterow as $data) {
|
97 |
+
# code...
|
98 |
+
$up = $wpdb->update($table_name, array('cwa_type'=> 'widget'), array('id'=>$data->id));
|
99 |
+
}
|
100 |
}
|
101 |
|
102 |
}
|
103 |
+
|
104 |
+
//new updates
|
105 |
+
if(!!$current_version && $current_version < '1.2.5'){
|
106 |
+
$row = $wpdb->get_results( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '$table_name' AND column_name = 'cwa_type'" );
|
107 |
+
if(empty($row)){
|
108 |
+
$x = $wpdb->query("ALTER TABLE $table_name MODIFY COLUMN cwa_widget_wrapper text, MODIFY COLUMN cwa_widget_header_wrapper text ");
|
109 |
+
}
|
110 |
+
|
111 |
+
}
|
112 |
}
|
113 |
|
114 |
+
|
115 |
run_plugin_name();
|
116 |
}
|
117 |
add_action( 'plugins_loaded', 'myplugin_update_db_check' );
|