-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
75 lines (65 loc) · 2.64 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* Plugin Name: WP Mobile Detect Shortcodes
* Description: Lightweight plugin that creates shortcodes to show or hide content based on the user's device, this uses the Mobile Detect Library https://github.com/serbanghita/Mobile-Detect
* Version: 0.0.1
* Author: MarcoLeeJr
* Author URI: https://github.com/marcoleejr
* License: GPL v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
require_once( __DIR__ . "/Mobile_Detect.php");
if (!class_exists('WP_Mobile_Detect_Shortcodes_MarcoLeeJr')) {
class WP_Mobile_Detect_Shortcodes_MarcoLeeJr {
public $detect;
function __construct() {
$this->detect = new WPMDS_Mobile_Detect;
add_shortcode('show_in_desktop', array($this, 'show_in_desktop'));
add_shortcode('show_in_mobile', array($this, 'show_in_mobile'));
add_shortcode('show_in_iOS', array($this, 'show_in_iOS'));
add_shortcode('show_in_android', array($this, 'show_in_android'));
add_shortcode('show_in_tablet', array($this, 'show_in_tablet'));
}
// [show_in_desktop] shortcode
public function show_in_desktop($atts, $content = null) {
if(!$this->detect->isMobile()) {
return wpautop( do_shortcode( $content ) );
} else {
return null;
}
}
// [show_in_mobile] excluding tablets shortcode
public function show_in_mobile($atts, $content = null) {
if($this->detect->isMobile() && !$this->detect->isTablet()){
return wpautop( do_shortcode( $content ) );
} else {
return null;
}
}
// [show_in_iOS] shortcode
public function show_in_iOS($atts, $content = null) {
if($this->detect->isiOS()) {
return wpautop( do_shortcode( $content ) );
} else {
return null;
}
}
// [show_in_android] shortcode
public function show_in_android($atts, $content = null) {
if($this->detect->isAndroidOS()) {
return wpautop( do_shortcode( $content ) );
} else {
return null;
}
}
// [show_in_tablet] shortcode
public function show_in_tablet($atts, $content = null) {
if($this->detect->isTablet()) {
return wpautop( do_shortcode( $content ) );
} else {
return null;
}
}
}
$WP_Mobile_Detect_Shortcodes_MarcoLeeJr = new WP_Mobile_Detect_Shortcodes_MarcoLeeJr();
}