/** * Callback function for the `transition_post_status` hook. This function saves the previous post status * as metadata. It also adds actions for more specific status changes. * * @since 1.0.0 * @access public * @param string $new_status * @param string $old_status * @param object $post * @return void */ function mb_transition_post_status($new_status, $old_status, $post) { /* Get post types. */ $forum_type = mb_get_forum_post_type(); $topic_type = mb_get_topic_post_type(); $reply_type = mb_get_reply_post_type(); /* If not one of our post types, bail. */ if (!in_array($post->post_type, array($forum_type, $topic_type, $reply_type))) { return; } /* Keep track of the old post status by saving it as post meta. */ update_post_meta($post->ID, mb_get_prev_status_meta_key(), $old_status); /* Get post type statuses. */ $forum_statuses = mb_get_forum_post_statuses(); $topic_statuses = mb_get_topic_post_statuses(); $reply_statuses = mb_get_reply_post_statuses(); /* Get the post statuses we need to work with. */ $publish_status = mb_get_publish_post_status(); $open_status = mb_get_open_post_status(); $close_status = mb_get_close_post_status(); $private_status = mb_get_private_post_status(); $hidden_status = mb_get_hidden_post_status(); $spam_status = mb_get_spam_post_status(); $trash_status = mb_get_trash_post_status(); /* If old status is not one of our statuses but the new is, assume we're publishing for the first time. */ if ($forum_type === $post->post_type && !in_array($old_status, $forum_statuses) && in_array($new_status, $forum_statuses)) { mb_insert_forum_data($post); } elseif ($topic_type === $post->post_type && !in_array($old_status, $topic_statuses) && in_array($new_status, $topic_statuses)) { mb_insert_topic_data($post); } elseif ($reply_type === $post->post_type && !in_array($old_status, $reply_statuses) && in_array($new_status, $reply_statuses)) { mb_insert_reply_data($post); } /* Publish status change. */ add_action("{$publish_status}_to_{$spam_status}", 'mb_publish_to_spam'); add_action("{$publish_status}_to_{$trash_status}", 'mb_publish_to_trash'); /* Open status change. */ add_action("{$open_status}_to_{$spam_status}", 'mb_publish_to_spam'); add_action("{$open_status}_to_{$trash_status}", 'mb_publish_to_trash'); /* Close status change. */ add_action("{$close_status}_to_{$spam_status}", 'mb_close_to_spam'); add_action("{$close_status}_to_{$trash_status}", 'mb_close_to_trash'); /* Private status change. */ add_action("{$private_status}_to_{$spam_status}", 'mb_publish_to_spam'); add_action("{$private_status}_to_{$trash_status}", 'mb_publish_to_trash'); /* Hidden status change. */ add_action("{$hidden_status}_to_{$spam_status}", 'mb_publish_to_spam'); add_action("{$hidden_status}_to_{$trash_status}", 'mb_publish_to_trash'); /* Spam status change. */ add_action("{$spam_status}_to_{$publish_status}", 'mb_spam_to_publish'); add_action("{$spam_status}_to_{$open_status}", 'mb_spam_to_publish'); add_action("{$spam_status}_to_{$close_status}", 'mb_spam_to_close'); add_action("{$spam_status}_to_{$private_status}", 'mb_spam_to_publish'); add_action("{$spam_status}_to_{$hidden_status}", 'mb_spam_to_publish'); /* Trash status change. */ add_action("{$trash_status}_to_{$publish_status}", 'mb_trash_to_publish'); add_action("{$trash_status}_to_{$open_status}", 'mb_trash_to_publish'); add_action("{$trash_status}_to_{$close_status}", 'mb_trash_to_close'); add_action("{$trash_status}_to_{$private_status}", 'mb_trash_to_publish'); add_action("{$trash_status}_to_{$hidden_status}", 'mb_trash_to_publish'); }
function mb_get_reply_toggle_trash_link($reply_id = 0) { $reply_id = mb_get_reply_id($reply_id); if (!current_user_can('moderate_reply', $reply_id)) { return ''; } $text = mb_is_reply_trash($reply_id) ? __('Restore', 'message-board') : get_post_status_object(mb_get_trash_post_status())->label; $link = sprintf('<a class="toggle-trash-link" href="%s">%s</a>', mb_get_reply_toggle_trash_url($reply_id), $text); return $link; }
/** * Custom row actions below the post title. * * @since 1.0.0 * @access public * @param array $actions * @param object $post * @return array */ function row_actions($actions, $post) { $topic_id = mb_get_topic_id($post->ID); /* Remove quick edit. */ if (isset($actions['inline hide-if-no-js'])) { unset($actions['inline hide-if-no-js']); } /* Add delete link for spam and orphan replies. */ if ((mb_is_topic_spam($topic_id) || mb_is_topic_orphan($topic_id)) && current_user_can('delete_post', $topic_id) && EMPTY_TRASH_DAYS) { $actions['delete'] = sprintf('<a class="submitdelete" href="%s">%s</a>', get_delete_post_link($topic_id, '', true), __('Delete Permanently', 'message-board')); } /* Add spam toggle link if user has permission. */ if (current_user_can('spam_topic', $topic_id) && !mb_is_topic_orphan($topic_id)) { /* Get post status objects. */ $spam_object = get_post_status_object(mb_get_spam_post_status()); /* Get spam link text. */ $spam_text = mb_is_topic_spam($topic_id) ? __('Not Spam', 'message-board') : $spam_object->mb_label_verb; /* Build spam toggle URL. */ $spam_url = remove_query_arg(array('topic_id', 'mb_topic_notice')); $spam_url = add_query_arg(array('topic_id' => $topic_id, 'mb_toggle_status' => 'spam'), $spam_url); $spam_url = wp_nonce_url($spam_url, "spam_topic_{$topic_id}"); /* Add toggle spam action link. */ $actions['mb_toggle_spam'] = sprintf('<a href="%s" class="%s">%s</a>', esc_url($spam_url), mb_is_topic_spam() ? 'restore' : 'spam', $spam_text); } /* Add open/close toggle link if user has permission and topic is not spam. */ if (current_user_can('open_topic', $topic_id) && !mb_is_topic_open($topic_id) && !mb_is_topic_spam($topic_id) && !mb_is_topic_orphan($topic_id)) { /* Get post status objects. */ $open_object = get_post_status_object(mb_get_open_post_status()); /* Build open/close toggle URL. */ $open_url = remove_query_arg(array('topic_id', 'mb_topic_notice')); $open_url = add_query_arg(array('topic_id' => $topic_id, 'mb_toggle_status' => 'open'), $open_url); $open_url = wp_nonce_url($open_url, "open_topic_{$topic_id}"); /* Add toggle open/close action link. */ $actions['mb_toggle_open'] = sprintf('<a href="%s" class="%s">%s</a>', esc_url($open_url), 'open', $open_object->mb_label_verb); } /* Add open/close toggle link if user has permission and topic is not spam. */ if (current_user_can('close_topic', $topic_id) && !mb_is_topic_closed($topic_id) && !mb_is_topic_spam($topic_id) && !mb_is_topic_orphan($topic_id)) { /* Get post status objects. */ $close_object = get_post_status_object(mb_get_close_post_status()); /* Build open/close toggle URL. */ $close_url = remove_query_arg(array('topic_id', 'mb_topic_notice')); $close_url = add_query_arg(array('topic_id' => $topic_id, 'mb_toggle_status' => 'close'), $close_url); $close_url = wp_nonce_url($close_url, "close_topic_{$topic_id}"); /* Add toggle open/close action link. */ $actions['mb_toggle_close'] = sprintf('<a href="%s" class="%s">%s</a>', esc_url($close_url), 'close', $close_object->mb_label_verb); } /* Don't allow stickies for these topic statuses. */ $icky_sticky = array(mb_get_orphan_post_status(), mb_get_spam_post_status(), mb_get_trash_post_status()); $topic_status = mb_get_topic_status($topic_id); /* Add super toggle link if user has permission and topic has a public status. */ if (current_user_can('super_topic', $topic_id) && !in_array($topic_status, $icky_sticky)) { $current_url = remove_query_arg(array('topic_id', 'mb_topic_notice')); /* Build sticky text. */ $super_text = mb_is_topic_super($topic_id) ? __('Unsuper', 'message-board') : __('Super', 'message-board'); /* Build super toggle URL. */ $super_url = add_query_arg(array('topic_id' => $topic_id, 'action' => 'mb_toggle_super'), $current_url); $super_url = wp_nonce_url($super_url, "super_topic_{$topic_id}"); $actions['mb_toggle_super'] = sprintf('<a href="%s" class="%s">%s</a>', esc_url($super_url), 'super', $super_text); } /* Add sticky toggle link if user has permission and topic has a public status. */ if (current_user_can('stick_topic', $topic_id) && !in_array($topic_status, $icky_sticky)) { $current_url = remove_query_arg(array('topic_id', 'mb_topic_notice')); /* Build sticky text. */ $sticky_text = mb_is_topic_sticky($topic_id) ? __('Unstick', 'message-board') : __('Stick', 'message-board'); /* Build sticky toggle URL. */ $sticky_url = add_query_arg(array('topic_id' => $topic_id, 'action' => 'mb_toggle_sticky'), $current_url); $sticky_url = wp_nonce_url($sticky_url, "sticky_topic_{$topic_id}"); $actions['mb_toggle_sticky'] = sprintf('<a href="%s" class="%s">%s</a>', esc_url($sticky_url), 'sticky', $sticky_text); } /* Move view action to the end. */ if (isset($actions['view'])) { $view_action = $actions['view']; unset($actions['view']); if (mb_get_spam_post_status() !== get_query_var('post_status')) { $actions['view'] = $view_action; } } return $actions; }
function mb_dropdown_forums($args = array()) { $defaults = array('child_type' => mb_get_forum_post_type(), 'post_type' => mb_get_forum_post_type(), 'post_status' => mb_get_forum_post_statuses(), 'walker' => new MB_Walker_Forum_Dropdown(), 'echo' => true); $trash = array_search(mb_get_trash_post_status(), $defaults['post_status']); if ($trash) { unset($defaults['post_status'][$trash]); } $r = $args = wp_parse_args($args, $defaults); $r['echo'] = false; $forums = wp_dropdown_pages($r); if ('' != $args['selected']) { if (mb_get_forum_post_type() === $args['child_type'] && !current_user_can('move_forums') || mb_get_topic_post_type() === $args['child_type'] && !current_user_can('move_topics')) { if (isset($args['name'])) { $forums = sprintf('<input type="hidden" name="%s" value="%s" />', esc_attr($args['name']), esc_attr($args['selected'])) . $forums; } $forums = preg_replace('/<select(.*?)>/i', "<select disabled='disabled'\$1>", $forums); } } if (false === $args['echo']) { return $forums; } echo $forums; }