| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: Secure Admin |
|---|
| 4 | Plugin URI: http://http://wordpress.org/extend/plugins/secure-admin/ |
|---|
| 5 | Description: Secures Login and Admin pages using Private or Shared SSL |
|---|
| 6 | Author: Ryan Boren and Robert Accettura |
|---|
| 7 | Version: 0.3b1 |
|---|
| 8 | |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | // |
|---|
| 12 | // What protocol |
|---|
| 13 | // |
|---|
| 14 | function http() { |
|---|
| 15 | if ( 'on' == $_SERVER['HTTPS'] ) |
|---|
| 16 | return 'https'; |
|---|
| 17 | return 'http'; |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | // |
|---|
| 21 | // Get the blog domain for both MU or Single installs |
|---|
| 22 | // |
|---|
| 23 | function sa_blog_domain(){ |
|---|
| 24 | global $current_blog; |
|---|
| 25 | if(isset($current_blog)){ |
|---|
| 26 | return $current_blog->domain; |
|---|
| 27 | } |
|---|
| 28 | return str_replace('http://', '', get_option('siteurl')); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | // |
|---|
| 32 | // If https is requested, present https links. |
|---|
| 33 | // |
|---|
| 34 | function sa_ob_handler($buffer) { |
|---|
| 35 | $replace_this = $with_this = array(); |
|---|
| 36 | |
|---|
| 37 | $siteurl = get_option('siteurl'); |
|---|
| 38 | $blogdomain = sa_blog_domain(); |
|---|
| 39 | |
|---|
| 40 | $replace_this[] = $siteurl . '/wp-admin'; |
|---|
| 41 | $with_this[] = "https://{$blogdomain}/wp-admin"; |
|---|
| 42 | |
|---|
| 43 | $replace_this[] = $siteurl . '/wp-login.php'; |
|---|
| 44 | $with_this[] = "https://{$blogdomain}/wp-login.php"; |
|---|
| 45 | |
|---|
| 46 | if( function_exists('is_redirected_domain') && is_redirected_domain() == false ) { |
|---|
| 47 | $replace_this[] = $siteurl . '/wp-comments-post.php'; |
|---|
| 48 | $with_this[] = "https://{$blogdomain}/wp-comments-post.php"; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | if ( is_admin() ) { |
|---|
| 52 | $replace_this[] = $includes_url = $siteurl . '/wp-includes'; |
|---|
| 53 | $with_this[] = preg_replace('/^https?/', 'https', $includes_url); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | if ( is_preview() && ( 'on' == $_SERVER['HTTPS'] ) ) { |
|---|
| 57 | $replace_this[] = $siteurl; |
|---|
| 58 | $with_this[] = preg_replace('/^https?/', 'https', $siteurl); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | if ( defined('STATIC_HOST') ) { |
|---|
| 62 | $replace_this[] = STATIC_HOST; |
|---|
| 63 | $with_this[] = preg_replace('/^https?/', 'https', STATIC_HOST); |
|---|
| 64 | } |
|---|
| 65 | return (str_replace($replace_this, $with_this, $buffer)); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | // |
|---|
| 69 | // Use secure post links when linking to posts from a secure page. |
|---|
| 70 | // |
|---|
| 71 | function sa_post_link($link) { |
|---|
| 72 | global $pagenow; |
|---|
| 73 | |
|---|
| 74 | if ( ('on' == $_SERVER['HTTPS']) && ('wp-comments-post.php' != $pagenow) ) |
|---|
| 75 | $link = preg_replace('/^https?/', 'https', $link); |
|---|
| 76 | return $link; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | // |
|---|
| 80 | // Use secure links when using edit links |
|---|
| 81 | // |
|---|
| 82 | function sa_edit_items_link($link) { |
|---|
| 83 | if ( strpos($link, 'wp-admin') !== false ) |
|---|
| 84 | $link = str_replace('http://', 'https://', $link); |
|---|
| 85 | return $link; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | function sa_register_ob_handler() { |
|---|
| 90 | if ('on' == $_SERVER['HTTPS']) |
|---|
| 91 | ob_start('sa_ob_handler'); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | add_action('init', 'sa_register_ob_handler'); |
|---|
| 95 | add_filter('preview_post_link', 'sa_post_link'); |
|---|
| 96 | add_filter('preview_page_link', 'sa_post_link'); |
|---|
| 97 | add_filter('edit_post_link', 'sa_edit_items_link'); |
|---|
| 98 | add_filter('edit_comment_link', 'sa_edit_items_link'); |
|---|
| 99 | |
|---|
| 100 | ?> |
|---|