load_text_domain(); // check caps. add_action( 'admin_init', array( $this, 'hustle_check_caps' ), 999 ); new Hustle_Init(); } /** * Returns list of optin providers based on their declared classes that implement Opt_In_Provider_Interface * * @return array */ public function get_providers() { if ( empty( self::$registered_providers ) ) { self::$registered_providers = Hustle_Provider_Utils::get_activable_providers_list(); } return self::$registered_providers; } /** * Loads text domain * * @since 1.0.0 */ public function load_text_domain() { load_plugin_textdomain( 'hustle', false, dirname( plugin_basename( self::$plugin_base_file ) ) . '/languages/' ); } /** * Callback function when user migrates from 3x to 4x from ftp. * The activation hook won't run we'd have to check it in init. * * @since 4.0.0 */ public function hustle_check_caps() { $admin = get_role( 'administrator' ); $roles = get_editable_roles(); if ( ( $admin && ! $admin->has_cap( 'hustle_menu' ) ) || ( ! $admin && ! empty( $roles ) ) ) { hustle_activation(); } } } }; if ( ! function_exists( 'hustle_init' ) ) { /** * Instantiate Opt_In */ function hustle_init() { new Opt_In(); } add_action( 'plugins_loaded', 'hustle_init' ); } if ( ! function_exists( 'hustle_activation' ) ) { /** * Handle tables creating if needed. * * @since unknown */ function hustle_activation() { if ( ! class_exists( 'Hustle_Db' ) ) { require_once trailingslashit( dirname( __FILE__ ) ) . 'inc/hustle-db.php'; } update_option( 'hustle_activated_flag', 1 ); Hustle_Db::maybe_create_tables( true ); /** * Add Hustle's custom capabilities. * * @since 4.0.1 */ $hustle_capabilities = array( 'hustle_menu', 'hustle_edit_module', 'hustle_create', 'hustle_edit_integrations', 'hustle_access_emails', 'hustle_edit_settings', 'hustle_analytics', ); $admin = get_role( 'administrator' ); if ( $admin ) { // If there's an "administrator" role. foreach ( $hustle_capabilities as $cap ) { $admin->add_cap( $cap ); } } else { // If there's no "administrator". $roles = get_editable_roles(); foreach ( $roles as $role_name => $data ) { // Add the capabilities to anyone who can manage options. This was the checked capability in 3.x. if ( isset( $data['capabilities']['manage_options'] ) && $data['capabilities']['manage_options'] ) { $role = get_role( $role_name ); foreach ( $hustle_capabilities as $cap ) { if ( $role ) { $role->add_cap( $cap ); } } } } } } } register_activation_hook( __FILE__, 'hustle_activation' ); if ( ! function_exists( 'hustle_deactivation' ) ) { /** * On deactivation hook * * @since 4.2.0 */ function hustle_deactivation() { // Remove the cron for data protection cleanup. wp_clear_scheduled_hook( 'hustle_general_data_protection_cleanup' ); } } register_deactivation_hook( __FILE__, 'hustle_deactivation' );