How to trigger “wp_handle_upload_prefilter” filter when uploading an image programatically?

I eventually got this. Solution was to use wp_handle_upload() function. Kinda obvious, when I come to think about it… function handle_upload( string $path ): array { $filename = basename( $path ); $random_filename = rand( 0, 1000 ) . $filename; $tmp_path = str_replace( $filename, $random_filename, $path ); /** Create a temporary copy of the original file, … Read more

Cloning production site down to local?

It can absolutely be done using WP-Cli. Do you have SSH access to the remote server/site? If so, I am happy to show you a process I’ve cooked up using rsync as well as just some standard SQL for the database. That’s my preferred way to do it at the moment.

Clone WordPress for testing on localhost (with Fiddler)

I added this to Fiddler’s script in %USER%\Documents\Fiddler2\Scripts\CustomRules.js under OnBeforeResponse and the response rewrite started working static function OnBeforeResponse(oSession: Session) { if (m_Hide304s && oSession.responseCode == 304) { oSession[“ui-hide”] = “true”; } if (oSession.oResponse.headers.ExistsAndContains(“Content-Type”,”text/html”)){ oSession.utilDecodeResponse(); oSession.utilReplaceInResponse(‘127.0.0.3′,’my.domain.name’); oSession.utilReplaceInResponse(‘http:’,’https:’); } } and needed to set // define(‘WP_HOME’,’http://127.0.0.3/blog’); // define(‘WP_SITEURL’,’http://127.0.0.3/blog’); define(‘FORCE_SSL_LOGIN’,false); define(‘FORCE_SSL_ADMIN’,false); in wp-config.php In order to be … Read more

Mocking WP_CLI static methods in unit tests

So I am using PEST as my testing framework, and if I just define my mocks in the helpers, they won’t be called correctly, because the WPCLI will probably be autoloaded after that on each test. So I added beforeEach(function () { $wpCliMock = \Mockery::mock(‘alias:WP_CLI’); $wpCliMock ->shouldReceive(‘success’) ->andReturnArg(0); $wpCliMock ->shouldReceive(‘error’) ->andReturnArg(0); }); Inside my tests, … Read more