In my article, Associate Extensionless Files with Notepad, I explain how to navigate the labyrinthine maze of Windows dialogue menus to assign Microsoft’s Notepad text editor as the opening application for files without extensions. In this post, I’ll show you how to associate any file type with any program (including Notepad) in less than five seconds.
Ready? Don’t blink, you’ll miss it.. ;)
Modify any file extension association in five seconds
A great to way to share your PHP code with visitors is to display it directly in the browser with automatically generated syntax highlighting. Here is a screenshot showing an example of syntax-highlighted PHP code:
Displaying your PHP scripts in syntax-highlighted form is an excellent way to share source code details directly with your readers. Rather than zipping the script and requiring users to download, unzip, and open the file in an editor, displaying your code directly saves you and your visitors time, effort, and hassle. Plus, in my opinion, looking at syntax-highlighted PHP code is a beautiful sight, day or night ;)
In this article, we will explore 5 different ways to display the syntax-highlighted source of your PHP scripts. Three of the methods are designed to highlight entire files, and the other two are aimed directly at highlighting individual strings of PHP code. All of these methods employ PHP’s built-in syntax highlighter.
One of the necessary evils associated with creating a highly customized WordPress-powered site involves the inevitable necessity to hack the WordPress core. WordPress is built for mass-consumption and tends to cater to the largest audience possible, making it necessary to bend and poke around the corners to get WordPress to function in a more specific or specialized capacity.
Of course, there is a major downside to tweaking core WordPress files: upgrading. The overambitious WordPress peeps are constantly rolling out upgrade after upgrade, many of which are required security fixes, patches, or whatever. The point is that editing the WordPress core on your current version of WordPress requires that you edit each and every subsequent upgrade, for each and every one of your sites.
Over time, I have realized the importance of documenting core changes for any sites that require them. Having a concise record of the files and code involved with each hack greatly facilitates the entire upgrade process. Without such a reference, subtle changes may be forgotten and key hacks may be overlooked. Here at Perishable Press, my former Core Hacks Log served me well from WordPress 1.5 to 2.0, however, much of it no longer applies to the new WordPress 2.3 configuration. Since the latest site overhaul, I have dramatically reduced the overall number of required core edits.
In this brief tutorial, we are going to enable users to access any file or directory of a site that is password-protected via htaccess. There are many reasons for wanting to employ this technique, including:
Share public resources from an otherwise private site
Enable visitors to access content during site maintenance
Testing and formatting of layout and design during development
As a webmaster, I have used this technique on several occasions. This trick works great for allowing access to any number of files, directories, and/or combination of both. We will begin with a generalized example, proceed with an explanatory discussion, and wrap things up with a couple of useful modifications.
Update: After upgrading Perishable Press in 2007, many of the hacks listed on this page are no longer applicable. Please refer to our new WordPress Core Edits for current information. Otherwise, this article remains online for reference purposes only.
The folks developing WordPress are continually rolling out “upgrades”. While it is generally a good idea to stay current, it can also be a bit of a pain if you have made any changes to the WordPress core files. Our recommendation? Keep a log such as this one that either includes all edits or links to posts describing them. That way, when it is time to upgrade to WP 3.0.1, WP 3.0.2, … WP 9.0.1, WP 9.0.2 … (you get the idea), it will simply be a matter of referring to your handy WP core file change log and then going thru the list, copying & pasting your way back to complete functionality. Just remember to add any subsequent changes to the list, though, or you may find yourself scratching your head after the next upgrade. Another good idea involves carefully comparing any code you are replacing, checking to make sure the wizards at WordPress haven’t changed any aspects of the original code (of which you are replacing).
So, without further ado, here are the WordPress core file edits currently operating here at Perishable Press:
Customize the_excerpt function
File: wp-includes/functions-formatting.php (~ lines #763 & 767): set to desired values:
$excerpt_length = 50;
...
array_pop($words);
array_push($words, '[...] ( click post title to read more )');
$text = implode(' ', $words);
Customize the wpautop function
File: wp-includes/functions-formatting.php (~ line #72, #83):
$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n\t\t\t\t\t\t", $pee); // make paragraphs, including one at the end
$string = '<a href="'.get_permalink($post->ID).'" title="Go to previous post">'.$previous;
...
$string = '<a href="'.get_permalink($post->ID).'" title="Go to next post">'.$next;
...
...
function next_posts_link($label='Next Page »', $max_page=0) {
...
echo '" title="Go backward in time">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
...
function previous_posts_link($label='« Previous Page') {
...
echo '" title="Go forward in time">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
...
function posts_nav_link($sep=' — ', $prelabel='« Previous Page', $nxtlabel='Next Page »') {
Vars Tweak for htaccess Edits
File: wp-includes/vars.php (~ #35):
// Server detection
//the next line is used to allow WP to write htaccess rules during permalink creation (comment out the $is_apache line first)
//$is_apache = 1;
$is_apache = ( strstr($_SERVER['SERVER_SOFTWARE'], 'Apache') || strstr($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') ) ? 1 : 0;
Customize Password-Protected Posts
File: template-functions-post.php (~ line #3):
function get_the_password_form() {
$output = '<form action="' . get_settings('siteurl') . '/wp-pass.php" method="post">
<p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
<p><small><label class="h">' . __("Password: ") . ' </label><input class="postpassword" name="post_password" type="password" size="11" /> <input class="passwordsubmit" type="submit" name="Submit" value="' . __("Submit »") . '" /></small></p>
</form>
<div class="clear vspace"> </div>
';
return $output;
}
File: wp-includes/functions.php (~ lines #1067): insert "@" before parse_url and praise the Lord!
Remove CSS Link to Print Stylesheet
File: press/wp-subscription-manager.php (~ line #100): delete the following line to eliminate unnecessary 404 errors when users subscribe/unsubscribe to comments (or when managing subscriptions):
File: wp-includes/feed-functions.php (line #84): edit according to current default theme requirements:
echo "<a href='$url'>$link_text</a>";
--- changed to --->
echo "<a class=\"feed-icon\" href='$url' title=\"Subscribe to comments for this article\" rel=\"nofollow\">$link_text</a>";
Customize Commentator Links
File: wp-includes/comment-functions.php (~lines #358-368): swap the following:
/* original */
function get_comment_author_link() {
global $comment;
$url = get_comment_author_url();
$author = get_comment_author();
if ( empty( $url ) || 'http://' == $url )
$return = $author;
else
$return = "<a href='$url' rel='external nofollow'>$author</a>";
return apply_filters('get_comment_author_link', $return);
}
There are several files that appear not to have extensions in Windows XP. Perhaps the best known example is the HOSTS file. Files such as the HOSTS file that appear to be "extensionless" actually contain an invisible period "." — or dot — at the end the file name. It is this invisible dot that will enable us to select a specific program with which to open files with no extensions.
As web developers, we are constantly checking and consulting server-generated error_log files. Like the HOSTS file, the error_log files appear to have no associated extension. In Windows XP, opening extensionless files requires opening the "Open with…" dialogue box and scrolling through a long list of file types. And, although there is a checkbox option within the dialogue box enabling users to "Always use the selected program to open this kind of file," the option is "greyed out" and useless. Thus opening an extensionless file requires four or five extra "clicks", as well as the extra time it takes to jump through the hoops. This may not sound like a big deal, but try opening any number of files by this method and the extra clicks begin to add up.
After opening our millionth error_log file using the "Open with" method, we decided to confront the problem and devise a solution. After a bit of research, we were presented with several options: editing the registry, installing software, or tweaking Windows "Folder Options". After fiddling with the registry and installing some software with no real progress, we decided to try the heretofore unsuccessful "Folder Options" method. Sure enough, armed with an invisible dot and a slight tweak, we were finally able to convince Windows XP to associate extensionless file types with Notepad, our program of choice for such files.
The Solution
Although this solution is relatively risk-free 1, requiring no registry editing or software installation, the process is fairly sensitive, requiring careful attention. Below are two methods: the first associates extensionless files with Notepad, while the second does such with WordPad. Both assume a Windows XP operating system.
Here is the method of associating extensionless file types with Notepad in WinXP:
Open Windows Explorer and go to the "Tools › Folder Options › File Types" menu.
Click the "New" button and type ".txt" in the "File Extension" field.
Click on the "Advanced ››" button and the "Associated File Type" should read "Text Document". If it is blank, or says something else, close everything out and start over, making sure to follow the steps in order.
Finally, in the "File Extension" field, replace the ".txt" with a single dot, "."
Click "OK" and exit. Find or create an extensionless file and check it out.
Here is a similar method of associating extensionless file types with WordPad in WinXp:
Open Windows Explorer and go to the "Tools › Folder Options › File Types" menu.
Click the "New" button and type ".txt" in the "File Extension" field.
Click on the "Advanced ››" button and the "Associated File Type" should read "Text Document". If it is blank, or says something else, close everything out and start over, making sure to follow the steps in order.
Open the "Associated File Type" dropdown menu. Scroll down and select "Wordpad Document".
Finally, in the "File Extension" field, replace the ".txt" with a single dot, "."
Click "OK" and exit. Find or create an extensionless file and check it out.
Footnotes
1 It is always a good idea to backup your registry and other critical documents before implementing any system changes.