: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace StringLocator\Extension\SQL;
private $override_save = false;
public function __construct() {
add_filter( 'string_locator_save_params', array( $this, 'check_save_parameters' ) );
add_filter( 'string_locator_save_handler', array( $this, 'maybe_handle_save' ) );
* Check the save parameters to determine if the SQL handler should take over the save request.
* @param array $parameters An array of REST API request parameters.
public function check_save_parameters( $parameters ) {
if ( isset( $parameters['file-type'] ) && 'sql' === $parameters['file-type'] ) {
$this->override_save = true;
* Override the save handler if the parameters indicate that the SQL handler should take over.
* @param mixed $handler The class handling the save request.
public function maybe_handle_save( $handler ) {
if ( ! $this->override_save ) {
* Funciton to trigger the save behavior.
* @param array $params An array of save parameters.
* @return array|\array[][]
public function save( $params ) {
$content = $params['string-locator-editor-content'];
* Filter if the save process should be performed or not.
* @attr bool $can_save Can the save be carried out.
* @attr string $content The content to save.
* @attr string $path Path to the file being edited.
$can_save = apply_filters( 'string_locator_pre_save', true, $content, 'sql' );
'notices' => apply_filters( 'string_locator_pre_save_fail_notice', array() ),
if ( 'int' === $params['sql-primary-type'] ) {
$original = $wpdb->get_var(
'SELECT ' . $params['sql-column'] . ' FROM ' . $params['sql-table'] . ' WHERE ' . $params['sql-primary-column'] . ' = %d LIMIT 1', // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- It is not possible to prepare a table or column name, but these are instead validated in `/includes/Search/class-sql.php` before reaching this point.
$params['sql-primary-key']
$original = $wpdb->get_var(
'SELECT ' . $params['sql-column'] . ' FROM ' . $params['sql-table'] . ' WHERE ' . $params['sql-primary-column'] . ' = %s LIMIT 1', // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- It is not possible to prepare a table or column name, but these are instead validated in `/includes/Search/class-sql.php` before reaching this point.
$params['sql-primary-key']
$params['sql-column'] => $content,
$params['sql-primary-column'] => $params['sql-primary-key'],
* Filter if the save process completed as it should or if warnings should be returned.
* @attr bool $save_successful Boolean indicating if the save was successful.
* @attr string $content The edited content.
* @attr string $original The original content.
* @attr string $path The path to the file being edited.
$save_successful = apply_filters( 'string_locator_post_save', true, $content, $original, 'sql' );
* Check the status of the site after making our edits.
* If the site fails, revert the changes to return the sites to its original state
if ( ! $save_successful ) {
$params['sql-column'] => $original,
$params['sql-primary-column'] => $params['sql-primary-key'],
'notices' => apply_filters( 'string_locator_post_save_fail_notice', array() ),
'message' => __( 'The database entry has been updated.', 'string-locator' ),