| 1 |
<?php |
| 2 |
/** |
| 3 |
* The feedback model class for ThemeIsle SDK |
| 4 |
* |
| 5 |
* @package ThemeIsleSDK |
| 6 |
* @subpackage Feedback |
| 7 |
* @copyright Copyright (c) 2017, Marius Cristea |
| 8 |
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License |
| 9 |
* @since 1.0.0 |
| 10 |
*/ |
| 11 |
// Exit if accessed directly. |
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
if ( ! class_exists( 'ThemeIsle_SDK_Feedback' ) ) : |
| 16 |
/** |
| 17 |
* Feedback model for ThemeIsle SDK. |
| 18 |
*/ |
| 19 |
abstract class ThemeIsle_SDK_Feedback { |
| 20 |
/** |
| 21 |
* @var ThemeIsle_SDK_Product $product Themeisle Product. |
| 22 |
*/ |
| 23 |
protected $product; |
| 24 |
|
| 25 |
/** |
| 26 |
* @var string $feedback_url Url where to send the feedback |
| 27 |
*/ |
| 28 |
private $feedback_url = 'http://feedback.themeisle.com/wordpress/wp-json/__pirate_feedback_/v1/feedback'; |
| 29 |
|
| 30 |
/** |
| 31 |
* ThemeIsle_SDK_Feedback constructor. |
| 32 |
* |
| 33 |
* @param ThemeIsle_SDK_Product $product_object Product Object. |
| 34 |
*/ |
| 35 |
public function __construct( $product_object ) { |
| 36 |
if ( $product_object instanceof ThemeIsle_SDK_Product ) { |
| 37 |
$this->product = $product_object; |
| 38 |
} |
| 39 |
$this->setup_hooks(); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Registers the hooks and then delegates to the child |
| 44 |
*/ |
| 45 |
public function setup_hooks() { |
| 46 |
$this->setup_hooks_child(); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Calls the API |
| 51 |
* |
| 52 |
* @param string $attributes The attributes of the post body. |
| 53 |
*/ |
| 54 |
protected function call_api( $attributes ) { |
| 55 |
$slug = $this->product->get_slug(); |
| 56 |
$version = $this->product->get_version(); |
| 57 |
$attributes['slug'] = $slug; |
| 58 |
$attributes['version'] = $version; |
| 59 |
|
| 60 |
$response = wp_remote_post( $this->feedback_url, array( |
| 61 |
'body' => $attributes, |
| 62 |
) ); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Randomizes the options array |
| 67 |
* |
| 68 |
* @param array $options The options array. |
| 69 |
*/ |
| 70 |
function randomize_options( $options ) { |
| 71 |
$new = array(); |
| 72 |
$keys = array_keys( $options ); |
| 73 |
shuffle( $keys ); |
| 74 |
|
| 75 |
foreach ( $keys as $key ) { |
| 76 |
$new[ $key ] = $options[ $key ]; |
| 77 |
} |
| 78 |
|
| 79 |
return $new; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Abstract function for delegating to the child |
| 84 |
*/ |
| 85 |
protected abstract function setup_hooks_child(); |
| 86 |
|
| 87 |
} |
| 88 |
endif; |
| 89 |
|