WP Custom Widget area - Version 1.2.0

Version Description

  • Added widget area edit option
Download this release

Release Info

Developer krozero199
Plugin Icon wp plugin WP Custom Widget area
Version 1.2.0
Comparing to
See all releases

Code changes from version 1.1.5 to 1.2.0

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.2.2
6
- Stable tag: 1.1.5
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -72,6 +72,9 @@ It allows you to show custom widget areas and menu locations created with this p
72
 
73
  == Changelog ==
74
 
 
 
 
75
  = 1.1.5 =
76
  * delete script bug fix
77
 
@@ -115,6 +118,9 @@ It allows you to show custom widget areas and menu locations created with this p
115
 
116
  == Upgrade Notice ==
117
 
 
 
 
118
  = 1.1.5 =
119
  * delete script bug fix
120
 
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.3.1
6
+ Stable tag: 1.2.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
72
 
73
  == Changelog ==
74
 
75
+ = 1.2.0 =
76
+ * Added widget area edit option
77
+
78
  = 1.1.5 =
79
  * delete script bug fix
80
 
118
 
119
  == Upgrade Notice ==
120
 
121
+ = 1.2.0 =
122
+ * Added widget area edit option
123
+
124
  = 1.1.5 =
125
  * delete script bug fix
126
 
admin/class-wp-custom-widget-area-admin.php CHANGED
@@ -72,6 +72,7 @@ class Custom_Widget_Area_Admin {
72
  }
73
  public function setup_ajax_request(){
74
  add_action( 'wp_ajax_add_cwa', array($this, 'add_cwa'));
 
75
 
76
  add_action( 'wp_ajax_delete_cwa', array($this, 'delete_cwa'));
77
  add_action( 'wp_ajax_check_cwa_id', array($this, 'check_cwa_id'));
@@ -97,20 +98,31 @@ class Custom_Widget_Area_Admin {
97
  //get parameter $x = $_POST['x'];
98
  $data = $_POST['data'];
99
  //echo "hello : your test is successfull!!!";
100
- //var_dump($_POST);
 
 
 
101
  //var_export($table_name);
102
  if($data['cwa_name'] !== '' && $data['cwa_id'] !== '' ){
103
  $new_data = $this->validatePost();
104
  //echo "id: " .$this->check_cwa_id($new_data['cwa_id']);
105
- if($this->check_cwa_id($new_data['cwa_id'])){
 
 
 
 
106
  $new_data['last_updated'] = date('Y-m-d');
107
  $new_data['cwa_type'] = "widget";
 
108
  //var_dump($new_data);
109
  $row = $wpdb->replace( $table_name, $new_data );
110
 
111
- if($row){
112
  wp_send_json(array('code'=>1, 'message' => $new_data['cwa_id'].' created successfully.'));
113
  }
 
 
 
114
  }
115
  else{
116
  wp_send_json(array('code' => 0, 'message' => 'Widget id already registered'));
@@ -122,6 +134,8 @@ class Custom_Widget_Area_Admin {
122
  }
123
  die(); // this is required to terminate immediately and return a proper response
124
  }
 
 
125
 
126
  public function delete_cwa(){
127
  global $table_name, $wpdb;
@@ -192,9 +206,14 @@ class Custom_Widget_Area_Admin {
192
  global $wpdb;
193
  $cwa_id = $_POST['data']['cwa_id'];
194
  //var_dump($cwa_id);
195
- $sql = "SELECT * FROM $this->table_name WHERE cwa_id='$cwa_id' AND cwa_type='widget'";
196
- $row = $wpdb->get_row( $sql, 'OBJECT');
 
 
 
 
197
  wp_send_json($row);
 
198
  }
199
  public function getall_cwa(){
200
  global $wpdb;
@@ -358,6 +377,9 @@ class Custom_Widget_Area_Admin {
358
 
359
  public function validatePost(){
360
  $data =$_POST['data'];
 
 
 
361
  $new_data = array();
362
  foreach ($data as $key => $value) {
363
  # code...
72
  }
73
  public function setup_ajax_request(){
74
  add_action( 'wp_ajax_add_cwa', array($this, 'add_cwa'));
75
+ add_action( 'wp_ajax_get_cwa', array($this, 'get_cwa'));
76
 
77
  add_action( 'wp_ajax_delete_cwa', array($this, 'delete_cwa'));
78
  add_action( 'wp_ajax_check_cwa_id', array($this, 'check_cwa_id'));
98
  //get parameter $x = $_POST['x'];
99
  $data = $_POST['data'];
100
  //echo "hello : your test is successfull!!!";
101
+ //var_dump($_POST['data']);
102
+ if(isset($data['task']) && $data['task'] == 'update'){
103
+ $data['cwa_id'] = $data['updateid'];
104
+ }
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
+ unset($new_data['task']);
111
+ unset($new_data['updateid']);
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
  //var_dump($new_data);
118
  $row = $wpdb->replace( $table_name, $new_data );
119
 
120
+ if($row && !$task ){
121
  wp_send_json(array('code'=>1, 'message' => $new_data['cwa_id'].' created successfully.'));
122
  }
123
+ elseif($row && $task ){
124
+ wp_send_json(array('code'=>1, 'message' => $new_data['cwa_id'].' updated successfully.'));
125
+ }
126
  }
127
  else{
128
  wp_send_json(array('code' => 0, 'message' => 'Widget id already registered'));
134
  }
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;
206
  global $wpdb;
207
  $cwa_id = $_POST['data']['cwa_id'];
208
  //var_dump($cwa_id);
209
+ array('code' => 0, 'message' => 'Invalid widget id!');
210
+ if(!!$cwa_id){
211
+ $sql = "SELECT * FROM $this->table_name WHERE cwa_id='$cwa_id' AND cwa_type='widget'";
212
+ $row = $wpdb->get_row( $sql, 'OBJECT');
213
+
214
+ }
215
  wp_send_json($row);
216
+ die();
217
  }
218
  public function getall_cwa(){
219
  global $wpdb;
377
 
378
  public function validatePost(){
379
  $data =$_POST['data'];
380
+ if(isset($data['task']) && $data['task'] == 'update'){
381
+ $data['cwa_id'] = $data['updateid'];
382
+ }
383
  $new_data = array();
384
  foreach ($data as $key => $value) {
385
  # code...
admin/css/wp-custom-widget-area-admin.css CHANGED
@@ -195,6 +195,10 @@
195
  width: 100%;
196
  min-width: 500px;
197
  }
 
 
 
 
198
  .no-data{
199
  color: #999;
200
  }
195
  width: 100%;
196
  min-width: 500px;
197
  }
198
+ .help-page h2{
199
+ font-weight: bold;
200
+ color: #343434;
201
+ }
202
  .no-data{
203
  color: #999;
204
  }
admin/img/help/cwa_1_edit.png ADDED
Binary file
admin/img/help/cwa_1_edit_save.png ADDED
Binary file
admin/js/wp-custom-widget-area-admin.js CHANGED
@@ -72,7 +72,30 @@
72
  checkId(self, $(self).val(), 'widget');
73
  });
74
 
75
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  $(document).on('click', '.cwa-delete-link', function(e){
77
  e.preventDefault();
78
  var id = $(this).data('id');
@@ -96,6 +119,7 @@
96
  });
97
  });
98
 
 
99
  $('#cwa-advance-btn').on('click', function(e){
100
  e.preventDefault();
101
  $('#cwa-form .advanced').toggle('show').toggleClass('hide');
@@ -211,7 +235,10 @@
211
  }, 5000);
212
  }
213
  function resetForm(){
 
 
214
  $('.cwa-form input[type="text"]' ).val('');
 
215
  $('.cwa-form .cwa-form-message' ).empty();
216
  }
217
  function runTooltip(){
@@ -224,4 +251,5 @@
224
  trigger: 'click'
225
  });
226
  }
 
227
  })( jQuery );
72
  checkId(self, $(self).val(), 'widget');
73
  });
74
 
75
+ $(document).on('click', '.cwa-edit-link', function(e){
76
+ e.preventDefault();
77
+ var id = $(this).data('id');
78
+
79
+ $.post(ajaxurl,{'action': 'get_cwa', 'data': {'cwa_id': id}}, function(data){
80
+ //console.log(data);
81
+ if(data.message)
82
+ showCwaError(data);
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
+ $('#cwa-form input[name='+k+']').val(data[k]);
90
+ // console.log($('#cwa-form #'+k));
91
+ }
92
+ }
93
+ //console.log(data);
94
+ $('.cwa-form input[type="submit"]' ).val('Update');
95
+ $('.cwa-form input[name="cwa_name"]' ).focus();
96
+ });
97
+ });
98
+
99
  $(document).on('click', '.cwa-delete-link', function(e){
100
  e.preventDefault();
101
  var id = $(this).data('id');
119
  });
120
  });
121
 
122
+
123
  $('#cwa-advance-btn').on('click', function(e){
124
  e.preventDefault();
125
  $('#cwa-form .advanced').toggle('show').toggleClass('hide');
235
  }, 5000);
236
  }
237
  function resetForm(){
238
+ $('.cwa-form input[type="hidden"]' ).val('');
239
+ $('.cwa-form input[disabled]' ).prop('disabled', false);
240
  $('.cwa-form input[type="text"]' ).val('');
241
+ $('.cwa-form input[type="submit"]' ).val('Create');
242
  $('.cwa-form .cwa-form-message' ).empty();
243
  }
244
  function runTooltip(){
251
  trigger: 'click'
252
  });
253
  }
254
+
255
  })( jQuery );
admin/partials/cwa-admin-display.php CHANGED
@@ -67,25 +67,27 @@ class CWA_view
67
  ?>
68
  <form class="cwa-form" method="post" action="" id="cwa-form">
69
  <input type="hidden" name="id">
 
 
70
  <div class="basic">
71
  <div class="cwa-form-row">
72
- <label class="cwa-form-label">Name </label><input type="text" name="cwa_name" placeholder="Widget area name" required> <span class="cwa-form-message"></span>
73
  </div>
74
  <div class="cwa-form-row">
75
- <label class="cwa-form-label">Id </label><input type="text" name="cwa_id" placeholder="Widget area id" required><span class="cwa-form-message"></span>
76
  </div>
77
  <div class="cwa-form-row">
78
- <label class="cwa-form-label">Description</label><input type="text" name="cwa_description" placeholder="Description"><span class="cwa-form-message"></span>
79
  </div>
80
 
81
  </div>
82
  <div class="advanced hide">
83
  <div class="cwa-form-row">
84
- <label class="cwa-form-label">Widget class</label><input type="text" name="cwa_widget_class" placeholder="Class"><span class="cwa-form-message"></span>
85
  </div>
86
  <div class="cwa-form-row">
87
- <label class="cwa-form-label">Before/After widget </label>
88
- <select name="cwa_widget_wrapper">
89
  <option selected value="li">li</option>
90
  <option value="div">div</option>
91
  <option value="aside">aside</option>
@@ -94,11 +96,11 @@ class CWA_view
94
  <span class="cwa-form-message"></span>
95
  </div>
96
  <div class="cwa-form-row">
97
- <label class="cwa-form-label">Widget title class</label><input type="text" name="cwa_widget_header_class" placeholder="Class"><span class="cwa-form-message"></span>
98
  </div>
99
  <div class="cwa-form-row">
100
- <label class="cwa-form-label">Before/After widget title </label>
101
- <select name="cwa_widget_header_wrapper">
102
  <option value="h1">h1</option>
103
  <option selected value="h2">h2</option>
104
  <option value="h3">h3</option>
@@ -159,7 +161,7 @@ class CWA_view
159
  <td><?php echo $table->cwa_widget_class; ?></td>
160
  <td><?php echo $table->cwa_widget_header_class; ?></td>
161
  <td><a href="#get_shortcode" data-id="<?php echo $table->cwa_id; ?>" class="cwa-detail-link tooltip" title="[cwa id='<?php echo $table->cwa_id; ?>']">Get shortcode</a> </td>
162
- <td><a href="#get_code" data-id="<?php echo $table->cwa_id; ?>" class="cwa-detail-link tooltip" title="dynamic_sidebar( '<?php echo $table->cwa_id; ?>' );">Get code</a> / <a href="#delete" data-id="<?php echo $table->cwa_id; ?>" class="cwa-delete-link">Delete</a></td>
163
  </tr>
164
  <?php
165
  $count++;
67
  ?>
68
  <form class="cwa-form" method="post" action="" id="cwa-form">
69
  <input type="hidden" name="id">
70
+ <input type="hidden" name="task">
71
+ <input type="hidden" name="updateid">
72
  <div class="basic">
73
  <div class="cwa-form-row">
74
+ <label class="cwa-form-label" for="cwa_name" >Name </label><input type="text" id="cwa_name" name="cwa_name" placeholder="Widget area name" required> <span class="cwa-form-message"></span>
75
  </div>
76
  <div class="cwa-form-row">
77
+ <label class="cwa-form-label" for="cwa_id">Id </label><input type="text" name="cwa_id" id="cwa_id" placeholder="Widget area id" required><span class="cwa-form-message"></span>
78
  </div>
79
  <div class="cwa-form-row">
80
+ <label class="cwa-form-label" for="cwa_description">Description</label><input type="text" id="cwa_description" name="cwa_description" placeholder="Description"><span class="cwa-form-message"></span>
81
  </div>
82
 
83
  </div>
84
  <div class="advanced hide">
85
  <div class="cwa-form-row">
86
+ <label class="cwa-form-label" for="cwa_widget_class">Widget class</label><input type="text" id="cwa_widget_class" name="cwa_widget_class" placeholder="Class"><span class="cwa-form-message"></span>
87
  </div>
88
  <div class="cwa-form-row">
89
+ <label class="cwa-form-label" for="cwa_widget_wrapper">Before/After widget </label>
90
+ <select name="cwa_widget_wrapper" id="cwa_widget_wrapper">
91
  <option selected value="li">li</option>
92
  <option value="div">div</option>
93
  <option value="aside">aside</option>
96
  <span class="cwa-form-message"></span>
97
  </div>
98
  <div class="cwa-form-row">
99
+ <label class="cwa-form-label" for="cwa_widget_header_class">Widget title class</label><input type="text" id="cwa_widget_header_class" name="cwa_widget_header_class" placeholder="Class"><span class="cwa-form-message"></span>
100
  </div>
101
  <div class="cwa-form-row">
102
+ <label class="cwa-form-label" for="cwa_widget_header_wrapper">Before/After widget title </label>
103
+ <select id="cwa_widget_header_wrapper" name="cwa_widget_header_wrapper">
104
  <option value="h1">h1</option>
105
  <option selected value="h2">h2</option>
106
  <option value="h3">h3</option>
161
  <td><?php echo $table->cwa_widget_class; ?></td>
162
  <td><?php echo $table->cwa_widget_header_class; ?></td>
163
  <td><a href="#get_shortcode" data-id="<?php echo $table->cwa_id; ?>" class="cwa-detail-link tooltip" title="[cwa id='<?php echo $table->cwa_id; ?>']">Get shortcode</a> </td>
164
+ <td><a href="#get_code" data-id="<?php echo $table->cwa_id; ?>" class="cwa-detail-link tooltip" title="dynamic_sidebar( '<?php echo $table->cwa_id; ?>' );">Get code</a> / <a href="#edit" data-id="<?php echo $table->cwa_id; ?>" class="cwa-edit-link">Edit</a> / <a href="#delete" data-id="<?php echo $table->cwa_id; ?>" class="cwa-delete-link">Delete</a></td>
165
  </tr>
166
  <?php
167
  $count++;
admin/partials/cwa-help.php CHANGED
@@ -89,7 +89,26 @@ function help_page(){
89
  where ".mynewwidgetareaclass" is your widget area class.
90
  </li>
91
  </ol>
92
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  </div>
94
  </div>
95
  <div id="custom-menu-location">
89
  where ".mynewwidgetareaclass" is your widget area class.
90
  </li>
91
  </ol>
92
+ <br>
93
+
94
+ </p>
95
+ <h2 style="margin-top: 0;">How to Update existing widget area? [New]</h2>
96
+ <p>
97
+ <ol class="list">
98
+ <li><h4>Click on the edit link. </h4>
99
+ <br>
100
+ <img src="<?php echo $plugin_url;?>/admin/img/help/cwa_1_edit.png" >
101
+ </li>
102
+ <li>
103
+ <h4>Edit widget area field values. </h4><br>
104
+ </li>
105
+ <li>
106
+ <h4>Then submit a changes by clicking update button. </h4>
107
+ <br>
108
+ <img src="<?php echo $plugin_url;?>/admin/img/help/cwa_1_edit_save.png" >
109
+ </li>
110
+ </ol>
111
+ </p>
112
  </div>
113
  </div>
114
  <div id="custom-menu-location">
includes/config.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*plugin configs*/
3
  global $wpdb;
4
- $kz_db_version = '1.1.5';
5
  $table_name = $wpdb->prefix . 'cwa';
6
  $charset_collate = '';
7
  ?>
1
  <?php
2
  /*plugin configs*/
3
  global $wpdb;
4
+ $kz_db_version = '1.2.0';
5
  $table_name = $wpdb->prefix . 'cwa';
6
  $charset_collate = '';
7
  ?>
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.1.5
20
  * Author: Kishor Khambu
21
  * Author URI: http://kishorkhambu.com.np
22
  * License: GPL-2.0+
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.0
20
  * Author: Kishor Khambu
21
  * Author URI: http://kishorkhambu.com.np
22
  * License: GPL-2.0+