-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,384 additions
and
5,996 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* Add logs page | ||
* | ||
* @package Reepay\Checkout\Admin | ||
*/ | ||
|
||
namespace Reepay\Checkout\Admin; | ||
|
||
/** | ||
* Class | ||
* | ||
* @package Reepay\Checkout\Admin | ||
*/ | ||
class LogsPage { | ||
public const SLUG = 'bw-logs'; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() { | ||
add_action( 'woocommerce_admin_status_tabs', array( $this, 'add_tab' ) ); | ||
add_action( 'woocommerce_admin_status_content_' . self::SLUG, array( $this, 'tab_content' ) ); | ||
} | ||
|
||
/** | ||
* Add tab. | ||
* | ||
* @param array $tabs slugs and tab names. | ||
* @return array | ||
*/ | ||
public function add_tab( array $tabs ): array { | ||
$tabs[ self::SLUG ] = __( 'Billwerk logs', 'reepay-checkout-gateway' ); | ||
return $tabs; | ||
} | ||
|
||
/** | ||
* Tab content | ||
* | ||
* @return void | ||
*/ | ||
public function tab_content() { | ||
$template_args = array(); | ||
reepay()->get_template( | ||
'admin/logs-page.php', | ||
$template_args | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* Controller logs | ||
* | ||
* @package Reepay\Checkout\Api\Controller | ||
*/ | ||
|
||
namespace Reepay\Checkout\Api\Controller; | ||
|
||
use WP_Error; | ||
use WP_REST_Controller; | ||
use WP_REST_Request; | ||
use WP_REST_Response; | ||
use WP_REST_Server; | ||
|
||
/** | ||
* Class controller | ||
* | ||
* @package Reepay\Checkout\Api\Controller | ||
*/ | ||
class LogsController extends WP_REST_Controller { | ||
/** | ||
* Constructor | ||
*/ | ||
public function __construct() { | ||
$this->namespace = 'billwerk/v1'; | ||
$this->rest_base = 'logs'; | ||
} | ||
|
||
/** | ||
* Register API routes | ||
* | ||
* @return void | ||
*/ | ||
public function register_routes() { | ||
register_rest_route( | ||
$this->namespace, | ||
"/$this->rest_base/", | ||
array( | ||
array( | ||
'methods' => WP_REST_Server::CREATABLE, | ||
'callback' => array( $this, 'get_logs' ), | ||
'permission_callback' => array( $this, 'get_items_permissions_check' ), | ||
), | ||
'schema' => array( $this, 'get_item_schema' ), | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Retrieves files logs | ||
* | ||
* @param WP_REST_Request $request Full details about the request. | ||
* | ||
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. | ||
*/ | ||
public function get_logs( WP_REST_Request $request ) { | ||
$files = reepay()->log()->get_files(); | ||
|
||
return rest_ensure_response( $files ); | ||
} | ||
|
||
/** | ||
* Checks if a given request has access to get items. | ||
* | ||
* @param WP_REST_Request $request Full details about the request. | ||
* | ||
* @return true|WP_Error True if the request has read access, WP_Error object otherwise. | ||
*/ | ||
public function get_items_permissions_check( $request ) { | ||
if ( ! current_user_can( 'manage_options' ) ) { | ||
return new WP_Error( 'rest_forbidden', esc_html__( 'You cannot view the post resource.' ), array( 'status' => rest_authorization_required_code() ) ); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* Class for working with WP_Filesystem | ||
* | ||
* @package Reepay\Checkout\Utils | ||
*/ | ||
|
||
namespace Reepay\Checkout\Utils; | ||
|
||
use Exception; | ||
use WP_Filesystem_Base; | ||
|
||
/** | ||
* FilesystemUtil class. | ||
* | ||
* @package Reepay\Checkout\Utils | ||
*/ | ||
class FilesystemUtil { | ||
/** | ||
* Wrapper to retrieve the class instance contained in the $wp_filesystem global, after initializing if necessary. | ||
* | ||
* @return WP_Filesystem_Base | ||
* @throws Exception Thrown when the filesystem fails to initialize. | ||
*/ | ||
public static function get_wp_filesystem(): WP_Filesystem_Base { | ||
global $wp_filesystem; | ||
|
||
if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) { | ||
$initialized = self::initialize_wp_filesystem(); | ||
|
||
if ( false === $initialized ) { | ||
throw new Exception( 'The WordPress filesystem could not be initialized.' ); | ||
} | ||
} | ||
|
||
return $wp_filesystem; | ||
} | ||
|
||
/** | ||
* Wrapper to initialize the WP filesystem with defined credentials if they are available. | ||
* | ||
* @return bool True if the $wp_filesystem global was successfully initialized. | ||
*/ | ||
protected static function initialize_wp_filesystem(): bool { | ||
global $wp_filesystem; | ||
|
||
if ( $wp_filesystem instanceof WP_Filesystem_Base ) { | ||
return true; | ||
} | ||
|
||
require_once ABSPATH . 'wp-admin/includes/file.php'; | ||
|
||
$method = get_filesystem_method(); | ||
$initialized = false; | ||
|
||
if ( 'direct' === $method ) { | ||
$initialized = WP_Filesystem(); | ||
} elseif ( false !== $method ) { | ||
// See https://core.trac.wordpress.org/changeset/56341. | ||
ob_start(); | ||
$credentials = request_filesystem_credentials( '' ); | ||
ob_end_clean(); | ||
|
||
$initialized = $credentials && WP_Filesystem( $credentials ); | ||
} | ||
|
||
return is_null( $initialized ) ? false : $initialized; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
/** | ||
* Custom logs page | ||
* | ||
* @package Reepay\Checkout | ||
*/ | ||
|
||
defined( 'ABSPATH' ) || exit(); | ||
?> | ||
|
||
<div class="wrap"> | ||
<div class="billwerk-logs"></div> | ||
</div> |
Binary file not shown.
Oops, something went wrong.