Go Back   vb.org Archive > vBulletin 5 Connect Discussion > vB5 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-15-2013, 10:09 AM
jdorsey jdorsey is offline
 
Join Date: Sep 2013
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Wordpress Header & Footer Integation

Hello,
I'm trying to integrate vBulletin 5.0.x with Wordpress. Specifically, I'm trying to add the WordPress header and footer to show in vBulletin using Wordpress's functions get_header() and get_footer() that come from the file wp-blog-header.php in the WordPress installation folder. So I'm trying to figure out the following:

1) require the wp-blog-header.php file somewhere for vbulletin to use using require()
2) to figure out where to insert the php functions get_header() and get_footer()

I looked at this post: https://vborg.vbsupport.ru/showthread.php?t=298770 and it gave some information on making an extension by adding a folder to the /core/packages folder and putting a class file there with a custom function that I could use in a template, but I couldn't find much information on how to create a product xml file. It seems important to do this because I can't register my extension in the Admin CP -> Products & Hooks -> Manage Products -> Add/Import Product without it.

I'm don't need to create hooks or templates, and this product I'm creating doesn't need any custom html. Here's the code I wrote so far:

PHP Code:
<?php
class wp_integrate extends vB_Api_Extensions
{
    public 
$product 'wp_integrate';
    public 
$version '1.0.0';
    public 
$developer 'me';
    public 
$title 'WordPress Integration Extension';
    public 
$minver '5.0.4';
    public 
$maxver '5.0.4';
    public 
$infourl '';
    public 
$checkurl '';
    public 
$AutoInstall 0;
    public 
$extensionOrder 9;
    
    public function 
wpHeader(){
        
get_header();
    }
    
    public function 
wpFooter(){
        
get_footer();
    }
}
I added these lines to the /core/global.php file because I couldn't figure out where to put a php require statement:

PHP Code:
define('ROOT_DIR',str_replace('\\\\''/'realpath(dirname(__FILE__))).'/'); #Get real path for root dir ---linux and windows
require(ROOT_DIR.'../beta/wp-blog-header.php'); // get WordPress 
So any help would be greatly appreciated - I couldn't find any docs on doing this after 6+ hours of searching.
Reply With Quote
  #2  
Old 09-15-2013, 10:33 AM
marco_kellershoff's Avatar
marco_kellershoff marco_kellershoff is offline
 
Join Date: Sep 2013
Location: Cologne
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You don't need a product xml. All you need is an extension and a product. The extension will show up without a product.xml. Once it shows up you can add a product for that extension manually in the AdminCP.

The extension is basically a .php file inside the packages/yourextensionname/api/ directory.

PHP Code:
<?php
class wpHeaderFooter_Api_Options extends vB_Api_Extensions
{
    public 
$product 'wpHeaderFooter';
    public 
$version '1.0.0';
    public 
$developer 'foo';
    public 
$title 'WordPress Integration Extension';
    public 
$minver '5.0.4';
    public 
$maxver '5.0.4';
    public 
$infourl '';
    public 
$checkurl '';
    public 
$AutoInstall 0;
    public 
$extensionOrder 10;
    
    public function 
wpHeader(){
        
define('ROOT_DIR',str_replace('\\\\''/'realpath(dirname(__FILE__))).'/'); #Get real path for root dir ---linux and windows
        
require_once(ROOT_DIR.'../beta/wp-blog-header.php'); // get WordPress  
        
get_header();
    }
    
    public function 
wpFooter(){
        
define('ROOT_DIR',str_replace('\\\\''/'realpath(dirname(__FILE__))).'/'); #Get real path for root dir ---linux and windows
        
require_once(ROOT_DIR.'../beta/wp-blog-header.php'); // get WordPress  
        
get_footer();
    }
}
Put this into packages/wpheaderfooter/api/options.php



Not tested, but should work.
Reply With Quote
  #3  
Old 09-15-2013, 11:27 AM
jdorsey jdorsey is offline
 
Join Date: Sep 2013
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you for such a quick reply! I got the extension successfully registered.

Is this how I run the function in a template?:

HTML Code:
{vb:data wp, wpHeaderFooter_Api_Options, wpHeader}
(not sure about the varname "wp") - I put this in but nothing shows up in the header template.

Also, do I need to register this as a product in the AdminCP import/add product page for this to work, or is just registering the extension good enough?

Thanks again!
Reply With Quote
  #4  
Old 09-15-2013, 11:42 AM
marco_kellershoff's Avatar
marco_kellershoff marco_kellershoff is offline
 
Join Date: Sep 2013
Location: Cologne
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not familiar with wordpress, so I don't really know what wpHeader() is doing.

If it is just returning the header html like so:
PHP Code:
return $wordpress_html_string
then you need to alter the extension's code a bit like this:

PHP Code:
    public function wpHeader(){
        
define('ROOT_DIR',str_replace('\\\\''/'realpath(dirname(__FILE__))).'/'); #Get real path for root dir ---linux and windows
        
require_once(ROOT_DIR.'../beta/wp-blog-header.php'); // get WordPress  
        
return get_header();
    } 
(now the function returns the value)

and then in your template you do something like this:

Code:
{vb:data wp_header_html_string, wpHeaderFooter_Api_Options, wpHeader}
{vb:raw wp_header_html_string}
the first line just assigns the data and the second ones echos it

--------------- Added [DATE]1379249675[/DATE] at [TIME]1379249675[/TIME] ---------------

You might also want to read about this related topic here:
http://stackoverflow.com/questions/1...-a-text-string
Reply With Quote
  #5  
Old 09-15-2013, 05:14 PM
jdorsey jdorsey is offline
 
Join Date: Sep 2013
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, I feel like I'm so close, but missing something. Here is my new extension class file so far. I simplified it just to get it to work at all:

PHP Code:
<?php

class wpHeaderFooter_Api_Options extends vB_Api_Extensions
{
    public 
$product 'wpheaderfooter';
    public 
$version '1.0.0';
    public 
$developer 'me';
    public 
$title 'WordPress Integration Extension';
    public 
$minver '5.0.4';
    public 
$maxver '5.0.4';
    public 
$infourl '';
    public 
$checkurl '';
    public 
$AutoInstall 1;
    public 
$extensionOrder 10;
    
    public function 
wpHeader(){
        
//define('ROOT_DIR',str_replace('\\\\', '/', realpath(dirname(__FILE__))).'/'); #Get real path for root dir ---linux and windows
        //require_once(ROOT_DIR.'../beta/wp-blog-header.php'); // get WordPress  
        //return get_header();
        
return "<h1>My Custom Header</h1>";
    }
    
    public function 
wpFooter(){
        
//define('ROOT_DIR',str_replace('\\\\', '/', realpath(dirname(__FILE__))).'/'); #Get real path for root dir ---linux and windows
        //require_once(ROOT_DIR.'../beta/wp-blog-header.php'); // get WordPress  
        //get_footer();
                
return "<h1>My Custom Footer</h1>";
    }
}
And here is my new template markup (using the header template), which I inserted around line 114 (shortly after the <body> opening tag):

Code:
<h1>Start</h1>
{vb:data wphead, wpHeaderFooter_Api_Options, wpHeader}
{vb:raw wphead}
<h2>End</h2>
Also, you mentioned I need that I need to manually add the product. I did so in the AdminCP ->Products & Hooks -> Manage Products -> Add/Import Product, Add Product section. Here I just gave the Product id text field the same name as $product variable I used in my class above: 'wpheaderfooter' .

I do have the options -> Products/Hook System enabled (set to yes).

However, I get no output. Thanks so much for your patience in helping me. Hopefully I'm just missing something simple.
Reply With Quote
  #6  
Old 09-15-2013, 08:28 PM
marco_kellershoff's Avatar
marco_kellershoff marco_kellershoff is offline
 
Join Date: Sep 2013
Location: Cologne
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just try to add a hook - then it should work
Reply With Quote
  #7  
Old 09-16-2013, 12:29 AM
jdorsey jdorsey is offline
 
Join Date: Sep 2013
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, I pulled my {vb:raw} code out of the header template and made a new template, "wp_header_footer" and put it in there:

HTML Code:
<h1>Start</h1>
{vb:data wphead, wpHeaderFooter_Api_Options, wpHeader}
{vb:raw wphead}
<h2>End</h2>

Then I created a new hook.
  • product: "WP Header and Footer"
  • title: "WP Header Footer Hook"
  • hook location: header_toolbar
  • execution order: 10 (Default)
  • template name: "wp_header_footer"
  • hook arguments: left blank

The html I put in the template shows up (h2 and h1), but the {vb:raw wphead} does not.

The thing I am bit worried about is that when I created a new Product ("WP Header and Footer"), I didn't have any way I could see to link it to my wpHeaderFooter_Api_Options class listed in the extensions. Am I missing a step?
Reply With Quote
  #8  
Old 09-16-2013, 06:00 AM
marco_kellershoff's Avatar
marco_kellershoff marco_kellershoff is offline
 
Join Date: Sep 2013
Location: Cologne
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you can wait until tommorow, I'll write you a detailed, step by step guide, including (working) source code and screenshots.

It's just that today we have planned a relaunch of one of our mayor sites Don't have really time for this ATM.

But please, don't get angry or sad - I know the vBulletin software is lacking good docs, which is really sad - I fiddled around about 2 full 8h workdays to understand how the new extension system in vB5 works - it's a shame.

I'll come back to you tomorrow, k?

--------------- Added [DATE]1379336922[/DATE] at [TIME]1379336922[/TIME] ---------------

Quote:
Originally Posted by jdorsey View Post
Ok, I pulled my {vb:raw} code out of the header template and made a new template, "wp_header_footer" and put it in there:

HTML Code:
<h1>Start</h1>
{vb:data wphead, wpHeaderFooter_Api_Options, wpHeader}
{vb:raw wphead}
<h2>End</h2>

Then I created a new hook.
  • product: "WP Header and Footer"
  • title: "WP Header Footer Hook"
  • hook location: header_toolbar
  • execution order: 10 (Default)
  • template name: "wp_header_footer"
  • hook arguments: left blank

The html I put in the template shows up (h2 and h1), but the {vb:raw wphead} does not.

The thing I am bit worried about is that when I created a new Product ("WP Header and Footer"), I didn't have any way I could see to link it to my wpHeaderFooter_Api_Options class listed in the extensions. Am I missing a step?



I'm really sorry for such misleading information ... must have been a lack of sleep & coffee on my side..

HTML Code:
<h1>Start</h1>
{vb:data wphead, options, wpHeader}
{vb:raw wphead}
<h2>End</h2>
it has to be options, because you are simply extending the options api from vbulletin..
Reply With Quote
  #9  
Old 09-16-2013, 01:25 PM
jdorsey jdorsey is offline
 
Join Date: Sep 2013
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That worked! I replaced wpHeaderFooter_Api_Options with options, and it now works. Thanks so much! Hopefully the rest is just php stuff and not vbulletin related. I may post how I actually completed the whole thing in a little tutorial for posterity. And that would be great if you could post a little tutorial for how to make a hello world extension. If you're like me, I know you must be very busy though.
Reply With Quote
  #10  
Old 10-01-2013, 11:15 PM
moonclamp's Avatar
moonclamp moonclamp is offline
 
Join Date: May 2004
Location: London
Posts: 516
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just posting briefly as I'm interested in this too, and have far less php knowledge!

When I get this right, will it also add the wordpress top menu, or is that another problem to solve?

A tutorial would benefit me immensely, thank you.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:22 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05202 seconds
  • Memory Usage 2,302KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (4)bbcode_html
  • (6)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete