Support » Plugin: Custom Upload Dir » [Plugin: Custom Upload Dir] correction submit

  • Resolved Claude ws


    Hello ulfben, thx for your great plugin.

    I made the following “correction” at line 160

    $post_name = (!empty($post->post_name)) ? $post->post_name : (!empty($post->post_title)) ? sanitize_title($post->post_title) : $post_id;

    $post_name = (!empty($post->post_name)) ? $post->post_name : (!empty($post->post_title) ? sanitize_title($post->post_title) : $post_id);

    simply moved a parenthesis. I was getting the post_title instead of the post_name(slug).

    Kind regards.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author 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,

    Plugin Author 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.

    – 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.

    Plugin Author 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,

    Plugin Author ulfben


    Thanks. So I can mark this resolved?

    Yes Ulf, you may.
    Kind regards

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: Custom Upload Dir] correction submit’ is closed to new replies.