| @@ -1,15 +1,20 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 3 | +// phpcs:disable Generic.Files.LineLength.TooLong | |
| 2 | 4 | /** |
| 3 | - * Plugin Name: Extendify | |
| 4 | - * Description: Extendify is the platform of site design and creation tools for people that want to build a beautiful WordPress website with a library of patterns and full page layouts for the Gutenberg block editor. | |
| 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. | |
| 5 | 7 | * Plugin URI: https://extendify.com/?utm_source=wp-plugins&utm_campaign=plugin-uri&utm_medium=wp-dash |
| 6 | 8 | * Author: Extendify |
| 7 | 9 | * Author URI: https://extendify.com/?utm_source=wp-plugins&utm_campaign=author-uri&utm_medium=wp-dash |
| 8 | - * Version: 0.6.0 | |
| 10 | + * Version: 3.2.1 | |
| 11 | + * Requires at least: 6.5 | |
| 12 | + * Requires PHP: 7.0 | |
| 9 | 13 | * License: GPL-2.0-or-later |
| 10 | 14 | * License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 11 | - * Text Domain: extendify | |
| 15 | + * Text Domain: extendify-local | |
| 16 | + * Domain Path: /languages | |
| 12 | 17 | * |
| 13 | 18 | * Extendify is free software: you can redistribute it and/or modify |
| 14 | 19 | * it under the terms of the GNU General Public License as published by |
| 15 | 20 | * the Free Software Foundation, either version 2 of the License, or |
| @@ -19,12 +24,11 @@ | ||
| 19 | 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | 26 | * GNU General Public License for more details. |
| 22 | 27 | */ |
| 28 | +// phpcs:enable Generic.Files.LineLength.TooLong | |
| 23 | 29 | |
| 24 | -if (!defined('ABSPATH')) { | |
| 25 | - exit; | |
| 26 | -} | |
| 30 | +defined('ABSPATH') || exit; | |
| 27 | 31 | |
| 28 | 32 | /** ExtendifySdk is the previous class name used */ |
| 29 | 33 | if (!class_exists('ExtendifySdk') && !class_exists('Extendify')) : |
| 30 | 34 | |
| @@ -30,12 +34,11 @@ | ||
| 30 | 34 | |
| 31 | 35 | /** |
| 32 | 36 | * The Extendify Library |
| 33 | 37 | */ |
| 34 | - // phpcs:ignore Squiz.Classes.ClassFileName.NoMatch,Squiz.Commenting.ClassComment.Missing,PEAR.Commenting.ClassComment.Missing | |
| 38 | + // phpcs:ignore PSR1.Classes.ClassDeclaration.MissingNamespace | |
| 35 | 39 | final class Extendify |
| 36 | 40 | { |
| 37 | - | |
| 38 | 41 | /** |
| 39 | 42 | * Var to make sure we only load once |
| 40 | 43 | * |
| 41 | 44 | * @var boolean $loaded |
| @@ -48,28 +51,107 @@ | ||
| 48 | 51 | * @return void |
| 49 | 52 | */ |
| 50 | 53 | public function __invoke() |
| 51 | 54 | { |
| 52 | - // Allow users to disable the libary. The latter is left in for historical reasons. | |
| 55 | + // Allow users to disable the library. The latter is left in for historical reasons. | |
| 53 | 56 | if (!apply_filters('extendify_load_library', true) || !apply_filters('extendifysdk_load_library', true)) { |
| 54 | 57 | return; |
| 55 | 58 | } |
| 56 | 59 | |
| 57 | - if (version_compare(PHP_VERSION, '5.6', '<') || version_compare($GLOBALS['wp_version'], '5.5', '<')) { | |
| 60 | + if (version_compare(PHP_VERSION, '7.0', '<') || version_compare($GLOBALS['wp_version'], '6.5', '<')) { | |
| 58 | 61 | return; |
| 59 | 62 | } |
| 60 | 63 | |
| 61 | 64 | if (!self::$loaded) { |
| 62 | 65 | self::$loaded = true; |
| 66 | + if (!defined('EXTENDIFY_PLUGIN_BASENAME')) { | |
| 67 | + define('EXTENDIFY_PLUGIN_BASENAME', plugin_basename(__FILE__)); | |
| 68 | + } | |
| 63 | 69 | require dirname(__FILE__) . '/bootstrap.php'; |
| 64 | - $app = new Extendify\Library\App(); | |
| 65 | 70 | if (!defined('EXTENDIFY_BASE_URL')) { |
| 66 | 71 | define('EXTENDIFY_BASE_URL', plugin_dir_url(__FILE__)); |
| 67 | 72 | } |
| 68 | 73 | } |
| 69 | 74 | } |
| 70 | - // phpcs:ignore Squiz.Classes.ClassDeclaration.SpaceBeforeCloseBrace | |
| 71 | 75 | } |
| 72 | 76 | |
| 73 | - $extendify = new Extendify(); | |
| 74 | - $extendify(); | |
| 77 | + add_action('plugins_loaded', function () { | |
| 78 | + $extendify = new Extendify(); | |
| 79 | + $extendify(); | |
| 80 | + }); | |
| 81 | + | |
| 82 | + // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed | |
| 83 | + add_action('upgrader_process_complete', function ($upgrader, $options) { | |
| 84 | + $updatedExtendify = isset($options['plugins']) && array_filter($options['plugins'], function ($plugin) { | |
| 85 | + return strpos($plugin, 'extendify') !== false; | |
| 86 | + }); | |
| 87 | + | |
| 88 | + if (!$updatedExtendify) { | |
| 89 | + return; | |
| 90 | + } | |
| 91 | + | |
| 92 | + \delete_transient('extendify_recommendations'); | |
| 93 | + \delete_transient('extendify_domains'); | |
| 94 | + \delete_transient('extendify_supportArticles'); | |
| 95 | + }, 10, 2); | |
| 96 | + | |
| 97 | + // Redirect logins to the Extendify Assist dashboard if they are an admin. | |
| 98 | + // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed | |
| 99 | + \add_filter('login_redirect', function ($redirectTo, $requestedRedirectTo, $user) { | |
| 100 | + // Only redirect if going to the admin page. | |
| 101 | + if ($redirectTo !== \admin_url()) { | |
| 102 | + return $redirectTo; | |
| 103 | + } | |
| 104 | + | |
| 105 | + if (!$user || !is_a($user, 'WP_User') || !defined('EXTENDIFY_PARTNER_ID')) { | |
| 106 | + return $redirectTo; | |
| 107 | + } | |
| 108 | + | |
| 109 | + $partnerData = get_option('extendify_partner_data_v2', []); | |
| 110 | + if (!$user->has_cap('manage_options') || empty($partnerData)) { | |
| 111 | + return $redirectTo; | |
| 112 | + } | |
| 113 | + | |
| 114 | + return \admin_url() . 'admin.php?page=extendify-assist'; | |
| 115 | + }, 10, 3); | |
| 116 | + | |
| 117 | + // Redirect to a safe place if the user doesn't have access. | |
| 118 | + add_action('admin_page_access_denied', function () { | |
| 119 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 120 | + if (isset($_GET['page']) && strpos(sanitize_text_field(wp_unslash($_GET['page'])), 'extendify') !== false) { | |
| 121 | + wp_safe_redirect(admin_url()); | |
| 122 | + exit; | |
| 123 | + } | |
| 124 | + }); | |
| 125 | + | |
| 126 | + // Clean up the site profile if being accessed | |
| 127 | + add_filter('option_extendify_site_profile', function ($value) { | |
| 128 | + $profile = is_string($value) ? json_decode($value, true) : $value; | |
| 129 | + $profile = is_array($profile) ? $profile : []; | |
| 130 | + | |
| 131 | + $map = [ | |
| 132 | + 'aiSiteType' => 'type', | |
| 133 | + 'aiTitle' => 'title', | |
| 134 | + 'aiDescription' => 'description', | |
| 135 | + 'aiObjective' => 'objective', | |
| 136 | + 'aiSiteCategory' => 'category', | |
| 137 | + 'aiStructure' => 'structure', | |
| 138 | + 'aiKeywords' => 'imageSearchTerms', | |
| 139 | + 'logoObjectName' => 'logoObjectName', | |
| 140 | + ]; | |
| 141 | + | |
| 142 | + foreach ($map as $old => $new) { | |
| 143 | + if (!array_key_exists($new, $profile)) { | |
| 144 | + $profile[$new] = $profile[$old] ?? null; | |
| 145 | + } | |
| 146 | + } | |
| 147 | + | |
| 148 | + // if tone is set and is not array (and ensure lowercase) | |
| 149 | + if (isset($profile['tone']) && !is_array($profile['tone'])) { | |
| 150 | + $profile['tone'] = array_map(function ($v) { | |
| 151 | + return strtolower((string) $v); | |
| 152 | + }, (array) ($profile['tone'] ?? [])); | |
| 153 | + } | |
| 154 | + | |
| 155 | + return $profile; | |
| 156 | + }); | |
| 75 | 157 | endif; |