WordPress как на ладони

Вывод дополнительного сообщения после публикации поста

При публикации поста обычно выдаётся сообщение "Запись опубликована" + ссылка на неё. Как можно дополнить это сообщение или сделать новое?

Цель: после публикации показывать список ссылок на твиттер-аккаунт (вручную добавить сообщение о новом посте) и подобные.

1
campusboy
7.8 лет назад 4750
  • 1
    Kama9616

    Привет, это можно делать через фильтр post_updated_messages. Будет примерно так:

    add_filter('post_updated_messages', function($messages){
    	$messages['post'][6] .= ' Дополнительное сообщение.'; 
    
    	return $messages;
    });

    Список всех сообщений в массиве $messages:

    Array
    (
    	[post] => Array
    		(
    			[0] => 
    			[1] => Post updated. <a href="http://example.com/foo/">View post</a>
    			[2] => Custom field updated.
    			[3] => Custom field deleted.
    			[4] => Post updated.
    			[5] => 
    			[6] => Post published. <a href="http://example.com/foo/">View post</a>
    			[7] => Post saved.
    			[8] => Post submitted. <a target="_blank" href="http://example.com/foo/?preview=true">Preview post</a>
    			[9] => Post scheduled for: <strong>May 28, 2016 @ 03:20</strong>. <a target="_blank" href="http://example.com/foo/">Preview post</a>
    			[10] => Post draft updated. <a target="_blank" href="http://example.com/foo/?preview=true">Preview post</a>
    		)
    
    	[page] => Array
    		(
    			[0] => 
    			[1] => Page updated. <a href="http://example.com/foo/">View page</a>
    			[2] => Custom field updated.
    			[3] => Custom field deleted.
    			[4] => Page updated.
    			[5] => 
    			[6] => Page published. <a href="http://example.com/foo/">View page</a>
    			[7] => Page saved.
    			[8] => Page submitted. <a target="_blank" href="http://example.com/foo/?preview=true">Preview page</a>
    			[9] => Page scheduled for: <strong>May 28, 2016 @ 03:20</strong>. <a target="_blank" href="http://example.com/foo/">Preview page</a>
    			[10] => Page draft updated. <a target="_blank" href="http://example.com/foo/?preview=true">Preview page</a>
    		)
    
    	[attachment] => Array
    		(
    			[1] => Media file updated.
    			[2] => Media file updated.
    			[3] => Media file updated.
    			[4] => Media file updated.
    			[5] => Media file updated.
    			[6] => Media file updated.
    			[7] => Media file updated.
    			[8] => Media file updated.
    			[9] => Media file updated.
    			[10] => Media file updated.
    		)
    
    )

    Обновлено: описал этот хук: post_updated_messages

    campusboy 7.8 лет назад

    Привет. Спасибо, это то, что нужно!

    Комментировать
На вопросы могут отвечать только зарегистрированные пользователи. Вход . Регистрация