Inpsyde\MultilingualPress\Database\TableStringReplacer::replace_string PHP Method

replace_string() public method

Replaces one string with another all given columns of the given table at once.
Since: 3.0.0
public replace_string ( string $table, array $columns, string $search, string $replacement ) : integer
$table string The name of the table to replace the string in.
$columns array The names of all columns to replace the string in.
$search string The string to replace.
$replacement string The replacment.
return integer The number of affected rows.
    public function replace_string($table, array $columns, $search, $replacement);

Usage Example

 /**
  * Updates attachment URLs according to the given arguments
  *
  * @param string $source_url      Source site uploads url.
  * @param string $destination_url Destination site uploads url.
  *
  * @return void
  */
 private function update_attachment_urls($source_url, $destination_url)
 {
     $tables = [$this->db->comments => ['comment_content'], $this->db->posts => ['guid', 'post_content', 'post_content_filtered', 'post_excerpt'], $this->db->term_taxonomy => ['description']];
     array_walk($tables, function (array $columns, $table) use(&$upated, $source_url, $destination_url) {
         $this->table_string_replacer->replace_string($table, $columns, $source_url, $destination_url);
     });
 }
TableStringReplacer