PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 1.6.4
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v1.6.4
2.12.7 2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 All 97 releases
sureforms / modules / gutenberg / classes / class-spec-filesystem.php

class-spec-filesystem.php in SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz 1.6.4, at modules/gutenberg/classes/class-spec-filesystem.php

112 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 * Sureforms Filesystem
4 *
5 * @package Sureforms
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * Class Spec_Filesystem.
14 */
15 class Spec_Filesystem {
16
17 /**
18 * Member Variable
19 *
20 * @var instance
21 */
22 private static $instance;
23
24 /**
25 * Initiator
26 */
27 public static function get_instance() {
28 if ( ! isset( self::$instance ) ) {
29 self::$instance = new self();
30 }
31 return self::$instance;
32 }
33
34 /**
35 * Get an instance of WP_Filesystem.
36 *
37 * @since 0.0.1
38 */
39 public function get_filesystem() {
40
41 global $wp_filesystem;
42
43 if ( ! $wp_filesystem || 'direct' !== $wp_filesystem->method ) {
44 require_once ABSPATH . '/wp-admin/includes/file.php';
45
46 /**
47 * Context for filesystem, default false.
48 *
49 * @see request_filesystem_credentials_context
50 */
51 $context = apply_filters( 'request_filesystem_credentials_context', false );//phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- wordpress hook
52
53 add_filter( 'filesystem_method', [ $this, 'filesystem_method' ] );
54 add_filter( 'request_filesystem_credentials', [ $this, 'request_filesystem_credentials' ] );
55
56 $creds = request_filesystem_credentials( site_url(), '', true, $context, null );
57
58 WP_Filesystem( $creds, $context );
59
60 remove_filter( 'filesystem_method', [ $this, 'filesystem_method' ] );
61 remove_filter( 'request_filesystem_credentials', [ $this, 'request_filesystem_credentials' ] );
62 }
63
64 // Set the permission constants if not already set.
65 if ( ! defined( 'FS_CHMOD_DIR' ) ) {
66 // phpcs:ignore
67 define( 'FS_CHMOD_DIR', 0755 ); // ignore statement added to avoid WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound, it's pre defined constant in bootstrap.php file
68 // phpcs:ignoreEnd
69 }
70 if ( ! defined( 'FS_CHMOD_FILE' ) ) {
71 // phpcs:ignore
72 define( 'FS_CHMOD_FILE', 0644 ); // ignore statement added to avoid WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound, it's pre defined constant in bootstrap.php file
73 // phpcs:ignoreEnd
74 }
75
76 return $wp_filesystem;
77 }
78
79 /**
80 * Method to direct.
81 *
82 * @since 0.0.1
83 */
84 public function filesystem_method() {
85 return 'direct';
86 }
87
88 /**
89 * Sets credentials to true.
90 *
91 * @since 0.0.1
92 */
93 public function request_filesystem_credentials() {
94 return true;
95 }
96 }
97
98 /**
99 * Prepare if class 'Spec_Filesystem' exist.
100 * Kicking this off by calling 'get_instance()' method
101 */
102 Spec_Filesystem::get_instance();
103
104 /**
105 * Filesystem class
106 *
107 * @since 0.0.1
108 */
109 function spec_filesystem() {
110 return Spec_Filesystem::get_instance()->get_filesystem();
111 }
112