diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8d64f2d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: '2' +services: + db: + image: mysql:5.7 + restart: always + environment: + MYSQL_ROOT_PASSWORD: wordpress + MYSQL_DATABASE: wordpress + MYSQL_USER: wordpress + MYSQL_PASSWORD: wordpress + + wordpress: + depends_on: + - db + image: wordpress:latest + links: + - db + ports: + - "8777:80" + volumes: + - .:/var/www/html/wp-content/plugins/opengraph + restart: always + environment: + WORDPRESS_DB_HOST: db:3306 + WORDPRESS_DB_USER: wordpress + WORDPRESS_DB_PASSWORD: wordpress + WORDPRESS_DEBUG: 1 \ No newline at end of file diff --git a/opengraph.php b/opengraph.php index cb71393..c44582d 100644 --- a/opengraph.php +++ b/opengraph.php @@ -5,7 +5,7 @@ * Description: Adds Open Graph metadata to your pages * Author: Will Norris * Author URI: https://willnorris.com/ - * Version: 1.11.3 + * Version: 1.12.0 * License: Apache License, Version 2.0 * License URI: http://www.apache.org/licenses/LICENSE-2.0.html * Text Domain: opengraph @@ -108,6 +108,14 @@ function opengraph_metadata() { $metadata[ "twitter:$property" ] = apply_filters( $filter, '' ); } + $fediverse_properties = array( 'creator' ); + + foreach ( $fediverse_properties as $property ) { + $filter = 'fediverse_' . $property; + + $metadata[ "fediverse:$property" ] = apply_filters( $filter, '' ); + } + return apply_filters( 'opengraph_metadata', $metadata ); } @@ -140,6 +148,9 @@ function opengraph_default_metadata() { // twitter card metadata add_filter( 'twitter_card', 'twitter_default_card', 5 ); add_filter( 'twitter_creator', 'twitter_default_creator', 5 ); + + // fediverse creator metadata + add_filter( 'fediverse_creator', 'fediverse_default_creator', 5 ); } add_action( 'wp', 'opengraph_default_metadata' ); @@ -469,6 +480,31 @@ function twitter_default_creator( $creator ) { } +/** + * Default fediverse creator. + * + * @see https://github.com/mastodon/mastodon/pull/30398 + */ +function fediverse_default_creator( $creator ) { + if ( ! is_singular() ) { + return $creator; + } + + $post = get_queried_object(); + $author = $post->post_author; + $webfinger = get_the_author_meta( 'fediverse', $author ); + + if ( ! $webfinger ) { + return $creator; + } + + $webfinger = ltrim( $webfinger, '@' ); + $webfinger = ltrim( $webfinger, 'acct:' ); + + return $webfinger; +} + + /** * Output Open Graph tags in the page header. */ @@ -482,16 +518,11 @@ function opengraph_meta_tags() { foreach ( $value as $v ) { // check if "strict mode" is enabled - if ( OPENGRAPH_STRICT_MODE === false ) { - // use "property" and "name" - printf( - '' . PHP_EOL, - esc_attr( $key ), - esc_attr( $v ) - ); - } else { - // use "name" attribute for Twitter Cards - if ( stripos( $key, 'twitter:' ) === 0 ) { + if ( OPENGRAPH_STRICT_MODE === true ) { + if ( // use "name" attribute for Twitter Cards + str_starts_with( $key, 'twitter:' ) || + str_starts_with( $key, 'fediverse:' ) + ) { printf( '' . PHP_EOL, esc_attr( $key ), @@ -504,6 +535,13 @@ function opengraph_meta_tags() { esc_attr( $v ) ); } + } else { + // use "property" and "name" + printf( + '' . PHP_EOL, + esc_attr( $key ), + esc_attr( $v ) + ); } } } @@ -576,6 +614,7 @@ function opengraph_article_metadata( $metadata ) { function opengraph_user_contactmethods( $user_contactmethods ) { $user_contactmethods['twitter'] = __( 'Twitter', 'opengraph' ); $user_contactmethods['facebook'] = __( 'Facebook (Profile URL)', 'opengraph' ); + $user_contactmethods['fediverse'] = __( 'Fediverse (username@host.tld)', 'opengraph' ); return $user_contactmethods; } @@ -606,3 +645,14 @@ function opengraph_trim_text( $text, $length = 55 ) { return wp_trim_words( $text, $excerpt_length, $excerpt_more ); } + +/** + * str_starts_with function for PHP < 8.0 + * + * @see https://www.php.net/manual/en/function.str-starts-with + */ +if ( ! function_exists( 'str_starts_with' ) ) { + function str_starts_with( $haystack, $needle ) { + return 0 === strncmp( $haystack, $needle, \strlen( $needle ) ); + } +} diff --git a/readme.txt b/readme.txt index 3582189..a40f6f6 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: willnorris, pfefferle Tags: social, opengraph, ogp, facebook Requires at least: 2.3 Tested up to: 6.5 -Stable tag: 1.11.3 +Stable tag: 1.12.0 License: Apache License, Version 2.0 License URI: https://www.apache.org/licenses/LICENSE-2.0.html @@ -62,6 +62,9 @@ The plugin populates the meta 'name' attribute alongside the 'property' attribut Project maintained on github at [willnorris/wordpress-opengraph](https://github.com/willnorris/wordpress-opengraph). += version 1.12.0 (Jul 3, 2024) = + - support `` + = version 1.11.3 (Jun 4, 2024) = - don't return description for password protected posts