Handle integration with the transition_post_status hook

@see wp_transition_post_status

@param string  $new_status
@param string  $old_status
@param WP_Post $post
425574
public function save_post_detect_new( $new_status, $old_status, $post ) {

		if ( $post ) {
			self::$old_post_status[ $post->post_type ] = $old_status;
		}

	}
607062
public function sendNotificationsReply($tid, $cur_posting, $new_pid, $post)
    {
        Container::get('hooks')->fire('model.post.send_notifications_reply_start', $tid, $cur_posting, $new_pid, $post);

        // Get the post time for the previous post in this topic
        $previous_post_time = DB::forTable('posts')
            ->select('posted')
            ->where('topic_id', $tid)
            ->order_by_desc('id');
        $previous_post_time = Container::get('hooks')->fireDB(
            'model.post.send_notifications_reply_previous',
            $previous_post_time
        );
        $previous_post_time = $previous_post_time->find_one();

        // Get any subscribed users that should be notified (banned users are excluded)
//        $result['where'] = array(
//            array('fp.read_forum' => 'IS NULL'),
//            array('fp.read_forum' => '1')
//        );
        $result['select'] = ['u.id', 'u.email', 'u.notify_with_post', 'u.language'];

        $result = DB::forTable('users')
                    ->table_alias('u')
                    ->select_many($result['select'])
                    ->inner_join(DB::prefix().'topic_subscriptions', ['u.id', '=', 's.user_id'], 's')
//                    ->left_outer_join('forum_perms', array('fp.forum_id', '=', $cur_posting['id']), 'fp', true)
//                    ->left_outer_join('forum_perms', array('fp.group_id', '=', 'u.group_id'))
            ->left_outer_join(
                DB::prefix().'forum_perms',
                '(fp.group_id=u.group_id AND fp.forum_id='. $cur_posting['id'].')',
                'fp'
            )
                    ->left_outer_join(DB::prefix().'online', ['u.id', '=', 'o.user_id'], 'o')
                    ->left_outer_join(DB::prefix().'bans', ['u.username', '=', 'b.username'], 'b')
                    ->where_raw('COALESCE(o.logged, u.last_visit)>'.$previous_post_time->posted)
                    ->where_null('b.username')
                    ->where_raw('(fp.read_forum IS NULL OR fp.read_forum=1)')
                    ->where('s.topic_id', $tid)
                    ->where_not_equal('u.id', User::get()->id);
        $result = Container::get('hooks')->fireDB('model.post.send_notifications_reply_query', $result);
        $result = $result->find_many();

        if ($result) {
            $notification_emails = [];

            $censored_message = Utils::trim(Utils::censor($post['message']));

            if (ForumSettings::get('o_censoring') == '1') {
                $cleaned_message = Container::get('email')->bbcode2email($censored_message, -1);
            } else {
                $cleaned_message = Container::get('email')->bbcode2email($post['message'], -1);
            }

            // Loop through subscribed users and send emails
            foreach ($result as $cur_subscriber) {
                // Is the subscription email for $cur_subscriber['language'] cached or not?
                if (!isset($notification_emails[$cur_subscriber['language']])) {
//                    if (file_exists(ForumEnv::get('FORUM_ROOT').'lang/'.$cur_subscriber['language'].
//                        '/mail_templates/new_reply.tpl')) {
                        $mail_tpl = Lang::getMailTemplate('new_reply')->text;
                    if ($mail_tpl) {
                        // Load the "new reply" template
//                        $mail_tpl = trim(file_get_contents(ForumEnv::get('FORUM_ROOT').'lang/'.
//                            $cur_subscriber['language'].'/mail_templates/new_reply.tpl'));
                        $mail_tpl = Container::get('hooks')->fire(
                            'model.post.send_notifications_reply_mail_tpl',
                            $mail_tpl
                        );

                        // Load the "new reply full" template (with post included)
//                        $mail_tpl_full = trim(file_get_contents(ForumEnv::get('FORUM_ROOT').'lang/'.
//                            $cur_subscriber['language'].'/mail_templates/new_reply_full.tpl'));
                        $mail_tpl_full = Lang::getMailTemplate('new_reply_full')->text;

                        $mail_tpl_full = Container::get('hooks')->fire(
                            'model.post.send_notifications_reply_mail_tpl_full',
                            $mail_tpl_full
                        );

                        // The first row contains the subject (it also starts with "Subject:")
                        $first_crlf = strpos($mail_tpl, "\n");
                        $mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8));
                        $mail_subject = Container::get('hooks')->fire(
                            'model.post.send_notifications_reply_mail_subject',
                            $mail_subject
                        );
                        $mail_message = trim(substr($mail_tpl, $first_crlf));

                        $first_crlf = strpos($mail_tpl_full, "\n");
                        $mail_subject_full = trim(substr($mail_tpl_full, 8, $first_crlf-8));
                        $mail_message_full = trim(substr($mail_tpl_full, $first_crlf));

                        $mail_subject = str_replace('<topic_subject>', $cur_posting['subject'], $mail_subject);
                        $mail_message = str_replace('<topic_subject>', $cur_posting['subject'], $mail_message);
                        $mail_message = str_replace('<replier>', $post['username'], $mail_message);
                        $mail_message = str_replace(
                            '<post_url>',
                            Router::pathFor('viewPost', ['pid' => $new_pid]).'#p'.$new_pid,
                            $mail_message
                        );
                        $mail_message = str_replace(
                            '<unsubscribe_url>',
                            Router::pathFor('unsubscribeTopic', ['id' => $tid]),
                            $mail_message
                        );
                        $mail_message = str_replace(
                            '<board_mailer>',
                            ForumSettings::get('o_board_title'),
                            $mail_message
                        );
                        $mail_message = Container::get('hooks')->fire(
                            'model.post.send_notifications_reply_mail_message',
                            $mail_message
                        );

                        $mail_subject_full = str_replace(
                            '<topic_subject>',
                            $cur_posting['subject'],
                            $mail_subject_full
                        );
                        $mail_message_full = str_replace(
                            '<topic_subject>',
                            $cur_posting['subject'],
                            $mail_message_full
                        );
                        $mail_message_full = str_replace('<replier>', $post['username'], $mail_message_full);
                        $mail_message_full = str_replace('<message>', $cleaned_message, $mail_message_full);
                        $mail_message_full = str_replace(
                            '<post_url>',
                            Router::pathFor('viewPost', ['pid' => $new_pid]).'#p'.$new_pid,
                            $mail_message_full
                        );
                        $mail_message_full = str_replace(
                            '<unsubscribe_url>',
                            Router::pathFor('unsubscribeTopic', ['id' => $tid]),
                            $mail_message_full
                        );
                        $mail_message_full = str_replace(
                            '<board_mailer>',
                            ForumSettings::get('o_board_title'),
                            $mail_message_full
                        );
                        $mail_message_full = Container::get('hooks')->fire(
                            'model.post.send_notifications_reply_mail_message_full',
                            $mail_message_full
                        );

                        $notification_emails[$cur_subscriber['language']][0] = $mail_subject;
                        $notification_emails[$cur_subscriber['language']][1] = $mail_message;
                        $notification_emails[$cur_subscriber['language']][2] = $mail_subject_full;
                        $notification_emails[$cur_subscriber['language']][3] = $mail_message_full;

                        $mail_subject = $mail_message = $mail_subject_full = $mail_message_full = null;
                    }
                }

                // We have to double check here because the templates could be missing
                if (isset($notification_emails[$cur_subscriber['language']])) {
                    if ($cur_subscriber['notify_with_post'] == '0') {
                        Container::get('email')->dispatchMail(
                            $cur_subscriber['email'],
                            $notification_emails[$cur_subscriber['language']][0],
                            $notification_emails[$cur_subscriber['language']][1]
                        );
                    } else {
                        Container::get('email')->dispatchMail(
                            $cur_subscriber['email'],
                            $notification_emails[$cur_subscriber['language']][2],
                            $notification_emails[$cur_subscriber['language']][3]
                        );
                    }
                }
            }

            Container::get('hooks')->fire('model.post.send_notifications_reply');

            unset($cleaned_message);
        }
    }
265259
public void setStatus(BounceProxyStatus status) throws IllegalStateException {
        // this checks if the transition is valid
        if (this.status.isValidTransition(status)) {
            this.status = status;
        } else {
            throw new IllegalStateException("Illegal status transition from " + this.status + " to " + status);
        }
    }
312473
public function status($status)
    {
        if (!($status instanceof Status)) {
            $status = new Status($status);
        }

        $this->status = $status;

        return $this;
    }
1100068
public function create(StatusInterface $statusFrom, StatusInterface $statusTo)
    {
        $transition = new $this->transitionClass();
        $transition->setStatusFrom($statusFrom);
        $transition->setStatusTo($statusTo);

        return $transition;
    }
309153
def change_status(self, status):
        

        def cb():
            self.user.update(status=status)
            return status

        return signals.user_update(self, ACTIONS["STATUS"], cb,
                                   data={"status": self.status})
989105
public function incrementPostCount($post, $new_tid)
    {
        Container::get('hooks')->fire('model.post.increment_post_count_start', $post, $new_tid);

        if (!User::get()->is_guest) {
            $increment = DB::forTable('users')
                            ->where('id', User::get()->id)
                            ->find_one()
                            ->set('last_post', $post['time'])
                            ->set_expr('num_posts', 'num_posts+1');
            $increment = Container::get('hooks')->fireDB('model.post.increment_post_count_query', $increment);
            $increment = $increment->save();

            // Promote this user to a new group if enabled
            if (User::get()->g_promote_next_group != 0 &&
                User::get()->num_posts + 1 >= User::get()->g_promote_min_posts) {
                $new_group_id = User::get()->g_promote_next_group;
                $promote = DB::forTable('users')
                            ->where('id', User::get()->id)
                            ->find_one()
                            ->set('group_id', $new_group_id);
                $promote = Container::get('hooks')->fireDB('model.post.increment_post_count_query', $promote);
                $promote = $promote->save();
            }

            // Topic tracking stuff...
            $tracked_topics = Track::getTrackedTopics();
            $tracked_topics['topics'][$new_tid] = time();
            Track::setTrackedTopics($tracked_topics);
        } else {
            // Update the last_post field for guests
            $last_post = DB::forTable('online')
                            ->where('ident', Utils::getIp())
                            ->find_one()
                            ->set('last_post', $post['time']);
            $last_post = Container::get('hooks')->fireDB('model.post.increment_post_count_last_post', $last_post);
            $last_post = $last_post->save();
        }

        Container::get('hooks')->fire('model.post.increment_post_count');
    }
1281204
public function dispatchPostUpdateEvent(Post $post, $changeSet)
    {
        $event = new LogPostUpdateEvent($post, $changeSet);

        return $this->dispatch($event);
    }
789562
def new_cast_status(self, status):
        
        self.status = status
        if status:
            self.status_event.set()
802691
public function createTransition( $type, $old_id, $new_id ) {
		$transition = new  \Pressbooks\Entities\Cloner\Transition();
		$transition->type = $type;
		$transition->oldId = $old_id;
		$transition->newId = $new_id;
		$this->transitions[] = $transition;
	}
1106602
private static function _processGoalStateChange($newGoalState)
    {
        $last = self::$_lastState;
        $changes = self::_calculateChanges();

        if (count($changes) == 0) {
            self::_acceptLatestIncarnation($newGoalState, $last);
        } else {
            self::_raiseChangingEvent($changes);

            self::_acceptLatestIncarnation($newGoalState, $last);

            self::$_currentEnvironmentData = self::$_runtimeClient
                ->getRoleEnvironmentData();

            self::_raiseChangedEvent($changes);
        }
    }
284692
def old_status(self, old_status):
        
        allowed_values = ["NEW", "DONE", "REJECTED"]
        if old_status not in allowed_values:
            raise ValueError(
                "Invalid value for `old_status` ({0}), must be one of {1}"
                .format(old_status, allowed_values)
            )

        self._old_status = old_status
350574
public function postStatiiConversion( $status, $pb_export ) {

		if ( ! is_bool( $pb_export ) ) {
			return $status; // Doing it wrong...
		}

		if ( $pb_export ) {
			// When pb_export = true and post_status = draft, new post_status = private
			if ( $status === 'draft' ) {
				return 'private';
			}
			// When pb_export = true and post_status = publish, new post_status = publish
			if ( $status === 'publish' ) {
				return 'publish';
			}
		} else {
			// When pb_export = false and post_status = draft, new post_status = draft
			if ( $status === 'draft' ) {
				return 'draft';
			}
			// When pb_export = false and post_status = publish, new post_status = web-only
			if ( $status === 'publish' ) {
				return 'web-only';
			}
		}

		return $status; // No change
	}
753951
final protected function initPostStatusesTrait(): void {
		$postStatuses = $this->getPostStatuses();
		
		// first, we register our statuses.  notice that we directly call the
		// WordPress add_action() function because we want to use anonymous
		// functions here, and there's no good way to add these actions to a
		// LoaderInterface object as a result.  plus, we want these actions to
		// "just happen" without a programmer having to think about them.
		
		$options = [];
		foreach ($postStatuses as $postStatus) {
			$args = $this->getPostStatusArguments($postStatus);
			add_action("init", function () use ($postStatus, $args) {
				register_post_status($postStatus, $args);
			});
			
			$options[$postStatus] = $args["label"];
		}
		
		add_action("post_submitbox_misc_actions",
			function (\WP_Post $post) use ($options) {
				// registering our post status tells WordPress all about it,
				// but WordPress doesn't automatically add them to the <select>
				// elements in the DOM.  so, we do that here.  for more info
				// see https://core.trac.wordpress.org/ticket/12706.
				
				$jsonOptions = "{";
				$optionFormat = '"%s": { "display": "%s", "selected": %d },';
				foreach ($options as $status => $display) {
					$selected = (int)$post->post_status === $status;
					
					// for each of our options, we use the above format to
					// create a series of JSON strings which we can inject
					// into our JavaScript below.
					
					$jsonOptions .= sprintf($optionFormat, $status, $display, $selected);
				}
				
				// the loop above adds an extra comma to our JSON string.
				// we'll replace that comma with a the closing curly brace
				// to end said string.
				
				$jsonOptions = preg_replace("/,$/", "}", $jsonOptions);
				ob_start(); ?>

                <script id="php7BoilerplateAddPostStatuses">
					(function ($) {

						// we'll add our statuses into the scope of this
						// anonymous functions.  that way, it's accessible
						// to the other functions, anonymous or otherwise,
						// herein.  but, it won't conflict with any other
						// variable named statuses outside this scope.

						var statuses = <?= $jsonOptions ?>;

						$(document).ready(function () {
							var statusSelect = $("#post_status");
							if (statusSelect.length > 0) {

								// as long as we have a status <select> in
								// the DOM, we'll want to do some work to make
                                // our custom statuses work.

								setDisplayedStatus(statusSelect);
								$(".save-post-status").click(setHiddenStatus);
								addCustomStatuses(statusSelect);
							}
						});
						
						function setDisplayedStatus(statusSelect) {
							var status = statusSelect.val();
							
							// as long as our status is in our list of custom
                            // statuses, we want to make sure that the on-
                            // screen display of the posts's status matches
                            // the display of the selected option.
                            
                            if ($.inArray(status, statuses)) {
                                var display = statusSelect.find("option[value=" + status + "]").text();
                                $("#post-status-display").text(display);
                            }
						}
						
						function setHiddenStatus() {
							var status = $("#post_status").val();

							// as long as the status that's selected is a part
							// of our list of statuses, we'll want to set the
							// the value of the #hidden_post_status field to
							// the selected status.

							if ($.inArray(status, statuses)) {
								$("#hidden_post_status").val(status);
							}
						}

						function addCustomStatuses(statusSelect) {
							for(status in statuses) {
								if (statuses.hasOwnProperty(status)) {

									// for each of our custom statuses, we
									// create an <option>.  if our status is
									// selected, then we set that property.
									// otherwise, we set various attributes
									// and then append it to our <select>
									// element.

									var option = $("<option>")
										.prop("selected", statuses[status].selected)
										.text(statuses[status].display)
										.attr("value", status)
										.data("custom", true);

									statusSelect.append(option);
								}
							}

							// in case we need to do anything else after we've
							// changed the DOM, we fire this event, too.  then,
							// other JS can watch for it and handle any clean
							// up or whatever when it's caught.

							var event = new jQuery.Event("postStatusesAdded");
							statusSelect.trigger(event);
						}
					})(jQuery);
                </script>
				
				<?php echo ob_get_clean();
				
			}
		);
	}
376828
public function updateStatus($status)
    {
        if(empty($this->payload['id'])) {
            return;
        }

        $statusInstance = new Status($this->payload['id']);
        $statusInstance->update($status);
    }
772774
public function update($old, $new): bool
    {
        if ($this->hasNot($old)) {
            return false;
        }

        $this->set($old, $new);

        return true;
    }
1158558
protected function insertNewPost( $post_type, $p, $html, $chapter_parent, $post_status ) {

		$new_post = [
			'post_title' => wp_strip_all_tags( $p['post_title'] ),
			'post_name' => $p['post_name'],
			'post_type' => $post_type,
			'post_status' => ( 'part' === $post_type ) ? 'publish' : $post_status,
			'post_content' => $html,
		];

		if ( 'chapter' === $post_type ) {
			$new_post['post_parent'] = $chapter_parent;
		}

		$pid = wp_insert_post( add_magic_quotes( $new_post ) );

		return $pid;
	}