the anatomy of an extension
DESCRIPTION
One of the least understood aspects of ExpressionEngine is the class of add-ons known as Extensions. Many developers don’t understand why they exist, what they actually do or what problems they solve. This confusion exists among both Extension users and developers alike. A quick browse of any ExpressionEngine support forum shows that a common first step to solving an issue is to “Disable all Extensions,” yet most don’t know why. This was is designed to demystify the world of Extensions. The goal was to help everyone, from the general user to the new add-on developer, understand why Extensions exist, what they do and how they work. You can also find the presentation in blog form here: http://focuslabllc.com/journal/the-anatomy-of-an-expressionengine-extensionTRANSCRIPT
![Page 1: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/1.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
THE ANATOMY OF AN EXTENSION
![Page 2: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/2.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
WHO IS THIS GUY?
2
A family man
![Page 3: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/3.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
WHO IS THIS GUY?
3
Jesus is my homeboy
![Page 4: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/4.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
WHO IS THIS GUY?
4
World famous (I’m on the internet)
![Page 5: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/5.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
WHO IS THIS GUY?
5
EE Reactor team member
![Page 6: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/6.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
WHO IS THIS GUY?
6
Partner & Technical Director
![Page 7: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/7.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
THE ANATOMY OF AN EXTENSION
7
![Page 8: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/8.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
GOALS• Extensions in the context of Add-ons
• What are Hooks?
• How do Hooks relate to Extensions?
• How are Extensions called by EE?
8
![Page 9: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/9.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
GOALS• Caveats in using Extensions
• end_script explanation & use
• Returning data back to EE
• Better Debugging Processes
9
![Page 10: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/10.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
ADD-ONS OVERVIEW• Plugins
• Accessories
• Modules
• Fieldtypes
• Extensions
10
![Page 11: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/11.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
PLUGINS• Runtime add-ons
• No settings interface
• No installation required
• No unique db tables (typically)
11
![Page 12: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/12.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
PLUGINS• No language file requirement
• Can format custom text fields
• Can provide Template tags
• Small learning curve
12
![Page 13: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/13.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
ACCESSORIES• Only shown in Control Panel
• EE handles installation & settings for you
• Small learning curve
13
![Page 14: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/14.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
MODULES• Can have a Control Panel interface
• Requires Language file
• Must be installed in the Control Panel
• Can utilize "actions"
• Can provide Template tags
14
![Page 15: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/15.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
FIELDTYPES• Fairly self-explanatory
• Fieldtypes for channel publish form
• Have corresponding Template tags
15
![Page 16: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/16.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
EXTENSIONS• Must be installed in the CP
• Can use EE's built-in simple settings builder
• Requires language file when you have settings
• Can have unique database tables (but they o!en don’t)
16
![Page 17: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/17.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
EXTENSIONS• Manipulates data or processing during a given point
in a page load
• Must behave nicely with other extensions
• Probably the steepest learning curve in add-ons
• Can only be used with existing system "hooks"
17
![Page 18: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/18.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
WHAT ARE HOOKS?
18
![Page 19: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/19.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#19
Hooks are used to alter or augment the behavior of an operating system, of applications, or of other so!ware components.
Wikipedia article on “Hooking”
![Page 20: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/20.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#20
How do hooks relate to Extensions?
![Page 21: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/21.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#21
How do hooks relate to Extensions?
![Page 22: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/22.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#22
HOOK PROCESSING1. ExpressionEngine encounters a "hook" in the system
![Page 23: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/23.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#23
HOOK PROCESSING2. It checks the exp_extensions table to see if there is a
record with the "hook" where the "enabled" column is set to "y" (yes)
![Page 24: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/24.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#24
HOOK PROCESSING3.If there is, then EE looks at the "class" column to
determine which add-on to look in for this extension
![Page 25: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/25.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#25
HOOK PROCESSING4.If the add-on Extension file exists, it is loaded
![Page 26: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/26.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#26
HOOK PROCESSING5.Within that Extension class, the method listed is
executed.
![Page 27: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/27.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#27
How do hooks relate to Extensions?
![Page 28: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/28.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#28
HOOK PROCESSINGLow Seg2Cat Example Applied
1. ExpressionEngine encounters the sessions_end hook in the system
![Page 29: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/29.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#29
HOOK PROCESSINGLow Seg2Cat Example Applied
2. It checks the already-loaded extensions dataset for an extension using the sessions_end hook which is enabled
![Page 30: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/30.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#30
HOOK PROCESSINGLow Seg2Cat Example Applied
3.EE looks at the class "Low_seg2cat_ext" and knows to look for a folder called third_party/low_seg2cat
![Page 31: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/31.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#31
HOOK PROCESSINGLow Seg2Cat Example Applied
4.If third_party/low_seg2cat/ext.low_seg2cat.php exists, the file is loaded and an object is created
![Page 32: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/32.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#32
HOOK PROCESSINGLow Seg2Cat Example Applied
5.Finally EE executes the sessions_end method within the ext.low_seg2cat.php file
![Page 33: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/33.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
EXTENSION PROCESSING
33
![Page 34: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/34.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
HOOK EXAMPLE
/* -------------------------------------------/* 'delete_entries_start' hook./* - Perform actions prior to entry deletion / take over deletion*/ $edata = $this->extensions->call('delete_entries_start'); if ($this->extensions->end_script === TRUE) return;/*/* -------------------------------------------*/
34
The “delete_entries_start” hook
![Page 35: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/35.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
HOOK EXAMPLE
/* -------------------------------------------/* 'delete_entries_start' hook./* - Perform actions prior to entry deletion / take over deletion*/ $edata = $this->extensions->call('delete_entries_start'); if ($this->extensions->end_script === TRUE) return;/*/* -------------------------------------------*/
35
The “delete_entries_start” hook
![Page 36: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/36.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
HOOKS QUERY
SELECT DISTINCT ee.*FROM exp_extensions eeWHERE enabled = 'y'ORDER BY hook, priority ASC, class
36
From libraries/Extensions.php
![Page 37: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/37.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
HOOK EXAMPLE
/* -------------------------------------------/* 'delete_entries_start' hook./* - Perform actions prior to entry deletion / take over deletion*/ $edata = $this->extensions->call('delete_entries_start'); if ($this->extensions->end_script === TRUE) return;/*/* -------------------------------------------*/
37
The “delete_entries_start” hook
![Page 38: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/38.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
HOOK EXAMPLE
/* -------------------------------------------/* 'delete_entries_start' hook./* - Perform actions prior to entry deletion / take over deletion*/ $edata = $this->extensions->call('delete_entries_start'); if ($this->extensions->end_script === TRUE) return;/*/* -------------------------------------------*/
38
The “delete_entries_start” hook
![Page 39: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/39.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#39
Extensions playing well with others
![Page 40: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/40.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
HOOK EXAMPLE
/* -------------------------------------------/* 'delete_entries_start' hook./* - Perform actions prior to entry deletion / take over deletion*/ $edata = $this->extensions->call('delete_entries_start'); if ($this->extensions->end_script === TRUE) return;/*/* -------------------------------------------*/
40
The “delete_entries_start” hook
![Page 41: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/41.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
DEBUGGING METHODS• Disable all extensions in the CP
• Disable all extensions in the config.php file
• Disable one extension at a time in the database
41
![Page 42: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/42.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#42
Add-ons → Extensions
![Page 43: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/43.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#43
config.php override
/*|-------------------------------------------------------| ExpressionEngine Config Items|-------------------------------------------------------|| The following items are for use with ExpressionEngine.| The rest of the config items are for use with| CodeIgniter.|*/
$config['app_version'] = "250";$config['is_system_on'] = "y";$config['allow_extensions'] = "y";
![Page 44: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/44.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#44
config.php override
/*|----------------------------------------------------------| ExpressionEngine Config Items|----------------------------------------------------------|| The following items are for use with ExpressionEngine.| The rest of the config items are for use with| CodeIgniter.|*/
$config['app_version'] = "250";$config['is_system_on'] = "y";$config['allow_extensions'] = "n";
![Page 45: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/45.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#45
exp_extensions table
![Page 46: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/46.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#46
All content available online at:
focuslabllc.com/blog
![Page 47: The Anatomy of an Extension](https://reader033.vdocuments.mx/reader033/viewer/2022052410/5557ab40d8b42a4a5d8b4e21/html5/thumbnails/47.jpg)
!ERIKREAGAN"""•"""EngineSummit"#$%#
!ERIKREAGANPartner"#Focus#Lab"#LLC!FocusLabLLC
47