Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle situations where pb_language is not set #738

Merged
merged 1 commit into from
May 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions includes/class-pb-globaltypography.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ function updateGlobalTypographyMixin() {
protected function _getBookLanguage() {

$lang = '';
$book_lang = Book::getBookInformation();
$book_lang = @$book_lang['pb_language'];
$metadata = Book::getBookInformation();
$book_lang = ( isset( $metadata['pb_language'] ) ) ? $metadata['pb_language'] : 'en';

switch ( $book_lang ) {
case 'el': // Ancient Greek
Expand Down
4 changes: 2 additions & 2 deletions includes/modules/export/class-pb-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,8 @@ static function setLocale( $lang ) {
$compare_with = get_available_languages( PB_PLUGIN_DIR . '/languages/' );

$codes = \Pressbooks\L10n\wplang_codes();
$book_lang = Book::getBookInformation();
$book_lang = ( isset( $book_lang['pb_language'] ) ) ? $book_lang['pb_language'] : 'en';
$metadata = Book::getBookInformation();
$book_lang = ( ! empty( $metadata['pb_language'] ) ) ? $metadata['pb_language'] : 'en';
$book_lang = $codes[ $book_lang ];

foreach ( $compare_with as $compare ) {
Expand Down
11 changes: 7 additions & 4 deletions includes/modules/export/indesign/templates/xhtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<?php if ( isset( $meta['pb_author'] ) ) { ?>
<h2><?php echo $meta['pb_author']; ?></h2>
<?php } ?>

<?php if ( isset( $meta['pb_contributing_authors'] ) ) { ?>
<h3><?php echo $meta['pb_contributing_authors']; ?></h3>
<?php } ?>
Expand All @@ -47,11 +47,14 @@
<?php if ( isset( $meta['pb_copyright_year'] ) || isset( $meta['pb_copyright_holder'] ) ) { ?>
<p class="copyright_notice"><strong>Copyright</strong>:
<?php
if ( ! empty( $meta['pb_copyright_year'] ) ) { echo $meta['pb_copyright_year'] . ' ';
if ( ! empty( $meta['pb_copyright_year'] ) ) {
echo $meta['pb_copyright_year'] . ' ';
}
if ( ! empty( $meta['pb_copyright_holder'] ) ) { echo ' by ' . $meta['pb_copyright_holder'] . '. ';
if ( ! empty( $meta['pb_copyright_holder'] ) ) {
echo ' by ' . $meta['pb_copyright_holder'] . '. ';
}
if ( ! empty( $do_copyright_license ) ) { echo $do_copyright_license . '. ';
if ( ! empty( $do_copyright_license ) ) {
echo $do_copyright_license . '. ';
}
?>
</p>
Expand Down
16 changes: 9 additions & 7 deletions includes/pb-l10n.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,23 +412,24 @@ function set_locale( $lang ) {

// Book information
$metadata = \Pressbooks\Book::getBookInformation();
$book_lang = ( ! empty( $metadata['pb_language'] ) ) ? $metadata['pb_language'] : 'en';

if ( is_admin() ) {
// If user locale isn't set, use the book information value.
if ( function_exists( 'wp_get_current_user' ) && ! get_user_option( 'locale' ) ) {
if ( '__UNSET__' == $loc && ! empty( $metadata['pb_language'] ) ) {
if ( ! get_user_option( 'locale' ) ) {
if ( '__UNSET__' == $loc ) {
$locations = \Pressbooks\L10n\wplang_codes();
$loc = $locations[ $metadata['pb_language'] ];
$loc = $locations[ $book_lang ];
}
}
} elseif ( 'wp-signup.php' == @$GLOBALS['pagenow'] ) {
// If we're on the registration page, use the global setting.
$loc = get_site_option( 'WPLANG' );
} else {
// Use the book information value.
if ( '__UNSET__' == $loc && ! empty( $metadata['pb_language'] ) ) {
if ( '__UNSET__' == $loc ) {
$locations = \Pressbooks\L10n\wplang_codes();
$loc = $locations[ $metadata['pb_language'] ];
$loc = $locations[ $book_lang ];
}
}

Expand Down Expand Up @@ -495,8 +496,9 @@ function install_book_locale( $meta_id, $post_id, $meta_key, $meta_value ) {
* @since 3.9.6
*/
function update_user_locale() {
if ( function_exists( 'wp_get_current_user' ) && $locale = get_user_meta( get_current_user_id(), 'user_interface_lang', true ) ) {
if ( 'en_US' !== $locale ) {
if ( function_exists( 'get_user_meta' ) ) {
$locale = get_user_meta( get_current_user_id(), 'user_interface_lang', true );
if ( 'en_US' != $locale ) {
update_user_meta( get_current_user_id(), 'locale', $locale );
require_once( ABSPATH . '/wp-admin/includes/translation-install.php' );
$result = \wp_download_language_pack( $locale );
Expand Down
6 changes: 3 additions & 3 deletions themes-book/pressbooks-book/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function pressbooks_copyright_license() {
$transient = get_transient("license-inf-$id" );
$updated = array( $license, $copyright_holder, $title );
$changed = false;
$lang = $book_meta['pb_language'];
$lang = ( ! empty( $book_meta['pb_language'] ) ) ? $book_meta['pb_language'] : 'en' ;


// Copyright holder, set in order of precedence
Expand All @@ -305,11 +305,11 @@ function pressbooks_copyright_license() {

} elseif ( isset( $book_meta['pb_copyright_holder'] ) ) {
// book copyright holder overrides book author
$copyright_holder = $book_meta['pb_copyright_holder'];
$copyright_holder = $book_meta['pb_copyright_holder'];

} elseif ( isset( $book_meta['pb_author'] ) ) {
// book author is the fallback, default
$copyright_holder = $book_meta['pb_author'];
$copyright_holder = $book_meta['pb_author'];
}

// Copyright license, set in order of precedence
Expand Down