| @@ -25,26 +25,29 @@ | ||
| 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 | 37 | $this->add_entry( $this->make_entry( '', '' ) ); // Empty string translation, just in case |
| 37 | 38 | |
| 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 | |
| 39 | + /* | |
| 40 | + * It would be convenient to store the whole object but it would take a huge space in DB. | |
| 41 | + * So let's keep only the strings in an array. | |
| 42 | + * The strings are slashed to avoid breaking slashed strings in update_post_meta. | |
| 43 | + * @see https://codex.wordpress.org/Function_Reference/update_post_meta#Character_Escaping. | |
| 44 | + */ | |
| 40 | 45 | $strings = array(); |
| 41 | 46 | foreach ( $this->entries as $entry ) { |
| 42 | - $strings[] = array( $entry->singular, $this->translate( $entry->singular ) ); | |
| 47 | + $strings[] = wp_slash( array( $entry->singular, $this->translate( $entry->singular ) ) ); | |
| 43 | 48 | } |
| 44 | 49 | |
| 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 | 50 | if ( empty( $lang->mo_id ) ) { |
| 48 | 51 | $post = array( |
| 49 | 52 | 'post_title' => 'polylang_mo_' . $lang->term_id, |
| 50 | 53 | '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 +60,14 @@ | ||
| 57 | 60 | } |
| 58 | 61 | } |
| 59 | 62 | |
| 60 | 63 | /** |
| 61 | - * Reads a PLL_MO object from a custom post meta | |
| 64 | + * Reads a PLL_MO object from a custom post meta. | |
| 62 | 65 | * |
| 63 | 66 | * @since 1.2 |
| 64 | 67 | * |
| 65 | - * @param object $lang The language in which we want to get strings | |
| 68 | + * @param PLL_Language $lang The language in which we want to get strings. | |
| 69 | + * @return void | |
| 66 | 70 | */ |
| 67 | 71 | public function import_from_db( $lang ) { |
| 68 | 72 | if ( ! empty( $lang->mo_id ) ) { |
| 69 | 73 | $strings = get_post_meta( $lang->mo_id, '_pll_strings_translations', true ); |
| @@ -75,13 +79,13 @@ | ||
| 75 | 79 | } |
| 76 | 80 | } |
| 77 | 81 | |
| 78 | 82 | /** |
| 79 | - * Returns the post id of the post storing the strings translations | |
| 83 | + * Returns the post id of the post storing the strings translations. | |
| 80 | 84 | * |
| 81 | 85 | * @since 1.4 |
| 82 | 86 | * |
| 83 | - * @param object $lang | |
| 87 | + * @param PLL_Language $lang The language object. | |
| 84 | 88 | * @return int |
| 85 | 89 | */ |
| 86 | 90 | public static function get_id( $lang ) { |
| 87 | 91 | global $wpdb; |
| @@ -100,9 +104,23 @@ | ||
| 100 | 104 | /** |
| 101 | 105 | * Invalidate the cache when adding a new language |
| 102 | 106 | * |
| 103 | 107 | * @since 2.0.5 |
| 108 | + * | |
| 109 | + * @return void | |
| 104 | 110 | */ |
| 105 | 111 | public function clean_cache() { |
| 106 | 112 | wp_cache_delete( 'polylang_mo_ids' ); |
| 113 | + } | |
| 114 | + | |
| 115 | + /** | |
| 116 | + * Deletes a string | |
| 117 | + * | |
| 118 | + * @since 2.9 | |
| 119 | + * | |
| 120 | + * @param string $string The source string to remove from the translations. | |
| 121 | + * @return void | |
| 122 | + */ | |
| 123 | + public function delete_entry( $string ) { | |
| 124 | + unset( $this->entries[ $string ] ); | |
| 107 | 125 | } |
| 108 | 126 | } |