PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.2 6.2.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 All 155 releases
← All changes | modules/api-backups/classes/class-api-backups-helper.php +124 -105 5.0.2 → 6.2.1 View file →
@@ -7,126 +7,145 @@
7 7 */
8 8
9 9 namespace MainWP\Dashboard\Module\ApiBackups;
10 10
11 +// Exit if accessed directly.
12 +if ( ! defined( 'ABSPATH' ) ) {
13 + exit;
14 +}
15 +
11 16 /**
12 17 * Class Api_Backups_Utility
13 18 */
14 19 class Api_Backups_Helper {
15 20
16 - /**
17 - * Public static variable to hold the single instance of the class.
18 - *
19 - * @var mixed Default null
20 - */
21 - public static $instance = null;
21 + /**
22 + * Public static variable to hold the single instance of the class.
23 + *
24 + * @var mixed Default null
25 + */
26 + public static $instance = null;
22 27
23 - /**
24 - * Get Instance
25 - *
26 - * Creates public static instance.
27 - *
28 - * @static
29 - *
30 - * @return Api_Backups_Utility
31 - */
32 - public static function get_instance() {
33 - if ( null === self::$instance ) {
34 - self::$instance = new self();
35 - }
36 - return self::$instance;
37 - }
28 + /**
29 + * Get Instance
30 + *
31 + * Creates public static instance.
32 + *
33 + * @static
34 + *
35 + * @return Api_Backups_Utility
36 + */
37 + public static function get_instance() {
38 + if ( null === static::$instance ) {
39 + static::$instance = new self();
40 + }
41 + return static::$instance;
42 + }
38 43
39 - /**
40 - * Construct.
41 - */
42 - public function __construct() {
43 - // constructor.
44 - }
44 + /**
45 + * Construct.
46 + */
47 + public function __construct() {
48 + // constructor.
49 + }
45 50
46 - /**
47 - * Get sites by website ID.
48 - *
49 - * @param int $website_id User ID.
50 - * @param bool $selectGroups Select groups.
51 - * @param array $extra_view get extra option fields.
52 - *
53 - * @return object|null Database query results or null on failure.
54 - */
55 - public static function get_website_by_id( $website_id, $selectGroups = false, $extra_view = array() ) {
56 - $website = apply_filters( 'mainwp_getwebsite_by_id', false, $website_id, $selectGroups, $extra_view );
57 - if ( ! empty( $website ) && is_object( $website ) ) {
58 - return (array) $website;
59 - }
60 - return array();
61 - }
62 51
52 + /**
53 + * Clean URL.
54 + * Remove http(s)://, www., and trailing slash(/) from the URL.
55 + *
56 + * @param string $url url.
57 + * @return string clean url.
58 + */
59 + public static function clean_url( $url ) {
60 + $clean_url = str_replace( array( 'https://www.', 'http://www.', 'https://', 'http://', 'www.' ), array( '', '', '', '', '' ), $url ); // NOSONAR - ok.
61 + $clean_url = rtrim( $clean_url, '/' );
62 + return $clean_url;
63 + }
63 64
64 - /**
65 - * Method update_website_option().
66 - *
67 - * Update the website option.
68 - *
69 - * @param object|int $website website object or ID.
70 - * @param string $opt_name website.
71 - * @param string $opt_value website.
72 - */
73 - public static function update_website_option( $website, $opt_name, $opt_value ) {
74 - return apply_filters( 'mainwp_updatewebsiteoptions', false, $website, $opt_name, $opt_value );
75 - }
65 + /**
66 + * Get sites by website ID.
67 + *
68 + * @param int $website_id User ID.
69 + * @param bool $selectGroups Select groups.
70 + * @param array $extra_view get extra option fields.
71 + *
72 + * @return object|null Database query results or null on failure.
73 + */
74 + public static function get_website_by_id( $website_id, $selectGroups = false, $extra_view = array() ) {
75 + $website = apply_filters( 'mainwp_getwebsite_by_id', false, $website_id, $selectGroups, $extra_view );
76 + if ( ! empty( $website ) && is_object( $website ) ) {
77 + return (array) $website;
78 + }
79 + return array();
80 + }
76 81
77 - /**
78 - * Method get_website_options().
79 - *
80 - * Get the website options.
81 - *
82 - * @param object|int $website website object or ID.
83 - * @param string|array $options Options name.
84 - */
85 - public static function get_website_options( $website, $options ) {
86 - return apply_filters( 'mainwp_getwebsiteoptions', false, $website, $options );
87 - }
88 82
83 + /**
84 + * Method update_website_option().
85 + *
86 + * Update the website option.
87 + *
88 + * @param object|int $website website object or ID.
89 + * @param string $opt_name website.
90 + * @param string $opt_value website.
91 + */
92 + public static function update_website_option( $website, $opt_name, $opt_value ) {
93 + return apply_filters( 'mainwp_updatewebsiteoptions', false, $website, $opt_name, $opt_value );
94 + }
89 95
90 - /**
91 - * Method fetch_object().
92 - *
93 - * Handle fetch object db.
94 - *
95 - * @param mixed $websites websites results.
96 - *
97 - * @return mixed results.
98 - */
99 - public static function fetch_object( $websites ) {
100 - return apply_filters( 'mainwp_db_fetch_object', false, $websites );
101 - }
96 + /**
97 + * Method get_website_options().
98 + *
99 + * Get the website options.
100 + *
101 + * @param object|int $website website object or ID.
102 + * @param string|array $options Options name.
103 + */
104 + public static function get_website_options( $website, $options ) {
105 + return apply_filters( 'mainwp_getwebsiteoptions', false, $website, $options );
106 + }
102 107
103 108
104 - /**
105 - * Method free_result().
106 - *
107 - * Handle fetch result db.
108 - *
109 - * @param mixed $results websites results.
110 - *
111 - * @return mixed results.
112 - */
113 - public static function free_result( $results ) {
114 - if ( empty( $results ) ) {
115 - return;
116 - }
117 - return apply_filters( 'mainwp_db_free_result', false, $results );
118 - }
109 + /**
110 + * Method fetch_object().
111 + *
112 + * Handle fetch object db.
113 + *
114 + * @param mixed $websites websites results.
115 + *
116 + * @return mixed results.
117 + */
118 + public static function fetch_object( $websites ) {
119 + return apply_filters( 'mainwp_db_fetch_object', false, $websites );
120 + }
119 121
120 - /**
121 - * Method security_nonce().
122 - *
123 - * Handle security nonce.
124 - *
125 - * @param string $action security action.
126 - */
127 - public static function security_nonce( $action ) {
128 - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
129 - do_action( 'mainwp_secure_request', $action );
130 - }
131 - }
122 +
123 + /**
124 + * Method free_result().
125 + *
126 + * Handle fetch result db.
127 + *
128 + * @param mixed $results websites results.
129 + *
130 + * @return mixed results.
131 + */
132 + public static function free_result( $results ) { //phpcs:ignore -- NOSONAR - complex.
133 + if ( empty( $results ) ) {
134 + return;
135 + }
136 + return apply_filters( 'mainwp_db_free_result', false, $results );
137 + }
138 +
139 + /**
140 + * Method security_nonce().
141 + *
142 + * Handle security nonce.
143 + *
144 + * @param string $action security action.
145 + */
146 + public static function security_nonce( $action ) {
147 + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
148 + do_action( 'mainwp_secure_request', $action );
149 + }
150 + }
132 151 }