always getting 404 erorr for some css files - css

Dear friend sorry if i am not expert but i try to find a soloution for my problems
when messure the performance of my site with gtmetrix tool, the onload time exceed 8 sec it take a long time because there are two missing files give 404, many times ago i added an empty file with the same name, but again i found them disappeared and 404 error come again such as
bootstrap.min.css?ver=3.0.1
query.fancybox.css?ver=3.0.1
**when i ask my host to help they said **
It looks like both the files are being loaded from your child themes files.
wp-content/themes/masterstudy-child/functions.php : line 5
wp_enqueue_style( 'boostrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css', NULL, STM_THEME_VERSION, 'all' );
wp-content/themes/masterstudy/inc/scripts_styles.php : line 13
wp_enqueue_style( 'masterstudy-bootstrap', get_template_directory_uri() . '/assets/vendors/bootstrap.min.css', null, STM_THEME_VERSION, 'all' );
wp-content/themes/masterstudy-child/functions.php : line 8
wp_enqueue_style( 'fancyboxcss', get_template_directory_uri() . '/assets/css/jquery.fancybox.css', NULL, STM_THEME_VERSION, 'all' );
i try to clear cash many times
===========================================================
also theme author said that these files were not generated by their theme, i can't understand the reason and can't find how to fix for ever
need some to explain the reason of this problem and how to fix for ever

Related

Getting notice is wordpress "WP_Scripts::localize was called incorrectly"

Complete message:
Notice: WP_Scripts::localize was called incorrectly. The $l10n parameter must be an array. To pass arbitrary data to scripts, use the wp_add_inline_script() function instead. Please see Debugging in WordPress for more information. (This message was added in version 5.7.0.) in /home3/dduconne/public_html/wp-includes/functions.php on line 5313
Appeared just after updating wordpress to 5.7.0
Ok since there quite a few views and the previous answer just throws it under the rug.
Yes it is a warning now, but who knows what will happen, it is a warning for a reason, disabling something is not resolving it, there is a reason devs set it as a warning for now.
While we wait for plugin developers to resolve it on their ends, you can find out the source of the problem by enabling php_xdebug in php. I recommend not leaving it after debugging, as I am not sure about the performance cost of it being enabled.
php_xdebug will return a stack of all files affected, from there you can trace it to the source of the problem. The fix once found the source is quite easy. Culprit most likely is wp_localize_script() which requires last parameter to be an array()!
So you would find something like this:
wp_localize_script( 'handle', 'object_name', 'l10n_culprit_string' );
Which should be turned into:
wp_localize_script( 'handle', 'object_name', array( 'l10n_culprit_string' ) );
Solution to problem came from here
This is a new warning appearing in Wordpress 5.7. If you don't want to see it, and still want to have WP_DEBUG set to true, it is possible to disable the message by adding the following for example in your theme's functions.php:
add_filter('doing_it_wrong_trigger_error', function () {return false;}, 10, 0);
It is now a notice if you are using wp5.7 and php7.4, but changing to php8 it may gets reported as error. For me, when i changed (in my own code) the passed value to array (yes, probably some changes also needed in the involved js), everything worked just fine.
This is because one of the PHP script in your wordpress installation uses wp_localize_script() to pass some PHP variables to a JS script through AJAX request, and it's not good practice anymore.
This can be inside a plugin or inside your custom theme or child-theme's functions.php.
If wp_localize_script() is not in a child-theme or custom theme's functions.php, try this :
backup your website
deactivate all plugins
reactivate them one by one until you get the notice again
when the notice shows up again, this means the plugin you just reactivated uses wp_localize_script() the wrong way
if it's not up-to-date, try updating it (if you want to) : maybe the notice is going to disappear
if it's already up-to-date, or you don't want to update it, search inside wp-content/plugins the corresponding plugin's folder
open it and try to find the file(s) where wp_localize_script() is called, you can also use CLI with your server's terminal to find string in files. For example, if your server runs on Linux : grep -H -r "wp_localize_script()" /root/pathtopluginfolder | cut -d: -f1
Then, replace the code as follow :
Old one should look almost like this :
wp_enqueue_script( 'wpdocs-my-script', 'https://url-to/my-script.js' );
wp_localize_script( 'wpdocs-my-script', 'MYSCRIPT', array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'otherParam' => 'some value',
) );
New one :
wp_enqueue_script( 'wpdocs-my-script', 'https://url-to/my-script.js' );
wp_add_inline_script( 'wpdocs-my-script', 'const MYSCRIPT = ' . json_encode( array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'otherParam' => 'some value',
) ), 'before' );
Note that you need to add 'before' as the third parameter to the wp_add_inline_script function.
Once it's done, the notice shouldn't show anymore. If so, contact the plugin dev to tell him about this so that it can be part of the next update.
For more informations, see Jules Colle's comment on this page : https://developer.wordpress.org/reference/functions/wp_add_inline_script/

ACF - User.php filter or aciton

I'm using wordpress with Advanced Custom Fields plugin v4.4.2
I need to modify the user select fields, so that it displays not only display_name, but also the user_login.
I found the bit of code that handles this, and it is here:
wp-content/plugins/advanced-custom-fields/core/fields/user.php on line 223
And i changed the default code from:
$field['choices'][ $label ][ $user->ID ] = ( $user->display_name );
to:
$field['choices'][ $label ][ $user->ID ] = ucfirst($user->user_login) . ' - ' . ucfirst( $user->display_name );
Now, everything's working fine, but, as you probably already know, changing core files it's not the best way to modifying things in wordpress, but i have to use filters or actions.
Now, simple question, is there a filter or action that allows me to change this bit?
I searched a lot but i couldn't find anything useful.
thanks for your help.
I quickly go through this plugin and I found that (although I haven't tested this) :
There is a filter acf/load_field_defaults. This filter hook can be used for this purpose.
I found this in file core/fields/_functions.php line number 546

rename() not working Wordpress plugin

I have a Wordpress plugin that will take the name of one directory on the server and rename to a name set in a Settings/Options field. The code I'm using is:
$base = basename(dirname(__FILE__));
$path = (isset($xgeneral['obf_plugin']))
?$xgeneral['obf_plugin']
:'original_directory';
if ($path != $base) {
$former = $base . DIRECTORY_SEPARATOR . 'mig_plugin.php';
$newer = $path . DIRECTORY_SEPARATOR . 'mig_plugin.php';
rename($former,$newer);
}
So what happens is when the plugin loads the first time, it checks if the obf_plugin option is the same as the directory in question; if they are different, it then renames it.
However, no matter what I try I get the error rename(migratex/mig_plugin.php,tango/mig_plugin.php): no such file or directory (tango is just the dumb sample word I tried to use) I tried referencing the absolute file path on the server using this code:
define("DS","/",true);
define('BASE_PATH',realpath(dirname(__FILE__)).DS,true);
but that doesn't make a difference.
Is there any reason why the rename() function is not working? It is running inside the Wordpress Admin page.
Thank you!
EDIT: Further investigation reveals this works in plain PHP but will not when running in Wordpress. Any thoughts as to how to enable rename() in Wordpress?

Wordpress Custom Permalinks plugin - Redirect Loop

We have two Wordpress (3.5) blogs in a network setup. We recently installed the Custom Permalinks plugin, https://wordpress.org/plugins/custom-permalinks/. It all works fine locally (Mac) and even on production for one of the blogs. For the other blog however, changing the URL slug using the Custom Permalinks plugin, gives: "This webpage has a redirect loop". If it makes any difference (even though it shouldn't) the blog is in Arabic and the posts' URL slugs are in Arabic. I have tried:
- Just going to the permalinks admin pages and hitting "Save", it worked for some people with similar issues.
- Tried to clear cache and cookies.
- Checked .htaccess
UPDATE
If this makes any difference, I noticed that on one of the blogs on our production set up, for which I get the "too many redirects" error, if I switch to using English URL slugs, it works. This blog is in Arabic, and we are using Arabic URL slugs.
I am running out of ideas, any help would be much appreciated, thanks!
Problem is caused by the custom permalink (edited in post itself) having characters invalid for the plugin logistics (even spaces).
The plugin registers a hook:
add_action( 'template_redirect', array( $this, 'make_redirect' ), 5 );
template_redirect occurs during template load, as provisioned by the plugin's hook into add_filter( 'request', array( $this, 'parse_request' ) );.
Due to plugin not supporting encoded url's, it fails to perform the database query.
The fix was fairly simple enough.
Adding urldecode() to the spots required for proper logistics.
/frontend/class-custom-permalinks-frontend.php
Line # 167 becomes:
$request_no_slash = preg_replace( '#/+#','/', urldecode(trim( $request, '/' ) ));
Line # 369 becomes:
$request_no_slash = urldecode($request_no_slash);
Line # 432 becomes:
substr( urldecode($request), 0, strlen( $custom_permalink ) ) != $custom_permalink
Line # 440 becomes:
if ( substr( urldecode($request), 0, strlen( $original_permalink ) ) == $original_permalink
Line # 441 becomes:
&& trim( urldecode($request), '/' ) != trim( $original_permalink, '/' )
solved for me instantly.

Override a WordPress plugin translation file on load

I'm using WordPress in french with the plugin The Events Calendar.
This plugin comes with a bundled french translation but it has some mistakes. I want to fix them but replacing the original file is a bad idea since it's gonna be replaced with the next update. I contacted the developer to submit a fix but it may take some time.
In the meantime, I would like to load a duplicate I did from my template directory. I already tried multiple things like:
load_plugin_textdomain( 'tribe-events-calendar', get_template_directory() . '/languages' );
Or with
add_filter('override_load_textdomain', …)
in my functions.php but it doesn't seem to work. The only thing I was able to do is disabling the load of the original translation file.
Is there any way to replace a plugin translation file on load? I use WPML too but in "Translate with .mo files" mode not in "Translate with WPML" so I can't change plugin translation on the fly. Maybe WPML can load my own translation of The Events Calendar?
You can add this few lines in your functions.php theme file
$text_domain = 'the-events-calendar';
$original_language_file = ABSPATH . DIRECTORY_SEPARATOR . 'wp-content' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'the-events-calendar' . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR . 'the-events-calendar-fr_FR.mo';
$override_language_file = ABSPATH . DIRECTORY_SEPARATOR . 'wp-content' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'your-own-theme' . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR . 'the-events-calendar-fr_FR.override.mo';
// Unload the translation for the text domain of the plugin
unload_textdomain($text_domain);
// Load first the override file
load_textdomain($text_domain, $override_language_file );
// Then load the original translation file
load_textdomain($text_domain, $original_language_file );
You'll have to replace the two file variables with the actual language file.
But we'll suppose that the french language file is in the plugin language folder and your override language file is in the language theme folder.
The idea is to :
Un load the language that has already been loaded automatically by WP
Load your override file first. This is important to load it first, because already defined translations will be skipped when you'll load another language file for this text domain (see WP core).
Load the original translation file, which will in fact load all the untranslated strings of the override file.
This works only with compiled mo file.
You can only add to your override file the few strings you want to override.
I am the author of the Transposh plugin,
Your answer actually is in the following four filters:
add_filter('gettext', ......, 3);
add_filter('gettext_with_context', ......, 3);
add_filter('ngettext', ......, 4);
add_filter('ngettext_with_context', ....., 4);
(Naturally, you need to add the function and the priority instead of the .....)
Those functions will get the strings and the domain, and you can use those to do functions like:
function gettext_filter($translation, $orig, $domain) {
if ($domain == 'plugin_domain') {
if ($orig == 'some text') {
return "some translation";
}
}
return $translation;
}
This solution uses wordpress's automatic loaders to override the plugin and doesn't need additional programming logic, instead it lets the CMS do the override.
Let's say you want to translate a plugin called my-plugin. A properly built plugin would have two translated files in the directory wp-content/languages/plugins/ called my-plugin-fr_FR.po and my-plugin-fr_FR.mo. (The locale fr_FR is just my example for French translation, it works respectively for other language translations).
If your plugin has this structure, the steps below will override the translations, if not you can try and see anyway:
Copy the .po and .mo files mentioned above into the directory wp-content/languages/my-plugin. If the directory doesn't exist, create it.
Edit the translation files as you wish and save them.

Resources