• Resolved Flare576

    (@flare576)


    I’ve created a set of php, js, css, and image files that act as a tool set for a our users. I now would like to integrate it into a WordPress install to take advantage of the our existing user system and layout. The problem is that I have no experience with WordPress. The tool needs to:

    Install several tables into WordPress DB and load with initial data
    Generate 3 distinct pages with the default WordPress header/menu/footer
    Have these 3 pages perform AJAX calls to several other files

    I believe that the first part can be done as a plugin, using the register_activation_hook() hook and then running dbDelta() with the CREATE TABLE statements and $wpdb->query() for the data loading. The rest has me stumped, though. From what I’ve read, I THINK I need to also include the AJAX php files in the plugin zip (and register them with add_action(‘wp_ajax_my_) ), and the 3 pages as templates. Is this correct?

    I’ve already attempted to build a page with a custom template, but I cannot get my content to show up in the “correct” location on the page. Here’s the basic code:

    <?php /* Template Name: Card Chooser Test */
    global $wpdb,$themePath;
    get_header('default');
    //ALL MY SCRIPT/STYLE STUFF
    print “</head><body onload=\”init();\”>
    wp_nav_menu(array('theme_location'=>'primary','menu'=>'ubermenu' ));
    //ALL MY DISPLAYABLE STUFF
    get_footer();
    ?>

    Is this even the right approach? All I want to use WordPress for in the instance of this tool is to pull in the style and access the user info (I’m integrating the tool into an existing WP install with an established userbase). Is there a smarter/easier way to accomplish this? Am I barking up the wrong tree?

    THANK YOU for any insight, and let me know if it would be beneficial to expound upon any element or provide more code!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Install several tables into WordPress DB and load with initial data

    Your solution for this is correct. At least, that is how I would do it.

    Generate 3 distinct pages with the default WordPress header/menu/footer

    If this is your site, just build theme templates as you are trying to do. If this needs to be portable, it is going to be tougher.

    Have these 3 pages perform AJAX calls to several other files

    Look into the AJAX API. I am becoming fond of it.

    http://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_%28action%29

    I don’t see anything obviously wrong with your theme template. What is it doing wrong?

    Thread Starter Flare576

    (@flare576)

    Thanks for the response!

    I’ve discovered a process that seems to work (though it apparently is frowned upon). I pull in
    include_once "../../../wp-config.php";
    into all of my files and I can access the variables I need, and since this is NOT designed to be installed on more than one WordPress site, I think it’ll work. I then just link to the file inside the plugin folder.

    This also should allow me to not have to convert all of my AJAX calls over to WordPress API. (Nothing against the API, I just need this done yesterday).

    The problem I was running into, however, was bringing in the template information. I accomplished this (ALMOST PERFECTLY) by learning about

    get_template_part( 'design', 'header' );

    Using the get_template_part I can pull in almost everything correctly… except the logo image. I have no idea why, but the logo image is pulling in some sort of stock “Salutation” image, but the right menu, background, and layout. I think this is my last hurdle. Any suggestions? is there a way to find out what OTHER pages on the site are using for template parts?

    Don’t include wp-config, include wp-load.php instead.

    is there a way to find out what OTHER pages on the site are using for template parts?

    grep the whole theme for ‘get_template_part`. That should tell you everything you need to know.

    Thread Starter Flare576

    (@flare576)

    s_ha_dum; thank you for your advice, it was key in getting me up and running.

    In case anyone stumbles on this in the future, here’s how I made it work:
    1. Take your PHP “Application” and ensure all files are in one “root” folder.
    2. Convert your sql calls to $wpdb->get_results and $wpdb->query calls.
    3. include include_once “wp-load.php” in every PHP file.
    4. On displayable pages you want themed, use:
    get_header(“default”);//Before your style/script/etc
    include(“custom_heading”);//just after you open the <body> tag, I will explain in a moment
    include(“custom_footer”);//last call on page, I will explain in a moment

    Custom Heading
    I had initially been using get_template_part( ‘design’, ‘header’ ), but I discovered that the stock design_header.php file my theme used defaulted to the THEME’s logo, not the one set in the admin tool, so I had to create my own and change the code. Everything in my custom one is identical to the stock, except:

    <h1 id="Logo"><?php theme_logo('', array('image'=>get_theme_var('design_setting,logo'), 'width'=>get_theme_var('design_setting,logo_width'), 'height'=>get_theme_var('design_setting,logo_height'), 'class'=>'')); ?></h1>

    Custom Footer
    This was just a convenience file, nothing special going on here, but I thought it might be useful to see:

    </div>
    			</div>
    		</div> <!--! end of .pageWrapper -->
    	</div> <!--! end of #Middle -->
    
    	<div id="Bottom">		
    
    		<?php $theFooter["content"]="footer-default"; get_template_part( 'design', 'footer' ); ?>
    
    	</div> <!--! end of #Bottom -->
    </div> <!--! end of #Wrapper -->
    
    <?php get_footer('default'); ?>
    
    </body>
    </html>

    Again, thank you for the help, and as a caveat: some of my steps are bad practices, and only work for me because I am NOT making a distributed plugin. I am not making use of the amazing feature set of WordPress, I’m simply making a tool LOOK like it’s part of WordPress. Be careful 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Attempting to integrate PHP tool into Worpdress’ is closed to new replies.