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

wp secondary theme into fb page app, whilst retaining main theme WordPress

  • SOLVED

this price is a speculative price - I am happy to up the price if the question is regarded OK - I don't want to give the pot high amounts if no one answers, as I read in the tips, its not recommended to ask complex questions, this might be :/

<strong>My Question</strong>

I would like to be able to make a secondary wordpress theme especially for my facebook app - but whilst retaining my main existing theme.

It would almost be similar to the 'wp mobile detector' plugin but for the facebook iframe - [[LINK href="http://wordpress.org/extend/plugins/wp-mobile-detector/"]]http://wordpress.org/extend/plugins/wp-mobile-detector/[[/LINK]]

The closest wordpress plugin I found to doing the job perfect is the 'automatic facebook wordpress converter' - [[LINK href="http://wordpress.org/extend/plugins/automatic-facebook-converter/"]]http://wordpress.org/extend/plugins/automatic-facebook-converter/[[/LINK]]

The 'automatic facebook wordpress converter' plugin does exactly what I need, but for some reason my fan gate PHP does not work inside the theme.

The original theme that comes with 'automatic facebook wordpress converter' is in a folder called 'fb_theme', and from what I can see it is just a regular wordpress theme - so I literally dropped in my secondary theme code/files and it worked.

But see below my fan gate PHP which does not work in the theme - I know this PHP works perfect in a normal wordpress theme pulled in directly into a facebook app


<?php
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

if (empty($data["page"]["liked"])) {

echo ' <p>BECOME A FAN</p> ';

} else {

echo ' <p>I AM A FAN</p> ';

}
?>


I believe it's the PHP before hand which is not letting my fan gate work in the secondary theme.

Does anybody think there is a work around to get my secondary theme (whilst retaining use of main theme) to feed into a facebook app iframe - whilst being able to use the above fan gate PHP ?

Thanks in advance.

Answers (2)

2011-09-09

Julian Lannigan answers:

First you need to download and upload the PHP-FB SDK from [[LINK href="https://github.com/facebook/php-sdk"]]https://github.com/facebook/php-sdk[[/LINK]]

Then you can insert the following code into your functions.php


require_once 'path/to/fb/php/sdk/src/facebook.php';
define("FB_APPID", "****YOUR FB APP ID****");
define("FB_SECRET", "****YOUR FB SECRET****");

global $fb, $signedRequest;
$fb = new Facebook(array(
'appId' => FB_APPID,
'secret' => FB_SECRET
));
$signedRequest = $fb->getSignedRequest();

function fb_user_theme( $template = '' ) {
if (isFacebook()) {
return "***YOUR THEME NAME***";
}
return $template;
}

function isFacebook() {
global $signedRequest;
if ($signedRequest != null) {
return true;
}
return false;
}

add_filter('template', 'fb_user_theme');
add_filter('stylesheet', 'fb_user_theme');


Mind you this will change the theme that is loaded. Also note that I have loaded the FB sdk into the global variable $fb and I have loaded the signed request into $signedRequest so that you can reuse them.


Josh Cranwell comments:

Hi Julian, thank you for answer

I added this into the functions of my main theme, I also downloaded and added the absolute path to the facebook sdk src folder in my theme (I double checked permissions and all good), I then added my app ID and my app secret.

I then changed the 'YOUR THEME NAME' to my theme folder name.

It definitely seems to be trying to do something but locks me out of the cms and front end and leaves a blank space on the facebook app. So guessing something might not be quite right.

You say 'this will change the theme that is loaded' - what do you mean by this? do you mean the current activated theme will no longer be visible to people visiting the main site?

I need to try and keep every thing running on the site/cms as normal - whist being able to design a facebook only theme only visible through the fb iframe.

Many thanks


Josh Cranwell comments:

*I then changed the 'YOUR THEME NAME' to my facebook theme folder name.


Julian Lannigan comments:

<blockquote>You say 'this will change the theme that is loaded' - what do you mean by this? do you mean the current activated theme will no longer be visible to people visiting the main site?</blockquote>
This means simply that if there is a valid signed request then we must be in the facebook app and change the theme to your FB theme.

<blockquote>It definitely seems to be trying to do something but locks me out of the cms and front end and leaves a blank space on the facebook app. So guessing something might not be quite right.</blockquote>
Do you have a test link to the app? Also, if you want I could login and play around with the script.


Julian Lannigan comments:

Also, add these addition filters to the end of the code block I initially sent you.

add_filter('option_template', 'fb_user_theme');
add_filter('option_stylesheet', 'fb_user_theme');


Josh Cranwell comments:

I would be happy for you to take a look at the source.

Do you want to drop me an email on [email protected] and we can go from there - thanks


Julian Lannigan comments:

Ok, I have it working, but I believe you have some settings set incorrectly in your Application. Could you please set me as a developer in the roles of the application? julian[dot]lannigan[at]gmail[dot]com

I made a plugin called FB Conductor in your installation. Here is the code of that file: ( I removed the FB_SECRET because this is a public forum.)

<?php
/*
Plugin Name: FB Conductor
Plugin URI: http://www.julianlannigan.com/
Description: This plugin will redirect the theme based on whether you are viewing this site in a facebook app.
Author: Julian Lannigan
Version: 1.0
Author URI: http://www.julianlannigan.com/
*/

require_once dirname(__FILE__).'/facebook-sdk/src/facebook.php';

define("FB_APPID", "152323798176778");
define("FB_SECRET", "***YOUR SECRET***");
define("FB_THEME", "motorcyclelive-facebook");

global $fb, $signedRequest;
$fb = new Facebook(array(
'appId' => FB_APPID,
'secret' => FB_SECRET
));

$signedRequest = $fb->getSignedRequest();

function fb_set_template($template) {
if (isFacebook()) {
$template = FB_THEME;
}
return $template;
}

function fb_set_stylesheet($template){
if (isFacebook()) {
$template = FB_THEME;
}
return $template;
}

function isFacebook() {
global $signedRequest;
if ($signedRequest != null) {
return true;
}
return false;
}

add_filter('stylesheet', 'fb_set_stylesheet');
add_filter('template', 'fb_set_template');
add_filter('option_template', 'fb_set_template');
add_filter('option_stylesheet', 'fb_set_stylesheet');


Julian Lannigan comments:

Found the error:

You needed a trailing slash in the Page Tab URL:

You had: [[LINK href="http://motorcyclelivemobile.co.uk/wp"]]http://motorcyclelivemobile.co.uk/wp[[/LINK]]
It is now: [[LINK href="http://motorcyclelivemobile.co.uk/wp/"]]http://motorcyclelivemobile.co.uk/wp/[[/LINK]]

You can now remove me as a developer.


Josh Cranwell comments:

huge thank you, just tested it with 'fan gate' and it works as you can see.

I look forward to using this over and over!

2011-09-09

Kailey Lampert answers:

If no one else chimes in with a suggestion and you're willing to give me access, I'd be happy to take a look at the code to see if I can spot anything.

However, I'm currently at my day job, so I won't be able to do anything for several hours.

I'll check back in later to see if you still need assistance.


Josh Cranwell comments:

Hi Kailey, thank you I will be in touch if no else can solve - though I'm in England which means communication between answers/replys can take time :)