#41151 closed defect (bug) (wontfix)
Fatal error on Plugin Activation if it bundled in theme
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Plugins | Keywords: | has-screenshots dev-feedback close |
Focuses: | administration | Cc: |
Description
I have bundled 'Hello Dolly' plugin in 'Twenty Seventeen' theme and it works fine but when i install and activate 'Hello Dolly' plugin, it display 'Plugin could not be activated because it triggered a fatal error.' and 'Fatal error: Cannot redeclare hello_dolly_get_lyric() (previously declared in C:\xampp\htdocs\start\wordpress-svn\src\wp-content\themes\twentyseventeen\hello-dolly\hello.php:46) in C:\xampp\htdocs\start\wordpress-svn\src\wp-content\plugins\hello-dolly\hello.php on line 52'
I have modified plugin and added {{{#!php
<?php
if( ! function_exists( 'hello_dolly_get_lyric' ) ) {
}}}
But still does not activate.
Attachments (2)
Change History (7)
#1
@
8 years ago
- Keywords reporter-feedback added
- Type changed from defect (bug) to enhancement
- Version 4.8 deleted
- Why have you included the Hello Dolly code in your copy of the Twenty Seventeen theme?
- If you have, then why are you trying to activate the original plugin?
- What are you trying to do?
- Why is this a problem that should be fixed by changing Hello Dolly?
- Since you are developer, aren't you able to avoid this error by renaming your copy of this function?
#2
@
8 years ago
- Keywords has-screenshots dev-feedback added; reporter-feedback removed
- Type changed from enhancement to defect (bug)
- Version set to trunk
Hi @knutsp
Suppose i am not a theme developer and some developer bundled it and now he want to use this plugin, then this plugin will not activate. I used 'Hello Dolly' plugin just for example because it is simplest plugin in plugin directory. It is properly modified and bundled in theme. This should not display Fatal Error on Activation because already declare function is inside condition.
PS: I am testing core WordPress instead developing a theme and using 'Hello Dolly' plugin. It is just for example. I know i can simply rename functions of 'Hello Dolly' and use it in theme but this not what you are understanding.
#3
@
8 years ago
- Keywords close added
Here's a recent explanation of why you shouldn't bundle plugins in themes: https://wordpress.stackexchange.com/questions/269547/what-would-happen-if-the-admin-installs-a-plugin-when-the-plugin-is-included-in?atw=1
It is properly modified and bundled in theme. This should not display Fatal Error on Activation because already declare function is inside condition.
Well, there's a condition in the bundled plugin inside your theme but not in the original plugin. Looking at the error message, the theme code is loaded first, which basically makes the condition pointless.
As WordPress currently has no dependency management, it's the developer's job to check for this kind of conflicts.
#4
@
8 years ago
- Resolution set to wontfix
- Status changed from new to closed
- Version trunk deleted
This goes for any function in core or plugin, except "pluggable" functions.
If you copy a function name from anywhere in the WordPress ecosystem, and elect not to prefix it, or replace the prefix, this is what you have to expect.
And WordPress Core cannot "fix" this for all plugins, so why for Hello Dolly, as you say is just an example?
Always prefix global names. hello_dolly_get_lyrics
is perfectly prefixed, and thus works as a good example on how to make a simple plugin.
Closing this. Discussion can continue on closed tickets.
Error Screenshot