How check if a post is saved from backend or frontend?

I would add some hidden input field to frontend form, and check for its presence in the save_post hook. … <input type=”hidden” name=”saved-on-frontend” value=”1″> … And then check for it in that hooked function: function my_save_hook() { if( isset( $_POST[‘saved-on-frontend’] ) ) { return; // don’t do anything … } } add_action( ‘save_post_CUSTOM_POST_TYPE’, ‘my_save_hook’ );

How do I use pre_option_{option_name} correctly?

The pre_option_{$option} hook is used to filter the value of the option before it’s retrieved. You need to hook after the value is retrieved so you can manipulate it. In this case, you can use the option_{$option} hook. So your code will look like this: add_filter(‘option_percify_api_key’, array( __CLASS__, ‘decrypt_api_key’) ); For more info – take … Read more

Associate multiple email addresses with the same user account, so they can log in with either

If you create them programmatically, you could set it up so that all of the usernames are one type of email address (business or personal) and the WP email address field contains the other type. It’s not clear if this would fit your particular use case, but one other login possibility is to integrate single … Read more

Call to undefined function is_home() or any conditional tags

It’s a timing issue. This tries to call is_home() before that function exists. $my_ver = check_home(); It works in the function called by add_action because then is_home() does exist because WP has fully loaded. If you load php files in your plugin, then you can call check_home anytime in those files. For example: define( ‘MY_PLUGIN_PATH’, … Read more

Adding Plugin Assets to Header

I finally done like this: $form_styles_header = [ “1” => “forms/vendor/bootstrap/css/bootstrap.min.css”, “2” => “forms/fonts/font-awesome-4.7.0/css/font-awesome.min.css”, “3” => “forms/vendor/animate/animate.css”, “4” => “forms/vendor/css-hamburgers/hamburgers.min.css”, “5” => “forms/vendor/animsition/css/animsition.min.css”, “6” => “forms/vendor/select2/select2.min.css”, “7” => “forms/vendor/daterangepicker/daterangepicker.css”, “8” => “forms/css/util.css”, “9” => “forms/css/main.css”, “10” => “table/css/table-styles.css” ]; foreach ($form_styles_header as $no=>$form_style) { wp_enqueue_style(‘du_form_style’.$no, $d_utility_url.”/assets/”.$form_style); } where $d_utility_url is the path to my plugin. … Read more

How to use template_include hook with form submission?

It turns out that $wp->query_vars[“post_type”] contains the data I need, regardless of whether the request method is GET or POST. namespace mynamespace; class MyPlugin { public static function template_include($template) { global $wp; if ($wp->query_vars[“post_type”] == ‘thing’) { return plugin_dir_path( __FILE__ ) . ‘templates/thing.php’; } return $template; } } add_filter(‘template_include’, ‘\mynamespace\MyPlugin::template_include’); Also, it appears that the … Read more

add short description under price

Looking at the content-single-product.php of woocommerce github, I see that product excerpt is already supposed to be after price /** * Hook: woocommerce_single_product_summary. * * @hooked woocommerce_template_single_title – 5 * @hooked woocommerce_template_single_rating – 10 * @hooked woocommerce_template_single_price – 10 * @hooked woocommerce_template_single_excerpt – 20 * @hooked woocommerce_template_single_add_to_cart – 30 * @hooked woocommerce_template_single_meta – 40 * … Read more