Support

Account

Home Forums Add-ons Options Page using options page fields for update messages

Solved

using options page fields for update messages

    • iRolf

    • April 29, 2019 at 10:31 pm

    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?

    • iRolf

    • May 4, 2019 at 5:59 am

    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;
    	}
    }
    • iRolf

    • May 4, 2019 at 4:53 pm

    addendum: this code is placed in a plugin.

  • 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?

    • iRolf

    • May 5, 2019 at 9:09 pm

    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'
    	));
    }
    • iRolf

    • May 5, 2019 at 9:39 pm

    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.

    • iRolf

    • May 5, 2019 at 9:58 pm

    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.

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.

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.