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

Activation/Deactivation methods #2698

Open
Tracked by #2044
jonathanbossenger opened this issue Jul 19, 2024 · 9 comments
Open
Tracked by #2044

Activation/Deactivation methods #2698

jonathanbossenger opened this issue Jul 19, 2024 · 9 comments

Comments

@jonathanbossenger
Copy link
Collaborator

jonathanbossenger commented Jul 19, 2024

Details

  • Content type (Online Workshop, Lesson, Course, Tutorial, or Lesson Plan): Lesson
  • Content title: Activation/Deactivation hooks
  • Topic description: The correct way to use plugins' activation and deactivation hooks.
  • Audience (User, Developer, Designer, Contributor, etc.): Developer
  • Experience Level (Beginner, Intermediate, Advanced, Any): Intermediate

Prerequisites

It is assumed that the learner has already completed the following lessons:

Learning Objectives

  • Describe, with examples, the ways to perform actions on plugin activation and deactivation

Related Resources and Other Notes

Automation Code

//lesson

Copy link
Contributor

Lesson Development Checklist

  • Gather any relevant links to Support, Docs, or related material
  • Description and Objectives finalized
  • Lesson created and announced to the team for review
  • Lesson reviewed
  • Lesson video submitted and published to WPTV
  • Lesson created on Learn.WordPress.org
  • Lesson video published to YouTube
  • Lesson on Learn.WordPress.org updated with YouTube video
  • Lesson published to Learn.WordPress.org

@WordPress WordPress deleted a comment from github-actions bot Aug 11, 2024
@jonathanbossenger jonathanbossenger changed the title Activation/Deactivation hooks Activation/Deactivation methods Sep 5, 2024
@WordPress WordPress deleted a comment from github-actions bot Sep 6, 2024
@MichelleBlanchette
Copy link

@jonathanbossenger I think training developers to use the activation and deactivation hooks for adding and removing data is quite risky for our ecosystem since my understanding is that is not the intended user experience in wp-admin. I think your code example is more appropriate in discussion of the uninstallation hook since that is typically when plugin data should actually be removed.

I believe the Cron lesson comes later in the course, but my understanding is the activation and deactivation hooks are best used for adding and cleaning up side-effects, similar to useEffect in React with mounting and unmounting.

Is there a more appropriate code sample that could be provided for this lesson?

@jonathanbossenger
Copy link
Collaborator Author

@MichelleBlanchette, thanks for your feedback; you do raise a valid point.

In this specific code example, it could be argued that the addition of the option in the database is a side effect of activating the plugin, and so, depending on the plugin's specific requirements, removing that option on deactivation could make sense.

The other problem is, this plugin is not something someone might build in the real world. One of the main reasons I went with a very simplified code example in this lesson is that it's easy to test that the deactivation code has worked. The learner can check the table and see that the option has been removed. That's always the problem with example code: It's generally not a real-world solution with all the considerations that go with it.

One thing I had planned on doing was including a section in the Uninstall Methods lesson, which is right after this one, on when it's generally recommended to use deactivation vs. uninstallation.

So perhaps a short section at the end of this lesson covering these considerations would help? This can also be used to direct learners to the next lesson, which could then also cover these considerations further.

@MichelleBlanchette
Copy link

@jonathanbossenger I like the idea of leaving a little cliffhanger at the end, like you're kind of saying, that encourages moving on to the next lesson about uninstallation. I think that could work. Thanks!

@jonathanbossenger
Copy link
Collaborator Author

Great. I'll work on getting the script updated.

@jonathanbossenger
Copy link
Collaborator Author

Added section on Plugin deactivation and data cleanup

@MichelleBlanchette
Copy link

Looks great @jonathanbossenger ~ Thank you for that!

@jonathanbossenger
Copy link
Collaborator Author

Audio: https://drive.google.com/file/d/1lt_jQFXDYg_5wnvi0lMyGjF7xZsXIcgS/view?usp=sharing

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

No branches or pull requests

2 participants