2014-02-26

"An error occurred in the upload..." (WordPress Media)

Seeing "An error occurred in the upload..." message when calling WP Media interface on the front?

I believe, that's a core problem, but here is a workaround that I am using quite often in my projects.

Admins won't have this bug, but regular users - will. Because we are on a page, which $post was not created by this regular user, so he does not have the editing capabilities... and Media needs them.

// Preserve the current Post
// (just in case, you may not need it)
$oldPost = $GLOBALS['post'];
// Make it a dummy
$GLOBALS['post'] = 0;

// For example, the editor, with "Media" button:
wp_editor($content, $editor_id, $settings);
// Or "Upload Avatar" code from the WPUA plugin
do_action( 'show_user_profile', $current_user );

// Restore
$GLOBALS['post'] = $oldPost;

// Be happy

2014-02-16

Visibility of Google Docs (Drive) in SERPs

I've been wondering how would it work if, instead of typing in a blog, I'd share Google Docs. There is a "Publish on the Web" option there. Would I still need a blog, or I can maintain a combination of Google Plus and Google Drive?

I do not have an answer yet, but here is a "discovery" I just made by checking the Google Docs visibility in search results. There is nothing surprising in what I saw, just a little fun :-)

Update:

I received this comment:
... they are not private as you suggest in your article, they are simply shared docs that violate G's TOS
Specifically, they are BH intermediary pages with the intention of passing PR via one of Google's own subdomains. ;(


  • Google publishes links to (probably) all people's docs.
  • All titles and descriptions are the same
This looks almost the same as it would look on your site with the Disallow instruction in the robots.txt file.

Almost - because Google substitutes the title and description with self-promotion.

and finally:
  • When you click on a link, it shows a "scary" message :-)



2014-01-24

Sender address rejected: Domain not found - outgoing mail settings with Postfix

Environment:

A staging server called "tst.myserver.com", with no DNS record pointing to it.
Trying to send email from there to myself (me@my-mail.com)

Problem:

$ echo foo | mail -s bar me@my-mail.com
$ tail /var/log/mail.log
Jan 24 18:30:24 tst postfix/smtp[26306]: 46D8FC2584: to=<me@my-mail>, relay=mail.my-mail[1.2.3.4]:25, delay=0.61, delays=0.02/0.01/0.45/0.13, dsn=5.1.8, status=bounced (host my-mail[1.2.3.4] said: 554 5.1.8 <me@tst.myserver.com>: Sender address rejected: Domain not found (in reply to RCPT TO command))

Explanation:

$ cat /etc/hostname
tst.myserver.com
This is the FQDN (fully qualified domain name), and Postfix appends it to the local user name.

What we want

We'd like Postfix to append only the myserver.com and not the tst.myserver.com

A solution

(figured out by reading http://www.postfix.org/ADDRESS_REWRITING_README.html)
# vi /etc/postfix/main.cf
(add this line:)
masquerade_domains = myserver.com
Restart Postfix
# postfix stop && postfix start

2014-01-04

Could not open input file: /cygdrive/c/PHP/phpunit (PHP under Cygwin)

The problem:

$ /cygdrive/c/PHP/php.exe /cygdrive/c/PHP/phpunit
Could not open input file: /cygdrive/c/PHP/phpunit

Environment:

MS Windows
PHP
Cygwin

Explanation:

While started in Cygwin, php.exe will be run in Windows environment, which does not know how to translate /cygdrive/c to C:\

Solution:

Use a wrapper script https://gist.github.com/tivnet/8256140
(Originally published by aefxx here)

2013-11-23

A Nostradamus Prophecy might speak about WordPress?

Years will pass quickly
Causing great tremors around the City of Matteus.
The Core will move at the speed of light,
And then Two Numbers will match


/**
 * The WordPress version string
 *
 * @global string $wp_version
 */

$wp_version = '3.8-beta-1';

/**
 * Holds the required PHP version
 *
 * @global string $required_php_version
 */
$required_php_version = '5.2.4';

2013-09-10

Testing Google Plus post embedding....

All you need is...
<div class="g-post" data-href="https://plus.google.com/106666163580246454307/posts/D82yhXHhhg9"></div>
The HTML is available by pressing "Embed Post" on the G+ post menu ([v] at the top right).



2013-06-19

WordPress: remove admin menu items

There are several well-written WordPress plugins that allow removing and re-ordering admin menu items. However, if you want something quick and simple for your site, the code snippet below may be useful. It removes all menus, except for Dashboard and WooCommerce "Products".

Feel free to modify is as necessary.

► Tip: you can print_r($menu) to see what to keep.


add_action('admin_menu', function () {
 if (current_user_can('administrator')) {
  return;
 }

 /**
  * Keep only specific menu items and remove all others
  */
 global $menu;
 $hMenu = $menu;
 foreach ($hMenu as $nMenuIndex => $hMenuItem) {
  if (in_array($hMenuItem[2], array(
       'index.php',
       'edit.php?post_type=product',
      ))
  ) {
   continue;
  }
  unset($menu[$nMenuIndex]);
 }
}