Add Custom Roles During Theme Activation

Hire Now!

Whether you’re looking to launch your brand, showcase your portfolio, or open an online store, we’re here to bring your ideas to life.

  • Post Created: 2 months ago
  • Views: 5

Add Custom Roles During Theme Activation

Reading Time: 1 Minute

Understanding the Hook: after_switch_theme

The after_switch_theme action allows you to add custom user roles when a theme is activated.

Why Use This Hook?

  • Set up roles specific to your theme’s functionality.
  • Automate user role configuration during theme setup.

How It Works

Create roles using add_role within the action.

Code Example

function add_custom_roles_on_activation() {
    add_role('custom_role', 'Custom Role', [
        'read' => true,
        'edit_posts' => true,
    ]);
}
add_action('after_switch_theme', 'add_custom_roles_on_activation');

Content Harmony: On-Site Data

Harmony

Contents

Website security is a top priority for WordPress site owners. From brute force attacks to malware, threats are everyw…

Affiliate marketing is a proven way to monetize your website and drive additional revenue streams. WordPress affilia…

Integrating secure and efficient payment gateways is essential for any e-commerce site. WordPress payment gateway pl…

WooCommerce is one of the most popular platforms for building online stores, but its functionality can be significan…

Discussion