PHP code example of rlankhorst / wp-consent-level-api
1. Go to this page and download the library: Download rlankhorst/wp-consent-level-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rlankhorst / wp-consent-level-api example snippets
//declare compliance with consent level API
$plugin = plugin_basename( __FILE__ );
add_filter( "wp_consent_api_registered_{$plugin}", '__return_true' );
/**
* Example how a plugin can register cookies with the consent API
* These cookies can then be shown on the front-end, to the user, with wp_get_cookie_info()
*/
function my_wordpress_register_cookies(){
if ( function_exists( 'wp_add_cookie_info' ) ) {
wp_add_cookie_info( 'AMP_token', 'AMP', 'marketing', __( 'Session' ), __( 'Store a unique User ID.' ), false, false, false );
}
}
add_action('plugins_loaded', 'my_wordpress_register_cookies');
//check if user has given marketing consent. Possible consent categories/purposes:
//functional, preferences', statistics', statistics-anonymous', statistics', marketing',
if (wp_has_consent('marketing')){
//do marketing stuff
}
//set the consent type (optin, optout, default false)
add_filter( 'wp_get_consent_type', 'my_set_consenttype' , 10, 1 );
function my_set_consenttype($consenttype){
return 'optin';
}
//filter consent categories types, example: remove the preferences category
add_filter( 'wp_consent_categories', 'my_set_consentcategories' , 10, 1 );
function my_set_consentcategories($consentcategories){
unset($consentcategories['preferences']);
return $consentcategories;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.