[wp-hackers] function_exists - user woes

Garett Harnish garett at harnish.ca
Fri Jul 30 22:10:05 UTC 2004


Chris Coggburn wrote:

> Garett Harnish wrote:
>
>> That sounds like a very easy to implement and functional solution.  
>> How about something like this:
>>
>> <snip>
>>
>> <?php wp_call_plugin_function('xyz_photos', array('foo' => 'bar', 'x' 
>> => '3')); ?>
>
> That looks good to us, but remember people that know nothing about php 
> will be completely confused about that. Sure they could just copy and 
> paste things...but it makes the user feel a little happier when they 
> actually understand what is going on in what they slap in their template.


True.  The reason for the array is mostly to reduce the code of 
wp_call_plugin_function.   The problem is the string "foo=bar:x=3" is a 
lot more complicated to do things with.   Still, it is doable:

function wp_call_plugin_function ($function, $str_params)
{
  // see if function exists
  if (function_exists($function))
  {
         // Break string into key/value pairs
         $array_temp = split(":", $str_params);

         // Build Associative Array
         foreach ($array_temp as $pair)
        {
                 list($key,$value) = split("=", $pair, 2);
                 $array_params[$key] = $value;
         }

         // Call function
         call_user_func($function, $array_params);
  }
}

Then one could call the function like so:
<?php wp_call_plugin_function('xyz_photos','foo=bar:x=3'); ?>

Assuming there isn't a logic flaw in my code, that should do it ... but 
it lacks elegance.  Still, it should make it easier for an end-user to 
understand what they are doing when they plug in the function call.

>> Using a parameter array would definitely make it a lot easier as well.
>
>
> This would, but would confuse the user as said before.


Would the above be better?

--
Garett
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : /pipermail/hackers_wordpress.org/attachments/20040730/7425a4ff/signature.bin


More information about the hackers mailing list