Category Archives: Hacks

Transposh translation filter and Yoast sitemaps compatibility

Transposh Translation Filter is a seldom updated, but very useful plugin for running multilanguage sites on WordPress. It is free, it is very intuitive to use and so far, does not appear to slow the site down too much. You can find the plugin here. Due to some differences with WordPress, the version on WordPress is outdated and no longer updated.

While the plugin creates translated page versions, the sitemaps created by the very popular Yoast SEO plugin (earlier known as WordPress SEO) don’t include those pages. The plugin documentation provides a patch that needs to be applied to the Yoast SEO plugin in the class-sitemaps.php file as follows.

/**
* This function integrates with yoast sitemap generator, and adds for each viewable language, the rest of the languages url
* Also - priority is reduced by 0.2
* And this requires the following patch in class-sitemaps.php
* For future yoast versions, and reference, look for this function:
if ( ! in_array( $url['loc'], $stackedurls ) ) {
// Use this filter to adjust the entry before it gets added to the sitemap
$url = apply_filters( 'wpseo_sitemap_entry', $url, 'post', $p );
if ( is_array( $url ) && $url !== array() ) {
$output .= $this->sitemap_url( $url );
$stackedurls[] = $url['loc'];
}
}

And change to:

if ( ! in_array( $url['loc'], $stackedurls ) ) {
// Use this filter to adjust the entry before it gets added to the sitemap
$url = apply_filters( 'wpseo_sitemap_entry', $url, 'post', $p );
if ( is_array( $url ) && $url !== array() ) {
$output .= $this->sitemap_url( $url );
$stackedurls[] = $url['loc'];
}
$langurls = apply_filters( 'wpseo_sitemap_language',$url);
if ( is_array( $langurls )) {
foreach ($langurls as $langurl) {
$output .= $this->sitemap_url( $langurl );
}
}
}
-------------------------------------------------------------------------
* @param yoast_url array $yoast_url Object containing the page information

However, on examining the code of the current version of the Yoast SEO plugin, I found that this function no longer exists at that location. With some experimentation, I found that the file inc/sitemaps/class-post-type-sitemap-provider.php needs to be edited to include the Transposh function. Find this part:

/**
* Filter URL entry before it gets added to the sitemap.
*
* @param array  $url  Array of URL parts.
* @param string $type URL type.
* @param object $post Data object for the URL.
*/
$url = apply_filters( 'wpseo_sitemap_entry', $url, 'post', $post );

if ( empty( $url ) ) {
continue;
}

if ( $post->ID === $this->get_page_for_posts_id() || $post->ID === $this->get_page_on_front_id() ) {

array_unshift( $links, $url );
continue;
}
$links[] = $url;
}

unset( $post, $url );
}

return $links;
}

And change it to

				/**
* Filter URL entry before it gets added to the sitemap.
*
* @param array  $url  Array of URL parts.
* @param string $type URL type.
* @param object $post Data object for the URL.
*/
$url = apply_filters( 'wpseo_sitemap_entry', $url, 'post', $post );

if ( empty( $url ) ) {
continue;
}

if ( $post->ID === $this->get_page_for_posts_id() || $post->ID === $this->get_page_on_front_id() ) {

array_unshift( $links, $url );
continue;
}
$links[] = $url;

/** Transposh Fix */
$langurls = apply_filters( 'wpseo_sitemap_language',$url);
if ( is_array( $langurls )) {
foreach ($langurls as $langurl) {
$links[] = $langurl;
continue;
}
}
/** End Transposh fix */
}

unset( $post, $url );
}

return $links;
}

Hope you find this useful.

Quick fix for curl: symbol lookup error: /usr/lib/x86_64-linux-gnu/libcurl.so.4: undefined symbol

So you’re trying to install something or compile something or you have curl installed, but it won’t work, because….

# curl -V
curl: symbol lookup error: /usr/lib/x86_64-linux-gnu/libcurl.so.4: undefined symbol: nghttp2_http2_strerror

Or it may be some other package doing this. If you land up on this obscure blog searching, chances are you already have been pulling your hair out wondering what to do.

Here is what I finally did in order to be able to get on with life. Please note, I am not a programmer or any kind of expert and do this at your own risk. I have no idea what you may break. In my case, it was a package I was fairly certain doesn’t belong on my system and isn’t installed.milfster.org comic xxx

Anyway, without further ado, here’s the magic pill.

# ldd /usr/bin/curl|grep /usr/local
	libnghttp2.so.14 => /usr/local/lib/libnghttp2.so.14 (0x00007f8a763ca000)
# mv /usr/local/lib/libnghttp2.so.14 /usr/local/lib/libnghttp2.so.14.bak
# curl -V
curl 7.52.1 (x86_64-pc-linux-gnu) libcurl/7.52.1 OpenSSL/1.0.2l zlib/1.2.8 libidn2/0.16 libpsl/0.17.0 (+libidn2/0.16) libssh2/1.7.0 nghttp2/1.18.1 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 

aaaand… we’re in business. As you clearly see, it is going to be suicidal if you rename something important. So like I said, no guarantees here. It is probably not the correct way of dealing with this, but I am beyond the point of correct now, and this works.

What I have basically done is checked the file referring to the non-existing package causing the problem and renamed it. I imagine you could move or delete it, but if you delete, and this doesn’t work, you can’t bring it back.

Final tip: If you’re using php-curl (or php7.0-curl) with Nginx, you’re still going to be haunted by the problem you have fixed unless… you restart php-fpm 🙂

#service php7.0-fpm restart

Now really done.

How to fix mixed content warning if page loads insecure content in spite of #WordPressHTTPS? #W3TC

So I had been confounded. I used to have a sweet green securely loaded blog for ages and I didn’t know what I had changed to make it start throwing up mixed content warnings. I didn’t recall changing ANYTHING on the blog at all. Yet, when pages were accessed over https, they loaded assets over http – in spite of WordPress HTTPS being active.

The problem turned out to be W3TC Disk Enhanced page caching. It does not seem to distinguish between http and https versions of the page, resulting in the https version of the page serving the http page – of course, with assets loaded over http.

I used to redirect the non ssl version of the blog to the ssl version, but for some reason, I decided to only use an HSTS header. Since the blog automatically loaded over https, I did not anticipate problems. However, the site being available over http apparently caused enough traffic (that ignored HSTS or was not capable?) to create cached pages that became a nuisance.

Mixed content warnings on assets loaded by wordpress

Two ways to fix this. I chose the easy one first. Redirected my non-ssl site to ssl. Done.

All content loaded securely by WordPress

If this results in any noticeable drop of traffic or complaints from anyone who needs to use it without ssl for any believable reason, I will choose method two: relying on HSTS alone again and using either the disk basic or opcode cache for page caching instead of “page enhanced” – this ought to work.

You can check your website on whynopadlock.com to identify the exact assets loaded that are giving mixed content errors.

Ubuntu 13.10 internet very slow “nothing helps” fix

I installed Ubuntu 13.10 on my laptop and went nuts with the laggy laptop. I have 2gb memory on it, which shouldn’t be causing such a comatose experience. I installed drivers, tweaked memory, did a hundred things, nothing helped.

Digging around in the innards, I found that /etc/resolv.conf was very strange and was showing localhost as the name server. This couldn’t be right. Digging around, I found that any attempt to put working DNS servers was getting rewritten.

In the end, I found a strange fix. Network Manager configuration (sudo gedit /etc/NetworkManager/NetworkManager.conf)was using dns from dnsmasq. Guessing (rightly as it turns out) that I didn’t need dns served from my computer (and i have no idea how it would sync it), I commented out that line and restarted network manager. It looks like this.

<code>dns=dnsmasq</code>

Commented it out like so

<code>#dns=dnsmasq</code>

Now /etc/resolv.conf is showing the DNS servers it gets from the internet provider.

I have no idea if this is the “right answer”, but if your computer is slow and freezing on using internet, and your /etc/resolv.conf is showing 127.0.1.1 or 127.0.0.1 or something as your dns server instead of proper dns server IPs, it is worth a shot. You can always uncomment it if it doesn’t help.

My computer is running faster, freezing less and hasn’t yet exploded.

Ioncube with Nginx+php-fpm giving 502 gateway error SOLVED

Ubuntu 13.10 seems to be having trouble with ioncube and php-fpm. My earlier guide on loading ioncube may not work for you anymore.

This is really strange and I have no idea why no one seems to mention it, but if you are getting frustrated trying to install the ioncube loader on php-fpm, just ignore the instructions to create the 20-ioncube.ini file, and plug the line directly into the end of your php ini.

Steps to install ioncube loader with php5-fpm

cd /usr/local
sudo wget http://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
sudo tar xzf ioncube_loaders_lin_x86-64.tar.gz
mv /usr/local/ioncube/* /usr/lib/php5/20121212/

This is the same.

Now, instead of creating a file called 20-ioncube.ini or ioncube.ini directly add it to your php.ini file (On Ubuntu with a repository installed php5-fpm package, php.ini will be found at /etc/php5/fpm/php.ini)

At the very end add:

zend_extension = /usr/lib/php5/20121212/ioncube_loader_lin_5.5.so

Then restart php-fpm

service php5-fpm restart

If it still doesn’t work, try doing the same thing as root.

If you can’t find your php.ini, create a php file on your website with some random name. Open it in an editor and add the line:

Access the file on your site with a browser. It will have all kinds of info about php, including the configuration files (php.ini and others) locations.

Ubuntu network slow RTL8101E/RTL8102E PCI Realtek

I recently reinstalled Ubuntu, and found that my network was agonizingly slow. Installing the driver from the Realtek website fixed this. My card is RTL8101E/RTL8102E PCI Express Fast Ethernet controller, but I imagine this will work for other versions too.

The problem is that the default driver does not support this card well. Blacklist it.

sudo gedit /etc/modprobe.d/blacklist-network

and add

r8169.ko

to it

Download driver from the Realtek website.

Extract it. Compile it by going to the folder where you have extracted it (Downloads, for example) as root (your prompt will be something like this: root@vidyut-Compaq-435-Notebook-PC:~/Downloads/r8101-1.025.00#)and:

make

and

make install

The make install didn’t work for me, so I had to manually copy it into the folder.

cp src/r8101.ko /lib/modules/3.11.0-12-generic/kernel/drivers/net/ethernet/realtek/

Then run:

depmod -a
modprobe r8101
service network-manager restart

That should do it or try

ifconfig eth0 down
ifconfig eth0 up
service network-manager restart

Your network should be working normally now.

Upload Error: client intended to send too large body

If you are using Nginx and are unable to upload files exceeding 1MB or so (most common) and get your error log shows “client intended to send too large body”, then here is the fix.

Edit your Nginx configuration file (which on Debian/Ubuntu will be found at /etc/nginx/nginx.conf) and edit the setting for client_max_body_size to something you can live with. If there is no line for it, add this line:

client_max_body_size 5M;

Obviously, replace 5M (for MB) with a number that makes you happy if your upload is larger.

Enhanced by Zemanta

PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature

If you are trying to upgrade, and suddenly start getting errors like:

Incompatible Archive. PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature

Here are some things to check.

  • This basically means that WordPress is not able to unzip the downloaded packages to install the upgrades.
  • Check to see available space on your disk. If your disk is full you should try upgrading your hosting package or freeing up some space on the disk. One easy way might be to delete old image thumbnails in sizes you no longer use.
  • If you have enough space on your disk, it may be that specific downloaded packages may be problematic. Try to install a plugin you don’t have, and if that works, you should check to see if there is a mysterious folder called “Upgrades” [DO NOT CONFUSE WITH UPLOADS]. If this folder exists, it is worth deleting it to see ii that lets  you do the upgrade.
Enhanced by Zemanta

Free space in your WordPress install by deleting old image sizes

If you change your theme often, your uploads folder will accumulate thumbnails of images in many sizes that you no longer use. This consumes disk space unnecessarily. I wish someone coded a plugin for this, but failing that, a handy way to do this via SSH is:

find . -name *-250x250.* | xargs rm -f

Where 250×250 is the image size you want to delete. You could also try something like:

find . -name *-250x*.* | xargs rm -f

if you have multiple thumbnail sizes like 250×250 250×300 etc.

What I do is list images in the folders to see the unwanted sizes there, and run this delete a few times with various sizes. A more ruthless person could try something like:

find . -name *-*x*.* | xargs rm -f

I do not recommend this, as it can match several files that you may not want to delete, for example a file with a hyphenated name and the letter x in the last hyphenated word, like “wish-merry-xmas.jpg” for example, which wouldn’t be a resized image, but an original or worse, it could be another file and not an image at all, like “here-are-exact-directions-to-our-property.html”.

But if you have a lot of thumbnail sizes, you may feel tempted anyway. Two suggested precautions. Change directory to your uploads folder (you should do this in any case)
cd /path/to/wprdpress/wp-content/uploads
find . -name *-*x*.* | xargs rm -f

The other precaution to take is to specify extension.
find . -name *-*x*.jpg | xargs rm -f
find . -name *-*x*.png | xargs rm -f

This will give you some protection from inadvertently deleting non-resize uploads like “entertaining-extras.pdf”

of course, if you are a patient soul (or don’t have too many files uploaded), you could find the files before deleting to see if any other files are getting selected along with resizes.

find . -name *-*x*.*
and if all is well
find . -name *-*x*.* | xargs rm -f

Do you have a better method?

Enhanced by Zemanta