isomeme
isomeme

Reputation: 471

Where to put Google API PHP library for Wordpress?

I want to use the Google API PHP client library on a Wordpress site.

https://code.google.com/p/google-api-php-client/

The instructions say to install the library under the "project root", but I'm not clear on what that means for a Wordpress installation. I'd certainly like to avoid having it under httpdocs; there seems to be no good reason to make the code web-visible. What is the best course?

Upvotes: 1

Views: 7304

Answers (2)

isomeme
isomeme

Reputation: 471

What I ended up doing:

I created a new 'libphp' directory, sibling to 'httpdocs', and put the 'google-api-php-client' under that.

Then, in the php file that needs to use the library, I did this:

<?php
$path = "/absolute/path/to/libphp";
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_FusiontablesService.php';

That worked fine, and met my goal of keeping the lib code out of the httpdocs tree. There's probably a way to add this to the global include path and hence avoid the set_include_path call, but this will do for now.

Upvotes: 0

David Chase
David Chase

Reputation: 2073

You can put the google-api into a created directory such as library/includes into your theme folder and then include inside the functions.php

For instance in my theme directory i have a folder called lib and inside i have a framework.php that i house the framework i built. I simple use

require_once locate_template( '/lib/framework.php' );

to call on it inside the functions.php.

That way you can use wordpress functions along with their functions...

Upvotes: 2

Related Questions