Skip to content

Commit

Permalink
Update 3.0.3 (#142)
Browse files Browse the repository at this point in the history
* Fix version check

* Correctly handle null check

Also handle a multiline replace

* Don’t crash when ‘replace’ is picked for text

* Enable replace button when remove is picked

* Send appropriate replace value to API

When empty string, send null
When ‘remove’ then send empty string

* Version bump to 3.0.3
  • Loading branch information
johngodley authored Aug 14, 2022
1 parent e400d85 commit 0fd315c
Show file tree
Hide file tree
Showing 11 changed files with 331 additions and 186 deletions.
3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ const SVN_SOURCE_FILES = [
'!api-header.md',
'!*.zip',
'!src',
'!src/**'
'!src/**',
'!phpstan.neon'
];

function downloadLocale( locale, wpName, type ) {
Expand Down
6 changes: 3 additions & 3 deletions includes/modifier/modifier-string.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function to_json() {
* @return Array Array of match positions
*/
public function get_replace_positions( $value ) {
if ( ! $this->search_value || ! $this->replace_value ) {
if ( ! $this->search_value || $this->replace_value === null ) {
return [];
}

Expand All @@ -114,7 +114,7 @@ public function get_replace_positions( $value ) {
$result = $this->replace_all( $this->search_value, self::BEFORE . $replace_value . self::AFTER, $value );

// Split into array
$pattern = '@' . self::BEFORE . '(.*?)' . self::AFTER . '@';
$pattern = '@' . self::BEFORE . '(.*?)' . self::AFTER . '@s';
if ( $this->search_flags->is_case_insensitive() ) {
$pattern .= 'i';
}
Expand Down Expand Up @@ -182,7 +182,7 @@ public function perform( $row_id, $row_value, Source\Source $source, Search\Colu
}

if ( $this->pos_id === null ) {
if ( ! $this->replace_value ) {
if ( $this->replace_value === null ) {
return $column;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/search-regex-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function searchregex_head() {

// phpcs:ignore
if ( isset( $_GET['page'] ) && $_GET['page'] === 'search-regex.php' && strpos( SEARCHREGEX_VERSION, '-beta' ) === false ) {
$is_new = $settings->is_new_version( SEARCHREGEX_VERSION );
$is_new = $settings->is_new_version( $major_version );
}

wp_localize_script( 'search-regex', 'SearchRegexi10n', array(
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "search-regex",
"version": "3.0.2",
"version": "3.0.3",
"description": "Adds search and replace functionality across posts, pages, comments, and meta-data, with full regular expression support",
"main": "search-regex.php",
"sideEffects": true,
Expand Down Expand Up @@ -39,14 +39,14 @@
"homepage": "https://github.com/johngodley/search-regex",
"devDependencies": {
"@types/jest": "^28.1.6",
"@types/react": "^18.0.15",
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"@types/react-highlight-words": "^0.16.4",
"@types/react-redux": "^7.1.24",
"@wordpress/base-styles": "^4.7.0",
"@wordpress/eslint-plugin": "^12.8.0",
"@wordpress/eslint-plugin": "^12.9.0",
"@wordpress/prettier-config": "^1.4.0",
"@wordpress/scripts": "^23.6.0",
"@wordpress/scripts": "^23.7.1",
"apidoc": "^0.52.0",
"chai": "^4.3.6",
"download": "^8.0.0",
Expand All @@ -62,17 +62,17 @@
"node-fetch": "2",
"path": "^0.12.7",
"prettier": "npm:[email protected]",
"release-it": "^15.2.0",
"release-it": "^15.3.0",
"request": "^2.88.2",
"through": "^2.3.8",
"through2": "^4.0.2",
"webpack-shell-plugin-next": "^2.2.2"
},
"dependencies": {
"@emotion/react": "^11.9.3",
"@redux-devtools/extension": "^3.2.2",
"@wordpress/element": "^4.12.0",
"@wordpress/i18n": "^4.14.0",
"@emotion/react": "^11.10.0",
"@redux-devtools/extension": "^3.2.3",
"@wordpress/element": "^4.13.0",
"@wordpress/i18n": "^4.15.0",
"classnames": "^2.3.1",
"date-fns": "^2.29.1",
"deep-equal": "^2.0.5",
Expand Down
6 changes: 6 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ Full documentation can be found on the [Search Regex](http://searchregex.com/) s

== Changelog ==

= 3.0.3 - August 14th 2022 =
* Fix error in error message
* Fix error when removing text
* Fix update notice never going away
* Fix multi-line replace not replacing

= 3.0.2 - July 28th 2022 =
* Fix more issues with older PHP
* Fix a failed update not showing an error message
Expand Down
2 changes: 1 addition & 1 deletion search-regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Search Regex
Plugin URI: https://searchregex.com/
Description: Adds search and replace functionality across posts, pages, comments, and meta-data, with full regular expression support
Version: 3.0.2
Version: 3.0.3
Author: John Godley
Text Domain: search-regex
Domain Path: /locale
Expand Down
10 changes: 5 additions & 5 deletions src/component/replace/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { __ } from '@wordpress/i18n';
import './style.scss';
import { Select } from '@wp-plugin-components';

/** @typedef {import('../state/preset/type.js').PresetValue} PresetValue */
/** @typedef {import('../../state/preset/type.js').PresetValue} PresetValue */

/**
* @callback SaveCallback
Expand All @@ -30,18 +30,18 @@ import { Select } from '@wp-plugin-components';
* @param {boolean} props.disabled - Whether we can replace this
* @param {string} props.className - Class
* @param {string|React} props.placeholder - Placeholder string
* @param {import('../state/search/type').SetReplace} props.setReplacement - Change the replacement
* @param {import('../../state/search/type').SetReplace} props.setReplacement - Change the replacement
* @param {object|null} props.replacement - Row replacement value
* @param {?PresetValue} [props.preset]
* @param {import('../state/search/type').SchemaColumn} props.schema
* @param {import('../state/search/type').ResultColumn} props.column
* @param {import('../../state/search/type').SchemaColumn} props.schema
* @param {import('../../state/search/type').ResultColumn} props.column
*/
function Replace( props ) {
const { disabled, replacement, setReplace } = props;
const [ searchFlags, setFlags ] = useState( 'single' );
const value = {
id: 'replace',
value: replacement,
value: replacement ?? '',
disabled: disabled || searchFlags === 'remove',
placeholder: searchFlags === 'remove' ? __( 'Matched values will be removed', 'search-regex' ) : __( 'Enter replacement value', 'search-regex' ),
name: 'replace',
Expand Down
4 changes: 4 additions & 0 deletions src/page/search-replace/search-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { STATUS_IN_PROGRESS } from '../../state/settings/type';
import { cancel, perform } from '../../state/search/action';

function isPerformReady( action, actionOption, replacement ) {
if ( action === 'replace' && replacement === null ) {
return true;
}

if ( action === 'replace' && replacement.length > 0 ) {
return true;
}
Expand Down
10 changes: 9 additions & 1 deletion src/state/search/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,15 @@ export function getSearchValues( values ) {
* @returns String
*/
export function getReplacement( replacement ) {
return replacement ? replacement : '';
if ( replacement === '' ) {
return null;
}

if ( replacement === null ) {
return '';
}

return replacement;
}

/**
Expand Down
Loading

0 comments on commit 0fd315c

Please sign in to comment.