Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Place Ad Blocking Recovery Tags on the website #7212

Merged
merged 19 commits into from
Jun 28, 2023

Conversation

kuasha420
Copy link
Contributor

@kuasha420 kuasha420 commented Jun 27, 2023

Summary

Addresses issue:

Relevant technical choices

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 5.6.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

Do not alter or remove anything below. The following sections will be managed by moderators only.

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

@github-actions
Copy link

github-actions bot commented Jun 27, 2023

Build files for 136eb77 have been deleted.

Copy link
Collaborator

@aaemnnosttv aaemnnosttv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kuasha420 – this is looking great, just a few things to address.

Comment on lines +22 to +31
class WP_Query_404_Guard implements Guard_Interface {
/**
* Determines whether the guarded tag can be activated or not.
*
* @since n.e.x.t
*
* @return bool TRUE if guarded tag can be activated, otherwise FALSE or an error.
*/
public function can_activate() {
return ! is_404();
Copy link
Collaborator

@aaemnnosttv aaemnnosttv Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works but we can make it easier to test by providing a WP_Query to this via the constructor. The global function is a wrapper for calling this on WP_Query anyways so it's almost the same thing but using dependency injection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have access to the WP_Query object inside the AdSense module without using global? If not and we need to use global there, then I think the current solution makes more sense and looks cleaner. Also, the current tests are pretty simple as well, we don't need to specifically make it easier.

What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have access to the WP_Query object inside the AdSense module without using global

Nope! That's ok though. The module classes are already very interconnected with many other parts, so it wouldn't be a big change there.

I don't feel super strongly about it, and I agree that it's simple in this form too, my thought is that it's better to make the class work as a pure function when possible.

includes/Modules/AdSense.php Outdated Show resolved Hide resolved
includes/Modules/AdSense.php Outdated Show resolved Hide resolved
2
);

$this->do_init_tag_action();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should do this here because this will fire the same action as the adsense tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, looks like we can't use the get_tag_blocked_on_consent_attribute and other goodies that Module_Web_Tag provides as well for ABR. Should we just extend from Blockable_Tag_Interface or override the do_init_tag_action here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point about the blocked on consent stuff as well. This looks good (implementing as a basic Tag instead of a Module_Tag) as it will "inherit" the blocking from the main tag, if blocked. There's nothing really to need consent for either since these tags don't track the user or serve ads, etc.

includes/Modules/AdSense.php Outdated Show resolved Hide resolved
includes/Modules/AdSense/Ad_Blocking_Recovery_Web_Tag.php Outdated Show resolved Hide resolved
includes/Core/Tags/Guards/WP_Query_404_Guard.php Outdated Show resolved Hide resolved
includes/Modules/AdSense/Ad_Blocking_Recovery_Web_Tag.php Outdated Show resolved Hide resolved
Copy link
Collaborator

@aaemnnosttv aaemnnosttv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @kuasha420!

*
* @since n.e.x.t
* @access private
* @ignore
*/
class Ad_Blocking_Recovery_Web_Tag extends Module_Web_Tag {
class Ad_Blocking_Recovery_Web_Tag extends Tag {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 59 to 66
* @dataProvider data_can_not_activate
*/
public function test_can_not_activate( $settings ) {
$this->settings->merge( $settings );
$this->assertFalse( $this->guard->can_activate() );
}

public function test_cant_activate_when_useAdBlockerDetectionSnippet_is_falsy() {
$this->settings->merge( array( 'useAdBlockerDetectionSnippet' => false ) );
$this->assertFalse( $this->guard->can_activate(), 'Should return FALSE when useAdBlockerDetectionSnippet is falsy.' );
public function data_can_not_activate() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

2
);

$this->do_init_tag_action();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point about the blocked on consent stuff as well. This looks good (implementing as a basic Tag instead of a Module_Tag) as it will "inherit" the blocking from the main tag, if blocked. There's nothing really to need consent for either since these tags don't track the user or serve ads, etc.

@aaemnnosttv aaemnnosttv merged commit 712004e into develop Jun 28, 2023
@aaemnnosttv aaemnnosttv deleted the enhance/7186-place-abr-tags branch June 28, 2023 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants