Adding post messages
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 19 Nov 2015 15:03:23 +0000 (10:03 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 19 Nov 2015 15:03:23 +0000 (10:03 -0500)
models/block.php

index 99d8286..088f6cf 100644 (file)
@@ -31,6 +31,7 @@ class glm_models_block
     {
         $this->pluginDirName = $path;
         add_action('init', array($this, 'addPostTypes'));
+        add_filter('post_updated_messages', array($this, 'blocksUpdatedMessages'));
         add_action('admin_enqueue_scripts', array($this, 'load_admin_scripts'));
         add_action('add_meta_boxes', array($this, 'addMetaBoxes'));
         add_action('save_post', array($this, 'saveMetaBox'));
@@ -64,7 +65,11 @@ class glm_models_block
      */
     public function sortQuery($query)
     {
-        if (is_admin() && !isset($_REQUEST['orderby'])) {
+        if (   is_admin()
+            && !isset($_REQUEST['orderby'])
+            && isset($query)
+            && is_object($query)
+            && isset($query->query['post_type'])) {
             $postType = $query->query['post_type'];
             if ($postType == GLM_BLOCK_POST_TYPE) {
                 $query->set('orderby', 'menu_order');
@@ -246,6 +251,50 @@ class glm_models_block
         include $this->pluginDirName . 'views/front/showBlocks.php';
     }
 
+    /**
+     * Update the message text for the block post type
+     *
+     * @global type $post    Post object
+     * @global type $post_ID Id of post
+     *
+     * @param type $messages Messages array
+     *
+     * @return type
+     */
+    public function blocksUpdatedMessages($messages)
+    {
+        global $post, $post_ID;
+
+        $messages['glm_blocks'] = array(
+            0  => '', // Unused. Messages start at index 1.
+            1  => sprintf(__('Block updated. <a href="%s">View item</a>'),
+                             esc_url(get_permalink($post_ID))),
+            2  => __('Custom field updated.'),
+            3  => __('Custom field deleted.'),
+            4  => __('Block updated.'),
+            /* translators: %s: date and time of the revision */
+            5  => isset($_GET['revision'])
+                ? sprintf(__('Block restored to revision from %s'),
+                             wp_post_revision_title((int) $_GET['revision'],
+                                                    false))
+                : false,
+            6  => sprintf(__('Block published. <a href="%s">View event</a>'),
+                             esc_url(get_permalink($post_ID))),
+            7  => __('Block saved.'),
+            8  => sprintf(__('Block submitted. <a target="_blank" href="%s">Preview event</a>'),
+                             esc_url(add_query_arg('preview', 'true',
+                                                   get_permalink($post_ID)))),
+            9  => sprintf(__('Block scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview job</a>'),
+                // translators: Publish box date format, see http://php.net/date
+                             date_i18n(__('M j, Y @ G:i'),
+                                          strtotime($post->post_date)),
+                                                    esc_url(get_permalink($post_ID))),
+            10 => sprintf(__('Block draft updated. <a target="_blank" href="%s">Preview event</a>'),
+                             esc_url(add_query_arg('preview', 'true',
+                                                   get_permalink($post_ID)))),
+        );
+        return $messages;
+    }
     /**
      * addOrderColumn
      *