PluginProbe
Recipe Cards For Your Food Blog from Zip Recipes / trunk
Recipe Cards For Your Food Blog from Zip Recipes vtrunk
trunk 8.0.8 8.0.9 8.1.0 8.1.1 8.2.8
zip-recipes / zip-recipes.php

zip-recipes.php in Recipe Cards For Your Food Blog from Zip Recipes trunk, at zip-recipes.php

289 lines 12.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: Zip Recipes Lover
5 Text Domain: zip-recipes
6 Domain Path: /languages
7 Plugin URI: https://ziprecipes.net/
8 Plugin GitHub: https://github.com/really-simple-plugins/zip-recipes-free
9 Description: A plugin that adds all the necessary microdata to your recipes, so they will show up in Google's Recipe Search
10 Version: 8.2.8
11 Author: Igor Benić
12 Author URI: https://ibenic.com/
13 License: GPLv3 or later
14 Copyright 2020 Rogier Lankhorst
15 */
16 /*
17 Zip Recipes is free software: you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation, either version 3 of the License, or
20 (at your option) any later version.
21
22 Zip Recipes Plugin is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with Zip Recipes Plugin. If not, see <http://www.gnu.org/licenses/>.
29 */
30 namespace ZRDN;
31
32 // Make sure we don't expose any info if called directly
33 defined( 'ABSPATH' ) or die( "Error! Cannot be called directly." );
34 if ( !function_exists( '\\ZRDN\\zr_fs' ) ) {
35 // Create a helper function for easy SDK access.
36 function zr_fs() {
37 global $zr_fs;
38 if ( !isset( $zr_fs ) ) {
39 // Include Freemius SDK.
40 require_once dirname( __FILE__ ) . '/freemius/start.php';
41 $zr_fs = fs_dynamic_init( array(
42 'id' => '14746',
43 'slug' => 'zip-recipes',
44 'premium_slug' => 'zip-recipes-lover',
45 'type' => 'plugin',
46 'public_key' => 'pk_8fce9733a1349d1c76abfbef87413',
47 'is_premium' => false,
48 'premium_suffix' => 'Lover',
49 'has_addons' => false,
50 'has_paid_plans' => true,
51 'menu' => array(
52 'slug' => 'zrdn-recipes',
53 'support' => false,
54 ),
55 'is_live' => true,
56 'is_org_compliant' => true,
57 ) );
58 }
59 return $zr_fs;
60 }
61
62 // Init Freemius.
63 zr_fs();
64 function zr_fs_custom_connect_message_on_update(
65 $message,
66 $user_first_name,
67 $plugin_title,
68 $user_login,
69 $site_link,
70 $freemius_link
71 ) {
72 return sprintf(
73 __( 'Hey %1$s' ) . ',<br>' . __( 'Please help us improve %2$s! If you opt-in, some data about your usage of %2$s will be sent to %5$s. If you skip this, that\'s okay! %2$s will still work just fine.', 'zip-recipes' ),
74 $user_first_name,
75 '<b>' . $plugin_title . '</b>',
76 '<b>' . $user_login . '</b>',
77 $site_link,
78 $freemius_link
79 );
80 }
81
82 zr_fs()->add_filter(
83 'connect_message_on_update',
84 __NAMESPACE__ . '\\zr_fs_custom_connect_message_on_update',
85 10,
86 6
87 );
88 $old_edd_license = get_option( 'zrdn_license_key' );
89 if ( $old_edd_license ) {
90 zr_fs()->override_i18n( array(
91 'activate-free-version' => __( "Continue using your old license", 'zip-recipes' ),
92 ) );
93 }
94 // Signal that SDK was initiated.
95 do_action( 'zr_fs_loaded' );
96 }
97 if ( !function_exists( __NAMESPACE__ . '\\zrdn_activation_check' ) ) {
98 /**
99 * Checks if the plugin can safely be activated, at least php 5.6 and wp 4.6
100 * @since 7.0.0
101 */
102 function zrdn_activation_check() {
103 if ( version_compare( PHP_VERSION, '7.2', '<' ) ) {
104 deactivate_plugins( plugin_basename( __FILE__ ) );
105 wp_die( __( 'Zip Recipes cannot be activated. The plugin requires PHP 7.2 or higher', 'zip-recipes' ) );
106 }
107 global $wp_version;
108 if ( version_compare( $wp_version, '4.9', '<' ) ) {
109 deactivate_plugins( plugin_basename( __FILE__ ) );
110 wp_die( __( 'Zip Recipes cannot be activated. The plugin requires WordPress 4.9 or higher', 'zip-recipes' ) );
111 }
112 if ( file_exists( WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'zip-recipes-premium' . DIRECTORY_SEPARATOR . 'zip-recipes-lover.php' ) ) {
113 deactivate_plugins( 'zip-recipes-premium/zip-recipes-lover.php' );
114 }
115 }
116
117 register_activation_hook( __FILE__, __NAMESPACE__ . '\\zrdn_activation_check' );
118 }
119 if ( defined( 'ZRDN_PLUGIN_BASENAME' ) ) {
120 if ( defined( 'ZRDN_FREE' ) ) {
121 deactivate_plugins( 'zip-recipes/zip-recipes.php' );
122 //add_action('admin_notices', __NAMESPACE__ . '\zrdn_notice_free_active');
123 } elseif ( defined( 'ZRDN_PRODUCT_ID' ) && ZRDN_PRODUCT_ID === 1851 ) {
124 deactivate_plugins( 'zip-recipes-friend/zip-recipes-friend.php' );
125 //add_action('admin_notices', __NAMESPACE__ . '\zrdn_notice_free_active');
126 } elseif ( file_exists( WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'zip-recipes-premium' . DIRECTORY_SEPARATOR . 'zip-recipes-lover.php' ) ) {
127 deactivate_plugins( 'zip-recipes-premium/zip-recipes-lover.php' );
128 } else {
129 deactivate_plugins( 'zip-recipes-lover/zip-recipes-lover.php' );
130 }
131 } else {
132 define( 'ZRDN_PLUGIN_PRODUCT_URL', 'https://ziprecipes.net/downloads/zip-recipes-lover' );
133 define( 'ZRDN_PLUGIN_PRODUCT_FILE', __FILE__ );
134 define( 'ZRDN_PLUGIN_DIRECTORY_URL', plugin_dir_url( __FILE__ ) );
135 define( 'ZRDN_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
136 define( 'ZRDN_PLUGIN_URL', sprintf( '%s/%s/', plugins_url(), dirname( plugin_basename( __FILE__ ) ) ) );
137 define( 'ZRDN_API_URL', "https://api.ziprecipes.net" );
138 define( 'ZRDN_PATH', plugin_dir_path( __FILE__ ) );
139 define( 'ZRDN_PLUGIN_PRODUCT_NAME', 'Zip Recipes Lover' );
140 $debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? time() : '' );
141 define( 'ZRDN_VERSION_NUM', '8.2.8' . $debug );
142 if ( !defined( 'ZRDN_PREMIUM' ) ) {
143 define( 'ZRDN_FREE', true );
144 }
145 add_action( 'plugins_loaded', __NAMESPACE__ . '\\init', 9 );
146 }
147 /**
148 * --exclude=plugins/AutomaticNutrition*
149 * --exclude=plugins/Authors*
150 * --exclude=plugins/CustomTemplates*
151 * --exclude=plugins/ImperialMetricsConverter*
152 * --exclude=plugins/Import*
153 * --exclude=plugins/Licensing*
154 * --exclude=plugins/MostPopularRecipes*
155 * --exclude=plugins/RecipeActions*
156 * --exclude=plugins/RecipeReviews*
157 * --exclude=plugins/RecipeSearch*
158 * --exclude=plugins/ServingAdjustment*
159 * --exclude=plugins/VisitorRating*
160 * --exclude=plugins/_internal*
161 * --exclude=*languages/zip-recipes*.po
162 * --exclude=*languages/zip-recipes*.mo zip-recipes-lover/. zip-recipes/
163 */
164 if ( !function_exists( __NAMESPACE__ . '\\init' ) ) {
165 function init( $className ) {
166 require_once ZRDN_PATH . '/models/Recipe.php';
167 require_once ZRDN_PATH . '_inc/class.ziprecipes.util.php';
168 require_once ZRDN_PATH . 'class.ziprecipes.php';
169 require_once ZRDN_PATH . 'class-review.php';
170 require_once ZRDN_PATH . '_inc/helper_functions.php';
171 require_once ZRDN_PATH . '_inc/PluginBase.php';
172 require_once ZRDN_PATH . 'RecipeTable/RecipeMenu.php';
173 require_once ZRDN_PATH . 'NutritionLabel/NutritionLabel.php';
174 require_once ZRDN_PATH . 'cron/cron.php';
175 if ( is_admin() ) {
176 require_once ZRDN_PATH . 'upgrade-zip.php';
177 require_once ZRDN_PATH . 'grid/grid-enqueue.php';
178 require_once ZRDN_PATH . 'class-field.php';
179 require_once ZRDN_PATH . 'shepherd/tour.php';
180 }
181 /**
182 * API endpoint & Basic Auth
183 */
184 require_once ZRDN_PATH . "controllers/Response.php";
185 require_once ZRDN_PATH . "controllers/EndpointController.php";
186 if ( !function_exists( 'is_plugin_active' ) ) {
187 require_once ABSPATH . '/wp-admin/includes/plugin.php';
188 }
189 ZipRecipes::init();
190 }
191
192 }
193 if ( !function_exists( __NAMESPACE__ . '\\zrdn_set_defaults' ) ) {
194 register_activation_hook( __FILE__, __NAMESPACE__ . '\\zrdn_set_defaults' );
195 /**
196 * set defaults on activation
197 */
198 function zrdn_set_defaults() {
199 if ( !get_option( 'zrdn_defaults_set' ) ) {
200 //set some defaults
201 $settings = get_option( 'zrdn_settings_general' );
202 $zrdn_print['show_summary_on_archive_pages'] = true;
203 update_option( 'zrdn_settings_general', $settings );
204 update_option( 'zrdn_defaults_set', true );
205 }
206 }
207
208 }
209 if ( !function_exists( __NAMESPACE__ . '\\zrdn_check_translations' ) ) {
210 register_activation_hook( __FILE__, __NAMESPACE__ . '\\zrdn_check_translations' );
211 function zrdn_check_translations() {
212 //dirname with levels does not exist before php 7
213 if ( version_compare( PHP_VERSION, '7.0', '<' ) ) {
214 return;
215 }
216 $path = dirname( ZRDN_PATH, 2 ) . "/languages/plugins/";
217 if ( !file_exists( $path ) ) {
218 return;
219 }
220 $extensions = array("po", "mo");
221 if ( $handle = opendir( $path ) ) {
222 while ( false !== ($file = readdir( $handle )) ) {
223 if ( $file != "." && $file != ".." ) {
224 $file = $path . '/' . $file;
225 $ext = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) );
226 if ( is_file( $file ) && in_array( $ext, $extensions ) && strpos( $file, 'zip-recipes' ) !== FALSE && strpos( $file, 'backup' ) === FALSE ) {
227 //copy to new file
228 $new_name = str_replace( 'zip-recipes', 'zip-recipes-backup', $file );
229 rename( $file, $new_name );
230 }
231 }
232 }
233 closedir( $handle );
234 }
235 }
236
237 }
238 /**
239 * Load iframe has to hook into admin init, otherwise languages are not loaded yet.
240 *
241 * */
242 if ( !function_exists( __NAMESPACE__ . '\\zrdn_maybe_load_iframe' ) ) {
243 function zrdn_maybe_load_iframe() {
244 // Setup query catch for recipe insertion popup.
245 if ( strpos( $_SERVER['REQUEST_URI'], 'media-upload.php' ) && strpos( $_SERVER['REQUEST_URI'], '&type=z_recipe' ) && !strpos( $_SERVER['REQUEST_URI'], '&wrt=' ) ) {
246 // pluggable.php is needed for current_user_can
247 require_once ABSPATH . 'wp-includes/pluggable.php';
248 // user is logged in and can edit posts or pages
249 if ( \current_user_can( 'edit_posts' ) || \current_user_can( 'edit_pages' ) ) {
250 $get_info = $_REQUEST;
251 $post_id = ( isset( $get_info["post_id"] ) ? intval( $get_info["post_id"] ) : 0 );
252 if ( isset( $get_info["recipe_post_id"] ) && !isset( $get_info["add-recipe-button"] ) && strpos( $get_info["recipe_post_id"], '-' ) !== false ) {
253 // EDIT recipe
254 $recipe_id = preg_replace( '/[0-9]*?\\-/i', '', $get_info["recipe_post_id"] );
255 wp_redirect( add_query_arg( array(
256 "page" => "zrdn-recipes",
257 "action" => "new",
258 "id" => $recipe_id,
259 "post_id" => $post_id,
260 "popup" => true,
261 ), admin_url( "admin.php" ) ) );
262 } else {
263 // New recipe
264 wp_redirect( add_query_arg( array(
265 "page" => "zrdn-recipes",
266 "action" => "new",
267 "post_id" => $post_id,
268 "popup" => true,
269 ), admin_url( "admin.php" ) ) );
270 }
271 }
272 exit;
273 }
274 }
275
276 add_action( 'admin_init', __NAMESPACE__ . '\\zrdn_maybe_load_iframe', 30 );
277 }
278 if ( !function_exists( __NAMESPACE__ . '\\zrdn_start_tour' ) ) {
279 /**
280 * Start the tour of the plugin on activation
281 */
282 function zrdn_start_tour() {
283 if ( !get_site_option( 'zrdn_tour_shown_once' ) ) {
284 update_site_option( 'zrdn_tour_started', true );
285 }
286 }
287
288 register_activation_hook( __FILE__, __NAMESPACE__ . '\\zrdn_start_tour' );
289 }