define('DISALLOW_FILE_EDIT', true);
Scripts n Styles is a free OpenSource GPL project that you can fork and contribute to on github! (You can also fork and contribute to CodeMirror and LESS.js)
As a Shortcode example: I placed the following html into the Shortcodes tab and gave it the name “tweet test”.
[code lang=”html”]
<a href="https://twitter.com/share" data-via="WraithKenny" data-size="large" data-related="unFocusProjects" data-hashtags="ScriptsnStyles">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
[/code]
I then use the shortcode [[sns_shortcode name=”tweet test”]] to display: [sns_shortcode name=”tweet test”]
]]>The meta box has been improved to provide a tabbed interface for less clutter, and syntax highlight and formating is added using the open-source CodeMirror 2.1.
An option has been added to allow adding script to the head element in addition to the traditional bottom of the page spot.
An Options page (under Tools) has been added so you can add Script n Styles to the entire site, rather then just the individual posts and pages.
Some minor code improvements:
If your theme is getting unwanted scroll-bars because of the new Admin Bar is WordPress 3.1, the core team included a way to handle it. Add Theme Support for it!
With a full height layout, you’ll want to avoid adding a margin or padding to a height that is already at 100% because you’ll get useless scrollbars, and no one wants that. Instead, find the first non-full height element (usually #header or some-such), and apply the margin there (either the 28px for the height of the admin bar, or add 28 to the existing margin if the element already has one). In the code snippet below I assumed you’d create an element or assign the class ‘admin-bar-fix’ to an existing element.
In your theme’s function file, add the following and modify as you see fit: (best to leave out the closing php tag though)
[cc lang=”php”]
< ?php
add_action( 'after_setup_theme', 'custom_theme_setup' );
function custom_theme_setup() {
add_theme_support( 'admin-bar', array( 'callback' => ‘admin_bar_bump_callback’) );
}
function admin_bar_bump_callback() { ?>
< ?php } ?>
[/cc]
This snippet is derived from the TwentyTen Theme’s function file. The callback’s original code can be found in the source. Original snippet also found commented in the source (props ocean90).
Basically, by declaring support for the new (as of 3.1) “Admin Bar,” you declare that you can handle how your theme’s content gets “bumped” (by default, it gets pushed down by 28px via a margin on the html.) Most of the time the default behavior is fine… but it’s not fine on theme’s that have a height declaration of 100% (even min-height) or that have external scripts that declare 100% height on the html/body (like Google Translate does).
WordPress’s admin needed a similar treatment but that got patched. The 28px margin is just a default to handle most normal cases. Your theme is your responsibility
Cheers! Hope this saves some time for someone!
If you don’t have a 100% height type of layout but are annoyed by improperly scrolling anchored links try the following.
If you add a >div id=”admin-bar-shim”> (for lack of a better name) in your theme surrounding everything inside the body except the wp_footer call (where the admin-bar gets echoed), you can add
[cc lang=”css”]
.admin-bar #admin-bar-shim {
position: fixed;
bottom: 0pt;
left: 0pt;
right: 0pt;
overflow: auto;
top: 28px;
}
[/cc]
to your style sheet, or use the method above adding the callback. This new method allows anchor links to scroll properly.
For fun (and for testing I attached some pics of some cool clouds that rolled right accross the road on the way into work one day). It was fun watching that.
No rich text editor. That’s a significant shortcoming.
]]>I found along the way that Share This doesn’t actually use very much of Prototype.js at all. It does a few id based element queries, and uses Prototype’s Position.cumulativeOffset once. So I just converted the dollar sign based id query with DOM standard getElementById, and replaced the cumulativeOffset method call. Then removed the bits that output a prototype.js header link.
That’s it. No more bulky prototype.js dependency!
You can grab the patch from the WP Plugins trac.
While I was at it, I also added gzip support for the js, css and static share-this page, along with a new flag to turn gzip on and off.
Here’s the gzip support patch.
If you’d rather skip all the patching, here is a prepatched share-this.php archive. To use it, download the Share This plugin, and overwrite share-this.php with the new one (patched against the latest from SVN as of this post date).
]]>Here’s the code:
[cc lang=’php’ ]
< ?php
/*
Plugin Name: unFocus.Insensitivity
Plugin URI: http://www.unfocus.com/projects/
Description: A plugin to make permalinks case insensitive.
Version: 1.0a
Author: Kevin Newman
Author URI: http://www.unfocus.com/projects/
*/
function unFocus_insensitivity() {
if (preg_match('/[A-Z]/', $_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = strtolower($_SERVER['REQUEST_URI']);
$_SERVER['PATH_INFO'] = strtolower($_SERVER['PATH_INFO']);
}
}
add_action('init', 'unFocus_insensitivity');
?>
[/cc]
Pretty simple really. Honestly, it doesn’t really even need to use a WordPress hook, just the two lines that convert the $_SERVER variables would do it (assuming those aren’t locked down in the php.ini). But I wanted to learn the plugin API anyway. There is an archive download at the end of this post, just unzip the enclosed file, and put it in your plugin directory, upload it and turn it on. No other configuration necessary.
If there is any interest, I was thinking about adding a config option that would allow you to either forward to the all lowercase URL, or to do what it does now, which is to behave pretty much the way IIS does for any other static files it hosts.
Also, if there’s interest, I may try to figure a way to work this WordPress IIS Permalink 404 handler into the plugin, if it’s possible (IIS users would set their custom 404 handler redirect URLs to redirect to /wordpresslocation/index.php instead of /wordpresslocation/404.php, which is how you do it now):
[cc lang=’php’ ]
< ?php
$_SERVER['REQUEST_URI'] = substr(
$_SERVER['QUERY_STRING'],
strpos(
$_SERVER['QUERY_STRING'],
':80'
) +3
);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
include('index.php');
?>
[/cc]
The archive – unFocus.Insensitivity
Update: Fixed the download link.
]]>Update 2: It seems that this new version is supposed to simply replace the functionality of the old Calendar, without requiring any extra work (so you’d just use the old Calendar Widget, and get the new functionality after the plugin is enabled). So far, I haven’t been able to get the Ajaxy stuff to work, although I can tell that it’s installed, because the calendar is wider in this theme with the new Calendar plugin.
While surfing the web aimlessly, I came across the Urban Giraffe Ajax Calendar plugin for WordPress. It’s not set up to take advantage of WordPress’s built-in Widget support, so I thought I’d add the necessary bits to make it work. Here’s how to do it.
Download the plugin, and add the following code to the bottom of ajax-calendar.php:
[cc lang=’php’ ]
function giraffe_ajax_register_widget() {
if ( !function_exists(‘register_sidebar_widget’) || !function_exists(‘register_widget_control’) )
return; register_sidebar_widget(‘Ajax Calendar’, ‘ajax_calendar’);
}add_action(‘plugins_loaded’, ‘giraffe_ajax_register_widget’);
[/cc]
Additionally, you can avoid a duplicate prototype.js header link, by replacing these lines:
[cc lang=’php’ ]
if ($giraffe_ajax_prototype)
add_action (‘wp_head’, ‘giraffe_ajax_head’);
[/cc]
with these:
[cc lang=’php’ ]
if (function_exists(‘wp_enqueue_script’))
wp_enqueue_script(‘prototype’);
else if ($giraffe_ajax_prototype)
add_action (‘wp_head’, ‘giraffe_ajax_head’);
[/cc]
You can see it working in my sidebar. And I didn’t even have to modify this theme.