ID, 'sp_eap_upload_options', true ); // Bail out, if no content. if ( empty( $content['accordion_content_source'] ) ) { return $strings_to_translate; } // Populate strings to translate with EA strings. foreach ( $content['accordion_content_source'] as $key => $value ) { $title = 'accordion_content_title'; $description = 'accordion_content_description'; $title_key = sprintf( '%s-%s', $key, $title ); $description_key = sprintf( '%s-%s', $key, $description ); $strings_to_translate[ $title_key ] = $value[ $title ] ?? ''; $strings_to_translate[ $description_key ] = $value[ $description ] ?? ''; } return $strings_to_translate; } /** * Update Translated EA Content. * * @since 1.0.0 * * @param mixed[] $post_array Post Array. * @param mixed[] $strings_to_translate Strings to Translate. * @param mixed $response WP_REST_Response or WP_Error. * @param \WP_Post $WP_Post WP Post object. * @param mixed[] $no_translation [ 'source_lang' => 'EN', 'target_lang' => 'RU' ] * @param string $bulk Bulk Bulk * @param string $bulk_action Bulk Action e.g. 'create'. * * @return void */ public function update_translated_ea_content( $post_array, $strings_to_translate, $response, $WP_Post, $no_translation, $bulk, $bulk_action ): void { // Bail out, if not EA post type. if ( 'sp_easy_accordion' !== get_post_type( $WP_Post ) ) { return; } // Get list of WP core keys. $wp_core_keys = [ 'post_title', 'post_content', 'post_excerpt' ]; // Unset core WP keys. foreach ( $wp_core_keys as $key ) { if ( isset( $post_array[ $key ] ) ) { unset( $post_array[ $key ] ); } } $content = get_post_meta( $WP_Post->ID, 'sp_eap_upload_options', true ); // Get accordion content array. $translated_content = []; foreach ( $post_array as $meta_key => $meta_value ) { if ( false === strpos( $meta_key, '-' ) ) { continue; } [ $index, $key ] = explode( '-', $meta_key ) + [ '', '' ]; if ( is_numeric( $index ) ) { $i = absint( $index ); $translated_content[ $i ][ $key ] = $meta_value; /** * Finally, remove post meta that was added * by DeepL Service in the same filter earlier on. * * We do this to ensure that the DB postmeta table * is not polluted with unnecessary post meta that is * not used by Easy Accordion. * * @since 1.0.0 */ delete_post_meta( $WP_Post->ID, $meta_key, $meta_value ); } } // Substitute content for translation. $content['accordion_content_source'] = $translated_content; // Update content. update_post_meta( $WP_Post->ID, 'sp_eap_upload_options', $content ); } }