Skip to content

Commit

Permalink
Revert "Simplify entry existence checks in source filters."
Browse files Browse the repository at this point in the history
This reverts commit 08cfbe8.
  • Loading branch information
remcotolsma committed Mar 26, 2024
1 parent 08cfbe8 commit c42318b
Showing 1 changed file with 19 additions and 41 deletions.
60 changes: 19 additions & 41 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,26 +271,15 @@ public function pre_submission( $form ) {
* @return string
*/
public function source_text( $text, Payment $payment ) {
$source_url = $this->source_url( '', $payment );
$text = __( 'Gravity Forms', 'pronamic_ideal' ) . '<br />';

$entry_text = \sprintf(
/* translators: %s: source id */
__( 'Entry #%s', 'pronamic_ideal' ),
$payment->get_source_id()
);
$entry = $this->is_active() ? RGFormsModel::get_lead( $payment->get_source_id() ) : false;

if ( '' !== $source_url ) {
$entry_text = \sprintf(
'<a href="%1$s">%2$s</a>',
$source_url,
$entry_text
);
}

$text = \sprintf(
'%1$s<br />%2$s',
\__( 'Gravity Forms', 'pronamic_ideal' ),
$entry_text
$text .= sprintf(
false === $entry ? '%2$s' : '<a href="%1$s">%2$s</a>',
add_query_arg( [ 'pronamic_gf_lid' => $payment->get_source_id() ], admin_url( 'admin.php' ) ),
/* translators: %s: source id */
sprintf( __( 'Entry #%s', 'pronamic_ideal' ), $payment->get_source_id() )
);

return $text;
Expand All @@ -317,9 +306,9 @@ public function source_description( $description, Payment $payment ) {
* @return string
*/
public function source_url( $url, Payment $payment ) {
$count_entries = \GFAPI::count_entries( null, [ 'id' => $payment->get_source_id() ] );
$entry = RGFormsModel::get_lead( $payment->get_source_id() );

if ( $count_entries > 0 ) {
if ( false !== $entry ) {
$url = add_query_arg(
[
'pronamic_gf_lid' => $payment->get_source_id(),
Expand All @@ -340,26 +329,15 @@ public function source_url( $url, Payment $payment ) {
* @return string
*/
public function subscription_source_text( $text, Subscription $subscription ) {
$source_url = $this->subscription_source_url( '', $subscription );
$text = __( 'Gravity Forms', 'pronamic_ideal' ) . '<br />';

$entry_text = \sprintf(
/* translators: %s: source id */
__( 'Entry #%s', 'pronamic_ideal' ),
$subscription->get_source_id()
);

if ( '' !== $source_url ) {
$entry_text = \sprintf(
'<a href="%1$s">%2$s</a>',
$source_url,
$entry_text
);
}
$entry = $this->is_active() ? RGFormsModel::get_lead( $subscription->get_source_id() ) : false;

$text = \sprintf(
'%1$s<br />%2$s',
\__( 'Gravity Forms', 'pronamic_ideal' ),
$entry_text
$text .= sprintf(
false === $entry ? '%2$s' : '<a href="%1$s">%2$s</a>',
add_query_arg( [ 'pronamic_gf_lid' => $subscription->get_source_id() ], admin_url( 'admin.php' ) ),
/* translators: %s: source id */
sprintf( __( 'Entry #%s', 'pronamic_ideal' ), $subscription->get_source_id() )
);

return $text;
Expand All @@ -386,9 +364,9 @@ public function subscription_source_description( $description, Subscription $sub
* @return string
*/
public function subscription_source_url( $url, Subscription $subscription ) {
$count_entries = \GFAPI::count_entries( null, [ 'id' => $subscription->get_source_id() ] );
$entry = RGFormsModel::get_lead( $subscription->get_source_id() );

if ( $count_entries > 0 ) {
if ( false !== $entry ) {
$url = add_query_arg(
[
'pronamic_gf_lid' => $subscription->get_source_id(),
Expand Down Expand Up @@ -1253,7 +1231,7 @@ public function replace_merge_tags( $text, $form, $entry, $url_encode, $esc_html

/**
* Bank transfer recipient details.
*
*
* Use bank transfer details from last subscription payment if available.
*/
$payment = null;
Expand Down

0 comments on commit c42318b

Please sign in to comment.