| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /** |
|---|
| 4 | * Public side of the plugin. |
|---|
| 5 | * |
|---|
| 6 | * @link http://www.webfactoryltd.com |
|---|
| 7 | * @since 0.1 |
|---|
| 8 | */ |
|---|
| 9 | |
|---|
| 10 | /* Include important files. */ |
|---|
| 11 | require_once 'include/functions.php'; |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | function csmm_plugin_init() { |
|---|
| 15 | // just to be on the safe side |
|---|
| 16 | if (defined('DOING_CRON') && DOING_CRON) { |
|---|
| 17 | return false; |
|---|
| 18 | } |
|---|
| 19 | if (defined('DOING_AJAX') && DOING_AJAX) { |
|---|
| 20 | return false; |
|---|
| 21 | } |
|---|
| 22 | if (defined('WP_CLI') && WP_CLI) { |
|---|
| 23 | return false; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | add_action('wp_ajax_csmm_subscribe_hide', 'csmm_subscribe_hide'); |
|---|
| 27 | |
|---|
| 28 | // Plugin options from the database |
|---|
| 29 | $signals_csmm_options = csmm_get_options(); |
|---|
| 30 | |
|---|
| 31 | // Getting custom login URL for the admin |
|---|
| 32 | $signals_login_url = wp_login_url(); |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | // Checking for the server protocol status |
|---|
| 36 | if ( isset($_SERVER['HTTPS']) === true ) { |
|---|
| 37 | $signals_protocol = 'https'; |
|---|
| 38 | } else { |
|---|
| 39 | $signals_protocol = 'http'; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | // This is the server address of the current page |
|---|
| 44 | if(isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_URI'])){ |
|---|
| 45 | $signals_server_url = $signals_protocol . '://' . sanitize_url(wp_unslash($_SERVER['HTTP_HOST'])) . parse_url(sanitize_url(wp_unslash($_SERVER['REQUEST_URI'])), PHP_URL_PATH); |
|---|
| 46 | } |
|---|
| 47 | // Checking for the custom_login_url value |
|---|
| 48 | if ( empty( $signals_csmm_options['custom_login_url'] ) ) { |
|---|
| 49 | $signals_csmm_options['custom_login_url'] = NULL; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | if(isset($_GET['preview_coming_soon']) && isset($_GET['_wpnonce']) && current_user_can('manage_options') && wp_verify_nonce(sanitize_key(wp_unslash($_GET['_wpnonce'])), 'csmm_preview')){ |
|---|
| 53 | csmm_render_template( $signals_csmm_options ); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | // Not for the backend |
|---|
| 57 | // Only modifies the frontend of the system |
|---|
| 58 | if ( ! is_admin() ) { |
|---|
| 59 | if ( '1' == $signals_csmm_options['status'] ) { |
|---|
| 60 | |
|---|
| 61 | /** |
|---|
| 62 | * A lot of checks are going on over here. |
|---|
| 63 | * We are checking for admin role, crawler status, and important wordpress pages to bypass. |
|---|
| 64 | * If the admin decides to exclude search engine from viewing the plugin, the website will be shown. |
|---|
| 65 | */ |
|---|
| 66 | |
|---|
| 67 | if ( false === strpos( $signals_server_url, '/wp-login.php' ) |
|---|
| 68 | && false === strpos( $signals_server_url, '/wp-admin/' ) |
|---|
| 69 | && false === strpos( $signals_server_url, '/async-upload.php' ) |
|---|
| 70 | && false === strpos( $signals_server_url, '/upgrade.php' ) |
|---|
| 71 | && false === strpos( $signals_server_url, '/plugins/' ) |
|---|
| 72 | && false === strpos( $signals_server_url, '/xmlrpc.php' ) |
|---|
| 73 | && false === strpos( $signals_server_url, $signals_login_url ) |
|---|
| 74 | && (empty($signals_csmm_options['custom_login_url']) || false === strpos( $signals_server_url, $signals_csmm_options['custom_login_url']) ) ) { |
|---|
| 75 | |
|---|
| 76 | // Checking for the search engine option |
|---|
| 77 | if ( '1' == $signals_csmm_options['exclude_se'] ) { |
|---|
| 78 | if ( ! csmm_check_referrer() ) { |
|---|
| 79 | if ( '1' == $signals_csmm_options['show_logged_in'] ) { |
|---|
| 80 | // Checking if the user is logged in or not |
|---|
| 81 | if ( ! is_user_logged_in() ) { |
|---|
| 82 | // Render the maintenance mode template since the user is not logged in |
|---|
| 83 | csmm_render_template( $signals_csmm_options ); |
|---|
| 84 | } |
|---|
| 85 | } else { |
|---|
| 86 | // Render the maintenance mode template |
|---|
| 87 | csmm_render_template( $signals_csmm_options ); |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | } else { |
|---|
| 91 | if ( '1' == $signals_csmm_options['show_logged_in'] ) { |
|---|
| 92 | // Checking if the user is logged in or not |
|---|
| 93 | if ( ! is_user_logged_in() ) { |
|---|
| 94 | // Render the maintenance mode template since the user is not logged in |
|---|
| 95 | csmm_render_template( $signals_csmm_options ); |
|---|
| 96 | } |
|---|
| 97 | } else { |
|---|
| 98 | // Render the maintenance mode template. |
|---|
| 99 | csmm_render_template( $signals_csmm_options ); |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | add_action( 'init', 'csmm_plugin_init' ); |
|---|
| 107 | |
|---|
| 108 | function csmm_subscribe_hide() { |
|---|
| 109 | set_transient('csmm_subscribe_hide', true, DAY_IN_SECONDS * 90); |
|---|
| 110 | |
|---|
| 111 | wp_send_json_success(); |
|---|
| 112 | } // csmm_subscribe_hide |
|---|