ace0930
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Theme Updater@greenshady Hi, I’m trying to use the hook
pre_set_site_transient_update_themes
to receive update ( for theme ) from my own API. I’m following the turtorial here, but I saw others articles has this line of codeif (empty($transient->checked)) { return $transient; }
which I’m not sure what it does and if I need it. Thank you!Forum: Developing with WordPress
In reply to: Bug with using getImageDataUpdate: Use offsetX and offsetY instead.
Forum: Developing with WordPress
In reply to: How WordPress get the base URL@hirenbhanderi Exactly, but how does WordPress get the base URL
localhost/example
before putting it into thewp_option
table, that’s what I’m asking…As I have mentioned that the
$_SERVER['SERVER_NAME']
only returnslocalhost
, so I wonder how WordPress findslocalhost/example
.Forum: Developing with WordPress
In reply to: How WordPress get the base URL@hirenbhanderi Hi,
get_site_url()
is also usingget_option ( 'siteurl' )
if you look at the source code.I’m not asking how to get the base URL like which function to use, I’m asking how WordPress gets the
siteurl
…HahaForum: Developing with WordPress
In reply to: Sequence of admin_post and admin_menu@threadi You saved my day, thank you so much!
Forum: Developing with WordPress
In reply to: Sequence of admin_post and admin_menu@threadi To be honest, I still do not fully understand. But do you mean the function
handle_data ()
will not be include/require on the form page? If it’s true, then my question is solved.Forum: Developing with WordPress
In reply to: Sequence of admin_post and admin_menuRemember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
Normally, we will have another file/script to handle the form like, right?
Assumeindex.php
has a form and it looks like this:<form action="process.php" method="post"></form>
Then in the
process.php
file, we use$_POST
to get the data like this ( call this “example-1” for later reference ):$name = $_POST['name']; header ( "Location: https://example.com" ); // Redirect user to https://example.com after processing the data.
But if we put the processing code above on the same file (
index.php
) and it looks like this ( call this “example-2” for later reference ):<form action="process.php" method="post"></form> <?php $name = $_POST['name']; header ( "Location: https://example.com" ); ?>
It would cause an error because there is already an output ( the form ) before the
header ()
.Now let’s get back to the “WordPress” way of handling form, we will use the hook
admin_post_{$action}
with a function like:add_action( admin_post_handle_data, handle_data );
Then we write the processing code inside
handle_data
like the below:function handle_data () { $name = $_POST['name']; header ( "Location: https://example.com" ); }
The form page is created by
add_menu_page
with theadmin_menu
hook.My question is:
1) Will this functionhandle_data ()
be include/require on the form page? If it does, it will look like the “example-2”.2) If the question “1)” is a yes, then the sequence matter, whether it’s
admin_post
first oradmin_menu
first. If it’sadmin_post
first, then the functionhandle_data ()
is before the form; If it’s theadmin_menu
first, then the functionhandle_data ()
is after the form.Or am I complicating it, WordPress will just do the traditional way like “example-1” where the processing code is in another script/file?
- This reply was modified 2 years, 4 months ago by ace0930.
Forum: Developing with WordPress
In reply to: Sequence of admin_post and admin_menu@threadi Hi, sorry but I don’t think you understand the question…
Forum: Developing with WordPress
In reply to: SQL – Single quotes and backticks for query@bcworkz It returns
NULL
when I echoprepare ()
if I%s
the table name.And I found this line in the source code:
$query = preg_replace( '/(?<!%)%s/', "'%s'", $query ); // Quote the strings, avoiding escaped strings like %%s.
I believe it becomes
'table_name'
( note the quotes ) if%s
the table name, and'table_name'
is different fromtable_name
.Forum: Developing with WordPress
In reply to: Passing function into wp_safe_redirect@bcworkz Nonono, you didn’t get the point. I didn’t put the
wp_safe_redirect
on the first line of the page like:<?php wp_safe_redirect ( $example ); ?> <form></form>
Instead, it’s in a function that would be called once the form is submitted to the
admin-post.php
with this hook. And it looks like this:<?php function send () { wp_safe_redirect ( $example ); } ?> <form></form>
Which mean the
wp_safe_redirect ( $example )
will not trigger until the function is called.Forum: Developing with WordPress
In reply to: SQL – Single quotes and backticks for query@bcworkz Is that mean the
$table_name
shouldn’t be replace by%s
like the below:
$wpdb -> prepare ( "SELECT !value! FROM !$table_name! WHERE !name! = %s", $name )
Instead and although the below matches the principle of
sprintf
but it won’t work with$wpdb -> prepare
:
$wpdb -> prepare ( "SELECT !value! FROM %s WHERE !name! = %s", array ( $table_name, $name ) )
Forum: Developing with WordPress
In reply to: Passing function into wp_safe_redirectForum: Developing with WordPress
In reply to: Passing function into wp_safe_redirect@bcworkz Okay, cannot believe this mistake took me two days, I think I know why.
Because the action of the form is set to
admin-post.php
, of course, the current URL would always be that…LOLBut you may still explain why
$_SERVER['REQUEST_URI']
may cause so many redirect error.Forum: Developing with WordPress
In reply to: SQL – Single quotes and backticks for query@bcworkz I found a relevant question although I don’t understand what the answer is talking about: https://wordpress.stackexchange.com/questions/25764/cant-pass-table-to-wpdb-prepare
quotation marks are added to the table name
So
$table_name = $wpdb -> prefix . testing;
will become"wp_testing"
according to the answer? Why is that so?And you said:
Even though including a variable in the first string arg works, it’s incorrect. All vars should be passed in the second arg’s array.
??
Forum: Developing with WordPress
In reply to: Passing function into wp_safe_redirect@bcworkz I have also tried:
$url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
It redirects to:
https://example.com/wp-admin/admin-post.php?
.With the original code:
https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']
It always redirects to
https://example.com/wp-admin/admin-post.php