module-plugin

Create Magento 2 plugin interception plans for public methods with di.xml registration and verification steps.

2|3|Updated Mar 19, 2026
One-click install
npx skills add https://github.com/caravanglory/magehub --skill module-plugin
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: module-plugin
Source: https://github.com/caravanglory/magehub/tree/main/skills/module/module-plugin
Command: npx skills add https://github.com/caravanglory/magehub --skill module-plugin

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps Magento 2 developers change the behavior of existing public methods safely through plugins instead of preferences or direct core edits, reducing coupling and upgrade risk.

Core Features & Use Cases

  • Before plugins normalize arguments before a method runs.
  • After plugins adjust return values after execution.
  • Around plugins wrap execution when control flow changes or conditional skipping is required.
  • Use cases include targeting public Magento classes, choosing the narrowest di.xml scope, managing plugin sort order, and verifying chain behavior with compile and test runs.

Quick Start

Ask for a Magento 2 plugin plan that targets a specific public method, recommends the right interceptor type, and shows the di.xml registration and verification steps.

Frequently Asked Questions about module-plugin

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I intercept a Magento 2 public method without modifying the original class?

To intercept a Magento 2 public method without core edits, use a plugin via di.xml to create before, after, or around interceptors that safely modify arguments, return values, or execution flow.

When should I use around plugins versus before or after plugins in Magento 2?

Use around plugins in Magento 2 when you need to change control flow or conditionally skip the original method execution. Otherwise, prefer before plugins to normalize arguments or after plugins to adjust return values.

What is the best way to manage plugin sort order in Magento 2 di.xml?

Manage plugin sort order in Magento 2 by assigning a sortOrder attribute in your di.xml registration to ensure the interceptor chain executes predictably and safely across different modules.

Why does my Magento 2 plugin throw a method signature error during compilation?

Magento 2 plugin compilation fails on method signature errors when your interceptor method parameters do not exactly match the original public method's strict typing, requiring precise signature matching and compile verification.

Can I use Magento 2 plugins to change private or protected methods?

Magento 2 plugins only intercept public methods. To change private or protected methods, you must use a preference or rewrite, though this increases coupling and upgrade risk compared to plugins.

How do I verify that my Magento 2 around plugin preserves the original proceed behavior?

Verify your Magento 2 around plugin preserves proceed behavior by ensuring the callable proceed argument is correctly invoked within your interceptor method and running a full compile and test verification.