Automattic / Automattic/jetpack

backtick column names

Open
#48,202 4 comments 0 reactions 1 assignee Claimed by @StefMattana View on GitHub
[Feature] Sitemaps Bug Needs triage
Dominant language
PHP
Stars
1.8k
Forks
898
Avg merge
1d 18h
Merged PRs (30d)
774

Description

### Impacted plugin

Jetpack

### Quick summary

I would like to request a code change. I would like to request that backticks be added to the column names in the method: Jetpack_Sitemap_Librarian::get_sanitized_post_columns($wpdb). I’m sure it can be done different ways, but I solved it temporarily by changing line 483 to:

```
return '`' . implode( '`,`', array_map( 'esc_sql', $columns ) ) . '`';
```

I was getting a sql error due to having a column name that is a keyword (order) in my wp_posts table. I’m not sure what plugin added that column in the past (nor whether it is even used still), but surrounding the column names with backticks takes care of the problem.

This problem was discovered when it conflicted with Solid Backups Legacy plugin causing the backup to fail.

Thank you for considering this change.

### Steps to reproduce

Add a column to the wp_posts table which is a reserved word.

### Site owner impact

Fewer than 20% of the total website/platform users

### Severity

Major

### What other impact(s) does this issue have?

_No response_

### If a workaround is available, please outline it here.

In Jetpack_Sitemap_Librarian::get_sanitized_post_columns($wpdb),
change line 483 to:

```
return '`' . implode( '`,`', array_map( 'esc_sql', $columns ) ) . '`';
```

### Platform (Simple and/or Atomic)

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.