I'm facing the following error in my WordPress Site
[03-Sep-2017 10:12:36 UTC] PHP Warning: simplexml_load_file(): in /home/syriacar/public_html/syria-cart.com/wp-content/plugins/polylang/modules/wpml/wpml-config.php on line 53
and here is the file error content
foreach ( $plugins as $plugin ) {
if ( file_exists( $file = WP_PLUGIN_DIR . '/' . dirname( $plugin ) . '/wpml-config.xml' ) && false !== $xml = simplexml_load_file( $file ) ) {
$this->xmls[ dirname( $plugin ) ] = $xml;
}
}
It might be due to malformed wpml-config.xml file.
For example, on this support WordPress forum page, you can find a similar issue and the cause was missing </key> closing tag before </admin-texts>.
UPDATE:
In your comments, you also mention yith-woocommerce-affiliates warning, so another possibility is that the YITH WooCommerce Affiliates plugin doesn't have the wpml-config.xml or is empty.
The polylang documentation about wpml-config.xml mentions the following:
Developpers must place the wpml-config.xml file in the root directory
of the plugin or theme.
Related
I wrote a PHP script to process files sent to it via POST.
On the frontend js script, I create a Formdata object, and append images to it...like:
formdata.append('image0', image0);
formdata.append('image1', image1);
etc
This is my PHP code, the code is in the wordpress root directory
<?php
header("Access-Control-Allow-Origin: *");
require_once('wp-admin/includes/image.php' );
require_once('wp-admin/includes/file.php' );
require_once('wp-admin/includes/media.php' );
$id_array = array();
$c = 0;
foreach ($_FILES as $file) {
$id_array[] = media_handle_upload('image' . $c, 0);
$c++;
}
echo implode(',', $id_array);
However when I run this code, I get the following error:
Fatal error: Call to undefined function __() in /home/website/public_html/wp-admin/includes/file.php on line 16
Am i missing to include additional files in the script? I used the documentation on wordpress and it said:
These files need to be included as dependencies when on the front end.
require_once( ABSPATH . 'wp-admin/includes/image.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/media.php' );
I would appreciate any help!
In order to use the native Wordpress functions, such as __() wp-config.php needs to be included additionally.
Adding wp-config.php solved the issue
I'm also facing same issue.
Adding this in functions.php will fix the error.
Some time it will show as "http error"
add_filter( 'wp_image_editors', 'raj_change_graphic_library' );
function raj_change_graphic_library($array) {
return array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
}
I need to check if a folder exist in an other folder. If not, then a new folder will be created. I can´t seem to get it to work. See code below.
Note: I use TCPDF.
// Create filename
$filnamnet = $id.'_'.$datum.'_'.$fornamn.'_'.$efternamn.'.pdf';
// Folder in iup_pdf
$mapparna_dir = 'iup_pdf/'.$id.'_'.$fornamn.'_'.$efternamn.'_'.$personnummer.'';
// Check if folder exist in iup_pdf
if(!is_dir($mapparna_dir) ) {
mkdir('iup_pdf/'.$id.'_'.$fornamn.'_'.$efternamn.'_'.$personnummer);
}
$pdf->Output(__DIR__ . '/iup_pdf/'.$id.'_'.$fornamn.'_'.$efternamn.'_'.$personnummer.'/'.$filnamnet.'', 'F');
The error states: TCPDF ERROR: Unable to create output file
You might find this of use.
function RecursiveMkdir( $path=NULL, $perm=0644 ) {
if( !file_exists( $path ) ) {
RecursiveMkdir( dirname( $path ) );
mkdir( $path, $perm, TRUE );
clearstatcache();
}
}
I tend to find that the fullpath works best - ie:$_SERVER['DOCUMENT_ROOT'].'/path/elements/to/folder' etc rather than the relative path. Also, is_dir() determines if a file is a directory - perhaps use file_exists as in the function.
if( !file_exists( $mapparna_dir ) ) RecursiveMKdir( $mapparna_dir );
Months ago, I have placed a 301 redirect rule in my .htaccess file to redirect all the www request to a non-www request.
The problem is two days ago, when I tried to access my example.net site using www.example.net I get the following warnings in the page and website is not loaded.
http://i.stack.imgur.com/nXBMF.png
Here are the corresponding lines:
1. Plugin.php Line 647 = if ( strpos( $file, $realdir ) === 0 ){
Full function:
/**
* Gets the basename of a plugin.
*
* This method extracts the name of a plugin from its filename.
*
* #since 1.5.0
*
* #param string $file The filename of plugin.
* #return string The name of a plugin.
*/
function plugin_basename( $file ) {
global $wp_plugin_paths;
foreach ( $wp_plugin_paths as $dir => $realdir ) {
if ( strpos( $file, $realdir ) === 0 ) { /** LINE 646 */
$file = $dir . substr( $file, strlen( $realdir ) );
}
}
$file = wp_normalize_path( $file );
$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
$file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir
$file = trim($file, '/');
return $file;
}
2. Pluggable.php Line 1178 = header("Location: $location", true, $status);
Full file: http://pastebin.com/0zMJZxV0
I use WordPress only to write some articles. My PHP knowledge is very basic and limited only to locate errors.
Please help me figure out the problem with this. As I have read from the Codex FAQ, they say that empty strings may be a culprit for the pluggable.php error. But I have no idea how to locate it and I have attached the file for your reference.
Please provide your suggestions to avoid this error in the future. Thanks in advance.
3. EDIT - wp setting file: (the error line - include_once( $plugin ); )
// Load active plugins.
foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
wp_register_plugin_realpath( $plugin );
include_once( $plugin );
}
unset( $plugin );
The issue with the header information has been discussed in here: Cannot modify header information error in Wordpress. Could you give this a try and see whether this solves this part of your problem?.
On the other issue:
try var_dump ($file) (for instance -- or echo $file ) to see what they actually contain.
Check your configuration path of plugins :
var_dump($wp_plugin_paths);
You've got an error because $realdir is empty.
I'm making a Wordpress theme, basically for portfolios.
Making plugins into the theme is bad, since changing themes can become a problem for the user and yourself if you do so. So I'm cooking up some script, that takes a plugins folder I made in my theme, which has the plugins that I would have built into the theme, but I'm making them install themselves when you select my theme. So these plugins will be updatable through the dashboard, and auto installed (if not already installed), into the site. Good idea no? (I got it from a forums post, but I dont think its been done as far as I know).
So I have a plugins folder in my theme, which has the plugins I want to auto install. I want to copy the plugins(single files or directories) into the wp-content/plugins folder and then install/activate them.
The problem is when I try to copy, it gives an error
Warning: copy(http://127.0.0.1/inside-theme/wordpress/wp-content/plugins): failed to open stream: HTTP wrapper does not support writeable connections in C:\**path-to-www-**\www\inside-theme\wordpress\wp-content\themes\Inside Theme\header.php on line 105
If you're wondering about why it's in header.php, I'm just doing this for testing purposes to see if it copies. I will put it in a hook after.
Here is my code I'm using to copy the plugins,
$dir = get_template_directory() . '/plugins/'; // the plugins folder in the theme
$plugins_in_theme = scandir($dir); // $dir's contents
$plugins_dir = plugins_url(); // url to the wp-content/plugins/
print_r($plugins_in_theme); // just to check the output, not important
foreach ($plugins_in_theme as $plugin) {
if ($plugin != '.' || '..') {
if (!file_exists($plugins_dir . $plugin)) {
if (is_dir($plugin)) {
recurse_copy($dir . $plugin, $plugins_dir);
} else {
copy($dir . $plugin, $plugins_dir);
}
}
}
}
recurse_copy() is a function I picked up off another stackoverflow question for copying directories since copy() only copies files, not folders. Also note that, it gives multiple errors, with the functions.php of my theme mentioned in most errors, which is where I put the recursive_copy() function. (Is that ok? It's my first theme..)
function recurse_copy($src,$dst) { //for copying directories
$dir = opendir($src);
#mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
recurse_copy($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}
So how can I remove this error and get it to work?
Extra details,
I'm using windows xp and I'm using the 'handcrafted wp' parent theme, I AM RUNNING THIS LOCALLY. (on local host)
Hope I was clear.
You are using $plugins_dir = plugins_url(); in the code which returns http://yoursite/wp-content/plugins/ However, copy function works with directories not URLs, so it's better to use, ABSPATH, dirname( __FILE__ ) . '/blablabla.php' and other functions returning directories not URLs. Click here to learn more about PHP copy function
It may be a silly question, but I cant understand how I can access every function (from functions.php for example) in WordPress without any include or require calls, I know if I want to create a new script I can simply require wp-load.php from that particular script, just dont understand why this is isn't needed in other template files.
WordPress does that automatically. Whenever there is a functions.php file for the active theme, WP will load it for you. The magic happens in wp-settings.php, specifically among the following lines:
if ( ! defined( 'WP_INSTALLING' ) || 'wp-activate.php' === $pagenow ) {
if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/functions.php' ) )
include( STYLESHEETPATH . '/functions.php' );
if ( file_exists( TEMPLATEPATH . '/functions.php' ) )
include( TEMPLATEPATH . '/functions.php' );
}