slug = sanitize_title($translations['product_title']); // Users of the wordpress.org release are required to explicitly opt in $this->require_user_confirmation = ('2' !== $updraftplus->version[0] || !defined('UDADDONS2_DIR')); if ($this->require_user_confirmation && 'no' === get_user_meta(get_current_user_id(), $this->slug.'_confirmed_news_offer', true)) return; parent::__construct($feed_url, $link, $translations); add_action('admin_enqueue_scripts', array($this, 'enqueue_inline_style')); add_action('wp_ajax_'.$this->slug.'_ajax_confirm_news_offer', array($this, 'confirm_news_offer')); } /** * Enqueue news offer cascading style sheet * * @return void */ public function enqueue_inline_style() { global $pagenow; if ('index.php' != $pagenow) return; wp_register_style('updraftplus-news-offer-style', false); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion -- not specifying the URL as we just need an alias name/handle wp_enqueue_style('updraftplus-news-offer-style'); wp_add_inline_style('updraftplus-news-offer-style', $this->news_offer_css_style()); } /** * Get dashboard news HTML based on the installed version while respecting user pre-existing preference * * @return String - the output of the offering message in HTML format */ protected function get_dashboard_news_html() { if ($this->require_user_confirmation) { $confirmed_news_offer = (string) get_user_meta(get_current_user_id(), $this->slug.'_confirmed_news_offer', true); if ('no' === $confirmed_news_offer) return; if (!in_array(strtolower($confirmed_news_offer), array('yes', 'no'))) return '
'.parent::get_dashboard_news_html().$this->get_news_offer_html().'
'; } return parent::get_dashboard_news_html(); } /** * Save current user confirmation as its own preferrence/meta to the database as to whether or not they prefer our news to be shown in their own admin dashboard */ public function confirm_news_offer() { $request = wp_unslash($_REQUEST); if (!wp_verify_nonce($request['nonce'], $this->slug.'-confirm-news-offer')) die('Security check.'); if (!empty($request['confirmation']) && in_array(strtolower($request['confirmation']), array('yes', 'no'))) { update_user_meta(get_current_user_id(), $this->slug.'_confirmed_news_offer', $request['confirmation']); } die(); } /** * Get the HTML that offers our news feed * * @return String - the resulting message */ protected function get_news_offer_html() { ob_start(); ?>
slug.'_confirmed_news_offer', true); if ($this->require_user_confirmation && !in_array(strtolower($confirmed_news_offer), array('yes', 'no'))) { ?> div.ud-news-container { position: relative; height: 90px; padding-bottom: 0px !important; margin-bottom: 6px; } div.ud-news-container > div { position: absolute; } div.ud-news-offer-box { background-color: #db6939; padding-top: 5px; padding-bottom: 5px; } li.updraftplus_dashboard_news_offer_item a { float: right; margin-right: 13%; } div.ud-news-offer-box li a { color: #fff; } li.updraftplus_dashboard_news_offer_item a:hover { color: #cfc8c5; } div.ud-news-container > div.rss-widget:first-child { display: none; }