Skip to content

Commit ad2fa19

Browse files
committed
Create main feature of plugin
0 parents  commit ad2fa19

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
//Silence is golden

posts-qr-code.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* Plugin Name: Posts QR Code
4+
* Description: Display QR Code under every posts
5+
* Plugin URI: http://github.com/ikamal7/posts-qr-code-wp-plugin/
6+
* Author: Kamal Hosen
7+
* Author URI: http://ikamal.me/
8+
* Version: 1.0.0
9+
* License: GPL2
10+
* Text Domain: posts-qrcode
11+
* Domain Path: /languages/
12+
*/
13+
14+
/**
15+
* Copyright (C) 2018 Kamal kamalhosen8920@gmail.com
16+
*
17+
* This program is free software; you can redistribute it and/or modify
18+
* it under the terms of the GNU General Public License, version 2, as
19+
* published by the Free Software Foundation.
20+
*
21+
* This program is distributed in the hope that it will be useful,
22+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
* GNU General Public License for more details.
25+
*
26+
* You should have received a copy of the GNU General Public License
27+
* along with this program; if not, write to the Free Software
28+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29+
*/
30+
31+
32+
function pqrc_load_textdomain() {
33+
load_plugin_textdomain( 'posts-qrcode', false, dirname( __FILE__ ) . '/languages' );
34+
}
35+
36+
37+
function pqrc_display_qr_code( $content ) {
38+
$current_post_id = get_the_ID();
39+
$current_post_title = get_the_title( $current_post_id );
40+
$current_post_url = urlencode_deep( get_the_permalink( $current_post_id ) );
41+
$current_post_type = get_post_type( $current_post_id );
42+
/**
43+
* Post Type Check
44+
*/
45+
$excluded_post_types = apply_filters( 'pqrc_excluded_post_types', array() );
46+
if ( in_array( $current_post_type, $excluded_post_types ) ){
47+
return $content;
48+
}
49+
50+
/**
51+
* Dimension Hook
52+
*
53+
*/
54+
$dimension = apply_filters('pqrc_qrcode_img_dimension', '185x185');
55+
56+
/**
57+
* Image Attributes
58+
*/
59+
$image_attributes = apply_filters('pqrc_image_attributes', null);
60+
/**
61+
* Generate QR Code
62+
*/
63+
$img_src = sprintf( 'https://api.qrserver.com/v1/create-qr-code/?size=%s&data=%s', $dimension, $current_post_url );
64+
$content .= sprintf( '<div class="qrcode"><img %s src="%s" alt="%s" /></div>', $image_attributes, $img_src, $current_post_title );
65+
66+
return $content;
67+
}
68+
69+
add_filter( 'the_content', 'pqrc_display_qr_code' );
70+

0 commit comments

Comments
 (0)