ring $option_name * @param string $stellar_slug The current stellar slug. */ $option_name = apply_filters('stellarwp/telemetry/show_optin_option_name', $option_name, $stellar_slug); /** * Filters the name of the option stored in the options table. * * @since 1.0.0 * @since 2.0.0 - Update to pass stellar slug for checking the current filter context. * * @param string $option_name * @param string $stellar_slug The current stellar slug. */ return apply_filters('stellarwp/telemetry/' . Config::get_hook_prefix() . 'show_optin_option_name', $option_name, $stellar_slug); } /** * Helper function to determine if the modal should be rendered. * * @since 1.0.0 * @since 2.0.0 - update to handle passed in stellar_slug. * * @param string $stellar_slug The stellar slug to get the option name for. * * @return boolean */ public function should_render(string $stellar_slug) { return (bool) get_option($this->get_option_name($stellar_slug), false); } /** * Renders the modal if it should be rendered. * * @since 1.0.0 * @since 2.0.0 - Add ability to render multiple modals. * * @param string $stellar_slug The stellar slug for which the modal should be rendered. * * @return void */ public function maybe_render(string $stellar_slug) { if ($this->should_render($stellar_slug)) { $this->render($stellar_slug); } } /** * Gets an array of opted-in plugin names. * * @since 1.0.0 * * @return string[] */ public function get_opted_in_plugin_names() { $option = Config::get_container()->get(Status::class)->get_option(); $site_plugins_dir = Config::get_container()->get(Core::SITE_PLUGIN_DIR); $opted_in_plugins = []; foreach ($option['plugins'] as $plugin) { if (true !== $plugin['optin']) { continue; } $plugin_path = trailingslashit($site_plugins_dir) . $plugin['wp_slug']; if (!file_exists($plugin_path)) { continue; } $plugin_data = get_plugin_data($plugin_path); if (empty($plugin_data['Name'])) { continue; } $opted_in_plugins[] = $plugin_data['Name']; } return $opted_in_plugins; } /** * Gets the primary message displayed on the opt-in modal. * * @param string $user_name The display name of the user. * @param string $plugin_name The name of the plugin. * * @return string */ public function get_intro($user_name, $plugin_name) { return sprintf( // Translators: The user name and the plugin name. esc_html__('Hi, %1$s! This is an invitation to help our StellarWP community. If you opt-in, some data about your usage of %2$s and future StellarWP Products will be shared with our teams (so they can work their butts off to improve). We will also share some helpful info on WordPress, and our products from time to time. And if you skip this, that’s okay! Our products still work just fine.', 'stellarwp-telemetry'), $user_name, $plugin_name ); } }