Welcome Guest, Not a member yet? Register   Sign In
Working With WordPress MU and Codeigniter
#1

[eluser]btray77[/eluser]
I created my little helper file to work with WordPress MU to create blogs and users. It works great outside of CI. but when I try to use it as a helper it comes up with errors.

Here's the code. It's thrown together... probably not the best way to do what I'm doing.
Tested with : WordPress MU 2.8.4a CI 1.7.1

Code:
<?PHP

require_once ('../wp-blog-header.php');
require_once ('../wp-includes/registration.php');

do_action('wpmuadminedit', '');

// Creates new blog user if there email address is not already in the system.
// If they are already in the system returns there user ID else creates new user ID
function create_blog_user($name, $password, $email)
{
    if (email_exists($email))
    {
        return email_exists($email);
    }
    else
    {
        return wpmu_create_user($name, $password, $email);
    }
}

//Creates a new blog, expects user to already exist.
function create_blog($domain, $email, $title, $public)
{
    $public = array("public" => 1);

    $user_id = email_exists($email);

    if (constant('VHOST') == 'yes')
    {
        $newdomain = $domain . "." . $current_site->domain;
        $path = $base;
    }
    else
    {
        $newdomain = $current_site->domain;
        $path = $base . $domain . '/';
    }
    $domain = strtolower($domain);
    $newdomain = strtolower($newdomain);
    $path = strtolower($path);
    return wpmu_create_blog($newdomain, $path, $title, $user_id, $public, $current_site-> id);
}

// disables blog, but doesn't not delete it, option to drop data when disabled.
function disableblog($blog_id, $drop = false)
{
    global $wpdb;
    if ($blog_id != $wpdb->blogid)
    {
        $switch = true;
        switch_to_blog($blog_id);
    }

    do_action('delete_blog', $blog_id, $drop);
    update_blog_status($blog_id, 'deleted', 1);

}
// deletes blog, with option to drop data when deleted.
function deleteblog($blog_id, $drop = false)
{
    wpmu_delete_blog($blog_id, $drop);
}

?>

Can someone give me an idea why it doesn't work as a helper? I change the require_once to the exact path of the wordpress mu file when I put it in as a helper.

I get the error: Fatal error: Call to undefined method stdClass:Confusedet_prefix() in /home/public_html/wp-settings.php on line 267

-Brad
MyBayAds.com
#2

[eluser]philpalmieri[/eluser]
i think you need to require in the wp-load.php file too: or at least some of these so you get the needed functions loaded:

/* Copied from the wp-load, you will need to adjust the paths */
require_once( ABSPATH . 'wp-config.php' );
require_once( dirname(ABSPATH) . '/wp-config.php' );
require_once( ABSPATH . '/wp-includes/classes.php' );
require_once( ABSPATH . '/wp-includes/functions.php' );
require_once( ABSPATH . '/wp-includes/plugin.php' );
#3

[eluser]btray77[/eluser]
I decided to can this approach, I did try it with the load options as you suggested.
I've decided to go with a custom XMLRPC plugin for wordpress and do the interactions though it. Which works out quite nicely. I can now have a remotely hosted version of my software also.

Thanks for the reply

-Brad
#4

[eluser]brianw1975[/eluser]
Any possibility you'll be releasing this code and plugin?

[quote author="btray77" date="1252603852"]I decided to can this approach, I did try it with the load options as you suggested.
I've decided to go with a custom XMLRPC plugin for wordpress and do the interactions though it. Which works out quite nicely. I can now have a remotely hosted version of my software also.

Thanks for the reply

-Brad[/quote]
#5

[eluser]btray77[/eluser]
[quote author="brianw1975" date="1252611977"]Any possibility you'll be releasing this code and plugin?

[/quote]

Look at http://wpmudev.org/project/xmlrpc-Addons (should work with regular wordpress also, just install in plugins folder for wordpress)

I basically started from that plugin and created the new functions I needed.

And then used the example code from the user guide and it came together very nicely and didn't take much time at all. I think I spent more time asking questions than it took to write the code.

If that doesn't help, I'll be glad to try to help some more if you tell me what you're trying to do.

-Brad
#6

[eluser]CroNiX[/eluser]
Just put this as the first line of your CI index.php:
require('blog/wp-blog-header.php');
It wont work unless it is loaded before CI gets triggered.

You should then have access to the wp api from within CI controllers/functions/etc.

Be aware that CI and WP have some identical function names like site_url(). There may be others but that is what I ran into. I ran into it mainly by using the anchor() helper, so I created a new function called make_anchor() which was identical to anchor() except it used base_url() instead of site_url() to generate the links.
#7

[eluser]123wesweat[/eluser]
@CroNiX,

i am having the same problem with anchor()

Where did you put make_anchor() and could you share the code?

Did you find a solution for site_url()???

simple replacing site_url() with base_url() didn't work
Code:
if ( ! function_exists('make_anchor'))
{
    function make_anchor($uri = '', $title = '', $attributes = '')
    {
        $title = (string) $title;

        if ( ! is_array($uri))
        {
            $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? base_url($uri) : $uri;
        }
        else
        {
            $site_url = base_url($uri);
        }

        if ($title == '')
        {
            $title = $site_url;
        }

        if ($attributes != '')
        {
            $attributes = _parse_attributes($attributes);
        }

        return '<a href="'.$site_url.'">'.$title.'</a>';
    }
}
#8

[eluser]123wesweat[/eluser]
ok i found this to work

Code:
base_url().$uri;
#9

[eluser]CroNiX[/eluser]
Yes thats how I did it. Its times like this I really wish every ci function was namespaced to avoid possible collisions like this.

ci_function_name
ci_function_name2
...




Theme © iAndrew 2016 - Forum software by © MyBB