Skip to content

Commit

Permalink
Merge pull request #3548 from CalderaWP/feature/3547-sendwp-sdk
Browse files Browse the repository at this point in the history
Update Sendwp sdk
  • Loading branch information
New0 authored Jun 11, 2020
2 parents 4ee87fb + 4c2b0d9 commit 12282c9
Show file tree
Hide file tree
Showing 5 changed files with 2,330 additions and 2,057 deletions.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"scripts": {
"build": "yarn build:legacy && yarn build:new",
"build:legacy": "grunt",
"build:new": "yarn build:clients:pre && yarn build:clients && yarn build:blocks",
"start": "yarn build:clients:pre && cross-env BABEL_ENV=development NODE_ENV=development webpack-dev-server --config webpack.clients.js",
"build:new": "yarn build:clients && yarn build:blocks",
"start": "cross-env BABEL_ENV=development NODE_ENV=development webpack-dev-server --config webpack.clients.js",
"start:blocks": "wp-scripts start --config webpack.blocks.js ",
"build:blocks": "wp-scripts build --config webpack.blocks.js ",
"build:clients": "yarn build:clients:pre && cross-env BABEL_ENV=default NODE_ENV=production webpack --config webpack.clients.js",
"build:clients": "cross-env BABEL_ENV=default NODE_ENV=production webpack --config webpack.clients.js",
"build:clients:pre": "node clients/deleteBuilds.js",
"build:webpack": "cross-env BABEL_ENV=default NODE_ENV=production webpack --config webpack.clients.js",
"build:grunt": "grunt",
Expand Down Expand Up @@ -133,7 +133,6 @@
"postcss-nested": "^4.2.1",
"promise-polyfill": "^8.1.3",
"raw-loader": "^4.0.0",
"react": "^16.9.0",
"react-bootstrap": "^0.32.4",
"react-dom": "^16.9.0",
"react-redux": "^5.1.1",
Expand Down
15 changes: 12 additions & 3 deletions sendwp/handler.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

add_action( 'wp_ajax_caldera_forms_sendwp_remote_install', 'wp_ajax_caldera_forms_sendwp_remote_install_handler' );
function wp_ajax_caldera_forms_sendwp_remote_install_handler () {
add_action( 'wp_ajax_caldera_forms_sendwp_remote_install', 'caldera_forms_sendwp_remote_install_handler' );
function caldera_forms_sendwp_remote_install_handler () {

//Security check via senwp_install_nonce
$security = check_ajax_referer('sendwp_install_nonce', 'sendwp_nonce', false);
Expand All @@ -24,6 +24,14 @@ function wp_ajax_caldera_forms_sendwp_remote_install_handler () {
break;
}

//Display an error message if a connection is activated on the website
if( $is_sendwp_installed && sendwp_client_connected() ){
ob_end_clean();
echo json_encode( array( 'error' => true, 'debug' => 'sendwp_connected' ) );
exit;
}


if( ! $is_sendwp_installed ) {

$plugin_slug = 'sendwp';
Expand Down Expand Up @@ -78,9 +86,10 @@ function wp_ajax_caldera_forms_sendwp_remote_install_handler () {
echo json_encode( array(
'partner_id' => 2400,
'register_url' => esc_url( sendwp_get_server_url() . '_/signup' ),
'client_name' => esc_url( sendwp_get_client_name() ),
'client_name' => esc_attr( sendwp_get_client_name() ),
'client_secret' => esc_attr( sendwp_get_client_secret() ),
'client_redirect' => esc_url( sendwp_get_client_redirect() ),
'client_url' => esc_url( sendwp_get_client_url() )
) );
exit;
}
1 change: 1 addition & 0 deletions sendwp/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function caldera_forms_admin_enqueue_sendwp_installer() {
'nonce' => wp_create_nonce( 'sendwp_install_nonce' ),
'security_failed_message' => esc_html__( 'Security failed to check sendwp_install_nonce', 'caldera-forms'),
'user_capability_message' => esc_html__( 'Ask an administrator for install_plugins capability', 'caldera-forms'),
'sendwp_connected_message' => esc_html__( 'SendWP is already connected.', 'caldera-forms'),
]);
}
add_action('caldera_forms_admin_main_enqueue', 'caldera_forms_admin_enqueue_sendwp_installer');
40 changes: 27 additions & 13 deletions sendwp/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,37 @@ function caldera_forms_sendwp_remote_install() {
'action': 'caldera_forms_sendwp_remote_install',
'sendwp_nonce': sendwp_vars.nonce
};

// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
var data = JSON.parse(response);
//Check for errors before calling caldera_forms_sendwp_register_client()
if(data.error === true ){

if( data.error ){

var element = jQuery("#cf-email-settings-ui"),
inner = '<div class="notice error"></div>',
message;

if( data.debug === '!security'){
jQuery("#cf-email-settings-ui").prepend('<div class="notice error"><p>' + sendwp_vars.security_failed_message + '</p></div>');
message = sendwp_vars.security_failed_message;
} else if( data.debug === '!user_capablity'){
jQuery("#cf-email-settings-ui").prepend('<div class="notice error"><p>' + sendwp_vars.user_capability_message + '</p></div>');
message = sendwp_vars.user_capability_message;
} else if( data.debug === 'sendwp_connected'){
message = sendwp_vars.sendwp_connected_message;
}

jQuery(element).prepend( jQuery( inner ).text(message) );

} else {
caldera_forms_sendwp_register_client(data.register_url, data.client_name, data.client_secret, data.client_redirect, data.partner_id);

caldera_forms_sendwp_register_client(data.register_url, data.client_name, data.client_secret, data.client_redirect, data.partner_id, data.client_url);

}

});
}

function caldera_forms_sendwp_register_client(register_url, client_name, client_secret, client_redirect, partner_id) {
function caldera_forms_sendwp_register_client(register_url, client_name, client_secret, client_redirect, partner_id, client_url) {

var form = document.createElement("form");
form.setAttribute("method", 'POST');
Expand All @@ -34,11 +47,12 @@ function caldera_forms_sendwp_register_client(register_url, client_name, client_
form.appendChild(input);
}

caldera_forms_sendwp_append_form_input('client_name', client_name);
caldera_forms_sendwp_append_form_input('client_secret', client_secret);
caldera_forms_sendwp_append_form_input('client_redirect', client_redirect);
caldera_forms_sendwp_append_form_input('partner_id', partner_id);

caldera_forms_sendwp_append_form_input('client_name', client_name);
caldera_forms_sendwp_append_form_input('client_secret', client_secret);
caldera_forms_sendwp_append_form_input('partner_id', partner_id);
caldera_forms_sendwp_append_form_input('client_redirect', client_redirect);
caldera_forms_sendwp_append_form_input('client_url', client_url);

document.body.appendChild(form);
form.submit();
}
}
Loading

0 comments on commit 12282c9

Please sign in to comment.