4

I am trying to write a WordPress plug-in. In my project I have three PHP files.

  1. My plug-in file
  2. Widget for the plug-in
  3. Data installation

I need to install data table on plug-in activation. For that sake I wrote code to create table for my plug-in in data installation file. But I am not able to create data table using this file.

My code for include data installation file and widget file in my plug-in file is

define ( 'OTHER_FILES_PATH', plugin_dir_path( __FILE__ ) );
require_once( OTHER_FILES_PATH . '/data_installation.php' );
require_once( OTHER_FILES_PATH . '/plugin_widget.php' );

My problem is when I put my data installation code in my plug-in file it's working fine but when I put it in separate file (data installation) I am unable to create tables for my plug-in.

Please let me know if I am making any mistake.

4

When using plugin_dir_path() like you do:

plugin_dir_path( __FILE__ );

It does return something like:

/var/www//wordpress/wp-content/plugins/your-plugin/

So it adds a trailing slash, because as the documentation states:

It is a wrapper for trailingslashit( dirname( $file ) );.

So remove the slash before the file in your calls:

require_once plugin_dir_path( __FILE__ ) . 'file.php';
  • i tried but not working for me. – Bushra Shahid Aug 12 '15 at 9:39
  • I don't know more specifics about your set-up, but what I've explained definitely has to be changed. Check/debug the path and see if it is correct. Do you have the files in the plug-in root folder? @BushraShahid – Nicolai Aug 12 '15 at 9:47
  • thanks for your support but i checked every thing.. and if / is the problem then Why my widget file is working so well. :( still could not find the reason. – Bushra Shahid Aug 12 '15 at 10:14
  • As said, I do not know the specifics of your set-up - without further debugging information and the code you use, so with limited information in general, there are nearly infinite possibilities for your set-up to fail. You will understand, that trying to guess the reason, out of a near infinity of options, is out of the question. So, if you want me, or anybody else, to help you further, then provide the information needed to do so. @BushraShahid – Nicolai Aug 12 '15 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.