Get main parent categories for a product

just to offer a alternative solution that might help somebody: code function wc_origin_trail_ancestor( $link = false, $trail = false ) { if (is_product_category()) { global $wp_query; $q_obj = $wp_query->get_queried_object(); $cat_id = $q_obj->term_id; $descendant = get_term_by(“id”, $cat_id, “product_cat”); $descendant_id = $descendant->term_id; $ancestors = get_ancestors($cat_id, ‘product_cat’); $ancestors = array_reverse($ancestors); $origin_ancestor = get_term_by(“id”, $ancestors[0], “product_cat”); $origin_ancestor_id = $origin_ancestor->term_id; … Read more

Trying to avoid including wp-load.php

Add a rewrite endpoint to give your plugin a public URL- function wpa_my_endpoint(){ add_rewrite_endpoint( ‘my_api’, EP_ROOT ); } add_action( ‘init’, ‘wpa_my_endpoint’ ); After you flush rewrite rules, you’ll have the URL available for the scheduler to ping. http://example.com/my_api/do/something/ Then catch those requests on the parse_query action to invoke your plugin action: function wpa_parse_query( $query ){ … Read more

How to use a Must-Use plugin to hide a regular one and to hide itself?

Apparently, there’s no way to remove one plugin from the Must-Use list… But then, found a filter that does even better: show_advanced_plugins will completely hide the sight of the Must-Use plugins. After all, if you’re trying to hide something of this nature, then hide it all… It’s inside the class WP_Plugins_List_Table and takes two arguments: … Read more

Claim Listing functionality – how to send email to users when their claim has been approved or denied

Unfortunately, the developers didn’t give you any hooks in their code to allow for customization without hacking it. But all is not lost – there are some hooks in WP that you could use to trigger your emails. The ideal would be to trigger off the update_post_meta(). That function is simply a wrapper for update_metadata() … Read more

How can I translate the name of my Plugin for other languages?

After searching a little bit more, I found that in the generation of the .pot file, the strings of plugin header already appear there. The tool I used to generate .pot file for my plugin was this command of wp-cli: https://developer.wordpress.org/cli/commands/i18n/make-pot/ I don’t know if another tools to make plugin translation do that. The reason … Read more

Add new password rule to Ultimate Member register form

You have to do various things. But you can change the hook the Ultimate Member uses. They Use the Validation class. But keeping your need in mind, you can bypass the use of this class. This is the solution I think will work remove_action( ‘um_submit_form_register’, ‘um_submit_form_register’, 10 ); Now we will register new method. add_action( … Read more

How can I add a custom header to a custom template in a plugin without using the theme folders

The get_header() functions is designed for themes. It usually look for header file in child theme first and then parent theme. You should be creating custom header under theme directory instead of in a plugin. But if you really must have to load header file from plugin then you have to create a custom function. … Read more