通过许可证密钥验证保护Wordpress主题 [英] Protect wordpress theme with license key validation

查看:105
本文介绍了通过许可证密钥验证保护Wordpress主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正计划开发一些专业的Wordpress主题,并希望使用许可证密钥对其进行保护吗?

I'm planning to develop some professional Wordpress Themes and would like to protect it using license keys, is it possible?

如果是这样,有人愿意链接到一些帖子或文章来帮助我入门吗?

If so, would any one be willing to link to some posts or articles to help me get started?

推荐答案

您可以在自己的服务器上设置数据库,并保留主题的许可证密钥和许可的url.然后,为您的主题设置一个管理页面.在其中,首先注册一个许可证设置数组.然后,在该页面上实现一个隐藏的设置字段,只要站点管理员正在更新许可证密钥,该字段就会更新.更新功能将通过许可证密钥和$_SERVER的主机,并将隐藏的license_settings字段设置为true或false,将请求发送到您的服务器.

You could set up a database on your own server, holding the license key and the licensed url for the theme. Then, set up an admin page for your theme. Within, first register a license settings array. Then implement a hidden settings field on that same page that gets updated whenever the license key is being updated by site admin. the update function sends a request to your server passing the license key and the $_SERVER's host and setting the hidden license_settings field to either true or false.

真正简化的代码如下:

functions.php

<?php
// functions.php
require("myadminpage.php");

# Functions follow here...
?>

myadminpage.php

<?php
// myadminpage.php

// register settings
function my_settings_init() {
  register_setting('settings_license', 'settings_license');
}
// register admin page
function my_add_admin_page() {
  add_menu_page(__( '' ), __( 'Manage License' ), 'administrator', 'myadminpage', 'my_admin_page');
}
add_action('admin_init', 'my_settings_init');   
add_action('admin_menu', 'my_add_admin_page' );

if(isset($_GET["settings-updated"]) && $_GET["settings-updated"] == true) { 
    $options = get_option('settings_license');
    $key = $options["key"];
    $host = parse_url($GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'], PHP_URL_HOST);
    $url = sprintf("http://you.com/check-license.php?key=%s&url=%s", $key, $host);
    $options["valid"] = trim(file_get_contents($url)) == 1) ? "true" : "false"; 
    update_option('settings_license', $options);
}

// callback function that renders your admin page
function my_admin_page() {
  settings_fields('settings_license'); 
  $options = get_option('settings_license'); 
  ?>
  <form method="post" action="options.php"> 
  <input id="settings_license[key]" type="text" name="settings_license[key]" value="<?php echo $options["key"]; ?>">
  <input id="settings_license[valid]" type="hidden" name="settings_license[valid]" value="<?php echo $options["valid"]; ?>">
  <input type="submit" value="Save"> 
  </form> 
  <?php
}
?>

现在,您可以在需要/需要时获得许可选项,并以所需的任何方式处理无效使用情况.例如(一种粗鲁的方式):

Now you can, when ever you need/want, get the license options and handle the invalid usage in any way you want. Eg (a rude way):

header.php

<?php
// very first line
$license = get_option('settings_license');
// see: http://ckon.wordpress.com/2006/08/09/server-request_uri-doesnt-always-work-correctly-heres-how-to-fix/
$ruri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'];
if(!preg_match("#wp-admin#", $ruri) && $license["valid"] != "true") {
  wp_die( __('This website uses unlicensed software.<br>Administrators can update their license key <a href="'. get_bloginfo('url') .'/wp-admin/admin.php?page=myadminpage.php">here</a>.') );
}

# rest of header.php comes here..    

最后混淆您的php代码(例如 http://www.ioncube.com/sa_encoder.php),您就完成了.但是,请确保您没有违反任何其他许可证,例如WP的许可证.如果最终代码中仅使用一行WordPress核心功能,则您不能使用WP(即GPL)以外的任何其他许可证来发布它.

Finally obfuscate your php code (eg http://www.ioncube.com/sa_encoder.php) and you're done. However, make sure you're not violating any other licenses, such as WP's. If there's one single line of WordPress core functions used within your final code, you can not release it under any other license than WP, which is GPL.

这篇关于通过许可证密钥验证保护Wordpress主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆