-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Call user function with --callback flag #104
Conversation
Abstract `wp export` to wp-cli/export-command
``` Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 0 installs, 14 updates, 0 removals - Updating symfony/yaml (v2.8.17 => v2.8.18): Loading from cache - Updating symfony/filesystem (v2.8.17 => v2.8.18): Loading from cache - Updating symfony/config (v2.8.17 => v2.8.18): Loading from cache - Updating symfony/debug (v2.8.17 => v2.8.18): Loading from cache - Updating symfony/dependency-injection (v2.8.17 => v2.8.18): Loading from cache - Updating symfony/event-dispatcher (v2.8.17 => v2.8.18): Loading from cache - Updating symfony/translation (v2.8.17 => v2.8.18): Loading from cache - Updating symfony/process (v2.8.17 => v2.8.18): Loading from cache - Updating symfony/finder (v2.8.17 => v2.8.18): Loading from cache - Updating symfony/console (v2.8.17 => v2.8.18): Loading from cache - Updating seld/jsonlint (1.5.0 => 1.6.0): Loading from cache - Updating justinrainbow/json-schema (4.1.0 => 5.1.0): Loading from cache - Updating composer/ca-bundle (1.0.6 => 1.0.7): Loading from cache - Updating composer/composer (1.3.2 => 1.4.1): Loading from cache Writing lock file Generating autoload files ```
Update Composer dependencies (3/10/2017)
This reverts commit 749466f.
Transform sub/sub directories into a proper dbprefix
Abstract `wp package *` to a separate wp-cli/package-command package
Doing so ensures tests run against local copy of command, instead of Phar bundled version.
Use Composer to install WP-CLI in tests
Include `"prefer-stable": true,` to always prefer stability
Require any WP-CLI, but install dev-master for tests
To allow for versions like 1.2.0 as well, the branch alias for `dev-master` needs to be changed from `1.0.x-dev` to `1.x-dev`.
Correct `dev-master` alias.
Update testing framework.
Fix Travis CI caching for composer
I am hoping someone is willing and able to test this out and release it in or let me know what needs to change. I am glad the CI tests are passing now. I am not able to test this locally because it appears to have conflicts with the search-replace that is installed by default. So I am seeing this even though I am passing 9 args in the new version:
I installed my fork as explained in the README:
Thanks |
Try updating to WP-CLI nightly |
Installing the nightly version fixed the issue. Everything looks good so far but I will report back after some more thorough testing. |
Tested thoroughly and everything looks good to go! |
@brandonkal The PR looks good at first glance. We still need to add functional tests through Behat. Are you able to add these? |
@brandonkal Are you interested in providing the required Behat tests to move this over the finish line? |
@brandonkal Gentle ping to see if you are up for adding the needed tests...? |
Thank you for the reminder @schlessera. I forgot about this. I am not very familiar with Behat and my WordPress projects are currently on hold so I expect it will be a few months before I can look into this again. |
src/WP_CLI/SearchReplacer.php
Outdated
$check = true; // Set to avoid bogus error on strpos | ||
|
||
if ( $this->callback ) { | ||
if ( $check = strpos( $data, $this->from ) !== false ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we are if ( $this->regex ) {
, what's the purpose of this strpos()
check? Shoudn't we just proceed with call_user_func
?
src/WP_CLI/SearchReplacer.php
Outdated
|
||
if ( $this->callback ) { | ||
if ( $check = strpos( $data, $this->from ) !== false ) { | ||
$result = \call_user_func( $this->callback, $data, $this->to, $search_regex ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would passing $this->form
(or $this
) makes more sense thant $search_regex
- Because callback may need raw
$from
- Because callback does
replace
which may rely onregex_limit / flags
individually
@wp-cli/committers There might be a much easier approach here: call |
I implemented callback support within #128 From a quick look, a filter sounds better because:
|
Proceeding with wp-cli/wp-cli#5594 for this repository. I've captured this PR to https://gist.github.com/danielbachhuber/f4bb0f6caaebc2c8a6390adc19cd1f50 in case this PR is auto-closed or broken in some way. |
288c656
to
fa755eb
Compare
Added --revision / --no-revision Added --callback Reroll wp-cli#104, wp-cli#128 Fixes wp-cli#125, wp-cli#127, wp-cli#142
This PR adds the ability to run a user function on search results if a match is found.
In my case, I needed this to change image src urls based on attachment id and size where a hash is a required part of the url.