Skip to content

Commit

Permalink
Changes for specific use
Browse files Browse the repository at this point in the history
  • Loading branch information
stiofan committed Feb 18, 2020
1 parent e240886 commit 735263a
Show file tree
Hide file tree
Showing 13 changed files with 2,158 additions and 964 deletions.
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Items to ignore when downloading release

.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
composer.json export-ignore
composer.lock export-ignore
CONTRIBUTING.md export-ignore
phpunit.xml export-ignore
README.md export-ignore
/tests/ export-ignore
/.idea/ export-ignore
/.github/ export-ignore
/.wordpress-org/ export-ignore
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea/

# Composer
composer.phar
composer.lock
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# wp-service-client
WP Service Client class
# ayecode-connect
AyeCode Connect Client class
7 changes: 7 additions & 0 deletions assets/css/ayecode-ui-compatibility.css

Large diffs are not rendered by default.

Binary file added assets/img/ayecode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/connect-site.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
126 changes: 126 additions & 0 deletions assets/js/ayecode-connect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**
* Request to enable update notifications.
*
* @param $input
* @param $state
*/
function ayecode_connect_updates($input,$state){
jQuery.ajax({
url: ajaxurl,
type: 'POST',
dataType: 'json',
data: {
action: 'ayecode_connect_updates',
security: ayecode_connect.nonce,
state: $state
},
beforeSend: function() {
jQuery($input).prop('disabled', true);
jQuery($input).closest('li').find('.spinner-border').toggleClass('d-none');
},
success: function(data, textStatus, xhr) {
console.log(data);
if(data.success){
// yay
// maybe switch off licence sync also
if (!$state && jQuery('#ac-setting-licences').is(':checked')) {
jQuery('#ac-setting-licences').trigger('click');
}

}else{
// oh dear, toggle it back
jQuery($input).prop('checked', !$state);
alert(ayecode_connect.error_msg);
}
jQuery($input).prop('disabled', false);
jQuery($input).closest('li').find('.spinner-border').toggleClass('d-none');
},
error: function(xhr, textStatus, errorThrown) {
alert(textStatus);
jQuery($input).prop('disabled', false);
jQuery($input).closest('li').find('.spinner-border').toggleClass('d-none');
}
}); // end of ajax
}

/**
* Request to disconnect site from AyeCode Connect.
*
* @param $input
*/
function ayecode_connect_disconnect($input){
if(window.confirm(ayecode_connect.disconnect_msg)){
jQuery.ajax({
url: ajaxurl,
type: 'POST',
dataType: 'json',
data: {
action: 'ayecode_connect_disconnect',
security: ayecode_connect.nonce
},
beforeSend: function() {
jQuery($input).prop('disabled', true);
jQuery($input).closest('p').find('.spinner-border').toggleClass('d-none');
},
success: function(data, textStatus, xhr) {
console.log(data);
if(data.success){
location.reload();
}else{
// oh dear
alert(ayecode_connect.error_msg);
}
jQuery($input).prop('disabled', false);
jQuery($input).closest('p').find('.spinner-border').toggleClass('d-none');
},
error: function(xhr, textStatus, errorThrown) {
alert(textStatus);
}
}); // end of ajax
}

}

/**
* Request to enable licence sync.
*
* @param $input
* @param $state
*/
function ayecode_connect_licences($input,$state){
jQuery.ajax({
url: ajaxurl,
type: 'POST',
dataType: 'json',
data: {
action: 'ayecode_connect_licences',
security: ayecode_connect.nonce,
state: $state
},
beforeSend: function() {
jQuery($input).prop('disabled', true);
jQuery($input).closest('li').find('.spinner-border').toggleClass('d-none');
},
success: function(data, textStatus, xhr) {
console.log(data);
if(data.success){
// yay
}else if(data.data){
// oh dear, toggle it back
jQuery($input).prop('checked', !$state);
alert(data.data);
}else{
// oh dear, toggle it back
jQuery($input).prop('checked', !$state);
alert(ayecode_connect.error_msg);
}
jQuery($input).prop('disabled', false);
jQuery($input).closest('li').find('.spinner-border').toggleClass('d-none');
},
error: function(xhr, textStatus, errorThrown) {
alert(textStatus);
jQuery($input).prop('disabled', false);
jQuery($input).closest('li').find('.spinner-border').toggleClass('d-none');
}
}); // end of ajax
}
74 changes: 74 additions & 0 deletions ayecode-connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/**
* Plugin Name: AyeCode Connect
* Plugin URI: https://ayecode.io/
* Description: A service plugin letting users connect AyeCode Services to their site.
* Version: 1.0.0
* Author: AyeCode
* Author URI: https://ayecode.io/
* Requires at least: 4.7
* Tested up to: 5.3
*
* Text Domain: ayecode-connect
* Domain Path: /languages/
*
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

if ( !defined( 'AYECODE_CONNECT_VERSION' ) ) {
define( 'AYECODE_CONNECT_VERSION', '1.0.0' );
}

add_action( 'plugins_loaded', 'ayecode_connect' );

/**
* Sets up the client
*/
function ayecode_connect() {

//Include the client connection class
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ayecode-connect.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ayecode-connect-settings.php';

//Prepare client args
$args = ayecode_connect_args();

$client = new AyeCode_Connect( $args );

//Call the init method to register routes. This should be called exactly once per client (Preferably before the init hook).
$client->init();

}

/**
* The AyeCode Connect arguments.
*
* @return array
*/
function ayecode_connect_args(){
$base_url = 'https://ayecode.io';
return array(
'remote_url' => $base_url, //URL to the WP site containing the WP_Service_Provider class
'connection_url' => $base_url.'/connect', //This should be a custom page the authinticates a user the calls the WP_Service_Provider::connect_site() method
'api_url' => $base_url.'/wp-json/', //Might be different for you
'api_namespace' => 'ayecode/v1',
'local_api_namespace' => 'ayecode-connect/v1', //Should be unique for each client implementation
'prefix' => 'ayecode_connect', //A unique prefix for things (accepts alphanumerics and underscores). Each client on a given site should have it's own unique prefix
'textdomain' => 'ayecode-connect',
);
}


/**
* Remove wp cron on deactivation if set.
*/
register_deactivation_hook( __FILE__, 'ayecode_connect_deactivation' );
function ayecode_connect_deactivation() {
$args = ayecode_connect_args();
$prefix = $args['prefix'];
wp_clear_scheduled_hook( $prefix.'_callback' );
}
100 changes: 0 additions & 100 deletions example.php

This file was deleted.

Loading

0 comments on commit 735263a

Please sign in to comment.