creating custom archive template within plugin for custom post type using archive_template filter

I was able to get it working as desired using the condition is_archive() && get_post_type($post) == ‘product’. I also created a custom taxonomy for products as product-category below is the code: function get_custom_post_type_template( $archive_template ) { global $post; $plugin_root_dir = WP_PLUGIN_DIR.’/product-plugin/’; if (is_archive() && get_post_type($post) == ‘product’) { $archive_template = $plugin_root_dir.’/inc/templates/archive-product.php’ } return $archive_template; } … Read more

Executing a function upon webhook calling wordpress

You don’t need to create an extra file for that. Simply place something like the following into your themes functions.php file: function grab_my_very_own_webhook(){ if( ! isset( $_GET[‘whateveriwant’] ) ){ return; } //create your own logic here } add_action( ‘init’, ‘grab_my_very_own_webhook’ ); In case you want to grab some data that is sent by the webhook, … Read more

Execute Hook on the footer or header after activating a plugin

Checking the action hooks API reference, “activated_plugin” is an Advanced hook. It operates outside the normal loop which would permit you to do what you want. A better way would be to add_action(‘admin_footer_text’), as illustrated in this WPBeginner article. However, if you only want this to show when a particular plugin is activated, you can … Read more

WordPress setting with select – where is my mistake?

The problem is that in your calls to selected() you haven’t set the 3rd parameter to false. For both selected() and checked() if you don’t do this it will echo the attribute immediately, which won’t work properly if you’re using it inside a concatenated string. So change: selected( get_option(‘myplugin_admin_bar’), 1 ) To: selected( get_option(‘myplugin_admin_bar’), 1, … Read more

How to set “Site Address (URL)” programmatically on WP multisite?

If you just want to update that one value, then you can use wp_update_site(): wp_update_site( 123, [ ‘domain’ => ‘new-slug.domain.com’, ] ); But to really update the site URL/address, you’d need to update both the siteurl and home options for the site: switch_to_blog( 123 ); update_option( ‘siteurl’, ‘new URL here’ ); update_option( ‘home’, ‘new URL … Read more

Custom url for a plugin page add_rewrite_rule WordPress

After a long search finally i found a working solution. I am posting here in case someone face the similar issue, it would be helpful. Here is my working code: add_action(‘template_redirect’, array($this, ‘zip_template’)); add_filter( ‘rewrite_rules_array’, array($this, ‘zip_rule’) ); add_filter( ‘query_vars’, array( $this, ‘zip_query_vars’ ) ); add_action( ‘wp_loaded’, array( $this, ‘flush_rules’ ) ); /** * Rewrite … Read more

add more custom post types and custom role to the code

its better to include your assets with admin_enqueue_scripts for your question add_action(‘admin_head’, ‘grup_custom_admin_post_css’); function grup_custom_admin_post_css() { $allow_post_types = array(‘custom_role’, ‘custom_role_2’, ‘etc’); $allow_roles = array(‘post_type’, ‘post_typ_2’); $current_user = wp_get_current_user(); if (array_intersect($current_user->roles, $allow_roles)) { // do something if user have one of these roles global $post_type; if ($post_type && in_array($post_type, $allow_post_types)) { echo “<style></style>”; } } }