PluginProbe
Qyrr – simply and modern QR-Code creation / 2.0.9
Qyrr – simply and modern QR-Code creation v2.0.9
2.0.13 2.0.12 2.0.11 trunk 0.8 1.2 1.3 1.4 1.5 2.0.10 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9
qyrr-code / qyrr-code.php

qyrr-code.php in Qyrr – simply and modern QR-Code creation 2.0.9, at qyrr-code.php

189 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: Qyrr-Code
5 * Plugin URI: https://qyrrwp.com
6 * Description: QR-Code generation, management and tracking as it should be.
7 * Version: 2.0.9
8 * Author: WPChill
9 * Author URI: https://wpchill.com
10 * License: GPL-2.0+
11 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
12 * Text Domain: qyrr-code
13 * Domain Path: /languages
14 *
15 *
16 *
17 * NOTE:
18 * Patrick Posner transferred ownership rights on: 11th of February, 2026 when ownership was handed over to WPChill
19 */
20 define( 'QYRR_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
21 define( 'QYRR_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) );
22 define( 'QYRR_VERSION', '2.0.9' );
23 // load setup.
24 require_once QYRR_PATH . '/inc/freemius-setup.php';
25 add_action( 'plugins_loaded', 'qyrr_run_plugin' );
26 // run plugin.
27 if ( !function_exists( 'qyrr_run_plugin' ) ) {
28 add_action( 'plugins_loaded', 'qyrr_run_plugin' );
29 /**
30 * Run plugin
31 *
32 * @return void
33 */
34 function qyrr_run_plugin() {
35 require_once QYRR_PATH . '/inc/class-qyrr-block-editor.php';
36 require_once QYRR_PATH . '/inc/class-qyrr-admin.php';
37 require_once QYRR_PATH . '/inc/admin/inc/class-qyrr-settings.php';
38 require_once QYRR_PATH . '/inc/class-qyrr-meta.php';
39 require_once QYRR_PATH . '/inc/class-qyrr-rest.php';
40 require_once QYRR_PATH . '/inc/class-qyrr-shortcode.php';
41 qyrr\QYRR_Block_Editor::get_instance();
42 qyrr\QYRR_Admin::get_instance();
43 qyrr\QYRR_Settings::get_instance();
44 qyrr\QYRR_Meta::get_instance();
45 qyrr\QYRR_Rest::get_instance();
46 qyrr\QYRR_Shortcode::get_instance();
47 }
48
49 // Register block.
50 add_action( 'init', 'qyrr_register_qyrr_block' );
51 function qyrr_register_qyrr_block() {
52 if ( qyrr_is_post_type() ) {
53 register_block_type( __DIR__ . '/build/qr' );
54 }
55 }
56
57 add_action( 'wp_enqueue_scripts', 'qyrr_register_scripts' );
58 function qyrr_register_scripts() {
59 $qr_asset_file = (include plugin_dir_path( __FILE__ ) . 'build/qr/index.asset.php');
60 wp_register_script(
61 'qyrr-code-script',
62 plugins_url( 'build/qr/index.js', __FILE__ ),
63 $qr_asset_file['dependencies'],
64 $qr_asset_file['version']
65 );
66 }
67
68 // Register Block styles and scripts.
69 add_action( 'enqueue_block_editor_assets', 'qyrr_add_block_editor_assets' );
70 function qyrr_add_block_editor_assets() {
71 if ( qyrr_is_post_type() ) {
72 $qr_asset_file = (include plugin_dir_path( __FILE__ ) . 'build/qr/index.asset.php');
73 $qyrr_options = get_option( 'qyrr' );
74 $script_args = array(
75 'is_pro' => false,
76 );
77 if ( isset( $qyrr_options['fonts_api_key'] ) ) {
78 $script_args['google_fonts_api_key'] = $qyrr_options['fonts_api_key'];
79 }
80 // Ad home URL to args.
81 $script_args['home_url'] = home_url();
82 // Handle rerender on update.
83 if ( qyrr_is_post_type() ) {
84 wp_enqueue_script(
85 'qyrr-code-rerender',
86 QYRR_URL . '/assets/rerender.js',
87 array(
88 'wp-api',
89 'wp-components',
90 'wp-element',
91 'wp-api-fetch',
92 'wp-data',
93 'wp-i18n'
94 ),
95 QYRR_VERSION,
96 true
97 );
98 }
99 wp_enqueue_script(
100 'qyrr-code-script',
101 plugins_url( 'build/qr/index.js', __FILE__ ),
102 $qr_asset_file['dependencies'],
103 $qr_asset_file['version']
104 );
105 wp_localize_script( 'qyrr-code-script', 'license', $script_args );
106 wp_enqueue_style( 'qyrr-code-style', plugins_url( 'build/qr/index.css', __FILE__ ) );
107 }
108 $selector_asset_file = (include plugin_dir_path( __FILE__ ) . 'build/qr-selector/index.asset.php');
109 $uploads_dir = wp_upload_dir();
110 wp_enqueue_script(
111 'qyrr-code-selector-script',
112 plugins_url( 'build/qr-selector/index.js', __FILE__ ),
113 $selector_asset_file['dependencies'],
114 $selector_asset_file['version']
115 );
116 wp_localize_script( 'qyrr-code-selector-script', 'qyrr_options', array(
117 'baseurl' => $uploads_dir['baseurl'],
118 ) );
119 wp_enqueue_style( 'qyrr-code-selector-style', plugins_url( 'build/qr-selector/index.css', __FILE__ ) );
120 // Make the blocks translatable.
121 if ( function_exists( 'wp_set_script_translations' ) ) {
122 wp_set_script_translations( 'qyrr-code-script', 'qyrr-code', plugin_dir_path( __FILE__ ) . 'languages' );
123 wp_set_script_translations( 'qyrr-code-selector-script', 'qyrr-code', plugin_dir_path( __FILE__ ) . 'languages' );
124 }
125 }
126
127 register_activation_hook( __FILE__, 'qyrr_activate' );
128 /**
129 * Add a flag that will allow to flush the rewrite rules when needed.
130 */
131 function qyrr_activate() {
132 if ( !get_option( 'qyrr_activated' ) ) {
133 add_option( 'qyrr_activated', true );
134 }
135 }
136
137 add_action(
138 'upgrader_process_complete',
139 'qyrr_upgrade',
140 10,
141 2
142 );
143 /**
144 * Add a flag that will allow to flush the rewrite rules when needed.
145 * @throws Exception
146 */
147 function qyrr_upgrade( $upgrader_object, $options ) {
148 $current_plugin_path_name = plugin_basename( __FILE__ );
149 if ( $options['action'] == 'update' && $options['type'] == 'plugin' ) {
150 foreach ( $options['plugins'] as $each_plugin ) {
151 if ( $each_plugin == $current_plugin_path_name ) {
152 if ( !get_option( 'qyrr_activated' ) ) {
153 add_option( 'qyrr_activated', true );
154 }
155 }
156 }
157 }
158 }
159
160 function qyrr_is_post_type() {
161 // Check if this is the intended custom post type
162 if ( is_admin() ) {
163 global $pagenow;
164 $typenow = '';
165 if ( 'post-new.php' === $pagenow ) {
166 if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) {
167 $typenow = $_REQUEST['post_type'];
168 }
169 } elseif ( 'post.php' === $pagenow ) {
170 if ( isset( $_GET['post'] ) && isset( $_POST['post_ID'] ) && (int) $_GET['post'] !== (int) $_POST['post_ID'] ) {
171 // Do nothing
172 } elseif ( isset( $_GET['post'] ) ) {
173 $post_id = (int) $_GET['post'];
174 } elseif ( isset( $_POST['post_ID'] ) ) {
175 $post_id = (int) $_POST['post_ID'];
176 }
177 if ( $post_id ) {
178 $post = get_post( $post_id );
179 $typenow = $post->post_type;
180 }
181 }
182 if ( $typenow === 'qr' ) {
183 return true;
184 }
185 }
186 return false;
187 }
188
189 }