@@ -66,7 +66,7 @@ function bbl_get_current_lang_code() {
66
66
* Given a lang object or lang code, this checks whether the
67
67
* language is public or not.
68
68
*
69
- * @param string $lang_code A language code
69
+ * @param string|object $lang_code A language code or a language object
70
70
* @return boolean True if public
71
71
* @access public
72
72
**/
@@ -77,21 +77,21 @@ function bbl_is_public_lang( $lang_code ) {
77
77
78
78
/**
79
79
* Set the current (content) lang.
80
- *
80
+ *
81
81
* @uses Babble_Locale::switch_to_lang to do the actual work
82
82
* @see switch_to_blog for similarities
83
83
*
84
84
* @param string $lang The language code to switch to
85
- * @return void
85
+ * @return bool Whether the switch was successful
86
86
**/
87
87
function bbl_switch_to_lang ( $ lang ) {
88
88
global $ bbl_locale ;
89
- $ bbl_locale ->switch_to_lang ( $ lang );
89
+ return $ bbl_locale ->switch_to_lang ( $ lang );
90
90
}
91
91
92
92
/**
93
93
* Restore the previous lang.
94
- *
94
+ *
95
95
* @uses Babble_Locale::restore_lang to do the actual work
96
96
* @see restore_current_blog for similarities
97
97
*
@@ -103,11 +103,11 @@ function bbl_restore_lang() {
103
103
}
104
104
105
105
/**
106
- * Get the terms which are the translations for the provided
107
- * term ID. N.B. The returned array of term objects (and false
106
+ * Get the terms which are the translations for the provided
107
+ * term ID. N.B. The returned array of term objects (and false
108
108
* values) will include the term for the term ID passed.
109
- *
110
- * @param int|object $term Either a WP Term object, or a term_id
109
+ *
110
+ * @param int|object $term Either a WP Term object, or a term_id
111
111
* @return array Either an array keyed by the site languages, each key containing false (if no translation) or a WP Post object
112
112
* @access public
113
113
**/
@@ -117,10 +117,10 @@ function bbl_get_term_translations( $term, $taxonomy ) {
117
117
}
118
118
119
119
/**
120
- * Get the posts which are the translation jobs for the provided
120
+ * Get the posts which are the translation jobs for the provided
121
121
* term ID.
122
- *
123
- * @param int|object $term Either a WP Term object, or a term_id
122
+ *
123
+ * @param int|object $term Either a WP Term object, or a term_id
124
124
* @return array An array keyed by the site languages, each key containing a WP Post object
125
125
* @access public
126
126
**/
@@ -134,9 +134,9 @@ function bbl_get_term_jobs( $term, $taxonomy ) {
134
134
* particular language.
135
135
*
136
136
* @param int|object $default_term The term in the default language to create a new translation for, either WP Post object or post ID
137
- * @param string $lang The language code
137
+ * @param string $lang The language code
138
138
* @param string $taxonomy The taxonomy
139
- * @return string The admin URL to create the new translation
139
+ * @return string|WP_Error The admin URL to create the new translation, a `WP_Error` object on failure
140
140
* @access public
141
141
**/
142
142
function bbl_get_new_term_translation_url ( $ default_term , $ lang , $ taxonomy = null ) {
@@ -147,7 +147,7 @@ function bbl_get_new_term_translation_url( $default_term, $lang, $taxonomy = nul
147
147
/**
148
148
* Returns the language code associated with a particular taxonomy.
149
149
*
150
- * @param string $taxonomy The taxonomy to get the language for
150
+ * @param string $taxonomy The taxonomy to get the language for
151
151
* @return string The lang code
152
152
**/
153
153
function bbl_get_taxonomy_lang_code ( $ taxonomy ) {
@@ -156,10 +156,10 @@ function bbl_get_taxonomy_lang_code( $taxonomy ) {
156
156
}
157
157
158
158
/**
159
- * Return the base taxonomy (in the default language) for a
159
+ * Return the base taxonomy (in the default language) for a
160
160
* provided taxonomy.
161
161
*
162
- * @param string $taxonomy The name of a taxonomy
162
+ * @param string $taxonomy The name of a taxonomy
163
163
* @return string The name of the base taxonomy
164
164
**/
165
165
function bbl_get_base_taxonomy ( $ taxonomy ) {
@@ -181,7 +181,7 @@ function bbl_get_taxonomy_in_lang( $taxonomy, $lang_code = null ) {
181
181
182
182
/**
183
183
* Test whether a particular taxonomy is translated or not.
184
- *
184
+ *
185
185
* @param string $taxonomy The name of the taxonomy to check
186
186
* @return bool True if this is a translated taxonomy
187
187
*/
@@ -191,7 +191,7 @@ function bbl_is_translated_taxonomy( $taxonomy ) {
191
191
192
192
/**
193
193
* Test whether a particular post type is translated or not.
194
- *
194
+ *
195
195
* @param string $post_type The name of the post type to check
196
196
* @return bool True if this is a translated post type
197
197
*/
@@ -212,11 +212,11 @@ function bbl_get_taxonomy_slug_in_lang( $slug, $lang_code = null ) {
212
212
}
213
213
214
214
/**
215
- * Get the posts which are the translations for the provided
216
- * post ID. N.B. The returned array of post objects (and false
215
+ * Get the posts which are the translations for the provided
216
+ * post ID. N.B. The returned array of post objects (and false
217
217
* values) will include the post for the post ID passed.
218
- *
219
- * @param int|object $post Either a WP Post object, or a post ID
218
+ *
219
+ * @param int|object $post Either a WP Post object, or a post ID
220
220
* @return array Either an array keyed by the site languages, each key containing false (if no translation) or a WP Post object
221
221
* @access public
222
222
**/
@@ -226,10 +226,10 @@ function bbl_get_post_translations( $post ) {
226
226
}
227
227
228
228
/**
229
- * Get the posts which are the translation jobs for the provided
229
+ * Get the posts which are the translation jobs for the provided
230
230
* post ID.
231
- *
232
- * @param int|object $post Either a WP Post object, or a post ID
231
+ *
232
+ * @param int|object $post Either a WP Post object, or a post ID
233
233
* @return array Either an array keyed by the site languages, each key containing a WP Post object
234
234
* @access public
235
235
**/
@@ -239,10 +239,10 @@ function bbl_get_incomplete_post_jobs( $post ) {
239
239
}
240
240
241
241
/**
242
- * Returns the post ID for the post in the default language from which
242
+ * Returns the post ID for the post in the default language from which
243
243
* this post was translated.
244
244
*
245
- * @param int|object $post Either a WP Post object, or a post ID
245
+ * @param int|object $post Either a WP Post object, or a post ID
246
246
* @return int The ID of the default language equivalent post
247
247
* @access public
248
248
**/
@@ -254,7 +254,7 @@ function bbl_get_default_lang_post( $post ) {
254
254
/**
255
255
* Return the language code for the language a given post is written for/in.
256
256
*
257
- * @param int|object $post Either a WP Post object, or a post ID
257
+ * @param int|object $post Either a WP Post object, or a post ID
258
258
* @return string|object Either a language code, or a WP_Error object
259
259
* @access public
260
260
**/
@@ -268,7 +268,7 @@ function bbl_get_post_lang_code( $post ) {
268
268
* particular language.
269
269
*
270
270
* @param int|object $default_post The post in the default language to create a new translation for, either WP Post object or post ID
271
- * @param string $lang The language code
271
+ * @param string $lang The language code
272
272
* @return string The admin URL to create the new translation
273
273
* @access public
274
274
**/
@@ -278,7 +278,7 @@ function bbl_get_new_post_translation_url( $default_post, $lang ) {
278
278
}
279
279
280
280
/**
281
- * Return the post type name for the equivalent post type for the
281
+ * Return the post type name for the equivalent post type for the
282
282
* supplied original post type in the requested language.
283
283
*
284
284
* @param string $post_type The originating post type
@@ -323,8 +323,8 @@ function bbl_is_page( $page = '' ) {
323
323
/**
324
324
* Returns the post in a particular language
325
325
*
326
- * @param int|object $post Either a WP Post object, or a post ID
327
- * @param string $lang_code The language code for the required language
326
+ * @param int|object $post Either a WP Post object, or a post ID
327
+ * @param string $lang_code The language code for the required language
328
328
* @param boolean $fallback If true: if a post is not available, fallback to the default language content (defaults to true)
329
329
* @return object|boolean The WP Post object, or if $fallback was false and no post then returns false
330
330
**/
@@ -336,9 +336,9 @@ function bbl_get_post_in_lang( $post, $lang_code, $fallback = true ) {
336
336
/**
337
337
* Returns the term in a particular language
338
338
*
339
- * @param int|object $term Either a term object, or a term ID
339
+ * @param int|object $term Either a term object, or a term ID
340
340
* @param string $taxonomy The term taxonomy
341
- * @param string $lang_code The language code for the required language
341
+ * @param string $lang_code The language code for the required language
342
342
* @param boolean $fallback If true: if a term is not available, fallback to the default language content (defaults to true)
343
343
* @return object|boolean The term object, or if $fallback was false and no term then returns false
344
344
**/
@@ -363,7 +363,7 @@ function bbl_get_post_type_slug_in_lang( $slug, $lang_code = null ) {
363
363
/**
364
364
* Echoes the title of a post, in the requested language (if available).
365
365
*
366
- * @param int|object $post Either a WP Post object, or a post ID
366
+ * @param int|object $post Either a WP Post object, or a post ID
367
367
* @param string $lang_code The code for the language the title is requested in
368
368
* @param bool $fallback Whether to provide a fallback title in the default language if the requested language is unavailable (defaults to false)
369
369
* @return void
@@ -375,7 +375,7 @@ function bbl_the_title_in_lang( $post = null, $lang_code = null, $fallback = fal
375
375
/**
376
376
* Returns the title of a post, in the requested language (if available).
377
377
*
378
- * @param int|object $post Either a WP Post object, or a post ID
378
+ * @param int|object $post Either a WP Post object, or a post ID
379
379
* @param string $lang_code The code for the language the title is requested in
380
380
* @param bool $fallback Whether to provide a fallback title in the default language if the requested language is unavailable (defaults to false)
381
381
* @return void
@@ -396,7 +396,7 @@ function bbl_get_the_title_in_lang( $post = null, $lang_code = null, $fallback =
396
396
/**
397
397
* Echoes the permalink of a post, in the requested language (if available).
398
398
*
399
- * @param int|object $post Either a WP Post object, or a post ID
399
+ * @param int|object $post Either a WP Post object, or a post ID
400
400
* @param string $lang_code The code for the language the title is requested in
401
401
* @param bool $fallback Whether to provide a fallback title in the default language if the requested language is unavailable (defaults to false)
402
402
* @return void
@@ -408,7 +408,7 @@ function bbl_the_permalink_in_lang( $post = null, $lang_code = null, $fallback =
408
408
/**
409
409
* Returns the permalink of a post, in the requested language (if available).
410
410
*
411
- * @param int|object $post Either a WP Post object, or a post ID
411
+ * @param int|object $post Either a WP Post object, or a post ID
412
412
* @param string $lang_code The code for the language the title is requested in
413
413
* @param bool $fallback Whether to provide a fallback title in the default language if the requested language is unavailable (defaults to false)
414
414
* @return void
@@ -444,10 +444,10 @@ function bbl_get_post_type_archive_link_in_lang( $post_type, $lang_code = null )
444
444
}
445
445
446
446
/**
447
- * Return the base post type (in the default language) for a
447
+ * Return the base post type (in the default language) for a
448
448
* provided post type.
449
449
*
450
- * @param string $post_type The name of a post type
450
+ * @param string $post_type The name of a post type
451
451
* @return string The name of the base post type
452
452
**/
453
453
function bbl_get_base_post_type ( $ post_type ) {
@@ -469,7 +469,7 @@ function bbl_get_base_post_types() {
469
469
* Returns an array of all the shadow post types associated with
470
470
* this post type.
471
471
*
472
- * @param string $base_post_type The post type to look up shadow post types for
472
+ * @param string $base_post_type The post type to look up shadow post types for
473
473
* @return array The names of all the related shadow post types
474
474
**/
475
475
function bbl_get_shadow_post_types ( $ base_post_type ) {
@@ -480,14 +480,14 @@ function bbl_get_shadow_post_types( $base_post_type ) {
480
480
/**
481
481
* Return the active language objects for the current site. A
482
482
* language object looks like:
483
- * 'ar' =>
483
+ * 'ar' =>
484
484
* object(stdClass)
485
485
* public 'name' => string 'Arabic'
486
486
* public 'code' => string 'ar'
487
487
* public 'url_prefix' => string 'ar'
488
488
* public 'text_direction' => string 'rtl'
489
489
* public 'display_name' => string 'Arabic'
490
- *
490
+ *
491
491
* @uses Babble_Languages::get_active_langs to do the actual work
492
492
*
493
493
* @return array An array of Babble language objects
@@ -500,7 +500,7 @@ function bbl_get_active_langs() {
500
500
/**
501
501
* Returns the requested language object.
502
502
*
503
- * @param string $code A language code, e.g. "fr_BE"
503
+ * @param string $code A language code, e.g. "fr_BE"
504
504
* @return object|boolean A Babble language object
505
505
**/
506
506
function bbl_get_lang ( $ lang_code ) {
@@ -542,16 +542,16 @@ function bbl_get_default_lang() {
542
542
}
543
543
544
544
/**
545
- * Checks whether either the provided language code,
545
+ * Checks whether either the provided language code,
546
546
* if provided, or the current language code are
547
547
* the default language.
548
- *
548
+ *
549
549
* i.e. is this language the default language
550
550
*
551
551
* n.b. the current language could have been switched
552
552
* using bbl_switch_to_lang
553
553
*
554
- * @param string $lang_code The language code to check (optional)
554
+ * @param string $lang_code The language code to check (optional)
555
555
* @return bool True if the default language
556
556
**/
557
557
function bbl_is_default_lang ( $ lang_code = null ) {
@@ -576,7 +576,7 @@ function bbl_get_default_lang_url_prefix() {
576
576
/**
577
577
* Returns the language code for the provided URL prefix.
578
578
*
579
- * @param string $url_prefix The URL prefix to find the language code for
579
+ * @param string $url_prefix The URL prefix to find the language code for
580
580
* @return string The language code, or false
581
581
**/
582
582
function bbl_get_lang_from_prefix ( $ url_prefix ) {
@@ -629,15 +629,15 @@ function bbl_stop_logging() {
629
629
/**
630
630
* Log a message.
631
631
*
632
- * @param string $msg Log this message
632
+ * @param string $msg Log this message
633
+ * @param bool $force If false, logging must have been initiated with bbl_start_logging
633
634
* @return void
634
635
**/
635
- function bbl_log ( $ msg ) {
636
+ function bbl_log ( $ msg, $ force = false ) {
636
637
global $ bbl_log ;
637
- if ( $ bbl_log )
638
+ if ( $ bbl_log || $ force ) {
638
639
$ bbl_log ->log ( $ msg );
639
- else
640
- error_log ( "Full Babble logging unavailable: $ msg " );
640
+ }
641
641
}
642
642
643
643
/**
@@ -649,5 +649,3 @@ function bbl_is_logging() {
649
649
global $ bbl_log ;
650
650
return $ bbl_log ->logging ;
651
651
}
652
-
653
- ?>
0 commit comments