Say what? - Version 1.0

Version Description

Allow strings with context to be replaced

Download this release

Release Info

Developer leewillis77
Plugin Icon 128x128 Say what?
Version 1.0
Comparing to
See all releases

Code changes from version 0.9.3 to 1.0

css/admin.css CHANGED
@@ -1,9 +1,12 @@
1
- .wp-list-table .column-orig_string {
2
- width: 35%;
3
- }
4
- .wp-list-table .column-replacement_string{
5
- width: 35%;
6
  }
7
  .wp-list-table .column-domain {
8
- width: 15%;
9
  }
 
 
 
 
1
+ .wp-list-table .column-orig_string,
2
+ .wp-list-table .column-context,
3
+ .wp-list-table .column-replacement_string {
4
+ width: 26%;
 
5
  }
6
  .wp-list-table .column-domain {
7
+ width: 12%;
8
  }
9
+ .wp-list-table .edit_links,
10
+ .wp-list-table .delete_links {
11
+ width: 5%;
12
+ }
html/say_what_admin_addedit.php CHANGED
@@ -18,6 +18,10 @@
18
  <label for="say_what_domain"><?php _e( 'Text domain', 'say_what' ); ?></label> <a href="http://plugins.leewillis.co.uk/doc_post/adding-string-replacement/"><i class="dashicons dashicons-info">&nbsp;</i></a><br/>
19
  <input type="text" name="say_what_domain" value="<?php echo esc_attr( $replacement->domain ); ?>"><br/>
20
  </p>
 
 
 
 
21
  <p>
22
  <label for="say_what_replacement_string"><?php _e( 'Replacement string', 'say_what' ); ?></label><br/>
23
  <input type="text" name="say_what_replacement_string" size="120" value="<?php echo esc_attr( $replacement->replacement_string ); ?>"><br/>
18
  <label for="say_what_domain"><?php _e( 'Text domain', 'say_what' ); ?></label> <a href="http://plugins.leewillis.co.uk/doc_post/adding-string-replacement/"><i class="dashicons dashicons-info">&nbsp;</i></a><br/>
19
  <input type="text" name="say_what_domain" value="<?php echo esc_attr( $replacement->domain ); ?>"><br/>
20
  </p>
21
+ <p>
22
+ <label for="say_what_context"><?php _e( 'Text context', 'say_what' ); ?></label> <a href="http://plugins.leewillis.co.uk/doc_post/replacing-wordpress-strings-context/"><i class="dashicons dashicons-info">&nbsp;</i></a><br/>
23
+ <input type="text" name="say_what_context" value="<?php echo esc_attr( $replacement->context ); ?>"><br/>
24
+ </p>
25
  <p>
26
  <label for="say_what_replacement_string"><?php _e( 'Replacement string', 'say_what' ); ?></label><br/>
27
  <input type="text" name="say_what_replacement_string" size="120" value="<?php echo esc_attr( $replacement->replacement_string ); ?>"><br/>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.leewillis.co.uk/wordpress-plugins/?utm_source=wordpress&
4
  Tags: string, change, translation
5
  Requires at least: 3.5
6
  Tested up to: 3.5.1
7
- Stable tag: 0.9.3
8
 
9
  == Description ==
10
  An easy-to-use plugin that allows you to alter strings on your site without editing WordPress core, or plugin code. Simply enter the current string, and what you want to replace it with and the plugin will automatically do the rest!
@@ -38,6 +38,9 @@ You can either have a guess, or checkout the plugin in question's source code, t
38
 
39
  == Changelog ==
40
 
 
 
 
41
  = 0.9.3 =
42
  Documentation improvements
43
 
4
  Tags: string, change, translation
5
  Requires at least: 3.5
6
  Tested up to: 3.5.1
7
+ Stable tag: 1.0
8
 
9
  == Description ==
10
  An easy-to-use plugin that allows you to alter strings on your site without editing WordPress core, or plugin code. Simply enter the current string, and what you want to replace it with and the plugin will automatically do the rest!
38
 
39
  == Changelog ==
40
 
41
+ = 1.0 =
42
+ Allow strings with context to be replaced
43
+
44
  = 0.9.3 =
45
  Documentation improvements
46
 
say-what-admin.php CHANGED
@@ -1,269 +1,199 @@
1
  <?php
2
 
3
-
4
-
5
  if ( ! defined( 'ABSPATH' ) )
6
  exit; // Exit if accessed directly
7
 
8
-
9
  /**
10
  * Say What admin class - controller for all of the admin pages
11
  */
12
  class say_what_admin {
13
 
14
-
15
-
16
  private $settings;
17
 
18
-
19
-
20
  /**
21
  * Constructor
22
  */
23
- function __construct($settings) {
24
-
25
  $this->settings = $settings;
26
- add_action( 'admin_menu', array ( $this, 'admin_menu' ) );
27
- add_action ( 'admin_init', array ( $this, 'admin_init' ) );
28
-
29
  }
30
 
31
-
32
-
33
  /**
34
  * Admin init actions. Takes care of saving stuff before redirects
35
  */
36
  public function admin_init() {
37
-
38
  if ( isset ( $_POST['say_what_save'] ) ) {
39
  $this->save();
40
  }
41
-
42
  if ( isset ( $_GET['say_what_action'] ) && ( $_GET['say_what_action'] == 'delete-confirmed' ) ) {
43
  $this->admin_delete_confirmed();
44
  }
45
-
46
  }
47
 
48
-
49
-
50
  /**
51
  * Register the menu item for the admin pages
52
  */
53
  public function admin_menu() {
54
-
55
- if ( current_user_can ( 'manage_options' ) ) {
56
-
57
- $page = add_management_page ( __('Text changes', 'say_what'),
58
- __('Text changes', 'say_what'),
59
- 'manage_options',
60
- 'say_what_admin',
61
- array ( $this, 'admin' ) );
62
-
63
- if ( isset ( $_GET['page'] ) && $_GET['page'] == 'say_what_admin' ) {
64
- add_action('admin_print_styles-' . $page, array ( &$this, 'enqueue_scripts' ) );
65
  }
66
-
67
  }
68
-
69
  }
70
 
71
-
72
-
73
  /**
74
  * Add CSS / javascript to admin pages
75
  */
76
  public function enqueue_scripts() {
77
-
78
- wp_register_style ( 'say_what_admin_css', plugins_url().'/say-what/css/admin.css', array() );
79
- wp_enqueue_style ( 'say_what_admin_css' );
80
-
81
  }
82
 
83
-
84
-
85
  /**
86
  * The main admin page controller
87
  */
88
  public function admin() {
89
-
90
  $action = isset( $_GET['say_what_action'] ) ? $_GET['say_what_action'] : 'list';
91
  switch ( $action ) {
92
-
93
  case 'addedit':
94
  $this->admin_addedit();
95
  break;
96
-
97
  case 'delete':
98
  $this->admin_delete();
99
  break;
100
-
101
  case 'list':
102
  default:
103
  $this->admin_list();
104
  break;
105
-
106
  }
107
-
108
  }
109
 
110
-
111
-
112
  /**
113
  * Render the list of currently configured replacement strings
114
  */
115
  public function admin_list() {
116
-
117
  require_once('html/say_what_admin_list.php');
118
-
119
  }
120
 
121
-
122
-
123
  /**
124
  * Show the page asking the user to confirm deletion
125
  */
126
  public function admin_delete() {
127
-
128
  global $wpdb, $table_prefix;
129
-
130
- if ( ! wp_verify_nonce ( $_GET['nonce'], 'swdelete' ) ) {
131
- wp_die ( __("Did you really mean to do that? Please go back and try again.", 'say_what') );
132
  }
133
-
134
  if ( isset ( $_GET['id'] ) ) {
135
-
136
  $sql = "SELECT * FROM {$table_prefix}say_what_strings WHERE string_id = %d";
137
- $replacement = $wpdb->get_row ( $wpdb->prepare ( $sql, $_GET['id'] ) );
138
-
139
  }
140
-
141
  if ( ! $replacement ) {
142
- wp_die ( __("Did you really mean to do that? Please go back and try again.", 'say_what') );
143
  }
144
-
145
  require_once('html/say_what_admin_delete.php');
146
-
147
  }
148
 
149
-
150
-
151
  /**
152
  * Show the page asking the user to confirm deletion
153
  */
154
  public function admin_delete_confirmed() {
155
-
156
  global $wpdb, $table_prefix;
157
-
158
- if ( ! wp_verify_nonce ( $_GET['nonce'], 'swdelete' ) ||
159
- empty ( $_GET['id'] ) ) {
160
- wp_die ( __("Did you really mean to do that? Please go back and try again.", 'say_what') );
161
  }
162
-
163
  $sql = "DELETE FROM {$table_prefix}say_what_strings WHERE string_id = %d";
164
- $wpdb->query ( $wpdb->prepare ( $sql, $_GET['id'] ) );
165
-
166
  wp_redirect( 'tools.php?page=say_what_admin', '303' );
167
  die();
168
-
169
  }
170
 
171
-
172
-
173
  /**
174
  * Render the add/edit page for a replacement
175
  */
176
  public function admin_addedit() {
177
-
178
  global $wpdb, $table_prefix;
179
-
180
  $replacement = false;
181
-
182
  if ( isset ( $_GET['id'] ) ) {
183
-
184
  $sql = "SELECT * FROM {$table_prefix}say_what_strings WHERE string_id = %d";
185
- $replacement = $wpdb->get_row ( $wpdb->prepare ( $sql, $_GET['id'] ) );
186
-
187
  }
188
-
189
  if ( ! $replacement ) {
190
  $replacement = new stdClass();
191
  $replacement->string_id = '';
192
  $replacement->orig_string = '';
193
  $replacement->replacement_string = '';
194
  $replacement->domain = '';
 
195
  }
196
-
197
  require_once('html/say_what_admin_addedit.php');
198
-
199
  }
200
 
201
-
202
-
203
  /**
204
  * Something on the admin pages needs saved. Handle it here
205
  * Output error/warning messages as required
206
  */
207
  private function save() {
208
-
209
  global $wpdb, $table_prefix;
210
-
211
- if ( ! wp_verify_nonce ($_POST['nonce'], 'swaddedit' ) ) {
212
- wp_die ( __("Did you really mean to do that? Please go back and try again.", 'say_what') );
213
  }
214
-
215
  $_POST = stripslashes_deep( $_POST );
216
-
217
  if ( isset ( $_POST['say_what_string_id'] ) ) {
218
-
219
  $sql = "UPDATE {$table_prefix}say_what_strings
220
  SET orig_string = %s,
221
  replacement_string = %s,
222
- domain = %s
 
223
  WHERE string_id = %d";
224
-
225
- $wpdb->query ( $wpdb->prepare ( $sql,
226
- $_POST['say_what_orig_string'],
227
- $_POST['say_what_replacement_string'],
228
- $_POST['say_what_domain'],
229
- $_POST['say_what_string_id']
230
- )
 
 
231
  );
232
-
233
  } else {
234
-
235
  $sql = "INSERT INTO {$table_prefix}say_what_strings
236
  VALUES ( NULL,
 
237
  %s,
238
  %s,
239
  %s )";
240
 
241
- $wpdb->query ( $wpdb->prepare ( $sql,
242
- $_POST['say_what_orig_string'],
243
- $_POST['say_what_domain'],
244
- $_POST['say_what_replacement_string']
245
- )
 
 
 
246
  );
247
-
248
  }
249
-
250
  wp_redirect( 'tools.php?page=say_what_admin', '303' );
251
  die();
252
-
253
  }
254
 
255
-
256
-
257
  /**
258
  * Show the current list of configured replacements.
259
  */
260
  private function show_current() {
261
-
262
  require_once ( 'say-what-list-table.class.php' );
263
- $list_table_instance = new say_what_list_table ( $this->settings );
264
  $list_table_instance->prepare_items();
265
  $list_table_instance->display();
266
-
267
  }
268
 
269
  }
1
  <?php
2
 
 
 
3
  if ( ! defined( 'ABSPATH' ) )
4
  exit; // Exit if accessed directly
5
 
 
6
  /**
7
  * Say What admin class - controller for all of the admin pages
8
  */
9
  class say_what_admin {
10
 
 
 
11
  private $settings;
12
 
 
 
13
  /**
14
  * Constructor
15
  */
16
+ function __construct( $settings ) {
 
17
  $this->settings = $settings;
18
+ add_action( 'admin_menu', array( $this, 'admin_menu' ) );
19
+ add_action( 'admin_init', array( $this, 'admin_init' ) );
 
20
  }
21
 
 
 
22
  /**
23
  * Admin init actions. Takes care of saving stuff before redirects
24
  */
25
  public function admin_init() {
 
26
  if ( isset ( $_POST['say_what_save'] ) ) {
27
  $this->save();
28
  }
 
29
  if ( isset ( $_GET['say_what_action'] ) && ( $_GET['say_what_action'] == 'delete-confirmed' ) ) {
30
  $this->admin_delete_confirmed();
31
  }
 
32
  }
33
 
 
 
34
  /**
35
  * Register the menu item for the admin pages
36
  */
37
  public function admin_menu() {
38
+ if ( current_user_can( 'manage_options' ) ) {
39
+ $page = add_management_page(
40
+ __( 'Text changes', 'say_what' ),
41
+ __( 'Text changes', 'say_what' ),
42
+ 'manage_options',
43
+ 'say_what_admin',
44
+ array( $this, 'admin' )
45
+ );
46
+ if ( isset( $_GET['page'] ) && $_GET['page'] == 'say_what_admin' ) {
47
+ add_action( 'admin_print_styles-' . $page, array( $this, 'enqueue_scripts' ) );
 
48
  }
 
49
  }
 
50
  }
51
 
 
 
52
  /**
53
  * Add CSS / javascript to admin pages
54
  */
55
  public function enqueue_scripts() {
56
+ wp_register_style( 'say_what_admin_css', plugins_url() . '/say-what/css/admin.css', array() );
57
+ wp_enqueue_style( 'say_what_admin_css' );
 
 
58
  }
59
 
 
 
60
  /**
61
  * The main admin page controller
62
  */
63
  public function admin() {
 
64
  $action = isset( $_GET['say_what_action'] ) ? $_GET['say_what_action'] : 'list';
65
  switch ( $action ) {
 
66
  case 'addedit':
67
  $this->admin_addedit();
68
  break;
 
69
  case 'delete':
70
  $this->admin_delete();
71
  break;
 
72
  case 'list':
73
  default:
74
  $this->admin_list();
75
  break;
 
76
  }
 
77
  }
78
 
 
 
79
  /**
80
  * Render the list of currently configured replacement strings
81
  */
82
  public function admin_list() {
 
83
  require_once('html/say_what_admin_list.php');
 
84
  }
85
 
 
 
86
  /**
87
  * Show the page asking the user to confirm deletion
88
  */
89
  public function admin_delete() {
 
90
  global $wpdb, $table_prefix;
91
+ if ( ! wp_verify_nonce( $_GET['nonce'], 'swdelete' ) ) {
92
+ wp_die( __( 'Did you really mean to do that? Please go back and try again.', 'say_what' ) );
 
93
  }
 
94
  if ( isset ( $_GET['id'] ) ) {
 
95
  $sql = "SELECT * FROM {$table_prefix}say_what_strings WHERE string_id = %d";
96
+ $replacement = $wpdb->get_row( $wpdb->prepare( $sql, $_GET['id'] ) );
 
97
  }
 
98
  if ( ! $replacement ) {
99
+ wp_die( __( 'Did you really mean to do that? Please go back and try again.', 'say_what' ) );
100
  }
 
101
  require_once('html/say_what_admin_delete.php');
 
102
  }
103
 
 
 
104
  /**
105
  * Show the page asking the user to confirm deletion
106
  */
107
  public function admin_delete_confirmed() {
 
108
  global $wpdb, $table_prefix;
109
+ if ( ! wp_verify_nonce( $_GET['nonce'], 'swdelete' ) ||
110
+ empty( $_GET['id'] ) ) {
111
+ wp_die( __( 'Did you really mean to do that? Please go back and try again.', 'say_what' ) );
 
112
  }
 
113
  $sql = "DELETE FROM {$table_prefix}say_what_strings WHERE string_id = %d";
114
+ $wpdb->query( $wpdb->prepare( $sql, $_GET['id'] ) );
 
115
  wp_redirect( 'tools.php?page=say_what_admin', '303' );
116
  die();
 
117
  }
118
 
 
 
119
  /**
120
  * Render the add/edit page for a replacement
121
  */
122
  public function admin_addedit() {
 
123
  global $wpdb, $table_prefix;
 
124
  $replacement = false;
 
125
  if ( isset ( $_GET['id'] ) ) {
 
126
  $sql = "SELECT * FROM {$table_prefix}say_what_strings WHERE string_id = %d";
127
+ $replacement = $wpdb->get_row( $wpdb->prepare( $sql, $_GET['id'] ) );
 
128
  }
 
129
  if ( ! $replacement ) {
130
  $replacement = new stdClass();
131
  $replacement->string_id = '';
132
  $replacement->orig_string = '';
133
  $replacement->replacement_string = '';
134
  $replacement->domain = '';
135
+ $replacement->context = '';
136
  }
 
137
  require_once('html/say_what_admin_addedit.php');
 
138
  }
139
 
 
 
140
  /**
141
  * Something on the admin pages needs saved. Handle it here
142
  * Output error/warning messages as required
143
  */
144
  private function save() {
 
145
  global $wpdb, $table_prefix;
146
+ if ( ! wp_verify_nonce( $_POST['nonce'], 'swaddedit' ) ) {
147
+ wp_die( __( 'Did you really mean to do that? Please go back and try again.', 'say_what' ) );
 
148
  }
 
149
  $_POST = stripslashes_deep( $_POST );
 
150
  if ( isset ( $_POST['say_what_string_id'] ) ) {
 
151
  $sql = "UPDATE {$table_prefix}say_what_strings
152
  SET orig_string = %s,
153
  replacement_string = %s,
154
+ domain = %s,
155
+ context = %s
156
  WHERE string_id = %d";
157
+ $wpdb->query(
158
+ $wpdb->prepare(
159
+ $sql,
160
+ $_POST['say_what_orig_string'],
161
+ $_POST['say_what_replacement_string'],
162
+ $_POST['say_what_domain'],
163
+ $_POST['say_what_context'],
164
+ $_POST['say_what_string_id']
165
+ )
166
  );
 
167
  } else {
 
168
  $sql = "INSERT INTO {$table_prefix}say_what_strings
169
  VALUES ( NULL,
170
+ %s,
171
  %s,
172
  %s,
173
  %s )";
174
 
175
+ $wpdb->query(
176
+ $wpdb->prepare(
177
+ $sql,
178
+ $_POST['say_what_orig_string'],
179
+ $_POST['say_what_domain'],
180
+ $_POST['say_what_replacement_string'],
181
+ $_POST['say_what_context']
182
+ )
183
  );
 
184
  }
 
185
  wp_redirect( 'tools.php?page=say_what_admin', '303' );
186
  die();
 
187
  }
188
 
 
 
189
  /**
190
  * Show the current list of configured replacements.
191
  */
192
  private function show_current() {
 
193
  require_once ( 'say-what-list-table.class.php' );
194
+ $list_table_instance = new say_what_list_table( $this->settings );
195
  $list_table_instance->prepare_items();
196
  $list_table_instance->display();
 
197
  }
198
 
199
  }
say-what-frontend.php CHANGED
@@ -13,21 +13,31 @@ class say_what_frontend {
13
  /**
14
  * Read the settings in and put them into a format optimised for the final filter
15
  */
16
- function __construct($settings) {
17
  foreach ( $settings->replacements as $key => $value ) {
18
  if ( empty ( $value['domain'] ) )
19
- $value['domain'] = 'default';
20
- $this->replacements[$value['domain']][$value['orig_string']] = $value['replacement_string'];
 
 
21
  }
22
- add_filter ( 'gettext', array ( $this, 'gettext' ), 10, 3 );
 
23
  }
24
 
25
  /**
26
- * The main function - optionally perform a string replacement
27
  */
28
- function gettext( $translated, $original, $domain ) {
29
- if ( isset ( $this->replacements[$domain][$original] ) ) {
30
- return $this->replacements[$domain][$original];
 
 
 
 
 
 
 
31
  } else {
32
  return $translated;
33
  }
13
  /**
14
  * Read the settings in and put them into a format optimised for the final filter
15
  */
16
+ function __construct( $settings ) {
17
  foreach ( $settings->replacements as $key => $value ) {
18
  if ( empty ( $value['domain'] ) )
19
+ $value['domain'] = 'sw-default-domain';
20
+ if ( empty ( $value['context'] ) )
21
+ $value['context'] = 'sw-default-context';
22
+ $this->replacements[$value['domain']][$value['orig_string']][$value['context']] = $value['replacement_string'];
23
  }
24
+ add_filter( 'gettext', array( $this, 'gettext' ), 10, 3 );
25
+ add_filter( 'gettext_with_context', array( $this, 'gettext_with_context' ), 10, 4 );
26
  }
27
 
28
  /**
29
+ * Perform a string replacement without context.
30
  */
31
+ public function gettext( $translated, $original, $domain ) {
32
+ return $this->gettext_with_context( $translated, $original, 'sw-default-context', $domain );
33
+ }
34
+
35
+ /**
36
+ * Perform a string replacement with context.
37
+ */
38
+ public function gettext_with_context( $translated, $original, $context, $domain ) {
39
+ if ( isset ( $this->replacements[$domain][$original][$context] ) ) {
40
+ return $this->replacements[$domain][$original][$context];
41
  } else {
42
  return $translated;
43
  }
say-what-list-table.class.php CHANGED
@@ -1,35 +1,24 @@
1
  <?php
2
 
3
-
4
- if ( ! class_exists ( 'WP_List_Table' ) ) {
5
  require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
6
  }
7
 
8
-
9
-
10
  /**
11
  * List table class for the admin pages
12
  */
13
  class say_what_list_table extends WP_List_Table {
14
 
15
-
16
-
17
  private $settings;
18
 
19
-
20
-
21
  /**
22
  * Constructor
23
  */
24
- function __construct ( $settings ) {
25
-
26
  $this->settings = $settings;
27
  parent::__construct();
28
-
29
  }
30
 
31
-
32
-
33
  /**
34
  * Description shown when no replacements configured
35
  */
@@ -37,32 +26,26 @@ class say_what_list_table extends WP_List_Table {
37
  _e( 'No string replacements configured yet.', 'say_what' );
38
  }
39
 
40
-
41
-
42
  /**
43
  * Specify the list of columns in the table
44
  * @return array The list of columns
45
  */
46
  function get_columns(){
47
-
48
  $columns = array(
49
  /*'cb' => 'Checkboxes',*/
50
  'string_id' => 'String replacement ID (Internal)',
51
  'orig_string' => __( 'Original string', 'say_what' ),
52
  'domain' => __( 'Text domain', 'say_what' ),
 
53
  'replacement_string' => __( 'Replacement string', 'say_what' ),
54
  'edit_links' => _x( '', 'Header for edit links on admin list table', 'say_what' ),
55
  'delete_links' => _x( '', 'Header for delete links on admin list table', 'say_what' ),
56
  );
57
  return $columns;
58
-
59
  }
60
 
61
-
62
-
63
  /**
64
  * Retrieve the items for display
65
- * @return [type] [description]
66
  */
67
  function prepare_items() {
68
 
@@ -78,92 +61,75 @@ class say_what_list_table extends WP_List_Table {
78
  // ordering/searhing/pagination easier. This may turn out bad if people have "lots"
79
  $sql = "SELECT * FROM {$table_prefix}say_what_strings";
80
  if ( isset ( $_GET['orderby'] ) ) {
81
-
82
- $sql .= " ORDER BY ".$wpdb->escape ( $_GET['orderby'] );
83
-
84
- if ( isset ( $_GET['order'] ) ) {
85
- $sql .= " ".$wpdb->escape ( $_GET['order'] );
86
  }
87
-
88
  } else {
89
-
90
  $sql .= ' ORDER BY orig_string ASC';
91
  }
92
-
93
- $this->items = $wpdb->get_results ( $sql, ARRAY_A );
94
-
95
  }
96
 
97
-
98
-
99
  /**
100
  * Indicate which columns are sortable
101
  * @return array A list of the columns that are sortable.
102
  */
103
  function get_sortable_columns() {
104
-
105
- return array (
106
- 'orig_string' => array ( 'orig_string', true ),
107
- 'domain' => array ( 'domain', false ),
108
- 'replacement_string' => array ( 'replacement_string', false ) );
109
-
110
  }
111
 
112
-
113
-
114
  /**
115
  * Specify the bulk actions available. Not used currently
116
  */
117
  function get_bulk_actions() {
118
-
119
- // FIXME - implement bulk actions
120
  //$actions = array ( 'delete' => __( 'Delete', 'say_what' ) );
121
-
122
  return array();
123
-
124
  }
125
 
126
-
127
-
128
  /**
129
  * Checkboxes for the rows. Not used while we don't have bulk actions
130
  */
131
- function column_cb ( $item ) {
132
-
133
- return sprintf ( '<input type="checkbox" name="string_id[]" value="%d" />', $item['string_id'] );
134
-
135
  }
136
 
137
-
138
  /**
139
  * Output column data
140
  */
141
- function column_default ( $item, $column_name ) {
142
-
143
  return $item[$column_name];
144
-
145
  }
146
 
147
-
148
-
149
  /**
150
  * Output an edit link for the row
151
  */
152
- function column_edit_links ( $item ) {
153
-
154
- return '<a href="tools.php?page=say_what_admin&amp;say_what_action=addedit&amp;id='.urlencode($item['string_id']).'&amp;nonce='.urlencode(wp_create_nonce('swaddedit')).'">'.__( 'Edit', 'say_what').'</a>';
155
-
 
 
 
 
156
  }
157
 
158
-
159
-
160
  /**
161
  * Output a delete link for the row
162
  */
163
- function column_delete_links ( $item ) {
164
-
165
- return '<a href="tools.php?page=say_what_admin&say_what_action=delete&id='.urlencode($item['string_id']).'&nonce='.urlencode(wp_create_nonce('swdelete')).'">'.__( 'Delete', 'say_what').'</a>';
166
-
 
 
 
 
167
  }
168
 
169
  }
1
  <?php
2
 
3
+ if ( ! class_exists( 'WP_List_Table' ) ) {
 
4
  require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
5
  }
6
 
 
 
7
  /**
8
  * List table class for the admin pages
9
  */
10
  class say_what_list_table extends WP_List_Table {
11
 
 
 
12
  private $settings;
13
 
 
 
14
  /**
15
  * Constructor
16
  */
17
+ function __construct( $settings ) {
 
18
  $this->settings = $settings;
19
  parent::__construct();
 
20
  }
21
 
 
 
22
  /**
23
  * Description shown when no replacements configured
24
  */
26
  _e( 'No string replacements configured yet.', 'say_what' );
27
  }
28
 
 
 
29
  /**
30
  * Specify the list of columns in the table
31
  * @return array The list of columns
32
  */
33
  function get_columns(){
 
34
  $columns = array(
35
  /*'cb' => 'Checkboxes',*/
36
  'string_id' => 'String replacement ID (Internal)',
37
  'orig_string' => __( 'Original string', 'say_what' ),
38
  'domain' => __( 'Text domain', 'say_what' ),
39
+ 'context' => __( 'Text context', 'say_what' ),
40
  'replacement_string' => __( 'Replacement string', 'say_what' ),
41
  'edit_links' => _x( '', 'Header for edit links on admin list table', 'say_what' ),
42
  'delete_links' => _x( '', 'Header for delete links on admin list table', 'say_what' ),
43
  );
44
  return $columns;
 
45
  }
46
 
 
 
47
  /**
48
  * Retrieve the items for display
 
49
  */
50
  function prepare_items() {
51
 
61
  // ordering/searhing/pagination easier. This may turn out bad if people have "lots"
62
  $sql = "SELECT * FROM {$table_prefix}say_what_strings";
63
  if ( isset ( $_GET['orderby'] ) ) {
64
+ $sql .= ' ORDER BY ' . $wpdb->escape( $_GET['orderby'] );
65
+ if ( isset( $_GET['order'] ) ) {
66
+ $sql .= ' ' . $wpdb->escape( $_GET['order'] );
 
 
67
  }
 
68
  } else {
 
69
  $sql .= ' ORDER BY orig_string ASC';
70
  }
71
+ $this->items = $wpdb->get_results( $sql, ARRAY_A );
 
 
72
  }
73
 
 
 
74
  /**
75
  * Indicate which columns are sortable
76
  * @return array A list of the columns that are sortable.
77
  */
78
  function get_sortable_columns() {
79
+ return array(
80
+ 'orig_string' => array( 'orig_string', true ),
81
+ 'domain' => array( 'domain', false ),
82
+ 'context' => array( 'context', false ),
83
+ 'replacement_string' => array( 'replacement_string', false ) );
 
84
  }
85
 
 
 
86
  /**
87
  * Specify the bulk actions available. Not used currently
88
  */
89
  function get_bulk_actions() {
90
+ // @TODO - implement bulk actions
 
91
  //$actions = array ( 'delete' => __( 'Delete', 'say_what' ) );
 
92
  return array();
 
93
  }
94
 
 
 
95
  /**
96
  * Checkboxes for the rows. Not used while we don't have bulk actions
97
  */
98
+ function column_cb( $item ) {
99
+ return sprintf( '<input type="checkbox" name="string_id[]" value="%d" />', $item['string_id'] );
 
 
100
  }
101
 
 
102
  /**
103
  * Output column data
104
  */
105
+ function column_default( $item, $column_name ) {
 
106
  return $item[$column_name];
 
107
  }
108
 
 
 
109
  /**
110
  * Output an edit link for the row
111
  */
112
+ function column_edit_links( $item ) {
113
+ return '<a href="tools.php?page=say_what_admin&amp;say_what_action=addedit&amp;id=' .
114
+ urlencode( $item['string_id'] ) .
115
+ '&amp;nonce=' .
116
+ urlencode( wp_create_nonce( 'swaddedit' ) ) .
117
+ '">' .
118
+ __( 'Edit', 'say_what' ) .
119
+ '</a>';
120
  }
121
 
 
 
122
  /**
123
  * Output a delete link for the row
124
  */
125
+ function column_delete_links( $item ) {
126
+ return '<a href="tools.php?page=say_what_admin&say_what_action=delete&id=' .
127
+ urlencode( $item['string_id'] ) .
128
+ '&nonce=' .
129
+ urlencode( wp_create_nonce( 'swdelete' ) ) .
130
+ '">' .
131
+ __( 'Delete', 'say_what' ) .
132
+ '</a>';
133
  }
134
 
135
  }
say-what-settings.php CHANGED
@@ -1,27 +1,17 @@
1
  <?php
2
 
3
-
4
  if ( ! defined( 'ABSPATH' ) )
5
  exit; // Exit if accessed directly
6
 
7
-
8
-
9
  /**
10
  * Settings class. Possibly overkill at the moment
11
  */
12
  class say_what_settings {
13
-
14
  public $replacements;
15
-
16
  function __construct() {
17
-
18
  global $wpdb, $table_prefix;
19
-
20
  // @TODO - Read other settings in when we have them
21
  $sql = "SELECT * FROM {$table_prefix}say_what_strings";
22
-
23
- $this->replacements = $wpdb->get_results ( $sql, ARRAY_A );
24
-
25
  }
26
-
27
  }
1
  <?php
2
 
 
3
  if ( ! defined( 'ABSPATH' ) )
4
  exit; // Exit if accessed directly
5
 
 
 
6
  /**
7
  * Settings class. Possibly overkill at the moment
8
  */
9
  class say_what_settings {
 
10
  public $replacements;
 
11
  function __construct() {
 
12
  global $wpdb, $table_prefix;
 
13
  // @TODO - Read other settings in when we have them
14
  $sql = "SELECT * FROM {$table_prefix}say_what_strings";
15
+ $this->replacements = $wpdb->get_results( $sql, ARRAY_A );
 
 
16
  }
 
17
  }
say-what.php CHANGED
@@ -4,13 +4,13 @@
4
  Plugin Name: Say What?
5
  Plugin URI: https://github.com/leewillis77/say-what
6
  Description: An easy-to-use plugin that allows you to alter strings on your site without editing WordPress core, or plugin code
7
- Version: 0.9.3
8
  Author: Lee Willis
9
  Author URI: http://www.leewillis.co.uk/
10
  */
11
 
12
  /**
13
- * Copyright (c) 2013 Lee Willis. All rights reserved.
14
  *
15
  * Released under the GPL license
16
  * http://www.opensource.org/licenses/gpl-license.php
@@ -34,83 +34,107 @@ Author URI: http://www.leewillis.co.uk/
34
  if ( ! defined( 'ABSPATH' ) )
35
  exit; // Exit if accessed directly
36
 
37
-
38
  /**
39
  * Main plugin class, responsible for triggering everything
40
  */
41
  class say_what {
42
 
43
-
44
-
45
  private $settings_instance;
46
  private $frontend_instance;
47
  private $admin_instance;
48
-
49
-
50
 
51
  /**
52
  * Constructor
53
  */
54
  public function __construct(){
55
-
56
- add_action ( 'init', array ( $this, 'init' ) );
57
-
58
  require_once ( 'say-what-settings.php' );
59
  $this->settings_instance = new say_what_settings();
60
-
61
  if ( is_admin() ) {
62
-
63
  require_once ( 'say-what-admin.php' );
64
- $this->admin_instance = new say_what_admin ( $this->settings_instance );
65
-
66
  }
67
-
68
  require_once ( 'say-what-frontend.php' );
69
- $this->frontend_instance = new say_what_frontend ( $this->settings_instance );
70
 
 
 
71
  }
72
 
73
-
74
-
75
  /**
76
- * Fires on init()
77
- * Set up translation for the plugin itself
78
  */
79
  public function init() {
 
 
 
 
80
 
81
- $locale = apply_filters ( 'plugin_locale', get_locale(), "say_what");
82
- load_textdomain ( 'say_what', WP_LANG_DIR.'/say_what/say_what-'.$locale.'.mo');
83
- load_plugin_textdomain ( 'say_what', false, basename( dirname( __FILE__ ) ) . '/languages/' );
 
 
 
 
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  }
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  }
88
 
89
-
90
-
91
  /**
92
  * Install function. Create the table to store the replacements
93
  */
94
  function say_what_install() {
95
-
96
  global $wpdb;
97
-
98
- $table_name = $wpdb->prefix . "say_what_strings";
99
-
100
  $sql = "CREATE TABLE $table_name (
101
  `string_id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
102
  `orig_string` text NOT NULL,
103
  `domain` varchar(255),
104
  `replacement_string` text
 
105
  )";
106
-
107
  require_once ABSPATH . 'wp-admin/includes/upgrade.php';
108
- dbDelta($sql);
109
-
110
  }
111
-
112
- register_activation_hook ( __FILE__, 'say_what_install' );
113
-
114
-
115
 
116
  $say_what = new say_what();
4
  Plugin Name: Say What?
5
  Plugin URI: https://github.com/leewillis77/say-what
6
  Description: An easy-to-use plugin that allows you to alter strings on your site without editing WordPress core, or plugin code
7
+ Version: 1.0
8
  Author: Lee Willis
9
  Author URI: http://www.leewillis.co.uk/
10
  */
11
 
12
  /**
13
+ * Copyright (c) 2013-2014 Lee Willis. All rights reserved.
14
  *
15
  * Released under the GPL license
16
  * http://www.opensource.org/licenses/gpl-license.php
34
  if ( ! defined( 'ABSPATH' ) )
35
  exit; // Exit if accessed directly
36
 
 
37
  /**
38
  * Main plugin class, responsible for triggering everything
39
  */
40
  class say_what {
41
 
 
 
42
  private $settings_instance;
43
  private $frontend_instance;
44
  private $admin_instance;
45
+ private $db_version = 2;
 
46
 
47
  /**
48
  * Constructor
49
  */
50
  public function __construct(){
 
 
 
51
  require_once ( 'say-what-settings.php' );
52
  $this->settings_instance = new say_what_settings();
 
53
  if ( is_admin() ) {
 
54
  require_once ( 'say-what-admin.php' );
55
+ $this->admin_instance = new say_what_admin( $this->settings_instance );
 
56
  }
 
57
  require_once ( 'say-what-frontend.php' );
58
+ $this->frontend_instance = new say_what_frontend( $this->settings_instance );
59
 
60
+ add_action( 'init', array( $this, 'init' ) );
61
+ add_action( 'admin_init', array( $this, 'admin_init' ) );
62
  }
63
 
 
 
64
  /**
65
+ * Fires on init().
66
+ * Set up translation for the plugin itself.
67
  */
68
  public function init() {
69
+ $locale = apply_filters( 'plugin_locale', get_locale(), 'say_what' );
70
+ load_textdomain( 'say_what', WP_LANG_DIR.'/say_what/say_what-' . $locale . '.mo' );
71
+ load_plugin_textdomain( 'say_what', false, basename( dirname( __FILE__ ) ) . '/languages/' );
72
+ }
73
 
74
+ /**
75
+ * Fires on admin_init().
76
+ * Check for any required database schema updates.
77
+ */
78
+ public function admin_init() {
79
+ $this->check_db_version();
80
+ }
81
 
82
+ /**
83
+ * Check for pending upgrades, and run them if required.
84
+ */
85
+ public function check_db_version() {
86
+ $current_db_version = (int) get_option( 'say_what_db_version', 1 );
87
+ // Bail if we're already up to date.
88
+ if ( $current_db_version >= $this->db_version ) {
89
+ return;
90
+ }
91
+ // Otherwise, check for, and run updates.
92
+ foreach ( range( $current_db_version + 1, $this->db_version ) as $version ) {
93
+ if ( is_callable( array( $this, 'upgrade_db_to_' . $version ) ) ) {
94
+ $this->{'upgrade_db_to_' . $version}();
95
+ update_option( 'say_what_db_version', $version );
96
+ } else {
97
+ update_option( 'say_what_db_version', $version );
98
+ }
99
+ }
100
  }
101
 
102
+ /**
103
+ * Database v2 upgrade.
104
+ *
105
+ * Add context to database schema.
106
+ */
107
+ private function upgrade_db_to_2() {
108
+ global $wpdb;
109
+ $table_name = $wpdb->prefix . 'say_what_strings';
110
+ $sql = "CREATE TABLE $table_name (
111
+ `string_id` int(11) NOT NULL AUTO_INCREMENT,
112
+ `orig_string` text NOT NULL,
113
+ `domain` varchar(255),
114
+ `replacement_string` text,
115
+ `context` text
116
+ )";
117
+ require_once ABSPATH . 'wp-admin/includes/upgrade.php';
118
+ dbDelta( $sql );
119
+ }
120
  }
121
 
 
 
122
  /**
123
  * Install function. Create the table to store the replacements
124
  */
125
  function say_what_install() {
 
126
  global $wpdb;
127
+ $table_name = $wpdb->prefix . 'say_what_strings';
 
 
128
  $sql = "CREATE TABLE $table_name (
129
  `string_id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
130
  `orig_string` text NOT NULL,
131
  `domain` varchar(255),
132
  `replacement_string` text
133
+ `context` text
134
  )";
 
135
  require_once ABSPATH . 'wp-admin/includes/upgrade.php';
136
+ dbDelta( $sql );
 
137
  }
138
+ register_activation_hook( __FILE__, 'say_what_install' );
 
 
 
139
 
140
  $say_what = new say_what();