| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if( ! class_exists( 'MywpShortcodeAbstractModule' ) ) { |
| 8 |
return false; |
| 9 |
} |
| 10 |
|
| 11 |
if ( ! class_exists( 'MywpShortcodeModuleUrl' ) ) : |
| 12 |
|
| 13 |
final class MywpShortcodeModuleUrl extends MywpShortcodeAbstractModule { |
| 14 |
|
| 15 |
protected static $id = 'mywp_url'; |
| 16 |
|
| 17 |
public static function do_shortcode( $atts = false , $content = false , $tag = false ) { |
| 18 |
|
| 19 |
if( empty( $atts['site_id'] ) && empty( $atts['blog_id']) ) { |
| 20 |
|
| 21 |
$site_id = get_current_blog_id(); |
| 22 |
|
| 23 |
} else { |
| 24 |
|
| 25 |
if( ! empty( $atts['site_id'] ) ) { |
| 26 |
|
| 27 |
$site_id = (int) $atts['site_id']; |
| 28 |
|
| 29 |
} elseif( ! empty( $atts['blog_id'] ) ) { |
| 30 |
|
| 31 |
$site_id = (int) $atts['blog_id']; |
| 32 |
|
| 33 |
} |
| 34 |
|
| 35 |
} |
| 36 |
|
| 37 |
if( (int) get_current_blog_id() === (int) $site_id ) { |
| 38 |
|
| 39 |
$site_id = false; |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
if( ! empty( $atts['admin'] ) ) { |
| 44 |
|
| 45 |
$url = admin_url( $site_id ); |
| 46 |
|
| 47 |
if( ! empty( $site_id ) ) { |
| 48 |
|
| 49 |
$url = get_admin_url( $site_id ); |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
} elseif( ! empty( $atts['network_admin'] ) ) { |
| 54 |
|
| 55 |
if( is_multisite() ) { |
| 56 |
|
| 57 |
$url = network_admin_url(); |
| 58 |
|
| 59 |
} else { |
| 60 |
|
| 61 |
$url = admin_url( $site_id ); |
| 62 |
|
| 63 |
if( ! empty( $site_id ) ) { |
| 64 |
|
| 65 |
$url = get_admin_url( $site_id ); |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
} elseif( ! empty( $atts['network_site'] ) ) { |
| 72 |
|
| 73 |
if( is_multisite() ) { |
| 74 |
|
| 75 |
$url = network_site_url(); |
| 76 |
|
| 77 |
} else { |
| 78 |
|
| 79 |
$url = get_site_url( $site_id ); |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
} elseif( ! empty( $atts['site'] ) ) { |
| 84 |
|
| 85 |
$url = get_site_url( $site_id ); |
| 86 |
|
| 87 |
} elseif( ! empty( $atts['post_id'] ) ) { |
| 88 |
|
| 89 |
$url = get_permalink( (int) $atts['post_id'] ); |
| 90 |
|
| 91 |
} elseif( ! empty( $atts['login'] ) ) { |
| 92 |
|
| 93 |
$url = wp_login_url(); |
| 94 |
|
| 95 |
} elseif( ! empty( $atts['logout'] ) ) { |
| 96 |
|
| 97 |
$url = wp_logout_url(); |
| 98 |
|
| 99 |
} elseif( ! empty( $atts['lost_password'] ) ) { |
| 100 |
|
| 101 |
$url = wp_lostpassword_url(); |
| 102 |
|
| 103 |
} elseif( ! empty( $atts['current'] ) ) { |
| 104 |
|
| 105 |
if( is_ssl() ) { |
| 106 |
|
| 107 |
$scheme = 'https'; |
| 108 |
|
| 109 |
} else { |
| 110 |
|
| 111 |
$scheme = 'http'; |
| 112 |
|
| 113 |
} |
| 114 |
|
| 115 |
$url = $scheme . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
| 116 |
|
| 117 |
} else { |
| 118 |
|
| 119 |
$url = home_url(); |
| 120 |
|
| 121 |
if( ! empty( $site_id ) ) { |
| 122 |
|
| 123 |
$url = get_home_url( $site_id ); |
| 124 |
|
| 125 |
} |
| 126 |
|
| 127 |
} |
| 128 |
|
| 129 |
if( ! empty( $atts['esc_url'] ) ) { |
| 130 |
|
| 131 |
$url = esc_url( $url ); |
| 132 |
|
| 133 |
} |
| 134 |
|
| 135 |
$content = apply_filters( 'mywp_shortcode_url' , $url , $atts ); |
| 136 |
|
| 137 |
return $content; |
| 138 |
|
| 139 |
} |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
MywpShortcodeModuleUrl::init(); |
| 144 |
|
| 145 |
endif; |
| 146 |
|