Post Meta Filter

<?php
/*
Plugin Name: CFInterceptor
Plugin URI: http://hyperspatial.com
Description: CFInterceptor is used for wordpress filters that need to load early in execution
Version: 1.0
Author: Adam J Nowak
Author URI: http://hyperspatial.com
License: GPL2
*/

/*
* CFInterceptor is designed to work with the CFProjectFilters class
*
* Calling actions/filters here registers them before the plugins are loaded
* Write callbacks in the CFProjectFilters class here: /wp-content/plugins/cf-project/includes/project-filters.php
*/

//Project Type Meta Filter
add_filter( 'get_post_metadata', array( 'CFProjectFilters', 'project_type_meta_filter' ), 10, 4 );

?>

<?php
/*
* CFProjectFilters is a class to package action and filter callbacks
*
* WP add_action() or add_filter() can be called in /wp-content/mu-plugins/interceptor.php
* Calling in the mu-plugins forces the actions/filters to be registered before the plugins are loaded
*/

class CFProjectFilters{
/* ~~~~~~~~~~ Project Type Meta Filter ~~~~~~~~~~ */
public function project_type_meta_filter( $metadata, $object_id, $meta_key, $single ){
if( $meta_key != '_project_type' ) return;
$meta_cache = wp_cache_get( $object_id, 'post_meta' );
$project_type = $meta_cache['_project_type'][0];

if( $project_type == 3 ) $metadata = 'Project type 3 is now a string, yay';
return $metadata;
}
}
?>

0 Comments

You must be logged in to post a comment.