Wordpress Theme development: Getting Undefined index error - wordpress

hello I am a wordpress theme developer. i created a theme which works fine in WP_DEBUG=False but gets undefined index error when I set WP_DEBUG=True
My theme has an options page, whenever i click on save i get these errors:
Notice: Undefined index: ang_temp in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php on line 147
Notice: Undefined index: ang_breadcrumbs in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php on line 147
Notice: Undefined index: ang_hide_social in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php on line 147
Notice: Undefined index: ang_hide_tw in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php on line 147
Notice: Undefined index: ang_hide_fb in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php on line 147
Notice: Undefined index: ang_hide_ms in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php on line 147
Notice: Undefined index: ang_hide_rss in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php on line 147
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php:147) in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php on line 156
Here is my themes functions.php
I don't know what I am doing wrong. I have very very little knowledge about php. Hope guys with php knowledge or wordpress theme development knowledge can help.

146. foreach ($options as $value) {
147. update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
The bit of code which is producing this error (above) is not checking whether $_REQUEST[ $value['id'] ] exists. The errors you are getting suggest that it doesn't (you will only get this notice with full error checking enabled). Other parts of your code are checking the existence of this variable before using it (so they are OK) and would suggest you should be doing the same here.
You say your theme works OK when debug is off, so this would suggest that you only need to check the existence of this variable before using it. Something like (replacing the 2 lines above):
foreach ($options as $value) {
if (isset($_REQUEST[ $value['id'] ])) {
update_option( $value['id'], $_REQUEST[ $value['id'] ] );
}
}
However, although this should prevent your 'errors' (they are only notices really), I'm unfamiliar with wordpress themes so can't say for sure whether this is expected behaviour or whether there is something underlying which is at fault.

Related

Fatal error within Woocommerce "wc-template-functions.php" file

I have tried to edit wc-template-functions.php in my store and did something wrong.
Now I am getting Fatal Error on 281 line.
Fatal error: Uncaught Error: Class 'Constants' not found in /home/kidsandm/oliverthedog/wp-content/plugins/woocommerce/includes/wc-template-functions.php:282 Stack trace: #0 /home/kidsandm/oliverthedog/wp-includes/class-wp-hook.php(292): wc_generator_tag('<meta name="gen...', 'xhtml') #1 /home/kidsandm/oliverthedog/wp-includes/plugin.php(212): WP_Hook->apply_filters('<meta name="gen...', Array) #2 /home/kidsandm/oliverthedog/wp-includes/general-template.php(4728): apply_filters('get_the_generat...', '<meta name="gen...', 'xhtml') #3 /home/kidsandm/oliverthedog/wp-includes/general-template.php(4650): get_the_generator('xhtml') #4 /home/kidsandm/oliverthedog/wp-includes/general-template.php(4627): the_generator('xhtml') #5 /home/kidsandm/oliverthedog/wp-includes/class-wp-hook.php(292): wp_generator('') #6 /home/kidsandm/oliverthedog/wp-includes/class-wp-hook.php(316): WP_Hook->apply_filters(NULL, Array) #7 /home/kidsandm/oliverthedog/wp-includes/plugin.php(484): WP_Hook->do_action(Array) #8 /home/kidsandm/oliverthedog/wp-includes/gen in /home/kidsandm/oliverthedog/wp-content/plugins/woocommerce/includes/wc-template-functions.php on line 282
Before that I also had warning at the top that said:
Warning: The use statement with non-compound name 'AutomatticJetpackConstants' has no effect in /home/kidsandm/hondamarine/wp-content/plugins/woocommerce/includes/wc-template-functions.php on line 11
but I have hide that line thinking it might help.
What I have change in file?
Additional information.
I was thinking it will change the name of it on front-end as well.
// Additional information tab - shows attributes.
if ( $product && ( $product->has_attributes() || apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() ) ) ) {
$tabs['additional_information'] = array(
'title' => __( 'Additional information', 'woocommerce' ),
'priority' => 20,
'callback' => 'woocommerce_product_additional_information_tab',
);
}
Line 1798.
I have tried to find a code only to replace it, and I found one but did not help.
Now, that code might not be original because I could not find it on GitHub.
Thanks a lot!
It just happened to me too, I tried to edit the code for the same reason, I searched a lot about this problem and I solved it when I downloaded the plugin in zip form and manually upload it and install it, now its working fine for me and all data still in place (categories, products, etc.)!
I had the following 2 errors:
Fatal Error: Uncaught error: Class 'Constants' not found in /Users/anastasiades/Local Sites/pisinaspa/app/public/wp-content/plugins/woocommerce/includes/wc-template-functions.php on line 282
Error: Class 'Constants' not found in /Users/anastasiades/Local Sites/pisinaspa/app/public/wp-content/plugins/woocommerce/includes/wc-template-functions.php on line 282
Steps:
1. Backup data in woocommerce
2. Download plugin here
3. On WordPress go to Plugins >> Add new >> Upload plugin
4. Choose Reinstall >> Install now
5. "Replace current with uploaded"
I recommend a good backup of the products and other data before doing this.
Peace!

How to fix "Warning: A non-numeric value encountered in" WP

On my WordPress page I use the plugin occupancy plan "https://wordpress.org/plugins/occupancyplan/" after the update to PHP 7.3 wordpress gives the following error message:
Warning: A non-numeric value encountered in
/homepages/XX/XXXXXXXXXX/htdocs/XXXXXXXXXX/wp-content/plugins/occupancyplan/occupancy_plan_classes.php
on line 4 - 38 and on line 620, 641, 657
How can I solve the problem?
it's probably a bit late but try adding this validation to every line with that error!
//fix issue with tax when it's not selected it
IF(empty ($ variable name)){
/* null */
}else{
$return = whatever was previously at the line
At the end you must to return something
}
return floatval( $return );
Good Luck!

Drupal 7 - Add node edit form into a 'Simple page'

I'm trying to add the edit form of an existing node to a Basic page. Based on a given nid.
This problem seemed simple, however my attempt resulted in the following error report:
$node = node_load(array('nid' => 83));
$output = drupal_get_form($node->type .'_node_form', $node);
echo $output;
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 175 of /home/PAE/www/paemanu/includes/entity.inc).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 388 of /home/PAE/www/paemanu/includes/entity.inc).
Notice: Trying to get property of non-object in eval() (line 3 of /home/PAE/www/paemanu/modules/php/php.module(80) : eval()'d code).
Notice: Undefined index: _node_form in drupal_retrieve_form() (line 806 of /home/PAE/www/paemanu/includes/form.inc).
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function '_node_form' not found or invalid function name in drupal_retrieve_form() (line 841 of /home/PAE/www/paemanu/includes/form.inc).
Notice: Undefined variable: output in eval() (line 3 of /home/PAE/www/paemanu/modules/php/php.module(80) : eval()'d code).
Notice: Undefined index: user-project in drupal_retrieve_form() (line 806 of /home/PAE/www/paemanu/includes/form.inc).
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'user-project' not found or invalid function name in drupal_retrieve_form() (line 841 of /home/PAE/www/paemanu/includes/form.inc).
I've been on this issue for many hours, any help is greatly appreciated.
Try this code:
$nid = 83;
$node = node_load($nid);
$type = $node->type;
module_load_include('inc', 'node', 'node.pages');
$form = drupal_get_form('node_edit_'.$type, $node);
render($form);

how to add require_once to a wordpress template file

I am creating a wordpress template file.
I need to require_once() a file path. Where should I put the code?
<?php require_once("phpChart/conf.php");?>
It is giving me errors if I put it in my template file. It doesn't seem to work either in the header.php file.
If I include it in the template file I can a ton of errors. I think it needs to be in the header before the html.
Here are some of the errors:
Notice: Undefined offset: -1 in /xxx/wp-includes/post-template.php on line 262 Call Stack #TimeMemoryFunctionLocation 10.0003283432{main}( ).../index.php:0 20.0004287208require( '/xxx/wp-blog-header.php' ).../index.php:17 30.454546621040require_once( '/xxx/wp-includes/template-loader.php' ).../wp-blog-header.php:16 40.459646824600include( '/xxx/wp-content/themes/gazette-child/email.php' ).../template-loader.php:74 50.537247474312get_header( ).../email.php:18 60.537547477952locate_template( ).../general-template.php:45 70.537547478144load_template( ).../template.php:477 80.537747516408require_once( '/xxx/wp-content/themes/gazette-child/header.php' ).../template.php:501 90.581648215152the_excerpt( ).../header.php:56 100.581648215264get_the_excerpt( ).../post-template.php:336 110.581748215672apply_filters( ).../post-template.php:367 120.581748217056call_user_func_array:{/xxx/wp-includes/plugin.php:213} ( ).../plugin.php:213 130.581748217088wp_trim_excerpt( ).../plugin.php:213 140.581748217248get_the_content( ).../formatting.php:2609 " /> ( ! ) Notice: Undefined offset: -1 in /xxx/wp-includes/post-template.php on line 262 Call Stack #TimeMemoryFunctionLocation 10.0003283432{main}( ).../index.php:0 20.0004287208require( '/xxx/wp-blog-header.php' ).../index.php:17 30.454546621040require_once( '/xxx/wp-includes/template-loader.php' ).../wp-blog-header.php:16 40.459646824600include( '/xxx/wp-content/themes/gazette-child/email.php' ).../template-loader.php:74 50.537247474312get_header( ).../email.php:18 60.537547477952locate_template( ).../general-template.php:45 70.537547478144load_template( ).../template.php:477 80.537747516408require_once( '/xxx/wp-content/themes/gazette-child/header.php' ).../template.php:501 90.585448229760the_excerpt( ).../header.php:68 100.585448229840get_the_excerpt( ).../post-template.php:336 110.585448230048apply_filters( ).../post-template.php:367 120.585448231280call_user_func_array:{/xxx/wp-includes/plugin.php:213} ( ).../plugin.php:213 130.585448231312wp_trim_excerpt( ).../plugin.php:213 140.585448231392get_the_content( ).../formatting.php:2609 - http://xxx/email/">
Use require_once() or include() to include a file. You didn't post what error are you getting?
require('phpChart/conf.php'); in functions.php worked.

WordPress Notice "Undefined Index"

I am getting following notice in WordPress
Notice: Undefined index: _wpnonce in /var/www/vhosts/abc.biz/php/func.php on line 338
Any solution?
Thanks for help
I found the solution, have to use isset() to check _wpnonce value, before comparing it.
if ( isset($_POST['_wpnonce']) && $_POST['_wpnonce'] = '123456789' ) {}
Thanks.

Resources