Error in WordPress with plugin reactpress - php

I'm using WordPress version 5.7.2 and when I upgrade it to php version 7.4.19 I get these errors:
Failed opening 'default' for inclusion (include_path='.:/usr/lib/php7.4') wp-includes/template-loader.php on line 106
Warning: include(default): failed to open stream: No such file or directory in /homepages/1/d229455270/htdocs/clickandbuilds/WordPress/DaseCMS/wp-includes/template-loader.php on line 106
This happens when I activate the plugin reactpress. This is the piece of code where the error occurs:
/**
* Filters the path of the current template before including it.
*
* #since 3.0.0
*
* #param string $template The path of the template to include.
*/
$template = apply_filters( 'template_include', $template );
if ( $template ) {
include $template; //Error in this line
} elseif ( current_user_can( 'switch_themes' ) ) {
$theme = wp_get_theme();
if ( $theme->errors() ) {
wp_die( $theme->errors() );
}
Why is this happening? How can I fix it? I see that is compatible with my WordPress version...
And with my php version...
Thank you in advance

Why is this happening?
Because there's a mistake in the Reactpress_Public::repr_change_page_template() method (see line 99 in wp-content/plugins/reactpress/public/class-reactpress-public.php) which is hooked onto template_include.
The author should check if the value of the _wp_page_template metadata (which stores the path of a custom page template) is not default (which is the default value) and only if so, then should the $template value be set to the metadata value.
And if one doesn't do that check, then we'd end up with include 'default' which then emits the error/warning in question ("Failed opening 'default' for inclusion").
How can I fix it?
Please contact the plugin support and ask them to fix the issue ASAP, but for the time being, you may just change the conditional here to: (* change the entire "if")
if (!empty($meta['_wp_page_template'][0]) && $meta['_wp_page_template'][0] != $template && // wrapped
'default' !== $meta['_wp_page_template'][0] // check if the value is NOT "default"
) {
$template = $meta['_wp_page_template'][0];
}
Yes, you shouldn't modify core plugin files; but this is a special case, because the plugin needs a fix, which hopefully will come in the plugin's next release.
Alternate solution without modifying the plugin files
.. is by overriding the template using the same hook:
// Add to the theme functions.php file:
add_filter( 'template_include', 'my_fix_template_include', 100 );
function my_fix_template_include( $template ) {
if ( 'default' === $template && is_page() ) { // * the plugin uses is_page()
$template = get_page_template();
}
return $template;
}

Related

WordPress Load .json Script Translations from Child Theme

I'm NOT a WordPress theme author! I want to load .json translations that comes from related admin .js string files inside a WordPress theme. I succeed to load translations by the following function:.
add_action( 'admin_enqueue_scripts', 'kadence_child_js_translations' );
function kadence_child_js_translations() {
if ( get_locale() == 'fa_IR' ) {
$handle = 'my-kadence-customizer-js';
$js_uri = get_template_directory_uri() . '/inc/dashboard/react/src/customizer.js';
$domain = 'kadence';
$json_path = get_stylesheet_directory() . '/languages';
wp_register_script( $handle, $js_uri );
wp_enqueue_script( $handle );
wp_set_script_translations( $handle, $domain, $json_path );
}
}
When I refresh the admin panel, Translations are loaded But I get this error in console:
Uncaught SyntaxError: import declarations may only appear at top level of a module ( customizer.js:6 )
I tried to use the load_script_textdomain() function instead of wp_set_script_translations() but not only none of translations are loaded but also I have this error again!
How can I load .json scripts of a WordPress Theme from a child theme correctly?

WordPress which is the right way to enqueue script and style in a php class? [duplicate]

So I'm busy in Wordpress. I have a theme for the site and all. It's all working fine. Then I want to activate the new theme. BENG BENG, white screen of death. I debugged and this is the error:
Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or init hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in C:\xampp\htdocs\wp-includes\functions.php on line 2944
Line 2944 is just the line that throws an error. I already checked that.
Anyone ever experienced and solved this?
EDIT:
Referencing lines:
function _doing_it_wrong( $function, $message, $version ) {
do_action( 'doing_it_wrong_run', $function, $message, $version );
// Allow plugin to filter the output error trigger
if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true ) ) {
$version = is_null( $version ) ? '' : sprintf( __( '(This message was added in version %s.)' ), $version );
$message .= ' ' . __( 'Please see Debugging in WordPress for more information.' );
trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) );
}
}
The error have nothing related to the code you've added added. It is not a Wordpress core related issue, but an issue with your theme or a plugin
What the error means is that some script is enqueued way too early, ie, wp_enqueue_script() is hooked to a wrong hook that runs before wp_enqueue_scripts, admin_enqueue_scripts, or init.
Unfortunately this error in Wordpress is a bit fague as it doesn't tell you exactly where the problem is, just that wp_enqueue_script is wrongly called.
You'll need to look for all instances in your theme and plugins for wp_enqueue_script and check that it is properly hooked
EDIT
From your comments, you have found three instances of wp_enqueue_script. You now need to see how it is hooked. It should look something like this
function some_function_name(){
wp_enqueue_script(ALL THE SCRIPT DETAILS IN HERE);
}
add_action( 'THIS IS THE HOOK THAT IS IMPORTANT', 'some_function_name');
THIS IS THE WRONG HOOK USED is what you must check, as this is the wrong hook. This must be wp_enqueue_scripts or admin_enqueue_scripts, depending on if the script is meant for front end or back end
In some of your plugins or your theme, a script may be included like this :
wp_enqueue_script( string $handle, string $src = '', array $deps = array(), string|bool|null $ver = false, bool $in_footer = false )
try to change it using this code:
<?php
function wpb_adding_scripts() {
wp_register_script('my_amazing_script', plugins_url('amazing_script.js', __FILE__), array('jquery'),'1.1', true);
wp_enqueue_script('my_amazing_script');
}
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );
?>

Stylesheet is getting removed/deregistered automatically - WordPress

I've put some custom code in my active child theme's functions.php. I'm trying to enqueue some style on a admin page. However, a style enqueued in admin_enqueue_scripts hook gets automatically removed and after debugging I found that its not present in the very next hook i.e. admin_print_styles.
Here's some code in active child theme's functions.php which I used for debugging purposes:
function debug_enqueue_admin_scripts() {
wp_enqueue_style( 'gforms_datepicker_css', GFCommon::get_base_url() . "/css/datepicker{$min}.css", null, GFCommon::$version );
if( wp_style_is( 'gforms_datepicker_css' ) {
// NOTE: This runs and I am able to view the following log
error_log( __FUNCTION__ . ': datepicker_css is enqueued.' );
}
}
add_action( 'admin_enqueue_scripts', 'debug_enqueue_admin_scripts', 11 );
function check_if_still_enqueued() {
if( wp_style_is( 'gforms_datepicker_css', 'registered' ) ) {
error_log( __FUNCTION__ . ' datepicker_css registered.');
} else {
// NOTE: It gets in this else block and following output is logged
error_log( __FUNCTION__ . ' datepicker_css **NOT** registered.');
}
}
add_action( 'admin_print_styles', 'check_if_still_enqueued' );
I'm not deregistering the gforms_datepicker_css anywhere, but its getting removed maybe due to some plugin.
While debugging, I've gone further and inspected if it was deregistered by putting extra line in WordPress core class method WP_Dependencies::remove() located here as following.
public function remove( $handles ) {
// NOTE: Check if deregistered
error_log( __METHOD__ . ' ' . var_export( $handles, true ) );
foreach ( (array) $handles as $handle )
unset($this->registered[$handle]);
}
But I'm unable to see log output with gforms_datepicker_css in it from this method.
I'm unsure why the style is getting removed from enqueue list. Can anybody please help me debugging this behaviour and find the solution?
The scripts and styles were not loading on admin pages because the No-Conflict Mode setting of Gravity Forms plugin was turned ON. As the setting is designed to do so:
As described in Gravity Forms documentation:
To temporarily resolve the issue, go to Forms > Settings and enable No
Conflict mode. This should stop third party scripts from writing to
Gravity Forms administration pages and allow you to do the things you
need.
The issue resolved after turning OFF the No-Conflict Mode.

Comments Not Posting on Wordpress - Blank Page

I am working on a theme (http://lillykauffman.com/wordpress/2017/06/26/hello-world/), which I've done before, but if you try to post a comment, you will be redirected to a blank page. This also happens on the other WP themes such as twentysixteen. Here is the code I have on wp-comments-post.php:
<?php
/**
* Handles Comment Post to WordPress and prevents duplicate comment posting.
*
* #package WordPress
*/
if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {
$protocol = $_SERVER['SERVER_PROTOCOL'];
if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) {
$protocol = 'HTTP/1.0';
}
header('Allow: POST');
header("$protocol 405 Method Not Allowed");
header('Content-Type: text/plain');
exit;
}
/** Sets up the WordPress Environment. */
require( dirname(__FILE__) . '/wp-load.php' );
nocache_headers();
$comment = wp_handle_comment_submission( wp_unslash( $_POST ) );
if ( is_wp_error( $comment ) ) {
$data = intval( $comment->get_error_data() );
if ( ! empty( $data ) ) {
wp_die( '<p>' . $comment->get_error_message() . '</p>', __( 'Comment Submission Failure' ), array( 'response' => $data, 'back_link' => true ) );
} else {
exit;
}
}
$user = wp_get_current_user();
/**
* Perform other actions when comment cookies are set.
*
* #since 3.4.0
*
* #param WP_Comment $comment Comment object.
* #param WP_User $user User object. The user may not exist.
*/
do_action( 'set_comment_cookies', $comment, $user );
$location = empty( $_POST['redirect_to'] ) ? get_comment_link( $comment ) :
$_POST['redirect_to'] . '#comment-' . $comment->comment_ID;
/**
* Filters the location URI to send the commenter after posting.
*
* #since 2.0.5
*
* #param string $location The 'redirect_to' URI sent via $_POST.
* #param WP_Comment $comment Comment object.
*/
$location = apply_filters( 'comment_post_redirect', $location, $comment );
wp_safe_redirect( $location );
exit;
I don't know why this isn't working since it's straight from WP, and other people online had this error because their file was blank, which is not my case. And all of this code looks to be in order. My MySQL version is 5.7 so that shouldn't be the issue, but at this point, I don't even know what's wrong anymore - the code, the installation, my hosting. Any help would be greatly appreciated.
Update: My host advertises full blog, comment and discussion board functionality but I contacted them and they were like, "not really." Apparently they don't support comments or email sending. What a waste. Thanks for everyone's help!
When you look your problem page with inspect manager, you can see that your problem is a 410 code error.
410 Gone
Indicates that the resource requested is no longer available at the server and will not be available again.
This error can occur in several ways.
Here it's the list of somes checkpoint to help you to find the problem:
1. Enable debugging in wp-config.php
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
// Enable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', true );
#ini_set( 'display_errors', 1 );
And test to know if your error appear. You'll be able to fix it quickly.
2. Reset permalink
Don't know why but, sometimes, Wordpress have some weird error du to a old permalink.
I suggest you to
Going to Settings -> Permalinks
Switch permalink setting,
Save,
Replace it to your current configuration,
save it again.
3. Deactivating all plugins.
if its works, activate plugin one by one to be able to detect which one create this error.
4. Refresh your .htaccess
place the basic wordpress .htaccess. Sometimes, some plugins change rules from your .htaccess and provoke many redirections error.
5. Switch your theme for a default theme without modification
It help you to know if a custom rules in your theme create this error.
6. Re-upload the wp-admin and wp-includes from fresh install
7. Reset folders write/read permissions
you can read Changing File permissions in Wordpress to help you to know what you should change and what it should do.
8. ULTIMATELY, Create a fresh install of Wordpress

Wordpress PHP Fatal Error with Openshift

When I try to access the plugins or themes section of my wordpress site from the admin panel I am presented with a blank screen. When I run the logs I get the following error:
Navigating to wp-admin/plugins.php:
PHP Fatal error: Call to undefined function wp_json_encode() in /var/lib/openshift/{userID}/app-root/data/current/wp-includes/update.php on line 277
Navigating to wp-admin/themes.php:
PHP Fatal error: Call to undefined function wp_json_encode() in /var/lib/openshift/{userID}/app-root/data/current/wp-includes/update.php on line 440
Solutions online indicated that I should re-add the function, or re-install Wordpress. Without access to the core files, I downloaded a local repository of the application (but noticed it did not contain any of the plugins or themes I had uploaded via the admin interface).
I extracted a plugin and theme (placing them in the respective directories) then pushed the changes to production in the hopes that it would extract and re-install an updated version of wordpress. I then restarted the app.
The error still persists and I can not validate if the plugin or theme I uploaded were installed. Is there a way to refresh or reinstall a wordpress instance on Openshift?
I'm wondering how I can fix this issue without creating a new gear and migrating my data via the database. Note: Front end is working fine.
Version of Wordpress: 4.1.1
I ended up connecting to the app via SFTP and modified the file the following directly
/var/lib/openshift/{userID}/app-root/data/current/wp-includes/functions.php
and added the following function:
function wp_json_encode( $data, $options = 0, $depth = 512 ) {
/*
* json_encode() has had extra params added over the years.
* $options was added in 5.3, and $depth in 5.5.
* We need to make sure we call it with the correct arguments.
*/
if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) {
$args = array( $data, $options, $depth );
} elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
$args = array( $data, $options );
} else {
$args = array( $data );
}
$json = call_user_func_array( 'json_encode', $args );
// If json_encode() was successful, no need to do more sanity checking.
// ... unless we're in an old version of PHP, and json_encode() returned
// a string containing 'null'. Then we need to do more sanity checking.
if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) ) {
return $json;
}
try {
$args[0] = _wp_json_sanity_check( $data, $depth );
} catch ( Exception $e ) {
return false;
}
return call_user_func_array( 'json_encode', $args );
}
Ref: https://wordpress.org/support/topic/fatal-error-call-to-undefined-function-wp_json_encode-in

Categories