*/ public $warnings = array(); /** * When set, the subscription is skipped (status 'invalid') with this code. * * @var string|null */ public $skip_reason = null; /** * Human message for the skip reason. * * @var string|null */ public $skip_message = null; /** * State before (fingerprint fields). * * @var array */ public $before_state = array(); /** * Predicted state after. * * @var array */ public $after_state = array(); /** * Adds a change if before and after differ. * * @param string $field Field. * @param mixed $before Before. * @param mixed $after After. * @param string|null $item_name Item name. * @return void */ public function change( $field, $before, $after, $item_name = null ) { if ( wp_json_encode( $before ) === wp_json_encode( $after ) ) { return; } $this->changes[] = new FieldDiff( $field, $before, $after, $item_name ); } /** * Adds a warning. * * @param string $code Code. * @param string $message Message. * @return void */ public function warn( $code, $message ) { $this->warnings[] = array( 'code' => $code, 'message' => $message, ); } /** * Marks the subscription as not applicable. * * @param string $code Code. * @param string $message Message. * @return void */ public function skip( $code, $message ) { $this->skip_reason = $code; $this->skip_message = $message; } /** * Whether any change is predicted. * * @return bool */ public function has_changes() { return ! empty( $this->changes ); } /** * Whether the subscription must be skipped. * * @return bool */ public function is_skipped() { return null !== $this->skip_reason; } /** * Fields with predicted changes. * * @return string[] */ public function changed_fields() { return array_map( static function ( FieldDiff $diff ) { return $diff->field; }, $this->changes ); } /** * Array form of the changes for storage. * * @return array> */ public function changes_to_array() { return array_map( static function ( FieldDiff $diff ) { return $diff->to_array(); }, $this->changes ); } }