Fixing Stepic unresponsiveness

Standard

Stepic is a great tool for learning, especially for Bioinformatics course, but one thing is really annoying – it forces you to resize your browser (you will see on the video below). It really annoys me so I decided to fix it and contact Stepic authors.

Lecture wrapper is not on center if the menu is opened.

After you open the menu, lesson is not on center anymore. If your browser is not very wide, this behaviour forces you to resize your browser and it annoys me.

This happens because they used webkit-transform: translateX for positioning. Better approach is to animate lesson wrapper just by changing it’s padding-left property. Also, menu’s position should be controlled by left property.

Lecture wrapper is not repositioned on resize event.

For some reason, Stepic developers applied position: fixed; on lesson wrapper. Just removing this fixes the thing.

Code that you can paste in inspector and temporary fix this bad behaviour can be found on my gist.

Extracting slice method

Standard

I was astonished today when I found following js snippet on MDN.
var slice = Function.prototype.call.bind(Array.prototype.slice);

After you have it initialised, you are free to use something like
var args = slice(arguments);

It has blown my mind when I realised how powerful bind and call functions are.

BTW if you fully understand it, I think you got how bind and call work.

Adding default custom fields on new posts in WordPress

Standard

Custom fields are essential part of every WordPress site. You know how to add it – Enter new – [type some name] – [type some content] – Add custom field. It’s not complicated process, but it is not as simple as it could be, especially if all of your posts need to have same custom fields, for example, price, size or some very general values. If it is your case, use this snippet and make your life easier.

<pre>add_action('wp_insert_post', 'mk_set_default_custom_fields');

function mk_set_default_custom_fields($post_id)
{
	if ( $_GET['post_type'] != 'page' ) {

		add_post_meta($post_id, 'price', '', true);
		add_post_meta($post_id, 'link', '', true);

	}

	return true;
}</pre>

Simple, right?

You can put numerous custom fields or put just one. It’s up to you.
Oh, I forgot. This adds an empty custom field (with no value). For adding custom field with some value add 

<pre>add_post_meta($post_id, 'custom field name', 'custom field value', true);</pre>

No, you can’t have a million files in your directory or “why WordPress’s storing pictures into subdirectories (year/month) is good?”

Standard

No, you can’t have a million files in your directory. Precisely, you can – but you should not have.

Asking why?

Today I was asked to transfer one old site to WordPress platform and everything seems so fine – I’ve created the script that sniffs through old system’s database, adds new posts (4000+), fix images URLs (4000+ posts x few images), redirect old URLs. But then, I noticed that some pictures are missing. For real, they’re not missing, but they are invisible on file list (direct link to file works), except first 1998 files. Continue reading

New plugin in the repository – Simple Coming soon is out

Standard

Update on July 3rd, 2012: Plugins is no more supported due to lack of free time.

UPDATE: Mukul Hinge wrote a great how-to article which explains how to fix your site when coming soon page is still there, even after deactivating the plugin – Read how.

Great example of coming soon page - created by Marko Prljić
Some time ago I was asked to work on two projects for Marko Prljić – very talented designer from Croatia. Both have needed option to show coming soon page in case that user is not logged in.

At first, this feature was solved by adding code into functions.php file, but today the plugin is born. Download it and have nice coming soon page (with countdown) or create the custom one. Continue reading

Your editors don’t like the dashboard? Redirect them!

Standard

Wordpress DashboardSince a small team (1dva) I freelanced for had migrated to WordPress, I’ve heard numerous times that old CMS was better. I know that our customers do not know why it is better, but I have to find out why they more like the Nano. The answer is more simple than I have expected – our customers don’t like the Dashboard, it is more friendly to go directly to Edit Posts page. Read how to redirect wordpress user from Dashboard. Continue reading

Creating stylesheet for Headline Replacement

Standard

Headline Replacement can be really useful, especially because we are able to choose what titles exactly we want to replace. Version 0.1.1 is out, but the plugin is still difficult to handle with. You have to display image as the img tag what is not the proper way (according the W3 standards) if the image is just replacement for the title . Let’s see how to create automatic stylesheet and avoid img tags. Continue reading