[wp-hackers] Conditionals not working properly when trying to filter admin_footer_text

Kim Parsell kparsell-wp at kpdesign.net
Wed Jul 6 02:19:54 UTC 2011


On 7/5/2011 8:02 PM, John Blackbourn wrote:
> On 6 July 2011 00:36, Kim Parsell<kparsell-wp at kpdesign.net>  wrote:
>> I'm trying to filter the admin footer text just for the Subscriber role
>> using admin_footer_text.
>>
>> I'm using conditionals to target Subscribers and version 3.2. The code I'm
>> using is:
>>
>> ---------------------------------------------------------
>>
>> function my_custom_admin_footer_text() {
>>     global $blog, $blog_id, $current_user, $custom_footer_text, $id,
>> $wp_db_version;
>>
>>     $custom_footer_text = '<span id="footer-thankyou">'.__('Powered by<a
>> title="WordPress" href="http://wordpress.org/">WordPress</a>').'</span>';
>>
>>     /* Let's change the footer text for Subscribers in WordPress 3.2 or
>> higher */
>>
>>     if ((!current_user_can('edit_posts') ||
>> !current_user_can_for_blog($blog_id, 'edit_posts'))&&  $wp_db_version>=
>> 18226) {
>>         echo $custom_footer_text;
>>     }
>>
>> }
>>
>> add_filter('admin_footer_text', 'my_custom_admin_footer_text');
>>
>> ---------------------------------------------------------
>>
>> The results are:
>>
>> - In version 3.1, for all roles, the footer text for every role is getting
>> whacked completely, rather than displaying the default footer text from
>> admin-footer.php. Conditional indicates db version is WP 3.2 or higher, so
>> 3.1 shouldn't get touched.
>>
>> - In version 3.2, the footer text is being replaced for Subscribers, but is
>> whacked completely for all other roles.
>>
>> Is there an issue with using conditionals when trying to filter
>> admin_footer_text? If not, any ideas on why the above code isn't functioning
>> properly?
> "admin_footer_text" is a filter which means you should return
> $custom_footer_text instead of echoing it. This will explain the
> behaviour you're seeing.
>
> John
------------------------------------------------------------------------
Thanks for the response John. I tried making the change you suggested, 
but no love - the results are the same.

In all of the examples I found on the web where people were trying to 
change that text, they applied the change to all roles, rather than 
limiting it to a specific role - none of them used conditionals.

Any other ideas on what may be happening?

Kim


More information about the wp-hackers mailing list