Jesse Graupmann
Forum Replies Created
-
Looks like you can patch this by just checking is term_id is set before operating on it. Since your goal is to throw it into a loop right after, try:
if ( ! isset($term_id ) ){ // set to empty array before the next check $term_id = array(); } if (!is_array($term_id)) { $term_id = array($term_id); } foreach ($term_id as $t_id) { ... }Weeeeell then, thanks for finding a bug in MY code 😉
Forum: Plugins
In reply to: [Query Monitor] Plugin causing Php Error – Undefined index: fileLooks like the quick fix is just to check if the value is empty before output.
echo self::output_filename( empty($mofile['caller']['display']) ? '' : $mofile['caller']['display'], empty($mofile['caller']['file']) ? '' : $mofile['caller']['file'], empty($mofile['caller']['line']) ? '' : $mofile['caller']['line'] ); // WPCS: XSS ok.Looks like it stems from the post__not_in. If the value is just a number this loop will fail. Making sure the value is wrapped before the loop seems to help.
if( ! is_array( $qv[$key] )) { $qv[$key] = array( $qv[$key] ); }BTW. I’m seeing similar errors for line 226. Same deal;
foreach ( $this->options['nav_menus'][ $theme ] as $menus ) {Forum: Plugins
In reply to: [Polylang] Polylang does not show the langauge set by the browswerFor me, I had to run the filter and reverse the order of the string position checks.
zh_cn would not match zh_tw before, but after the hook, zh is now found in zh_tw & zh_cn.
add_filter('pll_preferred_language', 'f_pll_preferred_language' ); function f_pll_preferred_language($pref){ global $polylang; if(!$polylang)return $pref; if(!$pref || empty($pref)) { $accept_langs = array(); if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { // break up string into pieces (languages and q factors) preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse); $k = $lang_parse[1]; $v = $lang_parse[4]; if ($n = count($k)) { // set default to 1 for any without q factor foreach ($v as $key => $val) if ($val === '') $v[$key] = 1; // bubble sort (need a stable sort for Android, so can't use a PHP sort function) if ($n > 1) { for ($i = 2; $i <= $n; $i++) for ($j = 0; $j <= $n-2; $j++) if ( $v[$j] < $v[$j + 1]) { // swap values $temp = $v[$j]; $v[$j] = $v[$j + 1]; $v[$j + 1] = $temp; //swap keys $temp = $k[$j]; $k[$j] = $k[$j + 1]; $k[$j + 1] = $temp; } } $accept_langs = array_combine($k,$v); } } // looks through sorted list and use first one that matches our language list $listlanguages = $polylang->get_languages_list(array('hide_empty' => true)); // hides languages with no post foreach (array_keys($accept_langs) as $accept_lang) { foreach ($listlanguages as $language) if (empty($pref_lang) && (0 === stripos($language->slug, $accept_lang ) || 0 == strcasecmp(str_replace('_', '-', $language->locale), $accept_lang)) ) $pref_lang = $language; } } return isset($pref_lang) ? $pref_lang->slug : $pref; }For you, I would throw this into a plugin and check what value it’s getting from $pref after it’s gone through polylang checks.
Also, check your variable $_SERVER[‘HTTP_ACCEPT_LANGUAGE’] to see what your browser is reporting. HTTP_ACCEPT_LANGUAGE lists quite a few languages & priorities of those – if set.
Forum: Plugins
In reply to: [Polylang] Polylang does not show the langauge set by the browswerI was looking into this today for Black-Buddha.com. It seems for Chinese at least, the language code needs to match exactly. ko works, but zh_cn doesn’t match zh_tw.
After reading this post and looking over polylang/frontend/choose-lang.php -> get_preferred_language() : line 85, it might just be a matter of hooking into the ‘pll_preferred_language’ filter.
// allow plugin to modify the preferred language (useful for example to have a different fallback than the default language) $slug = apply_filters('pll_preferred_language', isset($pref_lang) ? $pref_lang->slug : false);just make sure the cookie hasn’t been set or you’ll never get that far;
if (isset($_COOKIE[PLL_COOKIE])) return $this->model->get_language($_COOKIE[PLL_COOKIE]);This all assumes like Chrystl said, you’ve already set your preference in ‘/options-general.php?page=mlang&tab=settings’ and you’re hitting the homepage;
Detect browser language: When the front page is visited, set the language according to the browser preferenceThanks Chouby!
May I ask what this new feature is? And how best to use it in the future?
Forum: Plugins
In reply to: [WordPress Social Login] Abandoned?@miled – Thanks for this plugin!
You have made my life (and other lives) easier and any work you put into it is appreciated and valuable. 30,000+ active installs isn’t half bad.
All good. Yes, I’m developing a theme locally and I am doing a lot of logging to iterate on my own features so WP_DEBUG is true.
I guess this is two-fold.
1) I only care when a plugin needs to be updated and even then I like to wait a bit before upgrading.
2) I want my logs as clean as possible.
Does setting ‘fbrfg_dismiss_all_update_notifications’ remove this output? Or could you add another option in log_info;
// /plugins/favicon-by-realfavicongenerator/public/class-favicon-by-realfavicongenerator-common.php public function log_info( $message ) { if ( ( constant( 'WP_DEBUG') == 'true' ) || ( constant( 'WP_DEBUG') == 1 ) ) { if ( constant( ‘RFG_DEBUG') == 'true’ ) { error_log( 'RFG - ' . $message ); } } }Keep in mind this is pretty minor in the grand scheme of things.
Either way, I appreciate your consideration.
Forum: Plugins
In reply to: [Polylang] Getting language from pathI was looking into a similar solution, just a simple query override. Here is my attempt w/the information you’ve provided Chouby. The majority of this code is just checking the query against known supported languages before making the override.
This doesn’t work 100%, 100% of the time – but it get’s pretty close.
The goal would be for anyone, even an FB crawler to specify a locale when linking to a page like https://black-buddha.com/?locale=zh_TW or https://black-buddha.com/zh_tw/watch/mott32-2/?fb_locale=en_US. I’ve been seeing a lot of log entries from facebook.com/externalhit_uatext.php lately and I wonder if this might be helpful.
Either way, I just want to solve this translation override for the login form, so here is a start.
Cheers
/* ================================================== * OVERRIDE CURRENT PLL LANGUAGE * ==================================================*/ /** * HiJack the pll_language_defined action and override the current language. * @param string $slug * @param PLL_Language $curlang * @example https://black-buddha.com/?l=zh_TW * @example https://black-buddha.com/zh_tw/city/臺北/?locale=en_US * @example https://black-buddha.com/watch/flask/?fb_locale=zh_TW * @example https://black-buddha.com/?lang=zh_TW */ function ___pll_language_defined ( $slug, $curlang ) { static $override_language = FALSE; global $polylang; if ( ! $polylang ) { return; } if ( ! $override_language ) { $reqs = array( $_GET, $_POST ); $params = array( 'lang', 'locale', 'l' , 'fb_locale' ); foreach ( $reqs as $req ) { if ( $override_language ) break; foreach ( $params as $param ) { if ( $override_language ) break; if ( ! empty( $req[ $param ] ) ) { $override_language = sanitize_key( $req [ $param ] ); break; } } } } if ( $override_language ) { // validate against known languages $supported_languages = $polylang->model->get_languages_list ( ); foreach ($supported_languages as $lang) { if ( FALSE != preg_match( "/($override_language)/i", $lang->locale )) { $override_language = $lang->slug; break; } } if ( ! $override_language) { error_log ( 'FAILED to find language support for ' . $override_language ); $override_language = FALSE; return; } // try to get the language $nLanguage = $polylang->model->get_language( $override_language ); if ( $nLanguage ) { $polylang->curlang = $nLanguage; $GLOBALS [ 'text_direction' ] = $polylang->curlang->is_rtl ? 'rtl' : 'ltr'; stop_checking_language_code_in_url ( ); // NOTE: setcookie has been called already // (PLL_Choose_Lang)$this->maybe_setcookie(); } else { error_log ( 'FAILED to change language to ' . $override_language ); $override_language = FALSE; } } } // NOTE: do_action called from wp-content/plugins/polylang/frontend/choose-lang.php add_action('pll_language_defined', '___pll_language_defined', 0, 2); function stop_checking_language_code_in_url ( ) { global $polylang; if ( $polylang ) { remove_action('wp', array ( $polylang->choose_lang, 'check_language_code_in_url' )); } } // WARNING: Stops working well when you remove the code in url check... // if(did_action('plugins_loaded')) stop_checking_language_code_in_url(); // add_action( 'plugins_loaded', 'stop_checking_language_code_in_url', 10 );Thanks for the quick response!
Forum: Plugins
In reply to: [Enable Media Replace] 'Invalid argument supplied for foreach()'It looks like if you just do some null checks, you’ll be fine. I had an error where items did not correctly generate their size links and running replace would crash. Please add some checks to see if you can loop and it’ll fix the issue.
Thanks.
// Delete old resized versions if this was an image $suffix = substr($current_file, (strlen($current_file)-4)); $prefix = substr($current_file, 0, (strlen($current_file)-4)); $imgAr = array(".png", ".gif", ".jpg"); if (in_array($suffix, $imgAr)) { // It's a png/gif/jpg based on file name // Get thumbnail filenames from metadata $metadata = wp_get_attachment_metadata($_POST["ID"]); if (is_array($metadata) && isset($metadata["sizes"]) && is_array($metadata["sizes"])) { // Added fix for error messages when there is no metadata (but WHY would there not be? I don't know… foreach($metadata["sizes"] AS $thissize) { if(!is_array($thissize))continue; // Get all filenames and do an unlink() on each one; $thisfile = $thissize["file"]; // Create array with all old sizes for replacing in posts later $oldfilesAr[] = $thisfile; // Look for files and delete them if (strlen($thisfile)) { $thisfile = $current_path . "/" . $thissize["file"]; if (file_exists($thisfile)) { unlink($thisfile); } } } } // Old (brutal) method, left here for now //$mask = $prefix . "-*x*" . $suffix; //array_map( "unlink", glob( $mask ) ); }Forum: Plugins
In reply to: [Polylang] ACF relationship fields & PolylangBTW, @chouby, thank-you for a great product.
Forum: Plugins
In reply to: [Polylang] ACF relationship fields & PolylangACF has changed the way they get their posts in 5.2.X. It may be because of polylang/frontend/frontend-auto-translate.php; PLL_Frontend_Auto_Translate->pre_get_posts($query); Since the new method for ACF relies on pre_get_posts.
I am ready to launch a multilingual site with PolyLang and ACF in two weeks. I would love to work towards a solution for this.