WordPress plugin intelligence profile

Cookie Connector For Themer

Cookie Connector for (Beaver) Themer

WP PlugIndex snapshot

Current directory snapshot

Tested up to WordPress 5.5
Current version1.3.1
WordPress coverageTested up to WordPress 5.5
Minimum stackWP 4.7 · PHP 5.6.3
Directory statusactive
Last directory update1 Jun 20233y ago
Active installations10Adoption metric — not a quality score
WordPress.org ratingNo WordPress.org ratings yet
Official packageDirect from WordPress.org

Repository metrics are context, not quality scores. Active installations measure adoption and can strongly reflect a plugin’s age and historical popularity. Ratings, recent updates and “Tested up to” metadata also do not guarantee modern code, error-free operation, security, feature completeness or suitability for a particular site. Why active installs don’t tell the whole story →

WP PlugIndex currently records Cookie Connector For Themer version 1.3.1 as active, updated 3y ago and tested up to WordPress 5.5.

Overview

About this plugin

Cookie Connector for (Beaver) Themer

##

Plugin description

Cookie Connector for Beaver Themer is an unofficial addon-plugin for the popular Beaver Themer plugin. It allows you to read cookie-values using the Beaver Themer Connector and use Conditional Logic to hide/show seperate nodes (modules, columns and/or rows) using cookie values.

Cookie Connector also allows you to create cookies using an AJAX call. For security measures you will need to write the AJAX yourself, but an example file on how to do that can be found here, in the example folder:

com/badabingbreda/cookie-connector-for-themer/

Using the Cookie Connector

You can display the Cookie Connector wherever you’d normally insert it as a string, using either the connect or insert button.

Using the Conditional Logic filter

Because cookies have a certain validity, it can’t return a value when the cookie isn’t there or has become invalid. The Conditional Logic filter has an extra parameter to set a default value for whenever it doesn’t return anything. Setting this parameter return that value whenever it doesn’t exist.

Writing cookies values

Cookies are written before any headers are written to the visitor’s browser. The downside to that is that cookies can only be read when the visitor’s sends a request, since they are sent over WITH the request. This means that you can’t write a cookie’s value and immediately read that cookies new value, within a single run of a page-call.

To work around that, cookies can be written using an AJAX call.

“Cookie Connector for Themer” enqueues a script that registers the cookieConnector object, which handles the security and sending of requests.

Let’s consider the following html-code that is used in a HTML module:

set( 'unsetmycookie' );">Unset cookie value</a></p>

The first parameter is the actionname that is going to be called in the PHP script, so in this example (see below) the part after ‘wp_ajax_’ and ‘wp_ajax_nopriv_’.

log dump of the response, should you need to know what’s being answered:

set( 'unsetmycookie', {}, true );">Unset cookie value</a></p>

Adding the PHP code to create/change/delete the cookie

Clicking the link wil trigger an AJAX call that will set a cookie on the visitor’s device, if their browser allows it.

On the server-side, you will need to add one or two ajax callbacks, depending if the call can be made without being logged in.

php add_action( 'wp_ajax_setmycookie', 'callback_setmycookie' ); add_action( 'wp_ajax_nopriv_setmycookie', 'callback_setmycookie' ); add_action( 'wp_ajax_unsetmycookie', 'callback_setmycookie' ); add_action( 'wp_ajax_nopriv_unsetmycookie', 'callback_setmycookie' );

function callback_setmycookie() { // first check if this ajax call is // done using the script belonging to the installation // if(! ' ); wp_die(); }

defined( 'DOING_AJAX' ) ) define( 'DOING_AJAX', TRUE );

// set your cookie name here $cookie_name = 'mylanguage'; $default_validity = 60 * 60; // = 60 minutes

// try to get the cookie_value $cookie_value = isset( $_GET['cv'] )? $_GET['cv']: false; // try to get the cookie validity period. If not default to default validity $cookie_valid = isset( $_GET['valid'] )?

$_GET['valid']: $default_validity;

// if the action is setmycookie we need a cookie_value (cv) because else it will fail. Check for it and return an error if there isn't one. if (!

$cookie_value && $_GET['action'] == 'setmycookie' ) { wp_send_json_error( array( 'success' => false, 'error' => '402', 'message' => 'cookie not set, no value given. ( cv )' ) ); }

" ) );

} wp_die(); }

It is advised to use wp_send_json with a ‘success’ parameter (either true or false) so that you check it in your javascript and add actions after sending the cookieConnector() command, for instance a reload of the page or forwarding to an url that you received from the server based on the click.

For instance, the javascript below will try to create the cookie. 5 seconds.

message + '\r You can now safely shut down your browser, restart and visit this URL. reload(); }, 1500); } }); } </script>

Special thanks

Thanks to 10UP for creating this github action for easy deployment. com/marketplace/actions/wordpress-plugin-deploy

version history

1

md (this file). Small fix for isset because it’s not the value that we want (could be falsy) but return if the cookie is set.

0

Rewrite of plugin using Autoloader. Fixed isset error.

0

Removed admin_notice so that plugin can be used without Beaver Themer and Beaver Builder too (scripts), for ajax calls.

0

4 too

1

Updated example code

0

Initial release (January 18th, 2019)

WordPress.org metadata

Plugin tags

Topics listed for this plugin in the WordPress.org directory.

  • beaver builder
  • beaver themer
  • connector
  • cookie
Compatibility & maintenance

Compatibility & maintenance

Tested up to WordPress 5.5

Not yet marked as tested with WordPress 7.1. WordPress.org currently lists Tested up to 5.5.

Current WordPress releaseWordPress 7.1
WordPress.org Tested up to5.5
Minimum requirementsWordPress 4.7 · PHP 5.6.3
Update activity1 Jun 20233y ago

“Tested up to” is directory metadata supplied by the plugin author. WP PlugIndex does not turn an older declaration into a claim that the plugin is incompatible.

Changes recorded by WP PlugIndex

Recent tracked changes

No tracked version or compatibility changes have been recorded by WP PlugIndex yet.

Tracking & source

WP PlugIndex tracks public WordPress.org directory metadata and records selected version, compatibility and availability changes as they are detected.

Plugin watchlist

Watch this plugin

Sign in to your WP PlugIndex account or create a free account. Free accounts can watch up to 5 plugins and see what changed.

Watch limit

Watchlist limit reached

You have reached your current active watch limit.