| 1 |
<?php |
| 2 |
/** |
| 3 |
* Where the plugin sends people who want to tell us something. |
| 4 |
* |
| 5 |
* One place for both destinations, because they are linked from five different |
| 6 |
* spots and a URL that has to be changed in five files is a URL that ends up |
| 7 |
* inconsistent. |
| 8 |
* |
| 9 |
* These addresses ship inside every installed copy and stay there until the site |
| 10 |
* updates, which for a WordPress plugin can be years. They have to be addresses |
| 11 |
* we can redirect later, not addresses that happen to point at today's helpdesk. |
| 12 |
*/ |
| 13 |
|
| 14 |
namespace forge12\contactform7\CF7DoubleOptIn; |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Base of the product site. No language segment — see product_lang(). |
| 22 |
*/ |
| 23 |
const PRODUCT_BASE = 'https://www.forge12.com'; |
| 24 |
|
| 25 |
/** |
| 26 |
* The product page, without a language segment. |
| 27 |
* |
| 28 |
* forge12.com prefixes the locale itself (a request to /shop/… lands on |
| 29 |
* /de/shop/…), so the short form survives whatever the site does with its |
| 30 |
* language routing later. That matters here more than elsewhere: this URL is |
| 31 |
* used for the plugin headers, and a `Plugin URI:` is a static string that |
| 32 |
* cannot carry any locale logic at all. |
| 33 |
*/ |
| 34 |
const PRODUCT_PATH = '/shop/contact-form-7-double-opt-in'; |
| 35 |
|
| 36 |
/** |
| 37 |
* Feedback form — for "this could be better" and "this is broken for me". |
| 38 |
* |
| 39 |
* Deliberately without a language segment, unlike the support link below: |
| 40 |
* only the German page exists (`/de/shop/…/feedback`). Sending an English |
| 41 |
* speaker to a German page is a poor greeting; sending them to a 404 is worse. |
| 42 |
* Once `/en/shop/…/feedback` exists, this can take the same `%s` treatment as |
| 43 |
* SUPPORT_URL and the distinction disappears. |
| 44 |
*/ |
| 45 |
const FEEDBACK_URL = PRODUCT_BASE . PRODUCT_PATH . '/feedback'; |
| 46 |
|
| 47 |
/** |
| 48 |
* Support — for "I need help with my installation". |
| 49 |
* |
| 50 |
* Exists in both languages, so this one does resolve the segment. May sit |
| 51 |
* behind the login, since accounts live on the same domain. |
| 52 |
*/ |
| 53 |
const SUPPORT_URL = PRODUCT_BASE . '/%s/account/support'; |
| 54 |
|
| 55 |
/** |
| 56 |
* The language segment forge12.com expects. |
| 57 |
* |
| 58 |
* The site serves /de and /en. Shared by every link the plugin builds so they |
| 59 |
* cannot drift apart. |
| 60 |
* |
| 61 |
* @return string 'de' or 'en'. |
| 62 |
*/ |
| 63 |
function product_lang(): string { |
| 64 |
$locale = function_exists( 'determine_locale' ) ? determine_locale() : get_locale(); |
| 65 |
|
| 66 |
return strpos( (string) $locale, 'de' ) === 0 ? 'de' : 'en'; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Query arguments every outbound link carries. |
| 71 |
* |
| 72 |
* The plugin version and nothing else: enough to tell a report about 5.1 from |
| 73 |
* one about 4.0, without saying anything about the site it came from. The |
| 74 |
* `from` value names the entry point so we can see which of them people |
| 75 |
* actually use. |
| 76 |
* |
| 77 |
* @param string $from Which entry point the click came from (e.g. 'review-notice'). |
| 78 |
* |
| 79 |
* @return array<string, string> |
| 80 |
*/ |
| 81 |
function link_args( string $from = '' ): array { |
| 82 |
$args = array( 'v' => defined( 'FORGE12_OPTIN_VERSION' ) ? FORGE12_OPTIN_VERSION : '' ); |
| 83 |
|
| 84 |
if ( $from !== '' ) { |
| 85 |
$args['from'] = $from; |
| 86 |
} |
| 87 |
|
| 88 |
return $args; |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Build a link to the product page. |
| 93 |
* |
| 94 |
* @param string $from Which entry point the click came from. |
| 95 |
* |
| 96 |
* @return string |
| 97 |
*/ |
| 98 |
function get_product_url( string $from = '' ): string { |
| 99 |
$url = add_query_arg( link_args( $from ), PRODUCT_BASE . PRODUCT_PATH ); |
| 100 |
|
| 101 |
/** |
| 102 |
* Filter a link to the product site. |
| 103 |
* |
| 104 |
* @param string $url The full URL including its query arguments. |
| 105 |
* @param string $from Which entry point this is. |
| 106 |
* |
| 107 |
* @since 5.2.0 |
| 108 |
*/ |
| 109 |
return (string) apply_filters( 'f12_doi_product_url', $url, $from ); |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Build a feedback link. |
| 114 |
* |
| 115 |
* @param string $from Which entry point the click came from. |
| 116 |
* |
| 117 |
* @return string |
| 118 |
*/ |
| 119 |
function get_feedback_url( string $from = '' ): string { |
| 120 |
$url = add_query_arg( link_args( $from ), FEEDBACK_URL ); |
| 121 |
|
| 122 |
/** |
| 123 |
* Filter the feedback destination. |
| 124 |
* |
| 125 |
* @param string $url The full URL including its query arguments. |
| 126 |
* @param string $from Which entry point this is. |
| 127 |
* |
| 128 |
* @since 5.2.0 |
| 129 |
*/ |
| 130 |
return (string) apply_filters( 'f12_doi_feedback_url', $url, $from ); |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* Build a support link. Same rules as get_feedback_url(). |
| 135 |
* |
| 136 |
* @param string $from Which entry point the click came from. |
| 137 |
* |
| 138 |
* @return string |
| 139 |
*/ |
| 140 |
function get_support_url( string $from = '' ): string { |
| 141 |
$url = add_query_arg( link_args( $from ), sprintf( SUPPORT_URL, product_lang() ) ); |
| 142 |
|
| 143 |
/** |
| 144 |
* Filter the support destination. |
| 145 |
* |
| 146 |
* @param string $url The full URL including its query arguments. |
| 147 |
* @param string $from Which entry point this is. |
| 148 |
* |
| 149 |
* @since 5.2.0 |
| 150 |
*/ |
| 151 |
return (string) apply_filters( 'f12_doi_support_url', $url, $from ); |
| 152 |
} |
| 153 |
|