Space Pirate
Join Date: May 2004
Location: Atlanta
|
I'm looking at the code for a WordPress plugin called "PodPress" by Dan Kuykendall, trying to track down the places where he should add CSS tags so that people can style text created by the plugin. Some of the code he uses is something I haven't yet learned in PHP and I'm wondering if somebody could explain to me what it does.... the closest thing I can find is something called "magic functions"....
[php] $podPressContent .= __('Standard Podcast', 'podpress').': '; [/php] I see that he's concatenating everything on the right side of the ".=" assignment operator into the variable $podPressContent but I don't understand what's happening with the __('','') bit. I'd like to buy a clue Alex. |
quote |
Senior Member
|
Look for a function named "__" - It must be there somewhere.
|
quote |
Selfish Heathen
Join Date: May 2004
Location: Zone of Pain
|
It's part of WordPress.
See file wp-l10n.php: [php]// Return a translated string. function __($text, $domain = 'default') { global $l10n; if (isset($l10n[$domain])) return apply_filters('gettext', $l10n[$domain]->translate($text), $text); else return $text; } [/php] |
quote |
Less than Stellar Member
|
How's that for an informatively named function?!? I think the wp people know what they're doing, so there must be a reason they named it __. I think...
|
quote |
Selfish Heathen
Join Date: May 2004
Location: Zone of Pain
|
Programmers!
Back in high school I gave functions proper names, but they were names in Spanish and, you guessed it, Klingon. Since my programs generally worked perfectly and implemented lots of extra features that weren't even requested, my teacher didn't mind not being able to follow the code. Seriously, some programmers are just notorious for giving things awful names like that. There are actually code obfuscation contests that hinge on this idea. The problem is rather epidemic, apparently, because even in my 2nd senior year in computer science, professors are still harping about following proper naming conventions. The quality of this board depends on the quality of the posts. The only way to guarantee thoughtful, informative discussion is to write thoughtful, informative posts. AppleNova is not a real-time chat forum. You have time to compose messages and edit them before and after posting. |
quote |
monkey with a tiny cymbal
Join Date: Nov 2004
Location: Lost
|
Quote:
But, yeah, it took me forever to figure it out, too. I wish there was a nice linear guide to wordpress... I can never dig my way through the codex or function lookups without getting sidetracked 10 different ways. It takes me forever to figure out most functions. Oh, and Brad... the daily wtf is a marvelous site for that kind of code obfuscation. Let's see... Ah, here it is: http://thedailywtf.com/ Last edited by Majost : 2006-03-14 at 02:06. |
|
quote |
Selfish Heathen
Join Date: May 2004
Location: Zone of Pain
|
Quote:
[php]// Echo a translated string. function _e($text, $domain = 'default') { global $l10n; if (isset($l10n[$domain])) echo apply_filters('gettext', $l10n[$domain]->translate($text), $text); else echo $text; }[/php] It simply echos the text instead of returning it as a string object. Quote:
No, that's not years' of professors drilling that into my head. It's common sense that I quickly figured out after writing those programs in Spanish and Klingon and looking at them again mere weeks later. The quality of this board depends on the quality of the posts. The only way to guarantee thoughtful, informative discussion is to write thoughtful, informative posts. AppleNova is not a real-time chat forum. You have time to compose messages and edit them before and after posting. |
||
quote |
Senior Member
|
Quote:
|
|
quote |
|
If I remember correctly, this is a carry-over from the C gettext library. It has an implementation in PHP: http://us2.php.net/manual/en/function.gettext.php
And if you note, it can be referenced through an _() function call. I'd imagine this is their version of it. The reason why it's poorly named is to make it not add intrusive amounts of code to support localizations. |
quote |
Space Pirate
Join Date: May 2004
Location: Atlanta
|
Checkit!
The dude's first post is in the Programmer's Nook! Kewl. |
quote |
25 chars of wasted space.
|
Quote:
Basic programming classes are so sweet because they are easy, and something might take you a day that takes others a week. That was an AWESOME class. I never added extra features though, my goal was to do it in as few lines of code as possible without compromising my method of formatting… Code:
function()
{
//thing
} instead of Code:
function() {
//thing
} I HATE that second one.Last edited by ast3r3x : 2006-03-22 at 09:43. |
|
quote |
Posting Rules | Navigation |
|
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
PHP & Apache 2 | ast3r3x | Genius Bar | 0 | 2005-03-16 20:38 |
Search function | Banana | Feedback | 12 | 2005-02-25 19:49 |
Generating XML for Newsfeed (MovableType and PHP) | drewprops | Genius Bar | 3 | 2005-01-22 00:32 |
HELP! URGENT. DOWNGRADE PHP 5.0.1 to 4.3.6 | hype.it | Genius Bar | 2 | 2004-08-31 19:15 |
PHP Catastrophe! | ast3r3x | Genius Bar | 5 | 2004-08-20 09:10 |