PluginProbe
Extendify / 2.4.1
Extendify v2.4.1
3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 0.8.0 All 125 releases
extendify / extendify.php

extendify.php in Extendify 2.4.1, at extendify.php

157 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Generic.Files.LineLength.TooLong
4 /**
5 * Plugin Name: Extendify WordPress Onboarding and AI Assistant
6 * Description: AI-powered WordPress assistant for onboarding and ongoing editing offered exclusively through select WordPress hosting providers.
7 * Plugin URI: https://extendify.com/?utm_source=wp-plugins&utm_campaign=plugin-uri&utm_medium=wp-dash
8 * Author: Extendify
9 * Author URI: https://extendify.com/?utm_source=wp-plugins&utm_campaign=author-uri&utm_medium=wp-dash
10 * Version: 2.4.1
11 * Requires at least: 6.5
12 * Requires PHP: 7.0
13 * License: GPL-2.0-or-later
14 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
15 * Text Domain: extendify-local
16 * Domain Path: /languages
17 *
18 * Extendify is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 2 of the License, or
21 * any later version.
22 *
23 * Extendify is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 */
28 // phpcs:enable Generic.Files.LineLength.TooLong
29
30 defined('ABSPATH') || exit;
31
32 use Extendify\PartnerData;
33
34 /** ExtendifySdk is the previous class name used */
35 if (!class_exists('ExtendifySdk') && !class_exists('Extendify')) :
36
37 /**
38 * The Extendify Library
39 */
40 // phpcs:ignore PSR1.Classes.ClassDeclaration.MissingNamespace
41 final class Extendify
42 {
43 /**
44 * Var to make sure we only load once
45 *
46 * @var boolean $loaded
47 */
48 public static $loaded = false;
49
50 /**
51 * Set up the Library
52 *
53 * @return void
54 */
55 public function __invoke()
56 {
57 // Allow users to disable the library. The latter is left in for historical reasons.
58 if (!apply_filters('extendify_load_library', true) || !apply_filters('extendifysdk_load_library', true)) {
59 return;
60 }
61
62 if (version_compare(PHP_VERSION, '7.0', '<') || version_compare($GLOBALS['wp_version'], '6.5', '<')) {
63 return;
64 }
65
66 if (!self::$loaded) {
67 self::$loaded = true;
68 require dirname(__FILE__) . '/bootstrap.php';
69 if (!defined('EXTENDIFY_BASE_URL')) {
70 define('EXTENDIFY_BASE_URL', plugin_dir_url(__FILE__));
71 }
72 }
73 }
74 }
75
76 add_action('plugins_loaded', function () {
77 $extendify = new Extendify();
78 $extendify();
79 });
80
81 add_action('update_option', function ($option) {
82 if (in_array($option, ['WPLANG', 'blogname'], true)) {
83 \delete_transient('extendify_recommendations');
84 \delete_transient('extendify_domains');
85 \delete_transient('extendify_supportArticles');
86 }
87
88 // Delete the partner transient so we can fetch new data when the locale is switched.
89 if (($option === 'WPLANG') && get_transient('extendify_partner_data_cache_check')) {
90 delete_transient('extendify_partner_data_cache_check');
91 PartnerData::getPartnerData();
92 }
93 });
94
95 // Delete the partner transient so we can fetch new data when the locale is switched via WP-CLI.
96 add_action('cli_init', function () {
97 $command = sanitize_text_field(wp_unslash(($_SERVER['argv'][1] ?? '')));
98 if ($command === 'language' && get_transient('extendify_partner_data_cache_check')) {
99 delete_transient('extendify_partner_data_cache_check');
100 PartnerData::getPartnerData();
101 }
102 });
103
104 // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
105 add_action('upgrader_process_complete', function ($upgrader, $options) {
106 $updatedExtendify = isset($options['plugins']) && array_filter($options['plugins'], function ($plugin) {
107 return strpos($plugin, 'extendify') !== false;
108 });
109
110 if (!$updatedExtendify) {
111 return;
112 }
113
114 \delete_transient('extendify_recommendations');
115 \delete_transient('extendify_domains');
116 \delete_transient('extendify_supportArticles');
117 }, 10, 2);
118
119 // Redirect logins to the Extendify Assist dashboard if they are an admin.
120 // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
121 \add_filter('login_redirect', function ($redirectTo, $requestedRedirectTo, $user) {
122 // Only redirect if going to the admin page.
123 if ($redirectTo !== \admin_url()) {
124 return $redirectTo;
125 }
126
127 if (!$user || !is_a($user, 'WP_User') || !defined('EXTENDIFY_PARTNER_ID')) {
128 return $redirectTo;
129 }
130
131 $partnerData = get_option('extendify_partner_data_v2', []);
132 if (!$user->has_cap('manage_options') || empty($partnerData)) {
133 return $redirectTo;
134 }
135
136 return \admin_url() . 'admin.php?page=extendify-assist';
137 }, 10, 3);
138
139 // Redirect to a safe place if the user doesn't have access.
140 add_action('admin_page_access_denied', function () {
141 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
142 if (isset($_GET['page']) && strpos(sanitize_text_field(wp_unslash($_GET['page'])), 'extendify') !== false) {
143 wp_safe_redirect(admin_url());
144 exit;
145 }
146 });
147
148 // Allow Extendify requests to have a longer timeout.
149 add_filter('http_request_args', function ($args, $url) {
150 if (strpos($url, 'extendify') !== false) {
151 $args['timeout'] = 45;
152 }
153
154 return $args;
155 }, 100, 2);
156 endif;
157