PluginProbe
Qyrr – simply and modern QR-Code creation / 2.0.13
Qyrr – simply and modern QR-Code creation v2.0.13
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.13, at qyrr-code.php

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