mcnicks
Forum Replies Created
-
Forum: Plugins
In reply to: Rewrite rules for new pluginAlso, the rewriting filter does not need to be as complicated as the one above (which I pinched from the Jerome’s Keywords example in the codex, btw). This works too, and also gives you an ‘index page’:
function foo_rewrite_rules ( $rules ) {
global $wp_rewrite;$foo_rules[‘foo/?$’] = ‘index.php?fooaction=index’;
$foo_rules[‘foo/(.+)?$’] = ‘index.php?fooaction=$matches[1]’;return ( $rules + $foo_rules );
}Ohh and, the query vars tip came from Christine Davis of UltimateTagWarrior fame. She writes about it here:
https://www.neato.co.nz/archives/2005/12/05/wordpress-20-rc1-plugins-and-url-rewriting/
Forum: Plugins
In reply to: Rewrite rules for new pluginOk, I think I have something working in theory. It looks like I have to add threee filters:
1. Rewrite the URL so that it puts the path components into query variables, like so:
add_filter( ‘rewrite_rules_array’, ‘foo_rewrite_rules’ );
function foo_rewrite_rules ( $rewrite ) {
global $wp_rewrite;// add rewrite tokens
$wp_rewrite->add_rewrite_tag( ‘%fooaction%’, ‘(.+)’, ‘fooaction=’ );$foo_structure = $wp_rewrite->root . “foo/%fooaction%/”;
$foo_rewrite = $wp_rewrite->generate_rewrite_rules($foo_structure);return ( $rewrite + $foo_rewrite );
}2. Tell WP about the fooaction query variable:
add_filter( ‘query_vars’, ‘foo_query_vars’ );
function foo_query_vars ( $vars ) {
$vars[] = “fooaction”;
return $vars;
}3. Write an is_foo() function so we can tell when we are in the foo ‘application’:
function is_foo () {
global $wp_query;return $wp_query->get( “fooaction” );
}4. Finally, override template reidrection to return the relevant foo page templates if we are in the foo application:
add_filter( ‘template_redirect’, ‘foo_redirect’ );
function foo_redirect () {
if ( is_foo() ) {
include( ABSPATH . ‘wp-content/plugins/foo/main.php’ );
exit;
}
}And that’s it! The main.php file can still use the current theme just by calling the usual template functions, eg:
<?php get_header(); ?>
<div id=”content” class=”narrowcolumn”>
<div class=”post”>
<h2>Foo</h2>
<div class=”entrytext”>
You are in the foo application.
</div>
</div>
</div><?php get_sidebar(); ?>
<?php get_footer(); ?>
Forum: Plugins
In reply to: Rewrite rules for new pluginI have tried something similar … Maybe it would be more useful if I worked through and described a case where this definitely does not work.
I have set up a fresh version of WordPress 2.0 on a VirtualHost on my Windows XP laptop. I have dropped and recreated the database to make sure nothing pre-exists the installation. I perform the WP installation, and set up permalinks and category tags (ie the rewrite code and Apache mod_rewrite are definitely working). Then I add the following plugin into the plugins dir:
<?php
/*
Plugin Name: Test Plugin
Version: 1.0
Author: Me
Description: Test Plugin
*/function foo_rewrite_rules( $rules ) {
$newrules[‘foo/(.*)$’] = ‘/wp-content/plugins/foo.php?uri=$1’;
return array_merge( $newrules, $rules );
}add_filter( ‘rewrite_rules_array’, ‘foo_rewrite_rules’ );
?>
And created a dummy foo.php beside it with the content:
<h1>Foo</h1>
When I browse to https://test.local/foo/bar.html I see the WordPress index page. If I disable the test plugin and reload, I get a 404 error. So the rewrite rules must be doing _something_ …
This was done with Apache 2.0.55 and MySQL 4.1.6 on Windows XP SP2, and the URLs were viewed with Firefox 1.5.
PS: test.local is aliased to 127.0.0.1 in my hosts file, and Apache is set up to NameVirtualHost 127.0.0.1, so that I can set up and test multiple web sites like this one – I do not imagine that this will be affecting the issue, though.
Forum: Fixing WordPress
In reply to: Flickr PHP front-endI was going to mention this in a separate post – I still will – but my new plugin, called flickr-post, has a function defined in it which displays the N most recent thumbnails from your flickr photo stream.
https://mcnicks.org/plugins/flickr-post/
Its not documented yet but all you do is:
<?php fp_get_recent( 5 ); ?>
Somewhere to display your five most recent thumbnails – I have it on the template for my web site’s front page.
David
PS: My url-cache plugin works with flickr-post to cache thumbnails locally … this is all kind of beta right now, though.
Forum: Fixing WordPress
In reply to: ‘Pages’ and PermalinksI posted this elsewhere but I thought it would be relevant to this topic. I use a single .htaccess file outside of my blog directory to handle my rewrites so the automatic updates for pages were giving me some grief. To get round this I wrote a generic RewriteRule that should (ha!) handle all requests for pages:
RewriteCond %{REQUEST_URI} ^.*/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*/)?(.*)/$ /blog/index.php?pagename=$2 [QSA,L]The first RewriteCond checks whether the requested URI ends with a “/” character. The second checks whether the URI refers to a directory that exists. If it does not, then I assume that it is a request for a WP page. The RewriteRule gets invoked to redirect to the appropriate page in WordPress. This saves having to continually edit the WP .htaccess file as new pages are created.
The downside to the assumption is that, if it is not actually a request for a page, then WP has to handle dishing back the 404 error code.
David
Forum: Fixing WordPress
In reply to: Page ManagementI am using a 1.5 nightly build of WordPress (from 3rd January 2005) and I have started playing around with pages.
Does anybody know if there are any functions available that will return the full name of the current page, list the child pages under the current page and so on?
As an aside, I have written a little rewrite rule that automatically redirects to pages within WordPress. This sits in a .htaccess file in my web root:
RewriteCond %{REQUEST_URI} ^.*/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*/)?(.*)/$ /blog/index.php?pagename=$2 [QSA,L]The first RewriteCond checks whether the requested URI ends with a “/” character. The second checks whether the URI refers to a directory that exists. If it does not, then the RewriteRule gets invoked to redirect to the appropriate page in WordPress. This saves having to continually edit the WP .htaccess file as new pages are created.