Skip to content

Refactor Sign in with Google module to use the Web_Tag class/infrastructure #10027

@tofumatt

Description

@tofumatt

Feature Description

The current logic used to render the necessary script tag(s) for Sign in With Google does not conform to the standard used by other modules with a tag, and does not use the Module_With_Tag interface nor an implementation/extension of Module_Web_Tag. Instead, logic is self-contained within the main Sign_In_With_Google class by way of the render_signinwithgoogle() method.

The logic within the the render_signinwithgoogle() method, along with necessary tag guard logic (if any) should be migrated into a Web_Tag instance and incorporated into the main Sign_In_With_Google class via the same pattern used by other modules, i.e. use of a register_tag() method hooked to template_redirect action (and/or other actions applicable to SiWG given the locations the script needs to render), and creation of an applicable Web_Tag class which itself extends from Module_Web_Tag. This Web_Tag class should contain much (if not all) of the logic currently contained within the render_signinwithgoogle() method.


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

Acceptance criteria

  • The Sign_In_With_Google class implements the Module_With_Tag interface
  • All necessary Sign in With Google scripts/tags are rendered using an applicable tag class within the SiWG namespace, which itself is an extension of the Module_Web_Tag class, i.e. Google\Site_Kit\Modules\Sign_In_With_Google\Web_Tag
  • Tag registration is handled within the main Sign_In_With_Google using methods required by the Module_With_Tag interface
  • All (or as much of) the script rendering and guarding logic is moved from the current render_signinwithgoogle() method and into applicable methods within the SiWG specific Web_Tag class

Implementation Brief

  • Add includes/Modules/Sign_In_With_Google/Tag_Guard.php
    • Should extend Module_Tag_Guard, and include Module_Settings in the constructor
    • You can check includes/Modules/Reader_Revenue_Manager/Tag_Guard.php for an example
    • Add can_activate
  • Add includes/Modules/Sign_In_With_Google/Web_Tag.php
    • It should extend Module_Web_Tag
    • Add register method:
      • Hook into wp_footer and login_footer, and invoke callback render_signinwithgoogle_scripts
      • Add render_signinwithgoogle_scripts method and move over the logic from Google\Site_Kit\Modules\Sign_In_With_Google::render_signinwithgoogle
        • $this->can_render_signinwithgoogle() conditional won't be needed here anymore, as this is checked as part of the tag guard checks
  • Update Google\Site_Kit\Modules\Sign_In_With_Google
    • It should implement Module_With_Tag
    • In register method:
      • Hook into the template_redirect action and invoke register_tag method
    • Add register_tag method
      • You can check Google\Site_Kit\Modules\Ads::register_tag as an example
      • Instantiate Web_Tag using clientID setting for tag ID argument
      • Use only newly added Tag_Guard for guards $tag->use_guard, others are not needed as they are not affecting existing rendering.
      • Register tag invoking $tag->register()

Test Coverage

  • Split tests from tests/phpunit/integration/Modules/Sign_In_With_GoogleTest.php and move the parts for test_render_signinwithgoogle to the tests for web tag class

QA Brief

  • Enable the SiwG module and test login and registration continue to load and function as expected on the wp-login page and via the login button block within a post or page. See the epic bug bash instructions for details.

Changelog entry

  • Refactor Sign in with Google to use common web tag infrastructure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Module: Sign in with GoogleSign in with Google (SiwG) related issues.P2Low priorityTeam SIssues for Squad 1Type: EnhancementImprovement of an existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions