Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#41151 closed defect (bug) (wontfix)

Fatal error on Plugin Activation if it bundled in theme

Reported by: rinkuyadav999's profile rinkuyadav999 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)

Hello-Dolly-error-on-activation.png (47.7 KB) - added by rinkuyadav999 8 years ago.
Error Screenshot
hello.php (2.4 KB) - added by rinkuyadav999 8 years ago.
Modified Hello Dolly Plugin

Download all attachments as: .zip

Change History (7)

@rinkuyadav999
8 years ago

Error Screenshot

@rinkuyadav999
8 years ago

Modified Hello Dolly Plugin

#1 @knutsp
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 @rinkuyadav999
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.

Last edited 8 years ago by rinkuyadav999 (previous) (diff)

#3 @swissspidy
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.


Related: #12839, #22316.

#4 @knutsp
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.

#5 @netweb
8 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.