WordPress.org

Ready to get started?Download WordPress

Forums

echo vs return (10 posts)

  1. davidhouse
    Member
    Posted 10 years ago #

    Amen. I hate having to hack functions just for that one extra parameter.

  2. charle97
    Member
    Posted 10 years ago #

    i hope the developers don't waste time on this. i'd rather see the database cleaned up of deprecated elements.

  3. bstovold
    Member
    Posted 10 years ago #

    I'm not advocating its the only thing that needs improving Charle97. Just that its something that's pretty annoying when you're trying to write plug-ins or do more complex stuff in the template.
    I certainly wouldn't say its a "waste [of] time", any more than cleaning up the database. Really just depends on your needs. Anyways, this is just a requests/ feedback forum. I'm feeding back :-P

  4. charle97
    Member
    Posted 10 years ago #

    if you know the difference between echo and return, then adding either functionality to a function that already uses one is a simple exercise.

  5. davidhouse
    Member
    Posted 10 years ago #

    bstovold: charle97 meant that hacking a function to make it return rather than echo is a simple process, not that it's possible without hacking.
    Yes, it's simple, but I think that making WP simpler to use for hackers is something that needs to be addressed. Whether that's having an annotated version available (maybe online), or by adding a customary $echo paramater, it's a good idea.
    Bottom line: it's easy to hack, but in this instance at least it shouldn't be necessary.

  6. ScottHeavner
    Member
    Posted 10 years ago #

    bstovold:
    There's no need to hack a function to get it to echo its results. Instead of adding echo as a parameter, just put the word "echo" in front of the function.
    As a rule of thumb, I've noticed that functions starting with "the_" produce output (i.e. they use echo). Any of the others don't produce output, so you would have to do the echo yourself by placing the word "echo" in front of the function call.
    It's very easy to make things echo. It's harder to go the other route and get things that are echoing not to. For those it might be useful to have a parameter :)
    Some examples:
    </pre>
    the_title();
    /* produces output */
    wp_texturize('Some text');
    /* produces no output */
    echo wp_texturize('Some text');
    /* produces output */
    </pre>

  7. davidhouse
    Member
    Posted 10 years ago #

    You don't necessarily have to change everything when a new version of WordPress comes out. I have a file in wp-content/plugins/ that contains all the functions I've hacked, all with a dmh_ (my initials) prefix to their name. So when I hack a function, I'll copy-paste the code, rename it with the dmh_prefix and then change the code that I need. That way, I can continue to use (or not) these functions and the original files in /wp-includes/ remain untouched, ready for upgrade.

  8. carthik
    Member
    Posted 10 years ago #

    ...or you could use my-hacks.php to store your functions...

  9. TechGnome
    Moderator
    Posted 10 years ago #

    david - that's all fine and dandy, unless some new funtionality has been added to that function, you won't get it in your customized version. Granted it depends on if you want that new functionality or not.
    TG

  10. bstovold
    Member
    Posted 10 years ago #

    Sorry David/2fargon, that's what I was getting at: if you hack an internal function into a plug-in, or in my hacks, if they upgrade or fix 'em, your hacked version won't benefit.
    Once again, it's not an enormous problem, especially if you're customising or extending the logic beyond recognition. But if you're just copying it out to fix echo/return, it seems a bit silly.
    Maybe this is something the developers can factor into their coding standards for new routines in future drops. And build it into existing ones as they work on them. As Charles pointed out originally, it's not hard to do...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.