class-spec-block-config.php
2 years ago
class-spec-block-helper.php
1 year ago
class-spec-block-js.php
2 years ago
class-spec-block-loader.php
2 years ago
class-spec-filesystem.php
2 months ago
class-spec-gb-helper.php
11 months ago
class-spec-init-blocks.php
5 months ago
class-spec-spectra-compatibility.php
5 months ago
class-spec-filesystem.php
112 lines
| 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() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Shared Spectra/UAG helper; the name is kept identical across products for cross-plugin compatibility. |
| 110 | return Spec_Filesystem::get_instance()->get_filesystem(); |
| 111 | } |
| 112 |