WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 0 down vote accepted

Provide a filter:

$my_item = apply_filters( 
        '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
share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.