Alex (SirShurf) Frenkel's Blog

A web log of a PHP professional

Archive for the ‘Wordpress’ Category

WPML 3.1.8.x and the double slash problems continues.

leave a comment »

Well, after my previous post WPML have relised a new version 3.1.8.2, but it looks like this error gone unnoticed.

One other error with my solution was that on the homepage paging it had errors, so here is the revised version of the fix for WPML.

$arrUrl = parse_url($absolute_home_url);
if(!isset($arrUrl[‘path’])) $arrUrl[‘path’] = ‘/’;
$absolute_home_url = $arrUrl[‘scheme’].”://”.$arrUrl[‘host’].$arrUrl[‘path’];
if(isset($arrUrl[‘query’])) $absolute_home_url .= ‘?’.$arrUrl[‘query’];
if(isset($arrUrl[‘fragment’])) $absolute_home_url .= ‘#’.$arrUrl[‘fragment’];
unset($arrUrl);
$arrUrl = parse_url($this->settings[ ‘language_domains’ ][ $code ]);
if(!isset($arrUrl[‘path’])) $arrUrl[‘path’] = ‘/’;
$this->settings[ ‘language_domains’ ][ $code ] = $arrUrl[‘scheme’].”://”.$arrUrl[‘host’].$arrUrl[‘path’];
if(isset($arrUrl[‘query’])) $this->settings[ ‘language_domains’ ][ $code ] .= ‘?’.$arrUrl[‘query’];
if(isset($arrUrl[‘fragment’])) $this->settings[ ‘language_domains’ ][ $code ] .= ‘#’.$arrUrl[‘fragment’];
unset($arrUrl);
$arrUrl = parse_url($new_url);
if (!empty($arrUrl)){
if(!isset($arrUrl[‘path’])) $arrUrl[‘path’] = ‘/’;
$new_url = $arrUrl[‘scheme’].”://”.$arrUrl[‘host’].$arrUrl[‘path’];
if(isset($arrUrl[‘query’])) $new_url .= ‘?’.$arrUrl[‘query’];
if(isset($arrUrl[‘fragment’])) $new_url .= ‘#’.$arrUrl[‘fragment’];
}
unset($arrUrl);

 

The fix goes into sitepress.class.php on between lines 6463 and 6464:

                        $this->settings[ ‘language_domains’ ][ $default_language ] = $wpdb->get_var( “SELECT option_value FROM $wpdb->options WHERE option_name = ‘siteurl'”);
$new_url = str_replace( $absolute_home_url, $this->settings[ ‘language_domains’ ][ $code ], $new_url );

Advertisements

Written by Alex (Shurf) Frenkel

October 28, 2014 at 2:12 pm

Posted in Plugin, Wordpress, wpml

WPML makes the user logged out on 3.1.8.1 upgrade

with one comment

WPML rolled out an update to their plugin version 3.1.8.1.

But since the update you cannot work in the admin panel any more, each url will have more then one slash in it.

Here is my fix for the problem (until thy will issue an update).

The problem is in the sitepress.class.php file on line 6464, and created by in the addition of line 6463.

In line 6463 they have added a selection of site_url paramtere from the global parameter set of wordpress:

$this->settings[ ‘language_domains’ ][ $default_language ] = $wpdb->get_var( “SELECT option_value FROM $wpdb->options WHERE option_name = ‘siteurl'”);

This selection have an url of the website WITH the trailing slash in it.

And this data is sent to the next line: 6464

$new_url = str_replace( $absolute_home_url, $this->settings[ ‘language_domains’ ][ $code ], $new_url );

What this creates is a URL with next features:http://localhost//wp-admin/?lang=frAnd the double slash created the logout problem.By addint my lines of code, the error can be managed, untill a more permanent fix will be applied by WPML team:Simple add next code between 6463 and 6464 (inclusive)

                        $this->settings[ ‘language_domains’ ][ $default_language ] = $wpdb->get_var( “SELECT option_value FROM $wpdb->options WHERE option_name = ‘siteurl'”);
$arrUrl = parse_url($absolute_home_url);
if(!isset($arrUrl[‘path’])) $arrUrl[‘path’] = ‘/’;
$absolute_home_url = $arrUrl[‘scheme’].”://”.$arrUrl[‘host’].$arrUrl[‘path’];
if(!isset($arrUrl[‘query’])) $absolute_home_url .= ‘?’.$arrUrl[‘query’];
if(!isset($arrUrl[‘fragment’])) $absolute_home_url .= ‘#’.$arrUrl[‘fragment’];

$arrUrl = parse_url($this->settings[ ‘language_domains’ ][ $code ]);
if(!isset($arrUrl[‘path’])) $arrUrl[‘path’] = ‘/’;
$this->settings[ ‘language_domains’ ][ $code ] = $arrUrl[‘scheme’].”://”.$arrUrl[‘host’].$arrUrl[‘path’];
if(!isset($arrUrl[‘query’])) $this->settings[ ‘language_domains’ ][ $code ] .= ‘?’.$arrUrl[‘query’];
if(!isset($arrUrl[‘fragment’])) $this->settings[ ‘language_domains’ ][ $code ] .= ‘#’.$arrUrl[‘fragment’];

$new_url = str_replace( $absolute_home_url, $this->settings[ ‘language_domains’ ][ $code ], $new_url );

Written by Alex (Shurf) Frenkel

October 26, 2014 at 11:03 am

Posted in Wordpress, wpml

Tagged with

Another Week another beta – WordPress 3.4 Beta 2

with one comment

Well the second beta is out, and about 60 bug fixes were commited …

 

We will see how it works 🙂

Written by Alex (Shurf) Frenkel

April 13, 2012 at 11:26 am

Posted in Wordpress

Tagged with , ,

WPMU Ultimate Facebook Addon plugin Upgraded to version 0.3

with 2 comments

Well as stated in the topic, I have updated the WPMU Ultimate Facebook plugin Fix to version 0.3.

This is a maintenance only version since it’s only fixing posting description with a quotes (single quote to be exact).

You can download the plugin from: http://wordpress.org/extend/plugins/wpmu-dev-facebook-addon/

And you can get the plugin from: WPMUDev.org

 

Written by Alex (Shurf) Frenkel

March 12, 2012 at 7:05 pm

WPMU Infinite SEO plugin fix

with 7 comments

As you where able to see from my previous post’s I was quite made at some of the development decisions of WPMU stuff and I was stuck with a problem that was not possible (at least I did not know how) to fix.

Well I fixed it and here is the result.
My new plugin was approved by wordpress.org and can be downloaded here: http://wordpress.org/extend/plugins/wpmu-dev-seo-addon/

This plugin fix multibite problems with the description and fixes usage of caption.

Comments are welcomed.

Written by Alex (Shurf) Frenkel

February 22, 2012 at 10:41 pm

WPMU Ultimate Facebook plugin Fix

with one comment

In addition to this post:Problem with UTF, Excepts — AND GOOD CODING PRACTICES!

I have created a fix to Ultimate Facebook:
This fix address next things:
* Facebook OpenGraph fails if the text in description is incorrect – especially in Hebrew
* Current version of the plugin sends in wall post description blog tag line. In my fix I am sending Excerpts.

The plugin can be downloaded at wordpres.org.

http://wordpress.org/extend/plugins/wpmu-dev-facebook-addon/

Written by Alex (Shurf) Frenkel

February 20, 2012 at 9:42 pm

Problem with UTF, Excepts — AND GOOD CODING PRACTICES!

with 2 comments

I am sorry if what I am going to write will offend anybody but after more then 2 days of debugging… I am getting frustrated with this.

I have no problems with plugins not working with Hebrew, since this language is not that common, but for crying out loud, PLEASE pretty PLEASE use common sense when programming!

I will show here simple example of what I mean and this is only an example, unfortunaly the same problem exist in other plugins (I have seen the same general programming problems in Ultimate Facebook too).

This plugin create a description text for the “META-Description” tag.
Now the problem in the current version I faces is that it’s not stripping out “Caption” tags and it’s splitting multi-byte strings in the middle of the letter (usage of strlen which is not multibyte safe).
I am not asking here WHY the programmer not used a built in function to get excerpt of a set length, or added ANY hooks in his plugins!!!

Here is the code used:

First lets go to: wds_onepage.php that is responsible for printing the meta to the client, in it we see next code:

if (is_singular()) {
$metadesc = wds_get_value('metadesc');
if ($metadesc == '' || !$metadesc) {
$metadesc = wds_replace_vars($wds_options['metadesc-'.$post->post_type], (array) $post );
}
}

You can see here that first we try to get metadesc value and if it’s empty we are requesting metadesc value from the option.
Lets trace “wds_replace_vars” to the source, and we find it in wds_core.php
I will not put the full function here to save some space but here is the interesting part:
'%%excerpt%%' => !empty($r['post_excerpt']) ? apply_filters('get_the_excerpt', $r['post_excerpt']) : substr(wp_trim_excerpt($r['post_content']), 0, 155),

We are checking IF excerpt exists if not we will create one using “wp_trim_excerpt” and we will substr (not MB safe!!!).
The first part of the problem is easily fixed here all I need to do is to sit in the “wp_trim_excerpt” hook of WP:

add_filter( 'wp_trim_excerpt', array($objClass,'seo'));
...
function seo($strText){

$strText = strip_shortcodes( $strText );
$strText = strip_tags ( $strText );

return $strText;
}

That way we are getting text only and not all of the HTML junk the plugin is giving GOOGLE.

But now I am getting blank description, so lets trace it further, we have striped the text, and cutted it not MB safe to 155 characters. next things we have is this:

echo "\t".''."\n";

OUCH, now, we are stripping tags and using esc_attr on our cutted text. the first is stupid since the HTML we had was cutted to 155 in the middle so the strip_tags would not work, but that I have fixed using the hook above (I am stripping tags on the original text before the substr call).

But the biggest problem is the esc_attr call, since it’s checking for the CORRECT UTF text, and since we cutted the text in the middle of a letter it is not a VALID UTF!

to fix that lets change the hook above:

add_filter( 'wp_trim_excerpt', array($objClass,'seo'));
...
function seo($strText){

$strText = strip_shortcodes( $strText );
$strText = strip_tags ( $strText );
$strText = apply_filters('the_content', $strText);
$strText = str_replace(']]>', ']]>', $strText);
$excerpt_length = apply_filters('excerpt_length', 55);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$strText = wp_trim_words( $strText, $excerpt_length, $excerpt_more );

return $strText;
}

This time I am responsible for the shortening of the text (I am making it only 55 characters to fit in 155 that will be cutted later), and using wp_trim_words in order to have only full words in the description (Google dont like paritial words).

This has taken ceare of the first part the client part, but what about the Admin part?

Well this is the one that got me to write this post, in the admin part for some reason the creation of the text does not uses the same function at all!!!!

The parameter here is $desc in wds-core-metabox.php and is acheaved by this code:

$desc = wds_get_value('metadesc');
if (empty($desc))
$desc = substr(strip_tags($post->post_content), 0, 130).' ...';
if (empty($desc))
$desc = 'temp description';

Now here there is NO hooks and no methods for me to catch.
Currently as of writing this post, I have not yet found an answere of how to bypass this and ANY ideas will be welcomed.

In any way, my fix for this plugin will be availible at this location as soon as wordpress.org approve it:
http://wordpress.org/extend/plugins/wpmu-dev-seo-addon/

Written by Alex (Shurf) Frenkel

February 20, 2012 at 5:22 pm