Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mf2 meta #5

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions languages/mf2-feed.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# This file is distributed under the MIT.
msgid ""
msgstr ""
"Project-Id-Version: MF2 Feed 2.0.1\n"
"Project-Id-Version: MF2 Feed 2.1.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/mf2-feed\n"
"POT-Creation-Date: 2018-08-14 19:34:17+00:00\n"
"POT-Creation-Date: 2018-08-18 07:46:17+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
54 changes: 49 additions & 5 deletions mf2-feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: MF2 Feed
* Plugin URI: http://github.com/indieweb/wordpress-mf2-feed/
* Description: Adds a Microformats2 JSON feed for every entry
* Version: 2.0.1
* Version: 2.1.0
* Author: Matthias Pfefferle
* Author URI: https://notiz.blog/
* License: MIT
Expand All @@ -14,13 +14,10 @@

add_action( 'init', array( 'Mf2Feed', 'init' ) );


// flush rewrite rules
register_activation_hook( __FILE__, array( 'Mf2Feed', 'activate' ) );
register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );



/**
* Mf2Feed class
*
Expand All @@ -34,12 +31,13 @@ public static function init() {
self::setup_feeds();
// add 'json' as feed
add_action( 'do_feed_mf2', array( 'Mf2Feed', 'do_feed_mf2' ), 10, 1 );

add_action( 'do_feed_jf2', array( 'Mf2Feed', 'do_feed_jf2' ), 10, 1 );

add_action( 'wp_head', array( 'Mf2Feed', 'add_html_header' ), 5 );
add_filter( 'query_vars', array( 'Mf2Feed', 'query_vars' ) );
add_filter( 'feed_content_type', array( 'Mf2Feed', 'feed_content_type' ), 10, 2 );

add_filter( 'jf2_entry_array', array( 'Mf2Feed', 'add_mf2_meta' ), 10, 2 );
}

public static function activate() {
Expand Down Expand Up @@ -208,4 +206,50 @@ public static function add_html_header() {
<?php
}
}

/**
* Adds an array with only the mf2 prefixed meta.
*/
public static function add_mf2_meta( $data, $id ) {
$meta = get_post_meta( $id );

foreach ( $meta as $key => $value ) {
if ( ! self::str_prefix( $key, 'mf2_' ) ) {
unset( $meta[ $key ] );
} else {
unset( $meta[ $key ] );
$key = str_replace( 'mf2_', '', $key );
// Do not save microput prefixed instructions
if ( self::str_prefix( $key, 'mp-' ) ) {
continue;
}
$value = array_map( 'maybe_unserialize', $value );
if ( 1 === count( $value ) ) {
$value = array_shift( $value );
}
$meta[ $key ] = $value;
}
}

$meta = array_filter( $meta );

if ( ! $meta ) {
return $data;
}

$data = array_merge( $meta, $data );

return $data;
}

/**
* Is prefix in string.
*
* @param string $source The source string.
* @param string $prefix The prefix you wish to check for in source.
* @return boolean The result.
*/
public static function str_prefix( $source, $prefix ) {
return strncmp( $source, $prefix, strlen( $prefix ) ) === 0;
}
}
13 changes: 9 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
**Tags:** microformats, mf2, jf2, rel-alternate, indieweb
**Requires at least:** 4.7
**Tested up to:** 4.9.8
**Stable tag:** 2.0.1
**Stable tag:** 2.1.0
**Requires PHP:** 5.3
**License:** MIT
**License URI:** http://opensource.org/licenses/MIT
Expand Down Expand Up @@ -79,9 +79,14 @@ To install a WordPress Plugin manually:

Project actively developed on Github at [indieweb/wordpress-mf2-feed](https://github.com/indieweb/wordpress-mf2-feed). Please file support issues there.

### 2.0.1 ###

* Fixed "flush rewrite rules"
### 2.1.0 ###

* Add mf2 metas
* Fixed "flush rewrite rules" again

### 2.0.1 ###

* Fixed "flush rewrite rules"
* Added filter to extend the mf2/jf2 data

### 2.0.0 ###
Expand Down
13 changes: 9 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://notiz.blog/donate/
Tags: microformats, mf2, jf2, rel-alternate, indieweb
Requires at least: 4.7
Tested up to: 4.9.8
Stable tag: 2.0.1
Stable tag: 2.1.0
Requires PHP: 5.3
License: MIT
License URI: http://opensource.org/licenses/MIT
Expand Down Expand Up @@ -79,9 +79,14 @@ To install a WordPress Plugin manually:

Project actively developed on Github at [indieweb/wordpress-mf2-feed](https://github.com/indieweb/wordpress-mf2-feed). Please file support issues there.

= 2.0.1 =

* Fixed "flush rewrite rules"
= 2.1.0 =

* Add mf2 metas
* Fixed "flush rewrite rules" again

= 2.0.1 =

* Fixed "flush rewrite rules"
* Added filter to extend the mf2/jf2 data

= 2.0.0 =
Expand Down