Learn icon indicating copy to clipboard operation
Learn copied to clipboard

Activation/Deactivation methods

Open jonathanbossenger opened this issue 1 year ago • 11 comments

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

  • https://developer.wordpress.org/plugins/plugin-basics/activation-deactivation-hooks/

Automation Code

//lesson

jonathanbossenger avatar Jul 19 '24 19:07 jonathanbossenger

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

github-actions[bot] avatar Jul 19 '24 19:07 github-actions[bot]

Script: https://github.com/jonathanbossenger/wp-content/blob/main/plugin-developer-learning-pathway/01-Plugin-Development-Practices/03-Activation-Deactivation-methods.md

jonathanbossenger avatar Sep 06 '24 14:09 jonathanbossenger

@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?

MichelleBlanchette avatar Sep 11 '24 12:09 MichelleBlanchette

@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.

jonathanbossenger avatar Sep 12 '24 06:09 jonathanbossenger

@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!

MichelleBlanchette avatar Sep 12 '24 11:09 MichelleBlanchette

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

jonathanbossenger avatar Sep 12 '24 14:09 jonathanbossenger

Looks great @jonathanbossenger ~ Thank you for that!

MichelleBlanchette avatar Sep 13 '24 12:09 MichelleBlanchette

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

jonathanbossenger avatar Sep 17 '24 12:09 jonathanbossenger

Hi team, I would like to be involved in editing this video 👍

agiljulio avatar Oct 08 '24 03:10 agiljulio

Great stuff, thanks @agiljulio I have assigned you to the issue.

jonathanbossenger avatar Oct 08 '24 07:10 jonathanbossenger

Video link for review: https://drive.google.com/file/d/1YyCHMApYSBquN_sgUFUisKCn6iLrVv_E/view?usp=sharing

jonathanbossenger avatar Nov 20 '24 11:11 jonathanbossenger

Thanks @agiljulio looks good to me. I've announced this in the training team Slack channel for public review.

jonathanbossenger avatar Nov 25 '24 10:11 jonathanbossenger

@jonathanbossenger looks good to me.

I liked the final note that, activation / deactivation hooks don't work with CLI.

laxmariappan avatar Nov 25 '24 13:11 laxmariappan

This is a nice overview. I'm wondering if it would be a good idea to mention that if you want to give users the ability to delete on deactivation, that you add an option to your plugins settings. Something like "Delete all plugin data on deactivation" Which you see in some plugins.

Please tick all items you've confirmed:

  • [x] Learning outcomes/objectives are clear.
  • [x] Technical concepts introduced in the content are accurate.
  • [x] The speed of demonstrations are easy to follow.
  • [x] The narration audio matches what is shown visually.
  • [x] Spelling and grammar are correct.
  • [x] Sound quality is consistent throughout the video.
  • [x] Brand Usage Guidelines and Promotional Guidelines are being followed.
  • [x] Media assets are all in the public domain (CC0).

digitalchild avatar Nov 26 '24 05:11 digitalchild

Tutorial/Lessons Review Checklist

Please tick all items you've confirmed:

  • [x] Learning outcomes/objectives are clear.
  • [x] Technical concepts introduced in the content are accurate.
  • [x] The speed of demonstrations are easy to follow.
  • [x] The narration audio matches what is shown visually.
  • [x] Spelling and grammar are correct.
  • [x] Sound quality is consistent throughout the video.
  • [x] Brand Usage Guidelines and Promotional Guidelines are being followed.
  • [ ] Media assets are all in the public domain (CC0).
  • I don't know where the animated graphics and icons are from to confirm this

I have some feedback particularly on the visuals:

  • 0:35 & 1:02 & 1:32 All the code "errors" are very distracting and make it feel like I shouldn't trust the code examples being shown to me. Is that the PHP Intelephense extension for VS Code? 😆 Can that be disabled while showing code examples?
  • 1:45–2:10 I found these visuals unhelpful and distracting from what's being said. I think a text slide with the notable points being said and/or showing relevant screens in wp-admin would be more helpful.

MichelleBlanchette avatar Nov 27 '24 02:11 MichelleBlanchette

Thanks for the feedback everyone.

I'm wondering if it would be a good idea to mention that if you want to give users the ability to delete on deactivation, that you add an option to your plugins settings. Something like "Delete all plugin data on deactivation" Which you see in some plugins.

@digitalchild I did think of that. However I figured that would lead to more questions (How would I do this, how to create modals inside WordPress etc) and therefore ultimately left this out.

0:35 & 1:02 & 1:32 All the code "errors" are very distracting and make it feel like I shouldn't trust the code examples being shown to me. Is that the PHP Intelephense extension for VS Code? 😆 Can that be disabled while showing code examples?

@agiljulio this is a valid point. It could be PHP Intelephense or a PHPCS related extension. Are you able to disable those inline code error notifications? When looking at these sections, I also noticed that you're creating these files inside a theme directory, so all the theme-related files are showing in the file navigator panel. It might make more sense to have them located in a separate plugin directory.

1:45–2:10 I found these visuals unhelpful and distracting from what's being said. I think a text slide with the notable points being said and/or showing relevant screens in wp-admin would be more helpful.

@MichelleBlanchette this is an interesting one, and I think it's down to each video creator and learner. In this specific case I think it's ok, because the main reason this section exists is to direct folks to the uninstall lesson anyway.

jonathanbossenger avatar Dec 09 '24 12:12 jonathanbossenger