updated plugin GP Premium version 2.3.0

This commit is contained in:
2023-03-29 18:20:22 +00:00
committed by Gitium
parent e42ba0e05a
commit 16a556be53
40 changed files with 539 additions and 172 deletions

View File

@ -81,6 +81,16 @@ class GeneratePress_Pro_Rest extends WP_REST_Controller {
)
);
register_rest_route(
$namespace,
'/beta/',
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'update_beta_testing' ),
'permission_callback' => array( $this, 'update_settings_permission' ),
)
);
register_rest_route(
$namespace,
'/export/',
@ -167,14 +177,12 @@ class GeneratePress_Pro_Rest extends WP_REST_Controller {
*/
public function update_licensing( WP_REST_Request $request ) {
$new_license_key = $request->get_param( 'key' );
$new_beta_tester = $request->get_param( 'betaTester' );
$old_license = get_option( 'gen_premium_license_key', '' );
$old_status = get_option( 'gen_premium_license_key_status', 'deactivated' );
$new_license = strpos( $new_license_key, '***' ) !== false
? trim( $old_license )
: trim( $new_license_key );
if ( $new_license ) {
$api_params = array(
'edd_action' => 'activate_license',
@ -257,14 +265,35 @@ class GeneratePress_Pro_Rest extends WP_REST_Controller {
update_option( 'gen_premium_license_key_status', esc_attr( $license_data->license ) );
}
update_option( 'gen_premium_license_key', sanitize_key( $new_license ) );
if ( ! isset( $api_params ) ) {
return $this->success( __( 'Settings saved.', 'gp-premium' ) );
}
if ( ! empty( $message ) ) {
return $this->failed( $message );
}
return $this->success( $license_data );
}
/**
* Update licensing.
*
* @param WP_REST_Request $request request object.
*
* @return mixed
*/
public function update_beta_testing( WP_REST_Request $request ) {
$new_beta_tester = $request->get_param( 'beta' );
if ( ! empty( $new_beta_tester ) ) {
update_option( 'gp_premium_beta_testing', true, false );
} else {
delete_option( 'gp_premium_beta_testing' );
}
update_option( 'gen_premium_license_key', sanitize_key( $new_license ) );
if ( ! isset( $api_params ) ) {
return $this->success( __( 'Settings saved.', 'gp-premium' ) );
}

View File

@ -107,3 +107,46 @@ function generate_premium_remove_featured_image_class( $classes, $remove_class )
return $classes;
}
/**
* Returns the global $wp_filesystem with credentials set.
* Returns null in case of any errors.
*
* @return WP_Filesystem_Base|null
*/
function generate_premium_get_wp_filesystem() {
global $wp_filesystem;
$success = true;
// Initialize the file system if it has not been done yet.
if ( ! $wp_filesystem ) {
require_once ABSPATH . '/wp-admin/includes/file.php';
$constants = array(
'hostname' => 'FTP_HOST',
'username' => 'FTP_USER',
'password' => 'FTP_PASS',
'public_key' => 'FTP_PUBKEY',
'private_key' => 'FTP_PRIKEY',
);
$credentials = array();
// We provide credentials based on wp-config.php constants.
// Reference https://developer.wordpress.org/apis/wp-config-php/#wordpress-upgrade-constants.
foreach ( $constants as $key => $constant ) {
if ( defined( $constant ) ) {
$credentials[ $key ] = constant( $constant );
}
}
$success = WP_Filesystem( $credentials );
}
if ( ! $success || $wp_filesystem->errors->has_errors() ) {
return null;
}
return $wp_filesystem;
}