soderlind.no

I code for fun

25.9.2011
by PerS
41 Comments

Front-end editor in WordPress 3.3 is easy

Thanks to the work done by Andrew Ozz et al., adding a front-end editor in WordPress 3.3 is very simple.

Syntax:

wp_editor( $content, $editor_id, $settings = array() );

// default settings
$settings =   array(
	'wpautop' => true, // use wpautop?
	'media_buttons' => true, // show insert/upload button(s)
	'textarea_name' => $editor_id, // set the textarea name to something different, square brackets [] can be used here
	'textarea_rows' => get_option('default_post_edit_rows', 10), // rows="..."
	'tabindex' => '',
	'editor_css' => '', // intended for extra styles for both visual and HTML editors buttons, needs to include the <style> tags, can use "scoped".
	'editor_class' => '', // add extra class(es) to the editor textarea
	'teeny' => false, // output the minimal editor config used in Press This
	'dfw' => false, // replace the default fullscreen with DFW (needs specific css)
	'tinymce' => true, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
	'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
);

View the wp_editor() examples

5.7.2011
by PerS
0 comments

Upgraded to WordPress 3.2 and nothing worked (internal error …)

Luckily I log all PHP errors and the error log told me where the error was (an old plugin I’ve forgotten to remove) .. phew

To log errors, I have the following statement at the top of my wp-config.php:

@ini_set('log_errors','On');
@ini_set('display_errors','Off');
@ini_set('error_log','/PATH/log/php_errors.'.date('Y-m-d').'.log');

4.3.2010
by PerS
1 Comment

WordPress plugin template

UPDATE: As of WordPress 3.3, you shouldn’t use the wp_print_styles hook, I’ve updated the Adding JavaScript section below to reflect this change.

You can create a personalized plugin template by using my WordPress Plugin Template Creator

When I  rewrote my WP-DenyHost plugin, I wanted to do it as fast as possible. Instead of reinventing the wheel (again), I googled after a plugin template and found a very good one at Pressography. It had most of what I needed in a plugin template.

Continue Reading

4.3.2010
by PerS
0 comments

When .LESS is more

@the-border: 1px;
@base-color: #111;

#header {
	color: @base-color * 3;
	border-left: @the-border;
	border-right: @the-border * 2;
}

#footer {
	color: (@base-color + #111) * 1.5;
}

ul
{
	list-style-type: none;
	height: 30px;

	li
	{
		float: left;
		padding-right: 15px;

		a
		{
			padding: 5px;
			display: block;
			color: black;
			text-decoration: none;
		}

		a:hover
		{
			background-color: @menu_color - #222;
		}
	}
}

Curious? 4GuysFromRolla has a nice article about .LESS

btw, if you’re not doing ASP.NET, you can create css from .less by using the command line compiler:

dotless.Compiler.exe -m Styles.less Styles.css

25.2.2010
by PerS
1 Comment

jQuery 101: Adding unobtrusive ajax to your existing form page

Using jQuery and the form and validate plugins, it is simple to add  unobtrusive ajax to your existing form page

1, Modify your existing form page

  1. Add <input type="hidden" name="isAjax" id="isAjax" value="0" /> to your form. This field will tell the processing script, process_input.php in my example, if the values in the form were submitted using ajax or as an ordinary form submit, defaulting to isAjax = 0 (false).
  2. Add class="required" to the fields that requires input
  3. Add the <div id="result"></div> where you want the ajax output
<form id="form1" name="form1" method="post" action="process_input.php">
	<input type="hidden" name="isAjax" id="isAjax" value="0" />
	Name: <input type="text" name="name" class="required" id="name" value="" /> <br />
	<input type="submit" name="submit" id="submit" value="submit" />
</form>
<div id="result"></div>

Continue Reading

Rodney's 404 Handler Plugin plugged in.