-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c978fd
commit aa07d75
Showing
7 changed files
with
249 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace SearchRegex\Plugin; | ||
|
||
abstract class Plugin_Settings { | ||
/** @var null|Plugin_Settings */ | ||
protected static $instance = null; | ||
|
||
/** | ||
* Settings | ||
* | ||
* @var array | ||
*/ | ||
protected $settings = []; | ||
|
||
// Don't allow this to be created directly | ||
public function __construct() { | ||
$this->settings = $this->load(); | ||
|
||
$defaults = $this->get_defaults(); | ||
|
||
foreach ( $defaults as $key => $value ) { | ||
if ( ! isset( $this->settings[ $key ] ) ) { | ||
$this->settings[ $key ] = $value; | ||
} | ||
} | ||
|
||
// Remove any expired settings | ||
foreach ( array_keys( $this->settings ) as $key ) { | ||
if ( ! isset( $defaults[ $key ] ) ) { | ||
unset( $this->settings[ $key ] ); | ||
} | ||
} | ||
} | ||
|
||
abstract protected function get_setting_name(); | ||
|
||
/** | ||
* Get default Search Regex options | ||
* | ||
* @return Array | ||
*/ | ||
protected function get_defaults() { | ||
return []; | ||
} | ||
|
||
/** | ||
* Return Search Regex options | ||
* | ||
* @param String $name Name of setting. | ||
* @param mixed $default Default value. | ||
* @return mixed Data to return | ||
*/ | ||
protected function get( $name, $default = false ) { | ||
if ( isset( $this->settings[ $name ] ) ) { | ||
return $this->settings[ $name ]; | ||
} | ||
|
||
return $default; | ||
} | ||
|
||
/** | ||
* Set Search Regex options. Can be passed as many options as necessary and the rest will be unchanged | ||
* | ||
* @param Array $settings Array of name => value. | ||
* @return void | ||
*/ | ||
protected function set( array $settings ) { | ||
$this->settings = array_merge( $this->settings, $settings ); | ||
} | ||
|
||
protected function get_save_data( array $settings ) { | ||
return $settings; | ||
} | ||
|
||
public function save() { | ||
\update_option( $this->get_setting_name(), $this->get_save_data( $this->settings ) ); | ||
} | ||
|
||
protected function load() { | ||
return \get_option( $this->get_setting_name() ); | ||
} | ||
|
||
public function delete() { | ||
\delete_option( $this->get_setting_name() ); | ||
} | ||
|
||
public function get_as_json() { | ||
return $this->settings; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "search-regex", | ||
"version": "3.0.0-beta-5", | ||
"version": "3.0.0", | ||
"description": "Adds search and replace functionality across posts, pages, comments, and meta-data, with full regular expression support", | ||
"main": "search-regex.php", | ||
"sideEffects": true, | ||
|
@@ -36,7 +36,7 @@ | |
}, | ||
"homepage": "https://github.com/johngodley/search-regex", | ||
"devDependencies": { | ||
"@types/jest": "^28.1.5", | ||
"@types/jest": "^28.1.6", | ||
"@types/react": "^18.0.15", | ||
"@types/react-dom": "^18.0.6", | ||
"@types/react-highlight-words": "^0.16.4", | ||
|
@@ -45,7 +45,7 @@ | |
"@wordpress/eslint-plugin": "^12.7.0", | ||
"@wordpress/prettier-config": "^1.4.0", | ||
"@wordpress/scripts": "^23.5.0", | ||
"apidoc": "^0.51.1", | ||
"apidoc": "^0.52.0", | ||
"chai": "^4.3.6", | ||
"download": "^8.0.0", | ||
"glob-all": "^3.3.0", | ||
|
@@ -60,7 +60,7 @@ | |
"node-fetch": "2", | ||
"path": "^0.12.7", | ||
"prettier": "npm:[email protected]", | ||
"release-it": "^15.1.1", | ||
"release-it": "^15.1.3", | ||
"request": "^2.88.2", | ||
"through": "^2.3.8", | ||
"through2": "^4.0.2", | ||
|
@@ -72,12 +72,12 @@ | |
"@wordpress/element": "^4.11.0", | ||
"@wordpress/i18n": "^4.13.0", | ||
"classnames": "^2.3.1", | ||
"date-fns": "^2.28.0", | ||
"date-fns": "^2.29.1", | ||
"deep-equal": "^2.0.5", | ||
"file-saver": "^2.0.5", | ||
"qs": "^6.11.0", | ||
"rc-progress": "^3.4.0", | ||
"rc-util": "^5.22.5", | ||
"rc-util": "^5.23.0", | ||
"react": "^18.2.0", | ||
"react-copy-to-clipboard": "^5.1.0", | ||
"react-datepicker": "^4.8.0", | ||
|
@@ -92,7 +92,7 @@ | |
"redux-thunk": "^2.4.1", | ||
"typescript": "^4.7.4", | ||
"url": "^0.11.0", | ||
"use-debounce": "^8.0.1" | ||
"use-debounce": "^8.0.2" | ||
}, | ||
"apidoc": { | ||
"name": "Search Regex REST API", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.