Plugin Author
ulfben
(@ulfben)
Hi Claude, and thanks!
I’d like to run the modification through some test cases to make sure it’s correct. Do you have some string that will ’cause my original version to foul-up?
Hey Ulfben!
to test:
1. set custom upload to %post_name%.
2. create and save one post with “title-test” as title & “slug-test” as slug.
3. upload an image and it will create a folder with the name “title-test”, not “slug-test”.
Tell me if you get a different result.
Kind regards,
Claude.
Plugin Author
ulfben
(@ulfben)
Commited to the development version (along with some other fixes). I’d appreciate it if you could try it out and let me know if it seems alright.
http://ww.wp.xz.cn/extend/plugins/custom-upload-dir/download/
– Did a test. same problem.
– modified the line as described: works.
– furthermore. Allow me to be a bit “direct” about the use of parenthesis on that line:
(!empty($post->post_name)) ? $post->post_name : (!empty($post->post_title) ? sanitize_title($post->post_title) : $post_id);
is equal to
( if .. ) then .. else ( if .. ) then .. else ..
in which I fail to see the logic.
what you want is:
if .. then .. else (if .. then .. else .. )
But I could be mistaking.
Kind regards, & keep the good work.
claude.
Plugin Author
ulfben
(@ulfben)
The line you’re quoting now is identical to the correction you gave me, and identical to the line currently in the source. Can you please re-download the development version and make sure we’re talking about the same test?
Currently in the source:
(!empty($post->post_name)) ? $post->post_name : (!empty($post->post_title) ? sanitize_title($post->post_title) : $post_id);
Your correction:
(!empty($post->post_name)) ? $post->post_name : (!empty($post->post_title) ? sanitize_title($post->post_title) : $post_id);
As for the “redundant” parenthesis (surrounding the test-parts of the if-statement) they makes no logical difference to PHP. The pre-processor simply removes them when evaluating the line.
I use them to separate and clarify the expressions of the ternary operators – especially when doing multiple comparisons: ($a > 5 && $a < 15) ? doWhatever() : doSomethingElse();
Hello Ulf,
your modification of the line 160, in my latest download of custom-upload-dir, is the modification I made. Correct.
No worries, I do share your “parenthesis approach” when dealing with long formulations.
Thank you for you great plugin.
Kind regards,
Claude.
Plugin Author
ulfben
(@ulfben)
Thanks. So I can mark this resolved?
Yes Ulf, you may.
Kind regards
Claude.