PHP Creating a formula from mysql db values and db stored math operator

ok, i managed to get it to work with this $amount1 = $invoice_amount; $operator = $invoice_operator; $amount2 = $invoice_multiplier; $rvalue = mcalc ($amount1,$operator,$amount2); function mcalc ($amount1,$operator,$amount2) { if($operator==”+”) $result=$amount1+$amount2; else if($operator==”-“) $result=$amount1-$amount2; else if($operator==”x”) $result=$amount1*$amount2; else if($operator==”/”) $result=$amount1/$amount2; return $result; } echo $rvalue;

PHP Notice: Function is_page was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false

Your code looked good to me, so I believed that the PHP notice was unlikely caused by the code in question. But that issue could probably be caused by a previous version of that code. E.g. If you had used the init and not wp_enqueue_scripts hook to enqueue your script, then such notice is expected, … Read more

Warning: Attempt to read property “term_id” on int – Woocommerce

You can I think you should use get_terms_args filter instead of get_terms and just add exclude arg, so now get_terms() function won’t retrieve those cats and you’ll get right count. Here’s code example: add_filter( ‘get_terms_args’, ‘mamaduka_edit_get_terms_args’, 10, 2 ); /** * Exclude product categories from Woocommerce * */ function mamaduka_edit_get_terms_args( $args, $taxonomies ) { //print_r($taxonomies); … Read more

A better way to write this php function

This answer is completely based on the code and help from -KIKO Software. I did have to add in the global ‘$current_user’ for it to work correctly. Also, per @kikosoftware foresight, I added a means to track by year, just in case a user did not visit the site until the same quarter the following … Read more

Removing all Category pages with one exception

You can just change the if (is_category()){ line: // Remove category archives add_action(‘template_redirect’, ‘jltwp_adminify_remove_archives_category’); function jltwp_adminify_remove_archives_category() { // Ignore category 20. if (is_category() && !is_category(20)){ $target = get_option(‘siteurl’); $status=”301″; wp_redirect($target, 301); die(); } }

Activate and deactivate two plugins automatically at certain hours

Rather than update the database you could write a mu-plugin to intercept reads from the active_plugins option, e.g. function option_active_plugins_akismet_or_yoast( $plugins ) { if ( !defined(‘WP_ADMIN’) ) { $hour = getdate()[ ‘hours’ ]; if ( $hour >= 10 && $hour < 19 ) { $to_remove=”wordpress-seo/wp-seo.php”; } else { $to_remove=”akismet/akismet.php”; } $remove_index = array_search( $to_remove, $plugins … Read more

Remove default Image Sizes

To unset all default image sizes in WordPress using PHP you can use this function: add_filter( ‘intermediate_image_sizes’, ‘remove_default_img_sizes’, 10, 1); function remove_default_img_sizes( $sizes ) { $targets = [‘thumbnail’, ‘medium’, ‘medium_large’, ‘large’, ‘1536×1536’, ‘2048×2048’]; foreach($sizes as $size_index=>$size) { if(in_array($size, $targets)) { unset($sizes[$size_index]); } } return $sizes; } Alternatively, you can also unset default images by going … Read more

image_size with respect to aspect ratios

Right before image subsizes are created, there’s a filter called intermediate_image_sizes_advanced that lets you modify the list of sizes. Here’s code that you could expand on — right now it just removes the thumbnail as a proof of concept: function remove_image_sizes_before_generation( $new_sizes, $image_meta, $attachment_id ) { $width = $image_meta[0]; $height = $image_meta[1]; // … Calculate aspect … Read more