| 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( 'MywpShortcodeModuleSite' ) ) : |
| 12 |
|
| 13 |
final class MywpShortcodeModuleSite extends MywpShortcodeAbstractModule { |
| 14 |
|
| 15 |
protected static $id = 'mywp_site'; |
| 16 |
|
| 17 |
public static function do_shortcode( $atts , $content = false , $tag ) { |
| 18 |
|
| 19 |
if( empty( $atts['field'] ) ) { |
| 20 |
|
| 21 |
MywpHelper::error_not_found_message( '$atts["field"]' , sprintf( '[%s] shortcode' , self::$id ) ); |
| 22 |
|
| 23 |
return $content; |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
$field = strip_tags( $atts['field'] ); |
| 28 |
|
| 29 |
$current_site_id = get_current_blog_id(); |
| 30 |
|
| 31 |
if( empty( $atts['site_id'] ) && empty( $atts['blog_id']) ) { |
| 32 |
|
| 33 |
$site_id = get_current_blog_id(); |
| 34 |
|
| 35 |
} else { |
| 36 |
|
| 37 |
if( ! empty( $atts['site_id'] ) ) { |
| 38 |
|
| 39 |
$site_id = intval( $atts['site_id'] ); |
| 40 |
|
| 41 |
} elseif( ! empty( $atts['blog_id'] ) ) { |
| 42 |
|
| 43 |
$site_id = intval( $atts['blog_id'] ); |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
if( is_multisite() && $site_id !== $current_site_id ) { |
| 50 |
|
| 51 |
switch_to_blog( $site_id ); |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
if( $field === 'id' ) { |
| 56 |
|
| 57 |
$content = $site_id; |
| 58 |
|
| 59 |
} elseif( $field === 'name' ) { |
| 60 |
|
| 61 |
$content = get_bloginfo( 'name' ); |
| 62 |
|
| 63 |
} else { |
| 64 |
|
| 65 |
MywpHelper::error_not_found_message( '$atts["field"]' , sprintf( '[%s] shortcode' , self::$id ) ); |
| 66 |
|
| 67 |
return $content; |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
if( is_multisite() && $site_id !== $current_site_id ) { |
| 72 |
|
| 73 |
restore_current_blog(); |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
$content = apply_filters( 'mywp_shortcode_site' , $content , $atts ); |
| 78 |
|
| 79 |
return $content; |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
MywpShortcodeModuleSite::init(); |
| 86 |
|
| 87 |
endif; |
| 88 |
|