'Version'), 'plugin'); self::$version = $plugin_data['version']; return $plugin_data['version']; } // get_plugin_version // hook things up static function init() { // check if minimal required WP version is present if (false === self::check_wp_version(4.0)) { return false; } if (is_admin()) { // if the plugin was updated from ver < 1.20 upgrade settings array self::maybe_upgrade(); // add UCP menu to admin tools menu group add_action('admin_menu', array(__CLASS__, 'admin_menu')); // settings registration add_action('admin_init', array(__CLASS__, 'register_settings')); // aditional links in plugin description add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array(__CLASS__, 'plugin_action_links') ); add_filter('plugin_row_meta', array(__CLASS__, 'plugin_meta_links'), 10, 2); add_filter('admin_footer_text', array(__CLASS__, 'admin_footer_text')); add_filter('admin_footer', array(__CLASS__, 'admin_footer')); // manages admin header notifications add_action('admin_notices', array(__CLASS__, 'admin_notices')); add_action('admin_action_ucp_dismiss_notice', array(__CLASS__, 'dismiss_notice')); add_action('admin_action_ucp_change_status', array(__CLASS__, 'change_status')); add_action('admin_action_ucp_reset_settings', array(__CLASS__, 'reset_settings')); add_action('admin_action_install_weglot', array(__CLASS__, 'install_weglot')); add_action('admin_action_install_wpfssl', array(__CLASS__, 'install_wpfssl')); // enqueue admin scripts add_action('admin_enqueue_scripts', array(__CLASS__, 'admin_enqueue_scripts'), 100, 1); // AJAX endpoints add_action('wp_ajax_ucp_dismiss_pointer', array(__CLASS__, 'dismiss_pointer_ajax')); add_action('wp_ajax_ucp_dismiss_survey', array(__CLASS__, 'dismiss_survey_ajax')); add_action('wp_ajax_ucp_submit_survey', array(__CLASS__, 'submit_survey_ajax')); add_action('wp_ajax_ucp_submit_support_message', array(__CLASS__, 'submit_support_message_ajax')); } else { // main plugin logic add_action('wp', array(__CLASS__, 'display_construction_page'), 0, 1); // show under construction notice on login form add_filter('login_message', array(__CLASS__, 'login_message')); // disable feeds add_action('do_feed_rdf', array(__CLASS__, 'disable_feed'), 0, 1); add_action('do_feed_rss', array(__CLASS__, 'disable_feed'), 0, 1); add_action('do_feed_rss2', array(__CLASS__, 'disable_feed'), 0, 1); add_action('do_feed_atom', array(__CLASS__, 'disable_feed'), 0, 1); add_action('wp_footer', array(__CLASS__, 'whitelisted_notice')); } // if not admin // admin bar notice for frontend & backend add_action('wp_before_admin_bar_render', array(__CLASS__, 'admin_bar')); add_action('wp_head', array(__CLASS__, 'admin_bar_style')); add_action('admin_head', array(__CLASS__, 'admin_bar_style')); UCP_license::init(); } // init // check if user has the minimal WP version required by UCP static function check_wp_version($min_version) { if (!version_compare(get_bloginfo('version'), $min_version, '>=')) { add_action('admin_notices', array(__CLASS__, 'notice_min_wp_version')); return false; } else { return true; } } // check_wp_version // display error message if WP version is too low static function notice_min_wp_version() { echo '

' . sprintf(esc_attr__('UnderConstruction plugin requires WordPress version 4.0 or higher to function properly. You are using WordPress version %s. Please update it.', 'under-construction-page'), get_bloginfo('version'), admin_url('update-core.php')) . '

'; } // notice_min_wp_version_error // some things have to be loaded earlier static function plugins_loaded() { self::get_plugin_version(); load_plugin_textdomain('under-construction-page'); } // plugins_loaded // activate doesn't get fired on upgrades so we have to compensate public static function maybe_upgrade() { $meta = self::get_meta(); $options = self::get_options(); // added in v1.70 to rename roles to whitelisted_roles if (isset($options['roles'])) { $options['whitelisted_roles'] = $options['roles']; unset($options['roles']); update_option(UCP_OPTIONS_KEY, $options); } // check if we need to convert options from the old format to new, or maybe it is already done if (isset($meta['options_ver']) && $meta['options_ver'] == self::$version) { return; } if (get_option('set_size') || get_option('set_tweet') || get_option('set_fb') || get_option('set_font') || get_option('set_msg') || get_option('set_opt') || get_option('set_admin')) { // convert old options to new $options['status'] = (get_option('set_opt') === 'Yes') ? '1' : '0'; $options['content'] = trim(get_option('set_msg')); $options['whitelisted_roles'] = (get_option('set_admin') === 'No') ? array('administrator') : array(); $options['social_facebook'] = trim(get_option('set_fb')); $options['social_twitter'] = trim(get_option('set_tweet')); update_option(UCP_OPTIONS_KEY, $options); delete_option('set_size'); delete_option('set_tweet'); delete_option('set_fb'); delete_option('set_font'); delete_option('set_msg'); delete_option('set_opt'); delete_option('set_admin'); self::reset_pointers(); } // we update only once $meta['options_ver'] = self::$version; update_option(UCP_META_KEY, $meta); } // maybe_upgrade // get plugin's options static function get_options() { $options = get_option(UCP_OPTIONS_KEY, array()); if (!is_array($options)) { $options = array(); } $options = array_merge(self::default_options(), $options); return $options; } // get_options // get plugin's meta data static function get_meta() { $meta = get_option(UCP_META_KEY, array()); if (!is_array($meta) || empty($meta)) { $meta['first_version'] = self::get_plugin_version(); $meta['first_install'] = time(); update_option(UCP_META_KEY, $meta); } return $meta; } // get_meta // fetch and display the construction page if it's enabled or preview requested static function display_construction_page() { $options = self::get_options(); $request_uri = trailingslashit(strtolower(@parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))); // just to be on the safe side if (defined('DOING_CRON') && DOING_CRON) { return false; } if (defined('DOING_AJAX') && DOING_AJAX) { return false; } if (defined('WP_CLI') && WP_CLI) { return false; } // some URLs have to be accessible at all times if ( $request_uri == '/wp-admin/' || $request_uri == '/feed/' || $request_uri == '/feed/rss/' || $request_uri == '/feed/rss2/' || $request_uri == '/feed/rdf/' || $request_uri == '/feed/atom/' || $request_uri == '/admin/' || $request_uri == '/wp-login.php' ) { return; } if (true == self::is_construction_mode_enabled(false) || (is_user_logged_in() && isset($_GET['ucp_preview']))) { header(self::wp_get_server_protocol() . ' 200 OK'); if ($options['end_date'] && $options['end_date'] != '0000-00-00 00:00') { header('Retry-After: ' . date('D, d M Y H:i:s T', strtotime($options['end_date']))); } else { header('Retry-After: ' . DAY_IN_SECONDS); } $themes = self::get_themes(); if (!empty($_GET['theme']) && substr(sanitize_text_field($_GET['theme']), 5) != '_pro_' && !empty($themes[sanitize_text_field($_GET['theme'])])) { $theme = sanitize_text_field($_GET['theme']); } else { $theme = $options['theme']; } self::wp_kses_wf(self::get_template($theme)); die(); } } // display_construction_page // keeping compatibility with WP < v4.4 static function wp_get_server_protocol() { $protocol = $_SERVER['SERVER_PROTOCOL']; if (!in_array($protocol, array('HTTP/1.1', 'HTTP/2', 'HTTP/2.0'))) { $protocol = 'HTTP/1.0'; } return $protocol; } // wp_get_server_protocol // disables feed if necessary static function disable_feed() { if (true == self::is_construction_mode_enabled(false)) { echo 'Service unavailable.'; exit; } } // disable_feed // enqueue CSS and JS scripts in admin static function admin_enqueue_scripts($hook) { $surveys = get_option(UCP_SURVEYS_KEY); $meta = self::get_meta(); $pointers = get_option(UCP_POINTERS_KEY); // auto remove welcome pointer when options are opened if (self::is_plugin_page()) { unset($pointers['welcome']); update_option(UCP_POINTERS_KEY, $pointers); } // survey is shown min 5min after install // DISABLED if (0 && empty($surveys['usage']) && time() - $meta['first_install'] > 300) { $open_survey = true; } else { $open_survey = false; } $promo = self::is_promo_active(); if ($promo == 'welcome') { $countdown = $meta['first_install'] + HOUR_IN_SECONDS; } else { $countdown = 0; } $js_localize = array( 'undocumented_error' => esc_attr__('An undocumented error has occured. Please refresh the page and try again.', 'under-construction-page'), 'plugin_name' => esc_attr__('UnderConstructionPage', 'under-construction-page'), 'settings_url' => admin_url('options-general.php?page=ucp'), 'whitelisted_users_placeholder' => esc_attr__('Select whitelisted user(s)', 'under-construction-page'), 'open_survey' => $open_survey, 'promo_countdown' => $countdown, 'wpfssl_install_url' => add_query_arg(array('action' => 'install_wpfssl', '_wpnonce' => wp_create_nonce('install_wpfssl'), 'rnd' => rand()), admin_url('admin.php')), 'is_activated' => UCP_license::is_activated(), 'dialog_upsell_title' => '' . esc_attr__('UnderConstructionPage PRO', 'under-construction-page') . '', 'weglot_dialog_upsell_title' => '' . esc_attr__('Weglot', 'under-construction-page') . '', 'weglot_install_url' => add_query_arg(array('action' => 'install_weglot'), admin_url('admin.php')), 'nonce_dismiss_survey' => wp_create_nonce('ucp_dismiss_survey'), 'nonce_submit_survey' => wp_create_nonce('ucp_submit_survey'), 'nonce_submit_support_message' => wp_create_nonce('ucp_submit_support_message'), 'deactivate_confirmation' => esc_attr__('Are you sure you want to deactivate UnderConstruction plugin?' . "\n" . 'If you are removing it because of a problem please contact our support. They will be more than happy to help.', 'under-construction-page') ); if (self::is_plugin_page()) { remove_editor_styles(); wp_enqueue_style('wp-jquery-ui-dialog'); wp_enqueue_style('ucp-select2', UCP_PLUGIN_URL . 'css/select2.min.css', array(), self::$version); wp_enqueue_style('ucp-admin', UCP_PLUGIN_URL . 'css/ucp-admin.css', array(), self::$version); wp_enqueue_script('jquery-ui-tabs'); wp_enqueue_script('jquery-ui-dialog'); wp_enqueue_script('ucp-jquery-plugins', UCP_PLUGIN_URL . 'js/ucp-jquery-plugins.js', array('jquery'), self::$version, true); wp_enqueue_script('ucp-select2', UCP_PLUGIN_URL . 'js/select2.min.js', array(), self::$version, true); wp_enqueue_script('ucp-admin', UCP_PLUGIN_URL . 'js/ucp-admin.js', array('jquery'), self::$version, true); wp_localize_script('ucp-admin', 'ucp', $js_localize); // fix for agressive plugins wp_dequeue_style('uiStyleSheet'); wp_dequeue_style('wpcufpnAdmin'); wp_dequeue_style('unifStyleSheet'); wp_dequeue_style('wpcufpn_codemirror'); wp_dequeue_style('wpcufpn_codemirrorTheme'); wp_dequeue_style('collapse-admin-css'); wp_dequeue_style('jquery-ui-css'); wp_dequeue_style('tribe-common-admin'); wp_dequeue_style('file-manager__jquery-ui-css'); wp_dequeue_style('file-manager__jquery-ui-css-theme'); wp_dequeue_style('wpmegmaps-jqueryui'); wp_dequeue_style('wp-botwatch-css'); } if ($pointers) { $pointers['_nonce_dismiss_pointer'] = wp_create_nonce('ucp_dismiss_pointer'); wp_enqueue_script('wp-pointer'); wp_enqueue_script('ucp-pointers', plugins_url('js/ucp-admin-pointers.js', __FILE__), array('jquery'), self::$version, true); wp_enqueue_style('wp-pointer'); wp_localize_script('wp-pointer', 'ucp_pointers', $pointers); wp_localize_script('wp-pointer', 'ucp', $js_localize); } } // admin_enqueue_scripts // permanently dismiss a pointer static function dismiss_pointer_ajax() { check_ajax_referer('ucp_dismiss_pointer'); $pointers = get_option(UCP_POINTERS_KEY); $pointer = trim(sanitize_text_field($_POST['pointer'])); if (empty($pointers) || empty($pointers[$pointer])) { wp_send_json_error(); } unset($pointers[$pointer]); update_option(UCP_POINTERS_KEY, $pointers); wp_send_json_success(); } // dismiss_pointer_ajax // permanently dismiss a survey static function dismiss_survey_ajax() { check_ajax_referer('ucp_dismiss_survey'); $surveys = get_option(UCP_SURVEYS_KEY, array()); $survey = trim(sanitize_text_field($_POST['survey'])); $surveys[$survey] = -1; update_option(UCP_SURVEYS_KEY, $surveys); wp_send_json_success(); } // dismiss_survey_ajax // send support message static function submit_support_message_ajax() { check_ajax_referer('ucp_submit_support_message'); $options = self::get_options(); $email = sanitize_text_field($_POST['support_email']); if (!is_email($email)) { wp_send_json_error(esc_attr__('Please double-check your email address.', 'under-construction-page')); } $message = stripslashes(sanitize_text_field($_POST['support_message'])); $subject = 'UCP Support'; $body = $message; if (!empty($_POST['support_info'])) { $theme = wp_get_theme(); $body .= "\r\n\r\nSite details:\r\n"; $body .= ' WordPress version: ' . get_bloginfo('version') . "\r\n"; $body .= ' UCP version: ' . self::$version . "\r\n"; $body .= ' PHP version: ' . PHP_VERSION . "\r\n"; $body .= ' Site URL: ' . get_bloginfo('url') . "\r\n"; $body .= ' WordPress URL: ' . get_bloginfo('wpurl') . "\r\n"; $body .= ' Theme: ' . $theme->get('Name') . ' v' . $theme->get('Version') . "\r\n"; $body .= ' Options: ' . "\r\n" . serialize($options) . "\r\n"; } $headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email; if (true === wp_mail('ucp@webfactoryltd.com', $subject, $body, $headers)) { wp_send_json_success(); } else { wp_send_json_error(esc_attr__('Something is not right with your wp_mail() function. Please email as at ucp@webfactoryltd.com.', 'under-construction-page')); } } // submit_support_message // submit survey static function submit_survey_ajax() { check_ajax_referer('ucp_submit_survey'); $options = self::get_options(); $meta = self::get_meta(); $surveys = get_option(UCP_SURVEYS_KEY); $vars = wp_parse_args($_POST, array('survey' => '', 'answers' => '', 'custom_answer' => $options['theme'], 'emailme' => '')); $vars['answers'] = trim($vars['answers'], ','); $vars['custom_answer'] = trim(strip_tags($vars['custom_answer'])); $vars['custom_answer'] .= '; ' . date('Y-m-d H:i:s', $meta['first_install']); $vars['custom_answer'] = trim($vars['custom_answer'], ' ;'); if (empty($vars['survey']) || empty($vars['answers'])) { wp_send_json_error(); } $request_params = array('sslverify' => false, 'timeout' => 15, 'redirection' => 2); $request_args = array( 'action' => 'submit_survey', 'survey' => $vars['survey'], 'email' => $vars['emailme'], 'answers' => $vars['answers'], 'custom_answer' => $vars['custom_answer'], 'first_version' => $meta['first_version'], 'version' => UCP::$version, 'codebase' => 'free', 'site' => get_home_url() ); $url = add_query_arg($request_args, self::$licensing_servers[0]); $response = wp_remote_get(esc_url_raw($url), $request_params); if (is_wp_error($response) || !wp_remote_retrieve_body($response)) { $url = add_query_arg($request_args, self::$licensing_servers[1]); $response = wp_remote_get(esc_url_raw($url), $request_params); } $surveys[$vars['survey']] = time(); update_option(UCP_SURVEYS_KEY, $surveys); wp_send_json_success(); } // submit_survey_ajax // encode email for frontend use static function encode_email($email) { $len = strlen($email); $out = ''; for ($i = 0; $i < $len; $i++) { $out .= '&#' . ord($email[$i]) . ';'; } return $out; } // encode_email // parse shortcode alike variables static function parse_vars($string) { $org_string = $string; $vars = array( 'site-title' => get_bloginfo('name'), 'site-tagline' => get_bloginfo('description'), 'site-description' => get_bloginfo('description'), 'site-url' => trailingslashit(get_home_url()), 'wp-url' => trailingslashit(get_site_url()), 'site-login-url' => get_site_url() . '/wp-login.php' ); foreach ($vars as $var_name => $var_value) { $var_name = '[' . $var_name . ']'; $string = str_ireplace($var_name, $var_value, $string); } $string = apply_filters('ucp_parse_vars', $string, $org_string, $vars); return $string; } // parse_vars // generate HTML from social icons static function generate_social_icons($options, $template_id) { $out = ''; if (!empty($options['social_facebook'])) { $out .= ''; } if (!empty($options['social_twitter'])) { $out .= ''; } if (!empty($options['social_linkedin'])) { $out .= ''; } if (!empty($options['social_youtube'])) { $out .= ''; } if (!empty($options['social_vimeo'])) { $out .= ''; } if (!empty($options['social_pinterest'])) { $out .= ''; } if (!empty($options['social_dribbble'])) { $out .= ''; } if (!empty($options['social_behance'])) { $out .= ''; } if (!empty($options['social_instagram'])) { $out .= ''; } if (!empty($options['social_tumblr'])) { $out .= ''; } if (!empty($options['social_vk'])) { $out .= ''; } if (!empty($options['social_skype'])) { $out .= ''; } if (!empty($options['social_whatsapp'])) { $out .= ''; } if (!empty($options['social_telegram'])) { $out .= ''; } if (!empty($options['social_email'])) { $out .= ''; } if (!empty($options['social_phone'])) { $out .= ''; } return $out; } // generate_social_icons // shortcode for inserting things in header static function generate_head($options, $template_id) { $out = ''; $out .= '' . "\n"; $out .= '' . "\n"; $out .= '' . "\n"; $out .= '' . "\n"; $out .= ''; if (self::is_weglot_setup()) { $out .= ''; $out .= ''; } if (!empty($options['ga_tracking_id'])) { $out .= " "; } if (!empty($options['custom_css'])) { $out .= "\n" . ''; } $out = apply_filters('ucp_head', $out, $options, $template_id); return trim($out); } // generate_head // shortcode for inserting things in footer static function generate_footer($options, $template_id) { $out = ''; if ($options['linkback'] == '1') { $tmp = md5(get_site_url()); if ($tmp[0] < '4') { $out .= '

Create stunning under construction pages for WordPress. Completely free.

'; } elseif ($tmp[0] < '8') { $out .= '

Create a free under construction page for WordPress like this one in under a minute.

'; } elseif ($tmp[0] < 'c') { $out .= '

Join more than 400,000 happy people using the free Under Construction Page plugin for WordPress.

'; } else { $out .= '

Create free under construction pages for WordPress.

'; } } if ($options['login_button'] == '1') { if (is_user_logged_in()) { $out .= '
'; $out .= ''; } else { $out .= '
'; $out .= ''; } $out .= '
'; } $out = apply_filters('ucp_footer', $out, $options, $template_id); return $out; } // generate_footer // returnes parsed template static function get_template($template_id) { $vars = array(); $options = self::get_options(); $vars['version'] = self::$version; $vars['site-url'] = trailingslashit(get_home_url()); $vars['wp-url'] = trailingslashit(get_site_url()); $vars['theme-url'] = trailingslashit(UCP_PLUGIN_URL . 'themes/' . $template_id); $vars['theme-url-common'] = trailingslashit(UCP_PLUGIN_URL . 'themes'); $vars['title'] = self::parse_vars($options['title']); $vars['generator'] = esc_attr__('Free UnderConstructionPage plugin for WordPress', 'under-construction-page'); $vars['heading1'] = self::parse_vars($options['heading1']); $vars['content'] = nl2br(self::parse_vars($options['content'])); $vars['description'] = self::parse_vars($options['description']); $vars['social-icons'] = self::generate_social_icons($options, $template_id); $vars['head'] = self::generate_head($options, $template_id); $vars['footer'] = self::generate_footer($options, $template_id); $vars = apply_filters('ucp_get_template_vars', $vars, $template_id, $options); ob_start(); require UCP_PLUGIN_DIR . 'themes/' . $template_id . '/index.php'; $template = ob_get_clean(); foreach ($vars as $var_name => $var_value) { $var_name = '[' . $var_name . ']'; $template = str_ireplace($var_name, $var_value, $template); } $template = apply_filters('ucp_get_template', $template, $vars, $options); return $template; } // get_template // checks if construction mode is enabled for the current visitor static function is_construction_mode_enabled($settings_only = false) { $options = self::get_options(); $current_user = wp_get_current_user(); $override_status = apply_filters('ucp_is_construction_mode_enabled', null, $options); if (is_bool($override_status)) { return $override_status; } // just check if it's generally enabled if ($settings_only) { if ($options['status']) { return true; } else { return false; } } else { // check if enabled for current user if (!$options['status']) { return false; } elseif (self::user_has_role($options['whitelisted_roles'])) { return false; } elseif (in_array($current_user->ID, $options['whitelisted_users'])) { return false; } elseif (strlen($options['end_date']) === 16 && $options['end_date'] !== '0000-00-00 00:00' && $options['end_date'] < current_time('mysql')) { return false; } else { return true; } } } // is_construction_mode_enabled // check if user has the specified role static function user_has_role($roles) { $current_user = wp_get_current_user(); if ($current_user->roles) { $user_role = $current_user->roles[0]; } else { $user_role = 'guest'; } return in_array($user_role, $roles); } // user_has_role // frontend notification when UCP is enabled but current user is whitelisted static function whitelisted_notice() { $notices = get_option(UCP_NOTICES_KEY); $dismiss_url = add_query_arg(array('action' => 'ucp_dismiss_notice', 'notice' => 'whitelisted', 'redirect' => urlencode($_SERVER['REQUEST_URI'])), admin_url('admin.php')); if ( empty($notices['dismiss_whitelisted']) && is_user_logged_in() && self::is_construction_mode_enabled(true) && !self::is_construction_mode_enabled(false) ) // keeping everything inline due to minimal CSS echo '
X' . esc_attr__('Under Construction Mode is enabled but you are whitelisted so you see the normal site.', 'under-construction-page') . '
' . esc_attr__('Preview UnderConstructionPage', 'under-construction-page') . '
' . esc_attr__('Configure UnderConstructionPage', 'under-construction-page') . '
'; } // whitelisted_notification // displays various notices in admin header static function admin_notices() { $notices = get_option(UCP_NOTICES_KEY); $options = self::get_options(); $meta = self::get_meta(); $current_user = wp_get_current_user(); $shown = false; $promo = self::is_promo_active(); $name = ''; if (!empty($current_user->user_firstname)) { $name = ' ' . $current_user->user_firstname; } // pro activated - update if (self::is_plugin_page() && UCP_license::is_activated()) { echo '
'; echo '

Thank you for purchasing UnderConstructionPage PRO! Your license has been verified and activated.
To start using the PRO version, please follow these steps:

'; echo '
    '; echo '
  1. Download the latest version of the PRO plugin.
  2. '; echo '
  3. Go to Plugins - Add New - Upload Plugin and upload the ZIP you just downloaded.
  4. '; echo '
  5. If asked to replace (overwrite) the free version - confirm it.
  6. '; echo '
  7. Activate the plugin.
  8. '; echo '
  9. That\'s it, no more steps.
  10. '; echo '
'; echo '
'; $shown = true; return; } // ask for rating; disabled if ( false && empty($notices['dismiss_rate']) && (time() - $meta['first_install']) > (DAY_IN_SECONDS * 1.0) ) { $rate_url = 'https://wordpress.org/support/plugin/under-construction-page/reviews/?filter=5&rate=5#new-post'; $dismiss_url = add_query_arg(array('action' => 'ucp_dismiss_notice', 'notice' => 'rate', 'redirect' => urlencode($_SERVER['REQUEST_URI'])), admin_url('admin.php')); echo '

Hi' . esc_html($name) . '!
We saw you\'ve been using the plugin for a few days (that\'s awesome!) and wanted to ask for your help to make the plugin better.
We just need a minute of your time to rate the plugin. It helps us out a lot!'; echo '
' . esc_attr__('Help make the plugin better by rating it', 'under-construction-page') . ''; echo '    ' . esc_attr__('I\'ve already rated the plugin', 'under-construction-page') . ''; echo '

' . esc_attr__('Thank you very much! The UCP team', 'under-construction-page') . ''; echo '

'; $shown = true; } // end date in past if (self::is_plugin_page() && self::is_construction_mode_enabled(true) && !empty($options['end_date']) && $options['end_date'] != '0000-00-00 00:00' && $options['end_date'] < current_time('mysql')) { echo '

Under construction mode is enabled but the end date is set to a past date so the under construction page will not be shown. Either move the end date to a future date or disable it.

'; $shown = true; } // ask for translation // disabled till further notice if ( false && self::is_plugin_page() && empty($notices['dismiss_translate']) && (time() - $meta['first_install']) > 1 ) { $translate_url = self::generate_web_link('translate-notification', 'translate-the-plugin/'); $dismiss_url = add_query_arg(array('action' => 'ucp_dismiss_notice', 'notice' => 'translate', 'redirect' => urlencode($_SERVER['REQUEST_URI'])), admin_url('admin.php')); echo '

Hi' . esc_html($name) . ',
Help us translate UCP into your language and get a PRO license for free!
We want to make accessible to as many users as possible by translating it into their language. And we need your help!'; echo '
' . esc_attr__('Translate UCP into your language & get a PRO license for free', 'under-construction-page') . ''; echo '    ' . esc_attr__('I\'m not interested (remove this notice)', 'under-construction-page') . ''; echo '

'; $shown = true; } // promo for new users if ( self::is_plugin_page() && empty($notices['dismiss_welcome']) && !$shown && $promo == 'welcome' ) { $dismiss_url = add_query_arg(array('action' => 'ucp_dismiss_notice', 'notice' => 'welcome', 'redirect' => urlencode($_SERVER['REQUEST_URI'])), admin_url('admin.php')); echo '

Hi' . esc_html($name) . ',
'; echo 'We have a special time-sensitive offer available just for another 59min! A 20% DISCOUNT on our most popular lifetime licenses!
No nonsense! Pay once and use the plugin forever. Get more than 50+ extra features, 250+ premium themes and over two million professional images.

'; echo 'Upgrade to PRO now with a SPECIAL 20% WELCOME DISCOUNT'; echo '    ' . esc_attr__('I\'m not interested (remove this notice)', 'under-construction-page') . ''; echo '

'; $shown = true; } // promo for old users if ( self::is_plugin_page() && empty($notices['dismiss_olduser']) && !$shown && $promo == 'olduser' ) { $dismiss_url = add_query_arg(array('action' => 'ucp_dismiss_notice', 'notice' => 'olduser', 'redirect' => urlencode($_SERVER['REQUEST_URI'])), admin_url('admin.php')); echo '

Hi' . esc_html($name) . ',
'; echo 'We have a special offer only for users like you who\'ve been using the UnderConstructionPage for a longer period of time: a special DISCOUNT on our most popular lifetime licenses!
No nonsense! Pay once and use the plugin forever.
Upgrade now to PRO & get more than 50+ extra features, 220+ premium themes and over two million HD images.

'; echo 'Upgrade to PRO now with a SPECIAL DISCOUNT'; echo '    ' . esc_attr__('I\'m not interested (remove this notice)', 'under-construction-page') . ''; echo '

'; $shown = true; } } // notices // handle dismiss button for notices static function dismiss_notice() { if (empty($_GET['notice'])) { wp_safe_redirect(admin_url()); exit; } $notices = get_option(UCP_NOTICES_KEY, array()); $notice = sanitize_text_field($_GET['notice']); if ($notice == 'rate') { $notices['dismiss_rate'] = true; } elseif ($notice == 'translate') { $notices['dismiss_translate'] = true; } elseif ($notice == 'whitelisted') { $notices['dismiss_whitelisted'] = true; } elseif ($notice == 'olduser') { $notices['dismiss_olduser'] = true; } elseif ($notice == 'welcome') { $notices['dismiss_welcome'] = true; } else { wp_safe_redirect(admin_url()); exit; } update_option(UCP_NOTICES_KEY, $notices); if (!empty($_GET['redirect'])) { wp_safe_redirect($_GET['redirect']); } else { wp_safe_redirect(admin_url()); } exit; } // dismiss_notice // reset all settings to default values static function reset_settings() { check_admin_referer('ucp_reset_settings'); if (false === current_user_can('administrator')) { wp_safe_redirect(admin_url()); exit; } $options = self::default_options(); update_option(UCP_OPTIONS_KEY, $options); if (!empty($_GET['redirect'])) { wp_safe_redirect($_GET['redirect']); } else { wp_safe_redirect(admin_url()); } exit; } // reset_settings // change status via admin bar static function change_status() { check_admin_referer('ucp_change_status'); if (false === current_user_can('administrator') || empty($_GET['new_status'])) { wp_safe_redirect(admin_url()); exit; } $options = self::get_options(); if (sanitize_text_field($_GET['new_status']) == 'enabled') { $options['status'] = '1'; } else { $options['status'] = '0'; } update_option(UCP_OPTIONS_KEY, $options); if (!empty($_GET['redirect'])) { wp_safe_redirect($_GET['redirect']); } else { wp_safe_redirect(admin_url()); } exit; } // change_status static function admin_bar_style() { // admin bar has to be anabled, user an admin and custom filter true if (false === is_admin_bar_showing() || false === current_user_can('administrator') || false === apply_filters('ucp_show_admin_bar', true)) { return; } // no sense in loading a new CSS file for 2 lines of CSS echo ''; } // admin_bar_style // add admin bar menu and status static function admin_bar() { global $wp_admin_bar; // only show to admins if (false === current_user_can('administrator') || false === apply_filters('ucp_show_admin_bar', true)) { return; } if (self::is_construction_mode_enabled(true)) { $main_label = '' . esc_attr__('Under construction mode is enabled', 'under-construction-page') . ' ' . esc_attr__('UnderConstruction', 'under-construction-page') . ' '; $class = 'ucp-enabled'; $action_url = add_query_arg(array('action' => 'ucp_change_status', 'new_status' => 'disabled', 'redirect' => urlencode($_SERVER['REQUEST_URI'])), admin_url('admin.php')); $action_url = wp_nonce_url($action_url, 'ucp_change_status'); $action = esc_attr__('Under Construction Mode', 'under-construction-page'); $action .= 'OFFON'; } else { $main_label = '' . esc_attr__('Under construction mode is disabled', 'under-construction-page') . ' ' . esc_attr__('UnderConstruction', 'under-construction-page') . ' '; $class = 'ucp-disabled'; $action_url = add_query_arg(array('action' => 'ucp_change_status', 'new_status' => 'enabled', 'redirect' => urlencode($_SERVER['REQUEST_URI'])), admin_url('admin.php')); $action_url = wp_nonce_url($action_url, 'ucp_change_status'); $action = esc_attr__('Under Construction Mode', 'under-construction-page'); $action .= 'OFFON'; } $wp_admin_bar->add_menu(array( 'parent' => '', 'id' => 'under-construction-page', 'title' => $main_label, 'href' => admin_url('options-general.php?page=ucp'), 'meta' => array('class' => $class) )); $wp_admin_bar->add_node(array( 'id' => 'ucp-status', 'title' => $action, 'href' => false, 'parent' => 'under-construction-page' )); $wp_admin_bar->add_node(array( 'id' => 'ucp-preview', 'title' => esc_attr__('Preview', 'under-construction-page'), 'meta' => array('target' => 'blank'), 'href' => get_home_url() . '/?ucp_preview', 'parent' => 'under-construction-page' )); $wp_admin_bar->add_node(array( 'id' => 'ucp-settings', 'title' => esc_attr__('Settings', 'under-construction-page'), 'href' => admin_url('options-general.php?page=ucp'), 'parent' => 'under-construction-page' )); } // admin_bar // show under construction notice on WP login form static function login_message($message) { if (self::is_construction_mode_enabled(true)) { $message .= '
' . esc_attr__('Under Construction Mode is enabled.', 'under-construction-page') . '
'; } return $message; } // login_notice // add settings link to plugins page static function plugin_action_links($links) { $settings_link = '' . esc_attr__('Settings', 'under-construction-page') . ''; $pro_link = '' . __('Go PRO', 'under-construction-page') . ''; array_unshift($links, $pro_link); array_unshift($links, $settings_link); return $links; } // plugin_action_links // add links to plugin's description in plugins table static function plugin_meta_links($links, $file) { $support_link = '' . esc_attr__('Support', 'under-construction-page') . ''; $pro_link = '' . __('Get the PRO version', 'under-construction-page') . ''; if ($file == plugin_basename(__FILE__)) { $links[] = $support_link; $links[] = $pro_link; } return $links; } // plugin_meta_links // additional powered by text in admin footer; only on UCP page static function admin_footer_text($text) { if (!self::is_plugin_page()) { return $text; } $text = '' . esc_attr__('UnderConstructionPage', 'under-construction-page') . ' v' . self::$version . ' by ' . esc_attr__('WebFactory Ltd', 'under-construction-page') . '. Please rate the plugin ★★★★★ to help us spread the word. Thank you!'; return $text; } // admin_footer_text // fix for opening the plugin install modal static function admin_footer() { if (empty($_GET['fix-install-button']) || empty($_GET['tab']) || sanitize_text_field($_GET['tab']) != 'plugin-information') { return; } echo ''; } // admin_footer // test if we're on plugin's page static function is_plugin_page() { $current_screen = get_current_screen(); if ($current_screen->id == 'settings_page_ucp') { return true; } else { return false; } } // is_plugin_page // create the admin menu item static function admin_menu() { add_options_page(esc_attr__('UnderConstruction', 'under-construction-page'), esc_attr__('UnderConstruction', 'under-construction-page'), 'manage_options', 'ucp', array(__CLASS__, 'main_page')); } // admin_menu // all settings are saved in one option static function register_settings() { register_setting(UCP_OPTIONS_KEY, UCP_OPTIONS_KEY, array(__CLASS__, 'sanitize_settings')); } // register_settings // set default settings static function default_options() { $defaults = array( 'status' => '0', 'license_key' => '', 'license_active' => false, 'license_expires' => '1900-01-01', 'license_type' => '', 'end_date' => '', 'ga_tracking_id' => '', 'theme' => 'mad_designer', 'custom_css' => '', 'title' => '[site-title] is under construction', 'description' => '[site-tagline]', 'heading1' => esc_attr__('Sorry, we\'re doing some work on the site', 'under-construction-page'), 'content' => esc_attr__('Thank you for being patient. We are doing some work on the site and will be back shortly.', 'under-construction-page'), 'social_facebook' => '', 'social_twitter' => '', 'social_linkedin' => '', 'social_youtube' => '', 'social_vimeo' => '', 'social_pinterest' => '', 'social_dribbble' => '', 'social_behance' => '', 'social_instagram' => '', 'social_tumblr' => '', 'social_vk' => '', 'social_email' => '', 'social_phone' => '', 'social_skype' => '', 'social_telegram' => '', 'social_whatsapp' => '', 'login_button' => '1', 'linkback' => '0', 'whitelisted_roles' => array('administrator'), 'whitelisted_users' => array() ); return $defaults; } // default_options // sanitize settings on save static function sanitize_settings($options) { $old_options = self::get_options(); foreach ($options as $key => $value) { switch ($key) { case 'title': case 'description': $options[$key] = trim(strip_tags($value)); break; case 'heading1': case 'content': $options[$key] = trim(wp_kses($value, wp_kses_allowed_html('post'))); break; case 'custom_css': case 'social_facebook': case 'social_twitter': case 'social_linkedin': case 'social_youtube': case 'social_vimeo': case 'social_pinterest': case 'social_dribbble': case 'social_behance': case 'social_instagram': case 'social_tumblr': case 'social_vk': case 'social_email': case 'social_phone': case 'social_telegram': case 'social_whatsapp': case 'license_key': $options[$key] = trim(strip_tags($value)); break; case 'ga_tracking_id': $options[$key] = substr(strtoupper(trim($value)), 0, 15); break; case 'end_date': $options[$key] = substr(trim($value), 0, 16); break; } // switch } // foreach $options['title'] = strip_tags($options['title']); $options['description'] = strip_tags($options['description']); $options['heading1'] = strip_tags($options['heading1'], '

'); $options['content'] = strip_tags($options['content'], '