indieweb / wordpress-uf2

add "Microformats 2" classes to your WordPress theme
https://wordpress.org/plugins/wp-uf2/
22 stars 4 forks source link

move author h-cards into post and comment hidden blocks #4

Closed snarfed closed 11 years ago

snarfed commented 11 years ago

builds on the last pull request. adds new h-cards for comment authors, and adds u-url and gravatar u-photo to post authors.

pfefferle commented 11 years ago

Is the author filter not working?

snarfed commented 11 years ago

it's working, it just also adds the tags to the author's name in places where it's rendered, e.g. "View all posts by XXX." the span gets escaped in those places, so end users see the actual markup in their browser.

i'd much rather go with filters than these hidden blocks, but as you mention, wordpress's filters and action hooks are limited. SemPress is the best way to go, but if i want to use this plugin and get more microformats2 coverage, we probably have to do it this way.

it's ok if you don't want to merge it, i'll definitely understand. i may start maintaining my fork, but i'll still encourage people to use SemPress instead.

pfefferle commented 11 years ago

OK, I now what you mean... But hiding microformats is a bit hacky (http://microformats.org/wiki/faq#Hidden_Content)... what do you think about a nice and simple, but not hidden author box? Like here: http://www.wp-premiumthemes.de/wordpress-fanciest-author-box/ (without the tabs). With some basic CSS?

You can disable it via a child theme anyway or we can add a constant that you can disable it via you config.php?

snarfed commented 11 years ago

sure! an author box would be good. the other pull request for posts and comments has the same problem though. for that one, i think there were no good filters or action hooks to add classes to elements in entry-meta and other places where that data e.g. published and updated time (among others), are rendered.

i looked for a while, but i'm sure you know more about wordpress than me. i may have missed some big ones i can use regexp replace on. i'll go back and look some more to see if i can avoid the hidden blocks.

(i'm not entirely convinced that hidden blocks are bad - that page overstates the dangers and understates the uses - but no matter. i do understand.)

i'm not much of a designer, so i don't know that i

snarfed commented 11 years ago

ok, i figured out one big problem. most wordpress themes, especially the official ones, add the hfeed class to the post element in their header.php, and it looks like there's no filter or action hook i can use to remove it. this triggers the parsing a problem you all discovered a week ago: http://microformats.org/wiki/microformats2-parsing-issues#mixture_of_microformats2_and_classic_microformats_classnames_on_different_elements . you handle this better in SemPress, an some of my hacks here tried to fix the same thing, even if i didn't know why.

i can propose a patch for the theme i personally use, and it will probably get accepted, but that only helps one theme. to fix it all the way, wordpress itself probably needs a new filter, which is a bigger project than i'm ready for.

i'll keep poking at this.

pfefferle commented 11 years ago

Perhaps we could ask @barnabywalters to implement a way to disable the backwards-compatibility of the mf2-parser...

snarfed commented 11 years ago

sure! disappointing, but maybe. i'll ping him in irc later today.

snarfed commented 11 years ago

for the record, i ended up using this child theme header.php to remove the hfeed:

<?php

function get_include_contents($filename) {
  ob_start();
  include $filename;
  $contents = ob_get_contents();
  ob_end_clean();
  return $contents;
}

$header = get_include_contents(TEMPLATEPATH . '/header.php');
echo str_replace('class="hfeed site"', 'class="site"', $header);
?>
snarfed commented 11 years ago

...and here's more in the child theme to add the author h-card and timestamps to the actual content more cleanly.

i may eventually package this as a general purpose child theme that you can add to any normal theme and get the rest of the uf2 that we can't get from the plugin alone. we'll see. in the meantime, i'll close these pull requests.

function THEME_entry_meta() {
  printf(__('<span class="entry-date">' .
            '<a href="%1$s" title="%2$s" rel="bookmark">' .
            '<time class="dt-published" datetime="%3$s">%4$s</time>' .
            '</a></span>', 'ryu'),
         esc_url(get_permalink()),
         esc_attr(get_the_time()),
         esc_attr(get_the_date('c')),
         esc_html(get_the_date()));

  if ('page' == get_post_type() && get_the_date() != get_the_modified_date()) {
    printf(__('<span class="entry-modified-date">updated ' .
              '<a href="%1$s" title="%2$s" rel="bookmark">' .
              '<time class="dt-updated" datetime="%3$s">%4$s' .
              '</time></a></span>', 'ryu'),
           esc_url(get_permalink()),
           esc_attr(get_the_modified_time()),
           esc_attr(get_the_modified_date('c')),
           esc_html(get_the_modified_date()));
  }

  printf(__('<span class="author h-card vcard"> %1$s' .
            '<a class="u-url url fn n p-name" href="%2$s" title="%3$s" rel="author">' .
            '%4$s</a></span>', 'ryu'),
         get_avatar(get_the_author_meta("ID")),
         esc_url(get_the_author_meta('user_url')),
         esc_attr(get_the_author()),
         get_the_author());
}

remove_filter( 'the_author', 'uf2_the_author', 99, 1 );
pfefferle commented 11 years ago

because it is possible to run all the plugin functions also from a themes function.php, should we start creating a "generic child theme" instead of the plugin? or we can try to write it like we could use it as both… I think we could add the hfeed-removal part also as part of the plugin.php/function.php

I will have a look what hooks we can use for that!

pfefferle commented 11 years ago

You inspired me :)

I think we should rename the file to function.php so it is possible to use it as both (plugin and child-theme) and add all the functions (including THEME_entry_meta and a hook-version of the hfeed-remover). We could also add a basic author-box, so the user can choose what he wants to use by setting a constant (for example define('UF2_AUTHOR_BOX', true);) or renaming the THEME_entry_meta to replace the theme version. Together with a nice inline documentation, this could be a universal toolkit to add mf2 support. What do you think?

snarfed commented 11 years ago

sure! that makes a lot of sense. glad you're interested! i don't have much time to work on this right now, but i could eventually.

my only reservation is that the function names to override are (usually) theme-specific, so users would have to edit the PHP themselves. i don't know a lot of PHP; can it define functions with dynamic names? if so, we could make a UI that lets users choose the parent theme, then dynamically define the override functions.

pfefferle commented 11 years ago

I have found a version to overwrite the hfeed theme independent:

http://www.dagondesign.com/articles/wordpress-hook-for-entire-page-using-output-buffering/

Will implement it later or tomorrow and I will also have a look at the THEME_entry_meta. Perhaps we can use the same mechanism as you used for removing the hfeed. I will try out some ways.

snarfed commented 11 years ago

oh man, that's awesome! great hack. the hfeed is actually inside the header, so we can't use that technique as written, but i bet we can inject the ob_start() in an earlier hook. thanks for trying it!

pfefferle commented 11 years ago

have a look at your header.php... wp_head() is called in the html <head /> and before the body tag, so it should be perfect ;)

snarfed commented 11 years ago

ah, HTML header, not WordPress header. got it.

btw, we probably don't need a new author box, we can just add to the existing author name and link in entry-meta. my THEME_entry_meta() override above has the code: https://github.com/pfefferle/wordpress-uf2/pull/4#issuecomment-27367192

this all sounds promising!