| @@ -24,8 +24,9 @@ | ||
| 24 | 24 | * string if the URL could not be generated. |
| 25 | 25 | * |
| 26 | 26 | * @since 2.6.0 |
| 27 | 27 | * @since 3.1.0 Moved to class-dashboard-link.php. Added source parameter. |
| 28 | + * @since 3.16.1 Made the $campaign and $source parameters optional. | |
| 28 | 29 | * |
| 29 | 30 | * @param WP_Post $post Which post object or ID to check. |
| 30 | 31 | * @param string $site_id Site ID or empty string. |
| 31 | 32 | * @param string $campaign Campaign name for the `utm_campaign` URL parameter. |
| @@ -31,9 +32,9 @@ | ||
| 31 | 32 | * @param string $campaign Campaign name for the `utm_campaign` URL parameter. |
| 32 | 33 | * @param string $source Source name for the `utm_source` URL parameter. |
| 33 | 34 | * @return string |
| 34 | 35 | */ |
| 35 | - public static function generate_url( WP_Post $post, string $site_id, string $campaign, string $source ): string { | |
| 36 | + public static function generate_url( WP_Post $post, string $site_id, string $campaign = '', string $source = '' ): string { | |
| 36 | 37 | /** |
| 37 | 38 | * Internal variable. |
| 38 | 39 | * |
| 39 | 40 | * @var string|false |
| @@ -48,8 +49,20 @@ | ||
| 48 | 49 | 'utm_campaign' => $campaign, |
| 49 | 50 | 'utm_source' => $source, |
| 50 | 51 | 'utm_medium' => 'wp-parsely', |
| 51 | 52 | ); |
| 53 | + | |
| 54 | + if ( '' === $campaign ) { | |
| 55 | + unset( $query_args['utm_campaign'] ); | |
| 56 | + } | |
| 57 | + | |
| 58 | + if ( '' === $source ) { | |
| 59 | + unset( $query_args['utm_source'] ); | |
| 60 | + } | |
| 61 | + | |
| 62 | + if ( ! isset( $query_args['utm_campaign'] ) && ! isset( $query_args['utm_source'] ) ) { | |
| 63 | + unset( $query_args['utm_medium'] ); | |
| 64 | + } | |
| 52 | 65 | |
| 53 | 66 | return add_query_arg( $query_args, Parsely::get_dash_url( $site_id ) ); |
| 54 | 67 | } |
| 55 | 68 | |