# Extensible code

I would like to write this piece of code in an extendible way.

$my_item = array( 'post_title' =>$item->get_title(),
'post_content' => '',
'post_status' => 'publish',
'post_excerpt' => $item->get_description(), 'post_type' => 'post' );  If I use this in a plugin I would like to be able to create another plugin that can change that array and give different values or parameters. How can I do that? - ## 1 Answer Provide a filter: $my_item = apply_filters(
'plugin_name_item_args',
array(
'post_title'   => $item->get_title(), 'post_content' => '', 'post_status' => 'publish', 'post_excerpt' =>$item->get_description(),
'post_type'    => 'post'
),
$item # pass the$item object to the filter
);


A plugin can change these values now with:

add_filter( 'plugin_name_item_args', 'another_plugin_filter', 10, 2 );

function another_plugin_filter( $args,$item )
{
$args['post_type'] = 'page'; return$args
}

-
I get this error when using $args['post_title'] =$item->get_title(); in the plugin: Fatal error: Call to a member function get_title() on a non-object. –  drtanz Feb 10 '13 at 12:39
So $item is not an object. Try var_dump($item ); to see what it is. –  toscho Feb 10 '13 at 12:43
it is an object object(SimplePie_Item)[285] public 'feed' => object(SimplePie)[288] it works in the main plugin, but in the other plugin that contains the new array I get that error, so it appears that the $item object is not accessible from the new plugin that extends the original plugin. – drtanz Feb 10 '13 at 12:59 Ah, I see. I made an update to my answer. You get the $item object now as second argument in you filter function. –  toscho Feb 10 '13 at 13:39
Perfect, works nicely now, thank you. –  drtanz Feb 10 '13 at 16:58