File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/WPForms.tar
RestApi.php 0000644 00000002711 15154112135 0006623 0 ustar 00 <?php
/**
* WPForms API routes for usage in WP's RestApi.
*
* @since 2.9.0
*
* @author Eduardo Nakatsuka
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Rest Api class.
*
* @since 2.9.0
*/
class OMAPI_WPForms_RestApi extends OMAPI_BaseRestApi {
/**
* The OMAPI_WPForms instance.
*
* @since 2.8.0
*
* @var OMAPI_WPForms
*/
public $wpforms;
/**
* Constructor
*
* @since 2.13.0
*
* @param OMAPI_WPForms $wpforms
*/
public function __construct( OMAPI_WPForms $wpforms ) {
$this->wpforms = $wpforms;
parent::__construct();
}
/**
* Registers the Rest API routes for WPForms
*
* @since 2.9.0
*
* @return void
*/
public function register_rest_routes() {
register_rest_route(
$this->namespace,
'wpforms/forms',
array(
'methods' => WP_REST_Server::READABLE,
'permission_callback' => array( $this, 'logged_in_or_has_api_key' ),
'callback' => array( $this, 'forms' ),
)
);
}
/**
* Handles getting WPForms forms.
*
* Route: GET omapp/v1/woocommerce/forms
*
* @since 2.9.0
*
* @param WP_REST_Request $request The REST Request.
*
* @return WP_REST_Response The API Response
* @throws Exception If plugin action fails.
*/
public function forms() {
try {
return new WP_REST_Response(
$this->wpforms->get_forms_array(),
200
);
} catch ( Exception $e ) {
return $this->exception_to_response( $e );
}
}
}
Save.php 0000644 00000004215 15154112135 0006153 0 ustar 00 <?php
/**
* WPForms Save class.
*
* @since 2.9.0
*
* @package OMAPI
* @author Eduardo Nakatsuka
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WPForms Save class.
*
* @since 2.9.0
*/
class OMAPI_WPForms_Save {
/**
* Holds save error.
*
* @since 2.9.0
*
* @var mixed
*/
public $error = null;
/**
* Holds the base class object.
*
* @since 2.9.0
*
* @var OMAPI
*/
public $base;
/**
* Primary class constructor.
*
* @since 2.9.0
*/
public function __construct() {
$this->base = OMAPI::get_instance();
}
/**
* Helper method to handle connecting WPForms to OptinMonster.
*
* @since 2.9.0
*
* @return void
*/
public function connect() {
$this->update_connection();
}
/**
* Helper method to handle disconnecting WPForms to OptinMonster.
*
* @since 2.9.0
*
* @return void
*/
public function disconnect() {
$this->update_connection( false );
}
/**
* Handles connecting or disconnecting WPForms to OptinMonster.
*
* @since 2.9.0
*
* @param bool $connect True to connect, false to disconnect.
*
* @return void
*/
public function update_connection( $connect = true ) {
$creds = $this->base->get_api_credentials();
if ( empty( $creds['apikey'] ) && empty( $creds['user'] ) && empty( $creds['key'] ) ) {
return;
}
// Make a connection request.
$action = $connect ? 'connect' : 'disconnect';
$api = new OMAPI_Api( 'wpforms/' . $action, $creds, 'POST', 'v2' );
$response = $api->request( OMAPI_Api::get_url_args() );
if ( is_wp_error( $response ) ) {
$message = $connect
/* translators: %s - Error message found while connecting to OptinMonster. */
? esc_html__( 'WPForms could not be connected to OptinMonster. The OptinMonster API returned with the following response: %s', 'optin-monster-api' )
/* translators: %s - Error message found while disconnecting to OptinMonster. */
: esc_html__( 'WPForms could not be disconnected from OptinMonster. The OptinMonster API returned with the following response: %s', 'optin-monster-api' );
$this->error = sprintf( $message, $response->get_error_message() );
}
}
}