PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 3.2.1 3.2.0 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 All 128 releases
extendify / extendify.php

extendify.php in Extendify 3.2.2, at extendify.php

178 lines 6.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: 3.2.2
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 /** ExtendifySdk is the previous class name used */
33 if (!class_exists('ExtendifySdk') && !class_exists('Extendify')) :
34
35 /**
36 * The Extendify Library
37 */
38 // phpcs:ignore PSR1.Classes.ClassDeclaration.MissingNamespace
39 final class Extendify
40 {
41 /**
42 * Var to make sure we only load once
43 *
44 * @var boolean $loaded
45 */
46 public static $loaded = false;
47
48 /**
49 * Set up the Library
50 *
51 * @return void
52 */
53 public function __invoke()
54 {
55 // Allow users to disable the library. The latter is left in for historical reasons.
56 if (!apply_filters('extendify_load_library', true) || !apply_filters('extendifysdk_load_library', true)) {
57 return;
58 }
59
60 if (version_compare(PHP_VERSION, '7.0', '<') || version_compare($GLOBALS['wp_version'], '6.5', '<')) {
61 return;
62 }
63
64 if (!self::$loaded) {
65 self::$loaded = true;
66 if (!defined('EXTENDIFY_PLUGIN_BASENAME')) {
67 define('EXTENDIFY_PLUGIN_BASENAME', plugin_basename(__FILE__));
68 }
69 require dirname(__FILE__) . '/bootstrap.php';
70 if (!defined('EXTENDIFY_BASE_URL')) {
71 define('EXTENDIFY_BASE_URL', plugin_dir_url(__FILE__));
72 }
73 }
74 }
75 }
76
77 add_action('plugins_loaded', function () {
78 $extendify = new Extendify();
79 $extendify();
80 });
81
82 // Autoloaded options load on every request, even while the plugin is inactive.
83 // Before 6.6 there is no 'auto' value, so older sites are left alone.
84 if (function_exists('wp_autoload_values_to_autoload')) {
85 register_deactivation_hook(__FILE__, function () {
86 $names = preg_grep('/^extendify_/', array_keys(wp_load_alloptions()));
87 update_option('extendify_autoload_restore', $names, false);
88 wp_set_option_autoload_values(array_fill_keys($names, false));
89 });
90
91 register_activation_hook(__FILE__, function () {
92 global $wpdb;
93 // Passing true writes 'on', which skips WordPress's 150KB autoload size check.
94 foreach (get_option('extendify_autoload_restore', []) as $name) {
95 $wpdb->update($wpdb->options, ['autoload' => 'auto'], ['option_name' => $name]);
96 }
97 wp_cache_delete('alloptions', 'options');
98 delete_option('extendify_autoload_restore');
99 });
100 }
101
102 // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
103 add_action('upgrader_process_complete', function ($upgrader, $options) {
104 $updatedExtendify = isset($options['plugins']) && array_filter($options['plugins'], function ($plugin) {
105 return strpos($plugin, 'extendify') !== false;
106 });
107
108 if (!$updatedExtendify) {
109 return;
110 }
111
112 \delete_transient('extendify_recommendations');
113 \delete_transient('extendify_domains');
114 \delete_transient('extendify_supportArticles');
115 }, 10, 2);
116
117 // Redirect logins to the Extendify Assist dashboard if they are an admin.
118 // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
119 \add_filter('login_redirect', function ($redirectTo, $requestedRedirectTo, $user) {
120 // Only redirect if going to the admin page.
121 if ($redirectTo !== \admin_url()) {
122 return $redirectTo;
123 }
124
125 if (!$user || !is_a($user, 'WP_User') || !defined('EXTENDIFY_PARTNER_ID')) {
126 return $redirectTo;
127 }
128
129 $partnerData = get_option('extendify_partner_data_v2', []);
130 if (!$user->has_cap('manage_options') || empty($partnerData)) {
131 return $redirectTo;
132 }
133
134 return \admin_url() . 'admin.php?page=extendify-assist';
135 }, 10, 3);
136
137 // Redirect to a safe place if the user doesn't have access.
138 add_action('admin_page_access_denied', function () {
139 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
140 if (isset($_GET['page']) && strpos(sanitize_text_field(wp_unslash($_GET['page'])), 'extendify') !== false) {
141 wp_safe_redirect(admin_url());
142 exit;
143 }
144 });
145
146 // Clean up the site profile if being accessed
147 add_filter('option_extendify_site_profile', function ($value) {
148 $profile = is_string($value) ? json_decode($value, true) : $value;
149 $profile = is_array($profile) ? $profile : [];
150
151 $map = [
152 'aiSiteType' => 'type',
153 'aiTitle' => 'title',
154 'aiDescription' => 'description',
155 'aiObjective' => 'objective',
156 'aiSiteCategory' => 'category',
157 'aiStructure' => 'structure',
158 'aiKeywords' => 'imageSearchTerms',
159 'logoObjectName' => 'logoObjectName',
160 ];
161
162 foreach ($map as $old => $new) {
163 if (!array_key_exists($new, $profile)) {
164 $profile[$new] = $profile[$old] ?? null;
165 }
166 }
167
168 // if tone is set and is not array (and ensure lowercase)
169 if (isset($profile['tone']) && !is_array($profile['tone'])) {
170 $profile['tone'] = array_map(function ($v) {
171 return strtolower((string) $v);
172 }, (array) ($profile['tone'] ?? []));
173 }
174
175 return $profile;
176 });
177 endif;
178