PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.1
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 6.1, at modules/api-backups/classes/class-api-backups-manager.php

109 lines 2.6 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 // Exit if accessed directly.
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 /**
17 * Class Api_Backups_Manager
18 */
19 class Api_Backups_Manager {
20
21
22 /**
23 * Static variable to hold the single instance of the class.
24 *
25 * @static
26 *
27 * @var mixed Default null
28 */
29 public static $instance = null;
30
31 /**
32 * Get Instance
33 *
34 * Creates public static instance.
35 *
36 * @static
37 *
38 * @return Api_Backups_Manager
39 */
40 public static function get_instance() {
41 if ( null === static::$instance ) {
42 static::$instance = new self();
43 }
44 return static::$instance;
45 }
46
47 /**
48 * Constructor
49 *
50 * Runs each time the class is called.
51 */
52 public function __construct() {
53 spl_autoload_register( array( $this, 'autoload' ) );
54 Api_Backups_Admin::get_instance();
55 }
56
57 /**
58 * Autoloader for classes.
59 *
60 * @param string $class_name class name.
61 */
62 public function autoload( $class_name ) {
63
64 if ( ! preg_match( '/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class_name, $matches ) ) {
65 return;
66 }
67
68 static $reflection;
69
70 if ( empty( $reflection ) ) {
71 $reflection = new \ReflectionObject( $this );
72 }
73
74 if ( $reflection->getNamespaceName() !== $matches['namespace'] ) {
75 return;
76 }
77
78 $autoload_name = $matches['autoload'];
79 $autoload_dir = static::get_location_path();
80
81 $load_dirs = array(
82 'classes' => 'class',
83 );
84 foreach ( $load_dirs as $dir => $prefix ) {
85 $dir = $dir . DIRECTORY_SEPARATOR;
86 $autoload_path = sprintf( '%s%s%s-%s.php', $autoload_dir, $dir, $prefix, strtolower( str_replace( '_', '-', $autoload_name ) ) );
87 if ( is_readable( $autoload_path ) ) {
88 require_once $autoload_path; // NOSONAR - WP compatible.
89 return;
90 }
91 }
92 }
93
94 /**
95 * Method get_location().
96 *
97 * @param string $path what to get path/url.
98 *
99 * @return string value.
100 */
101 public static function get_location_path( $path = 'dir' ) {
102 $location = array(
103 'dir' => MAINWP_MODULES_DIR . 'api-backups' . DIRECTORY_SEPARATOR,
104 'url' => MAINWP_MODULES_URL . 'api-backups/',
105 );
106 return isset( $location[ $path ] ) ? $location[ $path ] : '';
107 }
108 }
109