WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#8776 closed enhancement (fixed)

Deprecate all get_the_author_ and the_author_

Reported by: 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 6 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 6 years ago.
fixed a missig bracket in depreciated and inline doc in author_template
8776.diff (19.3 KB) - added by DD32 5 years ago.
8776.2.diff (19.3 KB) - added by DD32 5 years ago.
minus the Debug
8776.3.diff (17.6 KB) - added by DD32 5 years ago.
8776_4.diff (434 bytes) - added by MichaelH 5 years ago.
8776.5.diff (1.2 KB) - added by coffee2code 5 years ago.
The same as 8776_4.diff but also with some docs

Download all attachments as: .zip

Change History (36)

comment:1 thee176 years ago

Other option could be the_author_meta('lastname')

comment:2 filosofo6 years ago

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

comment:3 ryan6 years ago

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

comment:4 filosofo6 years ago

Let's not do _data (which functions usually return arrays or objects) or _attribute (will be confused with the xml element's).

comment:5 thee176 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;
}

comment:6 DD326 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 : '';
}

comment:7 DD326 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 : '';
}

comment:8 DD326 years ago

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

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

comment:9 thee176 years ago

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

comment:10 thee176 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?

comment:11 DD326 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.

thee176 years ago

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

comment:12 thee176 years ago

Changing return to echo fixed it.

comment:13 thee176 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.

comment:14 jacobsantos6 years ago

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

comment:15 follow-up: jacobsantos6 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.

thee176 years ago

fixed a missig bracket in depreciated and inline doc in author_template

comment:16 in reply to: ↑ 15 thee176 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.

comment:17 thee175 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.

comment:18 DD325 years ago

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

comment:19 thee175 years ago

yes, for simplicity purposes.

DD325 years ago

DD325 years ago

minus the Debug

comment:20 DD325 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)

comment:21 ryan5 years ago

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

comment:22 DD325 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.

DD325 years ago

comment:23 DD325 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..

comment:24 thee175 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.

comment:25 ryan5 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

MichaelH5 years ago

comment:26 MichaelH5 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.

comment:27 coffee2code5 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

coffee2code5 years ago

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

comment:28 ryan5 years ago

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

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

comment:29 ryan5 years ago

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

Note: See TracTickets for help on using tickets.