WordPress.org

Make WordPress Core

Opened 6 weeks ago

Last modified 4 weeks ago

#44042 new enhancement

Hook for ‘delete_option’ behaviour required

Reported by: RobertoDonPedro Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 1.2
Component: Options, Meta APIs Keywords: good-first-bug has-patch dev-feedback
Focuses: Cc:

Description

Hi, I posted this about one month ago in the wordpress support forum: https://wordpress.org/support/topic/hook-for-delete_option-behaviour-required/

I did not receive any answers there but referred to this forum, so I post it here again:

Hi, I would need to prevent and change the deletion of certain options by the WP core function ‘delete_option’. There is a hook

do_action( 'delete_option', $option );

available here: https://core.trac.wordpress.org/browser/tags/4.9.4/src/wp-includes/option.php#L532

But this does neither provide a way to exit the delete_option function before the option is deleted nor to change the option name to be deleted. In fact this existing hook seems to be pretty useless. Therefore I would need a filter in the first line of the delete_option core function like

$option = apply_filters( 'delete_option_name', $option );

. Or change the line 535 from

$option = trim( $option );

to

$option = trim( apply_filters( 'delete_option_name', $option ));

Any chances to get this into core immediately?

Thx, Robert

Attachments (1)

44042.diff (505 bytes) - added by sebastien@… 6 weeks ago.

Download all attachments as: .zip

Change History (5)

#1 @danieltj
6 weeks ago

  • Component changed from General to Options, Meta APIs
  • Keywords needs-patch good-first-bug added
  • Milestone changed from Awaiting Review to Future Release
  • Type changed from defect (bug) to enhancement
  • Version set to 1.2

Hi @RobertoDonPedro, welcome to Core Trac.

It won't be possible to add this to Core straight away, but after reviewing the other similar functions such as add_option and update_option, they do both have methods are bailing out early through a filter.

I think this is a good idea and something worth exploring considering what is already available within Core, it would definitely bring the delete_option inline with the others.

I've tagged this as good-first-bug because I think this would be quite a nice one for someone new to have a go at.

Thanks!

@sebastien@…
6 weeks ago

#2 @sebastien@…
6 weeks ago

  • Keywords has-patch added; needs-patch removed

#3 @sebastien@…
5 weeks ago

  • Keywords dev-feedback added

#4 @RobertoDonPedro
4 weeks ago

Hi, it seams that the changes did not make it into 4.9.6. Any reasons why? Is there something I need to do? Thx, Robert

Note: See TracTickets for help on using tickets.