error in wordpress theme (formatting.php) - php

when i open my web site in homepage i see only header and this error :
Catchable fatal error: Object of class WP_Error could not be converted
to string in /home/mahooorc/public_html/wp-includes/formatting.php on
line 3275
this problem is just on my homepage and other links are ok. i disabled all plugins but it doesn't answer! line 3275 is
$url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%#$\|*\'()\\x80-\\xff]|i', '', $url);
function esc_url( $url, $protocols = null, $_context = 'display' ) {
$original_url = $url;
if ( '' == $url )
return $url;
$url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%#$\|*\'()\\x80-\\xff]|i', '', $url);

This is usually caused by missing taxonomies that are used in a menu, but do not exist anymore.
You have a couple of solutions to try, but do not forget to always create a backup of your files and database before you try any of them.
Method 1
Remove the taxonomy items from the menu
Delete all session data, cookies etc...
Method 2
Find the table wp_term_taxonomy in the database
Find a record called nav_menu
Delete that record
Method 3
Find the table wp_terms in the database
Look at the different terms and decide which ones you do not need
Delete the terms you do not need anymore
When none of these solutions, or a combination of the solutions work, please let me know. You have still a couple more options, but those are a lot more destructive.

Instead of receiving the expected $url as as string, the esc_url() function receive a WP_Error object.
Try to add this code before the faulty line to learn more about the error:
echo $url->get_error_message();
It will display the error message which can help you understand where it comes from.
Remember to remove this added line after that.
People having the same issue are often talking about encoding problems. Are you using special encoding ?

Related

First query string parameter being ignored by Laravel or Wordpress/WooCommerce?

Tech stack
PHP 7.4.2
Laravel 7
Background
I'm attempting to pull in the active products from our WooCommerce site, one page at a time. These then have required data pulled out and formatted into JSON, and returned to the user (in this case a marketing platform making an API call).
Issue
Whichever query parameter is first in my list is getting either removed before it leaves my system, or ignored by the WC/WP REST API.
Code making the call
function getProducts($page = 1, $per_page = 100, $status = 'publish') {
$query = array(
// 't' => 1, // For testing first parameter bug
'page' => $page,
'per_page' => $per_page,
'status' => $status,
);
$string = http_build_query($query, null, '&', PHP_QUERY_RFC3986);
$url = $this->finalUrl . '/wp-json/wc/v3/products?' . $string;
$json = file_get_contents($url);
return json_decode($json);
}
If I dump $url I get:
https://user:pass#domain.com/wp-json/wc/v3/products?page=5&per_page=100&status=publish
This seems valid as far as I can tell. Putting it into Postman, I get the 5th page of 100 records, as expected. However, if I run it in my system, I get the first page every time.
Then if I swap page and per_page round, I will get the page I want but only 10 records which is the default, not the 100 I ask for. Then of course if I put status first, I get inactive/archived products too.
Additionally if I change the URL to a Pipedream URL, I can see all 3 parameters clearly being listed.
Lastly, I tested by adding the t=1 parameter in first as a dummy parameter, and then the rest of the parameters all work fine, and I would get my 5th page of 100 records no problem.
If anyone can assist or point me in the right direction that will be much appreciated.
Cheers,
Tom
Turns out in this case, there was a stray letter in a uri rewrite rule on the wordpress site, causing the name of the first parameter to be prepended with said letter.
This was found within try_files $uri /index.php?uri=$uri&i$args; rule. Note the i before the $args being appended.
In my above example, page would be renamed ipage before it reache the API.
Removed and it now works.

osCommerce 2.3 - Unable to determine the page link

I have a problem in osCommerce 2.3
PHP/5.6.31
I have tried to setup on my localhost but it will return an error message.
So how can I fix this problem
Is there any problem in the configuration?
Error!
Unable to determine the page link!
Function used:
tep_href_link('', '', 'NONSSL')
If you look in catalog/includes/functions/html_output.php, you'll see the function definition for tep_href_link. It's
function tep_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true) {
You have provided a blank first parameter. If you look at some examples in the catalog directory, you'll see they provide a first parameter, generally drawn from a define in includes/filenames.php.
i have faced same issue and on debug found this issue comes due to tep_href_link(basename($PHP_SELF) $PHP_SELF is not working properly return blank and got fixed just placing
$PHP_SELF=$_SERVER['PHP_SELF'];
define('CONFIGURE_STATUS_COMPLETED', 1);
at the bottom of includes/configure.php and it worked.

Wordpress Categories not showing up on First Post of Front Page and on individual posts

I am migrating our wordpress host, and I've attempted the migration using both Wordpress Duplicator and Wordpress All-In-One Migration plug-ins. I am seeing that on the new host, the first post on the main page does not have categories, nor do categories show up when I drill in on them. I do know that they have categories because if I click on a category tab, the post is listed in there.
When I turn php error checking on, I see this error:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'add_to_byline' not found or invalid function name in /var/www/html/wp-includes/class-wp-hook.php on line 298
I am using a theme called Thesis, which has a function add_to_byline() in
wp-content/themes/thesis_185/custom/custom-functions.php like this:
function add_to_byline() { ?>
</p><p class = "dot_separator">ยท</p><p class="headline_meta"><?php echo __('', 'thesis') . ' <span>' . get_the_category_list(', ') . '</span>'; ?>
<?php }
add_action('thesis_hook_byline_item', 'add_to_byline', '99');
So add_to_byline() does exist, but somehow the new server host is unable to find it, and as a result isn't displaying the categories.
I've diffed the two versions and they are identical minus some white space differences that resulted from debugging. I've also checked file permissions on both old and new server and they are identical. Does anyone have any idea on how I can go about debugging this further?

Why does WordPress add a duplicate numeric slug upon post/page view?

This is my first post here, so I apologize in advance for any mishaps.
I've been searching for hours trying to figure this one out, but I simply can't seem to understand why this is happening.
The site I'm setting up is a child site (not in a multisite sense, but as a separate site/domain with the same branding). Some of the posts on my site will originate from the parent/main site (but will be made as new posts through copy-paste), and I want the original article ID as part of the permalinks.
E.g. http://www.example.com/hello-world/12345/, where 12345 is the article ID of the article on the parent/main site.
To accomplish this, I've added a custom field to my posts where I can add the article ID of the original article with external_article_id as Field Name. I've then tried to manipulate the permalinks with the following code:
add_filter('post_link', 'append_custom_permalink', 10, 2);
function append_custom_permalink($url, $post) {
$newurl = $url;
if ($post->post_type == 'post') {
$custom = get_post_custom_values('external_article_id', $post->ID);
if (!empty($custom))
$newurl = $url . $custom[0] . '/';
}
return $newurl;
}
Whenever I output the permalink to the posts it appears exactly as I want it, both in the editor and on the site. However, when I either click a link or enter the address manually, I get redirected automatically to http://www.example.com/hello-world/12345/12345/. It duplicates the additional numerical slug, and also happens when I replace $custom[0] with a hard-coded numeric value. This applies to all posts, and my permalink structure (in the settings) is set to /%postname%/.
I even tried setting the permalink structure to /%postname%/%ext_article_id%/ and replace %ext_article_id% with $custom[0], but with the exact same outcome. I also tried using the same code on another WordPress site, except this time with pages instead of posts, also with the exact same outcome.
Ideally I would like to use something like add_query_arg($custom[0], '', get_permalink($post->ID));, but omit the question mark that comes along with it.
Could someone please explain to me why this is happening, and how I can circumvent this? Do I need to use some other filter, or how can I approach this?
Thank you in advance!
In order to make this work you also need to make WordPress aware of the rewrite_tag and specify an additional permalink structure via add_permastruct. The following code should do the trick:
function append_custom_permalink( $post_link, $post ) {
if( $post->post_type == 'post' ) {
$custom = get_post_custom_values( 'external_article_id', $post->ID );
if( ! empty($custom) ) {
$post_link = $post_link.$custom[0].'/';
}
}
return $post_link;
}
add_filter('post_link', 'append_custom_permalink', 10, 2);
function sof_30058470_posts_rewrite() {
add_rewrite_tag('%external_article_id%', '([^/]+)', 'external_article_id=');
add_permastruct('external_article_id', '/%year%/%monthnum%/%day%/%postname%/%external_article_id%/', false);
}
add_action('init', 'sof_30058470_posts_rewrite', 10, 0);
Make sure to re-save your permalink structure at Settings->Permalinks once you added the code. You may also need to refresh/clear your browser cache.

In wordpress I am manipulation 404 response. I want to give the response before 404 error is given to google

May be the question in title is not explaining what exactly I want. So I will explain one logic and then ask what problem I am getting from that.
We are using wordpress.
We have 2 categories Option1(Having 64 different values) and Option2(Having 8 different values). We wanted url like ourdomain/Option1/Option2 depending on users location. And data on that url will be specific according to that Option1 and Option2. We dont wanted all this 64*8 actual wordpress pages to be created.
So after searching much on net we had one solution that I implemented one plugin for routing.
IN that code snippet was as follow.
function site_router() {
global $route,$wp_query,$window_title;
error_reporting(E_ALL);
if ( $wp_query->is_404 )
{
$wp_query->is_404 = false;
$cUrl="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$targetUrl="";
switch($cUrl)
{
/* According to condition I had written diffent cases like below.
*/
default :
{
include(get_template_directory() . "/home.php" );
$template =locate_template('pagepath/home.php');
$window_title = 'dynamically it will come';
if ($template) {
load_template($template);
die;
}
}
}
}
}
add_action( 'wp', 'site_router');
So by this my purpose was fulfilled successfully.
But now problem is that google is saying they are getting back a 404 error. I think obviosly it will give as after it gives the error we are doing all template loading and all stuff.
So Can any body guide me how can I do this before that 404 response is given to google.
I posted the question on wordpress stackexchange and got the answer over there. the link is as below.
https://wordpress.stackexchange.com/questions/70345/in-wordpress-i-am-manipulation-404-response-i-want-to-give-the-response-before

Categories