Forums » Altering $record in before_save_form_record doesn't work

RSS feed for this topic

Info

  • Posted in Plugins
  • Started 12 months ago by gatekiller
  • 2 posts by 2 users
  • Latest reply from John Flatness
  1. Altering the object $record after when the before_save_form_record does work as expected. I have tried the following different ways of doing it with no luck. I'm about to pull my hair out!! What am I doing wrong?

    Method 1 - Simply edit the record

    add_plugin_hook('before_save_form_record', 'my_before_save_record');
    
    function my_before_save_record($record) {
    	$record["tags"] = "Hello,World";
    }

    Method 2 - Return the edited record

    add_plugin_hook('before_save_form_record', 'my_before_save_record');
    
    function my_before_save_record($record) {
    	$record["tags"] = "Hello,World";
    	return $record;
    }

    Method 3 - Attempt to capture record by reference

    add_plugin_hook('before_save_form_record', 'my_before_save_record');
    
    function my_before_save_record(&$record) {
    	$record["tags"] = "Hello,World";
    }

    What do I need to do to get this to work?

    Many Thanks
    Stephen

  2. Your problem is that you can't assign tags by simply assigning them to the Record.

    Your best bet is to use the update_item() function (sadly undocumented on the Codex as of now).

    update_item($item, array('tags' => 'Hello,World'));

Reply

You must log in to post.