PluginProbe
Polylang / 3.3
Polylang v3.3
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | include/mo.php +29 -13 2.83.3 View file →
@@ -25,26 +25,27 @@
25 25 }
26 26 }
27 27
28 28 /**
29 - * Writes a PLL_MO object into a custom post meta
29 + * Writes a PLL_MO object into a custom post meta.
30 30 *
31 31 * @since 1.2
32 32 *
33 - * @param object $lang The language in which we want to export strings
33 + * @param PLL_Language $lang The language in which we want to export strings.
34 + * @return void
34 35 */
35 36 public function export_to_db( $lang ) {
36 - $this->add_entry( $this->make_entry( '', '' ) ); // Empty string translation, just in case
37 -
38 - // Would be convenient to store the whole object but it would take a huge space in DB
39 - // So let's keep only the strings in an array
37 + /*
38 + * It would be convenient to store the whole object but it would take a huge space in DB.
39 + * So let's keep only the strings in an array.
40 + * The strings are slashed to avoid breaking slashed strings in update_post_meta.
41 + * @see https://codex.wordpress.org/Function_Reference/update_post_meta#Character_Escaping.
42 + */
40 43 $strings = array();
41 44 foreach ( $this->entries as $entry ) {
42 - $strings[] = array( $entry->singular, $this->translate( $entry->singular ) );
45 + $strings[] = wp_slash( array( $entry->singular, $this->translate( $entry->singular ) ) );
43 46 }
44 47
45 - $strings = wp_slash( $strings ); // Avoid breaking slashed strings in update_post_meta. See https://codex.wordpress.org/Function_Reference/update_post_meta#Character_Escaping
46 -
47 48 if ( empty( $lang->mo_id ) ) {
48 49 $post = array(
49 50 'post_title' => 'polylang_mo_' . $lang->term_id,
50 51 'post_status' => 'private', // To avoid a conflict with WP Super Cache. See https://wordpress.org/support/topic/polylang_mo-and-404s-take-2
@@ -57,13 +58,14 @@
57 58 }
58 59 }
59 60
60 61 /**
61 - * Reads a PLL_MO object from a custom post meta
62 + * Reads a PLL_MO object from a custom post meta.
62 63 *
63 64 * @since 1.2
64 65 *
65 - * @param object $lang The language in which we want to get strings
66 + * @param PLL_Language $lang The language in which we want to get strings.
67 + * @return void
66 68 */
67 69 public function import_from_db( $lang ) {
68 70 if ( ! empty( $lang->mo_id ) ) {
69 71 $strings = get_post_meta( $lang->mo_id, '_pll_strings_translations', true );
@@ -75,13 +77,13 @@
75 77 }
76 78 }
77 79
78 80 /**
79 - * Returns the post id of the post storing the strings translations
81 + * Returns the post id of the post storing the strings translations.
80 82 *
81 83 * @since 1.4
82 84 *
83 - * @param object $lang
85 + * @param PLL_Language $lang The language object.
84 86 * @return int
85 87 */
86 88 public static function get_id( $lang ) {
87 89 global $wpdb;
@@ -100,9 +102,23 @@
100 102 /**
101 103 * Invalidate the cache when adding a new language
102 104 *
103 105 * @since 2.0.5
106 + *
107 + * @return void
104 108 */
105 109 public function clean_cache() {
106 110 wp_cache_delete( 'polylang_mo_ids' );
111 + }
112 +
113 + /**
114 + * Deletes a string
115 + *
116 + * @since 2.9
117 + *
118 + * @param string $string The source string to remove from the translations.
119 + * @return void
120 + */
121 + public function delete_entry( $string ) {
122 + unset( $this->entries[ $string ] );
107 123 }
108 124 }