PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / modules / api-backups / classes / class-api-backups-manager.php

class-api-backups-manager.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.0, at modules/api-backups/classes/class-api-backups-manager.php

104 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Module API Backups Admin class.
4 *
5 * @package MainWP\Dashboard
6 * @version 5.0
7 */
8
9 namespace MainWP\Dashboard\Module\ApiBackups;
10
11 /**
12 * Class Api_Backups_Manager
13 */
14 class Api_Backups_Manager {
15
16
17 /**
18 * Static variable to hold the single instance of the class.
19 *
20 * @static
21 *
22 * @var mixed Default null
23 */
24 public static $instance = null;
25
26 /**
27 * Get Instance
28 *
29 * Creates public static instance.
30 *
31 * @static
32 *
33 * @return Api_Backups_Manager
34 */
35 public static function get_instance() {
36 if ( null === self::$instance ) {
37 self::$instance = new self();
38 }
39 return self::$instance;
40 }
41
42 /**
43 * Constructor
44 *
45 * Runs each time the class is called.
46 */
47 public function __construct() {
48 spl_autoload_register( array( $this, 'autoload' ) );
49 Api_Backups_Admin::get_instance();
50 }
51
52 /**
53 * Autoloader for classes.
54 *
55 * @param string $class_name class name.
56 */
57 public function autoload( $class_name ) {
58
59 if ( ! preg_match( '/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class_name, $matches ) ) {
60 return;
61 }
62
63 static $reflection;
64
65 if ( empty( $reflection ) ) {
66 $reflection = new \ReflectionObject( $this );
67 }
68
69 if ( $reflection->getNamespaceName() !== $matches['namespace'] ) {
70 return;
71 }
72
73 $autoload_name = $matches['autoload'];
74 $autoload_dir = self::get_location_path();
75
76 $load_dirs = array(
77 'classes' => 'class',
78 );
79 foreach ( $load_dirs as $dir => $prefix ) {
80 $dir = $dir . DIRECTORY_SEPARATOR;
81 $autoload_path = sprintf( '%s%s%s-%s.php', $autoload_dir, $dir, $prefix, strtolower( str_replace( '_', '-', $autoload_name ) ) );
82 if ( is_readable( $autoload_path ) ) {
83 require_once $autoload_path;
84 return;
85 }
86 }
87 }
88
89 /**
90 * Method get_location().
91 *
92 * @param string $path what to get path/url.
93 *
94 * @return string value.
95 */
96 public static function get_location_path( $path = 'dir' ) {
97 $location = array(
98 'dir' => MAINWP_MODULES_DIR . 'api-backups' . DIRECTORY_SEPARATOR,
99 'url' => MAINWP_MODULES_URL . 'api-backups/',
100 );
101 return isset( $location[ $path ] ) ? $location[ $path ] : '';
102 }
103 }
104