PluginProbe
Qyrr – simply and modern QR-Code creation / 1.2
Qyrr – simply and modern QR-Code creation v1.2
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 1.2, at qyrr-code.php

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