Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Trying to hard-code a plugin into a theme WordPress

  • SOLVED

Hi There,

I plan to modify a plugin fairly significantly, so I'd like to hard-code the plugin into my theme. I'm running into some filepath issues and it's not working 100% correctly.

The plugin 'sorta' works, but some of the things like images, javascript, etc aren't getting loaded. I played around a bit and got some things to work, but I just reverted to default so you guys can help out.

The plugin I am using is here: http://wordpress.org/extend/plugins/grunion-contact-form/

I am using a slightly modified version of this, which the plugin developer sent me, which fixes a form submission issue. You can download that here: http://dl.dropbox.com/u/7008416/contact-form.zip

Just a heads up I did in fact test this new version by installing it as a regular plugin and everything works perfectly.

I've placed the plugin a few folders deep within my theme and I'm calling it from my functions.php file like so:


define('EXTENDED', TEMPLATEPATH . '/functions/extended');
require_once(EXTENDED . '/contact-form/grunion-contact-form.php');


The files are located in my theme here: functions/extended/contact-form/

I am assuming the plugin file that needs to be edited is: grunion-contact-form.php

On line 15+16 there are two variables which define the URL paths of the plugin. I played around with these and got certain things to work, but was unable to get everything completely working. Here is the code I'm referring to:

define( 'GRUNION_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'GRUNION_PLUGIN_URL', plugin_dir_url( __FILE__ ) );



As it is now, the plugin does indeed function via the shortcodes, but a few things like images and the javascript in the form builder pop-up window aren't working. A few things I tried which got it sort of working were this:


define('GRUNION_PLUGIN_DIR', TEMPLATEPATH . '/functions/extended/contact-form');
define('GRUNION_PLUGIN_URL', get_template_directory_uri() . '/functions/extended/contact-form');

Answers (2)

2011-02-01

Ivaylo Draganov answers:

Your approach is correct. Use a developer tool like Firebug(Firefox), Dragonfly(Opera) or Chrome and Safari's built in inspectors to find out whether any JS or CSS files fail to load.

I'm guessing it could be a missing trailing slash issue. E.g. maybe try this:
define('GRUNION_PLUGIN_DIR', TEMPLATEPATH . '/functions/extended/contact-form/');
define('GRUNION_PLUGIN_URL', get_template_directory_uri() . '/functions/extended/contact-form/');


But first use a debugging tool to find out if what fails and than search through the code. I'd recommend Firebug's Net panel as it shows all request to files.

EDIT:
Yes, I think there's an error in the plugin. Leave your defines the way they are and add a forward slash on line 16 of <em>grunion-form-view.php</em>, like this:
<script type="text/javascript" src="<?php echo GRUNION_PLUGIN_URL; ?>/js/grunion.js?00004"></script>


WP Answers comments:

Its working now! Thank you very much for your help.

I use firebug but never used the Net panel. Thanks a lot for that reeommendation.

Just in case anyone runs into this similar problem, I implemented draganov's edit above, and used my modified URL definitions within grunion-contact-form.php:

define('GRUNION_PLUGIN_DIR', TEMPLATEPATH . '/functions/extended/contact-form');

define('GRUNION_PLUGIN_URL', get_template_directory_uri() . '/functions/extended/contact-form');

Cheers!


2011-02-01

Sébastien | French WordpressDesigner answers:

probably js and image are called by a relative url

what's the url of your site ?