PluginProbe
Generate Images (AI) – Magic Post Thumbnail / 6.2.2
Generate Images (AI) – Magic Post Thumbnail v6.2.2
7.0.1 7.0.0 6.1.3 6.1.4 6.1.5 6.1.6 6.1.7 6.1.8 6.2.0 6.2.1 6.2.2 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 2.0 2.1 2.1.1 2.2 2.2.1 2.3 All 115 releases
magic-post-thumbnail / magic-post-thumbnail.php

magic-post-thumbnail.php in Generate Images (AI) – Magic Post Thumbnail 6.2.2, at magic-post-thumbnail.php

226 lines 8.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 *
5 * @link https://magic-post-thumbnail.com/
6 * @since 1.0.0
7 * @package Magic_Post_Thumbnail
8 *
9 * @wordpress-plugin
10 * Plugin Name: Magic Post Thumbnail
11 * Plugin URI: http://wordpress.org/plugins/magic-post-thumbnail/
12 * Description: Add stunning images to your posts effortlessly, as featured images or within content. Magic Post Thumbnail sources them automatically from multiple image banks.
13 * Version: 6.2.2
14 * Author: Magic Post Thumbnail
15 * Author URI: https://magic-post-thumbnail.com/
16 * License: GPL-2.0+
17 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
18 * Text Domain: magic-post-thumbnail
19 * Domain Path: /languages
20 *
21 *
22 *
23 *
24 */
25 // If this file is called directly, abort.
26 if ( !defined( 'WPINC' ) ) {
27 die;
28 }
29 if ( function_exists( 'mpt_freemius' ) ) {
30 mpt_freemius()->set_basename( false, __FILE__ );
31 } else {
32 if ( !function_exists( 'mpt_freemius' ) ) {
33 function mpt_freemius() {
34 global $mpt_freemius;
35 if ( !isset( $mpt_freemius ) ) {
36 // Include Freemius SDK.
37 require_once dirname( __FILE__ ) . '/admin/partials/freemius/start.php';
38 $mpt_freemius = fs_dynamic_init( array(
39 'id' => '2891',
40 'slug' => 'magic-post-thumbnail',
41 'type' => 'plugin',
42 'public_key' => 'pk_0842b408e487a0001e564a31d3a37',
43 'is_premium' => false,
44 'premium_suffix' => 'Pro',
45 'has_addons' => false,
46 'has_paid_plans' => true,
47 'has_affiliation' => 'selected',
48 'is_org_compliant' => true,
49 'menu' => array(
50 'slug' => 'magic-post-thumbnail-admin-display',
51 'first-path' => 'admin.php?page=magic-post-thumbnail-admin-display',
52 'contact' => false,
53 'support' => false,
54 'affiliation' => false,
55 'account' => false,
56 'addons' => false,
57 ),
58 'navigation' => 'tabs',
59 'is_live' => true,
60 ) );
61 }
62 return $mpt_freemius;
63 }
64
65 // Init Freemius.
66 mpt_freemius();
67 // Signal that SDK was initiated.
68 do_action( 'mpt_freemius_loaded' );
69 }
70 /**
71 * Currently plugin version.
72 * Start at version 1.0.0 and use SemVer - https://semver.org
73 * Rename this for your plugin and update it as you release new versions.
74 */
75 define( 'MAGIC_POST_THUMBNAIL_VERSION', '6.2.2' );
76 /**
77 * The code that runs during plugin activation.
78 * This action is documented in includes/class-magic-post-thumbnail-activator.php
79 */
80 function activate_magic_post_thumbnail() {
81 require_once plugin_dir_path( __FILE__ ) . 'includes/class-magic-post-thumbnail-activator.php';
82 Magic_Post_Thumbnail_Activator::activate();
83 }
84
85 /**
86 * The code that runs during plugin deactivation.
87 * This action is documented in includes/class-magic-post-thumbnail-deactivator.php
88 */
89 function deactivate_magic_post_thumbnail() {
90 require_once plugin_dir_path( __FILE__ ) . 'includes/class-magic-post-thumbnail-deactivator.php';
91 Magic_Post_Thumbnail_Deactivator::deactivate();
92 }
93
94 register_activation_hook( __FILE__, 'activate_magic_post_thumbnail' );
95 register_deactivation_hook( __FILE__, 'deactivate_magic_post_thumbnail' );
96 /**
97 * The core plugin class that is used to define internationalization,
98 * admin-specific hooks, and public-facing site hooks.
99 */
100 require plugin_dir_path( __FILE__ ) . 'includes/class-magic-post-thumbnail.php';
101 /**
102 * Add capabilities
103 */
104 function MPT_add_capability() {
105 $options = get_option( 'MPT_plugin_rights_settings' );
106 // Administrators always have the capability
107 $admin_role = get_role( 'administrator' );
108 if ( $admin_role ) {
109 $admin_role->add_cap( 'mpt_manage', true );
110 }
111 // Manage other roles by adding or removing capabilities according to options
112 $roles = array(
113 'editor' => 'rights_editor',
114 'author' => 'rights_author',
115 'contributor' => 'rights_contributor',
116 'subscriber' => 'rights_subscriber',
117 );
118 foreach ( $roles as $role_name => $option_key ) {
119 $role = get_role( $role_name );
120 if ( $role ) {
121 if ( isset( $options[$option_key] ) && $options[$option_key] === 'true' ) {
122 // Adds capacity if the option is enabled
123 $role->add_cap( 'mpt_manage', true );
124 } else {
125 // Removes the capacity if the option is deactivated
126 $role->remove_cap( 'mpt_manage' );
127 }
128 }
129 }
130 }
131
132 /**
133 * Check hook wp_insert_post to fire functionalities
134 *
135 * @since 6.0.0
136 */
137 function MPT_check_hook() {
138 }
139
140 /**
141 * Check capabilities before launching the plugin main features
142 *
143 * @since 5.0.0
144 */
145 function MPT_check_capability() {
146 $additional_check = false;
147 // add capability for the cron
148 if ( wp_doing_cron() || true == $additional_check ) {
149 global $current_user;
150 $current_user->add_cap( 'mpt_manage' );
151 }
152 if ( current_user_can( 'mpt_manage' ) ) {
153 $plugin = new Magic_Post_Thumbnail();
154 $plugin->run();
155 }
156 }
157
158 /**
159 * Begins execution of the plugin.
160 *
161 * Since everything within the plugin is registered via hooks,
162 * then kicking off the plugin from this point in the file does
163 * not affect the page life cycle.
164 *
165 * @since 4.0.0
166 */
167 function run_magic_post_thumbnail() {
168 // User role & capacity
169 add_action( 'init', 'MPT_add_capability', 1 );
170 add_action( 'init', 'MPT_check_capability', 2 );
171 // Features with hooks
172 add_action( 'init', 'MPT_check_hook', 5 );
173 }
174
175 run_magic_post_thumbnail();
176 // Fired when the plugin is uninstalled.
177 mpt_freemius()->add_action( 'after_uninstall', 'mpt_freemius_uninstall_cleanup' );
178 function mpt_freemius_uninstall_cleanup() {
179 // Remove logs
180 define( "MPT_FREEMIUS_UNINSTALL", true );
181 require_once dirname( __FILE__ ) . '/admin/partials/delete_log.php';
182 // Delete all plugin options
183 delete_option( 'MPT_plugin_posts_settings' );
184 delete_option( 'MPT_plugin_main_settings' );
185 delete_option( 'MPT_plugin_banks_settings' );
186 delete_option( 'MPT_plugin_interval_settings' );
187 delete_option( 'MPT_plugin_cron_settings' );
188 delete_option( 'MPT_plugin_rights_settings' );
189 delete_option( 'MPT_plugin_proxy_settings' );
190 delete_option( 'MPT_plugin_compatibility_settings' );
191 delete_option( 'MPT_plugin_logs_settings' );
192 }
193
194 }
195 add_action( 'init', function () {
196 if ( !current_user_can( 'manage_options' ) ) {
197 return;
198 }
199 if ( isset( $_GET['mpt_test_google'] ) ) {
200 $search = 'test image';
201 $params = array(
202 'tbm' => 'isch',
203 'q' => urlencode( $search ),
204 'hl' => 'en',
205 'safe' => 'medium',
206 'rsz' => '3',
207 );
208 $url = add_query_arg( $params, 'https://www.google.com/search' );
209 $defaults = array(
210 'redirection' => 9,
211 'user-agent' => 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) Chrome/41.0.2272.96',
212 'reject_unsafe_urls' => false,
213 'sslverify' => false,
214 );
215 $result = wp_remote_request( $url, $defaults );
216 header( 'Content-Type: text/plain; charset=utf-8' );
217 if ( is_wp_error( $result ) ) {
218 var_dump( $result->get_error_message() );
219 exit;
220 }
221 echo "HTTP CODE: " . $result['response']['code'] . "\n\n";
222 echo substr( $result['body'], 0, 50000 );
223 // début du HTML
224 exit;
225 }
226 } );