We would like to add a custom function of a shortcode in wp_include/functions.php.
This is the function:
function url_id() {
$apiUrl = 'https:exampleurl.api.com/exemple123';
$response = wp_remote_get($apiUrl);
return wp_remote_retrieve_body($response);
}
add_shortcode('session_id', 'url_id');
But we were getting this error:
There has been a critical error on this website.
Learn more about troubleshooting WordPress.
After reading some more troubleshooting documentation we added these two lines in wp-config:
define( 'WP_DEBUG', true );
define( 'WP_CACHE', true );
And after that we are getting this error:
Fatal error: Uncaught Error: Call to undefined function add_shortcode() in /home/c1624672c/public_html/woo/wp-includes/functions.php:18 Stack trace: #0 /home/c1624672c/public_html/woo/wp-settings.php(111): require() #1 /home/c1624672c/public_html/woo/wp-config.php(104): require_once('/home/c1624672c...') #2 /home/c1624672c/public_html/woo/wp-load.php(50): require_once('/home/c1624672c...') #3 /home/c1624672c/public_html/woo/wp-blog-header.php(13): require_once('/home/c1624672c...') #4 /home/c1624672c/public_html/woo/index.php(17): require('/home/c1624672c...') #5 {main} thrown in /home/c1624672c/public_html/woo/wp-includes/functions.php on line 18
There has been a critical error on this website. Learn more about troubleshooting WordPress.
If you want to add custom shortcodes to your website, that can be done via a custom plugin, or in your theme (as I suspect you're trying to do).
Instead of editing wp-includes/functions.php, add your code to wp-content/themes/<name-of-your-theme>/functions.php.
You should never edit the core files of WordPress, which includes all files in /wp-admin and /wp-includes. When you upgrade WordPress in the future, these files will be overwritten, and you'll lose any changes you've made.
The error message occurs because you're attempting to use the add_shortcode() function before WordPress has fully loaded, and defined all available functions.
Please change the shortcode parameter session_id because session_id predefined function in wordpress see the blow or your code
add_shortcode('session_id', 'url_id');
But right code will be work when you change the session_id.
Related
I'm attempting to move my wordpress sites over to Google Cloud, I've moved two successfully with revslider - the third had a bloated database and I needed to trim some fat to get it in.
I'm now getting the following error when trying to view a slide from any of the front-end pages.
Fatal error: Uncaught Error: Call to a member function get_slider_language() on null in /var/www/rr/wp-content/plugins/revslider/includes/output.class.php:675 Stack trace: #0 /var/www/rr/wp-content/plugins/revslider/includes/output.class.php(634): RevSliderOutput->add_slider_base() #1 /var/www/rr/wp-content/plugins/revslider/revslider.php(96): RevSliderOutput->add_slider_to_stage('new_home', '', '', '', '') #2 /var/www/rr/wp-includes/shortcodes.php(343): rev_slider_shortcode(Array, '', 'rev_slider') #3 [internal function]: do_shortcode_tag(Array) #4 /var/www/rr/wp-includes/shortcodes.php(218): preg_replace_callback('/\\[(\\[?)(rev_sl...', 'do_shortcode_ta...', '[rev_slider sli...') #5 /var/www/rr/wp-content/plugins/js_composer/include/helpers/helpers.php(240): do_shortcode('[rev_slider sli...') #6 /var/www/rr/wp-content/plugins/js_composer/include/templates/shortcodes/vc_column.php(94): wpb_js_remove_wpautop('[rev_slider sli...') #7 /var/www/rr/wp-content/plugins/js_composer/include/classes/shortcodes/core/class-wpbakerys in /var/www/rr/wp-content/plugins/revslider/includes/output.class.php on line 675
There has been a critical error on your website.
Learn more about debugging in WordPress.
I've attempted the following steps to no avail.
Switched theme.
Disabled all plugins.
Deleted all slides and attempted with a freshly made slide.
Updated all plugins, including deleting Slider Revolution entirely and reinstalling the latest version.
I removed some language packs from the VM in an attempt to claw back some space and thought that might've been it - but reinstalling with apt-get -y install "check-language-support -l en" doesn't seem to have helped.
Updated to PHP 7.4.8
I'm using a Google Cloud VM with OpenLiteSpeed, and MySQL+Redis. I changed the only relevant option I could see in Slider Revolution Global Config from using default as the language to en. The slide works as expected in preview mode within the admin panel.
This is caused by what appears to be a bug in the Revolution Slider plugin, at least as of v6.2.21 (and it doesn't appear to have been fixed since). In revslider/includes/output.class.php:678 it calls
$lang = $rs_wmpl->get_slider_language($this->slider);
but if the WPML plugin is not installed, then $rs_wmpl is null.
Until they fix it you can hack the plugin to check for null, e.g.,
//set slider language
if($this->get_preview_mode() == false && !empty($rs_wmpl)){
$lang = $rs_wmpl->get_slider_language($this->slider);
$this->change_language($lang);
}
Edit: This bug doesn't reproduce under ordinary page loads, but does reproduce when loading the site under WP-CLI, e.g., via wp profile. Suspect it has something to do with the way global variables are handled in that case.
When trying to preview a new theme for my blog, this appears...
The site is experiencing technical difficulties. Please check your site admin email inbox for instructions.
I didn't receive an email though. I've tried deactivating all of my plugins and this didn't work. Any ideas? I'm new to this.
You should detect the error before do anything.
Turn on WP debug mode and you will see what error do you have:
In wp-config.php:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', true );
More information about WP debugging: https://wordpress.org/support/article/debugging-in-wordpress/
Website/Admin is displaying "The site is experiencing technical difficulties. Please check your site admin email inbox for instructions."
This was my solution for our website. I only fixed enough issues for the admin page to start working again.
This was all done after I fixed my initial site issues that crashed the entire site, addressed in this question: https://stackoverflow.com/a/65357857/14850513
After I made those fixes, the admin page was still giving the previously stated error message that you described, so here is how I fixed it. The following bullets are all of the error messages I faced and how I fixed them. This may not solve everyone's issues but these were the specific ones I faced.
Go to the public.html/wp-config.php
go to the following line and change debugging to true
define('WP_DEBUG', false); #Change to true
This will show all of the errors that are causing the site to have issues. You must address them until it begins to function again. You will know because it will start working the next time you refresh.
ERROR 1: Array and string offset access syntax with curly braces is deprecated
Follow to each line listed and change '{}' to '[]'
ERROR 2: Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home1/seth/public_html/wp-content/plugins/revslider/includes/operations.class.php on line 2364
I open the php file at the problem line, I changed the term [continue;] to [break;]
ERROR 3: "Deprecated: Function create_function() is deprecated in xxx.php" on 258 line
Changed
public static function registerWidget($widgetName){
add_action('widgets_init', create_function('', 'return register_widget("'.$widgetName.'");'));
}
to
public static function registerWidget($widgetName){
add_action('widgets_init', function () use ($widgetName) {
return register_widget($widgetName);
});
}
ERROR 4: Fatal error: Uncaught Error: [] operator not supported for strings
the failing line was:
self::$arrMetaBoxes[] = $box;
The fix is to add the following line right before it
self::$arrMetaBoxes = [];
My admin page started working at this point, but you may need to continue fixing errors until it begins to function properly again.
I just wanted to add this as a SOLVED question because it took me a while to figure it out and there was no documentation on this.
Notice: Trying to get property of non-object in /srv/www/wordpress-default/wp-includes/post.php on line 3555
Trying to wp_update_post() via plugin settings page and was getting this notice.
The solution was to add this line before calling the wp function: $wp_rewrite = new wp_rewrite;
The solution was to add this line before calling the WP function: $wp_rewrite = new wp_rewrite;
I am getting the white screen of death with my Wordpress site and I have narrowed it down to a .php file in my Woocommerce includes file. The error is as follows:
PHP Fatal error: Call to a member function get_formatted_name() on a non-object in /home2/hatchchi/public_html/wp-content/plugins/woocommerce/includes/wc-deprecated-functions.php on line 63
Here is what line 63 includes:
function woocommerce_get_formatted_product_name( $product ) {
_deprecated_function( __FUNCTION__, '2.1', 'WC_Product::get_formatted_name()' );
return $product->get_formatted_name();
}
I tried removing the file, the line of code and replacing the Woocommerce plugin manually via FTP but nothing fixed it.
What would be causing this sort of error? What is the solution?
By best to narrow these sort of things down is to try deactivating all other plugins and trying a default WordPress theme to see if that solves your issue.
I created a code which generates content and I want to populate Wordpress's database with it. I am using wp_insert_post and add_post_meta functions but every time I load which triggers the script I get this error:
Fatal error: Call to undefined function add_action() in \www\scriptmafia\wp-includes\post.php on line 153
To my mind it due to some missing includes. I have included post.php which it mentioned as required include for wp_insert_post function.
I know this is pretty common among newbies in WordPress. However, any solution I have tried have not worked for me.
require_once( ABSPATH . '/wp-load.php'); should solve it :)