Detector icon indicating copy to clipboard operation
Detector copied to clipboard

Problems Incorporating with WordPress

Open isGabe opened this issue 11 years ago • 4 comments

I know you can't support all possible platforms, but WordPress is a pretty popular PHP based platform, so perhaps you have some ideas.

I did find and try this plugin, which is just a simple wrapper to include, in addition to trying to manually include Detector.

Here is what I found:

Detector WordPress issues

Notes

  • Local Install
  • WordPress 3.5.1
  • All other plugins deactivated
  • Twenty Twelve Theme
  • Using ServerPress - DesktopServer
  • PHP version 5.3.1
  • set permissions to 777 on all files in Detector directory

1) Plugin - As - Is

  • http://wordpress.org/plugins/detector/
  • Last updated: 9/10/2012
  • Installed as is I get the following PHP warning: Warning: Invalid argument supplied for foreach() in /[path_to_wp_install]/wp-content/plugins/detector/lib/Detector/Detector.php on line 77 Detector.php line 77: ```// populate some standard variables out of the config foreach ($config as $key => $value) { self::$$key = $value; }
- Below the warning, the rest fo the site appears to load normally

#### 2) Plugin - replacing entire /lib/Detector/ directory with current version from github
https://github.com/dmolsen/Detector/
- When I replace the /lib/Detector/ directory with the most current version I get a similar PHP warning
- `Warning: Invalid argument supplied for foreach() in /[path_to_wp_install]/wp-content/plugins/detector/lib/Detector/Detector.php on line 70`
- Detector.php line 70:
    ```// populate some standard variables out of the config
       foreach ($config as $key => $value) {
        self::$$key = $value;
       }
  • in addition, below the PHP warning I get a page full of raw code, and the rest of the site does not load.
  • screenshot http://d.pr/i/tRe7
  • It appears to break and print the raw code of Detector.php after line 380, which is within the buildTestPage() function.

3) Manually include latest version from github

https://github.com/dmolsen/Detector/

  • put /Detector directory inside the WordPress theme
  • include it in the theme's functions.php like so:
    • require_once('library/detector/lib/Detector/Detector.php');
  • Same results as #2 above.

isGabe avatar May 31 '13 17:05 isGabe

You can try two things. First, manually move config.ini.default to config.ini. Second, on line #65 it should say:

$config = @parse_ini_file(__DIR__."/config/config.ini");

Take out the @ symbol. I suspect it'll throw an error which will give you a better idea of why the foreach is blowing up.

dmolsen avatar Jun 11 '13 16:06 dmolsen

Hey, thanks for the reply. Not sure about the first thing, since config.ini and config.default.ini appear to be identical. Even so, I went ahead and removed config.ini, then renamed config.ini.default to config.ini, at which point I only got the "Please make sure config.ini.default exists before trying to have Detector build the config.ini file automagically."

As for the second thing, removing the @ symbol did indeed allow a new error message to come through: Warning: syntax error, unexpected BOOL_FALSE in ~/detector/lib/Detector/config/config.ini on line 26

The weird thing is that line 26 is a comment line: // do we show a default family for those browsers that don't support JavaScript, by default NO

I played around and discovered that somehow the word NO was triggering it. if I remove NO, then the unexpected BOOL_FALSE error goes away every time. If I put NO back in, the error comes back every time.

The bad news is that when I got rid of the BOOL_FALSE error, 3 new things pop up:

Notice: Undefined property: stdClass::$csstranforms in ~/lib/Detector/lib/feature-family/featureFamily.php on line 158

Warning: Cannot modify header information - headers already sent by (output started at ~/lib/Detector/lib/feature-family/featureFamily.php:158) in ~/wp-includes/option.php on line 568

Warning: Cannot modify header information - headers already sent by (output started at ~/wp-content/plugins/detector/lib/Detector/lib/feature-family/featureFamily.php:158) in /Users/hal/Documents/ArtFiles/web/Locality/wpajax.dev/wp-includes/option.php on line 569

I was ready to give up, but I noticed the typo "$csstranforms" (should be "$csstransforms"). I hunted that down to line 7 of /config/families.json and families.json.default. I corrected it and all of the notices went away except for a WordPress error: The plugin generated 10217 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.

So I finally have a chance to use it! Still some unexpected behavior, but I'll play with it some more and see how it works. In the meantime I may submit a pull request for that typo...

isGabe avatar Jun 11 '13 23:06 isGabe

I put the folders in the root directory of wordpress and included

require_once('library/detector/lib/Detector/Detector.php');

in the root index file as the first call, I can then use detector in all themes.

Not sure if that is right or wrong to put in root, need to remember if updating wordpress but it works for me.

afryer avatar Aug 22 '13 20:08 afryer

I didn't have a problem dropping the Detector directory into into my theme and then requiring it from functions.php. Everything seemed to work fine except for an XMLRPC issue, for which I am going to open a separate issue - but I just wanted to comment.

michaelschofield avatar Sep 03 '13 14:09 michaelschofield