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
4 changed files
with
169 additions
and
4 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,63 @@ | ||
<?php | ||
/** | ||
* Integration Demo Integration. | ||
* | ||
* @package WC_Integration_Demo_Integration | ||
* @category Integration | ||
* @author WooThemes | ||
*/ | ||
|
||
if ( ! class_exists( 'WC_Integration_Demo_Integration' ) ) : | ||
|
||
class WC_Integration_Demo_Integration extends WC_Integration { | ||
|
||
/** | ||
* Init and hook in the integration. | ||
*/ | ||
public function __construct() { | ||
global $woocommerce; | ||
|
||
$this->id = 'integration-demo'; | ||
$this->method_title = __( 'Integration Demo', 'woocommerce-integration-demo' ); | ||
$this->method_description = __( 'An integratino demo to show you how easy it is to extend WooCommerce.', 'woocommerce-integration-demo' ); | ||
|
||
// Load the settings. | ||
$this->init_form_fields(); | ||
$this->init_settings(); | ||
|
||
// Define user set variables. | ||
$this->api_key = $this->get_option( 'api_key' ); | ||
$this->debug = $this->get_option( 'debug' ); | ||
|
||
// Actions. | ||
add_action( 'woocommerce_update_options_integration_' . $this->id, array( $this, 'process_admin_options' ) ); | ||
|
||
} | ||
|
||
|
||
/** | ||
* Initialize integration settings form fields. | ||
* | ||
* @return void | ||
*/ | ||
public function init_form_fields() { | ||
$this->form_fields = array( | ||
'api_key' => array( | ||
'title' => __( 'API Key', 'woocommerce-integration-demo' ), | ||
'type' => 'text', | ||
'description' => __( 'Enter with your API Key. You can find this in "User Profile" drop-down (top right corner) > API Keys.', 'woocommerce-integration-demo' ), | ||
'desc_tip' => true, | ||
'default' => '' | ||
), | ||
'debug' => array( | ||
'title' => __( 'Debug Log', 'woocommerce-integration-demo' ), | ||
'type' => 'checkbox', | ||
'label' => __( 'Enable logging', 'woocommerce-integration-demo' ), | ||
'default' => 'no', | ||
'description' => __( 'Log events such as API requests', 'woocommerce-integration-demo' ), | ||
) | ||
); | ||
} | ||
} | ||
|
||
endif; |
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,19 @@ | ||
=== WooCommerce Integration Demo === | ||
Contributors: bftrick | ||
Tags: email, woocommerce, integration, | ||
Requires at least: 3.9 | ||
Tested up to: 3.9 | ||
Stable tag: 1.0 | ||
License: GPLv2 or later | ||
License URI: http://www.gnu.org/licenses/gpl-2.0.html | ||
|
||
An example plugin that shows you how to create a new WooCommerce integration. | ||
|
||
== Description == | ||
|
||
An example plugin that shows you how to create a new WooCommerce integration. | ||
|
||
== Changelog == | ||
|
||
= 1.0 = | ||
* Launch! |
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,87 @@ | ||
<?php | ||
/** | ||
* Plugin Name: WooCommerce Integration Demo | ||
* Plugin URI: https://github.com/BFTrick/woocommerce-integration-demo | ||
* Description: A plugin demonstrating how to add a new WooCommerce integration. | ||
* Author: Patrick Rauland | ||
* Author URI: http://speakinginbytes.com/ | ||
* Version: 1.0 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
if ( ! class_exists( 'WC_Integration_Demo' ) ) : | ||
|
||
class WC_Integration_Demo { | ||
|
||
/** | ||
* Instance of this class. | ||
* | ||
* @var object | ||
*/ | ||
protected static $instance = null; | ||
|
||
|
||
/** | ||
* Initialize the plugin. | ||
*/ | ||
private function __construct() { | ||
|
||
// Checks with WooCommerce is installed. | ||
if ( class_exists( 'WC_Integration' ) ) { | ||
// Integration classes. | ||
include_once 'includes/class-wc-integration-demo-integration.php'; | ||
|
||
// Register the integration. | ||
add_filter( 'woocommerce_integrations', array( $this, 'add_integration' ) ); | ||
|
||
} else { | ||
// throw an admin notice error | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Return an instance of this class. | ||
* | ||
* @return object A single instance of this class. | ||
*/ | ||
public static function get_instance() { | ||
// If the single instance hasn't been set, set it now. | ||
if ( null == self::$instance ) { | ||
self::$instance = new self; | ||
} | ||
|
||
return self::$instance; | ||
} | ||
|
||
|
||
/** | ||
* Add a new integration to WooCommerce. | ||
* | ||
* @param array $integrations WooCommerce integrations. | ||
* | ||
* @return array | ||
*/ | ||
public function add_integration( $integrations ) { | ||
$integrations[] = 'WC_Integration_Demo_Integration'; | ||
return $integrations; | ||
} | ||
|
||
} | ||
|
||
add_action( 'plugins_loaded', array( 'WC_Integration_Demo', 'get_instance' ), 0 ); | ||
|
||
endif; |