Call current_user_can after init()

Running buddypress? Are you getting a debug notice like this:

The current user is being initialized without using $wp->init()

and you cannot figure out where it is coming from ?

Most likely one of your plugins is calling a user related wordpress function a bit early (see wordpress action sequence).   You could try deactivating them until the debug message goes away.  The last plugin deactivated will be it.  Let the developer know because his/her code may not be quite working the way it was intended to.

eg: current_user_can()  or possibly  wp_set_current_user()

These need to be used after the init action.  The plugin or theme might have something like

add_action ('plugins_loaded', 'some_function');

The action should be added later, when the current user has been initialised.

add_action ('init', 'some_function');

 

 

Force new windows on external links?

Don’t force your users to open new windows…. even on external links.

There are many reasons why it is a bad idea and not many reasons to do it.   There are maybe a few special cases where it is ok – but is it ever really necessary?  Personally I like to control the opening of tabs myself – I use the right click frequently at times – when I’m researching I open heaps of tabs, then work my way through them.  That doesn’t mean I want a website to forcibly open those links in new windows for me!   Unless of course it is my webmail or feedreader service – then it’s practically obligatory.

Let us assume we are intelligent enough to adhere to standards and take advice from the experts.  Let us assume we all want

And of course we’d like our plugin developers, wordpress developers, tinymce developers to help us in this mission.   This research was done for my own use to determine what my plugins should do.

Summary:

  • forcing new tabs or windows is bad for usability (seriously, studies have shown it is harmful)
  • it is not recommended for accessibility
  • the methods to do it can cause invalid html
  • some folks think it doesn’t help your analytics (although one site had some thoughts on that)
  • it is not necessary… so why do it?  maybe just indicate an external link? or allow for optional js.

Who says no?

Possible reasons to force a new window on external links?

But I want to keep the user on my site…..

“Marketers love it because it allows them to link to external content without taking the reader off the page.”

This is a reasonable fear for a client to have. The user leaving the site and not being able to get back….In every single usability test I’ve done, opening external content in a new window makes this problem worse – not better.

quoted from the Stack exchange usability forum

Special cases perhaps?

  • webmail,
  • feed readers,
  • long lists of external resources.

If we need to do it, what is best way to deal with external links?

Best ways to handle external links

Indicate the external link.

See how Wikipedia  does it.  It classes links as external with a css class.  That css class is then styled with a background image.  It provides a clear visual clue as suggested here.   The css is something like:

 a.external {    background: 
    url(http://upload.wikimedia.org/wikipedia/commons/4/44/Icon_External_Link.svg") 
    no-repeat scroll right center transparent;
    padding-right: 13px;}

OR

style the rel=”external”

a[rel=external]....

 

Force it open anyway?

If you really truly must force  open a new tab or window on an external link, consider:

target=”_blank” is invalid html

 rel=”external” or rel=”external nofollow”

data-rel=”external nofollow”

WordPress and external links

I’m a wordpress plugin developer.  Sadly at stage of writing there doesn’t seem to be a consistent approach in wordpress. Perhaps it’s tinymc’s fault – can it be configured ?

post author or comment author links in twenty-twelve theme

  • uses “rel=”external nofollow”,
  • but by default there is no js to force a window open

wordpress.org links in meta sidebar or footer

  • no attributes, so not an issue

Links or link manager plugin

  • links are no longer a default feature in new sites, but can be added with link manager plugin
  • option to add target=”” and rel=(but only real relationships), not forced

Links in posts

  • (if added using visual editor’s insert link), then we get target=”_blank” ?
  • it’s tinymce allowing users to select ‘open in new window’ – can it be disabled?

external link plugins

even plugins that aim to help you manage outbound links note that opening new windows may have detrimental effects.  Semilogic suggests users may think you used a pop-under.

 Wordpress related discussions and requests:

 

References:

Accessibility guidelines:

Usability advice on external links and new windows:

Web design advice on target=”_blank”

Contrary Arguments

One argument for new windows on external links, but many comments questioning this advice

Need help discussing with your clients?

Some tips on discussing decisions like these:

 

Wp foreign characters, Php, Creating Tables

I knocked myself around trying to figure out why my plugin was not coping with ‘foreign’, multi byte, Greek, Japanese, Chinese characters.  Those damn questions marks ‘????’ – I had it all sorted before in another plugin – what was going on here ?   I had all the multi-byte functions happening.    Then I remembered – the database tables – of course!

Default Mysql

MySQL’s default database charset is usually latin1 and  thecollation is latin1_swedish_ci.  This can vary based on server configuration.  This is usually set before wordpress is installed.

Default wordpress

WordPress usually creates it’s table with charset utf8 and collation utf8_general_ci.    You can overwrite this in the config file.

See http://codex.wordpress.org/Editing_wp-config.php#Database_character_set.

Fix your wordpress database

You can Alter the database after the fact.  This will help the plugins who haven’t figured out that many of us (you?) haven’t set up our databases as well as they could be.

ALTER DATABASE yourdb CHARACTER SET utf8 COLLATE utf8_general_ci;

You may want to fix the individual tables and fields too – phpmyadmin has the tools to edit (or use the rename – it will let you change the collation).

Plugin authors

Make life easy on your self and others when creating custom tables.  Have a look at the wordpress db schema.  Note that there is a global $charset_collate.  Use it!

 

 global $wpdb, $charset_collate;
if (empty($charset_collate))
    $cachecollation = ' DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci ';
else
    $cachecollation = $charset_collate;

if ($wpdb->get_var("show tables like '$table_name'") != $table_name) {
 $sql = "CREATE TABLE " . $table_name . " (
 id bigint NOT NULL AUTO_INCREMENT,
 field1 text NOT NULL,
 field2 text NOT NULL,
 PRIMARY KEY (id) )
 ".$cachecollation. ";";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
 error_log($table_name.' not created');
 return false;
 }
 else return true;

 

Resources: