QR code integration?
-
Hi Barry,
Sorry to bring in codes from other developers into the mix, but alas my PHP coding abilities are failing me here…I’m currently using your great plugin on pages such as this one: https://meridianonline.staging.wpengine.com/events-program/
Basically, each of these pages displays an array of event post excerpts that can then be printed out as posters.
The problem with paper posters, of course, is that they make it difficult for people to click hyperlinks!So my aim would be to automatically integrate a QR code corresponding to each event post next to the post excerpt, so that people can learn more about it by scanning said code and reading the entire post on their mobile.
Being rather disappointed with the only available WP QR Code plugin I can find on the WP repo, I’m now experimenting with the method presented there: https://www.sitepoint.com/add-qr-codes-wordpress-posts/
(I’ll paste the code below for extra clarity)Thanks to that script, I’m able to generate QR Codes that are automatically posted at the end of every single post and page on my site. Naturally, that’s not particularly desirable.
Do you think there would be a convenient way to restrict QR code generation only to the items currently created by Events Rocket on pages like the one linked to above, instead?(I guess I need to edit my current Events Rocket “shortcode.embeds.php” file to get there, but I’m still probbing around without much success)
Thanks in advance ??
=====
For reference, here’s the plugin code:<?php /* Plugin Name: Awesome QR Code Plugin URI: https://sitepoint.com/ */ include("qrcode.php"); function qr_code($content) { $url = get_permalink(); $qr = new qrcode(); $qr->text($url); $html = "<p><b>QR Code:</b></p><p><img src='".$qr->get_link()."' border='0'/></p>"; $content .= $html; return $content; } add_filter("the_content", "qr_code"); ?>
and the actual qrcode.php script:
<?php /************************************************************* * This script is developed by Arturs Sosins aka ar2rsawseen, https://webcodingeasy.com **************************************************************/ class qrcode { private $data; //creating code with link mtadata public function link($url){ if (preg_match('/^http:\/\//', $url) || preg_match('/^https:\/\//', $url)) { $this->data = $url; } else { $this->data = "https://".$url; } } //...more options// //getting image public function get_image($size = 150, $EC_level = 'L', $margin = '0'){ $ch = curl_init(); $this->data = urlencode($this->data); curl_setopt($ch, CURLOPT_URL, 'https://chart.apis.google.com/chart'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, 'chs='.$size.'x'.$size.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$this->data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $response = curl_exec($ch); curl_close($ch); return $response; } //getting link for image public function get_link($size = 150, $EC_level = 'L', $margin = '0'){ $this->data = urlencode($this->data); return 'https://chart.apis.google.com/chart?chs='.$size.'x'.$size.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$this->data; } //forcing image download public function download_image($file){ header('Content-Disposition: attachment; filename=QRcode.png'); header('Content-Type: image/png'); echo $file; } //save image to server public function save_image($file, $path = "./QRcode.png"){ file_put_contents($path, $file); } } ?>
- The topic ‘QR code integration?’ is closed to new replies.