Full integration - aMember & WordPress

Discussion in 'Templates customization' started by miso, Apr 15, 2008.

  1. kengary

    kengary aMember Pro Customer

    Joined:
    Nov 13, 2008
    Messages:
    231
    BTW, here is my entire site.inc.php file if it will help you spot the problem...

    Code:
    <?php
    
    if (!defined('INCLUDED_AMEMBER_CONFIG'))
        die("Direct access to this location is not allowed");
    
    if (strpos($_SERVER['REQUEST_URI'],'/myaccount/admin/') === false)
    {
    
    	define('WP_USE_THEMES', false);
    
    	require_once('/home/kengary/public_html/wp-config.php');
    
        global $wp;
    
        if($wp)
        {
        	$wp->init();
        	$wp->parse_request();
        	$wp->query_posts();
        	$wp->register_globals();
        }
    
    } // end if not admin pages
    
    setup_plugin_hook('get_header'     , 'my_custom_header'     );
    function my_custom_header(&$header, array $vars)
    {
    
    	// get_header();	// this is all you have to on normal themes, but not thesis...
    
    	global $thesis, $thesis_design;
    
    	echo apply_filters('thesis_doctype', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">') . "\n";
    
    ?> <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> <?php
    
    	thesis_head::build();
    
    	echo "<body" . thesis_body_classes() . ">\n"; #filter
    
    	thesis_hook_before_html(); #hook
    
    	thesis_wrap_header();
    
    	thesis_hook_before_content_area(); #hook
    
    	echo "<div id=\"content_area\" class=\"full_width\">\n";
    
    	echo "\t<div class=\"page\">\n";
    
    	thesis_hook_before_content_box(); #hook
    
    	echo "\t\t<div id=\"content_box\"$add_class>\n";
    
    	thesis_hook_content_box_top(); #hook
    
    	echo "\t\t\t<div id=\"content\"" . thesis_content_classes() . ">\n";
    
    	thesis_hook_before_content(); #hook
    
    	echo "\t\t\t\t<div class=\"post_box top\">\n";
    
    	echo "\t\t\t\t\t<div class=\"headline_area\">\n";
    
    	echo "\t\t\t\t\t\t<h2>".$vars['title']."</h2>\n";
    
    	echo "\t\t\t\t\t</div>\n";
    
    	echo "\t\t\t\t\t<div class=\"format_text\">\n";
    
    	echo "\t\t\t\t\t\t<div class=\"amember_page\">\n";
    
    } // end my custom header
    
    setup_plugin_hook('get_footer'     , 'my_custom_footer'     );
    function my_custom_footer(&$footer, array $vars)
    {
    
    	global $thesis, $thesis_design;
    
    	echo "<p>&nbsp;</p>\n";
    
    	echo "\t\t\t\t\t\t</div><!-- amember_page -->\n";
    
    	echo "\t\t\t\t\t</div><!-- format_text -->\n";
    
    	echo "\t\t\t\t</div><!-- post_box top -->\n";
    
    	thesis_hook_after_content(); #hook
    
    	echo "\t\t\t</div><!-- content -->\n";
    
    	if (apply_filters('thesis_show_sidebars', true)) thesis_sidebars();
    
    	thesis_hook_content_box_bottom(); #hook
    
    	echo "\t\t</div><!-- content_box -->\n";
    
    	thesis_hook_after_content_box(); #hook
    
    	echo "\t</div><!-- page -->\n";
    
    	echo "</div><!-- content_area -->\n";
    
    	thesis_wrap_footer();
    
    	// get_footer();
    
    } // end my_custom_footer
    
    ?>
    
    Was I even close? ;-D
  2. andyb

    andyb Member

    Joined:
    Jul 10, 2010
    Messages:
    41
    my site.inc is just this

    Code:
    require_once(dirname(__FILE__).'/../wp-config.php'); // assuming amember is installed to folder in root of wp install
    global $wp;
    $wp->init();
    $wp->parse_request();
    $wp->query_posts();
    $wp->register_globals();

    my header
    Code:
    {php}get_header('amember');{/php}
    <div id="amember-wrap">
    this makes the current theme include the file called header-amember.php

    the file is the same as the regular theme header.php file but just has some added includes for the correct css for amember

    my footer
    Code:
    </div><!-- end amember-wrap -->
    {php}get_sidebar();{/php}
    {php}get_footer();{/php}
    and that's it, I don't have any issues with not being able to log in.

    You should check your settings to see if your session cookie AND your site cookies are being saved with the same domain value. If amember is saving the session to www.domain.com but wordpress is saving to domain.com then you might get into trouble with logged on cookies kicking you out again.

    I'll see if it's quiet at work tonight and install a test wordpress blog somewhere with a trial version of amember and see if it needs anything else doing.
  3. kengary

    kengary aMember Pro Customer

    Joined:
    Nov 13, 2008
    Messages:
    231
    Ok, but still trying to make use of the new hooks available in 3.2.3 that work with the new layout.html files that allow us to do whatever we want with the header/footer without editing any aMember core template files.

    This seems to work on "standard" themes such as the default TwentyTen, but not on "fancier" themes such as Thesis and Builder (only two I've tried so far) because they don't actually use the get_header() and get_footer() calls directly. So you have to explore each one of those.

    Edit site.inc.php like this...

    Code:
    <?php
    
    if (!defined('INCLUDED_AMEMBER_CONFIG'))
        die("Direct access to this location is not allowed");
    
    define('WP_USE_THEMES', false);
    
    require_once(dirname(__FILE__).'/../wp-config.php'); // assuming amember is installed to folder in root of wp install
    
    global $wp;
    
    $wp->init();
    $wp->parse_request();
    $wp->query_posts();
    $wp->register_globals();
    
    //
    // Header
    //
    
    setup_plugin_hook('get_header'     , 'my_custom_header'     );
    
    function my_custom_header(&$header, $vars)
    {
    
    	global $wp;
    
    	get_header();
    
    	echo '<div id="amember-wrap">'."\n";
    
    } // end header
    
    //
    // Footer
    //
    
    setup_plugin_hook('get_footer'     , 'my_custom_footer'     );
    
    function my_custom_footer(&$footer, $vars)
    {
    
    	global $wp;
    
    	echo '</div><!-- amember-wrap -->'."\n";
    
    	get_footer();
    
    } // end footer
    
    ?>
    
    Then of course you have to add whatever styles you want for amember-wrap to your themes CSS files.

    Plus this makes the two other new hooks in 3.2.3 not work anymore (get_header_code and my_custom_filter) which severely limits our options.

    Like I said, works with TwentyTen and no problems getting past the login. But in Thesis after I figured out what to do to get the header/footer to display, could not get past signup.

    With the Builder theme I didn't figure out how to display the header/footer yet. Just calling get_header() and get_footer() displays the actual theme contents between the head tags but not the body tag or the actual header of the theme. (Just need to spend more time with that.)

    So it all comes down to what theme you're using as to how hard this is going to be I suppose. It also still makes it a one-at-a-time problem to figure out. ;-D

    Still working and will report any new findings I have.
  4. andyb

    andyb Member

    Joined:
    Jul 10, 2010
    Messages:
    41
    I just went through the process of installing a brand new wp3.01 blog and set it up with amember 3.22 using the new get_header hooks for amember and it worked just fine. I did need to edit wp-config.php so it had the proper cookie domain by adding
    Code:
    define('COOKIE_DOMAIN', '.theempiregroup.co.uk');
    so it would save using the same domain value as the session cookie saved by amember
    (http://theempiregroup.co.uk/blog/amember/member.php)

    if you want to use a different header.php file then you can use the get_header('amember') call so it includes a file called header-amember.php for the header which can contain whatever code you want

    (get_header('somename') would include a file called header-somename.php from the current theme directory)

    it might just be because of thesis being too 'special' with it's code. I have been using the genesis framework with my sites and it's a whole lot easier to control and it retains full wordpress functionality with regards to core functions.

    hope you get it sorted!
  5. kengary

    kengary aMember Pro Customer

    Joined:
    Nov 13, 2008
    Messages:
    231
    That's really cool about the define statement for cookie domain. That'll be helpful to know.

    Did you use aMember 3.2.2 or the latest, 3.2.3? There is a bit of a difference.

    I too was able to get it to work with the TwentyTen theme.

    But unfortunately there are (at least) two drawbacks to this method that (currently) won't make it workable for everyone.

    1) Basic themes like TwentyTen that use the get_header() and get_footer() calls in WordPress will work great. But if you are using a more advance themes like Thesis and Builder that do their own thing and ignore this way of displaying the header then you will have to dig deeper to reconstruct the dynamic calls to get the header, sidebars and footer displayed.

    2) The fact that calling get_header() and get_footer() actually echos those bits of HTML directly out to the browser instead of being able to go to a buffer actually ends up disabling two other new necessary hooks that plugins are going to start using to modify content with rather than modifying templates, which is the new goal.

    Let me explain that last part a bit more.

    The normal way for the new header hook to work is like this:

    Code:
    function my_custom_header(&$header, $vars)
    {
    
        $header = "This is my new header.  It replaces the default aMember header.";
    
    }
    
    What that does is just prepare a buffer, called header, to be a portion of the page that will eventually get displayed. That buffer gets passed through all the plugins who each get to do what they want to it.

    When you call get_header() it just starts buffering to the output and is not captured into this header buffer in any way.

    And for some reason then, another hook called filter_output has no source to manipulate.

    It works like this:

    Code:
    function my_custom_filter(&$source, $resource_name, $smarty)
    {
    
    	$_SESSION['mycalls']++;
    
    	$source .= "<li>DEBUG: ".$_SESSION['mycalls'].": Resource: ".$resource_name."</li>\n";
    
    } // end my_custom_filter
    
    I discovered that if you're calling get_header() then this hook doesn't do anything.

    Plugins are going to want to be able to manipulate the page. That's the new shiny toy we get with aMember 3.2.3. But integrating WordPress/aMember this way is going to break this until we solve the issue.

    What I've been trying to figure out is a way to call the get_header() but just capture it into the buffer rather than immediately transferring it to the browser.

    Any ideas?

    The few things I've tried so far (ob_start()) have not stopped the output thus far, but I haven't spent a huge amount of time on it yet.

    My aim is to achieve all the goals:

    1. No modification to aMember templates so there are no issues doing upgrades from now on.

    2. Dynamic insertion of WordPress headers and footers (at least, if not everything else that's possible within WordPress).

    3. No hindrance to other aMember hooks that plugins are going to start using so that you don't break any plugins by doing this. Membership site owners are going to want to use all of the plugins they buy and plugin developers are going to want to use these new capabilities and not have compatability issues.

    BONUS: Make it work universally with any WordPress theme...but I think that is theme dependent and outside of what we can control.

    Whew! Sorry to be so long winded but this is very exciting to me.
  6. kengary

    kengary aMember Pro Customer

    Joined:
    Nov 13, 2008
    Messages:
    231
    @andyb, will you please post your entire aMember site.inc.php that you used in your testing?
  7. kengary

    kengary aMember Pro Customer

    Joined:
    Nov 13, 2008
    Messages:
    231
    Ok, I think I have it sorted now.

    1. Whatever was causing the filter_output call not to work right must have just been a typo on my part.

    2. I finally figured out you have to put part of the code into the config.inc.php (like you guys have been saying) and the rest in the site.inc.php.

    I was hoping it could all be done just by calling the hooks so that this kind of thing could be built into a plugin without having to edit ANY file, but apparently it's still going to take at least one edit to config.inc.php

    The part that goes into config.inc.php (at the top)...

    Code:
    define('WP_USE_THEMES', false);
    
    require_once(dirname(__FILE__).'/../wp-config.php'); // assuming amember is installed to folder in root of wp install
    
    global $wp;
    
    $wp->init();
    $wp->parse_request();
    $wp->query_posts();
    $wp->register_globals();
    
    And the part that goes into site.inc.php (or your plugin) is this...

    Code:
    //
    // Header
    //
    
    setup_plugin_hook('get_header'     , 'my_custom_header'     );
    
    function my_custom_header(&$header, $vars)
    {
    
    	global $wp;
    
    	$header  = get_header();
    
    	$header .= '<div id="amember-wrap">'."\n";
    
    } // end header
    
    //
    // Footer
    //
    
    setup_plugin_hook('get_footer'     , 'my_custom_footer'     );
    
    function my_custom_footer(&$footer, $vars)
    {
    
    	global $wp;
    
    	$footer  = '</div><!-- amember-wrap -->'."\n";
    
    	$footer .= get_footer();
    
    } // end footer
    
    So, anyway, there you go.
  8. kengary

    kengary aMember Pro Customer

    Joined:
    Nov 13, 2008
    Messages:
    231
    This code actually works much better in the site.inc.php...

    (This example works with the TwentyTen theme. You have to figure out the equivalent to this for your theme.)

    Code:
    //
    // Header :: From WordPress
    //
    
    setup_plugin_hook('get_header'     , 'my_custom_header'     );
    
    function my_custom_header(&$header, $vars)
    {
    
    	global $wp;
    
    	ob_start();
    
    	get_header();
    
    	$header = ob_get_contents();
    
    	ob_end_clean();
    
    	$header .= '<div id="container">'."\n";
    	$header .= '  <div id="content" role="main">'."\n";
       	$header .= '    <div id="amember_wrap">'."\n";
       	$header .= '      <h1 class="entry-title">'.$vars['title'].'</h1>'."\n";
    
    } // end header
    
    //
    // Footer :: From WordPress :: With Sidebar
    //
    
    setup_plugin_hook('get_footer'     , 'my_custom_footer'     );
    
    function my_custom_footer(&$footer, $vars)
    {
    
    	global $wp;
    
    	$footer  = '    </div><!-- amember_wrap -->'."\n";
    	$footer .= '  </div><!-- content -->'."\n";
    	$footer .= '</div><!-- container -->'."\n";
    
    	ob_start();
    
    	get_sidebar();
    
       	$footer .= ob_get_contents();
    
       	ob_end_clean();
    
    	ob_start();
    
    	get_footer();
    
       	$footer .= ob_get_contents();
    
       	ob_end_clean();
    
    } // end footer
    
    
    Then just remember you have to add some of your aMember CSS to your site's theme.

    (And of course the lines you have to put in top of the aMember config.inc.php to make it work! ;-D)
  9. andyb

    andyb Member

    Joined:
    Jul 10, 2010
    Messages:
    41
    Amazing what a bit of persistence and posting to a forum can do. I always figure something out right after I've posted to a forum for help, usually a day before anyone replies :)

    I haven't gone into too much detail for the plugin hooks because I'm not in the business for making modifications for other people. I only have to get this working for our site, it does and that's all that's matters!

    I can see it will be useful for you and your membership site related work though so I'm glad you got it sorted in the end.

    good luck with it!
  10. chriswylde

    chriswylde New Member

    Joined:
    Oct 28, 2010
    Messages:
    9
    Hi Guys,

    I'm having a bit of trouble getting this working. I'm not the strongest (or most confident) coder so I'm finding it a bit hard to follow this thread. Tried watching a video on Membership Academy about this topic but as it's for older versions, things are a bit different now.

    Is there anyone out there who can get this working for me? I'm using Wordpress 3.0, a Pagelines WP theme and latest version of Amember. Please PM me if you'd be interested in doing the job, and let me know how much you'd charge and any other details, or just let me know if there's anyone you can recommend.

    Really running out of time on this, so appreciate any help you can throw my way!

    Thanks in advance.
  11. slinky

    slinky Member

    Joined:
    Jul 15, 2010
    Messages:
    200
    I've done everything in the instructions and it's not working for me. I've emailed the guys in support and am sure they'll have an answer quickly.

    Take a look for my earlier messages and you'll see a few things that are just stated awkwardly and mentioned the guys should make some corrections to the manual. Are you having a problem completing all the steps? I have and, as I said, just can't get it to work reliably yet.
  12. slinky

    slinky Member

    Joined:
    Jul 15, 2010
    Messages:
    200
    OK - the guys explained it. If you set it up correctly (and set it up as a product) the user must login and you'll see the user. It works very nicely now!
  13. giorgiotave

    giorgiotave New Member

    Joined:
    Mar 25, 2010
    Messages:
    4
    WHat does it mean set it up as a product ? Amember and wp 3 doesn't work.
  14. gswaim

    gswaim CGI-Central Partner

    Joined:
    Jul 2, 2003
    Messages:
    641
    It means to open aMember click on the "Manage Products" in the left panel and then proceed to add a membership product. This is covered in the "First Steps" section of the manual.

    I might not work for you, but it will work. I am running WP 3.x and aMember using the amProtect plugin and all is well.
  15. kimboy

    kimboy New Member

    Joined:
    May 2, 2011
    Messages:
    20
    I am finding that this is not working with a widgetized sidebar. I'm using the exact code posted in this forum and the footer code is picking up my widgets instead of the footer.
  16. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Contact us in helpdesk we will help with that issue.

Share This Page