diff --git a/functions.php b/functions.php index 7bdb4c2..775f144 100644 --- a/functions.php +++ b/functions.php @@ -5,60 +5,65 @@ function contact_form_7_modules_promo_message() { global $pagenow; - if(!current_user_can('install_plugins')) { return; } - - $message = (int)get_option('cf7_modules_hide_promo_message'); - - if(isset($_REQUEST['hide']) && $_REQUEST['hide'] == 'cf7_modules_promo_message') { - $message = 3; - update_option('cf7_modules_hide_promo_message', $message); + if ( ! current_user_can( 'install_plugins' ) ) { + return; } - if($pagenow == 'admin.php' && isset($_REQUEST['page']) && $_REQUEST['page'] == 'wpcf7' && ($message !== 3 || isset($_REQUEST['show']) && $_REQUEST['show'] == 'cf7_modules_promo_message')) { - $message = contact_form_7_modules_get_remote_message(); + $message = (int) get_option( 'cf7_modules_hide_promo_message' ); - $message = str_replace('{hidelink}', add_query_arg('hide', 'cf7_modules_promo_message'), $message); - $message = str_replace('{showlink}', add_query_arg('show', 'cf7_modules_promo_message'), $message); - $message = str_replace('{adminurl}', admin_url(), $message); - $message = str_replace('{siteurl}', site_url(), $message); + if ( isset( $_REQUEST['hide'] ) && $_REQUEST['hide'] === 'cf7_modules_promo_message' ) { + $message = 5; + update_option( 'cf7_modules_hide_promo_message', $message ); + } - echo $message; + if ( $pagenow == 'admin.php' && isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wpcf7' && ( $message !== 5 || isset( $_REQUEST['show'] ) && $_REQUEST['show'] == 'cf7_modules_promo_message' ) ) { + echo contact_form_7_modules_get_message(); } } -function contact_form_7_modules_get_remote_message() { - - // The ad is stored locally for 30 days as a transient. See if it exists. - $cache = function_exists('get_site_transient') ? get_site_transient('contact_form_7_modules_remote_ad') : get_transient('contact_form_7_modules_remote_ad'); - - // If it exists, use that (so we save some request time), unless ?cache is set. - if(!empty($cache) && !isset($_REQUEST['cache'])) { return $cache; } - - // Get the advertisement remotely. An encrypted site identifier, the language of the site, and the version of the cf7 plugin will be sent to katz.co - $response = wp_remote_post('http://katz.co/ads/', array('timeout' => 45,'body' => array('siteid' => sha1(site_url()), 'language' => get_bloginfo('language'), 'plugin' => 'cf7_modules', 'version' => WPCF7_VERSION))); - - // If it was a successful request, process it. - if(!is_wp_error($response) && !empty($response)) { - - // Basically, remove