#8776 closed enhancement (fixed)
Deprecate all get_the_author_ and the_author_
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 2.8 | Priority: | normal |
Severity: | normal | Version: | 2.8 |
Component: | Template | Keywords: | has-patch tested |
Focuses: | Cc: |
Description
For example have one single function instead.
the_author_info('lastname')
and replace all current fuctions with:
function the_author_yim() { echo the_author_info('yim'); }
Attachments (7)
Change History (36)
#2
@
16 years ago
- Summary changed from Depreciate all get_the_author_ and the_author_ to Deprecate all get_the_author_ and the_author_
#4
@
16 years ago
Let's not do _data (which functions usually return arrays or objects) or _attribute (will be confused with the xml element's).
#5
@
16 years ago
This is what I'm trying:
function the_author_meta($field) { global $authordata; $output = '$authordata->' . $field; return $output; }
with theme code
<?php the_author_meta('last_name'); ?>
And it is not working and I'm not sure why?
the current code to get this is
function get_the_author_lastname() { global $authordata; return $authordata->last_name; }
#6
@
16 years ago
This is correct php: (With the addition of a isset to avoid PHP warnings when the field doesnt exist)
function the_author_meta($field) { global $authordata; return isset($aurhordata->$$field) ? $aurhordata->$$field : ''; }
#7
@
16 years ago
..Er, Typos of variable corrected: (But still untested other than in my mind)
function the_author_meta($field) { global $authordata; return isset($authordata->$$field) ? $authordata->$$field : ''; }
#8
@
16 years ago
:( There was no need for that $$...
function the_author_meta($field) { global $authordata; return isset($authordata->$field) ? $authordata->$field : ''; }
#10
@
16 years ago
ID has a different code
return (int) $authordata->ID;
Is the (int) part crutial or does a generic will a generic option work?
#11
@
16 years ago
I'm trying it with last_name and nickname and id and it doesn't work.
To be honest.. I didnt test it in place either, I tested with a standalone script:
<?php $a = (object) array('test' => 'fish'); $b = 'test'; var_dump($a->$b); ?> string 'fish' (length=4)
You need to get the case right, $b = 'TEST' wouldn't work.. etc
As for ID, returning an int is best, it might be used elsewhere and assumed to be an int (eg, If string, query for username, else grab user with that id).. but i'm not sure.
#13
@
16 years ago
- Keywords has-patch added; needs-patch dev-feedback removed
This replaces everything but AIM, URL, and ID since these ones appear to work differently. I tested it and it and all the old functions work.
#15
follow-up:
↓ 16
@
16 years ago
Some more suggestions: Use a switch or if statement for the ID and have a function which returns the value instead of echos it.
#16
in reply to:
↑ 15
@
16 years ago
Replying to jacobsantos:
Some more suggestions: Use a switch or if statement for the ID and have a function which returns the value instead of echos it.
I'm not sure how to do that, i have not had any luck in testing with return.
#17
@
16 years ago
- Keywords has-patch removed
I'm giving up on this one jut tried
function the_author_meta($field = '') { $output = ''; $output .= ("$authordata->" . $field); global $authordata; if ($field = 'ID') { return (int) $output; } else{ return $output; } }
And one again no success with return. Last patch works but echos.
#18
@
16 years ago
So the aim of this patch is to depreciate all the *the_author_* functions, and just use the single function.. right?
#20
@
16 years ago
- Keywords has-patch needs-testing added
attachment 8776.2.diff added
- the_author_meta(*)
- get_the_author_meta(*)
- Retains back-compat filters (while adding some extra filters for the other fields)
#22
@
16 years ago
Let's drop the requirement to have the "user_" prefix on the requested field.
Good idea. Not all the fields are prefixed with user_ which was the reason for leaving it in, But a multi-step if block should sort that out pretty quickly.
#23
@
16 years ago
attachment 8776.3.diff added
Maybe i should've mentioned i added this..
it now checks to see if a field user_$field exists before using $field..
#24
@
16 years ago
- Keywords tested added; needs-testing removed
I tried all the new possibilities and it seems to work, well even tried all the ofd functions too.
#26
@
16 years ago
Patch 8776_4.diff changes line 93 in author-template.php to use $user_id instead of $auth_id even though both seem to work.
#27
@
16 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
MichaelH is correct, the wrong variable name is being used. $auth_id
is an artifact of the now deprecated functions. $user_id
needs to be used to be able to use get_the_author_meta()
for someone other than the current user.
I've attached an amended version of 8776_4.diff which also includes some additional documentation for the $user_id
arguments for the new functions, as 8776.5.diff
Other option could be the_author_meta('lastname')