Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#8776 closed enhancement (fixed)

Deprecate all get_the_author_ and the_author_

Reported by: thee17's profile thee17 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)

8776-try-1.patch (3.6 KB) - added by thee17 16 years ago.
I could not get to work but here is what I have.
8776-working-tested-patch.diff (15.0 KB) - added by thee17 16 years ago.
fixed a missig bracket in depreciated and inline doc in author_template
8776.diff (19.3 KB) - added by DD32 16 years ago.
8776.2.diff (19.3 KB) - added by DD32 16 years ago.
minus the Debug
8776.3.diff (17.6 KB) - added by DD32 16 years ago.
8776_4.diff (434 bytes) - added by MichaelH 16 years ago.
8776.5.diff (1.2 KB) - added by coffee2code 16 years ago.
The same as 8776_4.diff but also with some docs

Download all attachments as: .zip

Change History (36)

#1 @thee17
16 years ago

Other option could be the_author_meta('lastname')

#2 @filosofo
16 years ago

  • Summary changed from Depreciate all get_the_author_ and the_author_ to Deprecate all get_the_author_ and the_author_

#3 @ryan
16 years ago

Fine by me. _data, _info, _meta, _attribute, what do we like best?

#4 @filosofo
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 @thee17
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 @DD32
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 @DD32
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 @DD32
16 years ago

:( There was no need for that $$...

function the_author_meta($field) {
	global $authordata;
	return isset($authordata->$field) ? $authordata->$field : '';
}

#9 @thee17
16 years ago

I'm trying it with last_name and nickname and id and it doesn't work.

#10 @thee17
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 @DD32
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.

@thee17
16 years ago

I could not get to work but here is what I have.

#12 @thee17
16 years ago

Changing return to echo fixed it.

#13 @thee17
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.

#14 @jacobsantos
16 years ago

Need to add _deprecated_function() to those functions you deprecated.

#15 follow-up: @jacobsantos
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.

@thee17
16 years ago

fixed a missig bracket in depreciated and inline doc in author_template

#16 in reply to: ↑ 15 @thee17
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 @thee17
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 @DD32
16 years ago

So the aim of this patch is to depreciate all the *the_author_* functions, and just use the single function.. right?

#19 @thee17
16 years ago

yes, for simplicity purposes.

@DD32
16 years ago

@DD32
16 years ago

minus the Debug

#20 @DD32
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)

#21 @ryan
16 years ago

Let's drop the requirement to have the "user_" prefix on the requested field.

#22 @DD32
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.

@DD32
16 years ago

#23 @DD32
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 @thee17
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.

#25 @ryan
16 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [11138]) get_the_author_meta() and the_author_meta(). Props DD32, thee17. fixes #8776

@MichaelH
16 years ago

#26 @MichaelH
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 @coffee2code
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

@coffee2code
16 years ago

The same as 8776_4.diff but also with some docs

#28 @ryan
16 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [11142]) Use correct var. Update phpdoc. Props MichaelH, coffee2code. fixes #8776

#29 @ryan
16 years ago

(In [11269]) Add the_author_aim() to deprecated. see #8776

Note: See TracTickets for help on using tickets.