Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Graham Kite
PLUS
Graham Kite
Courses Plus Student 8,123 Points

need some wordpress plugin help

I have spent about two weeks trying to get a wordpress plugin working.

All it needs is the path changed from the theme directory to the plugin directory and I can't do it.

Where can I go to get it fixed? I can't do it so I'm wasting time and not learning anything.

appreciate finding someone who can fix it so I can look at the code to understand why I am not able to get it working. Happy to pay.

This should have been a very simple thing to do.

I have tried plugins_url plugin_dir etc, etc etc.

Have absolutely no idea.

See answer 1 below for code

5 Answers

Graham Kite
PLUS
Graham Kite
Courses Plus Student 8,123 Points

the problem lies in this code as far as I can tell.

every attempt to change this " echo bloginfo('template_url'); echo "/wtf/wp-optin-page/player/ "

breaks the plugin...It either delivers a blankpage or a black box placeholder or a piece of text saying "this text will be replaced" but no video. I can't tell if there is something else over riding this code or what is happening.

if ($showvideo == 'on') {
    if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod') || strstr($_SERVER['HTTP_USER_AGENT'],'iPad') ) {
        echo "<video width='"; 
        echo get_post_meta($post_id,'wpoptin_video_width',true);
        echo "' height='";
        echo get_post_meta($post_id,'wpoptin_video_height',true); 
        echo "' controls='controls' autoplay='autoplay'><source src='";
        echo get_post_meta($post_id,'wpoptin_video_url',true);
        echo "'/>";
    }
    else {
        echo "<script type='text/javascript' src='";
        echo bloginfo('template_url'); 
        echo "/wtf/wp-optin-page/player/swfobject.js'></script><div id='mediaspace' style='width:";
        echo get_post_meta($post_id,'wpoptin_video_width',true);
        echo "px;height:";
        echo get_post_meta($post_id,'wpoptin_video_height',true); 
        echo "px;border:1px solid #ccc;'>This text will be replaced</div><script type='text/javascript'>var so = new SWFObject('";
        echo bloginfo('template_url');
        echo "/wtf/wp-optin-page/player/player.swf','ply','";
        echo get_post_meta($post_id,'wpoptin_video_width',true);
        echo "','";
        echo get_post_meta($post_id,'wpoptin_video_height',true); 
        echo "','9','#000000'); so.addParam('allowfullscreen','true'); so.addParam('allowscriptaccess','always');   so.addParam('wmode','opaque'); so.addVariable('file','";
        echo get_post_meta($post_id,'wpoptin_video_url',true);
        echo "');so.addVariable('volume','100');    so.addVariable('autostart','true'); so.addVariable('controlbar','over'); so.write('mediaspace');</script>  '";
        //echo $wp_plugin_url; 
        //echo "/wp-optin-page/player/player.swf'); so.write('mediaspace');</script>"; 
    }
}
Graham Kite
PLUS
Graham Kite
Courses Plus Student 8,123 Points

Hmm I have done a complete recode and I have it working, but the original code does not work correctly no matter what I do. Would still like to try and understand why if anyone has a clue.

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

What was this giving you?

echo plugin_dir_path( __FILE__ );
Graham Kite
PLUS
Graham Kite
Courses Plus Student 8,123 Points

Hi Zac, In almost every case I either got nothing or I got a black placeholder or I got a message that was coded in, "this will be replaced.

In the end I went back and looked at the entire code base for the plugin, because I kept seeing a ' where there should not have been one. But it showed as content not a php error. So that was also a clue.

What was concerning me was an extra closing </script> tag that was also not throwing an error.

I went back to the original plugin and went through it again.

In the end it was a combination of echo plugin_dir_path(FILE); and also cleaning up some code.

I think this is a poorly coded plugin but I like its' functionality and also I wanted to get it working to try and use it as a learning experience to refactor some poorly written but useful code.

I expected that to be the harder assignment, not setting the plugin path, which should have been a very simple, quick job.

But then that is the issue with open source platforms anyone who wants to, can and does write bad plugins.

The one good thing about this one is it has been written with code to backward comply with older wordpress versions, and other code to make it more compatible with premium themes such as woo, etc, so there is a lot of code in there that in many ways may potentially need to be refactored.

Graham Kite
PLUS
Graham Kite
Courses Plus Student 8,123 Points

I am looking at a lot of plugins that beak themes etc or do not work as expected, while time consuming at my level of php, it is also a great learning opportunity.

I keep saying this is what real people in the real word need.

Everyone says, "FORK A PLUGIN" AND OTHER SUCH ADVICE....yeah right. So easy if you have been coding since you were in nappies, but not so easy understanding someone else's codebase, if you are not a coding geek. Much easier to code a html to a plugin or theme, but trying to dig through someone else code is far from easy.

A lot more people are looking for this type of help than actually wanting to learn how to code a theme.

It is beyond me why no one has ever done this type of training.

Take a plugin from the repository and fork it into something more suitable for a specific need, or take a plugin that breaks a theme and teach how to debug and fix it.

Maybe it is a thought for teamtreehouse.

Not to mention all the poor/non-working plugin and themes that get sold on a certain forum every single day.

I have friends that send me brand new purchased plugins that do not work, and have never been fixed by the "developers"

And lets not forget all this knock off a jquery plugin and or a plugin from the repository and fully encode it and then sell it (on the same forum) And then tell people it is a breach of copyright to decode a plugin that we have taken from the repository and sold as our brand new plugin.

Not really knocking true, and proper developers of which there are many, but for every one of them, there are potentially 100+ others who are not so reputable.

While you may not want the business, it just highlights the point there are a lot of potential clients waiting to be had, for someone who can (in a simple, direct, uncomplicated) way show them how to fix the plugin and themes they just bought. :)

And that might also make some interesting topics for teamtreehouse What are the true rights when it come to open source platforms like wordpress/jomla etc. Where do people go to find out. and while on that topic, something along the lines of the can spam act and understanding the FTC etc.

There are so many "guru's" say I have to put this in for the FTC, but it's meaningless"

There are so many bantered about "acronyms" that it is starting to sound like a good topic for teamtreehoue treatment.

cheers