Skip to content

Instantly share code, notes, and snippets.

@goranefbl
Created October 23, 2023 07:28
Show Gist options
  • Select an option

  • Save goranefbl/fbf83290e5f9ab3ceacd433492029e12 to your computer and use it in GitHub Desktop.

Select an option

Save goranefbl/fbf83290e5f9ab3ceacd433492029e12 to your computer and use it in GitHub Desktop.
just
<?php
if (!defined('ABSPATH'))
exit;
class AWDP_Api
{
/**
* @var object
* @access private
* @since 1.0.0
*/
private static $_instance = null;
/**
* The version number.
* @var string
* @access public
* @since 1.0.0
*/
public $_version;
private $_active = false;
public function __construct()
{
add_action('rest_api_init', function () {
register_rest_route('awdp/v1', '/rules/', array(
'methods' => 'GET',
'callback' => array($this, 'get_rules'),
'permission_callback' => array($this, 'get_permission')
));
});
}
/**
*
* Ensures only one instance of AWDP is loaded or can be loaded.
*
* @since 1.0.0
* @static
* @see WordPress_Plugin_Template()
* @return Main AWDP instance
*/
public static function instance($file = '', $version = '1.0.0')
{
if (is_null(self::$_instance)) {
self::$_instance = new self($file, $version);
}
return self::$_instance;
}
function action_delete($data)
{
$data = $data->get_params();
if ($data['id']) {
$pt = get_post_type($data['id']);
if ($pt == AWDP_POST_TYPE && wp_delete_post($data['id'], true)) {
return admin_url('admin.php?page=awdp_admin_ui');
} else if ($pt == AWDP_PRODUCT_LIST && wp_delete_post($data['id'], true)) {
return admin_url('admin.php?page=awdp_admin_product_lists');
}
}
}
/**
* Permission Callback
**/
public function get_permission()
{
if (current_user_can('administrator') || current_user_can('manage_woocommerce')) {
return true;
} else {
return false;
}
}
/**
* Cloning is forbidden.
*
* @since 1.0.0
*/
public function __clone()
{
_doing_it_wrong(__FUNCTION__, __('Cheatin&#8217; huh?'), $this->_version);
}
/**
* Unserializing instances of this class is forbidden.
*
* @since 1.0.0
*/
public function __wakeup()
{
_doing_it_wrong(__FUNCTION__, __('Cheatin&#8217; huh?'), $this->_version);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment