Forum Replies Created

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter davidedw

    (@davidedw)

    I have found and resolved the problem. See the post “Spurious $GLOBALS name attribute caused 404 with widgetized theme”. You might also want to look at another post of mine “Understanding WordPress Flow – from URL to page”.

    In the end I used a fairly standard debugging approach:

    1. Identify what has changed (in this case the changes were well known, listed above),
    2. Compare the behaviour between the (old) working theme and the (new) broken theme, and
    3. Trace through the code using statements/variables written to the PHP log to determine where the point of change was between the working and broken theme behaviour.

    If you’re familiar with the Kepner-Tregoe method, any changed behaviour must be linked to changes in the environment. This was certainly the case here; I knew I’d introduced the new functions.php file and some custom sidebars as well as changing the template files.

    I was able to see that the query being sent to the DB to build the page involved the following variables:

    URI: //test_blog/testing-page-category/page/2
    query_string: paged=2&name=Search%20Sidebar&pagename=testing-page-category
    request:  SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND wp_posts.post_name = 'search-sidebar' AND wp_posts.post_type = 'post'  ORDER BY wp_posts.post_date DESC

    The corresponding variables for the working theme were:

    URI: //test_blog/testing-page-category/page/2
    query_string: paged=2&pagename=testing-page-category
    request:  SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND (wp_posts.ID = '264') AND wp_posts.post_type = 'page'  ORDER BY wp_posts.post_date DESC

    Obviously the request coming in from the HTTP server and passed in from the PHP processor (the URI) was correct, but between there and building the DB SQL statement something was screwed up.

    So debugging was a matter of determining where in the code the behaviour changed. I used the error_log() function to write statements/arguments to the PHP error log. For example:

    $dae_error = ">>>> 9a. Name: " . $name . " global name: " . $GLOBALS['name'];
    error_log($dae_error, 0);

    I then traced back up the code flow from the wrong SQL statement, placing error_log() statements to find the point of change.

    The problem was a global variable somehow being set in my custom functions.php file (see “Spurious $GLOBALS name attribute caused 404 with widgetized theme”).

    This was a very slow process, and I’m sure the developers have a more efficient mechanism. But it did give me a good understanding of how WordPress is built.

    Thread Starter davidedw

    (@davidedw)

    I’ve had some success with answering these questions, through good old fashioned tracing (use of the error_log() function at strategic points of the code) and a Codex article “Query Overview”.

    In response to my questions above:
    First – I can’t find where it’s unset, but the loop of wp-load.php, wp() and template-loader.php is run every time a URL is entered.

    Second – The query is processed in the parse_request() function in classes.php. The various parts of the URL and/or query string are split up and placed in the various wp_query attributes.

    Finally – it seems all paths are followed. I’m assuming that not every file is read from disk each time, but the same code paths are followed on each URL.

    Thread Starter davidedw

    (@davidedw)

    I figured it out. The Now Reading (Reloaded) functions require a URL string of something like; blog/index.php?now_reading_<blahtype>=<blahvalue>. Where blahtype is something like library, tag, author etc. and blahvalue relates to the type (e.g now_reading_library=1, now_reading_tag=Doctor).

    So to add a new template file you need to extend everything that plays with the URL and query strings…. For example, I decided to add a “now_reading_page=favourites.php” so I could add multiple pages with one set of plugin changes.

    The files I had to modify were:
    1. url.php: this module processes the URL’s that use the mod_rewrite function. I had to modify the
    1a. the nr_query_vars function to add a new variable (now_reading_page)…

    function nr_query_vars( $vars ) {
        $vars[] = 'now_reading_library';
        $vars[] = 'now_reading_id';
        $vars[] = 'now_reading_tag';
        $vars[] = 'now_reading_page';
        $vars[] = 'now_reading_search';
        $vars[] = 'now_reading_title';
        $vars[] = 'now_reading_author';
        $vars[] = 'now_reading_reader'; //in order to filter books by reader
        return $vars;
    }

    1b. the nr_mod_rewrite function to add a new mod_rewrite rule for URL’s of the format library/page/favourites.php…

    function nr_mod_rewrite( $rules ) {
        $options = get_option('nowReadingOptions');
        add_rewrite_rule(preg_quote($options['permalinkBase']) . '([0-9]+)/?$', 'index.php?now_reading_id=$matches[1]', 'top');
        add_rewrite_rule(preg_quote($options['permalinkBase']) . 'tag/([^/]+)/?$', 'index.php?now_reading_tag=$matches[1]', 'top');
        add_rewrite_rule(preg_quote($options['permalinkBase']) . 'page/([^/]+)/?$', 'index.php?now_reading_page=$matches[1]', 'top');
        add_rewrite_rule(preg_quote($options['permalinkBase']) . 'search/?$', 'index.php?now_reading_search=true', 'top');
        add_rewrite_rule(preg_quote($options['permalinkBase']) . 'reader/([^/]+)/?$', 'index.php?now_reading_library=1&now_reading_reader=$matches[1]', 'top');
        add_rewrite_rule(preg_quote($options['permalinkBase']) . '([^/]+)/([^/]+)/?$', 'index.php?now_reading_author=$matches[1]&now_reading_title=$matches[2]', 'top');
        add_rewrite_rule(preg_quote($options['permalinkBase']) . '([^/]+)/?$', 'index.php?now_reading_author=$matches[1]', 'top');
        add_rewrite_rule(preg_quote($options['permalinkBase']) . '?$', 'index.php?now_reading_library=1', 'top');
    }

    1c. The is_now_reading_page function to make the new query string register as a now_reading page…

    function is_now_reading_page() {
        global $wp;
        $wp->parse_request();
    
        return (
        get_query_var('now_reading_library') ||
            get_query_var('now_reading_search')  ||
            get_query_var('now_reading_id')      ||
            get_query_var('now_reading_tag')     ||
            get_query_var('now_reading_page')    ||
            get_query_var('now_reading_title')   ||
            get_query_var('now_reading_author')
        );
    }

    2. now-reading.php: the main file in the library_init() function to add a new check:

    if ( get_query_var('now_reading_page') ) {
        // get page name from query string:
            $nrr_page = get_query_var('now_reading_page');
    
            $load = nr_load_template($nrr_page);
            if ( is_wp_error($load) )
                echo $load->get_error_message();
    
            die;
        }

    3. I also had to create a new function in template-functions.php to return either a normal or mod_rewrite URL…

    /**
     * Returns a URL to the permalink for a given (custom) page.
     * @param string $page Page name (e.g. custom.php) to create URL for.
     * @param bool $echo Whether or not to echo the results.
     */
    function library_page_url( $page, $echo = true ) {
        $options = get_option('nowReadingOptions');
    
        if ( $options['useModRewrite'] )
            $url = get_option('home') . "/" . preg_replace("/^\/|\/+$/", "", $options['permalinkBase']) . "/page/" . urlencode($page);
        else
            $url = get_option('home') . '/index.php?now_reading_page=' . urlencode($page);
    
        $url = apply_filters('library_page_url', $url);
    
        if ( $echo )
            echo $url;
        return $url;
    }

    I have no idea what the apply_filters function is doing.

    Thread Starter davidedw

    (@davidedw)

    Brilliant, the mod-rewrite was the problem! When I’d setup the test blog I’d missed the custom permalink setting I used on the prod blog.

    I was in the middle of modifying the templates for my custom theme, thus the lack of css.

    Thanks for all your help.

    Thread Starter davidedw

    (@davidedw)

    OK, halfway there. I’ve done as suggested on both my prod and test blogs.

    For the prod blog (https://davidedwardsphotos.com/blog), which is WP 2.7.1, all appears fine.

    For the test blog (https://davidedwardsphotos.com/test_blog), which is running WP 2.8, I’m still getting the internal server errors.

    The php.ini file is showing 64M memory (“memory_limit = 64M”).

    I’ve checked the .htaccess files and they seem fine. The one in my root is for the phpsuexec and the one in the test blog root is:

    Options -Indexes

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress

    I’m not seeing anything in the http server or php error logs, which is a worry.

    Thread Starter davidedw

    (@davidedw)

    They were set. I’ve just checked them again and saved them again. Problem still persists.

    Thread Starter davidedw

    (@davidedw)

    I followed the old deactivate all plugins and then selectively re-activate them. It proved to be the Bluetrait Event Viewer plugin, which I had enabled to try and debug the issues with 4.4.5.

    Thread Starter davidedw

    (@davidedw)

    For example when trying to run https://davidedwardsphotos.com/test_blog/?now_reading_library=true, I get:

    Fatal error: Out of memory (allocated 33816576) (tried to allocate 20436801 bytes) in /home/davidedw/public_html/test_blog/wp-includes/wp-db.php on line 445

    Yes, that did it. I wasn’t aware of the specificity. Learn something new every day.

    So, I’m back to the vanilla Sociable with the following CSS:

    #content .sociable span {
    	# display: block;
    }
    #content .sociable ul {
    	display: inline;
    	margin: 0;
    	padding: 0;
    }
    #content .sociable ul li {
    	background: none;
    	display: inline;
    	list-style-type: none;
    	margin: 0;
    	padding: 1px;
    }
    #content .sociable ul li:before { content: ""; }
    #content .sociable img {
    	display: inline;
    	float: none;
    	width: 16px;
    	height: 16px;
    	border: 0;
    	margin: 0;
    	padding: 0;
    }

    I found that sociable is using a class=sociable in the div, and my id CSS was overwriting it (which has the bullet in my #content defs).

    So I changed the class=sociable in sociable.php to a id=sociable and put the set of #sociable settings in my style.css…

    #sociable span {
    	# display: block;
    }
    #sociable ul {
    	display: inline;
    	margin: 0;
    	padding: 0;
    }
    #sociable ul li {
    	background: none;
    	display: inline;
    	list-style-type: none;
    	margin: 0;
    	padding: 1px;
    }
    #sociable ul li:before { content: ""; }
    #sociable img {
    	display: inline;
    	float: none;
    	width: 16px;
    	height: 16px;
    	border: 0;
    	margin: 0;
    	padding: 0;
    }

    I found that sociable is using a class=sociable in the div, and my id CSS was overwriting it. So I changed the class=sociable in sociable.php to a id=sociable and put the set of #sociable settings in my style.css…

    #sociable span {
    	# display: block;
    }
    #sociable ul {
    	display: inline;
    	margin: 0;
    	padding: 0;
    }
    #sociable ul li {
    	background: none;
    	display: inline;
    	list-style-type: none;
    	margin: 0;
    	padding: 1px;
    }
    #sociable ul li:before { content: ""; }
    #sociable img {
    	display: inline;
    	float: none;
    	width: 16px;
    	height: 16px;
    	border: 0;
    	margin: 0;
    	padding: 0;
    }

    with my 2.3.3 WP.

    It must be fixed in WP 2.5, ‘cos I’ve just upgraded to Firefox 2.0.0.13 (from 2.0.0.12) and the error is still occurring.

    Thread Starter davidedw

    (@davidedw)

    BTW, it was not working before the upgrade.

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