WordPress.org

Ready to get started?Download WordPress

Forums

Custom Upload Dir
[resolved] correction submit (9 posts)

  1. ClaudeN
    Member
    Posted 2 years ago #

    Hello ulfben, thx for your great plugin.

    I made the following "correction" at line 160

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

    "correction"
    $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.
    Claude.

    http://wordpress.org/extend/plugins/custom-upload-dir/

  2. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    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?

  3. ClaudeN
    Member
    Posted 2 years ago #

    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.

  4. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    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://wordpress.org/extend/plugins/custom-upload-dir/download/

  5. ClaudeN
    Member
    Posted 2 years ago #

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

  6. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    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();

  7. ClaudeN
    Member
    Posted 2 years ago #

    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.

  8. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    Thanks. So I can mark this resolved?

  9. ClaudeN
    Member
    Posted 2 years ago #

    Yes Ulf, you may.
    Kind regards
    Claude.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic