1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* WordPress Settings |
4
|
|
|
* |
5
|
|
|
* Add setting pages with Amarkal UI components to your WordPress theme or |
6
|
|
|
* plugin. |
7
|
|
|
* |
8
|
|
|
* @package amarkal-settings |
9
|
|
|
* @depends amarkal-ui |
10
|
|
|
* @author Askupa Software <[email protected]> |
11
|
|
|
* @link https://github.com/askupasoftware/amarkal-settings |
12
|
|
|
* @copyright 2017 Askupa Software |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
// Prevent direct file access |
16
|
|
|
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Prevent loading the library more than once |
20
|
|
|
*/ |
21
|
|
|
if( defined( 'AMARKAL_SETTINGS' ) ) return false; |
22
|
|
|
define( 'AMARKAL_SETTINGS', true ); |
23
|
|
|
|
24
|
|
|
if(!function_exists('amarkal_add_settings_page')) |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Add a new settings page |
28
|
|
|
* |
29
|
|
|
* @param [array] $args |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
|
|
function amarkal_add_settings_page( $args ) |
33
|
|
|
{ |
34
|
|
|
$manager = Amarkal\Settings\Manager::get_instance(); |
35
|
|
|
return $manager->add_settings_page($args); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
if(!function_exists('amarkal_get_settings_page')) |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* Get a settings page instance |
43
|
|
|
* |
44
|
|
|
* @param string $slug |
45
|
|
|
* @return Amarkal\Settings\SettingsPage |
46
|
|
|
*/ |
47
|
|
|
function amarkal_get_settings_page( $slug ) |
48
|
|
|
{ |
49
|
|
|
$manager = Amarkal\Settings\Manager::get_instance(); |
50
|
|
|
return $manager->get_settings_page($slug); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if(!function_exists('amarkal_get_settings_value')) |
55
|
|
|
{ |
56
|
|
|
/** |
57
|
|
|
* Get the value of the given settings field |
58
|
|
|
* |
59
|
|
|
* @param string $slug |
60
|
|
|
* @param string $field_name |
61
|
|
|
* @return any |
62
|
|
|
*/ |
63
|
|
|
function amarkal_get_settings_value( $slug, $field_name ) |
64
|
|
|
{ |
65
|
|
|
$manager = Amarkal\Settings\Manager::get_instance(); |
66
|
|
|
$page = $manager->get_settings_page($slug); |
67
|
|
|
return $page->get_field_value($field_name); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if(!function_exists('amarkal_get_settings_values')) |
72
|
|
|
{ |
73
|
|
|
/** |
74
|
|
|
* Get all the values for the given settings page as an array |
75
|
|
|
* |
76
|
|
|
* @param string $slug |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
function amarkal_get_settings_values( $slug ) |
80
|
|
|
{ |
81
|
|
|
$manager = Amarkal\Settings\Manager::get_instance(); |
82
|
|
|
$page = $manager->get_settings_page($slug); |
83
|
|
|
return $page->get_field_values(); |
84
|
|
|
} |
85
|
|
|
} |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.