define('DISALLOW_FILE_EDIT', true); Kenneth Newman – unFocus Projects – Kevin Newman and Ken Newman http://www.unfocus.com Home of Scripts 'n Styles for WordPress, Backstage2D and History Keeper! Tue, 10 Sep 2013 04:23:48 +0000 en-US hourly 1 https://wordpress.org/?v=6.2.5 Multiple LocalHost Sites http://www.unfocus.com/2012/07/24/multiple-localhost-sites/ http://www.unfocus.com/2012/07/24/multiple-localhost-sites/#comments Tue, 24 Jul 2012 14:50:12 +0000 http://www.unfocus.com/?p=553 Continue reading "Multiple LocalHost Sites"]]> I’ve got XAMPP installed on a Windows 7 machine. I wanted a way to test multiple sites locally.

Set up the local host file

In your host file, add (replace with the domains you want):

[code]127.0.0.1    sub.domain.com.dev
127.0.0.1    www.example.com.dev
127.0.0.1    www.unfocus.com.dev[/code]

UPDATE: Thanks to xip.io the host file edits are optional if you use the style www.example.com.127.0.0.1.xip.io (replace 127.0.0.1 with your actual IP address). This is compatible with Adobe’s Edge Inspect.

Set up XAMPP config files

In \xampp\apache\conf\httpd.conf uncomment the following at about line 140:

[code]LoadModule vhost_alias_module modules/mod_vhost_alias.so[/code]

I’ve used the folder structure of “\xampp\htdocs\www.example.com\web\content\files.php” (for example) and the following config will find the folder with the exact name in the url.

In \xampp\apache\conf\extra\httpd-vhosts.conf:

[hoops name="config"]

Fix DOCUMENT_ROOT

If you are having issues with DOCUMENT_ROOT, create setdocroot.php at “\xampp\” and put the following in it:

[hoops name="fix"]

References:
https://issues.apache.org/bugzilla/show_bug.cgi?id=26052#c27
http://stackoverflow.com/questions/138162/wildcards-in-a-hosts-file
http://postpostmodern.com/instructional/a-smarter-mamp/

]]>
http://www.unfocus.com/2012/07/24/multiple-localhost-sites/feed/ 2
Scripts n Styles Update 3.1 http://www.unfocus.com/2012/05/03/scripts-n-styles-update-3-1/ http://www.unfocus.com/2012/05/03/scripts-n-styles-update-3-1/#respond Thu, 03 May 2012 19:11:16 +0000 http://www.unfocus.com/?p=4191 Continue reading "Scripts n Styles Update 3.1"]]> Scripts n Styles received a major update today. The two big features added are LESS.js support and Dynamic Shortcodes! The “Global” Settings page now has a LESS editor with syntax highlighting (via CodeMirror) and on-the-fly compiling so you can see how it’ll be outputted on the theme-side. The per-page meta-box has gained a new tab in which you can create one-off shortcodes which can contain arbitrary HTML content.

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”]

]]>
http://www.unfocus.com/2012/05/03/scripts-n-styles-update-3-1/feed/ 0
Scripts n Styles update 2.0.1 http://www.unfocus.com/2011/06/24/scripts-n-styles-update-2-0-1/ http://www.unfocus.com/2011/06/24/scripts-n-styles-update-2-0-1/#respond Fri, 24 Jun 2011 20:24:37 +0000 http://www.unfocus.com/?p=634 Scripts n Styles is a tool to allow admins (and editors in single installs) to add scripts and styles without editing template files, or worrying about authors overwriting the code (code is stripped when an author updates since they don’t have permission to use unfiltered html).

Improvements in version 2.0.1:

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:

  • Better selection of post_types.
  • micro-optimization for storage of class names.
  • Defined a later priority for Scripts n Styles to print after other scripts and styles.
  • Better adherence to coding standards.
  • began contextual help (notes on capabilities).
]]>
http://www.unfocus.com/2011/06/24/scripts-n-styles-update-2-0-1/feed/ 0
WordPress Admin Bar Theme Support http://www.unfocus.com/2011/02/07/wordpress-admin-bar-theme-support/ http://www.unfocus.com/2011/02/07/wordpress-admin-bar-theme-support/#respond Tue, 08 Feb 2011 00:37:01 +0000 http://www.unfocus.com/?p=568 Continue reading "WordPress Admin Bar Theme Support"]]> Here’s a quickie for WordPress Theme designers:

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!

Update: Admin Bar Shim!

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.

]]>
http://www.unfocus.com/2011/02/07/wordpress-admin-bar-theme-support/feed/ 0
Scripts n Styles http://www.unfocus.com/2010/09/15/scripts-n-styles/ http://www.unfocus.com/2010/09/15/scripts-n-styles/#respond Wed, 15 Sep 2010 17:59:25 +0000 http://www.unfocus.com/?p=502 Continue reading "Scripts n Styles"]]> Introducing a new plugin for WordPress from unFocus Projects!

Ever need to add a CSS style or some code snippet to just one page or post in WordPress? We release an admin tool to do just that.

On the post edit screen of the admin, Scripts n Styles adds a meta box where you can add JavaScript, CSS or even add class names to the body tag or the post content wrapper (as long as the theme supports wp_head, wp_footer, body_class, and post_class functions and almost all do).

The plugin is available on WordPress.org Extend (and therefor your plugin admin screen 🙂 ). You can also fork it on Github. It’s licensed GPLv2. (current version 1.0.2)

Enjoy!

]]>
http://www.unfocus.com/2010/09/15/scripts-n-styles/feed/ 0
Including Page Templates from a WordPress Plugin http://www.unfocus.com/2010/08/10/including-page-templates-from-a-wordpress-plugin/ http://www.unfocus.com/2010/08/10/including-page-templates-from-a-wordpress-plugin/#comments Tue, 10 Aug 2010 23:38:41 +0000 http://www.unfocus.com/?p=481 Continue reading "Including Page Templates from a WordPress Plugin"]]> Recently, It occurred to me while writing a plugin dealing with custom post types and taxonomies for WordPress that it’d be nice to have some custom templates to go along with it. I seemed onerous to ask the the user to add template tags to their theme to be able to display a better page then what WordPress displays by default. So I set out to make the plugin include the template pages from the plugin directory itself. The code below is derived directly from the WordPress source code, which means it’s GPL, so feel free to use it in your GPL licensed projects.

So the first thing I needed to figured out was what functions needed to be filtered to let me add the plugin directory to the locations that WordPress checks for. I eventually found the appropriate ones by reading the source code and asking in the #wordpress IRC chat (not #wordpress-dev, that’d be the wrong chat to ask this kind of question). “get_single_template()” and “get_taxonomy_template()” are the functions of interest and they in turn call “locate_template()” which is the function we need to rewrite.

[cc lang=”php”]
function locate_plugin_template($template_names, $load = false, $require_once = true )
{
if ( !is_array($template_names) )
return ”;

$located = ”;

$this_plugin_dir = WP_PLUGIN_DIR.’/’.str_replace( basename( __FILE__), “”, plugin_basename(__FILE__) );

foreach ( $template_names as $template_name ) {
if ( !$template_name )
continue;
if ( file_exists(STYLESHEETPATH . ‘/’ . $template_name)) {
$located = STYLESHEETPATH . ‘/’ . $template_name;
break;
} else if ( file_exists(TEMPLATEPATH . ‘/’ . $template_name) ) {
$located = TEMPLATEPATH . ‘/’ . $template_name;
break;
} else if ( file_exists( $this_plugin_dir . $template_name) ) {
$located = $this_plugin_dir . $template_name;
break;
}
}

if ( $load && ” != $located )
load_template( $located, $require_once );

return $located;
}
[/cc](reference: ‘function locate_template‘)

The “locate_plugin_template()” function is a direct copy of “locate_template” function but I added the $this_plugin_dir variable (using code I found on the wordpress.org forums) and added a 3rd check to the foreach loop. (Some of the code here can be removed, for example the $load check with the load_template() call, as our code won’t be invoking it but I left it to better reflect the source.)

Next we have to filter the appropriate functions to call our new function.
[cc lang=”php”]
add_filter( ‘taxonomy_template’, ‘get_custom_taxonomy_template’ );
add_filter( ‘single_template’, ‘get_custom_single_template’ );
[/cc]

There’s not much in the original functions that need to be changed:

[cc lang=”php”]
function get_custom_taxonomy_template($template)
{
// Twenty Ten adds a ‘pretty’ link at the end of the excerpt. We don’t need it for the taxonomy.
remove_filter( ‘get_the_excerpt’, ‘twentyten_custom_excerpt_more’ );
remove_filter( ‘get_the_excerpt’, ‘twentyten_auto_excerpt_more’ );

$taxonomy = get_query_var(‘taxonomy’);

if ( ‘custom_taxonomy_name’ == $taxonomy ) {
$term = get_query_var(‘term’);

$templates = array();
if ( $taxonomy && $term )
$templates[] = “taxonomy-$taxonomy-$term.php”;
if ( $taxonomy )
$templates[] = “taxonomy-$taxonomy.php”;

$templates[] = “taxonomy.php”;
$template = locate_plugin_template($templates);
}
// return apply_filters(‘taxonomy_template’, $template);
return $template;
}
[/cc](reference ‘function get_taxonomy_template‘)

There’s some bonus remove_filter calls at the beginning and ‘locate_template’ is replace by ‘locate_plugin_template’. The only other thing is that we simply return the $template variable instead of using ‘apply_filters’ (I got errors when trying to apply the filter while running the filter filtering the filter :-/). There is also a check to see if we are working with our own taxonomy: The code in the if statement doesn’t really need to run again unless it’s one of our taxonomies, else it’ll just return the original $template.

The single template function filter is much the same:

[cc lang=”php”]
function get_custom_single_template($template)
{
global $wp_query;
$object = $wp_query->get_queried_object();

if ( ‘custom_post_type_name’ == $object->post_type ) {
$templates = array(‘single-‘ . $object->post_type . ‘.php’, ‘single.php’);
$template = locate_plugin_template($templates);
}
// return apply_filters(‘single_template’, $template);
return $template;
}
[/cc](reference ‘function get_single_template‘)

Now, this isn’t a perfect solution. For example, themes have much varying structures, so building a template that’s compatible with Twenty Ten wouldn’t necessarily be compatible with any other theme. If the theme isn’t compatible, it could be bad since you’ve interrupted the fallback that the theme provides in favor of yours. You should probably include a check to see if the current theme is the theme you are targeting. I suggest you use this code in a plugin that is basically a companion plugin for your own theme or framework. Additionally, you could offer template tag functions, shortcodes, and widgets as a more robust solution.

]]>
http://www.unfocus.com/2010/08/10/including-page-templates-from-a-wordpress-plugin/feed/ 6
jQuery.historyKeeper http://www.unfocus.com/2009/09/11/jquery-historykeeper/ http://www.unfocus.com/2009/09/11/jquery-historykeeper/#comments Fri, 11 Sep 2009 18:59:23 +0000 http://www.unfocus.com/?p=272 Continue reading "jQuery.historyKeeper"]]> unFocus History Keeper is a JavaScript based library for managing browser history (back button) and providing support for deep linking for Flash and Ajax applications.

What I’m proposing is taking History Keeper and making a jQuery plugin, and also a WordPress plugin to include the History Keeper library for use in WordPress. I am primarily interested in this for the process of it: to learn more about making plugins.

]]>
http://www.unfocus.com/2009/09/11/jquery-historykeeper/feed/ 1
End of Life for IE6 http://www.unfocus.com/2009/07/14/end-of-life-for-ie6/ http://www.unfocus.com/2009/07/14/end-of-life-for-ie6/#comments Tue, 14 Jul 2009 17:22:15 +0000 http://www.unfocus.com/?p=233 Continue reading "End of Life for IE6"]]> Internet Explorer 6 is approaching its end of life! I did a quick Google search and found an “End of Life” movement calling for developers to abandon support on December 31, 2009 or January 1, 2010, but according to the Internet Explorer’s “Lifecycle Supported Service Packs” , it looks like support officially expires on July 13, 2010. Notwithstanding the 7 1/2 month difference, I’m simply happy the the end is in sight! And then I read that IE6 is covered under XP SP3 and therefor supported until 2014…

The only way to kill Internet Explorer, is to simply stop supporting it as developers. I feel we owe it to the web in general to support the latest standard (official or defacto) and the latest browsers.

]]>
http://www.unfocus.com/2009/07/14/end-of-life-for-ie6/feed/ 1