Wordpress functions.php won't save using unset() PHP function - php

I have the unset function in my functions.php theme file and WordPress no longer allows me to save my code in the editor.
I'm using it to unset product tabs on WooCommerce as per this code (found on the WooCoomerce site - https://docs.woocommerce.com/document/editing-product-data-tabs/):
add_filter( 'woocommerce_product_tabs', 'custom_remove_product_tabs', 98 );
function custom_remove_product_tabs( $tabs ) {
unset( $tabs['description'] ); // Remove the description tab
return $tabs;
}
With this code in I get the generic error of: "Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP." when saving my functions.php file. If I comment out the line with the unset function is saves just fine.
It does work on the site if I save this code using FTP etc so I appreciate some may say just do that, but I like to quickly edit things inside WordPress sometimes which is no longer possible so want to understand why it's happening (and WordPress have docs on using this function themselves so it's driving me mad!). I've tried adding a standard php unset function with a generic variable to check it's not WooCommerce related but this doesn't work either.
Am I missing something? If not, is it a server setting? We're using PHP 7.4 on a litespeed server so should be up to date. I'm not sure if there is a way to see a more detailed error log from this issue so if there is any help finding it would be great.
Thanks for any help!

Related

Gravityforms not found message - WP Plugin hook

I'm trying to hook onto the WP Gravityforms plugin's not found message.
I've found a hook(gform_form_not_found_message) for this but it doesn't seem to be firing. What am I doing wrong here?
My code:
function notfoundmessage($message, $id){
$message = 'test';
return $message;
}
add_filter( 'gform_form_not_found_message', 'notfoundmessage', 10, 2);
I tried several thing like writing the function inline, including it from the main plugin file, including it in an oop way but none of them seem to work. I was thinking that maybe I need to require a gravityforms Class but I can't find anything about that in the documentation.
Link to the hook in the documentation
It turned out the filter isn't applied yet in the version I'm using. For other people having this issue, make sure you are using the latest version of Gravityforms.

Wordpress - Stop plugins from requesting updates

I'm looking for a way to actually stop plugins from querying their developers sites to find out if there is a new version.
From running New Relic on a client site I'm working on I can see that outside calls to developer sites (such as WPMUdev) take a hell of a long time to complete, and must be tying up CPU time that would be much better utilised by actual processes that are needed.
Needless to say, there is no reason for a live site to ever be updated directly, so I'm looking for a way to stop these queries happening. Updates can then be done on a local copy and pushed via GIT.
TIA, Thall.
Disable automatic WordPress plugin updates:
add_filter( 'auto_update_plugin', '__return_false' );
Put above code in functions.php
Disable automatic WordPress theme updates:
add_filter( 'auto_update_theme', '__return_false' );
Disable automatic updates in WordPress by adding this line of code in your wp-config.php file:
define( 'WP_AUTO_UPDATE_CORE', false );
Agree with you.
I've came through a post which helps you to stop asking about you for the plugin update. For example I've wp-csv plugin, code in functions file will be like:
function filter_plugin_updates( $value ) {
unset( $value->response['wp-csv/wp-csv.php'] );
return $value;
}
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );
Ref link: https://wordpress.stackexchange.com/questions/25358/turn-off-auto-update-for-single-plugin?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

Woocommerce remove an action hook

I am using woocommerce plugin in my wordpress site. I want to remove a function named 'woocommerce_checkout_coupon_form' which is hooked in to the action 'woocommerce_before_checkout_form'.
I tried adding the below code in my theme functions.php
add_action('init','remove_coupon_text',10);
function remove_coupon_text() {
remove_action('woocommerce_before_checkout_form','woocommerce_checkout_login_form',10);
}
But this is not working. Any idea?
Sorry it was a mistake from my side. I used the wrong function name. The function name I intended to remove was 'woocommerce_checkout_coupon_form'. The issue is fixed now.
Try this
remove_all_actions( $tag, $priority );
Try increasing the priority.
remove_action('woocommerce_before_checkout_form','woocommerce_checkout_login_form',1 - 10);
Edit: Follow the comments below and dont use this as it is, what i meant by increasing priority was to gradually increase the priority till it matches the time when function was added, when it does match you will automatically see the results else it just wont work. Thank you everyone for making it clear.

WordPress admin and front end not opening

My site is http://www.empoweryourfamily.org/wordpress/
I was working on a plugin and wrote the following code in functions.php
add_action( 'wp_enqueue_scripts', 'table' );
function table() {
wp_register_script('table1', plugins_url() . '/Webinar_Reg/table.js', false, null, true);
if(is_admin()){
wp_enqueue_script('table1');
}
}
But, the moment I clicked on update everything went blank and now neither the frontend nor the backend is opening.
You most likely have a syntax error in functions.php or the function table() is already defined.
Try rolling back the changes you just applied.
Otherwise try looking in the server log for a specific error.
Using table as a function name is bad practice. You should name a function in such a way that it will be completely unique. Use something like mypluginname_table or mytheme_table where mypluginname is the name of your plugin and mytheme the name of your theme. And remember, function names needs to be unique, no two functions can have the same name, except if one is wrapped in a if(!function_exists()) {} conditional statement
I just replaced the modified functions.php file with the old(backup file) file and it is opening properly now. Thanks for your answers.

500 Internal server error with new php files on server (Wordpress/Woocommerce)

I am getting a strange 500 Internal Server Error with a new script I am trying to implement in the actual site. Here's a screen:
![500 Internal][1]
I can route to this files manually without problems and they are working too. But not in the script itself. The Paths are also correct.
Heres the link to the Site:
[>>> Link <<<][2] (just enter R10369 in the input field or a random number)
Everything else is working correctly except these 3 files:
reseller.php,
checkresellerid.php,
resellermail.php
I googled a bit and everywhere is the .htaccess mentioned. but I never modified it or overwrited it. What could be the Problem? Thanks for any Help and sorry for my bad Englisch.
(Let me know if you want to see the php files)
EDIT: I managed to include my new php files into wordpress but i still got the 500 Error
I checked out the website.
I think Wordpress doesn't let you call .php inside of it's system.
I mean you cannot call PHP files for ajax.
You need to use wordpress ajax. Here is a snippet how to use ajax:
Function.php in your theme file.
function myajax()
{
//do stuff
die();
}
add_action( 'wp_ajax_nopriv_product_s', 'myajax' );
add_action( 'wp_ajax_product_s', 'myajax' );
And in your javascript file using jQuery:
The url may change, maybe it's enough to have wp-admin/admin.ajax.php or something like this, i don't really remember right now.
$.post('/wp-admin/admin-ajax.php',{action:'myajax',yourdata:"mydata"}).done(function(data)
{
//do stuffs
});
Update:
So basically if you want to have ajax request inside wordpresss, you need to define these things and use it like this. the "action" parameter is the function name which you want to call. And you need to put the PHP code into your current theme's function.php.

Categories