{"id":22266461,"url":"https://github.com/objectivco/cgd_eddsl_magic","last_synced_at":"2025-06-20T00:02:54.260Z","repository":{"id":17553591,"uuid":"20356461","full_name":"Objectivco/CGD_EDDSL_Magic","owner":"Objectivco","description":"A drop-in class that magically manages your EDD SL plugin licensing.","archived":false,"fork":false,"pushed_at":"2024-01-15T22:44:38.000Z","size":91,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-27T16:47:31.662Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Objectivco.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-31T13:42:16.000Z","updated_at":"2024-01-11T21:58:16.000Z","dependencies_parsed_at":"2022-08-25T16:42:05.626Z","dependency_job_id":null,"html_url":"https://github.com/Objectivco/CGD_EDDSL_Magic","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Objectivco%2FCGD_EDDSL_Magic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Objectivco%2FCGD_EDDSL_Magic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Objectivco%2FCGD_EDDSL_Magic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Objectivco%2FCGD_EDDSL_Magic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Objectivco","download_url":"https://codeload.github.com/Objectivco/CGD_EDDSL_Magic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227895774,"owners_count":17836471,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T10:18:51.250Z","updated_at":"2024-12-03T10:18:51.779Z","avatar_url":"https://github.com/Objectivco.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"CGD_EDDSL_Magic\n===============\n\nA drop-in class that magically manages your EDD SL plugin licensing.\n\n#  What is magic and why do I need it?\nEDD's brilliant Software Licensing add-on is awesome, but its implementation examples are thin.  Managing the various activation and licensing states takes a good amount of research and setup.\n\nOnce you have it setup, it can be a major pain in the tucus to manage across your various plugins.\n\nFor example, I have 8 plugins.  Everytime I find a bug in my licensing code, I have to update 8 plugins that have 8 slightly different implementations.  It's a major headache.\n\n`CGD_EDDSL_Magic` fixes all of this.  With as little as a single line of code, you can add a fully functioning licensing settings page to your plugin.  \n\n## Installing\n\nThe best way to install is with composer:\n`composer require objectivco/cgd_eddsl_magic`\n\n### Alternative method\n1) Copy or clone CGD_EDDSL_Magic into your plugin project.  Put it in a lib or inc folder.\n\n2)  At the top of your main plugin file, or wherever you do your includes, add some code like:\n\n```php\nif ( ! class_exists( 'CGD_EDDSL_Magic' ) ) {\n\t// load our custom updater\n\tinclude( dirname( __FILE__ ) . '/lib/CGD_EDDSL_Magic/CGD_EDDSL_Magic.php' );\n}\n```\n\n## Instantiating \nIn your plugin constructor (or in the main plugin file if you're not using classes for some reason),  instantiate `CGD_EDDSL_Magic`.\n\n```php\n$updater = new CGD_EDDSL_Magic($prefix, $menu_slug,  $host_url, $plugin_version, $plugin_name, $plugin_author, $plugin_file, $theme = false, $beta = false, $home_url = false);\n```\n\n**Note: The last parameter, `$plugin_file` is technically optional, but it's better to pass it in. This should be the main file for your plugin, the one with the plugin header. If you're in the main plugin file, use `__FILE__`, otherwise, define it as a constant in your main plugin file and pass it in when you instantiate the class.**\n\n## The parameters:\n#### $prefix\nThis is a unique prefix for your instance.  It's used for saving settings and hooking up various behaviors.  Keep it short, and no spaces or weird symbols or other funny business.  Example: myplugin\n\n#### $menu_slug\nAssuming your plugin has a menu page, you would set the slug of that menu here so that `CGD_EDDSL_Magic` can add a submenu called \"License\" to this menu.  If you'd rather control this yourself, set to `false`.\n\n#### $host_url\nThe URL of the site that hosts your plugins.\n\n#### $plugin_version\nThe version of the plugin.\n\n#### $plugin_name\nThe name of the plugin as setup in EDD.\n\n#### $plugin_author\nThe author of the plugin.\n\n#### $plugin_file\nThe main plugin file.\n\n#### $theme\nSet to true for theme updates.\n\n#### $beta\nSet to true to enable beta versions.\n\n#### $home_url\nDefaults to false. If false, it uses home_url() for activation checks. Otherwise, you can pass in a URL to check.\n\n---\n\nIf you're using a class, it's probably a good idea to set a class variable called `updater` and then assign the new `CGD_EDDSL_Magic` instance to that. It will make it easier to access later.\n\n**In a basic setup, you're done at this point.  Your plugin will now have a fully functioning license settings page, added to whatever your parent menu is.  For more advanced options, continue below.**\n\n## What about updating themes?\n\nIf your project is a theme, you simply need to set the `$theme` parameter above to true. This makes the `$plugin_file` parameter uneccessary, so you can simply set this parameter to `false`. Either way, it will not be used.\n\n\n# Advanced Implementation\n\n## Controlling the licensing settings page\nBy default, a menu item called \"License\" is added to the parent menu of your choice. If you would like to have full control of where the license settings page is, that's actually really easy to do too.\n\nJust set `$menu_slug` to false in your instantation, and then drop this line in your admin page, wherever you prefer:\n``` php\n$updater-\u003eadmin_page();\n```\nObviously, the exact syntax will vary depending on how you implement it.  This is one reason I find it easier to set the updater instance as a class variable.\n\n**One important note: Do not place this line in another HTML form.  It will screw things up. Browsers hate nested forms. (and HTML standards do not permit them)**\n\n## Cronning license checks\nIf you want it,  `CGD_EDDSL_Magic` includes a way to force regular license checks.  To do this, you'd add the following code to your activation or deactivation hooks:\n\n### Activation hook\n``` php\n$this-\u003eupdater-\u003eset_license_check_cron();\n```\n\n### Deactivation hook\n``` php\n$this-\u003eupdater-\u003eunset_license_check_cron();\n```\n\nThis will create daily checks that keep your key_status variable up-to-date.\n\n# Really Advanced Implementation\n\nIf this does not satisfy you, and you want to add some type of nag to the plugin listing on the plugins page in WP admin, here's a quick example of how you might do that.  This is just a starting point, so you'll have to parse through it to figure out how it works.\n\n```php\n\tadd_action('admin_menu', 'add_key_nag', 11);\n\tfunction add_key_nag() {\n\t\tglobal $pagenow;\n\n\t    if( $pagenow == 'plugins.php' ) {\n\t        add_action( 'after_plugin_row_' . plugin_basename(__FILE__), 'after_plugin_row_message', 10, 2 );\n\t    }\n\t}\n\n\tfunction after_plugin_row_message() {\n\t\t$key_status = $this-\u003eupdater-\u003eget_field_value('key_status');\n\n\t\tif ( empty($key_status) ) return;\n\n\t\tif ( $key_status != \"valid\" ) {\n\t\t\t$current = get_site_transient( 'update_plugins' );\n\t\t\tif ( isset( $current-\u003eresponse[ plugin_basename(__FILE__) ] ) ) return;\n\n\t\t\tif ( is_network_admin() || ! is_multisite() ) {\n\t\t\t\t$wp_list_table = _get_list_table('WP_Plugins_List_Table');\n\t\t\t\techo '\u003ctr class=\"plugin-update-tr\"\u003e\u003ctd colspan=\"' . $wp_list_table-\u003eget_column_count() . '\" class=\"plugin-update colspanchange\"\u003e\u003cdiv class=\"update-message\"\u003e';\n\t\t\t\techo keynag();\n\t\t\t\techo '\u003c/div\u003e\u003c/td\u003e\u003c/tr\u003e';\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction keynag() {\n\t\treturn \"\u003cspan style='color:red'\u003eYou're missing out on important updates because your license key is missing, invalid, or expired.\u003c/span\u003e\";\n\t}\n```\n\n# Changelog\n## Version 0.5.3\n- Change license key field to a password field.\n\n## Version 0.5.2\n- Fixed bug with setting home url to passed in value.\n\n## Version 0.5.1\n- Ok, that deprecated option was a bad idea. I'm removing it and instead providing the ability to pass in the URL you want to use for activation with a default to `home_url()`\n\n## Version 0.5.0\n- Add deprecated_url option and default to true. This tells the updater to check `home_url()` for site activation actions instead of `get_site_url()`. New projects should use `get_site_url()`.\n- WP Coding Standards fixes.\n\n## Version 0.4.0\n- Fix return types.\n- Replace invalid reference to class EDD_SL_Theme_Updater with EDD_Theme_Updater.\n\n## Version 0.3.2\n- Composer package.\n- Update EDD_SL_Plugin_Updater.\n- Add some utility functions that we use internally that you may find useful. \n\n## Version 0.3.1\n- Add trailing slash to remote API url. Fixes odd bug with wp_remote_get().\n\n## Version 0.3\n- Added theme update support!\n\n## Version 0.2\n- Added url parameter to API requests for more reliable handling.\n\n## Version 0.1\n- Initial release.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobjectivco%2Fcgd_eddsl_magic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fobjectivco%2Fcgd_eddsl_magic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobjectivco%2Fcgd_eddsl_magic/lists"}