false,
"id"=>false,
"bundle"=>false,
"pro" => "",
"document"=>"#"
);
$args = wp_parse_args( $data, $defaults );
$this->data = $args;
add_filter( 'plugin_action_links_' . $this->data["plugin"] , array( $this, 'add_action' ) );
add_action( 'wp_ajax_rednumber_check_purchase_code', array($this,'check_purchase_code_ajax') );
add_action( 'wp_ajax_rednumber_check_purchase_code_remove', array($this,'check_purchase_remove_code_ajax') );
add_action('admin_enqueue_scripts', array($this,'add_js'));
add_action( 'admin_notices', array($this,"add_pro") );
add_action( 'admin_head', array($this,"add_head") );
}
function add_head() {
?>
data["id"] );
if($check != "ok" ) {
if ( in_array( $pagenow, $admin_pages )) {
?>
data["id"] );
$class_1 = "";
$class_2 = "";
if( $check =="ok" ){
$class_1 = "hidden";
}else{
$class_2 = "hidden";
}
$mylinks = array(
'
'.esc_html__("Get pro version","rednumber").'',
);
$mylinks[] ='Document';
return array_merge( $links, $mylinks );
}
function check_purchase_code_ajax(){
$code = sanitize_text_field($_POST["code"]);
$id = sanitize_text_field($_POST["id"]);
$status = $this->check_purchase_code($code,$id);
if( $status == "ok"){
update_option( '_redmuber_item_'.$id, "ok" );
update_option( '_redmuber_item_'.$id."_code", $code );
}
echo esc_attr($status);
die();
}
function check_purchase_remove_code_ajax(){
$id = sanitize_text_field($_POST["id"]);
$code = sanitize_text_field($_POST["code"]);
delete_option('_redmuber_item_'.$id);
delete_option('_redmuber_item_'.$id."_code");
$personalToken = "uzAMx8rZ3FRV0ecu8t1pXNWG0d0NA6qL";
$userAgent = "Purchase code verification";
$ch = curl_init();
$domain_name = preg_replace('/^www\./','',$_SERVER['SERVER_NAME']);
curl_setopt_array($ch, array(
CURLOPT_URL => "https://add-ons.org/wp-json/removepurchase_code/apiv2/token/{$code}/".htmlentities($domain_name),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 20,
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer {$personalToken}",
"User-Agent: {$userAgent}"
)
));
$response = curl_exec($ch);
if (curl_errno($ch) > 0) {
return "Error connecting to API: " . curl_error($ch);
}
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($responseCode === 404) {
return "The purchase code was invalid";
}
if ($responseCode !== 200) {
return "Failed to validate code due to an error: HTTP {$responseCode}";
}
$body = json_decode($response,true);
if ($body === false && json_last_error() !== JSON_ERROR_NONE) {
return "Error parsing response";
}
die();
}
function resolve_root_domain($url, $max=6){
$domain = parse_url($url, PHP_URL_HOST);
if (!strstr(substr($domain, 0, $max), '.'))
return ($domain);
else
return (preg_replace("/^(.*?)\.(.*)$/", "$2", $domain));
}
function check_purchase_code($code,$id_item){
$personalToken = "uzAMx8rZ3FRV0ecu8t1pXNWG0d0NA6qL";
$userAgent = "Purchase code verification";
$ch = curl_init();
$domain_name = preg_replace('/^www\./','',$_SERVER['SERVER_NAME']);
curl_setopt_array($ch, array(
CURLOPT_URL => "https://add-ons.org/wp-json/checkpurchase_code/apiv2/token/{$code}/".htmlentities($domain_name)."/".$id_item,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 20,
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer {$personalToken}",
"User-Agent: {$userAgent}"
)
));
$response = curl_exec($ch);
if (curl_errno($ch) > 0) {
return "Error connecting to API: " . curl_error($ch);
}
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($responseCode === 404) {
return "The purchase code was invalid";
}
if ($responseCode !== 200) {
return "Failed to validate code due to an error: HTTP {$responseCode}";
}
$body = json_decode($response,true);
if ($body === false && json_last_error() !== JSON_ERROR_NONE) {
return "Error parsing response";
}
if( isset($body["check"]) && $body["check"] == "ok" ){
return "ok";
}else{
if( isset($body["check"]) ){
return $body["check"];
}else{
return "Please choose other purchase.";
}
}
}
}
}