From db6074a9d9e47f79bf423c99e7b6bf87b197b5a6 Mon Sep 17 00:00:00 2001 From: Aurorum <43215253+Aurorum@users.noreply.github.com> Date: Wed, 22 May 2024 15:47:53 +0100 Subject: [PATCH 1/4] Initial commit --- client/my-sites/earn/ads/form-settings.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/client/my-sites/earn/ads/form-settings.tsx b/client/my-sites/earn/ads/form-settings.tsx index 01c0575d3b2635..77badf50a4bab5 100644 --- a/client/my-sites/earn/ads/form-settings.tsx +++ b/client/my-sites/earn/ads/form-settings.tsx @@ -32,6 +32,7 @@ type DisplayOptions = { display_archive?: boolean; enable_header_ad?: boolean; second_belowpost?: boolean; + inline_enabled?: boolean; sidebar?: boolean; }; @@ -253,6 +254,12 @@ const AdsFormSettings = () => { onChange={ () => handleDisplayToggle( 'second_belowpost' ) } label={ translate( 'Second ad below post' ) } /> + handleDisplayToggle( 'inline_enabled' ) } + label={ translate( 'Inline within post content' ) } + /> { ! siteIsJetpack && ( Date: Wed, 22 May 2024 16:14:21 +0100 Subject: [PATCH 2/4] WordAds: Include Inline Ads Setting --- client/my-sites/earn/ads/form-settings.tsx | 23 +++++++++++++------ client/my-sites/earn/ads/payments.tsx | 1 + .../wpcom/wordads/settings/index.js | 1 + .../state/selectors/get-wordads-settings.js | 1 + .../selectors/test/get-wordads-settings.js | 5 ++++ 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/client/my-sites/earn/ads/form-settings.tsx b/client/my-sites/earn/ads/form-settings.tsx index 77badf50a4bab5..027fd688ab77e2 100644 --- a/client/my-sites/earn/ads/form-settings.tsx +++ b/client/my-sites/earn/ads/form-settings.tsx @@ -21,7 +21,11 @@ import { useDispatch, useSelector } from 'calypso/state'; import getSiteUrl from 'calypso/state/selectors/get-site-url'; import { getWordadsSettings } from 'calypso/state/selectors/get-wordads-settings'; import isSavingWordadsSettings from 'calypso/state/selectors/is-saving-wordads-settings'; -import { isJetpackSite, getCustomizerUrl } from 'calypso/state/sites/selectors'; +import { + isJetpackSite, + isJetpackMinimumVersion, + getCustomizerUrl, +} from 'calypso/state/sites/selectors'; import { getSelectedSite, getSelectedSiteId } from 'calypso/state/ui/selectors'; import { saveWordadsSettings } from 'calypso/state/wordads/settings/actions'; @@ -65,6 +69,9 @@ const AdsFormSettings = () => { ); const wordadsSettings = useSelector( ( state ) => getWordadsSettings( state, siteId ) ); const widgetsUrl = useSelector( ( state ) => getCustomizerUrl( state, siteId, 'widgets' ) ); + const supportsInlineAds = useSelector( ( state ) => + isJetpackMinimumVersion( state, siteId, '13.5-a.1' ) + ); const isLoading = ! wordadsSettings || isSavingSettings; const isWordAds = site?.options?.wordads; @@ -254,12 +261,14 @@ const AdsFormSettings = () => { onChange={ () => handleDisplayToggle( 'second_belowpost' ) } label={ translate( 'Second ad below post' ) } /> - handleDisplayToggle( 'inline_enabled' ) } - label={ translate( 'Inline within post content' ) } - /> + { supportsInlineAds && ( + handleDisplayToggle( 'inline_enabled' ) } + label={ translate( 'Inline within post content' ) } + /> + ) } { ! siteIsJetpack && ( ( dispatch, getState ) => { wordads_display_archive: settings.display_options.display_archive, enable_header_ad: settings.display_options.enable_header_ad, wordads_second_belowpost: settings.display_options.second_belowpost, + wordads_inline_enabled: settings.display_options.inline_enabled, wordads_ccpa_enabled: settings.ccpa_enabled, wordads_ccpa_privacy_policy_url: settings.ccpa_privacy_policy_url, wordads_custom_adstxt_enabled: settings.custom_adstxt_enabled, diff --git a/client/state/selectors/get-wordads-settings.js b/client/state/selectors/get-wordads-settings.js index 71355916768a0c..31f84e45414fb3 100644 --- a/client/state/selectors/get-wordads-settings.js +++ b/client/state/selectors/get-wordads-settings.js @@ -37,6 +37,7 @@ export const getWordadsSettings = createSelector( display_archive: siteSettings.wordads_display_archive, enable_header_ad: siteSettings.enable_header_ad, second_belowpost: siteSettings.wordads_second_belowpost, + inline_enabled: siteSettings.wordads_inline_enabled, }, ccpa_enabled: siteSettings.wordads_ccpa_enabled, ccpa_privacy_policy_url: siteSettings.wordads_ccpa_privacy_policy_url, diff --git a/client/state/selectors/test/get-wordads-settings.js b/client/state/selectors/test/get-wordads-settings.js index b87511adfac071..f972980ad56991 100644 --- a/client/state/selectors/test/get-wordads-settings.js +++ b/client/state/selectors/test/get-wordads-settings.js @@ -90,6 +90,7 @@ describe( 'getWordadsSettings()', () => { wordads_display_archive: 'wordads_display_archive-test', enable_header_ad: 'enable_header_ad-test', wordads_second_belowpost: 'wordads_second_belowpost-test', + wordads_inline_enabled: 'wordads_inline_enabled-test', wordads_ccpa_enabled: 'wordads_ccpa_enabled-test', wordads_ccpa_privacy_policy_url: 'wordads_ccpa_privacy_policy_url-test', wordads_custom_adstxt_enabled: 'wordads_custom_adstxt_enabled-test', @@ -117,6 +118,10 @@ describe( 'getWordadsSettings()', () => { 'display_options.second_belowpost', 'wordads_second_belowpost-test' ); + expect( output ).toHaveProperty( + 'display_options.inline_enabled', + 'wordads_inline_enabled-test' + ); expect( output ).toHaveProperty( 'ccpa_enabled', 'wordads_ccpa_enabled-test' ); expect( output ).toHaveProperty( 'ccpa_privacy_policy_url', From 9bfce5ff7660321bc84ef52712bce34f3933db01 Mon Sep 17 00:00:00 2001 From: Aurorum <43215253+Aurorum@users.noreply.github.com> Date: Wed, 22 May 2024 23:05:40 +0100 Subject: [PATCH 3/4] Fix supportsInlineAds to include Simple sites --- client/my-sites/earn/ads/form-settings.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/my-sites/earn/ads/form-settings.tsx b/client/my-sites/earn/ads/form-settings.tsx index 027fd688ab77e2..78872b05e89723 100644 --- a/client/my-sites/earn/ads/form-settings.tsx +++ b/client/my-sites/earn/ads/form-settings.tsx @@ -69,9 +69,10 @@ const AdsFormSettings = () => { ); const wordadsSettings = useSelector( ( state ) => getWordadsSettings( state, siteId ) ); const widgetsUrl = useSelector( ( state ) => getCustomizerUrl( state, siteId, 'widgets' ) ); - const supportsInlineAds = useSelector( ( state ) => + const isMinVersionForInlineAds = useSelector( ( state ) => isJetpackMinimumVersion( state, siteId, '13.5-a.1' ) ); + const supportsInlineAds = ! siteIsJetpack || isMinVersionForInlineAds; const isLoading = ! wordadsSettings || isSavingSettings; const isWordAds = site?.options?.wordads; From e3ceca1acb5fdc2cbd24533581b882eb54eda553 Mon Sep 17 00:00:00 2001 From: Collyn Philleo Date: Wed, 22 May 2024 15:56:01 -0700 Subject: [PATCH 4/4] Fix TS error for siteId potentially being null --- client/my-sites/earn/ads/form-settings.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/my-sites/earn/ads/form-settings.tsx b/client/my-sites/earn/ads/form-settings.tsx index 78872b05e89723..c9bad80e91b602 100644 --- a/client/my-sites/earn/ads/form-settings.tsx +++ b/client/my-sites/earn/ads/form-settings.tsx @@ -69,8 +69,8 @@ const AdsFormSettings = () => { ); const wordadsSettings = useSelector( ( state ) => getWordadsSettings( state, siteId ) ); const widgetsUrl = useSelector( ( state ) => getCustomizerUrl( state, siteId, 'widgets' ) ); - const isMinVersionForInlineAds = useSelector( ( state ) => - isJetpackMinimumVersion( state, siteId, '13.5-a.1' ) + const isMinVersionForInlineAds = useSelector( + ( state ) => siteId && isJetpackMinimumVersion( state, siteId, '13.5-a.1' ) ); const supportsInlineAds = ! siteIsJetpack || isMinVersionForInlineAds;