1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* WordPress UI |
4
|
|
|
* |
5
|
|
|
* A set of UI components for WordPress. |
6
|
|
|
* This is a component within the Amarkal framework. |
7
|
|
|
* |
8
|
|
|
* @package amarkal-ui |
9
|
|
|
* @author Askupa Software <[email protected]> |
10
|
|
|
* @link https://github.com/amarkal/amarkal-ui |
11
|
|
|
* @copyright 2017 Askupa Software |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
// Prevent direct file access |
15
|
|
|
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Prevent loading the library more than once |
19
|
|
|
*/ |
20
|
|
|
if( defined( 'AMARKAL_UI' ) ) return false; |
21
|
|
|
define( 'AMARKAL_UI', true ); |
22
|
|
|
|
23
|
|
|
if(!function_exists('amarkal_ui_render')) |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Render a UI component. |
27
|
|
|
* |
28
|
|
|
* @param string $type The component's type - one of the core component types, |
29
|
|
|
* or a registered custom component. |
30
|
|
|
* @param array $props The component's properties |
31
|
|
|
* @return string The rendered HTML |
32
|
|
|
*/ |
33
|
|
|
function amarkal_ui_render( $type, array $props = array() ) |
34
|
|
|
{ |
35
|
|
|
$component = Amarkal\UI\ComponentFactory::create( $type, $props ); |
36
|
|
|
return $component->render(); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if(!function_exists('amarkal_ui_register_component')) |
41
|
|
|
{ |
42
|
|
|
/** |
43
|
|
|
* Register a custom UI component. The registered component's class should |
44
|
|
|
* inherit from Amarkal\UI\AbstractComponent. |
45
|
|
|
* |
46
|
|
|
* @param string $type The component's type. If the custom type is similar |
47
|
|
|
* to one of the core component's type, it will override the core component. |
48
|
|
|
* @param string $class_name The component's class name. |
49
|
|
|
*/ |
50
|
|
|
function amarkal_ui_register_component( $type, $class_name ) |
51
|
|
|
{ |
52
|
|
|
Amarkal\UI\ComponentFactory::register( $type, $class_name ); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if(!function_exists('amarkal_ui_register_scripts')) |
57
|
|
|
{ |
58
|
|
|
/** |
59
|
|
|
* Register Amarkal UI styles & scripts. These scripts are later enqueued by |
60
|
|
|
* UI components where applicable. |
61
|
|
|
*/ |
62
|
|
|
function amarkal_ui_register_scripts() |
63
|
|
|
{ |
64
|
|
|
\wp_register_script('amarkal-ui',Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/js/dist/amarkal-ui.min.js'),array('jquery','amarkal-core'),false,true); |
65
|
|
|
\wp_register_script('ace-editor','https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.9/ace.js',array('jquery'),false,true); |
66
|
|
|
\wp_register_style('amarkal-ui',Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/css/dist/amarkal-ui.min.css'),array()); |
67
|
|
|
} |
68
|
|
|
\add_action('admin_init','amarkal_ui_register_scripts'); |
69
|
|
|
} |
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.