PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 All 205 releases
← All changes | core/wpbc-translation.php +30 -16 11.4.3 → 11.9 View file →
@@ -409,11 +409,11 @@
409 409
410 410 /**
411 411 * Translate content. Check for language sections -- [lang=xx_XX] shortcode. // FixIn: 10.0.0.46.
412 412 *
413 - * @param $content_orig
413 + * @param mixed $content_orig Content containing optional language sections.
414 414 *
415 - * @return string
415 + * @return string Translated content, or an empty string for unsupported values.
416 416 */
417 417 function wpbc_lang( $content_orig ) {
418 418 return wpdev_check_for_active_language( $content_orig );
419 419 }
@@ -421,23 +421,31 @@
421 421
422 422 /**
423 423 * Check plugin text for active language section -- [lang=xx_XX] shortcode
424 424 *
425 - * @param string $content_orig
426 - * @return string
425 + * @param mixed $content_orig Content containing optional language sections.
426 + * @return string Translated content, or an empty string for unsupported values.
427 427 * Usage:
428 428 * $text = wpbc_lang( $text );
429 429 */
430 430 function wpdev_check_for_active_language( $content_orig ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
431 431
432 - $content = $content_orig;
432 + if ( is_string( $content_orig ) ) {
433 + $content = $content_orig;
434 + } elseif ( is_scalar( $content_orig ) ) {
435 + $content = (string) $content_orig;
436 + } elseif ( is_object( $content_orig ) && method_exists( $content_orig, '__toString' ) ) {
437 + $content = (string) $content_orig;
438 + } else {
439 + return '';
440 + }
433 441
434 - $languages = array();
435 - $content_ex = explode('[lang',$content);
442 + $languages = array();
443 + $content_ex = explode( '[lang', $content );
436 444
437 445 foreach ( $content_ex as $value ) {
438 446
439 - if ( '=' == substr( $value, 0, 1 ) ) {
447 + if ( '=' === substr( $value, 0, 1 ) ) {
440 448
441 449 $pos_s = strpos( $value, '=' );
442 450 $pos_f = strpos( $value, ']' );
443 451 $key = trim( substr( $value, ( $pos_s + 1 ), ( $pos_f - $pos_s - 1 ) ) );
@@ -448,9 +456,9 @@
448 456 $languages['default'] = $value;
449 457 }
450 458 }
451 459
452 - $locale = wpbc_get_maybe_reloaded_booking_locale(); // $locale = 'fr_FR';
460 + $locale = wpbc_get_maybe_reloaded_booking_locale(); // $locale = 'fr_FR'.
453 461
454 462 if ( isset( $languages[ $locale ] ) ) {
455 463 $return_text = $languages[ $locale ];
456 464 } else {
@@ -763,13 +771,15 @@
763 771
764 772 /**
765 773 * Download translations from wpbookingcalendar.com, unpack it to the ../WPBC_PLUGIN_DIR/languages/' folder
766 774 *
775 + * @param WP_Upgrader_Skin|null $skin Optional authorized upgrader skin.
776 + *
767 777 * @return array|bool|string|WP_Error - result
768 778 */
769 - function wpbc_translation_download_from_wpbc(){
779 + function wpbc_translation_download_from_wpbc( $skin = null ){
770 780
771 - $my_upgrader = wpbc_get_translation_upgrader_obj();
781 + $my_upgrader = wpbc_get_translation_upgrader_obj( $skin );
772 782
773 783 $result = $my_upgrader->run( array(
774 784 'package' => 'https://wpbookingcalendar.com/download/languages/languages.zip', // Please always pass this.
775 785 'destination' => WPBC_PLUGIN_DIR . '/languages/', // WPBC_PLUGIN_DIR . '/lang/', // ...and this.
@@ -786,11 +796,13 @@
786 796
787 797 /**
788 798 * Get translation Upgrader object
789 799 *
800 + * @param WP_Upgrader_Skin|null $skin Optional authorized upgrader skin.
801 + *
790 802 * @return WP_Upgrader obj
791 803 */
792 - function wpbc_get_translation_upgrader_obj(){
804 + function wpbc_get_translation_upgrader_obj( $skin = null ){
793 805
794 806 require_once ABSPATH . 'wp-admin/includes/file.php';
795 807 require_once ABSPATH . 'wp-admin/includes/plugin.php';
796 808 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
@@ -796,11 +808,13 @@
796 808 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
797 809 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
798 810
799 811 require_once WPBC_PLUGIN_DIR . '/core/class/wpbc-class-upgrader-translation-skin.php';
800 - $skin = new WPBC_Upgrader_Translation_Skin(
801 - array( 'skip_header_footer' => true )
802 - );
812 + if ( ! ( $skin instanceof WP_Upgrader_Skin ) ) {
813 + $skin = new WPBC_Upgrader_Translation_Skin(
814 + array( 'skip_header_footer' => true )
815 + );
816 + }
803 817
804 818 $my_upgrader = new WP_Upgrader( $skin );
805 819
806 820 $my_upgrader->init(); // it's required for defining skin messages
@@ -1444,9 +1458,9 @@
1444 1458 * Load translation POT file, and generate PHP file with all translations relative to plugin.
1445 1459 * Link: http://server.com/wp-admin/admin.php?page=wpbc-settings&system_info=show&pot=1#wpbc_general_settings_system_info_metabox
1446 1460 */
1447 1461 function wpbc_pot_to_php() {
1448 -
1462 + return;
1449 1463 /*
1450 1464 * $shortcode = 'wpml';
1451 1465
1452 1466 // Find anything between [wpml] and [/wpml] shortcodes. Magic here: [\s\S]*? - fit to any text