Archived

This topic is now archived and is closed to further replies.

  • 0

Resolved Action Hook For When A Custom Section Is Updated


Question

Posted · Report post

I am attempting to write a custom function to send the header and footer areas of the the pages to a .net web service anytime the content of the header or footer area is updated. I have worked out the WordPress action hook for when the menus are updated,

add_action( 'wp_update_nav_menu', 'write_html' );

, but I need to also call my function when the header or footer sections are updated via pagelines. We have custom sections that are being used for the header and footer areas.

I have looked through the Action hooks here: http://api.pagelines.com/hooks

and watched the hook tutorial here: http://www.pagelines.com/docs/base-child-theme

The video is talking more about Filters than Actions (using WordPress terminology) and the list of Actions in the api page doesn't show anything that might relate to updating a specific section.

So I have 2 questions:

1. Is there a pre-exisiting Action hook for when a custom section's site wide settings are updated such as through PageLines > Page Options and selecting the section?

2. If not, how can a custom Action hook be added to a section's update?

Share this post


Link to post
Share on other sites

12 answers to this question

Posted · Report post

Hi there, I honestly don't know the answer on that one, but I will forward your request on to one of our developers and either myself or someone on the team will get back to you shortly to advise further.

Share this post


Link to post
Share on other sites

Posted · Report post

Wordpress has a built in action hook for any option saved to the database, so you can use option_pagelines-settings-two

Share this post


Link to post
Share on other sites

Posted · Report post

Simon, though


add_action( 'option_pagelines-special', 'write_html' );

didn't work your suggestion lead me in the right direction. The hook I ended up using is

add_action( 'update_option_pagelines-special', 'write_html' );

Thanks for pointing me in the right direction :D

Share this post


Link to post
Share on other sites

Posted · Report post

If I understand you correctly Simon_P option_pagelines-settings-two will trigger when any option is saved. Is there a way to add an action hook to a specific custom pagelines section? Otherwise option_pagelines-settings-two will be triggering all the time and I only want to do all the processing and call the web service when the menus, custom header section or custom footer section are updated.

Share this post


Link to post
Share on other sites

Posted · Report post

Actually thats not gonna work...

This is how id suggest you do it...

First add an action that hooks into the option_pagelines-special option...when its triggered it can copy the settings you are monitoring to a temp setting. The the next time it is triggered, it can compare the saved 'new' setting with your temp setting ( the old one ), if they are different then fire your API calls.

Share this post


Link to post
Share on other sites

Posted · Report post

I'm very happy you were able to resolve this. Well done!

Share this post


Link to post
Share on other sites

Posted · Report post

We don't really care that much if the actual value of the option is being changes, just that someone has updated it. Also, it's not necessary to trigger this when someone makes a page specific change, but only when they update the site default options through pagelines > page options > site defaults.

Share this post


Link to post
Share on other sites

Posted · Report post

In that case just use the option_pagelines-special option action

Share this post


Link to post
Share on other sites

Posted · Report post

The topic was marked as resolved.

Share this post


Link to post
Share on other sites

Posted · Report post

Ok so


add_action( 'option_pagelines-special', 'write_html' );

seems to trigger any time someone navigates to any page options page, not just when an update occurs.

and

it seems to trigger every time a ploption is pulled to populate the page options page which means it is calls WAY too many times (and has even caused the script to timeout now)

Share this post


Link to post
Share on other sites

Posted · Report post

May I ask for an example? For instance in order to call my updater function when a WP menu is changed I use


add_action( 'wp_update_nav_menu', 'write_html' );

So to trigger the same function when the the page options for the custom header and footer sections are updated I'd use

add_action( 'option_pagelines-special', 'write_html' );

?

And if that is correct, how does it know to only trigger when specific page options are changed, i.e. the header and footer options? I was assuming I'd have to add some custom hook to those 2 sections.

Share this post


Link to post
Share on other sites