Home › Forums › Add-ons › Options Page › using options page fields for update messages
hi there,
I used add_filter( ‘post_updated_messages’, ‘my_post_update_messages’, 10, 1 ) to change the notification strings when saving custom post types, updating them and so on.
now I’d like to move these custom messages to an option page so my customer can modify the strings on his own. I give Advanced Custom Fields a try but the strings aren’t available when delivered with that filter.
is this a prirority issue or does someone has any help for me? thanks in advanced.
What is the code you’re using to get the messages from the options page fields?
I used stuff like this:
add_filter( 'post_updated_messages', 'gk_post_update_messages', 10, 1 );
function gk_post_update_messages( $messages ) {
if( !current_user_can( 'manage_options' ) ) {
$gk_messages = array();
...
$gk_messages['ww'] = array (
0 => '', // Unused. Messages start at index 1.
1 => sanitize_text_field( get_field('pref_note_ww_1', 'option') ),
2 => sanitize_text_field( get_field('pref_note_ww_2', 'option') ),
3 => sanitize_text_field( get_field('pref_note_ww_3', 'option') ),
4 => sanitize_text_field( get_field('pref_note_ww_4', 'option') ),
5 => isset($_GET['revision']) ? sprintf( sanitize_text_field( get_field('pref_note_ww_5', 'option') ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sanitize_text_field( get_field('pref_note_ww_6', 'option') ),
7 => sanitize_text_field( get_field('pref_note_ww_7', 'option') ),
8 => sanitize_text_field( get_field('pref_note_ww_8', 'option') ),
9 => sprintf( __( sanitize_text_field( get_field('pref_note_ww_9', 'option') ) . ' <strong>%1$s</strong>.'),
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sanitize_text_field( get_field('pref_note_ww_10', 'option') )
);
...
} else {
return $messages;
}
}
Looking at the code you supplied I don’t see any reason that this would not work. What are the settings for your options page?
hi John, thanks for you support!
these are the option page setting I use:
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'MySettings',
'menu_title' => 'MySettings',
'menu_slug' => 'my-settings'
));
}
i digged some more into it: the $gk_messages array from my code example above contains this at the time of editing the custom post type
[05-May-2019 11:32:59 UTC] write_log debug - context: test
[05-May-2019 11:32:59 UTC] Array
(
[post] => Array
(
[0] =>
[1] => Beitrag aktualisiert. <a href="https://dev.TLD.de/ww/test/">Anschauen</a>
[2] => Benutzerdefiniertes Feld aktualisiert.
[3] => Benutzerdefiniertes Feld gelöscht.
[4] => Beitrag aktualisiert.
[5] =>
[6] => Post published. <a href="https://dev.TLD.de/ww/test/">View post</a>
[7] => Beitrag gespeichert.
[8] => Post submitted. <a target="_blank" href="https://dev.TLD.de/ww/test/?preview=true">Preview post</a>
[9] => Post scheduled for: <strong>Apr 29, 2019 @ 14:18</strong>. <a target="_blank" href="https://dev.TLD.de/ww/test/">Preview post</a>
[10] => Post draft updated. <a target="_blank" href="https://dev.TLD.de/ww/test/?preview=true">Preview post</a>
)
[ww] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] => <strong>Apr 29, 2019 @ 14:18</strong>.
[10] =>
)
...
it looks like that get_field values are empty and so the array values are empty, too.
aargh!! my bad 🙁
these message fields are stored in an group field…
sorry for claiming your time, John.
Not a problem, my next question was going to be about the fields you were using. Glad you found the issue.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.