Answer the question
In order to leave comments, you need to log in
How to intercept get request in wordpress?
When the page is rendered, several get requests are made to load images.
GET: mysite.loc/cat/page1.html
GET: mysite.loc/cat/images/img1.jpg
GET: mysite.loc/cat/images/img2.jpg
...
RewriteRule ^([a-zA-z0-9]+)/(.*\.(jpg|jpeg|png|gif))$ /mysript.php?imgpath=$1/$2 [NC,L]
Answer the question
In order to leave comments, you need to log in
can stick
@file_put_contents('log_get.tmp', $_GET['image'], FILE_APPEND);
and already look in the file log_get.tmp
I think you are uploading wrong.
but, as an option, you can implement your task like this,
add endpint
add_rewrite_endpoint( 'imgpath', EP_ALL );
https://codex.wordpress.org/Rewrite_API/add_rewrit...
in functions.php add this
function prefix_output() {
switch (get_query_var( 'imgpath' )) {
// тут делаем что нужно с пойманной переменной
default:
break;
}
remove_action( 'template_redirect', 'prefix_output' );
exit;
}
function prefix_custom_get_vars(){
global $wp_query;
if( !in_array($wp_query->get( 'imgpath' ), array('разрешенные значения' ) ) && !is_admin() ) {
return;
}
add_action( 'template_redirect', 'prefix_output' );
}
add_action( 'pre_get_posts', 'prefix_custom_get_vars' );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question