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

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