Settings API Message Error is global

The setting that is the first parameter is the not the option key. It is the key that you would’ve registered using register_setting register_setting( ‘settings_unique_key4172_91h, ‘option_key’, ‘name_of_sanitiser_function’ ); Then you can add settings errors like this, inside the callback function name_of_sanitiser_function(){ add_settings_error( ‘settings_unique_key4172_91h’, esc_attr( ‘settings_updated’ ), $message, $type ); } You might like a few … Read more

Customizing $product->get_title() function

In WooCommerce, the product variants are children of the actual product. So perhaps just check if the $product_id you’re on is a child, and if so get the title of the parent. Untested code: // Check if product has parent if($product->post_parent){ $parents = get_post_ancestors( $product->ID ); /* Get the top Level page->ID count base 1, … Read more

Do rewrites added with add_rewrite_rule() persist after plugin deletion?

Let me say beforehand that when using add_rewrite_rule() nothing is written to the htaccess file. Rewrite rules are stored in the database and handled by WordPress internally on PHP level. TL;DR: Rewrite rules do persist after plugin deletion, but probably not the way you’d expect it. When using add_rewrite_rule these rules are added in the … Read more

Conditional custom redirect

It should not be tough. As you suggested you can use ACF to add a custom field in post/page and then use the template_redirect action hook to check if the current page’s custom field is a valid URL as well as $_GET[‘redirect’] is true, wp_redirect to that URL. function my_page_template_redirect() { if( is_url(GET_ACF_FIELD_VALUE( ‘CUSTOM_FIELD’ )) … Read more

How to add category and subcategory in WordPress custom code?

The syntax for adding an action in WordPress WITHIN a class is somewhat different. Your code will have to look somewhat more like the following… class MyPluginClass { public function __construct() { add_action( ‘init’, array( $this, ‘sample_insert_category’) ); } public function sample_insert_category() { if(!term_exists(‘sample-category’)) { wp_insert_term( ‘Sample Category’, ‘category’, array( ‘description’ => ‘This is an … Read more