Skip to content

Commit 4dccf7a

Browse files
committed
Merge branch 'develop' into fix/static-front-page
* develop: (127 commits) Fix merge issues in `class-taxonomy.php` More test coverage for post and term translations. Correctly flush term translation caches. Switch to using transids for term translation cache keys. Travis config: Travis config: Added `sudo: false` to use modern infrastructure Correct a test name. Travis config: Added `sudo: false` to use modern infrastructure Babble_Locale: Use an exploit priority, rather than null Babble_Taxonomies: Change from add_action method to core function Babble_Languages: Change from add_action method to core function Remove the reliance on `$lang.php` and use our static list of RTL languages. See #216. Introduce a static list of RTL languages from GlotPress and Wikipedia. Add tests to check post and term translations after adding a new translation. Use database query numbers as tests to ensure our post and term translation caching is working as expected. Add caching to `Babble_Taxonomies::get_term_translations()`. Avoids a call to `get_objects_in_term()`. See #246. Tests for term translations, and change `Babble_Taxonomies::get_term_translations()` so it returns real term objects. Tests for post translations. See #236. Remove a bunch of unused code. Remove empty post IDs from the `$post_ids` array. Remove unnecessary use of global API functions, use current object methods instead. ...
2 parents d8f495a + cff0b4a commit 4dccf7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2630
-2327
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
.idea
3+
vendor
4+
composer.lock

.travis.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
language: php
2+
sudo: false # Use modern Travis builds – http://docs.travis-ci.com/user/migrating-from-legacy/
3+
4+
notifications:
5+
on_success: never
6+
on_failure: change
7+
8+
php:
9+
- 5.6
10+
- 5.3
11+
- 5.2
12+
- hhvm
13+
14+
env:
15+
# latest stable:
16+
- WP_VERSION=latest WP_MULTISITE=0
17+
- WP_VERSION=latest WP_MULTISITE=1
18+
# previous stable:
19+
- WP_VERSION=4.1 WP_MULTISITE=0
20+
- WP_VERSION=4.1 WP_MULTISITE=1
21+
# earliest supported:
22+
- WP_VERSION=4.0 WP_MULTISITE=0
23+
- WP_VERSION=4.0 WP_MULTISITE=1
24+
25+
before_script:
26+
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
27+
28+
script:
29+
- if [[ "$WP_VERSION" == "latest" ]]; then if find . -not \( -path ./vendor -prune \) -not \( -path ./features -prune \) -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi;
30+
- phpunit

api.php

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function bbl_get_current_lang_code() {
6666
* Given a lang object or lang code, this checks whether the
6767
* language is public or not.
6868
*
69-
* @param string $lang_code A language code
69+
* @param string|object $lang_code A language code or a language object
7070
* @return boolean True if public
7171
* @access public
7272
**/
@@ -77,21 +77,21 @@ function bbl_is_public_lang( $lang_code ) {
7777

7878
/**
7979
* Set the current (content) lang.
80-
*
80+
*
8181
* @uses Babble_Locale::switch_to_lang to do the actual work
8282
* @see switch_to_blog for similarities
8383
*
8484
* @param string $lang The language code to switch to
85-
* @return void
85+
* @return bool Whether the switch was successful
8686
**/
8787
function bbl_switch_to_lang( $lang ) {
8888
global $bbl_locale;
89-
$bbl_locale->switch_to_lang( $lang );
89+
return $bbl_locale->switch_to_lang( $lang );
9090
}
9191

9292
/**
9393
* Restore the previous lang.
94-
*
94+
*
9595
* @uses Babble_Locale::restore_lang to do the actual work
9696
* @see restore_current_blog for similarities
9797
*
@@ -103,11 +103,11 @@ function bbl_restore_lang() {
103103
}
104104

105105
/**
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
108108
* 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
111111
* @return array Either an array keyed by the site languages, each key containing false (if no translation) or a WP Post object
112112
* @access public
113113
**/
@@ -117,10 +117,10 @@ function bbl_get_term_translations( $term, $taxonomy ) {
117117
}
118118

119119
/**
120-
* Get the posts which are the translation jobs for the provided
120+
* Get the posts which are the translation jobs for the provided
121121
* 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
124124
* @return array An array keyed by the site languages, each key containing a WP Post object
125125
* @access public
126126
**/
@@ -134,9 +134,9 @@ function bbl_get_term_jobs( $term, $taxonomy ) {
134134
* particular language.
135135
*
136136
* @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
138138
* @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
140140
* @access public
141141
**/
142142
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
147147
/**
148148
* Returns the language code associated with a particular taxonomy.
149149
*
150-
* @param string $taxonomy The taxonomy to get the language for
150+
* @param string $taxonomy The taxonomy to get the language for
151151
* @return string The lang code
152152
**/
153153
function bbl_get_taxonomy_lang_code( $taxonomy ) {
@@ -156,10 +156,10 @@ function bbl_get_taxonomy_lang_code( $taxonomy ) {
156156
}
157157

158158
/**
159-
* Return the base taxonomy (in the default language) for a
159+
* Return the base taxonomy (in the default language) for a
160160
* provided taxonomy.
161161
*
162-
* @param string $taxonomy The name of a taxonomy
162+
* @param string $taxonomy The name of a taxonomy
163163
* @return string The name of the base taxonomy
164164
**/
165165
function bbl_get_base_taxonomy( $taxonomy ) {
@@ -181,7 +181,7 @@ function bbl_get_taxonomy_in_lang( $taxonomy, $lang_code = null ) {
181181

182182
/**
183183
* Test whether a particular taxonomy is translated or not.
184-
*
184+
*
185185
* @param string $taxonomy The name of the taxonomy to check
186186
* @return bool True if this is a translated taxonomy
187187
*/
@@ -191,7 +191,7 @@ function bbl_is_translated_taxonomy( $taxonomy ) {
191191

192192
/**
193193
* Test whether a particular post type is translated or not.
194-
*
194+
*
195195
* @param string $post_type The name of the post type to check
196196
* @return bool True if this is a translated post type
197197
*/
@@ -212,11 +212,11 @@ function bbl_get_taxonomy_slug_in_lang( $slug, $lang_code = null ) {
212212
}
213213

214214
/**
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
217217
* 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
220220
* @return array Either an array keyed by the site languages, each key containing false (if no translation) or a WP Post object
221221
* @access public
222222
**/
@@ -226,10 +226,10 @@ function bbl_get_post_translations( $post ) {
226226
}
227227

228228
/**
229-
* Get the posts which are the translation jobs for the provided
229+
* Get the posts which are the translation jobs for the provided
230230
* 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
233233
* @return array Either an array keyed by the site languages, each key containing a WP Post object
234234
* @access public
235235
**/
@@ -239,10 +239,10 @@ function bbl_get_incomplete_post_jobs( $post ) {
239239
}
240240

241241
/**
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
243243
* this post was translated.
244244
*
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
246246
* @return int The ID of the default language equivalent post
247247
* @access public
248248
**/
@@ -254,7 +254,7 @@ function bbl_get_default_lang_post( $post ) {
254254
/**
255255
* Return the language code for the language a given post is written for/in.
256256
*
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
258258
* @return string|object Either a language code, or a WP_Error object
259259
* @access public
260260
**/
@@ -268,7 +268,7 @@ function bbl_get_post_lang_code( $post ) {
268268
* particular language.
269269
*
270270
* @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
272272
* @return string The admin URL to create the new translation
273273
* @access public
274274
**/
@@ -278,7 +278,7 @@ function bbl_get_new_post_translation_url( $default_post, $lang ) {
278278
}
279279

280280
/**
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
282282
* supplied original post type in the requested language.
283283
*
284284
* @param string $post_type The originating post type
@@ -323,8 +323,8 @@ function bbl_is_page( $page = '' ) {
323323
/**
324324
* Returns the post in a particular language
325325
*
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
328328
* @param boolean $fallback If true: if a post is not available, fallback to the default language content (defaults to true)
329329
* @return object|boolean The WP Post object, or if $fallback was false and no post then returns false
330330
**/
@@ -336,9 +336,9 @@ function bbl_get_post_in_lang( $post, $lang_code, $fallback = true ) {
336336
/**
337337
* Returns the term in a particular language
338338
*
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
340340
* @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
342342
* @param boolean $fallback If true: if a term is not available, fallback to the default language content (defaults to true)
343343
* @return object|boolean The term object, or if $fallback was false and no term then returns false
344344
**/
@@ -363,7 +363,7 @@ function bbl_get_post_type_slug_in_lang( $slug, $lang_code = null ) {
363363
/**
364364
* Echoes the title of a post, in the requested language (if available).
365365
*
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
367367
* @param string $lang_code The code for the language the title is requested in
368368
* @param bool $fallback Whether to provide a fallback title in the default language if the requested language is unavailable (defaults to false)
369369
* @return void
@@ -375,7 +375,7 @@ function bbl_the_title_in_lang( $post = null, $lang_code = null, $fallback = fal
375375
/**
376376
* Returns the title of a post, in the requested language (if available).
377377
*
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
379379
* @param string $lang_code The code for the language the title is requested in
380380
* @param bool $fallback Whether to provide a fallback title in the default language if the requested language is unavailable (defaults to false)
381381
* @return void
@@ -396,7 +396,7 @@ function bbl_get_the_title_in_lang( $post = null, $lang_code = null, $fallback =
396396
/**
397397
* Echoes the permalink of a post, in the requested language (if available).
398398
*
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
400400
* @param string $lang_code The code for the language the title is requested in
401401
* @param bool $fallback Whether to provide a fallback title in the default language if the requested language is unavailable (defaults to false)
402402
* @return void
@@ -408,7 +408,7 @@ function bbl_the_permalink_in_lang( $post = null, $lang_code = null, $fallback =
408408
/**
409409
* Returns the permalink of a post, in the requested language (if available).
410410
*
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
412412
* @param string $lang_code The code for the language the title is requested in
413413
* @param bool $fallback Whether to provide a fallback title in the default language if the requested language is unavailable (defaults to false)
414414
* @return void
@@ -444,10 +444,10 @@ function bbl_get_post_type_archive_link_in_lang( $post_type, $lang_code = null )
444444
}
445445

446446
/**
447-
* Return the base post type (in the default language) for a
447+
* Return the base post type (in the default language) for a
448448
* provided post type.
449449
*
450-
* @param string $post_type The name of a post type
450+
* @param string $post_type The name of a post type
451451
* @return string The name of the base post type
452452
**/
453453
function bbl_get_base_post_type( $post_type ) {
@@ -469,7 +469,7 @@ function bbl_get_base_post_types() {
469469
* Returns an array of all the shadow post types associated with
470470
* this post type.
471471
*
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
473473
* @return array The names of all the related shadow post types
474474
**/
475475
function bbl_get_shadow_post_types( $base_post_type ) {
@@ -480,14 +480,14 @@ function bbl_get_shadow_post_types( $base_post_type ) {
480480
/**
481481
* Return the active language objects for the current site. A
482482
* language object looks like:
483-
* 'ar' =>
483+
* 'ar' =>
484484
* object(stdClass)
485485
* public 'name' => string 'Arabic'
486486
* public 'code' => string 'ar'
487487
* public 'url_prefix' => string 'ar'
488488
* public 'text_direction' => string 'rtl'
489489
* public 'display_name' => string 'Arabic'
490-
*
490+
*
491491
* @uses Babble_Languages::get_active_langs to do the actual work
492492
*
493493
* @return array An array of Babble language objects
@@ -500,7 +500,7 @@ function bbl_get_active_langs() {
500500
/**
501501
* Returns the requested language object.
502502
*
503-
* @param string $code A language code, e.g. "fr_BE"
503+
* @param string $code A language code, e.g. "fr_BE"
504504
* @return object|boolean A Babble language object
505505
**/
506506
function bbl_get_lang( $lang_code ) {
@@ -542,16 +542,16 @@ function bbl_get_default_lang() {
542542
}
543543

544544
/**
545-
* Checks whether either the provided language code,
545+
* Checks whether either the provided language code,
546546
* if provided, or the current language code are
547547
* the default language.
548-
*
548+
*
549549
* i.e. is this language the default language
550550
*
551551
* n.b. the current language could have been switched
552552
* using bbl_switch_to_lang
553553
*
554-
* @param string $lang_code The language code to check (optional)
554+
* @param string $lang_code The language code to check (optional)
555555
* @return bool True if the default language
556556
**/
557557
function bbl_is_default_lang( $lang_code = null ) {
@@ -576,7 +576,7 @@ function bbl_get_default_lang_url_prefix() {
576576
/**
577577
* Returns the language code for the provided URL prefix.
578578
*
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
580580
* @return string The language code, or false
581581
**/
582582
function bbl_get_lang_from_prefix( $url_prefix ) {
@@ -629,15 +629,15 @@ function bbl_stop_logging() {
629629
/**
630630
* Log a message.
631631
*
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
633634
* @return void
634635
**/
635-
function bbl_log( $msg ) {
636+
function bbl_log( $msg, $force = false ) {
636637
global $bbl_log;
637-
if ( $bbl_log )
638+
if ( $bbl_log || $force ) {
638639
$bbl_log->log( $msg );
639-
else
640-
error_log( "Full Babble logging unavailable: $msg" );
640+
}
641641
}
642642

643643
/**
@@ -649,5 +649,3 @@ function bbl_is_logging() {
649649
global $bbl_log;
650650
return $bbl_log->logging;
651651
}
652-
653-
?>

0 commit comments

Comments
 (0)