-
- 2.1. Built With
- 2.2. Installation
-
- 3.1. Instance
- 3.2. WP_Query
- 3.3. Target field
- 3.4. Transform
- 3.4.1. Regex Replace.
- 3.4.2. Text Replace.
- 3.4.3. Prefix.
- 3.4.4. Suffix.
- 3.4.5. Remove.
- 3.5. Preview
- 3.6. Regex Sidebar
WARNING. CHANGES ARE PERMANENT. YOU CANNOT UNDO YOUR CHANGES ONCE YOU HAVE CHANGED THE POSTS. USE WITH CAUTION.
Highlights:
- Allows you to regex post fields on any post types.
- Uses
preg_replace()
on a post_type / post_field combination. - You can select preview or LIVE modes to test your regex before you apply it.
- Within the LIVE mode you can either specify a single post ID or leave it optionally blank to apply the regex to ALL posts of that post type.
This project was built with the following frameworks, technologies and software.
These are the steps to get up and running with this plugin.
- Clone the repo into your wordpress plugin folder
git clone https://github.com/IORoot/wp-plugin__regex-posts ./wp-content/plugins/regexer
- Activate plugin.
You can add as many regexer instances as you like. Each row is consisted of 5 tabs.
- Reference. What to call the instance.
- Enabled. Run this instance or not.
- What posts / pages to target. Add a
WP_Query
array here. e.g.
[
'post_type' => 'posts',
'numberposts' => 10,
]
- Target Field. Which field do you wish to perform the regex replace on.
- Transform (row). Add as many transform rows as you like. Each row will be performed in order and therefore can be chained together. There are five different types to choose from:
This is to use the PHP preg_replace_all()
function on the field.
-
Regex Match. Use a PCRE Pattern to match on.
-
Replacement. This is the text you will use as a replacement. You can use capture group variables
$1
,$2
, etc...
'/(text1)text2(text3)/is'
echo $1 # text1
echo $2 # text3
- Limit. Number of replacements to make. Leave blank for all.
A simpler version of the find/replace. Doesn't use a regular-expression, just a simple text find and replacement.
- Find. Text to look for.
- Replacement. Text to replace with.
Add text to the front of the field value.
- Prefix. Append to the start of any text in the field.
Add text to the end of the field value.
- Suffix. Append to the end of any text in the field.
- Remove. Similar to the the text replace, except that the replacement is nothing. So it will delete the found text.
- Original Value. This is what the the value looks like before the transform rules are applied.
- Transformed Value. This is what the the value looks like after the transform rules are applied.
- Preview. The 'preview' mode will do all of the replacements and show the results in the
preview
tab. Howeveer, it will not perform the transforms on the real data and will not save the changes to the post. - Save. Perform all of the transforms on the real data and save the results over the posts original value.
WARNING. THIS IS PERMANENT. YOU CANNOT UNDO YOUR CHANGES ONCE YOU HAVE CHANGED THE POSTS. USE WITH CAUTION.
-
/\? \<a href.*/s
-
/\<p\>\? \<a.*/s
-
/\?ALL PARKOUR TUTORIALS.*/s
-
/#londonparkour.*/
none.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue. Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License.
MIT License
Copyright (c) 2022 Andy Pearson
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Author Link: https://github.com/IORoot
v1.0.0 - initial version