In version 2.0 of Kalin’s PDF Creation Station, which I released earlier today, I moved some code around to facilitate the ability for people with a basic understanding of PHP (or even non-coders may be able to get this to work) to customize the location of the generated PDF files.
To do this, first open kalins-pdf-creation-station.php in a text editor (located in plugins/kalins-pdf-creation-station/), or enter the edit section under ‘plugins’ in your WordPress admin and find the file.
The code that designates the PDF directory currently begins on line 40 (this may change in the future, though probably not by much. Refer to code comments for updated information.) The code looks like this:
$uploads = wp_upload_dir();define("KALINS_PDF_DIR", $uploads['basedir'] .'/kalins-pdf/');//base location of PDF files define("KALINS_PDF_SINGLES_DIR", KALINS_PDF_DIR .'singles/');//location to save individual page/post PDF filesdefine("KALINS_PDF_URL", $uploads['baseurl'] .'/kalins-pdf/');//the url string will be different from the directory so be careful define("KALINS_PDF_SINGLES_URL", KALINS_PDF_URL .'singles/');
The first line, of course, just grabs the upload directory object of your wordpress installation. Then in the next line we define the base location of PDF files, using the upload directory (files created on the tool page will go here). You can see the second parameter of the define() is the actual directory path. You can change this to whatever you want, even a hard-coded value. The next line defines the location to save the single PDF files (the ones generated by the link on individual pages). This is usually a sub-folder of the base directory, but again you can set it to whatever you’d like, or it can be the same as the base (if you don’t mind a long list of PDFs on your tool page).
Remember, URLs that browsers use to navigate are different from the server directory that PHP uses to modify files. Thus, the last two lines now define the proper URLs that map to the corresponding directories in the previous two lines. You can see this is easy when using the $uploads object to simply grab the [‘baseurl’] or [‘basedir’] so things match properly, but if you understand your server’s directory structure and URL mapping, you should be able to put the folders wherever you’d like.
Also remember that you will either need to copy this code into wp-config.php or re-do this every time I make an upgrade to this plugin. Beware when copying into wp-config.php that you will not have access to the wp_upload_dir() function so you will need to hard-code the paths or use functions available outside of WordPress. Also remember to add your code above the line that says “/* That’s all, stop editing! Happy blogging. */” The example below should work in wp-config.php.
The actual final PDF folder does not need to exist yet. If it doesn’t, the PDF creation script will create it automatically.
In the next section in the PHP file you’ll find some more commented-out code that looks very similar to what we just looked at.
/* define("KALINS_PDF_DIR", $_SERVER['DOCUMENT_ROOT'] .'/pdf/');//base location of PDF files define("KALINS_PDF_SINGLES_DIR", KALINS_PDF_DIR);//location to save individual page/post PDF files define("KALINS_PDF_URL", "http://" .$_SERVER['HTTP_HOST'] .'/pdf/'); define("KALINS_PDF_SINGLES_URL", KALINS_PDF_URL);//this will put all PDFs in the same folder */
If un-commented to replace the previous section, this code will set the base and single PDF locations to the document root of your website in a folder called simply “pdf”.