Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions classes/models/FrmInbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,18 @@ private function is_for_user( $message ) {
return true;
}
$who = (array) $message['who'];
if ( in_array( 'all', $who, true ) || in_array( 'everyone', $who, true ) ) {
if ( $this->is_for_everyone( $who ) ) {
return true;
}
if ( in_array( $this->get_user_type(), $who, true ) ) {
if ( $this->is_user_type( $who ) ) {
return true;
}
if ( in_array( 'free_first_30', $who, true ) && $this->is_free_first_30() ) {
return true;
}
if ( in_array( 'free_not_first_30', $who, true ) && $this->is_free_not_first_30() ) {
return true;
}
/**
* Allow for other special inbox cases in other add-ons.
*
Expand All @@ -230,6 +233,26 @@ private function is_for_user( $message ) {
return (bool) apply_filters( 'frm_inbox_message_is_for_user', false, $who, $message );
}

/**
* @since x.x
*
* @param array $who
* @return bool
*/
private function is_for_everyone( $who ) {
return in_array( 'all', $who, true ) || in_array( 'everyone', $who, true );
}

/**
* @since x.x
*
* @param array $who
* @return bool
*/
private function is_user_type( $who ) {
return in_array( $this->get_user_type(), $who, true );
}

private function get_user_type() {
if ( ! FrmAppHelper::pro_is_installed() ) {
return 'free';
Expand Down Expand Up @@ -378,20 +401,45 @@ private function update_list() {
* @return bool
*/
private function is_free_first_30() {
return $this->is_free() && $this->is_first_30();
}

/**
* @since x.x
*
* @return bool
*/
private function is_first_30() {
$activation_timestamp = get_option( 'frm_first_activation' );
if ( false === $activation_timestamp ) {
// If the option does not exist, assume that it is
// because the user was active before this option was introduced.
return false;
}
if ( FrmAppHelper::pro_is_included() ) {
// Not free.
return false;
}
$cutoff = strtotime( '-30 days' );
return $activation_timestamp > $cutoff;
}

/**
* @since x.x
*
* @return bool
*/
private function is_free_not_first_30() {
return $this->is_free() && ! $this->is_first_30();
}
Comment thread
Crabcyborg marked this conversation as resolved.

/**
* Check if the Pro plugin is active. If not, consider the user to be on the free version.
*
* @since x.x
*
* @return bool
*/
private function is_free() {
return ! FrmAppHelper::pro_is_included();
}

/**
* Show a banner message if one is available.
*
Expand Down