Make WordPress Core

Opened 11 years ago

Closed 10 years ago

#22805 closed enhancement (wontfix)

Add a hook for the live theme preview event

Reported by: alexvorn2's profile alexvorn2 Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4.2
Component: Customize Keywords:
Focuses: Cc:

Description

We have a hook for theme activation and deactivation, but for the theme live preview - not...

Change History (12)

#1 follow-up: @helenyhou
11 years ago

  • Component changed from General to Themes

Why do you need one?

#2 in reply to: ↑ 1 @alexvorn2
11 years ago

Replying to helenyhou:

Why do you need one?

To save for example theme settings before the live preview, so theme will show exactly as after the activation.

#3 follow-up: @nacin
11 years ago

To save for example theme settings before the live preview, so theme will show exactly as after the activation.

A live preview shouldn't save *anything* to the database. Can you be more specific?

Last edited 11 years ago by nacin (previous) (diff)

#4 in reply to: ↑ 3 ; follow-up: @alexvorn2
11 years ago

Replying to nacin:

To save for example theme settings before the live preview, so theme will show exactly as after the activation.

A live preview shouldn't save *anything* to the database. Can you be more specific?

admin panel settings of the theme:

  1. style css file
  2. logo image
  3. show excerpt in the home page - yes/no

etc..
so I use after_switch_theme action to save all this stuff, but on live preview event settings are not saved because this action is not called.

I think that after such hook will be available a lot of developers will start to develop themes in more professional way, because now I think some of them just use update_option function to insert a data for knowing if settings were saved or not.

#5 in reply to: ↑ 4 ; follow-up: @nvartolomei
11 years ago

You just have to look if option exists, if not, just use default option without having to write database and then to read it again to use option.

There is no need to write anything to database at the preview.

Replying to alexvorn2:

admin panel settings of the theme:

  1. style css file
  2. logo image
  3. show excerpt in the home page - yes/no

etc..
so I use after_switch_theme action to save all this stuff, but on live preview event settings are not saved because this action is not called.

I think that after such hook will be available a lot of developers will start to develop themes in more professional way, because now I think some of them just use update_option function to insert a data for knowing if settings were saved or not.

Last edited 11 years ago by nvartolomei (previous) (diff)

#6 in reply to: ↑ 5 ; follow-up: @alexvorn2
11 years ago

Replying to nvartolomei:

So if we have activation and deactivation then we should have a life preview hook too.
Theme settings will be saved on theme activation or on theme live preview...
To check every time when the site loads if the settings were saved or not does not look very nice.

For me for example this is one thing that I think just is missed in the current WordPress build.

It would be great too to have a is_live_preview() function to know if the current state of theme is just a preview for reducing the files and load time but this is already for another ticket.

#7 in reply to: ↑ 6 ; follow-up: @nvartolomei
11 years ago

Replying to alexvorn2:

Useless, reread my answer, by the way look at this get_option.

How do you want to minimize load time for preview if user still wants to see the theme in action?

#8 in reply to: ↑ 7 @alexvorn2
11 years ago

Replying to nvartolomei:

Replying to alexvorn2:
How do you want to minimize load time for preview if user still wants to see the theme in action?

Sorry, this question is not related to this ticket.

#9 @alexvorn2
11 years ago

maybe I will open another one for that...

#10 @alexvorn2
11 years ago

  • Keywords needs-patch added

#11 @nacin
10 years ago

  • Component changed from Themes to Appearance

#12 @ocean90
10 years ago

  • Keywords needs-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

I agree to comment:3. Settings shouldn't be saved just because I preview something. get_option() supports a third parameter to define a default value, which should have in your case the same value as after a theme activation.

There is also an action start_previewing_theme[1] and you can use $wp_customize->is_preview()[2].

[1]: https://developer.wordpress.org/reference/hooks/start_previewing_theme/
[2]: https://developer.wordpress.org/reference/classes/wp_customize_manager/is_preview/

Note: See TracTickets for help on using tickets.