Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter mkemp1

    (@mkemp1)

    Here are the routines I use to change the content. The fixData is called with the DB field I want to change, the old URL base and then new. It seems to work.

    /**********************************************************************
     * This routine will test the target to see if it is serialized data, and it
     * it is it will unserialize the data, and if an array, will user fixElement
     * (recursively) to find and replace the old domain with the new one.  It
     * will then serialize the new data and return it.
     *
     * If it is not a serialized string, it will just replace the strings and
     * return the new string.
     *********************************************************************/
            function fixData ($target, $old_domain, $new_domain)
            {
                    $ut = unserialize ($target);
                    if ($ut === false) {
                            $ut = str_replace ($old_domain, $new_domain, $target);
                    } else {
                            $ut = fixElement ($ut, $old_domain, $new_domain);
                            $ut = serialize ($ut);
                    }
                    return $ut;
            }
    
    /**********************************************************************
     * This routine will accept an element that is eith an array or assumed to
     * be a string, and will replace the old domain with the new one.  It will
     * call itself recusively to handl arrays within arrays.
     *********************************************************************/
            function fixElement ($target, $old_domain, $new_domain)
            {
                    if (is_array ($target)) {
                            $ut = array ();
                            foreach ($target as $i => $t) {
                                    $ut[$i] = fixElement ($t, $old_domain, $new_domain);
                            }
                    } else {
                            $ut = str_replace ($old_domain, $new_domain, $target);
                    }
                    return $ut;
            }
    Thread Starter mkemp1

    (@mkemp1)

    As often is the case, I found my error just after posting this.

    Although the PHP documentation says that str_replace will work on arrays, it does not seem to. I replace that with a recursive routine that goes through the array elements and applies str_replace to non-array objects, hopefully strings. This does seem to work.

    If anyone is interested, I would be glad to share the script.

    Can someone tell me what the purpose of the akismet entries in the wp_commentmeta table serve? Is there any danger in deleting them if the referenced comment no longer exists in the wp_comments table?

Viewing 3 replies - 1 through 3 (of 3 total)