This plugin allows you to create Custom Fields with any kind of content, name them like mic:name and then, inside posts, when you use {mic:name} or [mic:name], it is replaced by the Custom Field, only after wpautop kicks in so it's not defaced anymore. (priority 11)
micev:name works the same (use {micev:name} or [micev:name]) but the output is eval()-ed before inserted into content. Use with caution... as it allows actual PHP code to run inside posts.
/*
Plugin Name: [Post] Metas In Content
Description: Enables <code>[mic:MIC_Name]</code> and <code>[micev:MIC_Name]</code> inside content.
Version: 0.0.7
Author: EarnestoDev
Author URI: http://www.earnestodev.com/
*/
// ---------------------------------------------------------- //
class Meta_In_Content{
public function __construct(){
register_uninstall_hook(__FILE__, array($this, 'uninstall'));
// Run after the WordPress wpautop and such killers of code
add_filter('the_content', array($this, 'the_content'), 11);
}
public function uninstall(){
global $wpdb;
$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE (`meta_key` LIKE 'mic:%') OR (`meta_key` LIKE 'micev:%');");
}
public function the_content($content){
global $post, $wpdb; $postID = $post->ID;
// mic:NAME metas are not eval()-ed before inserted in the content
$ph_metas = $wpdb->get_col("SELECT DISTINCT(`meta_key`) FROM {$wpdb->postmeta} WHERE `post_id`={$postID} AND `meta_key` LIKE 'mic:%';");
foreach($ph_metas as $ph_meta){
$value = get_post_meta($postID, $ph_meta, true);
if(!is_string($value)) continue;
$content = str_replace(array("[{$ph_meta}]", "{{$ph_meta}}") , array($value, $value), $content);
}
// micev:NAME metas are eval()-ed before inserted in the content
$ph_metas = $wpdb->get_col("SELECT DISTINCT(`meta_key`) FROM {$wpdb->postmeta} WHERE `post_id`={$postID} AND `meta_key` LIKE 'micev:%';");
foreach($ph_metas as $ph_meta){
$value = get_post_meta($postID, $ph_meta, true);
if(!is_string($value)) continue;
ob_start();
eval(sprintf(' ?>%s<?php ', $value));
$value = ob_get_clean();
$content = str_replace(array("[{$ph_meta}]", "{{$ph_meta}}") , array($value, $value), $content);
}
return $content;
}
};
// ---------------------------------------------------------- //
// Instantiate the Object once
$Meta_In_Content = new Meta_In_Content();
// ---------------------------------------------------------- //
Have fun!
Just save this in a plugin in /wp-content/mu-plugins. To disable the eval() functionality, just remove from // micev:NAME metas to right before the return.