get_membership(); if (empty($membership)) { return true; } // end if; $applicable_products_slugs = $membership->get_applicable_product_slugs(); $contains_product = empty(array_intersect($product_slug, $applicable_products_slugs)) === false; $active_status = true; if ($blocking) { $active_status = $membership->is_active(); } // end if; return $contains_product && $active_status; } // end wu_has_product; /** * Checks if the membership associated with a site is active. * * @since 2.0.0 * * @param string $site_id The site ID to test. * @return bool */ function wu_is_membership_active($site_id = '') { if (empty($site_id)) { $site_id = get_current_blog_id(); } // end if; $site = wu_get_site($site_id); if (empty($site)) { return new \WP_Error('site-not-found', __('Invalid site ID', 'wp-ultimo')); } // end if; $membership = $site->get_membership(); if (empty($membership)) { return true; } // end if; return $membership->is_active(); } // end wu_is_membership_active; /** * Register a new Limitation module. * * @since 2.0.0 * * @param string $id The id of the limitation module. * @param string $class_name The module class name. * @return void */ function wu_register_limit_module($id, $class_name) { add_filter('wu_limit_classes', function($classes) use ($id, $class_name) { $id = sanitize_title($id); $classes[$id] = $class_name; return $classes; }); } // end wu_register_limit_module; /** * Generate the modal link to search for an upgrade path. * * @since 2.0.0 * * @param array $args The module and type of limit that needs upgrading. * @return string */ function wu_generate_upgrade_to_unlock_url($args) { $args = wp_parse_args($args, array( 'module' => false, 'type' => false, )); $membership = wu_get_current_site()->get_membership(); if (!$membership) { return ''; } // end if; $upgrade_url = wu_get_membership_update_url($membership); $url = add_query_arg($args, $upgrade_url); /** * Allow developers to change the upgrade to unlock URL * * @param string $url The upgrade URL. * @param array $args The module and type of limit that needs upgrading. */ return apply_filters('wu_upgrade_to_unlock_url', $url, $args); } // end wu_generate_upgrade_to_unlock_url; /** * Generates a Unlock to Upgrade button for the upgrade modal. * * @since 2.0.0 * * @param string $title The title of the modal and label of the button. * @param array $args The module and type of limit that needs upgrading. * @return string */ function wu_generate_upgrade_to_unlock_button($title, $args) { $args = wp_parse_args($args, array( 'module' => false, 'type' => false, 'classes' => '', )); $url = wu_generate_upgrade_to_unlock_url(array( 'module' => $args['module'], 'type' => $args['type'], )); $element = sprintf( '%s', $url, $title, $args['classes'], $title ); return $element; } // end wu_generate_upgrade_to_unlock_button; /** * Activate a plugin(s) via Job Queue. * * @since 2.0.0 * * @param int $site_id The site ID. * @param string|array $plugins The plugin or list of plugins to activate. * @param boolean $network_wide If we want to activate it network-wide. * @param boolean $silent IF we should do the process silently - true by default. * @return void */ function wu_async_activate_plugins($site_id, $plugins, $network_wide = false, $silent = true) { wu_enqueue_async_action('wu_async_handle_plugins', array( 'action' => 'activate', 'site_id' => $site_id, 'plugins' => $plugins, 'network_wide' => $network_wide, 'silent' => $silent, )); } // end wu_async_activate_plugins; /** * Deactivates a plugin(s) via Job Queue. * * @since 2.0.0 * * @param int $site_id The site ID. * @param string|array $plugins The plugin or list of plugins to activate. * @param boolean $network_wide If we want to activate it network-wide. * @param boolean $silent IF we should do the process silently - true by default. * @return void */ function wu_async_deactivate_plugins($site_id, $plugins, $network_wide = false, $silent = true) { wu_enqueue_async_action('wu_async_handle_plugins', array( 'action' => 'deactivate', 'site_id' => $site_id, 'plugins' => $plugins, 'network_wide' => $network_wide, 'silent' => $silent, )); } // end wu_async_deactivate_plugins; /** * Switch themes via Job Queue. * * @since 2.0.0 * * @param int $site_id The site ID. * @param string $theme_stylesheet The theme stylesheet. * @return void */ function wu_async_switch_theme($site_id, $theme_stylesheet) { wu_enqueue_async_action('wu_async_switch_theme', array( 'site_id' => $site_id, 'theme_stylesheet' => $theme_stylesheet, )); } // end wu_async_switch_theme;