Passed
Push — master ( de7162...f256de )
by Brian
739:27 queued 623:54
created

AyeCode_UI_Plugin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 81
c 1
b 0
f 1
dl 0
loc 123
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A maybe_show_examples() 0 9 3
B get_examples() 0 95 1
1
<?php
2
/*
3
Plugin Name: AyeCode UI
4
Plugin URI: https://ayecode.io/
5
Description: This is an example plugin to test AyeCode UI Quickly.
6
Version: 1.0.0
7
Author: AyeCode Ltd
8
Author URI: https://userswp.io
9
License: GPL-2.0+
10
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
11
Text Domain: ayecode-ui
12
Domain Path: /languages
13
Requires at least: 4.9
14
Tested up to: 5.4
15
*/
16
17
// If this file is called directly, abort.
18
if ( ! defined( 'WPINC' ) ) {
19
	die;
20
}
21
22
class AyeCode_UI_Plugin {
23
24
	/**
25
	 * AUI Plugin constructor.
26
	 *
27
	 * @since 1.0.0
28
	 */
29
	public function __construct() {
30
31
		// load AUI
32
		require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' );
33
34
		// Maybe show example page
35
		add_action( 'template_redirect', array( $this,'maybe_show_examples' ) );
36
	}
37
38
	public function maybe_show_examples(){
39
		if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
40
			echo "<head>";
41
			wp_head();
42
			echo "</head>";
43
			echo "<body>";
44
			echo $this->get_examples();
45
			echo "</body>";
46
			exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
47
		}
48
	}
49
50
	public function get_examples(){
51
		$output = '';
52
53
54
		// open form
55
		$output .= "<form class='p-5 m-5 border rounded'>";
56
57
		// input example
58
		$output .= aui()->input(array(
59
			'type'  =>  'text',
60
			'id'    =>  'text-example',
61
			'name'    =>  'text-example',
62
			'placeholder'   => 'text placeholder',
63
			'title'   => 'Text input example',
64
			'value' =>  '',
65
			'required'  => false,
66
			'help_text' => 'help text',
67
			'label' => 'Text input example label'
68
		));
69
70
		// input example
71
		$output .= aui()->input(array(
72
			'type'  =>  'url',
73
			'id'    =>  'text-example2',
74
			'name'    =>  'text-example',
75
			'placeholder'   => 'url placeholder',
76
			'title'   => 'Text input example',
77
			'value' =>  '',
78
			'required'  => false,
79
			'help_text' => 'help text',
80
			'label' => 'Text input example label'
81
		));
82
83
		// checkbox example
84
		$output .= aui()->input(array(
85
			'type'  =>  'checkbox',
86
			'id'    =>  'checkbox-example',
87
			'name'    =>  'checkbox-example',
88
			'placeholder'   => 'checkbox-example',
89
			'title'   => 'Checkbox example',
90
			'value' =>  '1',
91
			'checked'   => true,
92
			'required'  => false,
93
			'help_text' => 'help text',
94
			'label' => 'Checkbox checked'
95
		));
96
97
		// checkbox example
98
		$output .= aui()->input(array(
99
			'type'  =>  'checkbox',
100
			'id'    =>  'checkbox-example2',
101
			'name'    =>  'checkbox-example2',
102
			'placeholder'   => 'checkbox-example',
103
			'title'   => 'Checkbox example',
104
			'value' =>  '1',
105
			'checked'   => false,
106
			'required'  => false,
107
			'help_text' => 'help text',
108
			'label' => 'Checkbox un-checked'
109
		));
110
111
		// switch example
112
		$output .= aui()->input(array(
113
			'type'  =>  'checkbox',
114
			'id'    =>  'switch-example',
115
			'name'    =>  'switch-example',
116
			'placeholder'   => 'checkbox-example',
117
			'title'   => 'Switch example',
118
			'value' =>  '1',
119
			'checked'   => true,
120
			'switch'    => true,
121
			'required'  => false,
122
			'help_text' => 'help text',
123
			'label' => 'Switch on'
124
		));
125
126
		// switch example
127
		$output .= aui()->input(array(
128
			'type'  =>  'checkbox',
129
			'id'    =>  'switch-example2',
130
			'name'    =>  'switch-example2',
131
			'placeholder'   => 'checkbox-example',
132
			'title'   => 'Switch example',
133
			'value' =>  '1',
134
			'checked'   => false,
135
			'switch'    => true,
136
			'required'  => false,
137
			'help_text' => 'help text',
138
			'label' => 'Switch off'
139
		));
140
141
		// close form
142
		$output .= "</form>";
143
144
		return $output;
145
	}
146
}
147
new AyeCode_UI_Plugin();