Skip to content

Commit 8af1e3e

Browse files
committed
Merge pull request #289 from Automattic/fix/error-suppression
Fix error suppression
2 parents 1d7b57d + 7ecdfe6 commit 8af1e3e

File tree

3 files changed

+50
-49
lines changed

3 files changed

+50
-49
lines changed

class-languages.php

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,37 @@ public function options() {
153153
$langs = $this->merge_lang_sets( $this->available_langs, $this->lang_prefs );
154154
// Merge in any POSTed field values
155155
foreach ( $langs as $code => & $lang ) {
156-
$lang->url_prefix = ( @ isset( $_POST[ 'url_prefix_' . $code ] ) ) ? $_POST[ "url_prefix_$code" ] : @ $lang->url_prefix;
157-
if ( ! $lang->url_prefix )
158-
$lang->url_prefix = $lang->url_prefix;
159-
$lang->text_direction = $lang->text_direction;
156+
if ( ! empty( $_POST[ "url_prefix_$code" ] ) ) {
157+
$lang->url_prefix = $_POST[ "url_prefix_$code" ];
158+
} else if ( empty( $lang->url_prefix ) ) {
159+
$parts = explode( '_', $lang->code );
160+
$lang->url_prefix = $parts[0];
161+
}
162+
if ( ! in_array( $lang->text_direction, array( 'ltr', 'rtl' ) ) ) {
163+
// @TODO is this needed?
164+
$lang->text_direction = 'ltr';
165+
}
160166
// This line must come after the text direction value is set
161167
$lang->input_lang_class = ( 'rtl' == $lang->text_direction ) ? 'lang-rtl' : 'lang-ltr' ;
162-
$lang->display_name = ( @ isset( $_POST[ "display_name_$code" ] ) ) ? $_POST[ "display_name_$code" ] : @ $lang->display_name;
163-
if ( ! $lang->display_name )
168+
169+
if ( ! empty( $_POST[ "display_name_$code" ] ) ) {
170+
$lang->display_name = $_POST[ "display_name_$code" ];
171+
} else if ( empty( $lang->display_name ) ) {
164172
$lang->display_name = $lang->name;
173+
}
174+
165175
// Note any url_prefix errors
166-
$lang->url_prefix_error = ( @ $this->errors[ "url_prefix_$code" ] ) ? 'babble-error' : '0' ;
176+
if ( ! empty( $this->errors[ "url_prefix_$code" ] ) ) {
177+
$lang->url_prefix_error = 'babble-error';
178+
} else {
179+
$lang->url_prefix_error = '0';
180+
}
181+
167182
// Flag the active languages
168183
$lang->active = false;
169-
if ( in_array( $code, $this->active_langs ) )
184+
if ( in_array( $code, $this->active_langs ) ) {
170185
$lang->active = true;
186+
}
171187

172188
}
173189
$vars = array();
@@ -342,8 +358,19 @@ protected function maybe_process_languages() {
342358
$url_prefixes = array();
343359
foreach ( $this->available_langs as $code => $lang ) {
344360
$lang_pref = new stdClass;
345-
$lang_pref->display_name = @ $_POST[ 'display_name_' . $code ];
346-
$lang_pref->url_prefix = @ $_POST[ 'url_prefix_' . $code ];
361+
362+
if ( ! empty( $_POST[ 'display_name_' . $code ] ) ) {
363+
$lang_pref->display_name = $_POST[ 'display_name_' . $code ];
364+
} else {
365+
$lang_pref->display_name = $lang->name;
366+
}
367+
368+
if ( ! empty( $_POST[ 'url_prefix_' . $code ] ) ) {
369+
$lang_pref->url_prefix = $_POST[ 'url_prefix_' . $code ];
370+
} else {
371+
$lang_pref->url_prefix = $lang->url_prefix;
372+
}
373+
347374
// Check we don't have more than one language using the same url prefix
348375
if ( array_key_exists( $lang_pref->url_prefix, $url_prefixes ) ) {
349376
$lang_1 = $this->format_code_lang( $code );
@@ -363,8 +390,11 @@ protected function maybe_process_languages() {
363390
if ( ! $this->errors ) {
364391
$langs = $this->merge_lang_sets( $this->available_langs, $this->lang_prefs );
365392
$active_langs = array();
366-
foreach ( (array) @ $_POST[ 'active_langs' ] as $code )
367-
$active_langs[ $langs[ $code ]->url_prefix ] = $code;
393+
if ( ! empty( $_POST[ 'active_langs' ] ) && is_array( $_POST[ 'active_langs' ] ) ) {
394+
foreach ( $_POST[ 'active_langs' ] as $code ) {
395+
$active_langs[ $langs[ $code ]->url_prefix ] = $code;
396+
}
397+
}
368398
if ( count( $active_langs ) < 2 ) {
369399
$this->set_admin_error( __( 'You must set at least two languages as active.', 'babble' ) );
370400
} else {
@@ -377,8 +407,11 @@ protected function maybe_process_languages() {
377407
$this->set_admin_error( __( 'You must set at least your default language as public.', 'babble' ) );
378408
} else {
379409
$public_langs = (array) $_POST[ 'public_langs' ];
380-
if ( ! in_array( @ $_POST[ 'default_lang' ], $public_langs ) )
410+
if ( empty( $_POST[ 'default_lang' ] ) ) {
411+
$this->set_admin_error( __( 'You must choose a default language.', 'babble' ) );
412+
} else if ( ! in_array( $_POST[ 'default_lang' ], $public_langs ) ) {
381413
$this->set_admin_error( __( 'You must set your default language as public.', 'babble' ) );
414+
}
382415
}
383416
}
384417
// Finish up, redirecting if we're all OK
@@ -387,7 +420,7 @@ protected function maybe_process_languages() {
387420
$this->update_option( 'public_langs', $public_langs );
388421

389422
// First the default language
390-
$default_lang = @ $_POST[ 'default_lang' ];
423+
$default_lang = $_POST[ 'default_lang' ];
391424
$this->update_option( 'default_lang', $default_lang );
392425
// Now the prefs
393426
$this->update_option( 'lang_prefs', $lang_prefs );

class-plugin.php

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ class Babble_Plugin {
9595
**/
9696
protected $type;
9797

98-
/**
99-
* Note the name of the function to call when the theme is activated.
100-
*
101-
* @var string
102-
**/
103-
protected $theme_activation_function;
104-
10598
/**
10699
* Initiate!
107100
*
@@ -115,13 +108,8 @@ public function setup( $name, $type = null ) {
115108
$ds = ( defined( 'DIRECTORY_SEPARATOR' ) ) ? DIRECTORY_SEPARATOR : '\\';
116109
$file = str_replace( $ds, '/', __FILE__ );
117110
$plugins_dir = str_replace( $ds, '/', dirname( __FILE__ ) );
118-
// Setup the dir and url for this plugin/theme
119-
if ( 'theme' == $type ) {
120-
// This is a theme
121-
$this->type = 'theme';
122-
$this->dir = get_stylesheet_directory();
123-
$this->url = get_stylesheet_directory_uri();
124-
} elseif ( stripos( $file, $plugins_dir ) !== false || 'plugin' == $type ) {
111+
// Setup the dir and url for this plugin
112+
if ( stripos( $file, $plugins_dir ) !== false || 'plugin' == $type ) {
125113
// This is a plugin
126114
$this->type = 'plugin';
127115

@@ -226,29 +214,9 @@ function remove_filter ($filter, $function = '', $priority = 10, $accepted_args
226214
function register_activation ( $pluginfile = __FILE__, $function = '' ) {
227215
if ( $this->type == 'plugin' ) {
228216
add_action ('activate_'.basename (dirname ($pluginfile)).'/'.basename ($pluginfile), array ($this, $function == '' ? 'activate' : $function));
229-
} elseif ( $this->type == 'theme' ) {
230-
$this->theme_activation_function = ( $function ) ? $function : 'activate';
231-
add_action ('load-themes.php', array ( $this, 'theme_activation' ) );
232217
}
233218
}
234219

235-
/**
236-
* Hack to catch theme activation. We hook the load-themes.php action, look for the
237-
* "activated" GET param and make a big fat assumption if we find it.
238-
*
239-
* @return void
240-
* @author Simon Wheatley
241-
**/
242-
public function theme_activation() {
243-
$activated = (bool) @ $_GET[ 'activated' ];
244-
if ( ! $activated )
245-
return;
246-
if ( ! $this->theme_activation_function )
247-
return;
248-
// Looks like the theme might just have been activated, call the registered function
249-
$this->{$this->theme_activation_function}();
250-
}
251-
252220
/**
253221
* Special deactivation function that takes into account the plugin directory
254222
*

class-switcher-content.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected function populate_links() {
9696
$this->jobs = bbl_get_incomplete_post_jobs( get_option( 'page_for_posts' ) );
9797
} else if ( ( !is_admin() and ( is_tax() || is_category() ) ) || $editing_term ) {
9898
if ( isset( $_REQUEST[ 'tag_ID' ] ) )
99-
$term = get_term( (int) @ $_REQUEST[ 'tag_ID' ], $this->screen->taxonomy );
99+
$term = get_term( absint( $_REQUEST[ 'tag_ID' ] ), $this->screen->taxonomy );
100100
else
101101
$term = get_queried_object();
102102
$this->translations = bbl_get_term_translations( $term->term_id, $term->taxonomy );

0 commit comments

Comments
 (0)