Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#5085 closed enhancement (fixed)

Unify generator strings

Reported by: docwhat Owned by: westi
Milestone: 2.5 Priority: normal
Severity: normal Version: 2.3
Component: General Keywords: privacy generator has-patch
Focuses: Cc:


In WordPress 2.3, there are about a dozen plus places that use a
generator comment or a generator XML element.

I would like to suggest adding an API for building the generator
interfaces. However, to me, the only obvious (and consistent)
generator string is the XML comment.

wp_generator_comment() would generate an XML comment such as:

<!-- generator="wordpress/2.3" -->

I need help figuring out an API for the various XML node formats, such

<generator uri="http://wordpress.com/" version="1.0.5-dc">WordPress.com Atom API</generator>
<generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator>
<generator>http://wordpress.org/?v=<?php echo $wp_version ?></generator>
<generator uri="http://wordpress.org/" version="<?php bloginfo_rss('version'); ?>">WordPress</generator>
<generator uri="http://wordpress.org/" version="<?php bloginfo('version'); ?>">WordPress</generator>
<admin:generatorAgent rdf:resource="http://wordpress.org/?v=<?php echo $wp_version ?>"/>

Tracing through the code I couldn't easily tell what bloginfo_rss
returns, I assume it returns $wp_version;

This would prevent repetition of code and allow for admins or plugin developers to add or remove information they are not comfortable sending out.


PS: This is related to bug #5065 in spirit.

Attachments (3)

wp-generator.patch (8.8 KB) - added by docwhat 7 years ago.
wp-free-gen.php (841 bytes) - added by docwhat 7 years ago.
generator.diff (9.6 KB) - added by westi 7 years ago.
Updated patch

Download all attachments as: .zip

Change History (19)

comment:1 Otto427 years ago

Most of the feeds and such have their own syntax for expressing the generator. So there's no one universal way.

I'd suggest something like this:

function get_generator($type='comment')
	switch ($type) {
	case 'meta':
		$gen = '<meta name="generator" content="WordPress/'. bloginfo('version') .'" />';
	case 'atom':
		$gen = '<generator uri="http://wordpress.org/" version="'.bloginfo_rss('version').'">WordPress</generator>';
	case 'rss2':
		$gen = '<generator>http://wordpress.org/?v='.bloginfo_rss('version').'</generator>';
	case 'rdf':
		$gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v='.bloginfo_rss('version').'" />';
	default: // case 'comment':
		$gen = '<!-- generator="WordPress/'.bloginfo('version').'" -->";
	return apply_filters('get_generator',$gen);

Then call the appropriate one with <?php echo get_generator('whatever'); ?> at the right point in the code.

comment:2 docwhat7 years ago

Thank you, I think that's a great idea. I'll do that.


comment:3 follow-up: JeremyVisser7 years ago

  • Milestone changed from 2.5 to 2.4
  • Owner changed from anonymous to docwhat

I like it. It's somewhat related to #4803, also.

comment:4 in reply to: ↑ 3 ; follow-up: foolswisdom7 years ago

Replying to JeremyVisser:

milestone changed from 2.5 to 2.4.

Generally, I've been leaving things without core developer owner or patch to trunk+1 .

docwhat7 years ago

docwhat7 years ago

comment:5 docwhat7 years ago

  • Keywords privacy generator added

JeremyVisser: Thanks for the info. Some of the concerns there applied to my patch, too.

I have attached a patch. The only problems I can think of is where it's located in the file or it's name. I can make those changes quickly, feel free to give me feedback.


comment:6 docwhat7 years ago

  • Keywords has-patch added

comment:7 in reply to: ↑ 4 JeremyVisser7 years ago

Replying to foolswisdom:

Replying to JeremyVisser:

milestone changed from 2.5 to 2.4.

Generally, I've been leaving things without core developer owner or patch to trunk+1 .

Thanks for that Lloyd. I'll try and remember that for next time. :) Part of the reason I changed it to 2.4 was that #4803's milestone was 2.4.

comment:8 follow-up: JeremyVisser7 years ago

In line with #4803, the generator tags could then be stripped out of the templates, and adding something like this somewhere:

add_action( 'wp_head', create_function('', "wp_get_generator('xhtml');") );

comment:9 in reply to: ↑ 8 docwhat7 years ago

Replying to JeremyVisser:

In line with #4803, the generator tags could then be stripped out of the templates, and adding something like this somewhere:

Even better, you can detect the DTD and user 'xhtml' or 'html' as appropriate!


comment:10 westi7 years ago

  • Owner changed from docwhat to westi
  • Status changed from new to assigned

I will take a look at these patches and review them.

comment:11 westi7 years ago

Ok I've reworked the patch to include the changes from #4803 and to improve the functionality a little bit.

New patch about to be attached.

Here is a summary of the changes:

 wp-app.php                           |    2 -
 wp-content/themes/classic/header.php |    2 -
 wp-content/themes/default/header.php |    2 -
 wp-includes/default-filters.php      |    3 +-
 wp-includes/feed-atom-comments.php   |    2 -
 wp-includes/feed-atom.php            |    2 -
 wp-includes/feed-rdf.php             |    4 +--
 wp-includes/feed-rss.php             |    2 -
 wp-includes/feed-rss2-comments.php   |    4 +--
 wp-includes/feed-rss2.php            |    4 +--
 wp-includes/general-template.php     |   43 +++++++++++++++++++++++++++++++++++
 wp-links-opml.php                    |    2 -
 12 files changed, 56 insertions(+), 16 deletions(-)

westi7 years ago

Updated patch

comment:12 Otto427 years ago

Suggestion: In feed-rss2.php, feed-rss2-comments.php, and feed-rdf.php, remove the call to <?php the_generator( 'comment' ); ?>. It's unnecessary, the rss2 format contains the stuff for a generator explicitly, we don't need an extra comment type thing in there. It's just taking up space to give the same information that's available in there already.

Other than that, +1.

comment:13 westi7 years ago

Note to self: We also need to include the generator for the export file in these changes

comment:14 westi7 years ago

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

(In [6195]) Centralise generator generation, move theme generator generation to wp-head hook. Fixes #5085, #4803. props docwhat, Viper007Bond.

comment:15 Viper007Bond7 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Type changed from defect to enhancement
  • Version set to 2.3

Shouldn't we use GMT for the generation time (in the export one)?

Also, a small nitpick: spaces after the commas in the_generator().

comment:16 Viper007Bond7 years ago

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

Sorry, I'll make a new ticket.

I always forget.

Note: See TracTickets for help on using tickets.