-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertion-sort.php
More file actions
92 lines (79 loc) · 2.22 KB
/
insertion-sort.php
File metadata and controls
92 lines (79 loc) · 2.22 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/*
* Plugin Name: Insertion Sort
* Plugin URI: https://github.com/normeno/wordpress-insertion-sort
* Description: Add code in our pages
* Version: 0.1 alpha
* Author: Nicolas Ormeno
* Author URI: //normeno.com
* Text Domain: insertion-sort
* Domain Path: /languages
* License: GPL-3.0
* License URI: https://opensource.org/licenses/MIT
*
* @package insertion-sort
* @author Nicolas Ormeno
* @license MIT
*/
/**
* Avoid direct file access
*
* @since 0.1
*/
defined( 'ABSPATH' ) || die( 'Don\'t try so hard!' );
/**
* Set current version
*
* @since 0.1
*/
define( 'INSERTIONS_VERSION', '0.1 alpha' );
/**
* Set common constants
*
* @since 0.1
*/
define( 'INSERTIONS_URL', plugin_dir_url( __FILE__ ) );
define( 'INSERTIONS_PATH', dirname( __FILE__ ) . DIRECTORY_SEPARATOR );
define( 'INSERTIONS_NAMESPACE', 'Insertions' );
define( 'INSERTIONS_ADMIN_SLUG', 'insertions' );
/**
* Class loader function
*
* @since 0.1
* @param string $class Class name.
* @return void
*/
function insertions_class_loader( $class ) {
$namespace = INSERTIONS_NAMESPACE . '\\';
if ( strpos( $class, $namespace ) !== false ) {
$class = strtolower( str_replace( $namespace, '', $class ) );
$path_array = explode( '\\', $class );
if ( count( $path_array ) > 1 ) {
$dir_array = array_slice( $path_array, 0, -1 );
$file_path = implode( DIRECTORY_SEPARATOR, $dir_array );
$file_name = DIRECTORY_SEPARATOR . 'class-' . end( $path_array ) . '.php';
$file = DIRECTORY_SEPARATOR . $file_path . $file_name;
} else {
$file = DIRECTORY_SEPARATOR . 'class-' . $class . '.php';
}
$file = INSERTIONS_PATH . 'includes' . $file;
if ( file_exists( $file ) ) {
include $file;
}
}
}
spl_autoload_register( 'insertions_class_loader' );
add_action( 'init', 'insertions_init' );
/**
* Initializes plugin
*
* @since 0.1
* @return void
*/
function insertions_init() {
load_plugin_textdomain( 'insertion-sort', false, basename( dirname( __FILE__ ) ) . '/languages');
new Insertions\Core();
if ( is_admin() ) {
new Insertions\Admin\Core();
}
}